package com.qqfortune;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.MotionEvent;
/**
* 开始LOGO跳转页
* @author CRF
* @2010-03-11
*/
public class LogoActivity extends Activity
{
private Handler objHandler = new Handler();
private int intCounter=0;
private boolean isTime=true;
private long delayMillis=5000;
private Runnable mTasks = new Runnable()
{
/*自动页面跳转 */
public void run()
{
/* 自动时间后跳转 */
// intCounter++;
// if(intCounter<10){
// objHandler.postDelayed(mTasks, 800);
// }
// else{
// Intent in=new Intent(LogoActivity.this,QQFortune.class);
// LogoActivity.this.startActivity(in);
// LogoActivity.this.finish();
// objHandler.removeCallbacks(mTasks);
// }
while(isTime){
boolean reachTime=objHandler.postDelayed(mTasks, delayMillis);
if (reachTime==true) isTime=false;
}
Intent in=new Intent(LogoActivity.this,QQFortune.class);
LogoActivity.this.startActivity(in);
LogoActivity.this.finish();
objHandler.removeCallbacks(mTasks);
}
};
public void onCreate(Bundle dl){
super.onCreate(dl);
this.setContentView(R.layout.logo);
objHandler.postDelayed(mTasks, 800);
}
/* 按键弹起事件*/
public boolean onKeyUp(int keyCode, KeyEvent event){
Intent in=new Intent(LogoActivity.this,QQFortune.class);
LogoActivity.this.startActivity(in);
LogoActivity.this.finish();
objHandler.removeCallbacks(mTasks);
return true;
}
/*触摸事件*/
public boolean onTouchEvent(MotionEvent event){
if(MotionEvent.ACTION_UP==event.getAction()){
Intent in=new Intent(LogoActivity.this,QQFortune.class);
LogoActivity.this.startActivity(in);
LogoActivity.this.finish();
objHandler.removeCallbacks(mTasks);
return true;
}
return false;
}
}
//////////////////////////参考///////////////
package org.me.android_timer;
02.import android.app.Activity; 03.import android.os.Bundle; 04.import android.os.Handler; 05.import android.widget.TextView; 06. 07.public class MainActivity extends Activity { 08. private Long startTime; 09. private Handler handler = new Handler(); 10. 11. @Override12. public void onCreate(Bundle savedInstanceState) { 13. super.onCreate(savedInstanceState); 14. setContentView(R.layout.main); 15. //取得目前時間 16. startTime = System.currentTimeMillis(); 17. //設定定時要執行的方法 18. handler.removeCallbacks(updateTimer); 19. //設定Delay的時間 20. handler.postDelayed(updateTimer, 1000); 21. } 22. 23. //固定要執行的方法 24. private Runnable updateTimer = new Runnable() { 25. public void run() { 26. final TextView time = (TextView) findViewById(R.id.timer); 27. Long spentTime = System.currentTimeMillis() - startTime; 28. //計算目前已過分鐘數 29. Long minius = (spentTime/1000)/60; 30. //計算目前已過秒數 31. Long seconds = (spentTime/1000) % 60; 32. time.setText(minius+":"+seconds); 33. handler.postDelayed(this, 1000); 34. } 35. }; 36.}
1610

被折叠的 条评论
为什么被折叠?



