- * If a preference hierarchy is given, the new preference hierarchies will - * be merged in. - * - * @param manager {@link PreferenceManager} context to use. - * @param intent The intent to match activities. - * - * @return The root hierarchy (if one was not provided, the new hierarchy's root). - */ - static PreferenceScreen inflateFromIntent(PreferenceManager manager, Intent intent, PreferenceScreen screen) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("inflateFromIntent", Intent.class, PreferenceScreen.class); - m.setAccessible(true); - PreferenceScreen prefScreen = (PreferenceScreen) m.invoke(manager, intent, screen); - return prefScreen; - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.inflateFromIntent by reflection", e); - } - return null; - } - - /** - * Inflates a preference hierarchy from XML. If a preference hierarchy is - * given, the new preference hierarchies will be merged in. - * - * @param manager The context of the resource. - * @param resId The resource ID of the XML to inflate. - * @return The root hierarchy (if one was not provided, the new hierarchy's - * root). - * @hide - */ - static PreferenceScreen inflateFromResource(PreferenceManager manager, Activity activity, int resId, PreferenceScreen screen) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class); - m.setAccessible(true); - PreferenceScreen prefScreen = (PreferenceScreen) m.invoke(manager, activity, resId, screen); - return prefScreen; - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.inflateFromResource by reflection", e); - } - - return null; - } - - /** - * Returns the root of the preference hierarchy managed by this class. - * - * @return The {@link PreferenceScreen} object that is at the root of the hierarchy. - */ - static PreferenceScreen getPreferenceScreen(PreferenceManager manager) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("getPreferenceScreen"); - m.setAccessible(true); - return (PreferenceScreen) m.invoke(manager); - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.getPreferenceScreen by reflection", e); - } - - return null; - } - - /** - * Called by the {@link PreferenceManager} to dispatch a subactivity result. - */ - static void dispatchActivityResult(PreferenceManager manager, int requestCode, int resultCode, Intent data) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityResult", int.class, int.class, Intent.class); - m.setAccessible(true); - m.invoke(manager, requestCode, resultCode, data); - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.dispatchActivityResult by reflection", e); - } - } - - /** - * Called by the {@link PreferenceManager} to dispatch the activity stop - * event. - */ - static void dispatchActivityStop(PreferenceManager manager) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityStop"); - m.setAccessible(true); - m.invoke(manager); - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.dispatchActivityStop by reflection", e); - } - } - - /** - * Called by the {@link PreferenceManager} to dispatch the activity destroy - * event. - */ - static void dispatchActivityDestroy(PreferenceManager manager) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityDestroy"); - m.setAccessible(true); - m.invoke(manager); - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.dispatchActivityDestroy by reflection", e); - } - } - - /** - * Sets the root of the preference hierarchy. - * - * @param manager {@link PreferenceManager} context. - * @param screen The root {@link PreferenceScreen} of the preference hierarchy. - * - * @return Whether the {@link PreferenceScreen} given is different than the previous. - */ - static boolean setPreferences(PreferenceManager manager, PreferenceScreen screen) - { - try - { - Method m = PreferenceManager.class.getDeclaredMethod("setPreferences", PreferenceScreen.class); - m.setAccessible(true); - return ((Boolean) m.invoke(manager, screen)); - } - catch (Exception e) - { - Log.w(TAG, "Couldn't call PreferenceManager.setPreferences by reflection", e); - } - return false; - } -} \ No newline at end of file