Android最全android验证验证码界面ui实现倒计时实现,2024年最新2024-2024蚂蚁金服Android面试真题解析

最后

对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。

同时我经过多年的收藏目前也算收集到了一套完整的学习资料以及高清详细的Android架构进阶学习导图及笔记分享给大家,希望对想成为架构师的朋友有一定的参考和帮助。

下面是部分资料截图,诚意满满:特别适合有开发经验的Android程序员们学习。

不论遇到什么困难,都不应该成为我们放弃的理由!

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言,一定会认真查询,修正不足,谢谢。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

//variables

private String code;

private int padding_left, padding_top;

private Random random = new Random();

public Bitmap createBitmap() {

padding_left = 0;

Bitmap bp = Bitmap.createBitmap(width, height, Config.ARGB_8888);

Canvas c = new Canvas(bp);

code = createCode();

c.drawColor(Color.WHITE);

Paint paint = new Paint();

paint.setTextSize(font_size);

for (int i = 0; i < code.length(); i++) {

randomTextStyle(paint);

randomPadding();

c.drawText(code.charAt(i) + “”, padding_left, padding_top, paint);

}

for (int i = 0; i < line_number; i++) {

drawLine(c, paint);

}

c.save( Canvas.ALL_SAVE_FLAG );

c.restore();//

return bp;

}

public String getCode() {

return code;

}

private String createCode() {

StringBuilder buffer = new StringBuilder();

for (int i = 0; i < codeLength; i++) {

buffer.append(CHARS[random.nextInt(CHARS.length)]);

}

return buffer.toString();

}

private void drawLine(Canvas canvas, Paint paint) {

int color = randomColor();

int startX = random.nextInt(width);

int startY = random.nextInt(height);

int stopX = random.nextInt(width);

int stopY = random.nextInt(height);

paint.setStrokeWidth(1);

paint.setColor(color);

canvas.drawLine(startX, startY, stopX, stopY, paint);

}

private int randomColor() {

return randomColor(1);

}

private int randomColor(int rate) {

int red = random.nextInt(256) / rate;

int green = random.nextInt(256) / rate;

int blue = random.nextInt(256) / rate;

return Color.rgb(red, green, blue);

}

private void randomTextStyle(Paint paint) {

int color = randomColor();

paint.setColor(color);

paint.setFakeBoldText(random.nextBoolean());

float skewX = random.nextInt(11) / 10;

skewX = random.nextBoolean() ? skewX : -skewX;

paint.setTextSkewX(skewX);

}

private void randomPadding() {

padding_left += base_padding_left + random.nextInt(range_padding_left);

padding_top = base_padding_top + random.nextInt(range_padding_top);

}

}

内部提供方法初始化和获取验证码内容

image_code.setImageBitmap(Code.getInstance().createBitmap()); //初始化验证码

Code.getInstance().getCode(); //获取验证码

计时器


