亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

封裝類

2019-11-09 14:04:21
字體:
來源:轉載
供稿:網友

1、偶然在下載以為大觸的代碼文件時發現,某大神封裝的Utils類,故保存一下,備用

以下是該封裝類:

package com.example.shopping;import android.annotation.SupPRessLint;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.content.pm.PackageManager.NameNotFoundException;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.telephony.TelephonyManager;import android.text.Editable;import android.text.TextWatcher;import android.view.Display;import android.widget.EditText;import android.widget.Toast;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.math.BigDecimal;import java.security.NoSuchAlgorithmException;import java.text.DateFormat;import java.text.DecimalFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.List;import java.util.Locale;import java.util.UUID;import java.util.regex.Matcher;import java.util.regex.Pattern;/** 工具類 */public class Utils {	// 字符串的非空	public static boolean isEmpty(String input) {		if (input == null || "".equals(input) || "null".equals(input))			return true;		for (int i = 0; i < input.length(); i++) {			char c = input.charAt(i);			if (c != ' ' && c != '/t' && c != '/r' && c != '/n') {				return false;			}		}		return true;	}	// 判斷網絡是否連接	public static boolean isNetworkConnected(Context context) {		if (context != null) {			ConnectivityManager mConnectivityManager = (ConnectivityManager) context					.getSystemService(Context.CONNECTIVITY_SERVICE);			NetworkInfo mNetworkInfo = mConnectivityManager					.getActiveNetworkInfo();			if (mNetworkInfo != null) {				return mNetworkInfo.isAvailable();			}		}		return false;	}	// 驗證手機號	public static boolean isMobileNO(String mobiles) {		// .compile("^((13[0-9]{1})|159|153|189|182)+//d{8}$");		Pattern pattern = Pattern.compile("^(1[3|4|5|6|7|8][0-9])+//d{8}$");		Matcher m = pattern.matcher(mobiles);		return m.matches();	}	// 驗證身份證	public static boolean doAuthentication(String shenfen) {		Pattern pattern = Pattern				.compile("^[1-9]//d{5}[1-9]//d{3}((0//d)|(1[0-2]))(([0|1|2]//d)|3[0-1])//d{3}([0-9]|X)$");		Matcher m = pattern.matcher(shenfen);		return m.matches();	}	// 驗證只能輸入數字和字母	public static boolean InputFigureLetter(String input) {		Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");		Matcher m = pattern.matcher(input);		return m.matches();	}	/**	 * 字符串轉日期(yyyy-MM-dd)	 * */	public static Date StrToDate(String str) {		return StrToDate(str, "yyyy-MM-dd");	}	/**	 * 字符串轉日期()	 * */	public static Date StrToDate2(String str) {		return StrToDate(str, "yyyy-MM-dd HH:mm:ss");	}	/**	 * 得到幾天前的時間	 * 	 * @param d	 * @param day	 * @return	 */	public static Date getDateBefore(Date d, int day) {		Calendar now = Calendar.getInstance();		now.setTime(d);		now.set(Calendar.DATE, now.get(Calendar.DATE) - day);		return now.getTime();	}	/**	 * 得到幾天后的時間	 * 	 * @param d	 * @param day	 * @return	 */	public static Date getDateAfter(Date d, int day) {		Calendar now = Calendar.getInstance();		now.setTime(d);		now.set(Calendar.DATE, now.get(Calendar.DATE) + day);		return now.getTime();	}	/**	 * 得到當前時間之后的幾個小時時間	 * 	 * @param differhour	 * @return	 */	public static String getCurrentHourAfter(int differhour) {		long currenttime = new Date().getTime();		Date dat = new Date(currenttime + 1000 * 60 * 60 * differhour);		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		return format.format(dat);	}	/**	 * 得到當前時間之前的幾個小時時間	 * 	 * @param differhour	 * @return	 */	public static String getCurrentHourBefor(int differhour) {		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",				Locale.ENGLISH);		long currenttime = new Date().getTime();		Date dat = new Date(currenttime - 1000 * 60 * 60 * 2);		// format.parse(format.format(dat))		return format.format(dat);	}	/**	 * 字符串轉日期	 * */	public static Date StrToDate(String str, String formatStr) {		SimpleDateFormat format = new SimpleDateFormat(formatStr);		Date date = null;		try {			date = format.parse(str);		} catch (ParseException e) {			e.printStackTrace();		}		return date;	}	/**	 * 日期轉換成Java字符串	 * 	 * @param date	 * @return str	 */	public static String DateToStr(Date date) {		String str = "";		try {			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");			str = format.format(date);		} catch (Exception e) {			e.printStackTrace();		}		return str;	}	/**	 * 時間轉化	 * 	 * @param time	 * @param type type類型	 * @return	 */	public static String DateToStr(Date time, String type) {		SimpleDateFormat dateFormat = new SimpleDateFormat(type);		String date = dateFormat.format(time);		return date;	}	/**	 * 獲取當前時間,格式為 :yyyy-MM-dd	 * 	 * @return	 */	public static String getCurrentDate() {		Date now = new Date();		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");		String date = dateFormat.format(now);		return date;	}	/**	 * 獲取當前時間,格式為 :yyyy-MM-dd	 * 	 * @return	 */	public static Integer getCurrentDate_MM() {		Date now = new Date();		SimpleDateFormat dateFormat = new SimpleDateFormat("MM");		String date = dateFormat.format(now);		return isInteger(date);	}	/**	 * 獲取當前時間,格式為 :yyyy-MM-dd	 * 	 * @return	 */	public static Integer getCurrentDate_dd() {		Date now = new Date();		SimpleDateFormat dateFormat = new SimpleDateFormat("dd");		String date = dateFormat.format(now);		return isInteger(date);	}	/**	 * 獲取指定日期的月	 * 	 * @return	 * @throws ParseException	 */	@SuppressLint("SimpleDateFormat")	public static Integer getDate_MM(String data) throws ParseException {		DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");		DateFormat dateFormat2 = new SimpleDateFormat("MM");		Date s = dateFormat1.parse(data);		String date = dateFormat2.format(s);		return isInteger(date);	}	/**	 * 獲取當前時間,格式為 :yyyy-MM-dd HH:mm:ss	 * 	 * @return	 */	public static String getCurrentDate2() {		Date now = new Date();		now.setTime(System.currentTimeMillis());		SimpleDateFormat dateFormat = new SimpleDateFormat(				"yyyy-MM-dd HH:mm:ss");		String date = dateFormat.format(now);		return date;	}	/**	 * 獲取當前時間,格式為 :yyyy-MM-dd HH:mm	 * 	 * @return	 */	public static String getCurrentDate3() {		Date now = new Date();		now.setTime(System.currentTimeMillis());		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");		String date = dateFormat.format(now);		return date;	}	/**	 * 獲取明天零點時間,格式為 :yyyy-MM-dd HH:mm:ss	 * 	 * @return	 */	public static String getTomorrowDateAtZeroAM() {		Date date = new Date();// 取時間		Calendar calendar = new GregorianCalendar();		calendar.setTime(date);		calendar.add(calendar.DATE, 1);// 把日期往后增加一天.整數往后推,負數往前移動		date = calendar.getTime(); // 這個時間就是日期往后推一天的結果		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		String dateString = formatter.format(date);		return dateString.substring(0, dateString.length() - 8) + "00:00:00";	}	/**	 * 獲取指定日期的日	 * 	 * @return	 * @throws ParseException	 */	public static Integer getDate_DD(String data) throws ParseException {		DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");		DateFormat dateFormat2 = new SimpleDateFormat("dd");		Date s = dateFormat1.parse(data);		String date = dateFormat2.format(s);		return isInteger(date);	}	/**	 * 比較兩個 yyyy-MM-dd 格式的日期字符串時間前后	 * 	 * @param date1	 * @param date2	 * @return true:"date1在date2后" , false:"date1在date2前"	 */	public static boolean dateComparator(String date1, String date2) {		return dateComparator(date1, date2, "yyyy-MM-dd");	}	/**	 * 比較兩個 yyyy-MM-dd HH:mm:ss 格式的日期字符串時間前后	 * 	 * @param date1	 * @param date2	 * @return true:"date1在date2前" , false:"date1在date2后"	 */	public static boolean dateComparator2(String date1, String date2) {		return dateComparator(date1, date2, "yyyy-MM-dd HH:mm:ss");	}	public static boolean dateComparator(String date1, String date2, String str) {		DateFormat df = new SimpleDateFormat(str);		try {			Date dt1 = df.parse(date1);			Date dt2 = df.parse(date2);			if (dt1.getTime() > dt2.getTime()) {				return false;			} else if (dt1.getTime() < dt2.getTime()) {				return true;			} else {				return true;			}		} catch (Exception exception) {			exception.printStackTrace();			return false;		}	}	/**	 * 獲取兩個日期的差 yyyy-MM-dd	 * 	 * @param date1	 * @param date2	 * @return	 */	public static long dateDifference1(String date1, String date2) {		return dateDifference(date1, date2, "yyyy-MM-dd");	}	/**	 * 獲取兩個日期的差 yyyy-MM-dd HH:mm:ss	 * 	 * @param date1	 * @param date2	 * @return	 */	public static long dateDifference2(String date1, String date2) {		return dateDifference(date1, date2, "yyyy-MM-dd HH:mm:ss");	}	/**	 * 獲取兩個日期的差	 * 	 * @param date1	 * @param date2	 * @param str	 * @return	 */	public static long dateDifference(String date1, String date2, String str) {		DateFormat df = new SimpleDateFormat(str);		try {			Date dt1 = df.parse(date1);			Date dt2 = df.parse(date2);			long temp = dt2.getTime() - dt1.getTime();			long result = temp / (1000 * 60);			return result;		} catch (Exception exception) {			exception.printStackTrace();			return 0;		}	}	/**	 * 得到兩個日期的差	 * 	 * @param fDate	 * @param oDate	 * @return 天數	 */	public static int daysOfTwo(String fDate, String oDate) {		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		Date dt1;		Date dt2;		try {			dt1 = df.parse(fDate);			dt2 = df.parse(oDate);			Calendar aCalendar = Calendar.getInstance();			aCalendar.setTime(dt1);			int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);			int year1 = aCalendar.get(Calendar.YEAR);			aCalendar.setTime(dt2);			int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);			int year2 = aCalendar.get(Calendar.YEAR);			return (day2 - day1) + (year2 - year1) * 365;		} catch (ParseException e) {			e.printStackTrace();			return 0;		}	}	/**	 * 比較兩個數的大小	 * 	 * @param num1	 * @param num2	 * @return	 */	public static boolean numComparator(String num1, String num2) {		int int1;		int int2;		try {			int1 = Integer.parseInt(num1.trim());			int2 = Integer.parseInt(num2.trim());			return int1 > int2;		} catch (Exception e) {			e.printStackTrace();			return false;		}	}	/**	 * 獲取當前日期是星期幾<br>	 * 	 * @param time	 *            需要獲取的日期	 * @return 當前日期是星期幾,(從0開始,周日、周一.....)	 */	public static int getWeekOfDate(String time) {		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");		Date dt;		int week = 0;		try {			dt = df.parse(time);			Calendar cal = Calendar.getInstance();			cal.setTime(dt);			week = cal.get(Calendar.DAY_OF_WEEK) - 1;			if (week < 0)				week = 0;		} catch (ParseException e) {		}		return week;	}	/**	 * 判斷是否為double類型	 * 	 * @param str	 * @return	 */	public static boolean isDoubleNumeric(String str) {		try {			Double.parseDouble(str);			return true;		} catch (NumberFormatException e) { // 不是數字			return false;		}	}	/**	 * 判斷是否為數字	 * 	 * @param str	 * @return	 */	public static boolean isNumeric(String str) {		try {			Integer.parseInt(str);			return true;		} catch (NumberFormatException e) { // 不是數字			return false;		}	}	/**	 * 關于EditText的判斷方法	 * 	 * @param editText	 * @param yajin	 *            限額大小	 * @param c	 */	public static void setPricePoint(final EditText editText,			final double yajin, final Context c) {		editText.addTextChangedListener(new TextWatcher() {			@Override			public void onTextChanged(CharSequence s, int start, int before,									  int count) {				if (isDoubleNumeric(s.toString())) {					if (s.toString().contains(".")) {						if (s.length() - 1 - s.toString().indexOf(".") > 2) {							s = s.toString().subSequence(0,									s.toString().indexOf(".") + 3);							editText.setText(s);							editText.setSelection(s.length());						}					}					if (s.toString().trim().substring(0).equals(".")) {						s = "0" + s;						editText.setText(s);						editText.setSelection(2);					}					if (s.toString().startsWith("0")							&& s.toString().trim().length() > 1) {						if (!s.toString().substring(1, 2).equals(".")) {							editText.setText(Utils.isDouble(s.subSequence(0,									s.length()).toString())									+ "");							// editText.setSelection(s.length()+1);							return;						}					}				} else {					return;				}			}			@Override			public void beforeTextChanged(CharSequence s, int start, int count,										  int after) {			}			@Override			public void afterTextChanged(Editable s) {				if (s.toString().equals("")) {					editText.setText("0");					return;				}				if (!isDoubleNumeric(s.toString())) {					editText.setText("0");					Toast.makeText(c, "請輸入正確價格", Toast.LENGTH_SHORT).show();					return;				}				double strcount = Double.parseDouble(s.toString());				double count = yajin;				if (strcount > count) {					editText.setText("0");					Toast.makeText(c, "超出限額", Toast.LENGTH_SHORT).show();				}			}		});	}	/** 時間秒數轉換為時間 */	public static String getDatesft(Long dates) {		// long sstime = dates.toString();		Calendar calendar = Calendar.getInstance();		calendar.setTimeInMillis(dates);		Date date = calendar.getTime();		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");		return sdf.format(date);	}	/** 時間秒數轉換為時間 */	public static String getFullDate(Long dates) {		// long sstime = dates.toString();		Calendar calendar = Calendar.getInstance();		calendar.setTimeInMillis(dates);		Date date = calendar.getTime();		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		return sdf.format(date);	}	/** 時間秒數轉換為時間 */	public static String getDate(Long dates) {		// long sstime = dates.toString();		Calendar calendar = Calendar.getInstance();		calendar.setTimeInMillis(dates);		Date date = calendar.getTime();		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");		return sdf.format(date);	}	/** 時間秒數轉換為時間 */	public static String getDate2(Long dates) {		// long sstime = dates.toString();		Calendar calendar = Calendar.getInstance();		calendar.setTimeInMillis(dates);		Date date = calendar.getTime();		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		return sdf.format(date);	}	public static String checkInt(String num) {		return (num == null || !Utils.isNumeric(num)) ? "0" : num;	}	public static String checkDouble(String num) {		return (num == null || "NaN".equals(num) || !Utils.isDoubleNumeric(num)) ? "0"				: num;	}	public static String checkStr(String str) {		return Utils.isEmpty(str) ? "" : str;	}	/** 獲取前3天時間 */	public static String FrontThreeDay() {		Calendar calendar = Calendar.getInstance();		calendar.add(Calendar.DATE, -3); // 得到前三天		Date date = calendar.getTime();		String dates = DateToStrtimeminute(date);		return dates;	}	/** 獲取前15天時間 */	public static String FroutFifteenFDays() {		Calendar calendar = Calendar.getInstance();		calendar.add(Calendar.DATE, -15); // 得到前十五天		Date date = calendar.getTime();		String dates = DateToStrtimeminute(date);		return dates;	}	/** 獲取前30天時間 */	public static String FroutthirtyDays() {		Calendar calendar = Calendar.getInstance();		calendar.add(Calendar.DATE, -30); // 得到前三十天		Date date = calendar.getTime();		String dates = DateToStrtimeminute(date);		return dates;	}	/**	 * 幾分鐘以后的時間	 * 	 * @param after	 * @return	 */	public static String MinueLaterTime(int after) {		Calendar calendar = Calendar.getInstance();		calendar.add(Calendar.MINUTE, after); // 得到前三十天		Date date = calendar.getTime();		String dates = DateToStrtimeminute(date);		return dates;	}	/** 日期轉換字符串 */	public static String DateToStrtimeminute(Date date) {		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		String str = format.format(date);		return str;	}	/** 檢查Integer數據 */	public static Integer isInteger(Integer num) {		return isInteger(num + "");	}	/** 檢查Double數據 */	public static Double isDouble(Double num) {		return isDouble(num + "");	}	/** String檢查Integer數據 */	public static Integer isInteger(String num) {		return Integer.parseInt(checkInt(num));	}	/** String檢查Double數據 */	public static Double isDouble(String num) {		return Double.parseDouble(checkDouble(num));	}	/**	 * 獲取小時和分鐘的字符串	 * 	 * @param mDate orderDate	 * @return	 */	public static String getShorDate(Date mDate) {		if (mDate == null) {			return "00:00";		}		String hoursstr = "";		String minutesStr = "";		int hours = mDate.getHours();		int minutes = mDate.getMinutes();		if (hours < 10) {			hoursStr = "0" + hours;		} else {			hoursStr = "" + hours;		}		if (minutes < 10) {			minutesStr = "0" + minutes;		} else {			minutesStr = "" + minutes;		}		return hoursStr + ":" + minutesStr;	}	/**	 * 兩個double相減 返回保留2位小數的字符串	 * 	 * @param a	 * @param b	 * @return	 */	public static String getDoubleMin(double a, double b) {		DecimalFormat df = new DecimalFormat("0.00");		return df.format(a - b);	}	/**	 * 兩個double相減 返回保留2位小數的字符串	 * 	 * @param x a	 * @param y b	 * @return	 */	public static double getAddDouble(double x, double y) {		BigDecimal add1 = new BigDecimal(Double.toString(x));		BigDecimal add2 = new BigDecimal(y + "");		return add1.add(add2).doubleValue();	}	/**	 * 得到小數點后兩位	 * 	 * @param x	 * @return	 */	public static double parseDecimalDouble2(double x) {		BigDecimal bg = new BigDecimal(isDouble(x));		return bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();	}	/**	 * 得到小數點后兩位	 * 	 * @param str	 * @return	 */	public static double parseDecimalDouble2(String str) {		BigDecimal bg = new BigDecimal(isDouble(str));		return bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();	}	/**	 * 兩個double相減 返回保留2位小數的字符串	 * 	 * @param a	 * @param b	 * @return	 */	public static String getDoubleMin(String a, String b) {		double x = isDouble(a);		double y = isDouble(b);		DecimalFormat df = new DecimalFormat("0.00");		return df.format(x - y);	}	/**	 * 兩個double相加 返回保留2位小數的字符串	 * 	 * @param a	 * @param b	 * @return	 */	public static String getDoubleAdd(double a, double b) {		DecimalFormat df = new DecimalFormat("0.00");		return df.format(a + b);	}	/**	 * 兩個double相加 返回保留2位小數的字符串	 * 	 * @param a	 * @param b	 * @return	 */	public static String getDoubleAdd(String a, String b) {		double x = isDouble(a);		double y = isDouble(b);		DecimalFormat df = new DecimalFormat("0.00");		return df.format(x + y);	}	/**	 * double取兩位	 * 	 * @param a	 * @return	 */	public static String formatDoubleReturnString(double a) {		DecimalFormat df = new DecimalFormat("0.00");		return df.format(a);	}	/**	 * 判斷app是否安裝	 * 	 * @author gaof	 * @return boolean	 */	public static boolean isAppInstalled(Context context, String packageName) {		final PackageManager packageManager = context.getPackageManager();		List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);		List<String> pName = new ArrayList<String>();		if (pinfo != null) {			for (int i = 0; i < pinfo.size(); i++) {				String pn = pinfo.get(i).packageName;				pName.add(pn);				if (pn.contains(packageName)) {					String version = pinfo.get(i).versionName;// 獲取版本號					int versionNum = Utils.isInteger(version.replace(".", "")							.trim());				}			}		}		return pName.contains(packageName);	}	/**	 * 得到當前應用版本號	 * 	 * @author gaof	 * @return boolean	 */	public static String getAppVersion(Context context) {		String version = "1.0.0";		final PackageManager packageManager = context.getPackageManager();		PackageInfo info = null;		try {			info = packageManager.getPackageInfo(context.getPackageName(), 0);			version = info.versionName;		} catch (NameNotFoundException e) {			e.printStackTrace();			return version;		}		// info.versionCode		// info.packageName;		// info.signatures;		return version;	}	/**	 * 獲取銀聯插件版本號	 * 	 * @param context	 * @return 插件版本號	 */	public static String getYinlianPluginVersion(Context context) {		String version = "1.0.0";		PackageInfo info = null;		PackageManager packageManager = context.getPackageManager();		try {			info = packageManager.getPackageInfo("com.chinaums.mpospluginpad",					0);			version = info.versionName;		} catch (NameNotFoundException e) {			e.printStackTrace();		}		return version;	}	/**	 * double取兩位	 * 	 * @param a	 * @return	 */	public static double formatDoubleReturnDouble(double a) {		DecimalFormat df = new DecimalFormat("0.00");		return isDouble(df.format(a));	}	/**	 * 把電話號碼替換成帶星號的 例如:182****6742 假如不是電話號碼的就不進行替換	 * 	 * @param phone	 * @return	 */	public static String replacePhoneWithAsterisk(String phone) {		if (phone==null || phone.length()!=11) {			return "";		}		String newphone = phone;		if (isMobileNO(newphone)) {			newphone = phone.substring(0, 3) + "****" + phone.substring(7);		}		return newphone;	}	/**	 * 獲取屏幕分辨率的高度	 * 	 * @param context	 * @return	 */	@SuppressWarnings("deprecation")	public static int getScreenHeight(Context context) {		Display mDisplay = ((Activity) context).getWindowManager()				.getDefaultDisplay();		return mDisplay.getHeight();	}	/**	 * 通過backtype的種類進行確認字段1.還車結算界面,2.違章結算界面,3.維修結算界面,4.取車租金支付,5.取車先付結算界面	 * 6.預授權列表界面 0:不關聯結算單 1:一次結算 2:二次結算 取車 支付 0 還車支付 1 違章預授權列表 2	 * 	 * @author gaof	 */	public static String ConfirmSettlementTimesVaule(String backtype) {		String SettlementTimes = "";		switch (Utils.isInteger(backtype)) {		case 1:			SettlementTimes = "1";			break;		case 2:			SettlementTimes = "1";			break;		case 3:			SettlementTimes = "1";			break;		case 4:			SettlementTimes = "0";			break;		case 5:			SettlementTimes = "0";			break;		case 6:			SettlementTimes = "2";			break;		}		return SettlementTimes;	}	/**	 * @author gaof	 *            將銀行卡號處理為前四后6的格式	 */	public static String ChangeToBankCard(String bankcard) {		String bankcardS = "";		bankcardS = bankcard.substring(0, 6) + "*******"				+ bankcard.substring(bankcard.length() - 4, bankcard.length());		return bankcardS;	}	/**	 * @author gaof	 * @param billsMID	 *            billsTID 商戶編號,商戶終端號	 */	public static boolean billsMidOrTid(String billsMID, String billsTID) {		if (Utils.isEmpty(billsMID) || Utils.isEmpty(billsTID)) {			return false;		} else {			return true;		}	}	/**	 * 驗證郵政編碼	 * 	 * @param post	 *            郵編	 * @return	 */	public static boolean checkPost(String post) {		if (post.matches("[1-9]//d{5}(?!//d)")) {			return true;		} else {			return false;		}	}	/**	 * double 乘法	 * 	 * @param d1	 * @param d2	 * @return	 */	public static double mul(double d1, double d2) {		BigDecimal bd1 = new BigDecimal(Double.toString(d1));		BigDecimal bd2 = new BigDecimal(Double.toString(d2));		return bd1.multiply(bd2).doubleValue();	}	/**	 * 根據月日判斷星座	 * 	 * @return int	 */	public static String getConstellation(int m, int d) {		final String[] constellationArr = { "魔羯座", "水瓶座", "雙魚座", "白羊座", "金牛座",				"雙子座", "巨蟹座", "獅子座", "處女座", "天秤座", "天蝎座", "射手座", "魔羯座" };		final int[] constellationEdgeDay = { 20, 18, 20, 20, 20, 21, 22, 22,				22, 22, 21, 21 };		int month = m;		int day = d;		if (day <= constellationEdgeDay[month - 1]) {			month = month - 1;		}		if (month >= 0) {			return constellationArr[month];		}		// default to return 魔羯		return constellationArr[11];	}	/**	 * 調用系統相冊	 */	public static void openSysPhone(int flag, Context context) {		Intent intent2 = new Intent(Intent.ACTION_PICK,				android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);		((Activity) context).startActivityForResult(intent2, flag);	}	/**	 * 獲得指定文件的byte數組	 */	public static byte[] getBytes(String filePath) {		byte[] buffer = null;		try {			File file = new File(filePath);			FileInputStream fis = new FileInputStream(file);			ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);			byte[] b = new byte[1000];			int n;			while ((n = fis.read(b)) != -1) {				bos.write(b, 0, n);			}			fis.close();			bos.close();			buffer = bos.toByteArray();		} catch (FileNotFoundException e) {			e.printStackTrace();		} catch (IOException e) {			e.printStackTrace();		}		return buffer;	}	/**	 * 判斷字符串是否是數字	 */	public static boolean isNumber(String value) {		return isInteger1(value) || isDouble1(value);	}	/**	 * 判斷字符串是否是整數	 */	public static boolean isInteger1(String value) {		try {			Integer.parseInt(value);			return true;		} catch (NumberFormatException e) {			return false;		}	}	/**	 * 判斷字符串是否是浮點數	 */	public static boolean isDouble1(String value) {		try {			Double.parseDouble(value);			if (value.contains("."))				return true;			return false;		} catch (NumberFormatException e) {			return false;		}	}	/** 獲取設備唯一標識 */	public static String getDeviceUnique(Context context) {		TelephonyManager tm = (TelephonyManager) context				.getSystemService(Context.TELEPHONY_SERVICE);		String tmDevice, tmSerial, tmPhone, androidId;		tmDevice = "" + tm.getDeviceId();		tmSerial = "" + tm.getSimSerialNumber();		androidId = ""				+ android.provider.Settings.Secure.getString(						context.getContentResolver(),						android.provider.Settings.Secure.ANDROID_ID);		UUID deviceUuid = new UUID(androidId.hashCode(),				((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());		String uniqueId = deviceUuid.toString();		return uniqueId;	}	/**	 * 將圖片文件轉化為字節數組字符串,并對其進行Base64編碼處理	 * 	 * @param filepath	 * @return	 */	public static byte[] getBase64(String filepath) {		if (Utils.isEmpty(filepath)) {			return null;		}		InputStream in = null;		byte[] data = null;		// 讀取圖片字節數組		try {			in = new FileInputStream(filepath);			data = new byte[in.available()];			in.read(data);			in.close();		} catch (IOException e) {			e.printStackTrace();			return null;		}		return android.util.Base64.encode(data, android.util.Base64.DEFAULT);	}	public static String getAge(Date birthDay) throws Exception {		Calendar cal = Calendar.getInstance();		if (cal.before(birthDay)) {			throw new IllegalArgumentException(					"The birthDay is before Now.It's unbelievable!");		}		int yearNow = cal.get(Calendar.YEAR);		int monthNow = cal.get(Calendar.MONTH) + 1;		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);		cal.setTime(birthDay);		int yearBirth = cal.get(Calendar.YEAR);		int monthBirth = cal.get(Calendar.MONTH);		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);		int age = yearNow - yearBirth;		if (monthNow <= monthBirth) {			if (monthNow == monthBirth) {				if (dayOfMonthNow < dayOfMonthBirth) {					age--;				}			} else {				age--;			}		}		return age + "";	}	/**	 * 根據手機的分辨率從 dp 的單位 轉成為 px(像素)	 */	public static int dip2px(Context context, float dpValue) {		final float scale = context.getResources().getDisplayMetrics().density;		return (int) (dpValue * scale + 0.5f);	}	/**	 * 根據手機的分辨率從 px(像素) 的單位 轉成為 dp	 */	public static int px2dip(Context context, float pxValue) {		final float scale = context.getResources().getDisplayMetrics().density;		return (int) (pxValue / scale + 0.5f);	}	/**	 * 驗證郵箱格式是否正確	 * 	 * @param mail	 * @return	 */	public static boolean isMail(String mail) {		boolean ismail = false;		String check = "^([a-zA-Z0-9_//-//.]+)@((//[[0-9]{1,3}//.[0-9]{1,3}//.[0-9]{1,3}//.)|(([a-zA-Z0-9//-]+//.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(//]?)$";		// String check =		// "^[a-z0-9]+([._//-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$";		try {			Pattern p = Pattern.compile(check);			Matcher m = p.matcher(mail);			ismail = m.matches();		} catch (Exception e) {			ismail = false;		}		return ismail;	}	/**	 * 獲取 數據摘要	 * @param source	 * @return	 */	public static String getmd5(byte[] source){		 String s = null;	        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  	                'a', 'b', 'c', 'd', 'e', 'f' };// 用來將字節轉換成16進制表示的字符  	        try {  	            java.security.MessageDigest md = java.security.MessageDigest  	                    .getInstance("MD5");  	            md.update(source);	            byte tmp[] = md.digest();// MD5 的計算結果是一個 128 位的長整數,  	            // 用字節表示就是 16 個字節  	            char str[] = new char[16 * 2];// 每個字節用 16 進制表示的話,使用兩個字符, 所以表示成 16  	            // 進制需要 32 個字符  	            int k = 0;// 表示轉換結果中對應的字符位置  	            for (int i = 0; i < 16; i++) {// 從第一個字節開始,對 MD5 的每一個字節// 轉換成 16  	                // 進制字符的轉換  	                byte byte0 = tmp[i];// 取第 i 個字節  	                str[k++] = hexDigits[byte0 >>> 4 & 0xf];// 取字節中高 4 位的數字轉換,// >>>  	                // 為邏輯右移,將符號位一起右移  	                str[k++] = hexDigits[byte0 & 0xf];// 取字節中低 4 位的數字轉換  	            }  	            s = new String(str);// 換后的結果轉換為字符串	        } catch (NoSuchAlgorithmException e) {	            // TODO Auto-generated catch block  	            e.printStackTrace();  	        }  	        return s;  	}}

2、根據封裝類自己寫的測試星座的小demo

package com.example.shopping;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener{    private TextView textView;    private Button button;    private EditText et1,et2;    private int yue,date;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initview();    }    private void initview(){        button= (Button) findViewById(R.id.button);        textView= (TextView) findViewById(R.id.textView);        et1= (EditText) findViewById(R.id.et1);        et2= (EditText) findViewById(R.id.et2);        button.setOnClickListener(this);    }    @Override    public void onClick(View v) {        switch (v.getId()){            case R.id.button:                String s=  et1.getText().toString();                String s2=et2.getText().toString();                String star= Utils.getConstellation(Integer.parseInt(s),Integer.parseInt(s2));                textView.setText(star);                break;        }    }}3、Mainactivity布局文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.shopping.MainActivity">  <EditText      android:id="@+id/et1"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:hint="輸入月份"/>    <EditText        android:id="@+id/et2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="輸入日期"/><TextView    android:id="@+id/textView"    android:layout_width="match_parent"    android:layout_height="50dp"    android:textSize="20dp"/>    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="點擊獲取"/></LinearLayout>

