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:
if (TextUtils.isEmpty(phone_number.getText().toString())){
Toast.makeText(mContext,“请您输入手机号码”, Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(input_code.getText().toString())){
Toast.makeText(mContext,“请您输入手机验证码”, Toast.LENGTH_SHORT).show();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
【附】相关架构及资料
资料领取
点击这里免费获取Android IOC架构设计等资料
0572263739)]
[外链图片转存中…(img-SJGRiueG-1710572263740)]
[外链图片转存中…(img-xGVZ8X7z-1710572263740)]
[外链图片转存中…(img-QS3Ok98V-1710572263741)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-d1J4MeoC-1710572263741)]
【附】相关架构及资料
[外链图片转存中…(img-ksGNJkUh-1710572263742)]
[外链图片转存中…(img-bjaaELuJ-1710572263742)]
资料领取
点击这里免费获取Android IOC架构设计等资料
领取获取往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter全方面的Android进阶实践技术,群内还有技术大牛一起讨论交流解决问题。