The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 18 | |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
Pankaj Garg | 1890256 | 2014-12-05 16:18:51 -0800 | [diff] [blame] | 20 | import android.app.Fragment; |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 22 | import android.os.Bundle; |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 23 | import android.preference.PreferenceActivity; |
Pankaj Garg | 59608b7 | 2014-12-15 11:22:23 -0800 | [diff] [blame] | 24 | import android.view.MenuItem; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 25 | |
Pankaj Garg | 1890256 | 2014-12-05 16:18:51 -0800 | [diff] [blame] | 26 | import com.android.browser.preferences.AboutPreferencesFragment; |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 27 | import com.android.browser.preferences.GeneralPreferencesFragment; |
John Reck | 7b182d7 | 2011-07-08 10:30:53 -0700 | [diff] [blame] | 28 | |
Pankaj Garg | 1890256 | 2014-12-05 16:18:51 -0800 | [diff] [blame] | 29 | import java.lang.reflect.Constructor; |
| 30 | import java.lang.reflect.InvocationTargetException; |
| 31 | |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 32 | public class BrowserPreferencesPage extends Activity { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 33 | |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 34 | public static void startPreferencesForResult(Activity callerActivity, String url, int requestCode) { |
| 35 | final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class); |
| 36 | intent.putExtra(GeneralPreferencesFragment.EXTRA_CURRENT_PAGE, url); |
| 37 | callerActivity.startActivityForResult(intent, requestCode); |
| 38 | } |
| 39 | |
| 40 | public static void startPreferenceFragmentForResult(Activity callerActivity, String fragmentName, int requestCode) { |
| 41 | final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class); |
| 42 | intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, fragmentName); |
| 43 | callerActivity.startActivityForResult(intent, requestCode); |
| 44 | } |
| 45 | |
Pankaj Garg | 1890256 | 2014-12-05 16:18:51 -0800 | [diff] [blame] | 46 | public static void startPreferenceFragmentExtraForResult(Activity callerActivity, |
| 47 | String fragmentName, |
| 48 | Bundle bundle, |
| 49 | int requestCode) { |
| 50 | final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class); |
| 51 | intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, fragmentName); |
| 52 | intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle); |
| 53 | callerActivity.startActivityForResult(intent, requestCode); |
| 54 | } |
| 55 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 56 | |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 57 | @Override |
| 58 | public void onCreate(Bundle icicle) { |
| 59 | super.onCreate(icicle); |
| 60 | |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 61 | Intent intent = getIntent(); |
| 62 | if (intent != null) { |
| 63 | String action = intent.getAction(); |
| 64 | // check if this page was invoked by 'App Data Usage' on the global data monitor |
| 65 | if ("android.intent.action.MANAGE_NETWORK_USAGE".equals(action)) { |
| 66 | // TODO: switch to the Network fragment here? |
| 67 | } |
Pankaj Garg | 1890256 | 2014-12-05 16:18:51 -0800 | [diff] [blame] | 68 | |
| 69 | Bundle extras = intent.getExtras(); |
| 70 | String fragment = (String) extras.getCharSequence(PreferenceActivity.EXTRA_SHOW_FRAGMENT); |
| 71 | if (fragment != null) { |
| 72 | try { |
| 73 | Class<?> cls = Class.forName(fragment); |
| 74 | Constructor<?> ctor = cls.getConstructor(); |
| 75 | Object obj = ctor.newInstance(); |
| 76 | |
| 77 | if (obj instanceof Fragment) { |
| 78 | Fragment frag = (Fragment) obj; |
| 79 | |
| 80 | Bundle bundle = extras.getBundle(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
| 81 | if (bundle != null) { |
| 82 | frag.setArguments(bundle); |
| 83 | } |
| 84 | |
| 85 | getFragmentManager().beginTransaction().replace( |
| 86 | android.R.id.content, |
| 87 | (Fragment) obj).commit(); |
| 88 | } |
| 89 | } catch (ClassNotFoundException e) { |
| 90 | } catch (NoSuchMethodException e) { |
| 91 | } catch (InvocationTargetException e) { |
| 92 | } catch (InstantiationException e) { |
| 93 | } catch (IllegalAccessException e) { |
| 94 | } |
| 95 | return; |
| 96 | } |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Pankaj Garg | b3b5746 | 2014-11-18 17:28:30 -0800 | [diff] [blame] | 99 | getFragmentManager().beginTransaction().replace(android.R.id.content, |
| 100 | new GeneralPreferencesFragment()).commit(); |
Ben Murdoch | 7ed9bd7 | 2010-12-13 14:30:33 +0000 | [diff] [blame] | 101 | } |
Pankaj Garg | 59608b7 | 2014-12-15 11:22:23 -0800 | [diff] [blame] | 102 | |
| 103 | @Override |
| 104 | public boolean onOptionsItemSelected(MenuItem item) { |
| 105 | switch (item.getItemId()) { |
| 106 | case android.R.id.home: |
| 107 | if (getFragmentManager().getBackStackEntryCount() > 0) { |
| 108 | getFragmentManager().popBackStack(); |
| 109 | } else { |
| 110 | finish(); |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | return super.onOptionsItemSelected(item); |
| 115 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 116 | } |