One-click animation cleanup for Android and one-click animation cleanup for android

Source: Internet
Author: User
Tags drawtext

One-click animation cleanup for Android and one-click animation cleanup for android
Version: 1.0 Date: 2014.7.29 2014.7.30 copyright:©2014 kince reprinted to indicate the source
One-click cleanup is a feature provided by many Launcher, and its effect is also quite beautiful. There may be many implementation methods. The common method is to use the image drawable. For details, refer to this article: imitating the one-click cleanup effect of the 360 desktop crystal ball. This document introduces how to use custom views to achieve the same effect, with higher performance and efficiency. ProgressWheel is believed to be familiar to many people. I have referenced some of the Code. Interestingly, after reading the code, I found that the unused rectangular progress bar is hidden. I guess it will never happen because of the project name. Therefore, the ProgressRectangle is formed based on the addition, modification, and modification. In order to save time, the first version does not use custom attributes. Please add them later. The Code is as follows:

/*****/Package com. kince. progressrectangle; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. rectF; import android. graphics. paint. style; import android. OS. handler; import android. OS. message; import android. util. attributeSet; import android. util. log; import android. view. view; /*** @ author kince * @ category solo desktop memory cleanup effect * @ since 2014.7.30 * @ version 1.0.0 * {@ link} **/public class ProgressRectangle extends View {// sizes (with defaults) private int layout_height = 0; private int layout_width = 0; // Colors (with defaults) private int bgColor = Color. TRANSPARENT; private int progressColor = 0xFF339933; // Paints private Paint progressPaint = new Paint (); private Paint bgPaint = new Paint (); private Paint titlePaint = new Paint (); private Paint usePaint = new Paint (); // Rectangles private RectF rectBgBounds = new RectF (); private RectF rectProgressBounds = new RectF (); int progress = 100; boolean isProgress; private Handler spinHandler = new Handler () {/*** This is the code that will increment the progress variable and so * spin the wheel */@ Override public void handleMessage (Message msg) {invalidate (); // super. handleMessage (msg) ;}};/*** @ param context */public ProgressRectangle (Context context) {super (context ); // TODO Auto-generated constructor stub}/*** @ param context * @ param attrs */public ProgressRectangle (Context context, AttributeSet attrs) {super (context, attrs ); // TODO Auto-generated constructor stub}/*** @ param context * @ param attrs * @ param defStyleAttr */public ProgressRectangle (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); // TODO Auto-generated constructor stub} @ Override protected void onSizeChanged (int w, int h, int oldw, int oldh) {// TODO Auto-generated method stub super. onSizeChanged (w, h, oldw, oldh); // Share the dimensions layout_width = w; Log. I ("layout_width", layout_width + ""); layout_height = h; Log. I ("layout_height", layout_height + ""); setupBounds (); setupPaints (); invalidate ();} private void setupPaints () {// TODO Auto-generated method stub bgPaint. setColor (bgColor); bgPaint. setAntiAlias (true); bgPaint. setStyle (Style. FILL); progressPaint. setColor (progressColor); progressPaint. setAntiAlias (true); progressPaint. setStyle (Style. FILL); titlePaint. setColor (Color. WHITE); titlePaint. setTextSize (20); titlePaint. setAntiAlias (true); titlePaint. setStyle (Style. FILL); usePaint. setColor (Color. WHITE); usePaint. setAntiAlias (true); usePaint. setTextSize (30); usePaint. setStyle (Style. FILL);} private void setupBounds () {// TODO Auto-generated method stub int width = getWidth (); // this. getLayoutParams (). width; Log. I ("width", width + ""); int height = getHeight (); // this. getLayoutParams (). height; Log. I ("height", height + ""); rectBgBounds = new RectF (0, 0, width, height) ;}@ Override protected void onDraw (Canvas canvas Canvas) {// TODO Auto-generated method stub super. onDraw (canvas); canvas. drawRect (rectBgBounds, bgPaint); Log. I ("progress", progress + ""); rectProgressBounds = new RectF (0, 0, progress, layout_height); canvas. drawRect (rectProgressBounds, progressPaint); canvas. drawText ("memory used", 25, 25, titlePaint); canvas. drawText (progress + "M" + "/1024 M", 25, 60, usePaint);}/*** Increment the progress by 1 (of 100) */public void incrementProgress () {isProgress = true; progress ++; if (progress> 200) progress = 100; // setText (Math. round (float) progress/360) * 100) + "%"); spinHandler. sendEmptyMessage (0);}/*** Increment the progress by 1 (of 100) */public void unIncrementProgress () {isProgress = true; progress --; if (progress <1) progress = 100; // setText (Math. round (float) progress/360) * 100) + "%"); spinHandler. sendEmptyMessage (0);}/*** Set the progress to a specific value */public void setProgress (int I) {progress = I; spinHandler. sendEmptyMessage (0 );}}
The implementation idea is also very simple. It is to draw the background and progress of the progress bar in the onDraw () method. The progress parameter is the passed value. The Activity code is as follows:
package com.kince.progressrectangle;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class RecActivity extends Activity {     boolean running;     int progress = 0;     ProgressRectangle progressRectangle;          @Override     protected void onCreate(Bundle savedInstanceState) {          // TODO Auto-generated method stub          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_rec);                    progressRectangle=(ProgressRectangle) findViewById(R.id.progressBar);          final Runnable r = new Runnable() {                    public void run() {                         running = true;                         while(progress<100) {                              progressRectangle.incrementProgress();                              progress++;                              try {                                   Thread.sleep(15);                              } catch (InterruptedException e) {                                   // TODO Auto-generated catch block                                   e.printStackTrace();                              }                         }                         while(progress>0) {                              progressRectangle.unIncrementProgress();                              progress--;                              try {                                   Thread.sleep(15);                              } catch (InterruptedException e) {                                   // TODO Auto-generated catch block                                   e.printStackTrace();                              }                         }                                   running = false;                    }             };                       Button increment = (Button) findViewById(R.id.btn_increment);        increment.setOnClickListener(new OnClickListener() {               public void onClick(View v) {                    if(!running) {                         progress = 0;                         Thread s = new Thread(r);                         s.start();                    }               }        });     }}
The effect is as follows:


In general, it is to draw a rectangle to achieve the goal. Of course, the effects in actual use are still different. You are welcome to give feedback and exchange. <-- Csdn download: http://download.csdn.net/detail/wangjinyu501/7694607 gitub address: https://github.com/wangjinyu501/ProgressRectangle -->


One-click cleanup software for Android?

Clear RAM?
Download to dangle: release memory

Does the one-click cleanup process often affect Android phones?

No harm

Related Article

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.