/***
* 判斷手機(jī)號(hào)是否合法
* @see 十一位數(shù)字,1開(kāi)頭
* @param mobiles
* @return boolean
*/
public static boolean isMobile(String mobiles) {
if (null==mobiles) {
return false;
}
if (mobiles.length()!=11) {
return false;
}
for (int i = mobiles.length();--i>=0;){
if (!Character.isDigit(mobiles.charAt(i))){
return false;
}
}
if (!mobiles.startsWith("1")) {
return false;
}
return true;
}
/**
* 根據(jù)手機(jī)的分辨率從 dp 的單位 轉(zhuǎn)成為 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
/**
* 根據(jù)手機(jī)的分辨率從 px(像素) 的單位 轉(zhuǎn)成為 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
public static SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm");
public static SimpleDateFormat sdf2 = new SimpleDateFormat("MM-dd");
public static SimpleDateFormat sdf3 = new SimpleDateFormat("yy-MM-dd");
public static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy");
public static SimpleDateFormat sdf5 = new SimpleDateFormat("MM-dd HH:mm");
public static SimpleDateFormat sdf6 = new SimpleDateFormat("yyyyMMddHHmmss");
/**
* @param string
* @return
*? ? 私信列表時(shí)間顯示說(shuō)明:
*? ? 當(dāng)天:顯示小時(shí):分鐘(hh:mm)殷勘。
*? ? 非當(dāng)天:顯示月-日(mm-dd)
*? ? 非當(dāng)年:顯示年-月-日(yy-mm-dd)
*/
public static String getLetterListDate(long time) {
Date nowDate = new Date();
Date date = new Date(time);
if (!sdf4.format(nowDate).equals(sdf4.format(date))) {
return sdf3.format(date);
} else if (sdf3.format(nowDate).equals(sdf3.format(date))) {
return sdf1.format(date);
} else {
return sdf2.format(date);
}
}
/**
* @param string
* @return
*? ? 私信列表時(shí)間顯示說(shuō)明:
*? ? 當(dāng)天:顯示小時(shí):分鐘(hh:mm)拥娄。
*? ? 非當(dāng)天:顯示月-日(mm-dd)
*? ? 非當(dāng)年:顯示年-月-日(yy-mm-dd)
*/
public static String getLetterListDatesimple(long time) {
Date nowDate = new Date();
Date date = new Date(time);
if (!sdf4.format(nowDate).equals(sdf4.format(date))) {
return sdf3.format(date);
} else if (sdf3.format(nowDate).equals(sdf3.format(date))) {
return sdf1.format(date);
} else {
return sdf2.format(date);
}
}
/**
* @param string
* @return
*? ? 私信聊天窗口時(shí)間顯示說(shuō)明:
*? ? 當(dāng)天:顯示小時(shí):分鐘(hh:mm)捆憎。
*? ? 非當(dāng)天:顯示月-日 小時(shí):分鐘(mm-dd? hh:mm)
*? ? 非當(dāng)年:顯示年-月-日? 小時(shí):分鐘(yy-mm-dd? hh:mm)
*/
public static String getLetterDate(long time) {
Date nowDate = new Date();
Date date = new Date(time);
if (!sdf4.format(nowDate).equals(sdf4.format(date))) {
return sdf.format(date);
} else if (sdf3.format(nowDate).equals(sdf3.format(date))) {
return sdf1.format(date);
} else {
return sdf5.format(date);
}
}
/**
* 計(jì)算text的字?jǐn)?shù)紊选,一個(gè)漢字=兩個(gè)英文字母亥宿,一個(gè)中文標(biāo)點(diǎn)=兩個(gè)英文標(biāo)點(diǎn) 注意:該函數(shù)的不適用于對(duì)單個(gè)字符進(jìn)行計(jì)算利凑,因?yàn)閱蝹€(gè)字符四舍五入后都是1
*
* @param c
* @return
*/
public static long calculateLength(CharSequence c) {
double len = 0;
for (int i = 0; i < c.length(); i++) {
int tmp = (int) c.charAt(i);
if (tmp > 0 && tmp < 127) {
len += 0.5;
} else {
len++;
}
}
return Math.round(len);
}
public static void openActivityAnim(Activity activity){
activity.overridePendingTransition(R.anim.tran_next_in, R.anim.tran_next_out);
}
public static void finishActivityAnim(Activity activity){
activity.overridePendingTransition(R.anim.left_in,R.anim.right_out);
}