Example usage for java.lang.reflect Field get

List of usage examples for java.lang.reflect Field get

Introduction

In this page you can find the example usage for java.lang.reflect Field get.

Prototype

@CallerSensitive
@ForceInline 
public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Returns the value of the field represented by this Field , on the specified object.

Usage

From source file:Main.java

static boolean setSystemUiVisibility(View view, String flagName) {
    try {/*from  ww w. jav  a 2 s  . co m*/
        Method setUiMethod = View.class.getMethod("setSystemUiVisibility", int.class);
        Field flagField = View.class.getField(flagName);
        setUiMethod.invoke(view, flagField.get(null));
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    int statusBarHeight = 0;
    try {//from ww w .  j  a  v  a2 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());
        statusBarHeight = context.getResources().getDimensionPixelSize(x);
    } catch (Exception e) {
    }
    return statusBarHeight;
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    try {// w ww . j  ava  2  s.c om
        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:Main.java

public static Object getStaticFieldValue(Class<?> clazz, String fieldName) throws Exception {
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);/*from www . ja va2s  . c om*/
    return field.get(fieldName);
}

From source file:Main.java

public static int systemBarHeight(Context context) {
    int sbar = 0;
    try {/*  w ww.  ja v  a 2 s. c  om*/
        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

public static int getStatusBarHeight(Context context) {
    int statusBarHeight = 0;
    if (statusBarHeight == 0) {
        try {/*  w  w w .j a va2 s.c o 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 Object getField(Class<?> clazz, String fieldName, Object object)
        throws NoSuchFieldException, IllegalAccessException {
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);/*  w  w  w  .  j a  va 2  s.co  m*/
    return field.get(object);
}

From source file:Main.java

public static Object getField(Object obj, Class<?> cl, String field)
        throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Field localField = cl.getDeclaredField(field);
    localField.setAccessible(true);//from  w  w w . j  av  a 2s . c o m
    return localField.get(obj);
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    if (sStatusBarHeight == 0) {
        try {//from  w w w .j a v  a  2s .  com
            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);
            sStatusBarHeight = context.getResources().getDimensionPixelSize(x);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return sStatusBarHeight;
}

From source file:Main.java

public static int getStatusHeight(Activity activity) {
    int statusBarHeight = 0;
    try {/*from   w  w w . j a v  a2  s  . c om*/
        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;
}