blob: a40c7c7647ba8ea95ef4c0d9022e90c1c5419bca [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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 Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
Pankaj Gargb3b57462014-11-18 17:28:30 -080019import android.app.Activity;
Pankaj Garg18902562014-12-05 16:18:51 -080020import android.app.Fragment;
Enrico Rosd6efa972014-12-02 19:49:59 -080021import android.content.Intent;
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000022import android.os.Bundle;
Enrico Rosd6efa972014-12-02 19:49:59 -080023import android.preference.PreferenceActivity;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010024
Pankaj Garg18902562014-12-05 16:18:51 -080025import com.android.browser.preferences.AboutPreferencesFragment;
Pankaj Gargb3b57462014-11-18 17:28:30 -080026import com.android.browser.preferences.GeneralPreferencesFragment;
John Reck7b182d72011-07-08 10:30:53 -070027
Pankaj Garg18902562014-12-05 16:18:51 -080028import java.lang.reflect.Constructor;
29import java.lang.reflect.InvocationTargetException;
30
Pankaj Gargb3b57462014-11-18 17:28:30 -080031public class BrowserPreferencesPage extends Activity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Enrico Rosd6efa972014-12-02 19:49:59 -080033 public static void startPreferencesForResult(Activity callerActivity, String url, int requestCode) {
34 final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class);
35 intent.putExtra(GeneralPreferencesFragment.EXTRA_CURRENT_PAGE, url);
36 callerActivity.startActivityForResult(intent, requestCode);
37 }
38
39 public static void startPreferenceFragmentForResult(Activity callerActivity, String fragmentName, int requestCode) {
40 final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class);
41 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
42 callerActivity.startActivityForResult(intent, requestCode);
43 }
44
Pankaj Garg18902562014-12-05 16:18:51 -080045 public static void startPreferenceFragmentExtraForResult(Activity callerActivity,
46 String fragmentName,
47 Bundle bundle,
48 int requestCode) {
49 final Intent intent = new Intent(callerActivity, BrowserPreferencesPage.class);
50 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
51 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle);
52 callerActivity.startActivityForResult(intent, requestCode);
53 }
54
Nicolas Roard78a98e42009-05-11 13:34:17 +010055
Ben Murdoch7ed9bd72010-12-13 14:30:33 +000056 @Override
57 public void onCreate(Bundle icicle) {
58 super.onCreate(icicle);
59
Enrico Rosd6efa972014-12-02 19:49:59 -080060 Intent intent = getIntent();
61 if (intent != null) {
62 String action = intent.getAction();
63 // check if this page was invoked by 'App Data Usage' on the global data monitor
64 if ("android.intent.action.MANAGE_NETWORK_USAGE".equals(action)) {
65 // TODO: switch to the Network fragment here?
66 }
Pankaj Garg18902562014-12-05 16:18:51 -080067
68 Bundle extras = intent.getExtras();
69 String fragment = (String) extras.getCharSequence(PreferenceActivity.EXTRA_SHOW_FRAGMENT);
70 if (fragment != null) {
71 try {
72 Class<?> cls = Class.forName(fragment);
73 Constructor<?> ctor = cls.getConstructor();
74 Object obj = ctor.newInstance();
75
76 if (obj instanceof Fragment) {
77 Fragment frag = (Fragment) obj;
78
79 Bundle bundle = extras.getBundle(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
80 if (bundle != null) {
81 frag.setArguments(bundle);
82 }
83
84 getFragmentManager().beginTransaction().replace(
85 android.R.id.content,
86 (Fragment) obj).commit();
87 }
88 } catch (ClassNotFoundException e) {
89 } catch (NoSuchMethodException e) {
90 } catch (InvocationTargetException e) {
91 } catch (InstantiationException e) {
92 } catch (IllegalAccessException e) {
93 }
94 return;
95 }
Enrico Rosd6efa972014-12-02 19:49:59 -080096 }
97
Pankaj Gargb3b57462014-11-18 17:28:30 -080098 getFragmentManager().beginTransaction().replace(android.R.id.content,
99 new GeneralPreferencesFragment()).commit();
Ben Murdoch7ed9bd72010-12-13 14:30:33 +0000100 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800101}