1. Activity
Import Java.util.Timer;
Import Java.util.TimerTask;
Import Android.annotation.SuppressLint;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import android.view.animation.Animation;
Import android.view.animation.RotateAnimation;
Import Android.widget.Button;
Import Android.widget.ImageView;
Import Android.widget.TextView;
public class Test extends activity {
Private long mlcount = 50;
Private long mcount = 0;
TextView Tvtime;
Private Button Startbuttondaoji;
Private timer timer = null;
Private TimerTask task = null;
Private Handler Handler = null;
Private message msg = NULL;
Private ImageView min_progress, Min_progress_hand;
Animation rotateanimation;
float Predegree = 0;
Boolean okclear = false;
@SuppressLint ("Handlerleak")
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Init ();
}
private void init () {
Setcontentview (r.layout.test);
Tvtime = (TextView) Findviewbyid (r.id.duocitvtime);
Startbuttondaoji = (Button) Findviewbyid (R.ID.STARTBUTTONDUOCI);
Min_progress = (ImageView) This.findviewbyid (r.id.duocimin_progress);
Min_progress_hand = (ImageView) This
. Findviewbyid (R.id.duocimin_progress_hand);
Tvtime.settext ("4");
Saverun.setisjishi (FALSE);
Handler = new Handler () {
@Override
public void Handlemessage (msg) {
Switch (msg.what) {
Case 1:
if (mlcount>1) {
mlcount--;
mcount++;
}else{
Break
}
int totalsec = 0;
totalsec = (int) (MLCOUNT/10);
int sec = (totalsec% 60);
try {
Rotateanimation = new Rotateanimation (Predegree,
(float) (* mcount),
Animation.relative_to_self, 0.5f,
Animation.relative_to_self, 0.5f);
Rotateanimation.setduration (100);
Rotateanimation.setfillafter (FALSE);
Min_progress_hand.startanimation (rotateanimation);
Min_progress.startanimation (rotateanimation);
Tvtime.settext (String.Format ("%1$2d"),
SEC));
Predegree = (float) (mcount);
catch (Exception e) {
Tvtime.settext (sec + "");
E.printstacktrace ();
}
Break
Default
Break
}
Super.handlemessage (msg);
}
};
}
@Override
protected void OnStart () {
Star ();
Super.onstart ();
}
private void Star () {
Startbuttondaoji.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Startbuttondaoji.setvisibility (View.gone);
if (null = = timer) {
if (null = Task) {
Saverun.setisjishi (TRUE);
Okclear = false;
Min_progress.setvisibility (view.visible);
task = new TimerTask () {
@Override
public void Run () {
if (null = msg) {
msg = new Message ();
} else {
msg = Message.obtain ();
}
Msg.what = 1;
Handler.sendmessage (msg);
}
};
}
Timer = new timer (true);
Timer.schedule (Task, 100, 100);
}
}
});
}
View.onclicklistener Startpauselistener = new View.onclicklistener () {
@Override
public void OnClick (View v) {
if (null = = timer) {
if (null = Task) {
Saverun.setisjishi (TRUE);
Okclear = false;
Min_progress.setvisibility (view.visible);
task = new TimerTask () {
@Override
public void Run () {
if (null = msg) {
msg = new Message ();
} else {
msg = Message.obtain ();
}
Msg.what = 1;
Handler.sendmessage (msg);
}
};
}
Timer = new timer (true);
Timer.schedule (Task, 100, 100);
} else {
try {
Saverun.setisjishi (FALSE);
Okclear = true;
Task.cancel ();
task = null;
Timer.cancel ();
Timer.purge ();
timer = null;
Handler.removemessages (Msg.what);
catch (Exception e) {
E.printstacktrace ();
}
}
}
};
}
2. layout file
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:ba"
Ckground= "@android: Color/background_dark" > <relativelayout android:layout_width= "match_parent"
android:layout_height= "Match_parent" android:layout_above= "@+id/buttonlinear" > <imageview Android:id= "@+id/duocimin_dial" android:layout_width= "wrap_content" android:layout_height= "WR" Ap_content "android:layout_centerinparent=" true "android:src=" @drawable/iv_bg "/> < ImageView android:id= "@+id/duocimin_progress" android:layout_width= "Wrap_content" Andr oid:layout_height= "Wrap_content" android:layout_centerinparent= "true" android:src= "@drawable/min_p Rogress "android:visibility=" inVisible "/> <imageview android:id=" @+id/duocimin_progress_hand "Android:layout_widt"
H= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerinparent= "true"
android:src= "@drawable/min_progress_hand"/> <textview android:id= "@+id/duocitvtime" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_cen Terinparent= "true" android:text= "00:00.0" android:textsize= "35sp" android:textstyle= "B" Old "/> <linearlayout android:id=" @+id/duocihoursoflinear "android:layout_width=" WR
Ap_content "android:layout_height=" wrap_content "android:layout_above=" @+id/duocitvtime " Android:layout_centerhorizontal= "true" android:gravity= "center" android:orientation= "horizontal "Android:visibility= "Invisible" > </LinearLayout> <linearlayout android:layout _width= "Match_parent" android:layout_height= "wrap_content" android:layout_alignbottom= "@+id/duocim" In_dial "android:gravity=" center_horizontal "android:orientation=" Horizontal "> &L T
Relativelayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content"
android:layout_marginright= "100SP" > </RelativeLayout> <relativelayout
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" > </RelativeLayout> </LinearLayout> </RelativeLayout> <relativelayout android: Id= "@+id/buttonlinear" android:layout_width= "match_parent" android:layout_height= "74SP" Android:la Yout_alignparentbottom= "true" android:background= "@drawable/v5_bottom_bar_bg_light" > <button android:id= "@
+id/startbuttonduoci "android:layout_width=" match_parent "android:layout_height=" Wrap_content " Android:layout_centerinparent= "true" android:layout_marginleft= "10SP" Android:layout_marg inright= "10SP" android:background= "@drawable/startback" android:text= "Start"/> </rela Tivelayout> </RelativeLayout>