List of usage examples for java.lang Class getField
@CallerSensitive public Field getField(String name) throws NoSuchFieldException, SecurityException
From source file:Main.java
public static int getStatusBarHeight(Context context) { try {//from w w w . j a v a 2 s . c o m Class<?> c = Class.forName("com.android.internal.R$dimen"); Object obj = c.newInstance(); Field field = c.getField("status_bar_height"); int x = Integer.parseInt(field.get(obj).toString()); return context.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:org.nebularis.defproxy.introspection.ReflectionUtils.java
static <T> Class<? extends T> primitiveForOrSame(Class<T> clazz) { try {/* w w w .j a va 2 s. c o m*/ return (Class<? extends T>) clazz.getField("TYPE").get(clazz); } catch (Exception e) { return clazz; } }
From source file:Main.java
public static int systemBarHeight(Context context) { int sbar = 0; try {// ww w .ja va2 s. co m Class<?> c = Class.forName("com.android.internal.R$dimen"); Object obj = c.newInstance(); Field field = c.getField("status_bar_height"); int x = Integer.parseInt(field.get(obj).toString()); sbar = context.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); } return sbar; }
From source file:Main.java
private static String getValue(String packageName, String fieldName) { String buildConfigClassName = packageName + ".BuildConfig"; try {// www . j a v a 2 s .co m Class<?> buildConfigClass = Class.forName(buildConfigClassName); Field field = buildConfigClass.getField(fieldName); return (String) field.get(null); } catch (Exception e) { throw new RuntimeException( String.format("%s.%s not set or not accessible", buildConfigClassName, fieldName), e); } }
From source file:Main.java
@SuppressWarnings("rawtypes") public static int getStatusBarHeigh(Context context) { int heigh = 0; try {//from w w w. ja v a 2 s .co m Class c = Class.forName("com.android.internal.R$dimen"); Object obj = c.newInstance(); Field field = c.getField("status_bar_height"); int x = Integer.parseInt(field.get(obj).toString()); heigh = context.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); } return heigh; }
From source file:Main.java
public static int getStatusBarHeight(Context context) { int statusBarHeight = 0; if (statusBarHeight == 0) { try {/* w w w. ja v a 2s . co m*/ Class c = Class.forName("com.android.internal.R$dimen"); Object o = c.newInstance(); Field field = c.getField("status_bar_height"); int x = (Integer) field.get(o); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); } } return statusBarHeight; }
From source file:Main.java
public static int getStatusHeight(Activity activity) { int statusBarHeight = 0; try {/* w w w .j a v a 2s. co m*/ Class<?> c = Class.forName("com.android.internal.R$dimen"); Object o = c.newInstance(); Field field = c.getField("status_bar_height"); int x = (Integer) field.get(o); statusBarHeight = activity.getResources().getDimensionPixelSize(x); } catch (Exception e) { e.printStackTrace(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); statusBarHeight = frame.top; } return statusBarHeight; }
From source file:org.energy_home.jemma.internal.ah.m2m.device.M2MUtils.java
static String getAhConstant(String name) { try {// w w w.j a v a 2 s .co m Class ahConstantsClass = Class.forName("org.energy_home.jemma.ah.AHConstants"); Field field = ahConstantsClass.getField(name); return (String) field.get(null); } catch (Exception e) { return null; } }
From source file:Main.java
/** * Returns status bar height;/*w w w . ja va2 s. co m*/ * * @param context * @return */ public static int getStatusBarHeight(Context context) { int height = 0; try { Class<?> c = Class.forName("com.android.internal.R$dimen"); Object obj = c.newInstance(); Field field = c.getField("status_bar_height"); int temp = Integer.parseInt(field.get(obj).toString()); height = context.getResources().getDimensionPixelSize(temp); } catch (Exception e) { e.printStackTrace(); } return height; }
From source file:Main.java
public static int getStatusBarHeight(Activity activity) { try {/* w ww . java2 s . co m*/ Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object object = clazz.newInstance(); Field field = clazz.getField("status_bar_height"); int dpHeight = Integer.parseInt(field.get(object).toString()); return activity.getResources().getDimensionPixelSize(dpHeight); } catch (Exception e1) { e1.printStackTrace(); return 0; } }