Skip to content

Instantly share code, notes, and snippets.

View jimbray's full-sized avatar

jimbray jimbray

View GitHub Profile
/**
* Created by jimbray on 2018/11/18.
* Email: jimbray16@gmail.com
*/
public class RosBridgeClientManager {
private static final String TAG = RosBridgeClientManager.class.getSimpleName();
private static RosBridgeClientManager instance;
@jimbray
jimbray / change release apk name
Created January 6, 2017 07:37
gradle 修改 release apk 名称
android {}外 定义 获取时间的函数
def release_time() {
return new Date().format("yyyy-MM-dd_HH-mm-ss")
}
更改apk 名称
//修改release apk名称
android.applicationVariants.all {
@jimbray
jimbray / CommonViewHolder
Created March 4, 2016 09:12
通用的ListView Adapter
package com.zrd.waukeen.common;
import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class CommonViewHolder {
@jimbray
jimbray / findViewById_type
Last active March 4, 2016 01:26
用泛型findViewById
public <T extends View> T $(int id) {
return (T) super.findViewById(id);
}
public <T extends View> T $(View view, int id) {
return (T) view.findViewById(id);
}
@jimbray
jimbray / isTablet
Last active March 3, 2016 08:52
判断设备是否是 Tablet,适配Tablet设备的时候特别有用。
/**
* 判断是否是 Tablet
*
* @param activity Activity
* @return true, if is tablet device
*/
public static boolean isTablet(Activity activity) {
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
@jimbray
jimbray / ActionbarDrawerToggle动画
Created July 14, 2015 07:24
DrawerLayout与toolbar 的联动动画(左上角的icon动画)
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
//质量压缩
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
@jimbray
jimbray / 通过反射获取(修改)类的字段与值
Created December 7, 2014 08:11
通过反射获取(修改)类的字段与值
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(
@jimbray
jimbray / 获取版本号
Created November 5, 2014 01:50
获取Android程序版本号
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 = "没有版本号";
}
@jimbray
jimbray / HashMap根据value寻找key
Created November 5, 2014 01:50
HashMap根据value寻找key
/**
* 根据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))) {