1. 程式人生 > >密碼找回業務邏輯

密碼找回業務邏輯

protect mit oid isempty tid cti sources cancel roi

package jiyun.com.example.lenovo.android_myfindpass;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.NotificationCompat; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; import java.util.Random; public class MainActivity extends Activity implements
View.OnClickListener { private ImageView iv_left; private EditText ed_phone; private EditText ed_captcha;//點擊獲取驗證碼按鈕證碼按鈕 private Button btn_captcha; private EditText ed_pass; private Button btn_find; // private TimeCount time;//驗證碼倒計時 private int s = 0; private int time = 60; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { iv_left = (ImageView) findViewById(R.id.iv_left); ed_phone = (EditText) findViewById(R.id.ed_phone); ed_captcha = (EditText) findViewById(R.id.ed_captcha); btn_captcha = (Button) findViewById(R.id.btn_captcha); ed_pass = (EditText) findViewById(R.id.ed_pass); btn_find = (Button) findViewById(R.id.btn_find); // time = new TimeCount(60000, 1000);//構造CountDownTimer對象 btn_captcha.setOnClickListener(this); btn_find.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_captcha: Random random = new Random(); s = random.nextInt(1000) + 8999; //通知 NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //延時發送 PendingIntent pend = PendingIntent.getActivity(this, 0, new Intent(MainActivity.this, MainActivity.class), 0); NotificationCompat.Builder buli = new NotificationCompat.Builder(this); buli.setDefaults(Notification.DEFAULT_VIBRATE);//默認震動 buli.setTicker("請查收你的驗證碼!!!"); buli.setSmallIcon(R.mipmap.ic_launcher); buli.setContentTitle("驗證碼提示:"); buli.setContentText("您的驗證碼為:" + s + ",不要隨便給別人看你的驗證碼,請不要上當"); buli.setContentIntent(pend); buli.setNumber(1); buli.setWhen(System.currentTimeMillis()); Notification notification = buli.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(1, notification); CountDownTimer timer = new CountDownTimer(60 * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { // TODO Auto-generated method stub btn_captcha.setText("還剩" + millisUntilFinished / 1000 + "s"); btn_captcha.setEnabled(false); } @Override public void onFinish() { btn_captcha.setText("倒計時完畢了"); btn_captcha.setEnabled(true); } }.start(); // if (btn_captcha.getText().toString().equals("獲取驗證碼")){ // btn_captcha.setBackgroundColor(getResources().getColor(R.color.colorAccent)); // }else { // btn_captcha.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); // } break; case R.id.btn_find: submit(); break; } } private void submit() { // validate String phone = ed_phone.getText().toString().trim(); if (TextUtils.isEmpty(phone)) { Toast.makeText(this, "請輸入手機號", Toast.LENGTH_SHORT).show(); return; } String captcha = ed_captcha.getText().toString().trim(); if (TextUtils.isEmpty(captcha)) { Toast.makeText(this, "驗證碼", Toast.LENGTH_SHORT).show(); return; } String pass = ed_pass.getText().toString().trim(); if (TextUtils.isEmpty(pass)) { Toast.makeText(this, "請輸入密碼", Toast.LENGTH_SHORT).show(); return; } // TODO validate success, do something if (captcha.equals(s)) { Toast.makeText(MainActivity.this, "您輸入的驗證碼有誤,請重新獲取", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "成功找回密碼", Toast.LENGTH_SHORT).show(); startActivity(new Intent(this, MainActivity.class)); } } } // /** // * 驗證碼倒計時 // */ // class TimeCount extends CountDownTimer { // public TimeCount(long millisInFuture, long countDownInterval) { // super(millisInFuture, countDownInterval);//參數依次為總時長,和計時的時間間隔 // } // // @Override // public void onTick(long l) { // btn_captcha.setClickable(false); // btn_captcha.setText("剩余"+1/ 60 + "秒"); // } // // //計時完畢時觸發 // @Override // public void onFinish() { // btn_captcha.setText("重新獲取"); // btn_captcha.setClickable(true); // } // } // /** // * 獲取驗證碼請求 // */ // private void getVerifyMessage() { // //驗證碼獲取成功後 // btn_captcha.setEnabled(false); // } // // /** // * 開始計時 // */ // private void startRockOn() { // // time.start();//開始計時 // }

package jiyun.com.example.lenovo.android_myfindpass;
import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.os.CountDownTimer;import android.support.v7.app.NotificationCompat;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.Toast;
import java.util.Random;
public class MainActivity extends Activity implements View.OnClickListener {
private ImageView iv_left; private EditText ed_phone; private EditText ed_captcha;//點擊獲取驗證碼按鈕證碼按鈕 private Button btn_captcha; private EditText ed_pass; private Button btn_find;// private TimeCount time;//驗證碼倒計時 private int s = 0; private int time = 60;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); }
private void initView() { iv_left = (ImageView) findViewById(R.id.iv_left); ed_phone = (EditText) findViewById(R.id.ed_phone); ed_captcha = (EditText) findViewById(R.id.ed_captcha); btn_captcha = (Button) findViewById(R.id.btn_captcha); ed_pass = (EditText) findViewById(R.id.ed_pass); btn_find = (Button) findViewById(R.id.btn_find);
// time = new TimeCount(60000, 1000);//構造CountDownTimer對象

btn_captcha.setOnClickListener(this); btn_find.setOnClickListener(this); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_captcha: Random random = new Random(); s = random.nextInt(1000) + 8999; //通知 NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //延時發送 PendingIntent pend = PendingIntent.getActivity(this, 0, new Intent(MainActivity.this, MainActivity.class), 0); NotificationCompat.Builder buli = new NotificationCompat.Builder(this); buli.setDefaults(Notification.DEFAULT_VIBRATE);//默認震動 buli.setTicker("請查收你的驗證碼!!!"); buli.setSmallIcon(R.mipmap.ic_launcher); buli.setContentTitle("驗證碼提示:"); buli.setContentText("您的驗證碼為:" + s + ",不要隨便給別人看你的驗證碼,請不要上當"); buli.setContentIntent(pend); buli.setNumber(1); buli.setWhen(System.currentTimeMillis()); Notification notification = buli.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(1, notification);
CountDownTimer timer = new CountDownTimer(60 * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { // TODO Auto-generated method stub btn_captcha.setText("還剩" + millisUntilFinished / 1000 + "s"); btn_captcha.setEnabled(false); }
@Override public void onFinish() { btn_captcha.setText("倒計時完畢了"); btn_captcha.setEnabled(true); } }.start();
// if (btn_captcha.getText().toString().equals("獲取驗證碼")){// btn_captcha.setBackgroundColor(getResources().getColor(R.color.colorAccent));// }else {// btn_captcha.setBackgroundColor(getResources().getColor(R.color.colorPrimary));// } break; case R.id.btn_find: submit(); break; } }
private void submit() { // validate String phone = ed_phone.getText().toString().trim(); if (TextUtils.isEmpty(phone)) { Toast.makeText(this, "請輸入手機號", Toast.LENGTH_SHORT).show(); return; }
String captcha = ed_captcha.getText().toString().trim(); if (TextUtils.isEmpty(captcha)) { Toast.makeText(this, "驗證碼", Toast.LENGTH_SHORT).show(); return; }
String pass = ed_pass.getText().toString().trim(); if (TextUtils.isEmpty(pass)) { Toast.makeText(this, "請輸入密碼", Toast.LENGTH_SHORT).show(); return; }
// TODO validate success, do something
if (captcha.equals(s)) { Toast.makeText(MainActivity.this, "您輸入的驗證碼有誤,請重新獲取", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "成功找回密碼", Toast.LENGTH_SHORT).show(); startActivity(new Intent(this, MainActivity.class));
}

}}
// /**// * 驗證碼倒計時// */// class TimeCount extends CountDownTimer {// public TimeCount(long millisInFuture, long countDownInterval) {// super(millisInFuture, countDownInterval);//參數依次為總時長,和計時的時間間隔// }//// @Override// public void onTick(long l) {// btn_captcha.setClickable(false);// btn_captcha.setText("剩余"+1/ 60 + "秒");// }//// //計時完畢時觸發// @Override// public void onFinish() {// btn_captcha.setText("重新獲取");// btn_captcha.setClickable(true);// }// }// /**// * 獲取驗證碼請求// */// private void getVerifyMessage() {// //驗證碼獲取成功後// btn_captcha.setEnabled(false);// }//// /**// * 開始計時// */// private void startRockOn() {//// time.start();//開始計時// }

密碼找回業務邏輯