安卓手机工具类

淩亂°似流年 2023-10-03 17:59 116阅读 0赞
  1. import android.content.Context;
  2. import android.content.Intent;
  3. import android.content.res.ColorStateList;
  4. import android.net.Uri;
  5. import android.os.CountDownTimer;
  6. import android.text.TextUtils;
  7. import android.widget.TextView;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. /**
  11. * Created by wuxy on 2017/5/19.
  12. */
  13. public class PhoneUtils {
  14. //拨打电话
  15. public static void call(Context context, String phone) {
  16. if (context == null) {
  17. return;
  18. }
  19. Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
  20. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  21. context.startActivity(intent);
  22. }
  23. /* *//**验证手机号码
  24. * @param mobiles
  25. * @return
  26. *//*
  27. public static boolean isMobleNo(String mobiles){
  28. String telRegex = "[1][345789]\\d{9}";//"[1]"代表第1位为数字1,"[34578]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
  29. if (TextUtils.isEmpty(mobiles)) return false;
  30. else return mobiles.matches(telRegex);
  31. }*/
  32. /**
  33. * 验证手机格式
  34. */
  35. public static boolean isMobleNo(String phone) {
  36. boolean flag = true;
  37. String regex = "^((13[0-9])|(14[5|7|9])|(15([0-3]|[5-9]))|(16[6])|(17[013678])|(18[0-9])|(19[8|9]))\\d{8}$";
  38. if (phone.length() != 11 || TextUtils.isEmpty(phone)) {
  39. flag = false;
  40. return flag;
  41. } else {
  42. Pattern p = Pattern.compile(regex);
  43. Matcher m = p.matcher(phone);
  44. boolean isMatch = m.matches();
  45. if (!isMatch) {
  46. flag = false;
  47. }
  48. }
  49. return flag;
  50. }
  51. /**
  52. * 验证电话号码
  53. *
  54. * @param tel
  55. * @return
  56. */
  57. public static boolean isTelNo(String tel) {
  58. // Pattern p = Pattern.compile("^(0\\d{2,3}-\\d{7,8}(-\\d{3,5}){0,1})|(1[3578]\\d{9})$");
  59. Pattern p = Pattern.compile("^(400|800)([0-9\\\\-]{7,10})|(0?[0-9]{3}(-| )?)?([0-9]{7,8})$");
  60. Matcher m = p.matcher(tel);
  61. return m.matches();
  62. }
  63. /**
  64. * 验证是否为手机号或电话号
  65. *
  66. * @param phoneNumber
  67. * @return
  68. */
  69. public static boolean isPhoneNumber(String phoneNumber) {
  70. return isMobleNo(phoneNumber) || isTelNo(phoneNumber);
  71. }
  72. /**
  73. * 隐藏手机号中间四位
  74. *
  75. * @param phone
  76. * @return
  77. */
  78. public static String formatPhone(String phone) {
  79. return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
  80. }
  81. /* public static String formatDisplayPhoneByPermission(Context context, String phone) {
  82. if (!SpDataUtils.getIsLogin(context)) {
  83. return formatPhone(phone);
  84. } else {
  85. return phone;
  86. }
  87. }*/
  88. /**
  89. * 获取验证码倒计时
  90. */
  91. public static void setRegisterTimeCount(final TextView view, long fen, long miao) {
  92. CountDownTimer timer = new CountDownTimer(fen, miao) {
  93. ColorStateList originalColor = view.getTextColors();
  94. @Override
  95. public void onTick(long millisUntilFinished) {
  96. view.setEnabled(false);
  97. view.setAllCaps(false);
  98. view.setTextColor(0xfff47f32);
  99. view.setText(millisUntilFinished / 1000 + "s");
  100. }
  101. @Override
  102. public void onFinish() {
  103. view.setText("重新发送");
  104. view.setTextColor(originalColor);
  105. view.setEnabled(true);
  106. }
  107. };
  108. timer.start();
  109. }
  110. }

发表评论

表情:
评论列表 (有 0 条评论,116人围观)

还没有评论,来说两句吧...

相关阅读

    相关 手机图标尺寸

      应用程序图标 (Icon)应当是一个 Alpha 通道透明的32位 PNG 图片。由于安卓设备众多,一个应用程序图标需要设计几种不同大小,如: LDPI (Low

    相关 adb控制手机

           最近做项目发现同事做的Api能够让电脑通过USB控制手机进行操作,原来用的是谷歌开发的adb。简单说一下如何控制手机拍照吧,其他的以后接触到了再补上。