实例介绍
【实例简介】
【实例截图】

【核心代码】
package com.haodai.quickloan.activity;
import com.haodai.quickloan.R;
import com.haodai.quickloan.R.layout;
import com.haodai.quickloan.R.menu;
import com.haodai.quickloan.SmsContent;
import com.haodai.quickloan.bean.VerificationResult;
import com.haodai.quickloan.parser.JsonParser;
import com.haodai.quickloan.utils.Constans;
import com.haodai.quickloan.utils.RegexUtils;
import android.net.Uri;
import android.nfc.tech.IsoDep;
import android.os.Bundle;
import android.os.Handler;
import android.R.integer;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class RegisterActivity extends BaseActivity implements TextWatcher, OnClickListener, AnimatorListener {
View registerSheet;
EditText userName;
EditText passWord;
EditText phoneNo;
TextView descForRegister;
Button btnToVerify;
Dialog progressDialog;
Button btnToLogin;
TextView countDown;
EditText etForVerificationCode;
Button veriCodeAgain;
View verificationCodeSheet;
SmsContent content;
String currentPhoneNo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initViews();
setListener();
if (registerSheet.getVisibility()==View.GONE) {
showRegisterSheet();
}
content = new SmsContent(RegisterActivity.this, new Handler(), etForVerificationCode);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
// 注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
this.getContentResolver().unregisterContentObserver(content);
}
private void initViews(){
registerSheet = findViewById(R.id.registersheet);
userName = (EditText) findViewById(R.id.username);
passWord = (EditText) findViewById(R.id.password);
phoneNo = (EditText) findViewById(R.id.phoneno);
descForRegister = (TextView) findViewById(R.id.descForRegister);
btnToVerify = (Button) findViewById(R.id.btnToVerify);
verificationCodeSheet = findViewById(R.id.verificationCodeSheet);
btnToLogin = (Button) findViewById(R.id.btnToLogin);
countDown = (TextView) findViewById(R.id.countDown);
etForVerificationCode = (EditText) findViewById(R.id.etForVerificationCode);
veriCodeAgain = (Button) findViewById(R.id.veriCodeAgain);
}
private void setListener(){
phoneNo.addTextChangedListener(this);
btnToVerify.setOnClickListener(this);
btnToLogin.setOnClickListener(this);
veriCodeAgain.setOnClickListener(this);
}
private void showRegisterSheet(){
Animation animation = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.registersheet_in);
registerSheet.setAnimation(animation);
registerSheet.setVisibility(View.VISIBLE);
}
private void hideRegisterSheet(){
if (registerSheet.getVisibility() == View.VISIBLE) {
currentPhoneNo = phoneNo.getText().toString().trim();
Animation animation = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.registersheet_out);
registerSheet.setAnimation(animation);
registerSheet.setVisibility(View.GONE);
}
}
private void showVerificationCodeSheet(){
Animation animation = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.registersheet_in);
verificationCodeSheet.setAnimation(animation);
verificationCodeSheet.setVisibility(View.VISIBLE);
}
private void hideVerificationCodeSheet(){
Animation animation = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.registersheet_out);
verificationCodeSheet.setAnimation(animation);
verificationCodeSheet.setVisibility(View.GONE);
}
private boolean isUserNameVaild(){
String userNameString = userName.getText().toString().trim();
StringBuffer sb = new StringBuffer();
String tempStr ;
int count=0;
for(int i = 0;i<userNameString.length();i ){
tempStr = String.valueOf(userNameString.charAt(i)).trim();
if(tempStr.getBytes().length==3){
count ;
sb.append(tempStr);
}
}
if (sb.toString().equals(userNameString)&&count>1&&count<5) {
return true;
}
return false;
}
private boolean isPasswordValid(){
String passWordString = passWord.getText().toString().trim();
return RegexUtils.checkPassword(passWordString);
}
private boolean isRegisterInfoValid(){
return true;
}
private boolean submitRegisterInfoToServer(){
return true;
}
private String getVerificationCode(String phoneNoString){
String verificationCode = null;
return verificationCode;
}
private void requestVerificationCode(){
requestUrl(Constans.Url.requestVeriCodePrefix currentPhoneNo, null);
}
private void hideKeyboard(){
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (btnToVerify.getVisibility() == View.GONE) {
if (!userName.getText().toString().trim().isEmpty()&&!passWord.getText().toString().trim().isEmpty()) {
descForRegister.setVisibility(View.GONE);
btnToVerify.setVisibility(View.VISIBLE);
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
private void showProgressDialog(Context context,String message){
View view = LayoutInflater.from(context).inflate(R.layout.registerloginprogress, null);
TextView textView = (TextView) view.findViewById(R.id.message);
textView.setText(message);
progressDialog = new Dialog(context, R.style.progressdialog);
progressDialog.setContentView(view);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
private void cancelProgressDialog(){
progressDialog.cancel();
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.btnToVerify:
if (isRegisterInfoValid()) {
hideRegisterSheet();
showProgressDialog(baseActivity, "验证中,请稍后....");
requestVerificationCode();
}
break;
case R.id.veriCodeAgain:
requestVerificationCode();
break;
case R.id.btnToLogin:
if (isVerificationCodeValid()) {
hideVerificationCodeSheet();
showProgressDialog(baseActivity, "登录中,请稍后....");
// cancelProgressDialog();
}
break;
default:
break;
}
}
private boolean login(){
return true;
}
@Override
public void responseSucess(String respone, String url) {
// TODO Auto-generated method stub
super.responseSucess(respone, url);
if (verificationCodeSheet.getVisibility() == View.GONE) {
cancelProgressDialog();
showVerificationCodeSheet();
}
VerificationResult verificationResult = JsonParser.parseVerificationResult(respone);
if (verificationResult!=null) {
if (verificationResult.getExpired_time()!=null) {
showCountDownAnimation(Integer.valueOf(verificationResult.getExpired_time()));
}
}
}
private void showCountDownAnimation(int countDownBegin){
AnimCountDown animCountDown = new AnimCountDown(countDown);
ObjectAnimator objectAnimator = ObjectAnimator.ofInt(animCountDown, "x",countDownBegin,1);
objectAnimator.setDuration(99*500);
objectAnimator.addListener(this);
objectAnimator.start();
}
class AnimCountDown{
int x;
TextView btn;
public AnimCountDown(TextView btn) {
super();
this.btn = btn;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
btn.setText("离下次获取验证码还有" x "秒");
}
}
@Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
veriCodeAgain.setClickable(true);
veriCodeAgain.setAlpha(1f);
}
@Override
public void onAnimationEnd(Animator arg0) {
// TODO Auto-generated method stub
veriCodeAgain.setClickable(true);
veriCodeAgain.setAlpha(1f);
countDown.setText("请在上面的编辑框中输入短信中的验证码");
}
@Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
veriCodeAgain.setClickable(false);
veriCodeAgain.setAlpha(0.3f);
}
private boolean isVerificationCodeValid(){
String verificationCode = etForVerificationCode.getText().toString().trim();
return true;
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论