package com.bigdo.util; import java.math.BigDecimal; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.bigdo.app.Main_Activity; import com.bigdo.app.R; import com.bigdo.common.RConfig; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Parcelable; public final class Pub { public static String handleDownVideoUrl(String url) { StringBuilder sb = new StringBuilder(url.length() * 4 / 3); String c = ""; int lg = url.length(); for (int i = 0; i < lg; i++) { c = url.substring(i, i + 1); if (c.matches("[^a-zA-Z0-9\\_\\/\\.:\\-=\\&\\?]")) { sb.append(Uri.encode(c)); } else { sb.append(c); } } return sb.toString(); } /** * 手机号验证 * * @param str * @return 验证通过返回true */ public static boolean isMobilePhone(String str) { if (str != null) { str = str.trim(); if (!str.equals("")) { Pattern p = null; Matcher m = null; boolean b = false; p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号 m = p.matcher(str); b = m.matches(); return b; } } return false; } /** * 电话号码验证 * * @param str * @return 验证通过返回true */ public static boolean isPhone(String str) { Pattern p1 = null, p2 = null; Matcher m = null; boolean b = false; p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的 p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的 if (str.length() > 9) { m = p1.matcher(str); b = m.matches(); } else { m = p2.matcher(str); b = m.matches(); } return b; } public static boolean isEmail(String email) { String str = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"; Pattern p = Pattern.compile(str); Matcher m = p.matcher(email); return m.matches(); } public static double sum(double d1, double d2) { BigDecimal bd1 = new BigDecimal(Double.toString(d1)); BigDecimal bd2 = new BigDecimal(Double.toString(d2)); return bd1.add(bd2).doubleValue(); } public static double sub(double d1, double d2) { BigDecimal bd1 = new BigDecimal(Double.toString(d1)); BigDecimal bd2 = new BigDecimal(Double.toString(d2)); return bd1.subtract(bd2).doubleValue(); } /** * * 创建桌面快捷方式 */ public static void createSystemSwitcherShortCut(Context context) { final Intent addIntent = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); final Parcelable icon = Intent.ShortcutIconResource.fromContext( context, R.drawable.applogo); // 获取快捷键的图标 addIntent.putExtra("duplicate", false); final Intent myIntent = new Intent(context, Main_Activity.class); myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); myIntent.setAction("android.intent.action.MAIN"); // 绑定快捷方式和应用程序 myIntent.setAction("android.intent.category.DEFAULT"); myIntent.addCategory("android.intent.category.LAUNCHER"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));// 快捷方式的标题 addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标 addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作 context.sendBroadcast(addIntent); } }