@ -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 ;
@ -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 ) ;
@ -234,18 +236,18 @@ public class ColorPickerView extends View {
@@ -234,18 +236,18 @@ public class ColorPickerView extends View {
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 } ) ;
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 ) ;
@ -267,15 +269,13 @@ public class ColorPickerView extends View {
@@ -267,15 +269,13 @@ public class ColorPickerView extends View {
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 ) ;
}
@ -298,17 +298,16 @@ public class ColorPickerView extends View {
@@ -298,17 +298,16 @@ public class ColorPickerView extends View {
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 ) {
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 ) ;
}
@ -318,8 +317,7 @@ public class ColorPickerView extends View {
@@ -318,8 +317,7 @@ public class ColorPickerView extends View {
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 ) ;
@ -396,21 +394,17 @@ public class ColorPickerView extends View {
@@ -396,21 +394,17 @@ public class ColorPickerView extends View {
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 ) {
y = 0f ;
}
else if ( y > rect . bottom ) {
} else if ( y > rect . bottom ) {
y = height ;
}
else {
} else {
y = y - rect . top ;
}
@ -429,11 +423,9 @@ public class ColorPickerView extends View {
@@ -429,11 +423,9 @@ public class ColorPickerView extends View {
if ( y < rect . top ) {
y = 0f ;
}
else if ( y > rect . bottom ) {
} else if ( y > rect . bottom ) {
y = height ;
}
else {
} else {
y = y - rect . top ;
}
@ -447,11 +439,9 @@ public class ColorPickerView extends View {
@@ -447,11 +439,9 @@ public class ColorPickerView extends View {
if ( x < rect . left ) {
x = 0 ;
}
else if ( x > rect . right ) {
} else if ( x > rect . right ) {
x = width ;
}
else {
} else {
x = x - ( int ) rect . left ;
}
@ -482,15 +472,13 @@ public class ColorPickerView extends View {
@@ -482,15 +472,13 @@ public class ColorPickerView extends View {
if ( sat < 0f ) {
sat = 0f ;
}
else if ( sat > 1f ) {
} else if ( sat > 1f ) {
sat = 1f ;
}
if ( val < 0f ) {
val = 0f ;
}
else if ( val > 1f ) {
} else if ( val > 1f ) {
val = 1f ;
}
@ -507,8 +495,7 @@ public class ColorPickerView extends View {
@@ -507,8 +495,7 @@ public class ColorPickerView extends View {
if ( hue < 0f ) {
hue = 0f ;
}
else if ( hue > 360f ) {
} else if ( hue > 360f ) {
hue = 360f ;
}
@ -522,15 +509,13 @@ public class ColorPickerView extends View {
@@ -522,15 +509,13 @@ public class ColorPickerView extends View {
if ( ! mShowAlphaPanel | | mAlphaRect = = null ) {
update = false ;
}
else {
} else {
int alpha = ( int ) ( mAlpha - x * 10 ) ;
if ( alpha < 0 ) {
alpha = 0 ;
}
else if ( alpha > 0xff ) {
} else if ( alpha > 0xff ) {
alpha = 0xff ;
}
@ -608,7 +593,9 @@ public class ColorPickerView extends View {
@@ -608,7 +593,9 @@ public class ColorPickerView extends View {
private boolean moveTrackersIfNeeded ( MotionEvent event ) {
if ( mStartTouchPoint = = null ) return false ;
if ( mStartTouchPoint = = null ) {
return false ;
}
boolean update = false ;
@ -622,8 +609,7 @@ public class ColorPickerView extends View {
@@ -622,8 +609,7 @@ public class ColorPickerView extends View {
mHue = pointToHue ( event . getY ( ) ) ;
update = true ;
}
else if ( mSatValRect . contains ( startX , startY ) ) {
} else if ( mSatValRect . contains ( startX , startY ) ) {
mLastTouchedPanel = PANEL_SAT_VAL ;
@ -633,8 +619,7 @@ public class ColorPickerView extends View {
@@ -633,8 +619,7 @@ 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 ;
@ -670,20 +655,17 @@ public class ColorPickerView extends View {
@@ -670,20 +655,17 @@ public class ColorPickerView extends View {
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 ) {
width = widthAllowed ;
height = ( int ) ( widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT ) ;
}
else {
} else {
height = heightAllowed ;
}
@ -733,7 +715,6 @@ public class ColorPickerView extends View {
@@ -733,7 +715,6 @@ public class ColorPickerView extends View {
}
@Override
protected void onSizeChanged ( int w , int h , int oldw , int oldh ) {
super . onSizeChanged ( w , h , oldw , oldh ) ;
@ -779,7 +760,9 @@ public class ColorPickerView extends View {
@@ -779,7 +760,9 @@ public class ColorPickerView extends View {
private void setUpAlphaRect ( ) {
if ( ! mShowAlphaPanel ) return ;
if ( ! mShowAlphaPanel ) {
return ;
}
final RectF dRect = mDrawingRect ;
@ -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 ) ) ;
}
@ -901,7 +880,8 @@ public class ColorPickerView extends View {
@@ -901,7 +880,8 @@ public class ColorPickerView extends View {
mValShader = null ;
mSatShader = null ;
mHueShader = null ;
mAlphaShader = null ; ;
mAlphaShader = null ;
;
requestLayout ( ) ;
}