注:測試工程中出現了NumberFormatException

String轉int的時候報錯,導致閃退,原因: 使用editText獲取的兩個字符串放在了initView()中,導致每次點擊按鈕就閃退,最后,直接放在點擊事件里面就好了


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
精品久久久久久中文字幕大豆网| 欧美成人精品h版在线观看| 日韩精品在线播放| 91丨九色丨国产在线| 亚洲精品欧美一区二区三区| 久久亚洲精品国产亚洲老地址| 91精品免费久久久久久久久| 欧美黑人又粗大| 亚洲最大福利网站| 欧美一级片一区| 国产精品久久久av| 国产精品日日摸夜夜添夜夜av| 欧美一级片免费在线| 欧美亚洲在线观看| 日韩女优人人人人射在线视频| 91美女高潮出水| 亚洲精品720p| 亚洲国产日韩一区| 欧美人与物videos| 成人av.网址在线网站| 日韩欧美极品在线观看| 亚洲欧洲国产一区| 欧美激情在线有限公司| 日本成熟性欧美| 国产欧亚日韩视频| 性色av一区二区三区红粉影视| 亚洲三级 欧美三级| 国产精品视频免费在线观看| 国内精品久久影院| 久久久中精品2020中文| 欧美一级高清免费| 亚洲第一福利在线观看| 亚洲新声在线观看| 欧美电影免费播放| 日韩中文字幕网址| 精品久久久久久亚洲国产300| 97国产在线视频| 奇米4444一区二区三区| 中文字幕日韩在线观看| 狠狠干狠狠久久| 97在线观看视频| 欧美专区国产专区| 欧美尺度大的性做爰视频| 91中文在线视频| 亚洲国语精品自产拍在线观看| 欧美在线一区二区三区四| 国产精品男人爽免费视频1| 欧美一级电影免费在线观看| 91成人在线视频| 欧美肥婆姓交大片| 久久99精品视频一区97| 成人www视频在线观看| 粉嫩老牛aⅴ一区二区三区| 欧美一级片久久久久久久| 欧美激情2020午夜免费观看| 亚洲最大的免费| 欧美理论电影网| 狠狠干狠狠久久| 日韩av在线直播| 亚洲欧美中文字幕| 日韩激情第一页| 国产午夜精品久久久| 欧美亚洲成人xxx| 国产精品观看在线亚洲人成网| 日韩精品欧美国产精品忘忧草| 欧美日韩国产综合视频在线观看中文| 国产69精品久久久久久| 亚洲free性xxxx护士白浆| 国产成人久久久精品一区| 亚洲人成在线电影| 久久久久久久激情视频| 欧美国产日产韩国视频| 精品调教chinesegay| 国产精品视频公开费视频| 国内精品视频一区| 国产美女精品视频免费观看| 亚洲老头同性xxxxx| 日韩在线免费视频| 成人啪啪免费看| 国产精品a久久久久久| 国产美女主播一区| 日韩高清电影好看的电视剧电影| 亚洲高清免费观看高清完整版| 国产精品ⅴa在线观看h| 精品久久中文字幕久久av| 国产丝袜一区二区三区免费视频| 国产日韩在线观看av| 久久成人精品一区二区三区| www.亚洲男人天堂| 欧美激情欧美激情| 精品久久久一区二区| 精品久久久久久国产| 国内精品一区二区三区四区| 中文.日本.精品| 欧美日韩精品在线视频| 粗暴蹂躏中文一区二区三区| 欧美日韩免费区域视频在线观看| 中文字幕亚洲综合久久| 国产精品久久中文| 欧美俄罗斯性视频| 91tv亚洲精品香蕉国产一区7ujn| 国产精品久久久久久久久久久久| 91黄色8090| 欧美床上激情在线观看| 久久这里有精品| 中文字幕精品在线| 亚洲美女激情视频| 98精品在线视频| 久久久精品久久久久| 国产成人精品久久二区二区| 成人欧美在线观看| 亚洲精品98久久久久久中文字幕| 国外成人免费在线播放| 亚洲国产精品网站| 欧美日韩色婷婷| 亚洲综合日韩中文字幕v在线| 日韩一区二区福利| 日韩欧美在线中文字幕| 91免费欧美精品| 中文字幕日韩电影| 久久精品亚洲94久久精品| 亚洲iv一区二区三区| 日韩免费av一区二区| 久久精品亚洲精品| 欧美激情综合色| 中文字幕av一区二区| 91夜夜未满十八勿入爽爽影院| 狠狠色狠色综合曰曰| 中文字幕亚洲综合| 欧美人与性动交a欧美精品| 欧美激情亚洲精品| 最新亚洲国产精品| 亚洲精品自拍第一页| 欧美日韩国产精品一区二区不卡中文| 少妇高潮久久久久久潘金莲| 韩国一区二区电影| 成人欧美在线视频| 国产精品久久久久久久久久| 久久精品国产电影| 欧美黄色小视频| 中文字幕亚洲欧美日韩2019| 色狠狠av一区二区三区香蕉蜜桃| 欧美精品在线网站| 国产精品专区一| 亚洲人午夜色婷婷| 亚洲最新视频在线| 国产精品盗摄久久久| 欧美亚洲日本黄色| 国产精品日韩在线观看| 亚洲第一页中文字幕| 国产视频在线观看一区二区| 5278欧美一区二区三区| 永久555www成人免费| 色999日韩欧美国产| 成人黄色av网站| 亚洲男人第一av网站| 欧美亚洲国产成人精品| 日韩精品免费在线观看| 国产99久久精品一区二区永久免费| 欧美日韩在线第一页| www国产精品com| 国产日韩欧美在线播放| 久久久久中文字幕| 97国产精品久久|