List of usage examples for android.app Activity getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.example.library.inject.InjectUtil.java
public static void inject(Activity target) { init(target);//from www . j a v a 2s . c om Class<? extends Object> targetClazz = target.getClass(); View contentView = target.getWindow().getDecorView(); InjectViewUtil.injectField(targetClazz, target, contentView); InjectEventUtil.injectMethod(targetClazz, target, contentView); }
From source file:Main.java
public static void changeToTheme(Activity activity, int theme) { sTheme = theme;/*from w ww . j av a 2s.c om*/ activity.finish(); activity.startActivity(new Intent(activity, activity.getClass())); activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); }
From source file:Main.java
public static Object getVariableFromMethod(Activity activity, String method) { Object value = false;/*w ww.j av a 2 s . c o m*/ Class c = activity.getClass(); try { Method m = (Method) c.getDeclaredMethod(method, new Class[] {}); m.setAccessible(true); value = m.invoke(activity, new Object[] {}); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return value; }
From source file:Main.java
/** * Helper method to recreate the Activity. This method should be called after a Locale change. * @param activity the Activity that will be recreated * @param animate a flag indicating if the recreation will be animated or not *//*from w w w .j ava 2 s. co m*/ public static void recreate(Activity activity, boolean animate) { Intent restartIntent = new Intent(activity, activity.getClass()); Bundle extras = activity.getIntent().getExtras(); if (extras != null) { restartIntent.putExtras(extras); } if (animate) { ActivityCompat.startActivity(activity, restartIntent, ActivityOptionsCompat .makeCustomAnimation(activity, android.R.anim.fade_in, android.R.anim.fade_out).toBundle()); } else { activity.startActivity(restartIntent); activity.overridePendingTransition(0, 0); } activity.finish(); }
From source file:Main.java
public static String getCofigValue(Activity activity, String filename, String keyName) { String ret = ""; InputStream is = activity.getClass().getResourceAsStream(filename); if (is != null) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; try {/* w w w. j a v a2 s. c o m*/ builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } Document doc = null; try { doc = builder.parse(is); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } doc.normalize(); NodeList list = doc.getElementsByTagName(keyName); if (list != null && list.getLength() > 0) { ret = list.item(0).getFirstChild().getNodeValue(); } } return ret; }
From source file:Main.java
/** * Enables the NFC foreground dispatch system for the given Activity. * //w w w . j ava 2 s . com * @param targetActivity The Activity that is in foreground and wants to have NFC Intents. * @see #disableNfcForegroundDispatch(android.app.Activity) */ public static void enableNfcForegroundDispatch(Activity targetActivity) { if (mNfcAdapter != null && mNfcAdapter.isEnabled()) { Intent intent = new Intent(targetActivity, targetActivity.getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(targetActivity, 0, intent, 0); mNfcAdapter.enableForegroundDispatch(targetActivity, pendingIntent, null, new String[][] { new String[] { NfcA.class.getName() } }); } }
From source file:org.simple.injector.SimpleDagger.java
/** * @param activity// w w w.j av a2 s . c om */ public static void inject(Activity activity) { InjectAdapter<Activity> adapter = getViewAdapter(activity.getClass()); adapter.injects(activity); }
From source file:com.yixia.zi.utils.UIUtils.java
/** * Set the theme of the Activity, and restart it by creating a new Activity of * the same type.//from ww w . j a v a 2s .c o m */ public static void changeToTheme(Activity activity) { activity.finish(); activity.startActivity(new Intent(activity, activity.getClass())); }
From source file:Main.java
public static Dialog waitForCurrentDialogShowing(final Activity activity, final long timeout) throws InterruptedException { long start = System.currentTimeMillis(); try {/* w w w . j a va 2 s . c om*/ Field currentDialogField = activity.getClass().getDeclaredField("currentDialog"); currentDialogField.setAccessible(true); Dialog dialog = null; while (dialog == null || !dialog.isShowing()) { dialog = (Dialog) currentDialogField.get(activity); Thread.sleep(50); long now = System.currentTimeMillis(); if (now - start > timeout) { throw new InterruptedException( String.format("Timeout exceeded while waiting for dialog showing")); } } return dialog; } catch (Exception e) { throw new InterruptedException(String.format("Exception while waiting for dialog showing")); } }
From source file:Main.java
public static void finishAllActivies(Activity activity) { try {/*from w w w . j a v a2 s.c om*/ Class<?> clazz_Activity = Class.forName("android.app.Activity"); Field field_mMainThread = clazz_Activity.getDeclaredField("mMainThread"); field_mMainThread.setAccessible(true); Object mMainThread = field_mMainThread.get(activity); Class<?> clazz_ActivityThread = Class.forName("android.app.ActivityThread"); Field field_mActivities = clazz_ActivityThread.getDeclaredField("mActivities"); field_mActivities.setAccessible(true); Object mActivities = field_mActivities.get(mMainThread); HashMap<?, ?> map = (HashMap<?, ?>) mActivities; Collection<?> collections = map.values(); if (null != collections && !collections.isEmpty()) { Class<?> clazz_ActivityClientRecord = Class .forName("android.app.ActivityThread$ActivityClientRecord"); Field field_activitiy = clazz_ActivityClientRecord.getDeclaredField("activity"); field_activitiy.setAccessible(true); Activity acti; for (Object obj : collections) { acti = (Activity) field_activitiy.get(obj); Log.d(TAG, "activity.name=" + acti.getClass().getName()); if (null != acti && !acti.isFinishing()) { Log.d(TAG, "activity.name=" + acti.getClass().getName() + " not finish."); acti.finish(); } } } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }