1 package mhr.appandroid.views.colorpicker;
3 import mhr.appandroid.R;
4 import mhr.appandroid.views.colorpicker.SVPickerView.OnSVPickerChangeListener;
5 import android.app.Activity;
6 import android.content.Context;
7 import android.graphics.Color;
8 import android.graphics.LinearGradient;
9 import android.graphics.Paint;
10 import android.graphics.Paint.Style;
11 import android.graphics.Path;
12 import android.graphics.Shader;
13 import android.graphics.Shader.TileMode;
14 import android.graphics.drawable.Drawable;
15 import android.graphics.drawable.GradientDrawable;
16 import android.graphics.drawable.ScaleDrawable;
17 import android.graphics.drawable.ShapeDrawable;
18 import android.graphics.drawable.GradientDrawable.Orientation;
19 import android.graphics.drawable.shapes.PathShape;
20 import android.graphics.drawable.shapes.RectShape;
21 import android.os.Bundle;
22 import android.os.Parcelable;
23 import android.util.AttributeSet;
24 import android.view.View;
25 import android.widget.Button;
26 import android.widget.FrameLayout;
27 import android.widget.SeekBar;
28 import android.widget.SeekBar.OnSeekBarChangeListener;
29 import android.widget.TextView;
30 import android.widget.Toast;
31 import android.view.View.OnClickListener;
106 protected float[]
tmp =
new float[3];
192 overlay.setVisibility(VISIBLE);
210 Path pth =
new Path();
213 ShapeDrawable sdr =
new ShapeDrawable(
new PathShape(pth, 100, 100));
214 Paint paint = sdr.getPaint();
215 paint.setStyle(Style.STROKE);
216 paint.setStrokeWidth(20);
217 sb.setProgressDrawable(sdr);
229 return 0xFF000000 | (b << 16) | (g << 8) | r;
239 return 0xFF000000 | ((clr & 0x000000FF) << 16) | (clr & 0x0000FF00) | ((clr & 0x00FF0000) >> 16);
249 return 0xFF000000 | ((nativeClr & 0x000000FF) << 16) | (nativeClr & 0x0000FF00) | ((nativeClr & 0x00FF0000) >> 16);
258 ((ShapeDrawable) sb.getProgressDrawable()).getPaint().setShader(
new LinearGradient(0, 0, 100, 0, colors, null, TileMode.CLAMP));
269 return Color.HSVToColor(
tmp);
280 return Color.HSVToColor(
tmp);
291 return Color.HSVToColor(
tmp);
299 int[] retVal =
new int[7];
305 retVal[0] = Color.HSVToColor(
tmp);
308 retVal[1] = Color.HSVToColor(
tmp);
311 retVal[2] = Color.HSVToColor(
tmp);
314 retVal[3] = Color.HSVToColor(
tmp);
317 retVal[4] = Color.HSVToColor(
tmp);
320 retVal[5] = Color.HSVToColor(
tmp);
323 retVal[6] = Color.HSVToColor(
tmp);
335 super(context, attrs);
340 super(context, attrs, defStyle);
348 if (isInEditMode()) {
349 TextView tv =
new TextView(getContext());
350 tv.setText(
"ColorPickerView, preview not availiable.");
355 ((Activity) getContext()).getLayoutInflater().inflate(
R.layout.view_color_picker,
this,
true);
356 }
catch (ClassCastException exc) {
358 TextView tv =
new TextView(getContext());
359 tv.setText(
"Prewiew not available, requires Activity to be Context.");
365 redValueSB = (SeekBar) findViewById(
R.id.RedValueSB);
368 hueValueSB = (SeekBar) findViewById(
R.id.HueValueSB);
372 redValueTV = (TextView) findViewById(
R.id.RedValueTV);
374 blueValueTV = (TextView) findViewById(
R.id.BlueValueTV);
375 hueValueTV = (TextView) findViewById(
R.id.HueValueTV);
380 selectBtn = (Button) findViewById(
R.id.SelectColorBtn);
381 cancelBtn = (Button) findViewById(
R.id.CancelColorBtn);
382 overlay = findViewById(
R.id.ColorPickerDisabledOverlay);
411 if (state instanceof Bundle) {
412 Bundle bundle = (Bundle) state;
415 super.onRestoreInstanceState(bundle.getParcelable(
"instanceState"));
419 super.onRestoreInstanceState(state);
425 Bundle bundle =
new Bundle();
426 bundle.putParcelable(
"instanceState", super.onSaveInstanceState());
427 bundle.putInt(
"newColor",
newColor);
428 bundle.putInt(
"oldColor",
oldColor);
450 newColor = 0xFF000000 | (r << 16) | (g << 8) | b;
475 protected void setColor(
float h,
float s,
float v) {