public abstract class CountDownTimer {

/**

  • Millis since epoch when alarm should stop.

执行的总时间

*/

private final long mMillisInFuture;

/**

  • The interval in millis that the user receives callbacks

时间间隔

*/

private final long mCountdownInterval;

// 停止时间

private long mStopTimeInFuture;

/**

  • @param millisInFuture The number of millis in the future from the call

  • to {@link #start()} until the countdown is done and {@link #onFinish()}

  • is called.

  • @param countDownInterval The interval along the way to receive

  • {@link #onTick(long)} callbacks.

两参数构造函数,总时间,时间间隔

*/

public CountDownTimer(long millisInFuture, long countDownInterval) {

mMillisInFuture = millisInFuture;

mCountdownInterval = countDownInterval;

}

/**

  • Cancel the countdown.

取消到timer

*/

public final void cancel() {

mHandler.removeMessages(MSG);

}

/**

  • Start the countdown.

开始

*/

public synchronized final CountDownTimer start() {

if (mMillisInFuture <= 0) {

onFinish();

return this;

}

// 停止时间 = 系统启动时间 + 总计时间

mStopTimeInFuture = SystemClock.elapsedRealtime() + mMillisInFuture;

mHandler.sendMessage(mHandler.obtainMessage(MSG));

return this;

}

/**

  • Callback fired on regular interval.

  • @param millisUntilFinished The amount of time until finished.

*/

public abstract void onTick(long millisUntilFinished);

/**

  • Callback fired when the time is up.

*/

public abstract void onFinish();

private static final int MSG = 1;

// handles counting down

private Handler mHandler = new Handler() {

@Override

public void handleMessage(Message msg) {

synchronized (CountDownTimer.this) {

// 计算剩余总时间

final long millisLeft = mStopTimeInFuture - SystemClock.elapsedRealtime();

// 小于等于 0 ,回调 onFinish

if (millisLeft <= 0) {

onFinish();

} else if (millisLeft < mCountdownInterval) { // 小于计时间隔 ,delayed 一个消息

// no tick, just delay until done

sendMessageDelayed(obtainMessage(MSG), millisLeft);

} else {

long lastTickStart = SystemClock.elapsedRealtime();

onTick(millisLeft);

// take into account user’s onTick taking time to execute

long delay = lastTickStart + mCountdownInterval - SystemClock.elapsedRealtime();

// special case: user’s onTick took more than interval to

// complete, skip to next interval

while (delay < 0) delay += mCountdownInterval;

sendMessageDelayed(obtainMessage(MSG), delay);

}

}

}

};

使用:倒计时

final CountDownTimer timer = new CountDownTimer(60000, 1000) {

@Override

public void onTick(long millisUntilFinished) {

get_verfiy_code.setText(millisUntilFinished/1000 + “秒”);

}

@Override

public void onFinish() {

get_verfiy_code.setEnabled(true);

get_verfiy_code.setText(“获取验证码”);

}

};

点击按钮的时候:

get_verfiy_code.setEnabled(false);

timer.start();

popupwinow全部如下:

/**

  • Created by

  • xiaomi on 2017/9/8.

*/

public class VerifyPopupWindow {

/**

  • 手机验证popupwindow

*/

private EditText phone_number;

private EditText input_image_code;

private ImageView image_code;

private EditText input_code;

private Button sure;

private String inputcode;

private String realCode;

private Button no_verify;

private CustomPopWindow mPopWindow;

private Button get_verfiy_code;

private Context mContext;

public VerifyPopupWindow(Context context){

this.mContext=context;

}

public void showPopupWindow(){

View contentView = LayoutInflater.from(mContext).inflate(R.layout.user_phone_number, null);

phone_number = (EditText) contentView.findViewById(R.id.phone_number); //填入手机号

input_image_code=(EditText)contentView.findViewById(R.id.input_image_code);//填入图片验证码

image_code=(ImageView)contentView.findViewById(R.id.image_code); //图片验证码

input_code=(EditText) contentView.findViewById(R.id.input_code); //填入手机验证码

sure=(Button)contentView.findViewById(R.id.user_verfiy_submit); //确定绑定

no_verify=(Button)contentView.findViewById(R.id.ignore_verfiy_submit); //暂不验证

get_verfiy_code=(Button)contentView.findViewById(R.id.get_verfiy_code);//获取手机验证码

final CountDownTimer timer = new CountDownTimer(60000, 1000) {

@Override

public void onTick(long millisUntilFinished) {

get_verfiy_code.setText(millisUntilFinished/1000 + “秒”);

}

@Override

public void onFinish() {

get_verfiy_code.setEnabled(true);

get_verfiy_code.setText(“获取验证码”);

}

};

image_code.setImageBitmap(Code.getInstance().createBitmap()); //初始化验证码

View.OnClickListener listener = new View.OnClickListener() {

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.image_code:

image_code.setImageBitmap(Code.getInstance().createBitmap());

break;

case R.id.user_verfiy_submit:

最后

给大家分享一份移动架构大纲,包含了移动架构师需要掌握的所有的技术体系,大家可以对比一下自己不足或者欠缺的地方有方向的去学习提升;

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

new View.OnClickListener() {

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.image_code:

image_code.setImageBitmap(Code.getInstance().createBitmap());

break;

case R.id.user_verfiy_submit:

最后

给大家分享一份移动架构大纲,包含了移动架构师需要掌握的所有的技术体系,大家可以对比一下自己不足或者欠缺的地方有方向的去学习提升;

[外链图片转存中…(img-Lf8YBo0g-1715229937265)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值