List of usage examples for java.lang.reflect Field getInt
@CallerSensitive @ForceInline public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:com.swtxml.util.parser.ConstantParser.java
private Map<String, Integer> extractConstants(Class<?> cl) { Map<String, Integer> constants = new HashMap<String, Integer>(); try {//from ww w .j ava 2 s . c o m Collection<Field> fields = Reflector.findFields(Visibility.PUBLIC, Subclasses.NONE).isStatic(true) .type(Integer.TYPE).all(cl); for (Field field : fields) { constants.put(field.getName(), field.getInt(cl)); } } catch (Exception e) { throw new ReflectorException(e); } return constants; }
From source file:com.unlockdisk.android.opengl.MainGLActivity.java
private int findSoundId(Activity activity, String variable) { try {//from w ww . jav a2 s . c om String idClass = activity.getPackageName() + ".R$raw"; Class clazz = Class.forName(idClass); Field field = clazz.getField(variable); return field.getInt(clazz); } catch (Exception e) { return -1; } }
From source file:org.eyeseetea.malariacare.layout.dashboard.config.DashboardSettings.java
/** * Resolves the value of the given attribute in the given class * @param generatedAndroidClass/* w w w .j a v a 2 s . co m*/ * @param attributeName * @return */ private int resolve(Class generatedAndroidClass, String attributeName) { try { Field field = generatedAndroidClass.getField(attributeName); return field.getInt(null); } catch (Exception ex) { return 0; } }
From source file:org.openqa.selendroid.server.model.internal.execute_native.FindRId.java
@Override public Object executeScript(JSONArray args) { Class rClazz;// w w w . j ava 2s . co m try { rClazz = serverInstrumentation.getTargetContext().getClassLoader() .loadClass(serverInstrumentation.getTargetContext().getPackageName() + ".R$id"); } catch (ClassNotFoundException e) { e.printStackTrace(); return ""; } String using = null; try { using = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } for (Field field : rClazz.getFields()) { if (field.getName().equalsIgnoreCase(using)) { try { return field.getInt(null); } catch (IllegalAccessException e) { e.printStackTrace(); } } } return ""; }
From source file:io.selendroid.server.model.internal.execute_native.FindRId.java
@Override public Object executeScript(JSONArray args) { Class rClazz;//from w w w .j a v a 2 s .c om try { rClazz = serverInstrumentation.getTargetContext().getClassLoader() .loadClass(serverInstrumentation.getTargetContext().getPackageName() + ".R$id"); } catch (ClassNotFoundException e) { SelendroidLogger.error("Cannot find id", e); return ""; } String using = null; try { using = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } for (Field field : rClazz.getFields()) { if (field.getName().equalsIgnoreCase(using)) { try { return field.getInt(null); } catch (IllegalAccessException e) { e.printStackTrace(); } } } return ""; }
From source file:org.jasig.cas.util.annotation.IsInAnnotationBeanPostProcessor.java
protected void processField(final Field field, final Annotation annotation, final Object bean, final String beanName) throws IllegalAccessException { final IsIn isIn = (IsIn) annotation; final int val = field.getInt(bean); for (int i = 0; i < isIn.value().length; i++) { if (val == isIn.value()[i]) { return; }/*from w w w .j av a 2 s.c o m*/ } throw new FatalBeanException("field '" + field.getName() + "' does not contain a value of '" + isIn.value() + "' on bean '" + beanName + "'"); }
From source file:com.efithealth.app.activity.BaseActivity.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); // ????//w w w. j ava 2 s. com Window window = getWindow(); Class<? extends Window> clazz = window.getClass(); int tranceFlag = 0; int darkModeFlag = 0; Class<?> layoutParams; try { layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_TRANSPARENT"); tranceFlag = field.getInt(layoutParams); field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); darkModeFlag = field.getInt(layoutParams); Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); // ????? // extraFlagField.invoke(window, tranceFlag, tranceFlag); // ??? extraFlagField.invoke(window, tranceFlag | darkModeFlag, tranceFlag | darkModeFlag); // // extraFlagField.invoke(window, 0, darkModeFlag); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.acdd.homelauncher.MainActivity.java
int getVersionCode() { try {// w w w.ja v a2 s. c o m Class sdk = Class.forName("org.acdd.sdk.BuildConfig"); Field mField = Reflect.getField(sdk, "VERSION_CODE"); int verName = mField.getInt(null); return verName; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return 1; }
From source file:com.oprisnik.semdroid.app.parser.DefaultAndroidAppParser.java
protected synchronized void extract(App app, DexFileReader dexFileReader) { try {/*from w w w .ja v a 2 s. c o m*/ // get the number of classes Field f = dexFileReader.getClass().getDeclaredField("class_defs_size"); f.setAccessible(true); mVisitor.setNumberOfClasses(f.getInt(dexFileReader)); } catch (Exception e) { Log.e(TAG, "Could not retrieve number of classes. Ignoring... Exception:" + e.getMessage()); } mLastProgress = -1; // set app for visitor and extract data mVisitor.setApp(app); dexFileReader.accept(mVisitor); }
From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java
static String getForeGroundL(Context context) { final int PROCESS_STATE_TOP = 2; RunningAppProcessInfo currentInfo = null; Field field = null; try {// w w w. j ava 2 s . c om field = RunningAppProcessInfo.class.getDeclaredField("processState"); } catch (Exception e) { e.printStackTrace(); } ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appList = am.getRunningAppProcesses(); for (RunningAppProcessInfo app : appList) { if (app.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && app.importanceReasonCode == 0) { Integer state = null; try { state = field.getInt(app); } catch (Exception e) { e.printStackTrace(); } if (state != null && state == PROCESS_STATE_TOP) { currentInfo = app; break; } } } return currentInfo.processName; }