This article elaborated the Android Lottery program realization Method, the procedure is a lottery big dial code, inside has defined many graphics method and the animation.
Import android.app.Activity;
Import Android.content.Context;
Import Android.graphics.BlurMaskFilter;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.ColorMatrixColorFilter;
Import Android.graphics.EmbossMaskFilter;
Import Android.graphics.MaskFilter;
Import Android.graphics.Paint;
Import Android.graphics.PorterDuffXfermode;
Import Android.graphics.Paint.Style;
Import Android.graphics.PorterDuff.Mode;
Import Android.graphics.Path;
Import android.graphics.RadialGradient;
Import Android.graphics.RectF;
Import Android.graphics.Shader.TileMode;
Import Android.util.AttributeSet;
Import Android.util.TypedValue;
Import Android.view.View; public class Slyderview extends view{public slyderview (context context, AttributeSet attrs, int defstyleattr) {sup
ER (context, attrs, defstyleattr);
Init (context);
Public Slyderview (context, AttributeSet attrs) {Super (context, attrs);
Init (context); } public Slyderview (context ContexT) {super (context);
Init (context);
/** * Screen width */private int screenw;
/** * Screen Height * * private int screenh;
/** * The degree of the split * * private int [] Drgrees = {20,50,40,90,70,40,50};
/*** * Split text */private String [] STRs = {"Level1", "Level2", "Level3", "Level4", "Level5", "Level6", "Level7"}; /** * Split color/private int [] Colos = new int[] {0xfed9c960, 0xfe57c8c8, 0xfe9fe558, 0xfef6b000, 0xfef46212, 0xFE
cf2911, 0xfe9d3011};
/** * Brush/private Paint Paint; /** * Text Size * * Private float TEXTSIZE = typedvalue.applydimension (typedvalue.complex_unit_sp, Getresources (). g
Etdisplaymetrics ());
/** * Text color * * Private int textcolor = Color.White; /** * The radius of the garden * * private float radius = typedvalue.applydimension (typedvalue.complex_unit_sp, Getresources (). Get
Displaymetrics ()); /** * Draw the text distance * * Private float Textdis = typedvalue.applydimension (typedvalue.complex_unit_sp, Getresources (). g EtdisplAymetrics ()); /** * Picture Arrow Size * * Private float roketsize = typedvalue.applydimension (typedvalue.complex_unit_sp, Getresources ()
. Getdisplaymetrics ());
private float initdegress = 0;
/** * Center/private float CenterX;
/** * Center/private float CenterY;
/** * Solid Edge * * Private maskfilter filter = new Embossmaskfilter (new float[] {1, 1, 1},0.4f, 6, 3.5f);
Private Maskfilter Outerfilter = new Blurmaskfilter (ten, BlurMaskFilter.Blur.OUTER);
Private Maskfilter Innerfilter = new Blurmaskfilter (ten, BlurMaskFilter.Blur.INNER);
@SuppressWarnings ("deprecation") private void init (context context) {paint = new paint ();
Paint.setantialias (TRUE);
Paint.setstyle (Style.fill);
Paint.setcolor (Color.White);
Screenw = ((activity) context). Getwindowmanager (). Getdefaultdisplay (). GetWidth ();
Screenh = ((activity) context). Getwindowmanager (). Getdefaultdisplay (). GetHeight ();
int[] Colores = new Int[3]; Colores[0] = Color.rgb (0xfF, 0X99, 0x00);
COLORES[1] = Color.rgb (0xFF, 0xFF, 0x00);
COLORES[2] = Color.rgb (0xFF, 0x99, 0x00);
float[] positions = new FLOAT[3];
Positions[0] = 0.0f;
POSITIONS[1] = 0.5f;
POSITIONS[2] = 1.0f;
Gradient = new Radialgradient (CenterX, CenterY, RADIUS/5, Colores, positions, tilemode.clamp);
/** * Draw the triangle arrow * * Private path PATH = new Path ();
/** * Draw Rectangular frame * * * private RECTF oval; /** * Outer circle inner Shadow matrix/private Colormatrixcolorfilter Colorfilter = new Colormatrixcolorfilter (New float[]{1,0,0,
0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,-1,255});
@Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
CenterX = SCREENW/2;
CenterY = SCREENH/2;
Oval = new RECTF (Centerx-radius,centery-radius,centerx+radius,centery+radius);
float start = 0;
Paint.setcolor (Color.rgb (0XDD, 0XDD, 0XDD));
Paint.setalpha (127);
Canvas.drawcircle (CenterX, CenterY, radius+10, paint); Paint.setalpha (255);
Draw Fan Paint.setantialias (true);
for (int i=0;i<drgrees.length;i++) {float sweepangle = drgrees[i];
float startangle = start;
Paint.setcolor (Colos[i%colos.length]);
Canvas.drawarc (oval, StartAngle, Sweepangle, true, paint);
Start + = Drgrees[i];
///Draw Text Paint.setcolor (TextColor);
Paint.setantialias (TRUE);
Paint.settextsize (TEXTSIZE);
Paint.settextalign (Paint.Align.RIGHT);
start = 0;
for (int i=0;i<drgrees.length;i++) {canvas.save ();
Canvas.rotate (START+DRGREES[I]/2, CenterX, centery);
Canvas.drawtext (Strs[i], Centerx+textdis, centery, paint);
Canvas.restore ();
Start + = Drgrees[i];
int savecount = Canvas.save ();
Painting outer stereo effect Paint.setcolorfilter (colorfilter);
Canvas.savelayer (Oval,paint,canvas.all_save_flag);
Paint.setcolorfilter (NULL);
Canvas.drawargb (255, 0, 0, 0);
Paint.setxfermode (New Porterduffxfermode (mode.clear)); Canvas.drawcircle (CenterX, CenterY, radius, paint);
Paint.setxfermode (NULL);
Paint.setmaskfilter (Innerfilter);
Paint.setcolor (Color.argb (0xff, 0, 0, 0));
Canvas.drawcircle (CenterX, centery, radius, paint);
Paint.setmaskfilter (NULL);
Canvas.restoretocount (Savecount);
Draw inside and inside the Garden effect Canvas.save ();
Paint.setcolor (Color.argb (0xff, 0, 0, 0));
Paint.setantialias (TRUE);
Paint.setmaskfilter (Outerfilter);
Canvas.rotate (initdegress, CenterX, centery);
Canvas.drawcircle (CenterX, CenterY, RADIUS/3, paint);
Paint.setmaskfilter (NULL);
Paint.setcolor (Color.White);
Canvas.drawcircle (CenterX, CenterY, RADIUS/3, paint);
Draw triangular Overlay when Arrow path.moveto (CENTERX-RADIUS/3, centery);
Path.lineto (CenterX, centery-radius/3-roketsize);
Path.lineto (CENTERX+RADIUS/3, centery);
Path.close ();
Canvas.drawpath (path, paint);
Canvas.restore ();
Paint.setmaskfilter (filter);
Paint.setcolor (Color.green);
Paint.setshader (gradient); Canvas.drawcircle (centErX, CenterY, RADIUS/5, paint);
Paint.setmaskfilter (NULL);
Paint.setshader (NULL); Redrawing the direction of the triangle to achieve scrolling effect, the actual project can not be used in this way, the efficiency is too low, split view with animation to complete the scroll is the King if (isrunning) {if (initdegress>=360) {initdeg
ress = 0;
} initdegress +=4;
Invalidate ();
} if (isstoping) {if (initdegress<=360) {initdegress+=4;
Invalidate ();
}else{if (initdegress-360<stop_degress) {initdegress+=2;
Invalidate ();
}}} private Boolean isrunning = false;
Private Boolean isstoping = false;
private int stop_degress = 90;
/** * Gradient * * Private radialgradient gradient;
public void Play () {isrunning = true;
Invalidate (); public void Stop (int. count) {for (int i =0;i<=count;i++) {if (i = = count) {stop_degress +=drgrees[i
]/2;
}else{stop_degress +=drgrees[i];
} isstoping = true;
IsRunning = false;
Invalidate ();
}
}