Android 一键清理动画
本文另辟蹊径,使用自己定义View来完毕相同的效果,性能、效率更高。
/**
*
*/
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桌面内存清理效果
* @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) {
// 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("使用内存", 25, 25, titlePaint);
canvas.drawText(progress + "M" + "/1024M", 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);
} }
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();
}
}
});
}
}
效果例如以下:
Android 一键清理动画的更多相关文章
- Android特效专辑(七)——飞机升空特效,一键清理缓存,灵活运用动画会有不一样的感受
Android特效专辑(七)--飞机升空特效,一键清理缓存,灵活运用属性动画 最近的几篇博文反响还不错,也会继续的写下去的,关于这些特效的专辑,大多数也是借鉴大神的,最近由于工作的关系,会深入的了解一 ...
- Android立体旋转动画实现与封装(支持以X、Y、Z三个轴为轴心旋转)
本文主要介绍Android立体旋转动画,或者3D旋转,下图是我自己实现的一个界面 立体旋转分为以下三种: 1. 以X轴为轴心旋转 2. 以Y轴为轴心旋转 3. 以Z轴为轴心旋转--这种等价于andro ...
- Android中矢量动画
Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...
- Android Animation(动画)
前言 Android 平台提供实现动画的解决方案(三种) 一.3.0以前,android支持两种动画: (1)Frame Animation:顺序播放事先做好的图像,与gif图片原理类似,是一种逐帧动 ...
- android 补间动画和Animation
介绍: 补间动画是一种设定动画开始状态.结束状态,其中间的变化由系统计算补充.这也是他叫做补间动画的原因. 补间动画由Animation类来实现具体效果,包括平移(TranslateAnimation ...
- Android中过场动画
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); 第一参数为进入的动画 第二参数为退出的动画 进入的动画 ...
- Android 自定义波浪动画 --"让进度浪起来~"
原文链接:http://www.jianshu.com/p/0e25a10cb9f5 一款效果不错的动画,实现也挺简单的,推荐阅读学习~ -- 由 傻小孩b 分享 waveview <Andro ...
- Android 三种动画详解
[工匠若水 http://blog.csdn.net/yanbober 转载请注明出处.点我开始Android技术交流] 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让 ...
- 一键清理Windows垃圾的BAT文件代码
@echo off color 0atitle win7一键清理系统垃圾echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★ ...
随机推荐
- mybatis如何传入一个list参数
<!-- 7.2 foreach(循环List<String>参数) - 作为where中in的条件 --> <select id="getStudentLi ...
- 【CF1025A】Doggo Recoloring(签到)
题意:给定一个长度为 n 的小写字母串.可以将出现次数大于等于2的字母全部变成另一个小写字母,问最后能否将该小写字母串的所有字母变成同一个字母 n<=1e5 思路: #include<cs ...
- 【NOIP2015】子串(字符串DP)
题意:有AB两个字符串,用A中连续的K串匹配B全串,问不同的方案总数 n<=1000,m<=200,k<=m 思路:设dp[k,i,j]为用k串 A中前i个字符匹配B中前j个字符的方 ...
- 快充 IC BQ25896 的 input current monitor
BQ25896 沒有顯示 input current 的 register, 但可以讀 ILIM pin 的 電壓 做計算求出 input current.
- Laravel 5.1 框架返回状态拦截
Laravel 5.1 返回信息状态拦截 可以在app\Exceptions\Handler.php文件中修改, public function render($request, Exception ...
- SpringCloud 分布式事务解决方案
目录 TX-LCN分布式事务框架 TX-LCN分布式事务框架 随着互联化的蔓延,各种项目都逐渐向分布式服务做转换.如今微服务已经普遍存在,本地事务已经无法满足分布式的要求,由此分布式事务问题诞生. 分 ...
- android应用无法接收到广播?
本篇文章记录Android应用无法接收到广播的几种case 1. 没有register 广播其实是一种订阅者模式,所以当然需要先register,register的方式有两种 1.1 through ...
- java基础第三篇
6.Java 中的容器(重点) a.变量:变量是一个容器,它存储的单个值 //int i=3; 1.局部变量:定义在方法中,没有默认值 2.成员变量:定义在类中方法外,这个事物的属性(特征)定义为成员 ...
- Failed to check the status of the service报错解决
报这个错误是因为我的application_context.service.xml 文件里的的dubbo声明暴露口时的ref属性写错了. <dubbo:service interface=&qu ...
- PS 基础知识 .pat文件如何使用
我下了pat文件单打不开,也下了ps 匿名 回答:5 人气:7 解决时间:2009-05-25 12:48 满意答案 将你下载的pat文件放到下面文件夹内,(这是默认安装地址),重新打开Photosh ...