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; }
/** * Set the bar color. <br> * <br> * Its discouraged to use this method. * * @param color */ public void setColor(int color) { int x1, y1; if (mOrientation == ORIENTATION_HORIZONTAL) { x1 = (mBarLength + mBarPointerHaloRadius); y1 = mBarThickness; } else { x1 = mBarThickness; y1 = (mBarLength + mBarPointerHaloRadius); } Color.colorToHSV(color, mHSVColor); shader = new LinearGradient( mBarPointerHaloRadius, 0, x1, y1, new int[] {0xffffffff, color, 0xff000000}, null, Shader.TileMode.CLAMP); mBarPaint.setShader(shader); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); if (mPicker.hasOpacityBar()) mPicker.changeOpacityBarColor(mColor); } invalidate(); }
/** * Set the pointer on the bar. With the saturation value. * * @param saturation float between 0 > 1 */ public void setSaturation(float saturation) { mBarPointerPosition = Math.round((mSVToPosFactor * saturation) + mBarPointerHaloRadius); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); // Check whether the Saturation/Value bar is added to the ColorPicker // wheel if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); } invalidate(); }
public ColorPickerDialog(Context context, String color, OnColorChangedListener listener) { super(context); mColorChangedListener = listener; View view = LayoutInflater.from(context).inflate(R.layout.color_picker_dialog, null); mColorPicker = (ColorPicker) view.findViewById(R.id.color_picker); mColorPicker.addSVBar((SVBar) view.findViewById(R.id.svbar)); setColor(color); setView(view); setButton( BUTTON_POSITIVE, context.getString(R.string.ok), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mColorChangedListener != null) { int colorValue = mColorPicker.getColor(); String color = String.format( Locale.US, "%02x%02x%02x", Color.red(colorValue), Color.green(colorValue), Color.blue(colorValue)); mColorChangedListener.colorChanged(color); } } }); setButton(BUTTON_NEGATIVE, context.getString(R.string.cancel), (OnClickListener) null); }
/** * Set the pointer on the bar. With the opacity value. * * @param opacity float between 0 and 255 */ public void setOpacity(int opacity) { mBarPointerPosition = Math.round((mOpacToPosFactor * opacity)) + mBarPointerHaloRadius; calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); }
@Override protected View onCreateDialogView() { View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_colorpicker, null); mColorPickerView = (ColorPicker) view.findViewById(R.id.pk_colorPicker); OpacityBar mOpacityBar = (OpacityBar) view.findViewById(R.id.pk_opacityBar); SVBar svBar = (SVBar) view.findViewById(R.id.pk_svBar); mOpacityBar.setColorPicker(mColorPickerView); svBar.setColorPicker(mColorPickerView); mColorPickerView.addOpacityBar(mOpacityBar); mColorPickerView.addSVBar(svBar); mOpacityBar.setVisibility(mAlphaAllowed ? View.VISIBLE : View.GONE); svBar.setVisibility(mSVAllowed ? View.VISIBLE : View.GONE); return view; }
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(); }
@Override public boolean onTouchEvent(MotionEvent event) { getParent().requestDisallowInterceptTouchEvent(true); // Convert coordinates to our internal coordinate system float dimen; if (mOrientation == ORIENTATION_HORIZONTAL) { dimen = event.getX(); } else { dimen = event.getY(); } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mIsMovingPointer = true; // Check whether the user pressed on (or near) the pointer if (dimen >= (mBarPointerHaloRadius) && dimen <= (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); invalidate(); } break; case MotionEvent.ACTION_MOVE: if (mIsMovingPointer) { // Move the the pointer on the bar. if (dimen >= mBarPointerHaloRadius && dimen <= (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } else if (dimen < mBarPointerHaloRadius) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.TRANSPARENT; mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } else if (dimen > (mBarPointerHaloRadius + mBarLength)) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.HSVToColor(mHSVColor); mBarPointerPaint.setColor(mColor); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } invalidate(); } } if (onOpacityChangedListener != null && oldChangedListenerOpacity != getOpacity()) { onOpacityChangedListener.onOpacityChanged(getOpacity()); oldChangedListenerOpacity = getOpacity(); } break; case MotionEvent.ACTION_UP: mIsMovingPointer = false; break; } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.themechooser); // Google Analytics // Get a Tracker (should auto-report) ((Frontend) getApplication()).getTracker(Frontend.TrackerName.APP_TRACKER); int int_color = Color.parseColor("#222222"); int ab_theme = PreferenceManager.getDefaultSharedPreferences(this).getInt("ab_theme", int_color); ActionBar ab = getActionBar(); ab.setSubtitle("Theme Chooser"); ab.setBackgroundDrawable(new ColorDrawable(ab_theme)); ab.setDisplayHomeAsUpEnabled(true); final TextView tv1 = (TextView) findViewById(R.id.textView1); tv1.setText("Sample"); tv1.setTextSize(50); final ColorPicker picker = (ColorPicker) findViewById(R.id.picker); SVBar svBar = (SVBar) findViewById(R.id.svbar); OpacityBar opacityBar = (OpacityBar) findViewById(R.id.opacitybar); picker.addSVBar(svBar); picker.addOpacityBar(opacityBar); // To get color picker.getColor(); // To apply previously selected color picker.setShowOldCenterColor(true); // Intent listener final boolean ab_intent = getIntent().getExtras().getBoolean("ab_theme"); final boolean text_intent = getIntent().getExtras().getBoolean("text_theme"); final boolean poppy_intent = getIntent().getExtras().getBoolean("poppy_theme"); final boolean nav_intent = getIntent().getExtras().getBoolean("nav_theme"); // Applying previously selected color // Action bar if (ab_intent) { ab.setTitle("Action Bar"); int ab_def_color = Color.parseColor("#222222"); int ab_color = PreferenceManager.getDefaultSharedPreferences(this).getInt("ab_theme", ab_def_color); picker.setOldCenterColor(ab_color); picker.setColor(ab_color); tv1.setTextColor(ab_color); } // Poppy bar if (poppy_intent) { ab.setTitle("Poppy Bar"); int poppy_def_color = Color.parseColor("#222222"); int poppy_color = PreferenceManager.getDefaultSharedPreferences(this) .getInt("poppy_theme", poppy_def_color); picker.setOldCenterColor(poppy_color); picker.setColor(poppy_color); tv1.setTextColor(poppy_color); } // Text color if (text_intent) { ab.setTitle("Lyrics Text"); int text_def_color = Color.parseColor("#222222"); int text_color = PreferenceManager.getDefaultSharedPreferences(this).getInt("text_theme", text_def_color); picker.setOldCenterColor(text_color); picker.setColor(text_color); tv1.setTextColor(text_color); } // Navigation drawer if (nav_intent) { ab.setTitle("Navigation Drawer"); int nav_def_color = Color.parseColor("#222222"); int nav_color = PreferenceManager.getDefaultSharedPreferences(this).getInt("nav_theme", nav_def_color); picker.setOldCenterColor(nav_color); picker.setColor(nav_color); tv1.setTextColor(nav_color); } // Hint colors ImageButton ib1 = (ImageButton) findViewById(R.id.imageButton1); ImageButton ib2 = (ImageButton) findViewById(R.id.imageButton2); ImageButton ib3 = (ImageButton) findViewById(R.id.imageButton3); ImageButton ib4 = (ImageButton) findViewById(R.id.imageButton4); ImageButton ib5 = (ImageButton) findViewById(R.id.imageButton5); // Hint color click listeners ib1.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub // int darksky = Color.parseColor("#464ea3"); picker.setColor(-12165121); } }); ib2.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int frooti = Color.parseColor("#fbba00"); picker.setColor(frooti); } }); ib3.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int lavender = Color.parseColor("#92278f"); picker.setColor(lavender); } }); ib4.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int lime = Color.parseColor("#669002"); picker.setColor(lime); } }); ib5.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // int mojo = Color.parseColor("#c84741"); picker.setColor(-42415); } }); picker.setOnColorChangedListener( new OnColorChangedListener() { @Override public void onColorChanged(final int color) { // TODO Auto-generated method stub tv1.setTextColor(color); Button b = (Button) findViewById(R.id.button1); b.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if (ab_intent) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ThemeChooser.this); sp.edit().putInt("ab_theme", color).commit(); Toast.makeText(ThemeChooser.this, "Applied", Toast.LENGTH_LONG).show(); // System.exit(0); onBackPressed(); } if (text_intent) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ThemeChooser.this); sp.edit().putInt("text_theme", color).commit(); Toast.makeText(ThemeChooser.this, "Applied", Toast.LENGTH_LONG).show(); // System.exit(0); onBackPressed(); } if (poppy_intent) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ThemeChooser.this); sp.edit().putInt("poppy_theme", color).commit(); Toast.makeText(ThemeChooser.this, "Applied", Toast.LENGTH_LONG).show(); // System.exit(0); onBackPressed(); } if (nav_intent) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ThemeChooser.this); sp.edit().putInt("nav_theme", color).commit(); Toast.makeText(ThemeChooser.this, "Applied", Toast.LENGTH_LONG).show(); // System.exit(0); onBackPressed(); } } }); } }); }
@Override public void onClickPositive() { float alpha = picker.getAlpha(); String hexColor = ColorUtil.getHex(picker.getColor()); Project4App.getApp(context).setEditProjectColorString(hexColor); }
@Override protected void onDialogClosed(boolean positiveResult) { if (positiveResult) setNewValue(mColorPickerView.getColor()); }
@Override protected void onBindDialogView(View view) { super.onBindDialogView(view); mColorPickerView.setOldCenterColor(mValue); mColorPickerView.setColor(mValue); }
/** * Set the color the color picker should highlight as selected color. * * @param color The RGB value of a color */ public void setColor(String color) { int colorValue = Color.parseColor("#" + color); mColorPicker.setColor(colorValue); mColorPicker.setOldCenterColor(colorValue); }