1263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio/*
2263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project
3263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
4263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License");
5263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * you may not use this file except in compliance with the License.
6263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * You may obtain a copy of the License at
7263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
8263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *      http://www.apache.org/licenses/LICENSE-2.0
9263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
10263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software
11263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS,
12263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * See the License for the specific language governing permissions and
14263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * limitations under the License.
15263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */
16263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
17263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopackage com.android.settings;
18263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
197ac78f2daf482a121bc17018653f187147f1bdf6Matthew Fritzeimport android.app.ActivityManager;
20263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment;
21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager;
22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction;
237ac78f2daf482a121bc17018653f187147f1bdf6Matthew Fritzeimport android.app.ActionBar;
24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver;
25d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName;
26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context;
27263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent;
28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter;
29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences;
30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo;
31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager;
32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException;
33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration;
34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter;
35fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monkimport android.os.AsyncTask;
36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle;
37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
3939b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v14.preference.PreferenceFragment;
4039b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.Preference;
4139b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.PreferenceManager;
42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
4359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
45d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
46d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
5059a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
51263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
52d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
532869157ba9b071f56691a285394500fa4c8a0a79Fan Zhang
54263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
554da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settings.Settings.WifiSettingsActivity;
56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
57b1795f554921249420bf588280396d6920541556Anna Galuszaimport com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
596d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
61b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.accounts.ChooseAccountActivity;
6264f6d9896f4a7dea961698914177abc15e594f5bTony Makimport com.android.settings.accounts.ManagedProfileSettings;
6391e2f89b0f8b440728fe395ee02a71ae59e21ffcJason Monkimport com.android.settings.applications.AdvancedAppSettings;
64fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lauimport com.android.settings.applications.DrawOverlayDetails;
65d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
6786a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xiaimport com.android.settings.applications.ManageAssist;
682ef1aa589427f96e15bea5c158c926d8196908c7Todd Kennedyimport com.android.settings.applications.ManageDomainUrls;
69a2d47fcf59f03d091edaf5895fd3b651e1f499e1Jason Monkimport com.android.settings.applications.NotificationApps;
702cdafc6be386bb767404e42fc728a1a810aa896aJason Monkimport com.android.settings.applications.ProcessStatsSummary;
71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
72d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monkimport com.android.settings.applications.UsageAccessDetails;
73c461d5c03d652907c1b726cd0110a407d1c5bee8Ruben Brunkimport com.android.settings.applications.VrListenerSettings;
74ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhangimport com.android.settings.applications.WriteSettingsDetails;
75263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
762869157ba9b071f56691a285394500fa4c8a0a79Fan Zhangimport com.android.settings.dashboard.DashboardContainerFragment;
77d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
78b37e2887d3112082589997f1bbd802ec282cca6dJason Monkimport com.android.settings.datausage.DataUsageSummary;
793981889d1d19f18443a3d2bee45d4a4bcffbbb93Daniel Nishiimport com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
80b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.deviceinfo.ImeiInformation;
81a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeForget;
82e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeSettings;
8342833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.PublicVolumeSettings;
84b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.deviceinfo.SimStatus;
85b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.deviceinfo.Status;
8642833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.StorageSettings;
87eae3d9f9329efb08296259100160204f3ae270a2Justin Klaassenimport com.android.settings.display.NightDisplaySettings;
88c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings;
891eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monkimport com.android.settings.fuelgauge.PowerUsageDetail;
90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary;
919136523a434cb9ddf4619f7013753e42bfc2e64aDoris Lingimport com.android.settings.gestures.GestureSettings;
92976bb3f45915bdd5165d9a50402d4c1163dae809Abodunrinwa Tokiimport com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings;
94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
955f0b59babfbfe483855b294098613f8d0fc2f9b4Abodunrinwa Tokiimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
96b28b2cc68f0f61388383d1dd75630c3b86597a8eAbodunrinwa Tokiimport com.android.settings.inputmethod.PhysicalKeyboardFragment;
97263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings;
98263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList;
99d7d48fda53747a7a25e903d9ef6defa6ea590ebbMihai Nitaimport com.android.settings.localepicker.LocaleListEditor;
100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings;
101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam;
102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings;
103802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings;
1048c0a4238655990094fe444ac8f7b182963497030Julia Reynoldsimport com.android.settings.notification.ConfigureNotificationSettings;
1054a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings;
1064a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation;
1072ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.notification.OtherSoundSettings;
108b37e2887d3112082589997f1bbd802ec282cca6dJason Monkimport com.android.settings.notification.SoundSettings;
10908531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlockimport com.android.settings.notification.ZenAccessSettings;
110533a5664da21d6bf8819623673fe14b20ba23207John Spurlockimport com.android.settings.notification.ZenModeAutomationSettings;
111f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlockimport com.android.settings.notification.ZenModeEventRuleSettings;
112c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlockimport com.android.settings.notification.ZenModePrioritySettings;
11345fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlockimport com.android.settings.notification.ZenModeScheduleRuleSettings;
11439b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport com.android.settings.notification.ZenModeSettings;
1155555d26b209d8856d862e7fe369f34cb29dcd3a7Julia Reynoldsimport com.android.settings.notification.ZenModeVisualInterruptionSettings;
116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
11812c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandlerimport com.android.settings.qstile.DevelopmentTiles;
1192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor;
1202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index;
1213815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings;
125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings;
12641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar;
127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings;
1287837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings;
129b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.wifi.WifiAPITest;
130b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monkimport com.android.settings.wifi.WifiInfo;
131263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings;
132263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings;
1334da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settingslib.drawer.DashboardCategory;
1344da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settingslib.drawer.SettingsDrawerActivity;
1357ea14c5625c988a81c09625f54faed846fc07ec7Jason Monkimport com.android.settingslib.drawer.Tile;
1362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13726bf003df92b05fafd4e015680a22611724aa25bDoris Lingimport java.net.URISyntaxException;
138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList;
139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List;
1400d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set;
141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1424da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkpublic class SettingsActivity extends SettingsDrawerActivity
143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        implements PreferenceManager.OnPreferenceTreeClickListener,
144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        PreferenceFragment.OnPreferenceStartFragmentCallback,
145cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
146d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
147cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        MenuItem.OnActionExpandListener {
148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String LOG_TAG = "Settings";
150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
151d9779db8c966347734c5791cf63b7dc2e466a0f4Philip P. Moltmann    private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
152d9779db8c966347734c5791cf63b7dc2e466a0f4Philip P. Moltmann
153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Constants for state save/restore
154769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
155d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
156d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
157b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
1583d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
159ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity, the invoking Intent can contain this extra
163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * string to specify which fragment should be initially displayed.
164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * will call isValidFragment() to confirm that the fragment class name is valid for this
166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * activity.
167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * this extra can also be specified to supply a Bundle of arguments to pass
173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * to that fragment when it is instantiated during the initial creation
174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * of the activity.
175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
179c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
180c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     */
181c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
182c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
1836f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio    public static final String BACK_STACK_PREFS = ":settings:prefs";
1846f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio
185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // extras that allow any preference activity to be launched as part of a wizard
186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // show Back and Next buttons? takes boolean parameter
188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Back will then return RESULT_CANCELED and Next RESULT_OK
189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // add a Skip button?
192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // specify custom text for the Back or Next buttons, or cause a button to not appear
195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // at all by setting it to null
196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
201a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio     * those extra can also be specify to supply the title or title res id to be shown for
202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * that fragment.
203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
204d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
20562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    /**
20662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     * The package name used to resolve the title resource id.
20762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     */
20862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
20962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            ":settings:show_fragment_title_res_package_name";
21061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
21161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_title_resid";
21261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
21361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_shortcut";
21461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
21561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
21661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_subsetting";
217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
21892779ce70156031f4fa3b8c2d84305f5b3b44105Udam Saini    public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
21992779ce70156031f4fa3b8c2d84305f5b3b44105Udam Saini
2203069581512bcb9687cb8d79675f6c4950c9ac087Jason Monk    public static final String META_DATA_KEY_FRAGMENT_CLASS =
221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        "com.android.settings.FRAGMENT_CLASS";
222263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
223263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
225d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio    private static final String EMPTY_QUERY = "";
226d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
227d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    private static final int REQUEST_SUGGESTION = 42;
228d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk
229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String mFragmentClass;
230263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
2318eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private CharSequence mInitialTitle;
232a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private int mInitialTitleResId;
2338eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Show only these settings for restricted users
2354da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private String[] SETTINGS_FOR_RESTRICTED = {
2364da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //wireless_section
2374da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            WifiSettingsActivity.class.getName(),
2384da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.BluetoothSettingsActivity.class.getName(),
2394da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DataUsageSummaryActivity.class.getName(),
2404da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.SimSettingsActivity.class.getName(),
2414da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.WirelessSettingsActivity.class.getName(),
2424da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //device_section
2434da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.HomeSettingsActivity.class.getName(),
2448c0a4238655990094fe444ac8f7b182963497030Julia Reynolds            Settings.SoundSettingsActivity.class.getName(),
2454da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DisplaySettingsActivity.class.getName(),
2464da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.StorageSettingsActivity.class.getName(),
2474da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.ManageApplicationsActivity.class.getName(),
2484da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PowerUsageSummaryActivity.class.getName(),
2499136523a434cb9ddf4619f7013753e42bfc2e64aDoris Ling            Settings.GestureSettingsActivity.class.getName(),
2504da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //personal_section
2514da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.LocationSettingsActivity.class.getName(),
2524da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.SecuritySettingsActivity.class.getName(),
2534da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
2544da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.UserSettingsActivity.class.getName(),
2554da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.AccountSettingsActivity.class.getName(),
2564da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //system_section
2574da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DateTimeSettingsActivity.class.getName(),
2584da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DeviceInfoSettingsActivity.class.getName(),
2594da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.AccessibilitySettingsActivity.class.getName(),
2604da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PrintSettingsActivity.class.getName(),
2614da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PaymentSettingsActivity.class.getName(),
262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String[] ENTRY_FRAGMENTS = {
265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WirelessSettings.class.getName(),
266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiSettings.class.getName(),
267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AdvancedWifiSettings.class.getName(),
2687837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest            SavedAccessPointsWifiSettings.class.getName(),
269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            BluetoothSettings.class.getName(),
2703815561997eced7fd773062ce32eaa50bece072cPauloftheWest            SimSettings.class.getName(),
271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TetherSettings.class.getName(),
272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiP2pSettings.class.getName(),
273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            VpnSettings.class.getName(),
274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DateTimeSettings.class.getName(),
275d7d48fda53747a7a25e903d9ef6defa6ea590ebbMihai Nita            LocaleListEditor.class.getName(),
276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            InputMethodAndLanguageSettings.class.getName(),
277976bb3f45915bdd5165d9a50402d4c1163dae809Abodunrinwa Toki            AvailableVirtualKeyboardFragment.class.getName(),
278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
2813033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.class.getName(),
285a2d47fcf59f03d091edaf5895fd3b651e1f499e1Jason Monk            NotificationApps.class.getName(),
28686a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xia            ManageAssist.class.getName(),
287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ProcessStatsUi.class.getName(),
288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationStation.class.getName(),
289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocationSettings.class.getName(),
290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SecuritySettings.class.getName(),
291d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monk            UsageAccessDetails.class.getName(),
292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrivacySettings.class.getName(),
293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceAdminSettings.class.getName(),
294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccessibilitySettings.class.getName(),
295b1795f554921249420bf588280396d6920541556Anna Galusza            AccessibilitySettingsForSetupWizard.class.getName(),
296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CaptionPropertiesFragment.class.getName(),
297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TextToSpeechSettings.class.getName(),
29942833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkey            StorageSettings.class.getName(),
300a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkey            PrivateVolumeForget.class.getName(),
301e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PrivateVolumeSettings.class.getName(),
302e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PublicVolumeSettings.class.getName(),
303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DevelopmentSettings.class.getName(),
304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
3086d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
3099136523a434cb9ddf4619f7013753e42bfc2e64aDoris Ling            GestureSettings.class.getName(),
310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
31508531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlock            ZenAccessSettings.class.getName(),
316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
3215f0b59babfbfe483855b294098613f8d0fc2f9b4Abodunrinwa Toki            KeyboardLayoutPickerFragment2.class.getName(),
322b28b2cc68f0f61388383d1dd75630c3b86597a8eAbodunrinwa Toki            PhysicalKeyboardFragment.class.getName(),
323d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
3248c0a4238655990094fe444ac8f7b182963497030Julia Reynolds            SoundSettings.class.getName(),
3258c0a4238655990094fe444ac8f7b182963497030Julia Reynolds            ConfigureNotificationSettings.class.getName(),
326d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
327d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
328c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
329c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
330dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
331e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
33233acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath            ApnSettings.class.getName(),
333b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            ApnEditor.class.getName(),
33445fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            WifiCallingSettings.class.getName(),
335c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlock            ZenModePrioritySettings.class.getName(),
336533a5664da21d6bf8819623673fe14b20ba23207John Spurlock            ZenModeAutomationSettings.class.getName(),
33745fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            ZenModeScheduleRuleSettings.class.getName(),
338f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlock            ZenModeEventRuleSettings.class.getName(),
3395555d26b209d8856d862e7fe369f34cb29dcd3a7Julia Reynolds            ZenModeVisualInterruptionSettings.class.getName(),
3402583fc1e069d0a54df46258d360499492d7e86d2Jason Monk            ProcessStatsUi.class.getName(),
3411eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monk            PowerUsageDetail.class.getName(),
3422cdafc6be386bb767404e42fc728a1a810aa896aJason Monk            ProcessStatsSummary.class.getName(),
343fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            DrawOverlayDetails.class.getName(),
344fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            WriteSettingsDetails.class.getName(),
34591e2f89b0f8b440728fe395ee02a71ae59e21ffcJason Monk            AdvancedAppSettings.class.getName(),
346b9e5d238b64abf3a45f148b43b8d8fcca912d976Jason Monk            WallpaperTypeSettings.class.getName(),
347c461d5c03d652907c1b726cd0110a407d1c5bee8Ruben Brunk            VrListenerSettings.class.getName(),
34864f6d9896f4a7dea961698914177abc15e594f5bTony Mak            ManagedProfileSettings.class.getName(),
349b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            ChooseAccountActivity.class.getName(),
350b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            IccLockSettings.class.getName(),
351b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            ImeiInformation.class.getName(),
352b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            SimStatus.class.getName(),
353b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            Status.class.getName(),
354b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            TestingSettings.class.getName(),
355b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            WifiAPITest.class.getName(),
356b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk            WifiInfo.class.getName(),
3577d73a29e2863782c60c83dbedb042c882e7f060bDoris Ling            MasterClear.class.getName(),
358eae3d9f9329efb08296259100160204f3ae270a2Justin Klaassen            NightDisplaySettings.class.getName(),
3592ef1aa589427f96e15bea5c158c926d8196908c7Todd Kennedy            ManageDomainUrls.class.getName(),
3603981889d1d19f18443a3d2bee45d4a4bcffbbb93Daniel Nishi            AutomaticStorageManagerSettings.class.getName()
361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3635a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3645a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3655a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3665a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3675a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
3814da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    updateTilesList();
382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
386263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3876934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri    private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
3886934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri        @Override
3896934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri        public void onReceive(Context context, Intent intent) {
3906934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri            String action = intent.getAction();
3916934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri            if (action.equals(Intent.ACTION_USER_ADDED)
3926934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri                    || action.equals(Intent.ACTION_USER_REMOVED)) {
3936934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri                Index.getInstance(getApplicationContext()).update();
3946934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri            }
3956934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri        }
3966934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri    };
3976934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri
398990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
399990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
400853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
401d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
40241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
40341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
40441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
4053d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
406b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
4073d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
408d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
40935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
4100d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
41135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
41259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
41359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
414d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
415d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
416d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
417d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
418d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
419d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
420769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
421769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
423b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
425d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
426d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4270698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
428d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    private ComponentName mCurrentSuggestion;
4290698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
43041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
43141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
43241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
43341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
43621ef89fd6be6506487a70394e3649c915253a535Sunny Goyal        startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
44239b467482d1bf256a111c757e9b7621c6f523271Jason Monk    public boolean onPreferenceTreeClick(Preference preference) {
443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
4496f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
453d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4543d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4553d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4563d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4573d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
462d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
463d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4649593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
4659593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
466d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
46723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
46823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
46923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
47023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
4718c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
4728c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
4738c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
4748c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
4759593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
476d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
477d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
478d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
481d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
482d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
483d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
484d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
485d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
486d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
48731c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk    @Override
48831c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk    public SharedPreferences getSharedPreferences(String name, int mode) {
48931c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk        if (name.equals(getPackageName() + "_preferences")) {
490e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk            return new SharedPreferencesLogger(this, getMetricsTag());
49131c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk        }
49231c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk        return super.getSharedPreferences(name, mode);
49331c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk    }
49431c7c32fcc26a421a4d2fef7f006917ef590f426Jason Monk
495e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk    private String getMetricsTag() {
496e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        String tag = getClass().getName();
497e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
498e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk            tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
499e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        }
500e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        if (tag.startsWith("com.android.settings.")) {
501e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk            tag = tag.replace("com.android.settings.", "");
502e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        }
503e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        return tag;
504e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk    }
505e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk
5060d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
5070d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
5080d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
5090d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
5100d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5115b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
5125b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
5135a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
5145a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
5155a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5165a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
5175a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
5185a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5195a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
5205b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
5215b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
522d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
523d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
5240d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
525fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        long startTime = System.currentTimeMillis();
5260d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5270d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
5280d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
5290d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5300d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
5310d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
5320d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
533263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
53492779ce70156031f4fa3b8c2d84305f5b3b44105Udam Saini        if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
53592779ce70156031f4fa3b8c2d84305f5b3b44105Udam Saini            setIsDrawerPresent(false);
53692779ce70156031f4fa3b8c2d84305f5b3b44105Udam Saini        }
537263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
538263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
539263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
540263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
541da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
5420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
5430d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5445b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
5450d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
546da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
547e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
5485a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
549da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
5504da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        mIsShowingDashboard = className.equals(Settings.class.getName())
5514da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.WirelessSettings.class.getName())
5524da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.DeviceSettings.class.getName())
5534da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.PersonalSettings.class.getName())
5544da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.WirelessSettings.class.getName());
5555a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
55661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
55761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
55861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
5594dfcb8208cdb49167ccf99aeaddf9e206eba87d1Jorim Jaggi        final boolean isSubSettings = this instanceof SubSettings ||
56061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
56161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
56261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
56361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
564712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
565712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
566712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
567712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
568712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
569712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
570da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
571da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
572d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
573d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
5756b1e9dbea47bded54a593ef1bb989d3c2d0c2bc4Anna Galusza        mContent = (ViewGroup) findViewById(R.id.main_content);
57659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
57935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
580dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            // Run the Index update only if we have some space
581dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            if (!Utils.isLowStorage(this)) {
582fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk                long indexStartTime = System.currentTimeMillis();
5836c9e884aa04b19634722d95cb65d7df1050a0c28Jason Monk                Index.getInstance(getApplicationContext()).update();
584fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk                if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
585fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk                        + (System.currentTimeMillis() - indexStartTime) + " ms");
586dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            } else {
587dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
588dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            }
5895cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5905cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
591d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5921800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5931800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
594d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
595d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
5960d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
5975529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
598769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
599769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
600769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
6015f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
602769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
603b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
605b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
606b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
6073d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
60812c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez
609263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
61035062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
611ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                mDisplaySearch = false;
612ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                // UP will be shown only if it is a sub settings
6130d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
6140d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
6155a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
6165a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
61761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
61861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
619d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                }
6200d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                setTitleFromIntent(intent);
621c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
6220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
623a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                switchToFragment(initialFragmentName, initialArguments, true, false,
624a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
62510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            } else {
6265a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // No UP affordance if we are displaying the main Dashboard
627b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio                mDisplayHomeAsUpEnabled = false;
6285a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // Show Search affordance
6295a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                mDisplaySearch = true;
630a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                mInitialTitleResId = R.string.dashboard_title;
63112c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez
63212c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez                // add argument to indicate which settings tab should be initially selected
63312c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez                final Bundle args = new Bundle();
63412c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez                final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
63512c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez                args.putString(extraName, intent.getStringExtra(extraName));
63612c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez
63712c5208ad0ef0fdf1b2e9c6ea2de852a8414990fSalvador Martinez                switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
638a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
639263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
641263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
642d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mActionBar = getActionBar();
643d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        if (mActionBar != null) {
644d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
645d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
646d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        }
64741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
648e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        if (mSwitchBar != null) {
649e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk            mSwitchBar.setMetricsTag(getMetricsTag());
650e4ebcd12be7baae58a1fabcda6c7544c911c95ebJason Monk        }
65141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
652263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // see if we should show Back/Next buttons
653263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
654263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
655d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio            View buttonBar = findViewById(R.id.button_bar);
656263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (buttonBar != null) {
657263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                buttonBar.setVisibility(View.VISIBLE);
658263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
659d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button backButton = (Button)findViewById(R.id.back_button);
660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                backButton.setOnClickListener(new OnClickListener() {
661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6620698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_CANCELED, getResultIntentData());
663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
666d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button skipButton = (Button)findViewById(R.id.skip_button);
667263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                skipButton.setOnClickListener(new OnClickListener() {
668263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6690698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
671263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
673d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                mNextButton = (Button)findViewById(R.id.next_button);
674263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mNextButton.setOnClickListener(new OnClickListener() {
675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6760698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                // set our various button parameters
682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setVisibility(View.GONE);
686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setText(buttonText);
689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setVisibility(View.GONE);
695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setText(buttonText);
698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
699263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
701263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    skipButton.setVisibility(View.VISIBLE);
702263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
703263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
704263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
705ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
706fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
707fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk                + " ms");
708ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    }
709ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
710ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang    public void setDisplaySearchMenu(boolean displaySearch) {
711ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang        if (displaySearch != mDisplaySearch) {
712ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang            mDisplaySearch = displaySearch;
713ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang            invalidateOptionsMenu();
714ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang        }
715ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang    }
716ece8ff63b6a689d159e2295e1da674e4c0d7994fFan Zhang
717a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private void setTitleFromIntent(Intent intent) {
718a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
719a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (initialTitleResId > 0) {
720a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = null;
721a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = initialTitleResId;
72262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina
72362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            final String initialTitleResPackageName = intent.getStringExtra(
72462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
72562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            if (initialTitleResPackageName != null) {
72662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                try {
72762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Context authContext = createPackageContextAsUser(initialTitleResPackageName,
72862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                            0 /* flags */, new UserHandle(UserHandle.myUserId()));
72962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
73062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    setTitle(mInitialTitle);
73162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitleResId = -1;
73262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    return;
73362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                } catch (NameNotFoundException e) {
73462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
73562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                }
73662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            } else {
73762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                setTitle(mInitialTitleResId);
73862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            }
739a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else {
740a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = -1;
741a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
742a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
743a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitle);
744a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        }
745a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    }
746a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio
747c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    @Override
748263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onBackStackChanged() {
749d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        setTitleFromBackStack();
7508eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    }
7518eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
7522869157ba9b071f56691a285394500fa4c8a0a79Fan Zhang    private void setTitleFromBackStack() {
7538eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int count = getFragmentManager().getBackStackEntryCount();
754b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7558eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (count == 0) {
756a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (mInitialTitleResId > 0) {
757a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitleResId);
758a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
759a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitle);
760a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
7612869157ba9b071f56691a285394500fa4c8a0a79Fan Zhang            return;
762263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
763b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7648eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
7658eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        setTitleFromBackStackEntry(bse);
766263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
767263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
7688eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
7695529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        final CharSequence title;
7708eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int titleRes = bse.getBreadCrumbTitleRes();
7718eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (titleRes > 0) {
7728eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = getText(titleRes);
7735529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        } else {
7748eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = bse.getBreadCrumbTitle();
7758eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        }
7768eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (title != null) {
7778eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            setTitle(title);
7785529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        }
7795529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio    }
7805529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
781263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
782263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected void onSaveInstanceState(Bundle outState) {
783263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onSaveInstanceState(outState);
784263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
785769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (mCategories.size() > 0) {
786769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
787263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
788d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
789b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
7903d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
7913d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7923d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (mDisplaySearch) {
7933d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // The option menus are created if the ActionBar is visible and they are also created
7943d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // asynchronously. If you launch Settings with an Intent action like
7953d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
7963d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
7973d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // menu item and search view are null.
7983d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
7993d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
8003d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
8013d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
8023d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
8033d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
804263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
805263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
806263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
807350a930c68fa35d912e11d319848ac44bd868d59Jason Monk    protected void onStart() {
808350a930c68fa35d912e11d319848ac44bd868d59Jason Monk        super.onStart();
809350a930c68fa35d912e11d319848ac44bd868d59Jason Monk
810350a930c68fa35d912e11d319848ac44bd868d59Jason Monk        if (mNeedToRevertToInitialFragment) {
811350a930c68fa35d912e11d319848ac44bd868d59Jason Monk            revertToInitialFragment();
812350a930c68fa35d912e11d319848ac44bd868d59Jason Monk        }
813263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            @Override
816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
8174da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                updateTilesList();
818263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        };
820263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
821263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mDevelopmentPreferencesListener);
822263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
8246934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri        registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
8256934a044b8ebf4dac28d1c1142b6eee4ecc64f66Clara Bayarri        registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
826853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
827d9779db8c966347734c5791cf63b7dc2e466a0f4Philip P. Moltmann        mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
828a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio
8293d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
830a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            onQueryTextSubmit(mSearchQuery);
831a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
8324da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        updateTilesList();
833263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
834263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
835263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
836350a930c68fa35d912e11d319848ac44bd868d59Jason Monk    protected void onStop() {
837350a930c68fa35d912e11d319848ac44bd868d59Jason Monk        super.onStop();
838263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        unregisterReceiver(mBatteryInfoReceiver);
8398c9521f27c86e86ff64ca5a086dea4a6a469a3e5Clara Bayarri        unregisterReceiver(mUserAddRemoveReceiver);
840990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.unregister();
841263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
842263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
843263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
844263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onDestroy() {
845263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onDestroy();
846680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio
847680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
848680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio                mDevelopmentPreferencesListener);
849680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferencesListener = null;
850263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
851263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
852263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected boolean isValidFragment(String fragmentName) {
853263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Almost all fragments are wrapped in this,
854263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // except for a few that have their own activities.
855263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
856263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
857263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
858263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
859263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
860263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
861263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
862263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Intent getIntent() {
863263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        Intent superIntent = super.getIntent();
864263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String startingFragment = getStartingFragmentClass(superIntent);
865263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // This is called from super.onCreate, isMultiPane() is not yet reliable
866263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Do not use onIsHidingHeaders either, which relies itself on this method
867263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (startingFragment != null) {
868263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Intent modIntent = new Intent(superIntent);
869263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
870263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Bundle args = superIntent.getExtras();
871263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (args != null) {
872263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle(args);
873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle();
875263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
876263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            args.putParcelable("intent", superIntent);
877ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy            modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
878263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            return modIntent;
879263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
880263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return superIntent;
881263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
882263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
883263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
884263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Checks if the component name in the intent is different from the Settings class and
885263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * returns the class name to load as a fragment.
886263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
887263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String getStartingFragmentClass(Intent intent) {
888263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (mFragmentClass != null) return mFragmentClass;
889263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
890263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String intentClass = intent.getComponent().getClassName();
891263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intentClass.equals(getClass().getName())) return null;
892263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if ("com.android.settings.ManageApplications".equals(intentClass)
894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.RunningServices".equals(intentClass)
895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.applications.StorageUse".equals(intentClass)) {
896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // Old names of manage apps.
897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            intentClass = com.android.settings.applications.ManageApplications.class.getName();
898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
900263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return intentClass;
901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
903263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
90410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment containing a preference panel.  If the preferences
90510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * are being displayed in multi-pane mode, the given fragment class will
90610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * be instantiated and placed in the appropriate pane.  If running in
90710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * single-pane mode, a new activity will be launched in which to show the
90810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
90910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
91010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragmentClass Full name of the class implementing the fragment.
91110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param args Any desired arguments to supply to the fragment.
91210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleRes Optional resource identifier of the title of this
91310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
91410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleText Optional text of the title of this fragment.
91510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultTo Optional fragment that result data should be sent to.
91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * If non-null, resultTo.onActivityResult() will be called when this
91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * preference panel is done.  The launched panel must use
91810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
91910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultRequestCode If resultTo is non-null, this is the caller's
92058146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio     * request code to be received with the result.
92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
92210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
923d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
924a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        String title = null;
925a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleRes < 0) {
926a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (titleText != null) {
927a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = titleText.toString();
928a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
929a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                // There not much we can do in that case
930a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = "";
931a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
932911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio        }
933a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
9340d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                titleRes, title, mIsShortcut);
93510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
93610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
93710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
9387a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * Start a new fragment in a new activity containing a preference panel for a given user. If the
9397a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * preferences are being displayed in multi-pane mode, the given fragment class will be
9407a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
9417a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * activity will be launched in which to show the fragment.
9427a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     *
9437a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param fragmentClass Full name of the class implementing the fragment.
9447a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param args Any desired arguments to supply to the fragment.
9457a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleRes Optional resource identifier of the title of this fragment.
9467a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleText Optional text of the title of this fragment.
9477a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param userHandle The user for which the panel has to be started.
9487a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     */
9497a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
9507a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            CharSequence titleText, UserHandle userHandle) {
951d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // This is a workaround.
952d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
953d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
954d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // starting the fragment could cause a native stack corruption. See b/17523189. However,
955d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // adding that flag and start the preference panel with the same UserHandler will make it
956d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // impossible to use back button to return to the previous screen. See b/20042570.
957d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
958d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
959d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
960d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // when we're calling it as the same user.
961d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
962d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
963d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        } else {
964d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            String title = null;
965d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            if (titleRes < 0) {
966d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                if (titleText != null) {
967d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = titleText.toString();
968d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                } else {
969d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    // There not much we can do in that case
970d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = "";
971d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                }
9727a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            }
973d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            Utils.startWithFragmentAsUser(this, fragmentClass, args,
974d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    titleRes, title, mIsShortcut, userHandle);
9757a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        }
9767a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    }
9777a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban
9787a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    /**
979263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Called by a preference panel fragment to finish itself.
980263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     *
981263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param caller The fragment that is asking to be finished.
982263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultCode Optional result code to send back to the original
983263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
984263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultData Optional result data to send back to the original
985263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
986263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
987263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
988263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        setResult(resultCode, resultData);
98958146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio        finish();
990263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
991263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
992263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
99310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment.
99410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
99510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragment The fragment to start
99610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param push If true, the current fragment will be pushed onto the back stack.  If false,
99710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * the current fragment will be replaced.
99810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
99910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferenceFragment(Fragment fragment, boolean push) {
100010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
10016b1e9dbea47bded54a593ef1bb989d3c2d0c2bc4Anna Galusza        transaction.replace(R.id.main_content, fragment);
100210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        if (push) {
100310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
100410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.addToBackStack(BACK_STACK_PREFS);
100510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        } else {
100610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
100710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        }
100810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        transaction.commitAllowingStateLoss();
100910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
101010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
101110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
1012d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     * Switch to a specific Fragment with taking care of validation, Title and BackStack
1013d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     */
1014d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
1015a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
1016d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (validate && !isValidFragment(fragmentName)) {
1017d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            throw new IllegalArgumentException("Invalid fragment for this activity: "
1018d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                    + fragmentName);
1019d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1020d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        Fragment f = Fragment.instantiate(this, fragmentName, args);
1021d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
10226b1e9dbea47bded54a593ef1bb989d3c2d0c2bc4Anna Galusza        transaction.replace(R.id.main_content, f);
1023d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (withTransition) {
102459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio            TransitionManager.beginDelayedTransition(mContent);
1025d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1026d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (addToBackStack) {
1027d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1028d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1029a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleResId > 0) {
1030a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            transaction.setBreadCrumbTitle(titleResId);
1031a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else if (title != null) {
1032d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.setBreadCrumbTitle(title);
1033d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1034d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        transaction.commitAllowingStateLoss();
103559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio        getFragmentManager().executePendingTransactions();
1036d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return f;
1037d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1038d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
10394da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private void updateTilesList() {
1040fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        // Generally the items that are will be changing from these updates will
1041fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        // not be in the top list of tiles, so run it in the background and the
1042fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        // SettingsDrawerActivity will pick up on the updates automatically.
1043fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        AsyncTask.execute(new Runnable() {
1044fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk            @Override
1045fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk            public void run() {
1046fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk                doUpdateTilesList();
1047fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk            }
1048fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk        });
1049fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk    }
1050fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk
1051fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk    private void doUpdateTilesList() {
10524da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        PackageManager pm = getPackageManager();
10534da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        final UserManager um = UserManager.get(this);
10544da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        final boolean isAdmin = um.isAdminUser();
105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10564da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        String packageName = getPackageName();
10574da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
10584da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10604da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10614da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.BluetoothSettingsActivity.class.getName()),
10624da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10644da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10654da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.DataUsageSummaryActivity.class.getName()),
10664da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Utils.isBandwidthControlEnabled(), isAdmin, pm);
106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10684da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10694da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.SimSettingsActivity.class.getName()),
10704da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Utils.showSimCardTile(this), isAdmin, pm);
107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10724da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10734da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.PowerUsageSummaryActivity.class.getName()),
10744da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                mBatteryPresent, isAdmin, pm);
107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10764da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10774da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.UserSettingsActivity.class.getName()),
10784da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
10794da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                && !Utils.isMonkeyRunning(), isAdmin, pm);
108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1081ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov        setTileEnabled(new ComponentName(packageName,
1082ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov                        Settings.WirelessSettingsActivity.class.getName()),
1083ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov                !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1084ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov
1085ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov        setTileEnabled(new ComponentName(packageName,
1086ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov                        Settings.DateTimeSettingsActivity.class.getName()),
1087ca060e3e98c561cad5e28603200810ca70ae4869Fyodor Kupolov                !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
10884da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
10894da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10904da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        Settings.PaymentSettingsActivity.class.getName()),
10914da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_NFC)
10924da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
10934da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        && adapter != null && adapter.isEnabled(), isAdmin, pm);
10944da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
10954da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10964da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.PrintSettingsActivity.class.getName()),
10974da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
110012c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler                    DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
110112c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler                && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
11024da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
11034da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        Settings.DevelopmentSettingsActivity.class.getName()),
110412c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler                showDev, isAdmin, pm);
110512c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler
110612c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler        // Reveal development-only quick settings tiles
110712c4ba4224a42d54ef671302a09c14ed0d3c09b0Dan Sandler        DevelopmentTiles.setTilesEnabled(this, showDev);
11084da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
11094da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (UserHandle.MU_ENABLED && !isAdmin) {
11104da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            // When on restricted users, disable all extra categories (but only the settings ones).
1111fd2c7224185bef301cfaa7de6fe1af22cab8df2fJason Monk            List<DashboardCategory> categories = getDashboardCategories();
11124da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            for (DashboardCategory category : categories) {
1113d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk                for (Tile tile : category.tiles) {
11144da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    ComponentName component = tile.intent.getComponent();
11155862c1ef02ebb6c23b30d470913dac508700cb53Jason Monk                    if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
11164da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                            SETTINGS_FOR_RESTRICTED, component.getClassName())) {
11174da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        setTileEnabled(component, false, isAdmin, pm);
111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
111957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
112226bf003df92b05fafd4e015680a22611724aa25bDoris Ling
112326bf003df92b05fafd4e015680a22611724aa25bDoris Ling        String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
112426bf003df92b05fafd4e015680a22611724aa25bDoris Ling        boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
112526bf003df92b05fafd4e015680a22611724aa25bDoris Ling        setTileEnabled(new ComponentName(packageName,
112626bf003df92b05fafd4e015680a22611724aa25bDoris Ling                Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
112726bf003df92b05fafd4e015680a22611724aa25bDoris Ling        boolean hasBackupActivity = false;
112826bf003df92b05fafd4e015680a22611724aa25bDoris Ling        if (!useDefaultBackup) {
112926bf003df92b05fafd4e015680a22611724aa25bDoris Ling            try {
113026bf003df92b05fafd4e015680a22611724aa25bDoris Ling                Intent intent = Intent.parseUri(backupIntent, 0);
113126bf003df92b05fafd4e015680a22611724aa25bDoris Ling                hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
113226bf003df92b05fafd4e015680a22611724aa25bDoris Ling            } catch (URISyntaxException e) {
113326bf003df92b05fafd4e015680a22611724aa25bDoris Ling                Log.e(LOG_TAG, "Invalid backup intent URI!", e);
113426bf003df92b05fafd4e015680a22611724aa25bDoris Ling            }
113526bf003df92b05fafd4e015680a22611724aa25bDoris Ling        }
113626bf003df92b05fafd4e015680a22611724aa25bDoris Ling        setTileEnabled(new ComponentName(packageName,
1137bb6859ca751e5813685ef8a71bebe22381ce575bChristine Franks                BackupSettingsActivity.class.getName()), hasBackupActivity,
1138bb6859ca751e5813685ef8a71bebe22381ce575bChristine Franks                isAdmin || Utils.isCarrierDemoUser(this), pm);
113926bf003df92b05fafd4e015680a22611724aa25bDoris Ling
11402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
11412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
11424da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
11434da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                                PackageManager pm) {
11445862c1ef02ebb6c23b30d470913dac508700cb53Jason Monk        if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
11454da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
11464da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            enabled = false;
11472ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
11485862c1ef02ebb6c23b30d470913dac508700cb53Jason Monk        setTileEnabled(component, enabled);
114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1177d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1178d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1179d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1180d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1181d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1182d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1184d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1185d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1186d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
11877e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1188a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1189a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1190a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1191d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1193d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1194d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1195d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1196d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1198d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1199d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1200d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1201bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1203d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1204d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1206d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1207d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1208d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1209bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1210d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1213d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1214d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
12164da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    @Override
1217d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    protected void onTileClicked(Tile tile) {
12184da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (mIsShowingDashboard) {
12194da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            // If on dashboard, don't finish so the back comes back to here.
12204da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            openTile(tile);
12214da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        } else {
12224da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            super.onTileClicked(tile);
12234da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        }
12244da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    }
12254da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
1226af00109242a5766ca9418b145c4fb098360c5648Jason Monk    @Override
1227af00109242a5766ca9418b145c4fb098360c5648Jason Monk    public void onProfileTileOpen() {
1228af00109242a5766ca9418b145c4fb098360c5648Jason Monk        if (!mIsShowingDashboard) {
1229af00109242a5766ca9418b145c4fb098360c5648Jason Monk            finish();
1230af00109242a5766ca9418b145c4fb098360c5648Jason Monk        }
1231af00109242a5766ca9418b145c4fb098360c5648Jason Monk    }
1232af00109242a5766ca9418b145c4fb098360c5648Jason Monk
1233d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1234bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1235bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1236263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
12376b1e9dbea47bded54a593ef1bb989d3c2d0c2bc4Anna Galusza        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1238bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1239bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1240bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
12412869157ba9b071f56691a285394500fa4c8a0a79Fan Zhang            setContentHeaderView(null);
1242bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1243a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1244a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1245bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1246d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1247bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1248d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1250d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1251d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1252d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1254d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1255d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1256d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1257bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1258bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1259bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
126023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
126123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
126223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
12640698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
12650698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
12660698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
12670698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
12680698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
12690698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
12700698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
12710698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1272d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk
1273d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    public void startSuggestion(Intent intent) {
12747ac78f2daf482a121bc17018653f187147f1bdf6Matthew Fritze        if (intent == null || ActivityManager.isUserAMonkey()) {
1275703dc60b14ca72c3a1051a377079bbbc0f92d495Matthew Fritze            return;
1276703dc60b14ca72c3a1051a377079bbbc0f92d495Matthew Fritze        }
1277f265dbc44768b10e7fa45a104801e9222ae8c089Matthew Fritze        mCurrentSuggestion = intent.getComponent();
1278d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk        startActivityForResult(intent, REQUEST_SUGGESTION);
1279d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    }
1280d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk
1281d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    @Override
1282d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1283d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk        if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1284d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk                && resultCode != RESULT_CANCELED) {
1285d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk            getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1286d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1287d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk        }
1288d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk        super.onActivityResult(requestCode, resultCode, data);
1289d4f03ec86f9e8b7b108fc63684e23f5c0fb2a864Jason Monk    }
1290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1291