Android源碼下載:驗證碼倒計時

來源:互聯網
上載者:User

Android源碼下載:驗證碼倒計時

功能分類:特效

支援平台:Android

運行環境:Eclipse

開發語言:Java

開發工具:Eclipse

源碼大小:1.38MB

源碼:http://down.51cto.com/data/1977282

源碼簡介

Service+CountDownTimer+Handler完成倒計時功能,頁面切換不中斷。

源碼運行

運行效果

 

源碼片段

 
  1. package com.zihao.timerdemo; 
  2.   
  3. import com.zihao.service.RegisterCodeTimerService; 
  4. import com.zihao.util.RegisterCodeTimer; 
  5. import android.os.Bundle; 
  6. import android.os.Handler; 
  7. import android.os.Message; 
  8. import android.view.View; 
  9. import android.view.View.OnClickListener; 
  10. import android.widget.Button; 
  11. import android.annotation.SuppressLint; 
  12. import android.app.Activity; 
  13. import android.content.Intent; 
  14.   
  15. /** 
  16.  * 主介面 
  17.  * 
  18.  * @author zihao 
  19.  * 
  20.  */ 
  21. public class MainActivity extends Activity { 
  22.   
  23.     private Button mGetCodeBtn;// 倒計時按鈕 
  24.     private Intent mIntent; 
  25.   
  26.     @Override 
  27.     protected void onCreate(Bundle savedInstanceState) { 
  28.         super.onCreate(savedInstanceState); 
  29.         setContentView(R.layout.activity_main); 
  30.         initView(); 
  31.     } 
  32.   
  33.     /** 
  34.      * 初始化視圖 
  35.      */ 
  36.     private void initView() { 
  37.         mGetCodeBtn = (Button) findViewById(R.id.get_code_btn); 
  38.         RegisterCodeTimerService.setHandler(mCodeHandler); 
  39.         mIntent = new Intent(MainActivity.this, RegisterCodeTimerService.class); 
  40.         mGetCodeBtn.setOnClickListener(new OnClickListener() { 
  41.   
  42.             @Override 
  43.             public void onClick(View v) { 
  44.                 // TODO Auto-generated method stub 
  45.                 mGetCodeBtn.setEnabled(false); 
  46.                 startService(mIntent); 
  47.             } 
  48.         }); 
  49.     } 
  50.   
  51.     /** 
  52.      * 倒計時Handler 
  53.      */ 
  54.     @SuppressLint("HandlerLeak") 
  55.     Handler mCodeHandler = new Handler() { 
  56.         public void handleMessage(Message msg) { 
  57.             if (msg.what == RegisterCodeTimer.IN_RUNNING) {// 正在倒計時 
  58.                 mGetCodeBtn.setText(msg.obj.toString()); 
  59.             } else if (msg.what == RegisterCodeTimer.END_RUNNING) {// 完成倒計時 
  60.                 mGetCodeBtn.setEnabled(true); 
  61.                 mGetCodeBtn.setText(msg.obj.toString()); 
  62.             } 
  63.         }; 
  64.     }; 
  65.   
  66.     @Override 
  67.     protected void onDestroy() { 
  68.         // TODO Auto-generated method stub 
  69.         super.onDestroy(); 
  70.         stopService(mIntent); 
  71.     } 
  72.   

源碼:http://down.51cto.com/data/1977282

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.