This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Resources resources = getResources();//获得res资源对象 | |
Configuration config = resources.getConfiguration();//获得设置对象 | |
DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。 | |
config.locale = Locale.SIMPLIFIED_CHINESE; //简体中文 | |
resources.updateConfiguration(config, dm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 将科学计数法转换为常规计数法 | |
*/ | |
public static String ConScience2NumValue(String str) | |
{ | |
int len = Integer.parseInt(str.substring(getNum(str),getNum(str)+1)); | |
String bit = "1"; | |
for(int i = 0 ; i<len;i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 金额格式化 | |
* @param s 金额 | |
* @param len 小数位数 | |
* @return 格式后的金额 | |
*/ | |
public static String FormatCurrency(String s, int len) { | |
if (s == null || s.length() < 1) { | |
return "0.00"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* /** | |
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) | |
*/ | |
public static int dip2px(Context context, int dpValue) { | |
final float scale = context.getResources().getDisplayMetrics().density; | |
return (int) (dpValue * scale + 0.5f); | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取屏幕大小 | |
* @param context | |
* @return | |
*/ | |
public static int[] getScreenSize(Context context) { | |
DisplayMetrics dm = new DisplayMetrics(); | |
//获取屏幕信息 | |
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); | |
int screenWidth = dm.widthPixels; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据value寻找key | |
* @param map | |
* @param value | |
* @return | |
*/ | |
public static String getMapKeyByValue(HashMap<String, String> map, Object value) { | |
Set<String> kset = map.keySet(); | |
for(String ks : kset){ | |
if(value.equals(map.get(ks))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getCurVersionName(Context context) { | |
String versionName = null; | |
try { | |
PackageInfo pInfo = context.getPackageManager().getPackageInfo( | |
context.getPackageName(), 0); | |
versionName = pInfo.versionName; | |
} catch (NameNotFoundException e) { | |
versionName = "没有版本号"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Object reflect2(Object obj) { | |
if (obj == null) | |
return null; | |
Field[] fields = obj.getClass().getDeclaredFields(); | |
for (int j = 0; j < fields.length; j++) { | |
fields[j].setAccessible(true); | |
// 字段名 | |
System.out.print(fields[j].getName() + ","); | |
// 字段值 | |
if (fields[j].getType().getName().equals( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//质量压缩 | |
private Bitmap compressImage(Bitmap image) { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 | |
int options = 100; | |
while ( baos.toByteArray().length / 1024>100) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩 | |
baos.reset();//重置baos即清空baos | |
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中 | |
options -= 10;//每次都减少10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); | |
drawerToggle = setupDrawerToggle(); | |
mDrawerLayout.setDrawerListener(drawerToggle); | |
private ActionBarDrawerToggle setupDrawerToggle() { | |
return new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, | |
R.string.app_name, R.string.app_name); | |
} | |
@Override |
OlderNewer