@ -22,12 +22,12 @@ import android.graphics.Color;
@@ -22,12 +22,12 @@ import android.graphics.Color;
import android.graphics.ComposeShader ;
import android.graphics.LinearGradient ;
import android.graphics.Paint ;
import android.graphics.Paint.Align ;
import android.graphics.Paint.Style ;
import android.graphics.Point ;
import android.graphics.PorterDuff ;
import android.graphics.RectF ;
import android.graphics.Shader ;
import android.graphics.Paint.Align ;
import android.graphics.Paint.Style ;
import android.graphics.Shader.TileMode ;
import android.util.AttributeSet ;
import android.view.MotionEvent ;
@ -42,103 +42,103 @@ import android.view.View;
@@ -42,103 +42,103 @@ import android.view.View;
* /
public class ColorPickerView extends View {
private final static int PANEL_SAT_VAL = 0 ;
private final static int PANEL_HUE = 1 ;
private final static int PANEL_ALPHA = 2 ;
private final static int PANEL_SAT_VAL = 0 ;
private final static int PANEL_HUE = 1 ;
private final static int PANEL_ALPHA = 2 ;
/ * *
* The width in pixels of the border
* surrounding all color panels .
* /
private final static float BORDER_WIDTH_PX = 1 ;
private final static float BORDER_WIDTH_PX = 1 ;
/ * *
* The width in dp of the hue panel .
* /
private float HUE_PANEL_WIDTH = 30f ;
private float HUE_PANEL_WIDTH = 30f ;
/ * *
* The height in dp of the alpha panel
* /
private float ALPHA_PANEL_HEIGHT = 20f ;
private float ALPHA_PANEL_HEIGHT = 20f ;
/ * *
* The distance in dp between the different
* color panels .
* /
private float PANEL_SPACING = 10f ;
private float PANEL_SPACING = 10f ;
/ * *
* The radius in dp of the color palette tracker circle .
* /
private float PALETTE_CIRCLE_TRACKER_RADIUS = 5f ;
private float PALETTE_CIRCLE_TRACKER_RADIUS = 5f ;
/ * *
* The dp which the tracker of the hue or alpha panel
* will extend outside of its bounds .
* /
private float RECTANGLE_TRACKER_OFFSET = 2f ;
private float RECTANGLE_TRACKER_OFFSET = 2f ;
private float mDensity = 1f ;
private float mDensity = 1f ;
private OnColorChangedListener mListener ;
private OnColorChangedListener mListener ;
private Paint mSatValPaint ;
private Paint mSatValTrackerPaint ;
private Paint mSatValPaint ;
private Paint mSatValTrackerPaint ;
private Paint mHuePaint ;
private Paint mHueTrackerPaint ;
private Paint mHuePaint ;
private Paint mHueTrackerPaint ;
private Paint mAlphaPaint ;
private Paint mAlphaTextPaint ;
private Paint mAlphaPaint ;
private Paint mAlphaTextPaint ;
private Paint mBorderPaint ;
private Paint mBorderPaint ;
private Shader mValShader ;
private Shader mSatShader ;
private Shader mHueShader ;
private Shader mAlphaShader ;
private Shader mValShader ;
private Shader mSatShader ;
private Shader mHueShader ;
private Shader mAlphaShader ;
private int mAlpha = 0xff ;
private float mHue = 360f ;
private float mSat = 0f ;
private float mVal = 0f ;
private int mAlpha = 0xff ;
private float mHue = 360f ;
private float mSat = 0f ;
private float mVal = 0f ;
private String mAlphaSliderText = "" ;
private int mSliderTrackerColor = 0xff1c1c1c ;
private int mBorderColor = 0xff6E6E6E ;
private boolean mShowAlphaPanel = false ;
private String mAlphaSliderText = "" ;
private int mSliderTrackerColor = 0xff1c1c1c ;
private int mBorderColor = 0xff6E6E6E ;
private boolean mShowAlphaPanel = false ;
/ *
* To remember which panel that has the "focus" when
* processing hardware button data .
* /
private int mLastTouchedPanel = PANEL_SAT_VAL ;
private int mLastTouchedPanel = PANEL_SAT_VAL ;
/ * *
* Offset from the edge we must have or else
* the finger tracker will get clipped when
* it is drawn outside of the view .
* /
private float mDrawingOffset ;
private float mDrawingOffset ;
/ *
* Distance form the edges of the view
* of where we are allowed to draw .
* /
private RectF mDrawingRect ;
private RectF mDrawingRect ;
private RectF mSatValRect ;
private RectF mHueRect ;
private RectF mAlphaRect ;
private RectF mSatValRect ;
private RectF mHueRect ;
private RectF mAlphaRect ;
private AlphaPatternDrawable mAlphaPattern ;
private AlphaPatternDrawable mAlphaPattern ;
private Point mStartTouchPoint = null ;
private Point mStartTouchPoint = null ;
public interface OnColorChangedListener {
public void onColorChanged ( int color ) ;
}
public ColorPickerView ( Context context ) {
public ColorPickerView ( Context context ) {
this ( context , null ) ;
}
@ -151,7 +151,7 @@ public class ColorPickerView extends View {
@@ -151,7 +151,7 @@ public class ColorPickerView extends View {
init ( ) ;
}
private void init ( ) {
private void init ( ) {
mDensity = getContext ( ) . getResources ( ) . getDisplayMetrics ( ) . density ;
PALETTE_CIRCLE_TRACKER_RADIUS * = mDensity ;
RECTANGLE_TRACKER_OFFSET * = mDensity ;
@ -168,7 +168,7 @@ public class ColorPickerView extends View {
@@ -168,7 +168,7 @@ public class ColorPickerView extends View {
setFocusableInTouchMode ( true ) ;
}
private void initPaintTools ( ) {
private void initPaintTools ( ) {
mSatValPaint = new Paint ( ) ;
mSatValTrackerPaint = new Paint ( ) ;
@ -197,19 +197,19 @@ public class ColorPickerView extends View {
@@ -197,19 +197,19 @@ public class ColorPickerView extends View {
}
private float calculateRequiredOffset ( ) {
private float calculateRequiredOffset ( ) {
float offset = Math . max ( PALETTE_CIRCLE_TRACKER_RADIUS , RECTANGLE_TRACKER_OFFSET ) ;
offset = Math . max ( offset , BORDER_WIDTH_PX * mDensity ) ;
return offset * 1 . 5f ;
}
private int [ ] buildHueColorArray ( ) {
private int [ ] buildHueColorArray ( ) {
int [ ] hue = new int [ 361 ] ;
int count = 0 ;
for ( int i = hue . length - 1 ; i > = 0 ; i - - , count + + ) {
for ( int i = hue . length - 1 ; i > = 0 ; i - - , count + + ) {
hue [ count ] = Color . HSVToColor ( new float [ ] { i , 1f , 1f } ) ;
}
@ -220,7 +220,9 @@ public class ColorPickerView extends View {
@@ -220,7 +220,9 @@ public class ColorPickerView extends View {
@Override
protected void onDraw ( Canvas canvas ) {
if ( mDrawingRect . width ( ) < = 0 | | mDrawingRect . height ( ) < = 0 ) return ;
if ( mDrawingRect . width ( ) < = 0 | | mDrawingRect . height ( ) < = 0 ) {
return ;
}
drawSatValPanel ( canvas ) ;
drawHuePanel ( canvas ) ;
@ -228,24 +230,24 @@ public class ColorPickerView extends View {
@@ -228,24 +230,24 @@ public class ColorPickerView extends View {
}
private void drawSatValPanel ( Canvas canvas ) {
private void drawSatValPanel ( Canvas canvas ) {
final RectF rect = mSatValRect ;
final RectF rect = mSatValRect ;
if ( BORDER_WIDTH_PX > 0 ) {
if ( BORDER_WIDTH_PX > 0 ) {
mBorderPaint . setColor ( mBorderColor ) ;
canvas . drawRect ( mDrawingRect . left , mDrawingRect . top , rect . right + BORDER_WIDTH_PX , rect . bottom + BORDER_WIDTH_PX , mBorderPaint ) ;
canvas . drawRect ( mDrawingRect . left , mDrawingRect . top , rect . right + BORDER_WIDTH_PX ,
rect . bottom + BORDER_WIDTH_PX , mBorderPaint ) ;
}
if ( mValShader = = null ) {
mValShader = new LinearGradient ( rect . left , rect . top , rect . left , rect . bottom ,
0xffffffff , 0xff000000 , TileMode . CLAMP ) ;
mValShader = new LinearGradient ( rect . left , rect . top , rect . left , rect . bottom , 0xffffffff , 0xff000000 ,
TileMode . CLAMP ) ;
}
int rgb = Color . HSVToColor ( new float [ ] { mHue , 1f , 1f } ) ;
int rgb = Color . HSVToColor ( new float [ ] { mHue , 1f , 1f } ) ;
mSatShader = new LinearGradient ( rect . left , rect . top , rect . right , rect . top ,
0xffffffff , rgb , TileMode . CLAMP ) ;
mSatShader = new LinearGradient ( rect . left , rect . top , rect . right , rect . top , 0xffffffff , rgb , TileMode . CLAMP ) ;
ComposeShader mShader = new ComposeShader ( mValShader , mSatShader , PorterDuff . Mode . MULTIPLY ) ;
mSatValPaint . setShader ( mShader ) ;
@ -261,21 +263,19 @@ public class ColorPickerView extends View {
@@ -261,21 +263,19 @@ public class ColorPickerView extends View {
}
private void drawHuePanel ( Canvas canvas ) {
private void drawHuePanel ( Canvas canvas ) {
final RectF rect = mHueRect ;
if ( BORDER_WIDTH_PX > 0 ) {
if ( BORDER_WIDTH_PX > 0 ) {
mBorderPaint . setColor ( mBorderColor ) ;
canvas . drawRect ( rect . left - BORDER_WIDTH_PX ,
rect . top - BORDER_WIDTH_PX ,
rect . right + BORDER_WIDTH_PX ,
rect . bottom + BORDER_WIDTH_PX ,
mBorderPaint ) ;
canvas . drawRect ( rect . left - BORDER_WIDTH_PX , rect . top - BORDER_WIDTH_PX , rect . right + BORDER_WIDTH_PX ,
rect . bottom + BORDER_WIDTH_PX , mBorderPaint ) ;
}
if ( mHueShader = = null ) {
mHueShader = new LinearGradient ( rect . left , rect . top , rect . left , rect . bottom , buildHueColorArray ( ) , null , TileMode . CLAMP ) ;
mHueShader = new LinearGradient ( rect . left , rect . top , rect . left , rect . bottom , buildHueColorArray ( ) , null ,
TileMode . CLAMP ) ;
mHuePaint . setShader ( mHueShader ) ;
}
@ -296,37 +296,35 @@ public class ColorPickerView extends View {
@@ -296,37 +296,35 @@ public class ColorPickerView extends View {
}
private void drawAlphaPanel ( Canvas canvas ) {
private void drawAlphaPanel ( Canvas canvas ) {
if ( ! mShowAlphaPanel | | mAlphaRect = = null | | mAlphaPattern = = null ) return ;
if ( ! mShowAlphaPanel | | mAlphaRect = = null | | mAlphaPattern = = null ) {
return ;
}
final RectF rect = mAlphaRect ;
if ( BORDER_WIDTH_PX > 0 ) {
if ( BORDER_WIDTH_PX > 0 ) {
mBorderPaint . setColor ( mBorderColor ) ;
canvas . drawRect ( rect . left - BORDER_WIDTH_PX ,
rect . top - BORDER_WIDTH_PX ,
rect . right + BORDER_WIDTH_PX ,
rect . bottom + BORDER_WIDTH_PX ,
mBorderPaint ) ;
canvas . drawRect ( rect . left - BORDER_WIDTH_PX , rect . top - BORDER_WIDTH_PX , rect . right + BORDER_WIDTH_PX ,
rect . bottom + BORDER_WIDTH_PX , mBorderPaint ) ;
}
mAlphaPattern . draw ( canvas ) ;
float [ ] hsv = new float [ ] { mHue , mSat , mVal } ;
float [ ] hsv = new float [ ] { mHue , mSat , mVal } ;
int color = Color . HSVToColor ( hsv ) ;
int acolor = Color . HSVToColor ( 0 , hsv ) ;
mAlphaShader = new LinearGradient ( rect . left , rect . top , rect . right , rect . top ,
color , acolor , TileMode . CLAMP ) ;
mAlphaShader = new LinearGradient ( rect . left , rect . top , rect . right , rect . top , color , acolor , TileMode . CLAMP ) ;
mAlphaPaint . setShader ( mAlphaShader ) ;
canvas . drawRect ( rect , mAlphaPaint ) ;
if ( mAlphaSliderText ! = null & & mAlphaSliderText ! = "" ) {
if ( mAlphaSliderText ! = null & & mAlphaSliderText ! = "" ) {
canvas . drawText ( mAlphaSliderText , rect . centerX ( ) , rect . centerY ( ) + 4 * mDensity , mAlphaTextPaint ) ;
}
@ -345,7 +343,7 @@ public class ColorPickerView extends View {
@@ -345,7 +343,7 @@ public class ColorPickerView extends View {
}
private Point hueToPoint ( float hue ) {
private Point hueToPoint ( float hue ) {
final RectF rect = mHueRect ;
final float height = rect . height ( ) ;
@ -358,7 +356,7 @@ public class ColorPickerView extends View {
@@ -358,7 +356,7 @@ public class ColorPickerView extends View {
return p ;
}
private Point satValToPoint ( float sat , float val ) {
private Point satValToPoint ( float sat , float val ) {
final RectF rect = mSatValRect ;
final float height = rect . height ( ) ;
@ -372,7 +370,7 @@ public class ColorPickerView extends View {
@@ -372,7 +370,7 @@ public class ColorPickerView extends View {
return p ;
}
private Point alphaToPoint ( int alpha ) {
private Point alphaToPoint ( int alpha ) {
final RectF rect = mAlphaRect ;
final float width = rect . width ( ) ;
@ -386,7 +384,7 @@ public class ColorPickerView extends View {
@@ -386,7 +384,7 @@ public class ColorPickerView extends View {
}
private float [ ] pointToSatVal ( float x , float y ) {
private float [ ] pointToSatVal ( float x , float y ) {
final RectF rect = mSatValRect ;
float [ ] result = new float [ 2 ] ;
@ -394,23 +392,19 @@ public class ColorPickerView extends View {
@@ -394,23 +392,19 @@ public class ColorPickerView extends View {
float width = rect . width ( ) ;
float height = rect . height ( ) ;
if ( x < rect . left ) {
if ( x < rect . left ) {
x = 0f ;
}
else if ( x > rect . right ) {
} else if ( x > rect . right ) {
x = width ;
}
else {
} else {
x = x - rect . left ;
}
if ( y < rect . top ) {
if ( y < rect . top ) {
y = 0f ;
}
else if ( y > rect . bottom ) {
} else if ( y > rect . bottom ) {
y = height ;
}
else {
} else {
y = y - rect . top ;
}
@ -421,38 +415,34 @@ public class ColorPickerView extends View {
@@ -421,38 +415,34 @@ public class ColorPickerView extends View {
return result ;
}
private float pointToHue ( float y ) {
private float pointToHue ( float y ) {
final RectF rect = mHueRect ;
float height = rect . height ( ) ;
if ( y < rect . top ) {
if ( y < rect . top ) {
y = 0f ;
}
else if ( y > rect . bottom ) {
} else if ( y > rect . bottom ) {
y = height ;
}
else {
} else {
y = y - rect . top ;
}
return 360f - ( y * 360f / height ) ;
}
private int pointToAlpha ( int x ) {
private int pointToAlpha ( int x ) {
final RectF rect = mAlphaRect ;
final int width = ( int ) rect . width ( ) ;
if ( x < rect . left ) {
if ( x < rect . left ) {
x = 0 ;
}
else if ( x > rect . right ) {
} else if ( x > rect . right ) {
x = width ;
}
else {
x = x - ( int ) rect . left ;
} else {
x = x - ( int ) rect . left ;
}
return 0xff - ( x * 0xff / width ) ;
@ -469,87 +459,82 @@ public class ColorPickerView extends View {
@@ -469,87 +459,82 @@ public class ColorPickerView extends View {
boolean update = false ;
if ( event . getAction ( ) = = MotionEvent . ACTION_MOVE ) {
if ( event . getAction ( ) = = MotionEvent . ACTION_MOVE ) {
switch ( mLastTouchedPanel ) {
switch ( mLastTouchedPanel ) {
case PANEL_SAT_VAL :
case PANEL_SAT_VAL :
float sat , val ;
float sat , val ;
sat = mSat + x / 50f ;
val = mVal - y / 50f ;
sat = mSat + x / 50f ;
val = mVal - y / 50f ;
if ( sat < 0f ) {
sat = 0f ;
}
else if ( sat > 1f ) {
sat = 1f ;
}
if ( sat < 0f ) {
sat = 0f ;
} else if ( sat > 1f ) {
sat = 1f ;
}
if ( val < 0f ) {
val = 0f ;
}
else if ( val > 1f ) {
val = 1f ;
}
if ( val < 0f ) {
val = 0f ;
} else if ( val > 1f ) {
val = 1f ;
}
mSat = sat ;
mVal = val ;
mSat = sat ;
mVal = val ;
update = true ;
update = true ;
break ;
break ;
case PANEL_HUE :
case PANEL_HUE :
float hue = mHue - y * 10f ;
float hue = mHue - y * 10f ;
if ( hue < 0f ) {
hue = 0f ;
}
else if ( hue > 360f ) {
hue = 360f ;
}
if ( hue < 0f ) {
hue = 0f ;
} else if ( hue > 360f ) {
hue = 360f ;
}
mHue = hue ;
mHue = hue ;
update = true ;
update = true ;
break ;
break ;
case PANEL_ALPHA :
case PANEL_ALPHA :
if ( ! mShowAlphaPanel | | mAlphaRect = = null ) {
update = false ;
}
else {
if ( ! mShowAlphaPanel | | mAlphaRect = = null ) {
update = false ;
} else {
int alpha = ( int ) ( mAlpha - x * 10 ) ;
int alpha = ( int ) ( mAlpha - x * 10 ) ;
if ( alpha < 0 ) {
alpha = 0 ;
}
else if ( alpha > 0xff ) {
alpha = 0xff ;
}
if ( alpha < 0 ) {
alpha = 0 ;
} else if ( alpha > 0xff ) {
alpha = 0xff ;
}
mAlpha = alpha ;
mAlpha = alpha ;
update = true ;
}
update = true ;
}
break ;
break ;
}
}
if ( update ) {
if ( update ) {
if ( mListener ! = null ) {
if ( mListener ! = null ) {
mListener . onColorChanged ( Color . HSVToColor ( mAlpha , new float [ ] { mHue , mSat , mVal } ) ) ;
}
@ -566,35 +551,35 @@ public class ColorPickerView extends View {
@@ -566,35 +551,35 @@ public class ColorPickerView extends View {
boolean update = false ;
switch ( event . getAction ( ) ) {
switch ( event . getAction ( ) ) {
case MotionEvent . ACTION_DOWN :
case MotionEvent . ACTION_DOWN :
mStartTouchPoint = new Point ( ( int ) event . getX ( ) , ( int ) event . getY ( ) ) ;
mStartTouchPoint = new Point ( ( int ) event . getX ( ) , ( int ) event . getY ( ) ) ;
update = moveTrackersIfNeeded ( event ) ;
update = moveTrackersIfNeeded ( event ) ;
break ;
break ;
case MotionEvent . ACTION_MOVE :
case MotionEvent . ACTION_MOVE :
update = moveTrackersIfNeeded ( event ) ;
update = moveTrackersIfNeeded ( event ) ;
break ;
break ;
case MotionEvent . ACTION_UP :
case MotionEvent . ACTION_UP :
mStartTouchPoint = null ;
mStartTouchPoint = null ;
update = moveTrackersIfNeeded ( event ) ;
update = moveTrackersIfNeeded ( event ) ;
break ;
break ;
}
if ( update ) {
if ( update ) {
if ( mListener ! = null ) {
if ( mListener ! = null ) {
mListener . onColorChanged ( Color . HSVToColor ( mAlpha , new float [ ] { mHue , mSat , mVal } ) ) ;
}
@ -606,9 +591,11 @@ public class ColorPickerView extends View {
@@ -606,9 +591,11 @@ public class ColorPickerView extends View {
return super . onTouchEvent ( event ) ;
}
private boolean moveTrackersIfNeeded ( MotionEvent event ) {
private boolean moveTrackersIfNeeded ( MotionEvent event ) {
if ( mStartTouchPoint = = null ) return false ;
if ( mStartTouchPoint = = null ) {
return false ;
}
boolean update = false ;
@ -616,14 +603,13 @@ public class ColorPickerView extends View {
@@ -616,14 +603,13 @@ public class ColorPickerView extends View {
int startY = mStartTouchPoint . y ;
if ( mHueRect . contains ( startX , startY ) ) {
if ( mHueRect . contains ( startX , startY ) ) {
mLastTouchedPanel = PANEL_HUE ;
mHue = pointToHue ( event . getY ( ) ) ;
update = true ;
}
else if ( mSatValRect . contains ( startX , startY ) ) {
} else if ( mSatValRect . contains ( startX , startY ) ) {
mLastTouchedPanel = PANEL_SAT_VAL ;
@ -633,12 +619,11 @@ public class ColorPickerView extends View {
@@ -633,12 +619,11 @@ public class ColorPickerView extends View {
mVal = result [ 1 ] ;
update = true ;
}
else if ( mAlphaRect ! = null & & mAlphaRect . contains ( startX , startY ) ) {
} else if ( mAlphaRect ! = null & & mAlphaRect . contains ( startX , startY ) ) {
mLastTouchedPanel = PANEL_ALPHA ;
mAlpha = pointToAlpha ( ( int ) event . getX ( ) ) ;
mAlpha = pointToAlpha ( ( int ) event . getX ( ) ) ;
update = true ;
}
@ -662,28 +647,25 @@ public class ColorPickerView extends View {
@@ -662,28 +647,25 @@ public class ColorPickerView extends View {
widthAllowed = chooseWidth ( widthMode , widthAllowed ) ;
heightAllowed = chooseHeight ( heightMode , heightAllowed ) ;
if ( ! mShowAlphaPanel ) {
if ( ! mShowAlphaPanel ) {
height = ( int ) ( widthAllowed - PANEL_SPACING - HUE_PANEL_WIDTH ) ;
//If calculated height (based on the width) is more than the allowed height.
if ( height > heightAllowed | | getTag ( ) . equals ( "landscape" ) ) {
if ( height > heightAllowed | | getTag ( ) . equals ( "landscape" ) ) {
height = heightAllowed ;
width = ( int ) ( height + PANEL_SPACING + HUE_PANEL_WIDTH ) ;
}
else {
} else {
width = widthAllowed ;
}
}
else {
} else {
width = ( int ) ( heightAllowed - ALPHA_PANEL_HEIGHT + HUE_PANEL_WIDTH ) ;
if ( width > widthAllowed ) {
if ( width > widthAllowed ) {
width = widthAllowed ;
height = ( int ) ( widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT ) ;
}
else {
} else {
height = heightAllowed ;
}
@ -692,7 +674,7 @@ public class ColorPickerView extends View {
@@ -692,7 +674,7 @@ public class ColorPickerView extends View {
setMeasuredDimension ( width , height ) ;
}
private int chooseWidth ( int mode , int size ) {
private int chooseWidth ( int mode , int size ) {
if ( mode = = MeasureSpec . AT_MOST | | mode = = MeasureSpec . EXACTLY ) {
return size ;
} else { // (mode == MeasureSpec.UNSPECIFIED)
@ -700,7 +682,7 @@ public class ColorPickerView extends View {
@@ -700,7 +682,7 @@ public class ColorPickerView extends View {
}
}
private int chooseHeight ( int mode , int size ) {
private int chooseHeight ( int mode , int size ) {
if ( mode = = MeasureSpec . AT_MOST | | mode = = MeasureSpec . EXACTLY ) {
return size ;
} else { // (mode == MeasureSpec.UNSPECIFIED)
@ -708,11 +690,11 @@ public class ColorPickerView extends View {
@@ -708,11 +690,11 @@ public class ColorPickerView extends View {
}
}
private int getPrefferedWidth ( ) {
private int getPrefferedWidth ( ) {
int width = getPrefferedHeight ( ) ;
if ( mShowAlphaPanel ) {
if ( mShowAlphaPanel ) {
width - = ( PANEL_SPACING + ALPHA_PANEL_HEIGHT ) ;
}
@ -721,11 +703,11 @@ public class ColorPickerView extends View {
@@ -721,11 +703,11 @@ public class ColorPickerView extends View {
}
private int getPrefferedHeight ( ) {
private int getPrefferedHeight ( ) {
int height = ( int ) ( 200 * mDensity ) ;
int height = ( int ) ( 200 * mDensity ) ;
if ( mShowAlphaPanel ) {
if ( mShowAlphaPanel ) {
height + = PANEL_SPACING + ALPHA_PANEL_HEIGHT ;
}
@ -733,14 +715,13 @@ public class ColorPickerView extends View {
@@ -733,14 +715,13 @@ public class ColorPickerView extends View {
}
@Override
protected void onSizeChanged ( int w , int h , int oldw , int oldh ) {
super . onSizeChanged ( w , h , oldw , oldh ) ;
mDrawingRect = new RectF ( ) ;
mDrawingRect . left = mDrawingOffset + getPaddingLeft ( ) ;
mDrawingRect . right = w - mDrawingOffset - getPaddingRight ( ) ;
mDrawingRect . right = w - mDrawingOffset - getPaddingRight ( ) ;
mDrawingRect . top = mDrawingOffset + getPaddingTop ( ) ;
mDrawingRect . bottom = h - mDrawingOffset - getPaddingBottom ( ) ;
@ -749,12 +730,12 @@ public class ColorPickerView extends View {
@@ -749,12 +730,12 @@ public class ColorPickerView extends View {
setUpAlphaRect ( ) ;
}
private void setUpSatValRect ( ) {
private void setUpSatValRect ( ) {
final RectF dRect = mDrawingRect ;
final RectF dRect = mDrawingRect ;
float panelSide = dRect . height ( ) - BORDER_WIDTH_PX * 2 ;
if ( mShowAlphaPanel ) {
if ( mShowAlphaPanel ) {
panelSide - = PANEL_SPACING + ALPHA_PANEL_HEIGHT ;
}
@ -763,11 +744,11 @@ public class ColorPickerView extends View {
@@ -763,11 +744,11 @@ public class ColorPickerView extends View {
float bottom = top + panelSide ;
float right = left + panelSide ;
mSatValRect = new RectF ( left , top , right , bottom ) ;
mSatValRect = new RectF ( left , top , right , bottom ) ;
}
private void setUpHueRect ( ) {
final RectF dRect = mDrawingRect ;
private void setUpHueRect ( ) {
final RectF dRect = mDrawingRect ;
float left = dRect . right - HUE_PANEL_WIDTH + BORDER_WIDTH_PX ;
float top = dRect . top + BORDER_WIDTH_PX ;
@ -779,9 +760,11 @@ public class ColorPickerView extends View {
@@ -779,9 +760,11 @@ public class ColorPickerView extends View {
private void setUpAlphaRect ( ) {
if ( ! mShowAlphaPanel ) return ;
if ( ! mShowAlphaPanel ) {
return ;
}
final RectF dRect = mDrawingRect ;
final RectF dRect = mDrawingRect ;
float left = dRect . left + BORDER_WIDTH_PX ;
float top = dRect . bottom - ALPHA_PANEL_HEIGHT + BORDER_WIDTH_PX ;
@ -791,12 +774,8 @@ public class ColorPickerView extends View {
@@ -791,12 +774,8 @@ public class ColorPickerView extends View {
mAlphaRect = new RectF ( left , top , right , bottom ) ;
mAlphaPattern = new AlphaPatternDrawable ( ( int ) ( 5 * mDensity ) ) ;
mAlphaPattern . setBounds (
Math . round ( mAlphaRect . left ) ,
Math . round ( mAlphaRect . top ) ,
Math . round ( mAlphaRect . right ) ,
Math . round ( mAlphaRect . bottom )
) ;
mAlphaPattern . setBounds ( Math . round ( mAlphaRect . left ) , Math . round ( mAlphaRect . top ) , Math . round ( mAlphaRect . right ) ,
Math . round ( mAlphaRect . bottom ) ) ;
}
@ -806,7 +785,7 @@ public class ColorPickerView extends View {
@@ -806,7 +785,7 @@ public class ColorPickerView extends View {
* selected by the user has changed .
* @param listener
* /
public void setOnColorChangedListener ( OnColorChangedListener listener ) {
public void setOnColorChangedListener ( OnColorChangedListener listener ) {
mListener = listener ;
}
@ -814,7 +793,7 @@ public class ColorPickerView extends View {
@@ -814,7 +793,7 @@ public class ColorPickerView extends View {
* Set the color of the border surrounding all panels .
* @param color
* /
public void setBorderColor ( int color ) {
public void setBorderColor ( int color ) {
mBorderColor = color ;
invalidate ( ) ;
}
@ -822,7 +801,7 @@ public class ColorPickerView extends View {
@@ -822,7 +801,7 @@ public class ColorPickerView extends View {
/ * *
* Get the color of the border surrounding all panels .
* /
public int getBorderColor ( ) {
public int getBorderColor ( ) {
return mBorderColor ;
}
@ -830,15 +809,15 @@ public class ColorPickerView extends View {
@@ -830,15 +809,15 @@ public class ColorPickerView extends View {
* Get the current color this view is showing .
* @return the current color .
* /
public int getColor ( ) {
return Color . HSVToColor ( mAlpha , new float [ ] { mHue , mSat , mVal } ) ;
public int getColor ( ) {
return Color . HSVToColor ( mAlpha , new float [ ] { mHue , mSat , mVal } ) ;
}
/ * *
* Set the color the view should show .
* @param color The color that should be selected .
* /
public void setColor ( int color ) {
public void setColor ( int color ) {
setColor ( color , false ) ;
}
@ -848,7 +827,7 @@ public class ColorPickerView extends View {
@@ -848,7 +827,7 @@ public class ColorPickerView extends View {
* @param callback If you want to get a callback to
* your OnColorChangedListener .
* /
public void setColor ( int color , boolean callback ) {
public void setColor ( int color , boolean callback ) {
int alpha = Color . alpha ( color ) ;
int red = Color . red ( color ) ;
@ -864,7 +843,7 @@ public class ColorPickerView extends View {
@@ -864,7 +843,7 @@ public class ColorPickerView extends View {
mSat = hsv [ 1 ] ;
mVal = hsv [ 2 ] ;
if ( callback & & mListener ! = null ) {
if ( callback & & mListener ! = null ) {
mListener . onColorChanged ( Color . HSVToColor ( mAlpha , new float [ ] { mHue , mSat , mVal } ) ) ;
}
@ -879,7 +858,7 @@ public class ColorPickerView extends View {
@@ -879,7 +858,7 @@ public class ColorPickerView extends View {
* the currently selected color and want to align it perfectly .
* @return The offset in pixels .
* /
public float getDrawingOffset ( ) {
public float getDrawingOffset ( ) {
return mDrawingOffset ;
}
@ -888,9 +867,9 @@ public class ColorPickerView extends View {
@@ -888,9 +867,9 @@ public class ColorPickerView extends View {
* If it is set to false no alpha will be set .
* @param visible
* /
public void setAlphaSliderVisible ( boolean visible ) {
public void setAlphaSliderVisible ( boolean visible ) {
if ( mShowAlphaPanel ! = visible ) {
if ( mShowAlphaPanel ! = visible ) {
mShowAlphaPanel = visible ;
/ *
@ -901,14 +880,15 @@ public class ColorPickerView extends View {
@@ -901,14 +880,15 @@ public class ColorPickerView extends View {
mValShader = null ;
mSatShader = null ;
mHueShader = null ;
mAlphaShader = null ; ;
mAlphaShader = null ;
;
requestLayout ( ) ;
}
}
public void setSliderTrackerColor ( int color ) {
public void setSliderTrackerColor ( int color ) {
mSliderTrackerColor = color ;
mHueTrackerPaint . setColor ( mSliderTrackerColor ) ;
@ -916,7 +896,7 @@ public class ColorPickerView extends View {
@@ -916,7 +896,7 @@ public class ColorPickerView extends View {
invalidate ( ) ;
}
public int getSliderTrackerColor ( ) {
public int getSliderTrackerColor ( ) {
return mSliderTrackerColor ;
}
@ -925,7 +905,7 @@ public class ColorPickerView extends View {
@@ -925,7 +905,7 @@ public class ColorPickerView extends View {
* alpha slider . Set to null to disable text .
* @param res string resource id .
* /
public void setAlphaSliderText ( int res ) {
public void setAlphaSliderText ( int res ) {
String text = getContext ( ) . getString ( res ) ;
setAlphaSliderText ( text ) ;
}
@ -935,7 +915,7 @@ public class ColorPickerView extends View {
@@ -935,7 +915,7 @@ public class ColorPickerView extends View {
* alpha slider . Set to null to disable text .
* @param text Text that should be shown .
* /
public void setAlphaSliderText ( String text ) {
public void setAlphaSliderText ( String text ) {
mAlphaSliderText = text ;
invalidate ( ) ;
}
@ -946,7 +926,7 @@ public class ColorPickerView extends View {
@@ -946,7 +926,7 @@ public class ColorPickerView extends View {
* slider .
* @return
* /
public String getAlphaSliderText ( ) {
public String getAlphaSliderText ( ) {
return mAlphaSliderText ;
}
}