[Android Notes] fake cheetah cleanup master wave effect, Android Cheetah

Source: Internet
Author: User

[Android Notes] fake cheetah cleanup master wave effect, Android Cheetah

First, let's look at the effect:


Implementation Method -----> Custom Control Core code:
Package com.example.wav edemo1; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. path; import android. OS. handler; import android. util. attributeSet; import android. view. view;/*** @ author Rowandjj ** copy the cheetah to clear the master wave effect */public class WaterWaveView extends View {private Handler mHandler; private long c = 0L; private boo Lean mStarted = false; private final float f = 0.033F; private int mAlpha = 70; // transparency private int mColor = Color. BLUE; private float mamplint = 6.0F; // amplitude private final Paint mPaint = new Paint (); private float mWateLevel = 0.5F; // water height (0 ~ 1) private Path mPath; public WaterWaveView (Context paramContext) {super (paramContext); init (paramContext);} public WaterWaveView (Context paramContext, AttributeSet paramAttributeSet) {super (paramContext, paramAttributeSet); init (paramContext);}/*** start fluctuation */public void startWave () {if (! MStarted) {this. c = 0L; mStarted = true; this. mHandler. sendEmptyMessage (0) ;}} private void init (Context context) {mPaint. setStrokeWidth (1.0F); mPaint. setColor (mColor); mPaint. setAlpha (mAlpha); mPath = new Path (); mHandler = new Handler () {@ Overridepublic 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 );}}}};}@ Overrideprotected void onDraw (Canvas canvas) {canvas. save (); mPaint. setAlpha (mAlpha); mPaint. setColor (mColor); // you can obtain the width and height of the Control. int width = getWidth (); int height = getHeight (); // if it is not started (the startWave method is not called ), draw a rectangle if ((! MStarted) | (width = 0) | (height = 0) {canvas. drawRect (0.0F, height/2, width, height, mPaint); return;} if (this. c> = 8388607L) {this. c = 0L;} // c will auto-increment this each time onDraw. c = (1L + this. c); float f1 = height * (1.0F-mWateLevel); int top = (int) (f1 + mamplath); mPath. reset (); // draw a rectangle, that is, the height canvas when the water surface is still. drawRect (0.0F, top, width, height, mPaint); int startX = 0; // wave effect while (startX <width) {int startY = (int) (f1-mAmplitude * Math. sin (Math. PI * (2.0F * (startX + this. c * width * this. f)/width); canvas. drawLine (startX, startY, startX, top, mPaint); startX ++;} canvas. restore ();}/*** set the amplitude * @ param amplitued */public void setampled (float amplitued) {mampled = amplitued ;} /*** set transparency * @ param alpha */public void setWaterAlpha (float alpha) {this. mAlpha = (int) (255.0F * alpha); mPaint. setAlpha (this. mAlpha);}/*** set the color * @ param color */public void setColor (int color) {this. mColor = color;}/*** set the water surface height * @ param paramFloat */public void setWaterLevel (float paramFloat) {mWateLevel = paramFloat;} @ Overrideprotected void onAttachedToWindow () {super. onAttachedToWindow (); // disable hardware acceleration to prevent unsupported operation exceptionthis. setLayerType (View. LAYER_TYPE_SOFTWARE, null );}}


Like a common control, configure the following in the layout file: 
 <com.example.wavedemo1.WaterWaveView        android:id="@+id/wav"        android:layout_width="match_parent"        android:layout_height="match_parent"        />

Then, the water surface starts to fluctuate by calling the startWave method in the code, and the set method can be called to control its attributes.




Android cheetah cleanup master game acceleration mechanism

Yes. It is cleaned up in advance when it is just running.

It is really useful to clean up game acceleration in the android cheetah master.

Not very useful, but it can be cleaned up to some extent. If some software is running in the background, it will not work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.