public View buildView() { View mainView = loadViewFromXml(R.layout.color_picker); picker = (ColorPicker) mainView.findViewById(R.id.picker); // svBar = (SVBar) findViewById(R.id.svbar); // opacityBar = (OpacityBar) findViewById(R.id.opacitybar); saturationBar = (SaturationBar) mainView.findViewById(R.id.saturationbar); // valueBar = (ValueBar) findViewById(R.id.valuebar); oldColorHex = Project4App.getApp(context).getEditProjectColorString(); int oldColor = Color.parseColor(oldColorHex); picker.setColor(oldColor); picker.setOldCenterColor(oldColor); // picker.addSVBar(svBar); // picker.addValueBar(valueBar); // picker.addOpacityBar(opacityBar); picker.addSaturationBar(saturationBar); // picker.setOnColorChangedListener(this); // picker.setShowOldCenterColor(false); return mainView; }
private void showColorPickerDialog( Context context, int preColor, final ColorPicker.OnColorChangedListener listener) { AlertDialog.Builder builder = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(params); final ColorPicker picker = new ColorPicker(context); picker.setLayoutParams(params); OpacityBar opacityBar = new OpacityBar(context); opacityBar.setLayoutParams(params); SaturationBar saturationBar = new SaturationBar(context); saturationBar.setLayoutParams(params); ValueBar valueBar = new ValueBar(context); valueBar.setLayoutParams(params); linearLayout.addView(picker); linearLayout.addView(opacityBar); linearLayout.addView(saturationBar); linearLayout.addView(valueBar); picker.addOpacityBar(opacityBar); picker.addSaturationBar(saturationBar); picker.addValueBar(valueBar); picker.setOldCenterColor(preColor); picker.setColor(preColor); builder.setView(linearLayout); builder.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setColor(picker.getColor()); listener.onColorChanged(picker.getColor()); } }); builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); }