Android shares a traffic display page
Version: 1.0 Date: 2014.8.9 2014.9.24 copyright:©2014 kince reprinted to indicate the source
Waveform effects have several different forms of presentation, such as waveforms dispersed from the center to the surrounding area, that is, well-known water ripple, as well as upper and lower fluctuation curves, such as the five-line spectrum. Waves or Ripple can be called in English. Therefore, WaveView, WaveLayout, RippleView, and RippleLayout are called for the time being. First, let's take a look at Solo's popular football live wallpaper,
The button in the middle of the figure below is a waveform button, which will continuously radiate around. Because it is a static graph, you can download it if you want to experience the real effect. The implementation idea of this effect is to constantly draw a circle, of course, the radius must also change, and the transparency is the same. The Code is as follows:
/*****/Package com. kince. rippleview; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. rectF; import android. OS. handler; import android. OS. message; import android. util. attributeSet; import android. view. view;/*** @ author kince * @ category ripple * @ since 2014.8.9 * @ version v1.0.0 **/public class RippleView extends View {private int mScreenWidth; private int mScreenHeight; private Bitmap mRippleBitmap; private Paint mRipplePaint = new Paint (); private int mBitmapWidth; private int mBitmapHeight; private boolean isStartRipple; private int heightPaddingTop; private int hidden; private int widthPaddingLeft; private int widthPaddingRight; private RectF mRect = new RectF (); private int rippleFirstRadius = 0; private int rippleSecendRadius =-33; private int rippleThirdRadius =-66; private Paint textPaint = new Paint (); private String mText = click me; private Handler handler = new Handler () {@ Override public void handleMessage (Message msg) {// TODO Auto-generated method stub super. handleMessage (msg); invalidate (); if (isStartRipple) {rippleFirstRadius ++; if (rippleFirstRadius> 100) {rippleFirstRadius = 0;} rippleSecendRadius ++; if (latency> 100) {rippleSecendRadius = 0;} rippleThirdRadius ++; if (rippleThirdRadius> 100) {rippleThirdRadius = 0;} sendEmptyMessageDelayed (0, 20 );}}}; /*** @ param context */public RippleView (Context context) {super (context); // TODO Auto-generated constructor stub init ();} /*** @ param context * @ param attrs */public RippleView (Context context, AttributeSet attrs) {super (context, attrs ); // TODO Auto-generated constructor stub init ();}/*** @ param context * @ param attrs * @ param defStyleAttr */public RippleView (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); // TODO Auto-generated constructor stub init ();} private void init () {mRipplePaint. setColor (4961729); mRipplePaint. setAntiAlias (true); mRipplePaint. setStyle (Paint. style. FILL); textPaint. setTextSize (26); textPaint. setAntiAlias (true); textPaint. setStyle (Paint. style. FILL); textPaint. setColor (Color. WHITE); mRippleBitmap = BitmapFactory. decodeStream (getResources (). openRawResource (R. drawable. easy3d_ic_apply); mBitmapWidth = mRippleBitmap. getWidth (); mBitmapHeight = mRippleBitmap. getHeight () ;}@ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {// TODO Auto-generated method stub super. onMeasure (widthMeasureSpec, heightMeasureSpec); int mh = getMeasuredHeight ()-getPaddingTop ()-evaluate (); int mw = getMeasuredWidth ()-getPaddingLeft ()-getPaddingRight (); if (mBitmapWidth <2 * mBitmapHeight) {mBitmapWidth = (2 * mBitmapHeight);} setMeasuredDimension (mBitmapWidth, mBitmapHeight);} @ Override protected void onDraw (Canvas canvas Canvas) {// TODO Auto-generated method stub super. onDraw (canvas); if (isStartRipple) {float f1 = 3 * mBitmapHeight/10; mRipplePaint. setAlpha (1, 255); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 7 * mBitmapHeight/10, mRipplePaint); int i1 = (int) (220366f-(220366f-0.0F)/100366f * Rows); mRipplePaint. setAlpha (i1); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 7 * mBitmapHeight/10 + f1 * rippleFirstRadius/100366f, mRipplePaint); if (rippleSecendRadius> = 0) {int i3 = (int) (2200000f-(2200000f-0.0F)/1000000f * rippleSecendRadius); mRipplePaint. setAlpha (i3); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 7 * mBitmapHeight/10 + f1 * rippleSecendRadius/100366f, mRipplePaint);} if (rippleThirdRadius> = 0) {int i2 = (int) (220366f-(220366f-0.0F)/100366f * rippleThirdRadius); mRipplePaint. setAlpha (i2); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 7 * mBitmapHeight/10 + f1 * rippleThirdRadius/100366f, mRipplePaint);} mRipplePaint. setAlpha (30); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, mBitmapHeight, mRipplePaint); mRipplePaint. setAlpha (1, 120); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 9 * mBitmapHeight/10, mRipplePaint); mRipplePaint. setAlpha (1, 180); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 8 * mBitmapHeight/10, mRipplePaint); mRipplePaint. setAlpha (1, 255); canvas. drawCircle (mBitmapWidth/2, mBitmapHeight, 7 * mBitmapHeight/10, mRipplePaint); float length = textPaint. measureText (mText); canvas. drawText (mText, (mBitmapWidth-length)/2, mBitmapHeight * 3/4, textPaint);} @ Override protected void onSizeChanged (int w, int h, int oldw, int oldh) {// TODO Auto-generated method stub super. onSizeChanged (w, h, oldw, oldh); mScreenWidth = w; mScreenHeight = h; confirmSize (); invalidate ();} private void confirmSize () {int minScreenSize = Math. min (mScreenWidth, mScreenHeight); int widthOverSize = mScreenWidth-minScreenSize; int mask = mScreenHeight-minScreenSize; mask = (getPaddingTop () + extract/2); mask = (getPaddingBottom () + heightOverSize/2); widthPaddingLeft = (getPaddingLeft () + widthOverSize/2); widthPaddingRight = (getPaddingRight () + widthOverSize/2); int width = getWidth (); int height = getHeight (); mRect = new RectF (widthPaddingLeft, heightPaddingTop, width-widthPaddingRight, height * 2-rows);} public void stratRipple () {isStartRipple = true; handler. sendEmptyMessage (0 );}}Is the traffic display interface of an application. The second form is used. The method to achieve the above effect is to use a sine or cosine curve. The Code is as follows:
/*****/Package com.kince.wav eview; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. path; import android. graphics. rectF; import android. OS. handler; import android. OS. parcel; import android. OS. parcelable; import android. util. attributeSet; import android. view. view; import android. widget. progressBar;/*** @ author ki Nce * @ category View must be square **/public class WaterWaveView extends View {private Context mContext; private int mScreenWidth; private int mScreenHeight; private Paint mRingPaint; private Paint mCirclePaint; private Paint mWavePaint; private Paint linePaint; private Paint flowPaint; private Paint leftPaint; private int mRingSTROKEWidth = 15; private int mCircleSTROKEWidth = 2; private int mLineSTROKEWi Dth = 1; private int mCircleColor = Color. WHITE; private int mRingColor = Color. WHITE; private int mWaveColor = Color. WHITE; private Handler mHandler; private long c = 0L; private boolean mStarted = false; private final float f = 0.033F; private int mAlpha = 50; // transparency private float mamplat = 10.0F; // amplitude private float mWateLevel = 0.5F; // water height (0 ~ 1) private Path mPath; private String flowNum = 1024 M; private String flowLeft = remaining;/*** @ param context */public WaterWaveView (Context context) {super (context); // TODO Auto-generated constructor stub mContext = context; init (mContext );} /*** @ param context * @ param attrs */public WaterWaveView (Context context, AttributeSet attrs) {super (context, attrs); // TODO Auto-generated constructor Stub mContext = context; init (mContext);}/*** @ param context * @ param attrs * @ param defStyleAttr */public WaterWaveView (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); // TODO Auto-generated constructor stub mContext = context; init (mContext);} private void init (Context context) {mRingPaint = new Paint (); mRingPaint. setColor (mRingColor); mRingPa Int. setAlpha (50); mRingPaint. setStyle (Paint. style. STROKE); mRingPaint. setAntiAlias (true); mRingPaint. setStrokeWidth (mRingSTROKEWidth); mCirclePaint = new Paint (); mCirclePaint. setColor (mCircleColor); mCirclePaint. setStyle (Paint. style. STROKE); mCirclePaint. setAntiAlias (true); mCirclePaint. setStrokeWidth (mCircleSTROKEWidth); linePaint = new Paint (); linePaint. setColor (mCircleColor); linePaint. setSty Le (Paint. style. STROKE); linePaint. setAntiAlias (true); linePaint. setStrokeWidth (mLineSTROKEWidth); flowPaint = new Paint (); flowPaint. setColor (mCircleColor); flowPaint. setStyle (Paint. style. FILL); flowPaint. setAntiAlias (true); flowPaint. setTextSize (36); leftPaint = new Paint (); leftPaint. setColor (mCircleColor); leftPaint. setStyle (Paint. style. FILL); leftPaint. setAntiAlias (true); leftPaint. setTextSize (18); mWavePaint = new Paint (); mWavePaint. setStrokeWidth (1.0F); mWavePaint. setColor (mWaveColor); mWavePaint. setAlpha (mAlpha); mPath = new Path (); mHandler = new Handler () {@ Override public void handleMessage (android. OS. message msg) {if (msg. what = 0) {invalidate (); if (mStarted) {// constantly send messages to yourself so that you are repeatedly re-painted mHandler. sendEmptyMessageDelayed (0, 60L) ;}}};}@ Override protected void onMeasure (int WidthMeasureSpec, int heightMeasureSpec) {int width = measure (widthMeasureSpec, true); int height = measure (heightMeasureSpec, false); if (width
CREATOR = new Parcelable. Creator
() {Public SavedState createFromParcel (Parcel in) {return new SavedState (in);} public SavedState [] newArray (int size) {return new SavedState [size] ;}}}}