From 78936d7814c43551a6bbe671636659184bec736f Mon Sep 17 00:00:00 2001 From: November <1562064520@qq.com> Date: Mon, 21 Apr 2025 10:19:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/login/RegisterResultActivity.java | 8 +- .../digitalagriculture/utils/ToolUtil.java | 1041 +++++++++++++++++ .../res/layout/activity_register_result.xml | 1 + 3 files changed, 1047 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/yinhetairui/digitalagriculture/utils/ToolUtil.java diff --git a/app/src/main/java/com/yinhetairui/digitalagriculture/ui/login/RegisterResultActivity.java b/app/src/main/java/com/yinhetairui/digitalagriculture/ui/login/RegisterResultActivity.java index 403f4ab..5573f7c 100644 --- a/app/src/main/java/com/yinhetairui/digitalagriculture/ui/login/RegisterResultActivity.java +++ b/app/src/main/java/com/yinhetairui/digitalagriculture/ui/login/RegisterResultActivity.java @@ -4,6 +4,8 @@ import android.content.Context; import android.content.Intent; import android.view.View; +import androidx.appcompat.widget.AppCompatTextView; + import com.hjq.bar.TitleBar; import com.hjq.shape.view.ShapeButton; import com.yinhetairui.digitalagriculture.R; @@ -18,11 +20,10 @@ import com.yinhetairui.digitalagriculture.app.AppActivity; public final class RegisterResultActivity extends AppActivity { private TitleBar title; + private AppCompatTextView tvHint; private ShapeButton btnLogin; - /** - * 来源:0-注册,1-忘记密码 - */ + /** 来源:0-注册,1-忘记密码 */ private int mSource = 0; public static void start(Context context, int source) { @@ -39,6 +40,7 @@ public final class RegisterResultActivity extends AppActivity { @Override protected void initView() { title = (TitleBar) findViewById(R.id.title); + tvHint = (AppCompatTextView) findViewById(R.id.tv_hint); btnLogin = (ShapeButton) findViewById(R.id.btn_login); setOnClickListener(btnLogin); diff --git a/app/src/main/java/com/yinhetairui/digitalagriculture/utils/ToolUtil.java b/app/src/main/java/com/yinhetairui/digitalagriculture/utils/ToolUtil.java new file mode 100644 index 0000000..dfe38a1 --- /dev/null +++ b/app/src/main/java/com/yinhetairui/digitalagriculture/utils/ToolUtil.java @@ -0,0 +1,1041 @@ +package com.yinhetairui.digitalagriculture.utils; + +import android.app.Activity; +import android.app.ActivityManager; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.graphics.Point; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.Uri; +import android.os.Build; +import android.text.TextUtils; +import android.view.Display; +import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; + +import androidx.core.app.NotificationManagerCompat; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.regex.Pattern; + +import static java.math.BigDecimal.ROUND_HALF_UP; + +/** + * TODO 通用工具类 + * + * @Author ZhaoQy + * @Date 2017/12/26. + */ +public class ToolUtil { + + public static final String ZH_PHONE = "^(\\+?0?86\\-?)?1[3456789]\\d{9}$"; + public static final String EN_PHONE = "^(\\+?1)?[2-9]\\d{2}[2-9](?!11)\\d{6}$"; + //密码必须由字母、数字组成,区分大小写;密码长度为8-20位 + public static final String CHARE_NUM_PWD = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$"; + //密码必须由字母、数字、特殊符号组成,区分大小写;特殊符号包含(. _ ~ ! @ # $ ^ & *);密码长度为6-16位 + public static final String CHARE_NUM_PWD_TWO = "^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[._~!@#$^&*])[A-Za-z0-9._~!@#$^&*]{6,16}$"; + /** + * 正则表达式:验证邮箱 + */ + public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; + + /** + * 校验中国或美国手机号码 + * + * @param countryCode + * @param phone + * @return + */ + public static boolean checkPhone(String countryCode, String phone) { + if ("+1".equals(countryCode)) { + return (countryCode + phone).matches(EN_PHONE); + } else if ("+86".equals(countryCode)) { + return (countryCode + phone).matches(ZH_PHONE); + } + return false; + } + + /** + * 校验密码 8-20位 同时包含字母和数字 + * + * @param pwd + * @return + */ + public static boolean checkPwd(String pwd) { + return Pattern.matches(CHARE_NUM_PWD, pwd); + } + + /** + * 校验邮箱 + * + * @param email + * @return + */ + public static boolean checkEmail(String email) { + return Pattern.matches(REGEX_EMAIL, email); + } + + /** + * 最后点击时间 + */ + private static long lastClickTime; + + /** + * 判断是否以在短时间内点击 + * + * @return + */ + public static boolean isFastDoubleClick() { + long time = System.currentTimeMillis(); + if (time - lastClickTime < 500) { + return true; + } + lastClickTime = time; + return false; + } + + /** + * 获取当前的版本名 + * + * @param context + * @return 版本名 + */ + public static String getVersionName(Context context) { + String versionName = ""; + try { + PackageManager packageManager = context.getPackageManager(); + PackageInfo packageInfo = packageManager.getPackageInfo( + context.getPackageName(), 0); + versionName = packageInfo.versionName; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return versionName; + } + + /** + * 获取当前的版本号 + * + * @param context + * @return 版本号 + */ + public static int getVersionCode(Context context) { + int versionCode = 1; + try { + PackageManager packageManager = context.getPackageManager(); + PackageInfo packageInfo = packageManager.getPackageInfo( + context.getPackageName(), 0); + versionCode = packageInfo.versionCode; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return versionCode; + } + + /** + * 隐藏键盘 + * + * @param activity + */ + public static void hideBrod(Activity activity) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + } + } + + /** + * 两个字符串数字相除 + * + * @param str1 + * @param str2 + * @return + */ + public static String twoStringDivide(String str1, String str2) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.divide(bigDecimal2, 2, RoundingMode.HALF_UP)).toString(); + } + + /** + * 两个字符串数字相除 + * + * @param str1 + * @param str2 + * @param mode + * @return + */ + public static String twoStringDivide(String str1, String str2, RoundingMode mode) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.divide(bigDecimal2, 2, mode)).toString(); + } + + /** + * 两个字符串数字相除 + * + * @param str1 + * @param str2 + * @param mode + * @return + */ + public static String twoStringDivide(String str1, String str2, int scale, RoundingMode mode) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.divide(bigDecimal2, scale, mode)).toString(); + } + + /** + * 两个字符串数字相乘 + * + * @param str1 + * @param str2 + * @return + */ + public static String twoStringMultiply(String str1, String str2) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.multiply(bigDecimal2)).toString(); + } + + /** + * 两个字符串数字相乘 + * + * @param str1 + * @param str2 + * @param mode + * @return + */ + public static String twoStringMultiply(String str1, String str2, RoundingMode mode) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.multiply(bigDecimal2)).toString(); + } + + /** + * 两个字符串数字相加 + * + * @param str1 + * @param str2 + * @return + */ + public static String twoStringAdd(String str1, String str2) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.add(bigDecimal2)).toString(); + } + + /** + * 两个字符串数字相减 + * + * @param str1 + * @param str2 + * @return + */ + public static String twoStringSubtract(String str1, String str2) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return (bigDecimal1.subtract(bigDecimal2)).toString(); + } + + /** + * 比较字符串大小 + * + * @param str1 + * @param str2 + * @return + */ + public static int compareSize(String str1, String str2) { + if (TextUtils.isEmpty(str1)) { + str1 = "0"; + } + if (TextUtils.isEmpty(str2)) { + str2 = "0"; + } + BigDecimal bigDecimal1 = new BigDecimal(str1); + BigDecimal bigDecimal2 = new BigDecimal(str2); + return bigDecimal1.compareTo(bigDecimal2); + } + + /** + * 保留两位小数 + * + * @param decimals + * @return + */ + public static String formatDecimal(String decimals) { + if (TextUtils.isEmpty(decimals)) { + return "0.00"; + } + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).toString(); + } + + public static String formatDecimal(int decimals) { + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).toString(); + } + + public static String formatDecimal(double decimals) { + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).toString(); + } + + /** + * 保留两位小数,并且去掉末尾多余的零 + * + * @param decimals + * @return + */ + public static String formatDecimalTwo(String decimals) { + if (TextUtils.isEmpty(decimals)) { + return "0"; + } + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + } + + public static String formatDecimalTwo(int decimals) { + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + } + + public static String formatDecimalTwo(double decimals) { + return new BigDecimal(decimals).setScale(2, ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + } + + /** + * 去除文本后多余的小数 + * + * @param text + * @return + */ + public static String formatInteger(String text) { + if (!TextUtils.isEmpty(text) && text.indexOf(".") > 0) { + text = text.replaceAll("0+?$", ""); + text = text.replaceAll("[.]$", ""); + return text; + } + return text; + } + + /** + * 将时间字符串转换为时间年月日 + * + * @param s + * @return + */ + public static String dateStrToDate(String s) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = simpleDateFormat.parse(s); + long ts = date.getTime(); + return millionToYMD(ts); + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + /** + * 将时间字符串转换为时间年月日时分 + * + * @param s + * @return + */ + public static String dateStrToDateYMDHM(String s) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date date = simpleDateFormat.parse(s); + String dateStr = simpleDateFormat.format(date); + return dateStr; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + /** + * 将时间戳转换为时间 + * + * @param million + * @return + */ + public static String millionToDate(long million) { + return new SimpleDateFormat("yyyy-MM-dd HH:mm:00").format(new Date(million)); + } + + public static String millionToYMDHM(long million) { + return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(million)); + } + + public static String millionToYMD(long million) { + return new SimpleDateFormat("yyyy-MM-dd").format(new Date(million)); + } + + public static String millionToYM(long million) { + return new SimpleDateFormat("yyyy-MM").format(new Date(million)); + } + + public static String millionToYear(long million) { + return new SimpleDateFormat("yyyy").format(new Date(million)); + } + + public static String millionToMonth(long million) { + return new SimpleDateFormat("MM").format(new Date(million)); + } + + public static String millionToMD(long million) { + return new SimpleDateFormat("MM-dd").format(new Date(million)); + } + + public static String millionToHM(long million) { + return new SimpleDateFormat("HH:mm").format(new Date(million)); + } + + /** + * 获取当前系统时间 + * + * @return + */ + public static Long getNowDate() { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + try { + Date date = format.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm") + .format(new Date(Calendar.getInstance().getTimeInMillis()))); + return date.getTime(); + } catch (ParseException e) { + e.printStackTrace(); + return 0L; + } + } + + /** + * 获取当前时间 + * + * @return + */ + public static String getNowDateString() { + SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String strDate = null; + try { + strDate = sfd.format(new Date()); + } catch (Exception e) { + e.printStackTrace(); + } + return strDate; + } + + /** + * 获取当前时间 + * + * @param format 时间格式 + * @return + */ + public static String getNowDateString(String format) { + SimpleDateFormat sfd = new SimpleDateFormat(format); + String strDate = null; + try { + strDate = sfd.format(new Date()); + } catch (Exception e) { + e.printStackTrace(); + } + return strDate; + } + + /** + * 将时间转换为时间戳 + * + * @param s + * @return + */ + public static Long dateToMillion(String s) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = simpleDateFormat.parse(s); + long ts = date.getTime(); + return ts; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将时间转换为时间戳 + * + * @param s + * @return + */ + public static Long dateToMillions(String s) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date date = simpleDateFormat.parse(s); + long ts = date.getTime(); + return ts; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Long YMDHMToMillion(String s) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date date = simpleDateFormat.parse(s); + long ts = date.getTime(); + return ts; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + //毫秒转秒 + public static String long2String(long time) { + //毫秒转秒 + int sec = (int) time / 1000; + int min = sec / 60; //分钟 + sec = sec % 60; //秒 + if (min < 10) { //分钟补0 + if (sec < 10) { //秒补0 + return "0" + min + ":0" + sec; + } else { + return "0" + min + ":" + sec; + } + } else { + if (sec < 10) { //秒补0 + return min + ":0" + sec; + } else { + return min + ":" + sec; + } + } + } + + /** + * 获取当前天数和后六天的集合 + * + * @return + */ + public static List getSevenDate() { + String mYear; // 当前年 + String mMonth; // 月 + String mDay; + + List dates = new ArrayList(); + final Calendar c = Calendar.getInstance(); + c.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); + + for (int i = 0; i < 7; i++) { + mYear = String.valueOf(c.get(Calendar.YEAR));// 获取当前年份 + mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份 + mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH) + i);// 获取当前日份的日期号码 + if (Integer.parseInt(mDay) > MaxDayFromDay_OF_MONTH(Integer.parseInt(mYear), (i + 1))) { + mDay = String.valueOf(MaxDayFromDay_OF_MONTH(Integer.parseInt(mYear), (i + 1))); + } + String date = mMonth + "." + mDay; + dates.add(date); + } + return dates; + } + + /** + * 得到当年当月的最大日期 + * + * @param year + * @param month + * @return + */ + public static int MaxDayFromDay_OF_MONTH(int year, int month) { + Calendar time = Calendar.getInstance(); + time.clear(); + time.set(Calendar.YEAR, year); + time.set(Calendar.MONTH, month - 1);//注意,Calendar对象默认一月为0 + int day = time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天数 + return day; + } + + /** + * 拨打电话 + * + * @param context + * @param phoneNumber + */ + public static void dialPhoneNumber(Context context, String phoneNumber) { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse("tel:" + phoneNumber)); + //这个判断在Android 11上一直是null,所以采用try catch来预防crash + /*if (intent.resolveActivity(context.getPackageManager()) != null) { + context.startActivity(intent); + }*/ + try { + context.startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 判断网络是否连接 + * + * @param context + * @return + */ + public static boolean isConnected(Context context) { + ConnectivityManager connectivity = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + + if (null != connectivity) { + NetworkInfo info = connectivity.getActiveNetworkInfo(); + if (null != info && info.isConnected()) { + if (info.getState() == NetworkInfo.State.CONNECTED) { + return true; + } + } + } + return false; + } + + /** + * 判断消息通知是否开启 + * + * @param context + * @return + */ + public static boolean isNotificationEnabled(Context context) { + boolean isOpened = false; + try { + isOpened = NotificationManagerCompat.from(context).areNotificationsEnabled(); + } catch (Exception e) { + e.printStackTrace(); + isOpened = false; + } + return isOpened; + } + + /** + * 方法描述:判断某一应用是否正在运行 + * Created by cafeting on 2017/2/4. + * + * @param context 上下文 + * @param packageName 应用的包名 + * @return true 表示正在运行,false 表示没有运行 + */ + public static boolean isAppRunning(Context context, String packageName) { + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + List list = am.getRunningTasks(100); + if (list.size() <= 0) { + return false; + } + for (ActivityManager.RunningTaskInfo info : list) { + if (info.baseActivity.getPackageName().equals(packageName)) { + return true; + } + } + return false; + } + + /** + * 获取当前时区 GMT+08:00 + * + * @return + */ + public static String getCurrentTimeZone() { + char sign = '+'; + int _t = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / (3600 * 1000); + if (_t < 0) { + _t = Math.abs(_t); + sign = '-'; + } + StringBuilder builder = new StringBuilder(9); + builder.append("GMT"); + builder.append(sign); + appendNumber(builder, 2, _t); + builder.append(':'); + appendNumber(builder, 2, 0); + return builder.toString(); + } + + /** + * 获取当前时区 GMT+08 + * + * @return + */ + public static String getCurrentTimeZone1() { + char sign = '+'; + int _t = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / (3600 * 1000); + if (_t < 0) { + _t = Math.abs(_t); + sign = '-'; + } + StringBuilder builder = new StringBuilder(9); + builder.append("GMT"); + builder.append(sign); + appendNumber(builder, 2, _t); + return builder.toString(); + } + + public static void appendNumber(StringBuilder builder, int count, int value) { + String string = Integer.toString(value); + for (int i = 0; i < count - string.length(); i++) { + builder.append('0'); + } + builder.append(string); + } + + /** + * 复制内容到剪切板 + * + * @param copyStr + * @return + */ + public static boolean copy(Context context, String copyStr) { + try { + //获取剪贴板管理器 + ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + // 创建普通字符型ClipData + ClipData mClipData = ClipData.newPlainText("Order number", copyStr); + // 将ClipData内容放到系统剪贴板里。 + cm.setPrimaryClip(mClipData); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 手机号码中间4位置为*号 + * + * @param phoneStr + */ + public static String hidePhone(String phoneStr) { + if (!TextUtils.isEmpty(phoneStr) && phoneStr.length() >= 7) { + StringBuilder builder = new StringBuilder(phoneStr); + builder.replace(3, 7, "****"); + return builder.toString(); + } + return phoneStr; + } + + /** + * 身份证号隐藏中间8位 + * + * @param identityNumber + * @return + */ + public static String hideIdentityNumber(String identityNumber) { + if (!TextUtils.isEmpty(identityNumber) && identityNumber.length() >= 10) { + return identityNumber.substring(0, 6) + "********" + identityNumber.substring(identityNumber.length() - 4, identityNumber.length()); + } + return identityNumber; + } + + /** + * 银行卡号大于8位,隐藏中间的字符串(使用*号),显示前四后四 + * 银行卡号小于8位隐藏前面的字符串(使用*号),显示后四 + * + * @param cardNo + * @return + */ + public static String hideCardNo(String cardNo) { + + if (TextUtils.isEmpty(cardNo)) { + return cardNo; + } + + int length = cardNo.length(); + int beforeLength = 0; + int afterLength = 0; + if (length > 8) { + beforeLength = 4; + afterLength = 4; + } else { + beforeLength = 0; + afterLength = 4; + } + //替换字符串,当前使用“*” + String replaceSymbol = "*"; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + if (i < beforeLength || i >= (length - afterLength)) { + sb.append(cardNo.charAt(i)); + } else { + sb.append(replaceSymbol); + } + } + + return sb.toString(); + } + + /** + * 获取屏幕高度 + * + * @param context + * @return + */ + public static int getScreenHeight(Context context) { + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + final Display display = windowManager.getDefaultDisplay(); + Point outPoint = new Point(); + if (Build.VERSION.SDK_INT >= 19) { + // 可能有虚拟按键的情况 + display.getRealSize(outPoint); + } else { + // 不可能有虚拟按键 + display.getSize(outPoint); + } + int mRealSizeHeight;//手机屏幕真实高度 + mRealSizeHeight = outPoint.y; + return mRealSizeHeight; + } + + /** + * 时间差(秒数)转为:xx:xx:xx + * + * @param eDate + * @return + */ + public static String getTimeDifferenceTwo(String eDate) { + if (TextUtils.isEmpty(eDate)) { + return "00:00:00"; + } + long date = Long.parseLong(eDate); + if (date <= 0) { + return "00:00:00"; + } + long day = date / (60 * 60 * 24); + long hour = (date / (60 * 60) - day * 24); + long min = ((date / 60) - day * 24 * 60 - hour * 60); + long s = (date - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); + if (date > 0) { + if (day != 0) { + return (day * 24 + hour) + ":" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } else if (hour != 0) { + return (hour > 9 ? hour : "0" + hour) + ":" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } else { + return "00:" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } + } else { + return "00:00:00"; + } + } + + /** + * 距离结束时间(含时分秒)的时间差 + * 差的形式为:xx:xx:xx + * + * @param eDate + * @return + * @throws ParseException + */ + public static String getTimeDifference(String eDate) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date startDate = new Date(); + Date endDate = null; + try { + endDate = simpleDateFormat.parse(eDate); + } catch (ParseException e) { + e.printStackTrace(); + } + long date = endDate.getTime() - startDate.getTime(); + long day = date / (1000 * 60 * 60 * 24); + long hour = (date / (1000 * 60 * 60) - day * 24); + long min = ((date / (60 * 1000)) - day * 24 * 60 - hour * 60); + long s = (date / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); + if (date > 0) { + if (day != 0) { + return (day * 24 + hour) + ":" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } else if (hour != 0) { + return (hour > 9 ? hour : "0" + hour) + ":" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } else { + return "00:" + (min > 9 ? min : "0" + min) + ":" + (s > 9 ? s : "0" + s); + } + } else { + return "00:00:00"; + } + } + + /** + * 隐藏名字,找到第一个中文、英文、数字,后面的隐藏显示* + * + * @param nameStr + * @return + */ + public static String hideUserName(String nameStr) { + + if (!TextUtils.isEmpty(nameStr)) { + return nameStr.replaceAll("([\\u4e00-\\u9fa5A-Za-z0-9]{1})(.*)", "$1" + createAsterisk(nameStr.length() - 1)); + } + return nameStr; + } + + //生成很多个*号 + public static String createAsterisk(int length) { + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < length; i++) { + stringBuffer.append("*"); + } + return stringBuffer.toString(); + } + + /** + * 跳转到应用设置界面 + * + * @param context + */ + public static void toSelfSetting(Context context) { + + Intent mIntent = new Intent(); + mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (Build.VERSION.SDK_INT >= 9) { + mIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); + mIntent.setData(Uri.fromParts("package", context.getPackageName(), null)); + } else if (Build.VERSION.SDK_INT <= 8) { + mIntent.setAction(Intent.ACTION_VIEW); + mIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails"); + mIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName()); + } + context.startActivity(mIntent); + + } + + /** + * 大数值格式化 + * + * @param num + * @return + */ + public static String formatBigNumber(String num) { + if (TextUtils.isEmpty(num)) { + return "0.00"; + } + if (compareSize(num, "10000") == -1) { + return num; + } else if (compareSize(num, "10000") == 0) { + return "1W"; + } else { + String w = twoStringDivide(num, "10000", RoundingMode.DOWN); + return w + "W"; + } + } + + /** + * 获取指定时间字符串 + * + * @param dateStr 时间 + * @param targetFormat 转换的目标格式 + * @return + */ + public static String getTimeStr(String dateStr, String targetFormat) { + if (TextUtils.isEmpty(dateStr)) { + return "暂无时间"; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date; + try { + date = sdf.parse(dateStr); + } catch (ParseException e) { + e.printStackTrace(); + return ""; + } + SimpleDateFormat target = new SimpleDateFormat(targetFormat); + return target.format(date); + } + + /** + * 获取指定时间字符串 + * + * @param dateStr 时间 + * @param defaultFormat 传入时间的格式 + * @param targetFormat 转换的目标格式 + * @return + */ + public static String getTimeStr(String dateStr, String defaultFormat, String targetFormat) { + if (TextUtils.isEmpty(dateStr)) { + return "暂无时间"; + } + SimpleDateFormat sdf = new SimpleDateFormat(defaultFormat); + Date date; + try { + date = sdf.parse(dateStr); + } catch (ParseException e) { + e.printStackTrace(); + return ""; + } + SimpleDateFormat target = new SimpleDateFormat(targetFormat); + return target.format(date); + } + + /** + * 判断某App是否安装(防止部分手机默认拒绝读取应用列表) + * + * @param context + * @param pkgName + * @return + */ + public static boolean hasPackage(Context context, String pkgName) { + if (pkgName == null || pkgName.isEmpty()) { + return false; + } + boolean bHas = true; + try { + context.getPackageManager().getPackageInfo(pkgName, PackageManager.GET_GIDS); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + // 抛出找不到的异常,说明该程序已经被卸载 + bHas = false; + } + return bHas; + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_register_result.xml b/app/src/main/res/layout/activity_register_result.xml index 8755a2b..37a2746 100644 --- a/app/src/main/res/layout/activity_register_result.xml +++ b/app/src/main/res/layout/activity_register_result.xml @@ -23,6 +23,7 @@ android:src="@drawable/icon_success" />