Skip to content

Instantly share code, notes, and snippets.

jimbray jimbray

Block or report user

Report or block jimbray

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View RosBridgeClientManager.java
/**
* 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 Jan 6, 2017
gradle 修改 release apk 名称
View change release apk name
android {}外 定义 获取时间的函数
def release_time() {
return new Date().format("yyyy-MM-dd_HH-mm-ss")
}
更改apk 名称
//修改release apk名称
android.applicationVariants.all {
@jimbray
jimbray / CommonViewHolder
Created Mar 4, 2016
通用的ListView Adapter
View CommonViewHolder
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 Mar 4, 2016
用泛型findViewById
View findViewById_type
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 Mar 3, 2016
判断设备是否是 Tablet,适配Tablet设备的时候特别有用。
View isTablet
/**
* 判断是否是 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 Jul 14, 2015
DrawerLayout与toolbar 的联动动画(左上角的icon动画)
View ActionbarDrawerToggle动画
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
View android图片压缩方法
//质量压缩
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 Dec 7, 2014
通过反射获取(修改)类的字段与值
View 通过反射获取(修改)类的字段与值
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 Nov 5, 2014
获取Android程序版本号
View 获取版本号
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 Nov 5, 2014
HashMap根据value寻找key
View 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))) {
You can’t perform that action at this time.