package cn.com.magnity.magnitycx; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageButton; import android.widget.TextView; import cn.com.magnity.magnitycx.sdk.DeviceController; import cn.com.magnity.magnitycx.sdk.SharedPreferencesManager; import java.util.HashMap; /* loaded from: classes.dex */ public class DialogFragmentPalette extends DialogFragment implements View.OnClickListener { private View rootView_; private HashMap mapIndex2Id_ = new HashMap() { // from class: cn.com.magnity.magnitycx.DialogFragmentPalette.1 { put(0, Integer.valueOf(R.id.id_palette_white_hot)); put(1, Integer.valueOf(R.id.id_palette_black_hot)); put(2, Integer.valueOf(R.id.id_palette_iron_bow)); put(3, Integer.valueOf(R.id.id_palette_rain_bow)); put(4, Integer.valueOf(R.id.id_palette_glow_bow)); put(5, Integer.valueOf(R.id.id_palette_autumn)); put(6, Integer.valueOf(R.id.id_palette_winter)); put(7, Integer.valueOf(R.id.id_palette_hot_metal)); put(8, Integer.valueOf(R.id.id_palette_jet)); put(9, Integer.valueOf(R.id.id_palette_red_saturation)); put(10, Integer.valueOf(R.id.id_palette_high_contrast)); put(11, Integer.valueOf(R.id.id_palette_ret_hot)); } }; private HashMap mapId2Index_ = new HashMap() { // from class: cn.com.magnity.magnitycx.DialogFragmentPalette.2 { put(Integer.valueOf(R.id.id_palette_white_hot), 0); put(Integer.valueOf(R.id.id_palette_black_hot), 1); put(Integer.valueOf(R.id.id_palette_iron_bow), 2); put(Integer.valueOf(R.id.id_palette_rain_bow), 3); put(Integer.valueOf(R.id.id_palette_glow_bow), 4); put(Integer.valueOf(R.id.id_palette_autumn), 5); put(Integer.valueOf(R.id.id_palette_winter), 6); put(Integer.valueOf(R.id.id_palette_hot_metal), 7); put(Integer.valueOf(R.id.id_palette_jet), 8); put(Integer.valueOf(R.id.id_palette_red_saturation), 9); put(Integer.valueOf(R.id.id_palette_high_contrast), 10); put(Integer.valueOf(R.id.id_palette_ret_hot), 11); } }; @Override // android.support.v4.app.DialogFragment, android.support.v4.app.Fragment public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override // android.support.v4.app.Fragment @Nullable public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.rootView_ = inflater.inflate(R.layout.dialog_fragment_palette, container); initPalette(this.rootView_); getDialog().requestWindowFeature(1); getDialog().setCanceledOnTouchOutside(true); getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.liveBackground))); return this.rootView_; } @Override // android.support.v4.app.DialogFragment, android.support.v4.app.Fragment public void onStart() { super.onStart(); Window window = getDialog().getWindow(); WindowManager.LayoutParams windowParams = window.getAttributes(); windowParams.dimAmount = 0.0f; windowParams.alpha = 0.7f; window.setAttributes(windowParams); } @Override // android.support.v4.app.DialogFragment, android.support.v4.app.Fragment public void onDestroyView() { super.onDestroyView(); } private void initPalette(View rootView) { fillPalette(rootView, R.id.id_palette_white_hot, R.mipmap.palette_white_hot, R.string.paletteWhiteHot); fillPalette(rootView, R.id.id_palette_black_hot, R.mipmap.palette_black_hot, R.string.paletteBlackHot); fillPalette(rootView, R.id.id_palette_iron_bow, R.mipmap.palette_iron_bow, R.string.paletteIronBow); fillPalette(rootView, R.id.id_palette_rain_bow, R.mipmap.palette_rain_bow, R.string.paletteRainBow); fillPalette(rootView, R.id.id_palette_glow_bow, R.mipmap.palette_glow_bow, R.string.paletteGlowBow); fillPalette(rootView, R.id.id_palette_autumn, R.mipmap.palette_autumn, R.string.paletteAutumn); fillPalette(rootView, R.id.id_palette_winter, R.mipmap.palette_winter, R.string.paletteWinter); fillPalette(rootView, R.id.id_palette_hot_metal, R.mipmap.palette_hot_metal, R.string.paletteHotMetal); fillPalette(rootView, R.id.id_palette_jet, R.mipmap.palette_jet, R.string.paletteJet); fillPalette(rootView, R.id.id_palette_red_saturation, R.mipmap.palette_red_saturation, R.string.paletteRedSaturation); fillPalette(rootView, R.id.id_palette_high_contrast, R.mipmap.palette_high_contrast, R.string.paletteHighContrast); fillPalette(rootView, R.id.id_palette_ret_hot, R.mipmap.palette_red_hot, R.string.paletteRedhot); updateSelectionUi(0, SharedPreferencesManager.getInt("paletteIndex", 2)); } private void fillPalette(View rootView, int viewId, int imgId, int tvId) { View v = rootView.findViewById(viewId); v.setBackgroundColor(0); ImageButton viewer = (ImageButton) v.findViewById(R.id.id_palette_image); viewer.setImageResource(imgId); viewer.setOnClickListener(this); TextView tv = (TextView) v.findViewById(R.id.id_palette_label); tv.setText(tvId); } void updateSelectionUi(int formerSelected, int currentSelected) { View v = this.rootView_.findViewById(((Integer) this.mapIndex2Id_.get(Integer.valueOf(formerSelected))).intValue()); v.setBackgroundColor(0); View v2 = this.rootView_.findViewById(((Integer) this.mapIndex2Id_.get(Integer.valueOf(currentSelected))).intValue()); v2.setBackgroundColor(1073741823); } @Override // android.view.View.OnClickListener public void onClick(View v) { ViewGroup parent; if (v.getId() == R.id.id_palette_image && (parent = (ViewGroup) v.getParent().getParent()) != null) { int index = ((Integer) this.mapId2Index_.get(Integer.valueOf(parent.getId()))).intValue(); updateSelectionUi(SharedPreferencesManager.getInt("paletteIndex", 2), index); DeviceController.Lock(); DeviceController.setColorPalette(index); DeviceController.Unlock(); SharedPreferencesManager.putIntWithCommit("paletteIndex", index); } } }