SettingsActivity.java revision 3069581512bcb9687cb8d79675f6c4950c9ac087
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
19263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar;
20263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment;
21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager;
22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction;
23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver;
24d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName;
25263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context;
26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent;
27263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter;
28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences;
29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo;
30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager;
31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException;
32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo;
33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration;
34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter;
35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle;
36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
3839b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v14.preference.PreferenceFragment;
3939b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.Preference;
4039b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.PreferenceManager;
41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
4259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
44d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
45d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
4959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
51d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
528a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger;
53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
544da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settings.Settings.WifiSettingsActivity;
55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
576d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
59fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lauimport com.android.settings.applications.DrawOverlayDetails;
60d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
61263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
6286a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xiaimport com.android.settings.applications.ManageAssist;
632cdafc6be386bb767404e42fc728a1a810aa896aJason Monkimport com.android.settings.applications.ProcessStatsSummary;
64263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
65d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monkimport com.android.settings.applications.UsageAccessDetails;
66fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lauimport com.android.settings.applications.WriteSettingsDetails;
67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary;
69d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
70a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeForget;
71e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeSettings;
7242833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.PublicVolumeSettings;
7342833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.StorageSettings;
74c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings;
751eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monkimport com.android.settings.fuelgauge.PowerUsageDetail;
76263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary;
77263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings;
78263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
79263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings;
80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList;
81263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings;
82263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam;
83263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings;
84802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings;
854a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings;
864a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings;
874a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation;
882ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.notification.OtherSoundSettings;
8908531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlockimport com.android.settings.notification.ZenAccessSettings;
90533a5664da21d6bf8819623673fe14b20ba23207John Spurlockimport com.android.settings.notification.ZenModeAutomationSettings;
91f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlockimport com.android.settings.notification.ZenModeEventRuleSettings;
92c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlockimport com.android.settings.notification.ZenModePrioritySettings;
9345fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlockimport com.android.settings.notification.ZenModeScheduleRuleSettings;
9439b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport com.android.settings.notification.ZenModeSettings;
95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
96263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
972ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor;
982ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index;
993815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings;
103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings;
10441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar;
105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings;
1067837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings;
107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings;
108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings;
1094da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settingslib.drawer.DashboardCategory;
1104da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settingslib.drawer.DashboardTile;
1114da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkimport com.android.settingslib.drawer.SettingsDrawerActivity;
1122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList;
114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List;
1150d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set;
116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1174da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monkpublic class SettingsActivity extends SettingsDrawerActivity
118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        implements PreferenceManager.OnPreferenceTreeClickListener,
119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        PreferenceFragment.OnPreferenceStartFragmentCallback,
120cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
121d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
122cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        MenuItem.OnActionExpandListener {
123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String LOG_TAG = "Settings";
125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Constants for state save/restore
127769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
128d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
129d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
130b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
1313d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
132ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
134263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity, the invoking Intent can contain this extra
136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * string to specify which fragment should be initially displayed.
137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * will call isValidFragment() to confirm that the fragment class name is valid for this
139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * activity.
140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * this extra can also be specified to supply a Bundle of arguments to pass
146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * to that fragment when it is instantiated during the initial creation
147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * of the activity.
148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
152c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
153c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     */
154c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
155c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
1566f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio    public static final String BACK_STACK_PREFS = ":settings:prefs";
1576f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio
158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // extras that allow any preference activity to be launched as part of a wizard
159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // show Back and Next buttons? takes boolean parameter
161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Back will then return RESULT_CANCELED and Next RESULT_OK
162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // add a Skip button?
165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // specify custom text for the Back or Next buttons, or cause a button to not appear
168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // at all by setting it to null
169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
174a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio     * those extra can also be specify to supply the title or title res id to be shown for
175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * that fragment.
176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
177d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
17862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    /**
17962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     * The package name used to resolve the title resource id.
18062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     */
18162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
18262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            ":settings:show_fragment_title_res_package_name";
18361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
18461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_title_resid";
18561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
18661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_shortcut";
18761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
18861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
18961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_subsetting";
190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1913069581512bcb9687cb8d79675f6c4950c9ac087Jason Monk    public static final String META_DATA_KEY_FRAGMENT_CLASS =
192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        "com.android.settings.FRAGMENT_CLASS";
193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
196d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio    private static final String EMPTY_QUERY = "";
197d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String mFragmentClass;
199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
2008eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private CharSequence mInitialTitle;
201a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private int mInitialTitleResId;
2028eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Show only these settings for restricted users
2044da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private String[] SETTINGS_FOR_RESTRICTED = {
2054da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //wireless_section
2064da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            WifiSettingsActivity.class.getName(),
2074da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.BluetoothSettingsActivity.class.getName(),
2084da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DataUsageSummaryActivity.class.getName(),
2094da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.SimSettingsActivity.class.getName(),
2104da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.WirelessSettingsActivity.class.getName(),
2114da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //device_section
2124da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.HomeSettingsActivity.class.getName(),
2134da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.NotificationSettingsActivity.class.getName(),
2144da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DisplaySettingsActivity.class.getName(),
2154da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.StorageSettingsActivity.class.getName(),
2164da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.ManageApplicationsActivity.class.getName(),
2174da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PowerUsageSummaryActivity.class.getName(),
2184da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //personal_section
2194da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.LocationSettingsActivity.class.getName(),
2204da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.SecuritySettingsActivity.class.getName(),
2214da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
2224da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.UserSettingsActivity.class.getName(),
2234da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.AccountSettingsActivity.class.getName(),
2244da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            //system_section
2254da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DateTimeSettingsActivity.class.getName(),
2264da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.DeviceInfoSettingsActivity.class.getName(),
2274da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.AccessibilitySettingsActivity.class.getName(),
2284da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PrintSettingsActivity.class.getName(),
2294da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            Settings.PaymentSettingsActivity.class.getName(),
230263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
231263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
232263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String[] ENTRY_FRAGMENTS = {
233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WirelessSettings.class.getName(),
234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiSettings.class.getName(),
235263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AdvancedWifiSettings.class.getName(),
2367837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest            SavedAccessPointsWifiSettings.class.getName(),
237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            BluetoothSettings.class.getName(),
2383815561997eced7fd773062ce32eaa50bece072cPauloftheWest            SimSettings.class.getName(),
239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TetherSettings.class.getName(),
240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiP2pSettings.class.getName(),
241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            VpnSettings.class.getName(),
242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DateTimeSettings.class.getName(),
243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocalePicker.class.getName(),
244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            InputMethodAndLanguageSettings.class.getName(),
245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
2483033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.class.getName(),
25286a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xia            ManageAssist.class.getName(),
253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ProcessStatsUi.class.getName(),
254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationStation.class.getName(),
255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocationSettings.class.getName(),
256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SecuritySettings.class.getName(),
257d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monk            UsageAccessDetails.class.getName(),
258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrivacySettings.class.getName(),
259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceAdminSettings.class.getName(),
260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccessibilitySettings.class.getName(),
261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CaptionPropertiesFragment.class.getName(),
262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TextToSpeechSettings.class.getName(),
26442833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkey            StorageSettings.class.getName(),
265a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkey            PrivateVolumeForget.class.getName(),
266e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PrivateVolumeSettings.class.getName(),
267e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PublicVolumeSettings.class.getName(),
268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DevelopmentSettings.class.getName(),
269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
2736d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
27908531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlock            ZenAccessSettings.class.getName(),
280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
285d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
286d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            NotificationSettings.class.getName(),
287d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
288d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
289c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
290c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
291dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
292e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
29333acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath            ApnSettings.class.getName(),
29445fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            WifiCallingSettings.class.getName(),
295c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlock            ZenModePrioritySettings.class.getName(),
296533a5664da21d6bf8819623673fe14b20ba23207John Spurlock            ZenModeAutomationSettings.class.getName(),
29745fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            ZenModeScheduleRuleSettings.class.getName(),
298f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlock            ZenModeEventRuleSettings.class.getName(),
2992583fc1e069d0a54df46258d360499492d7e86d2Jason Monk            ProcessStatsUi.class.getName(),
3001eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monk            PowerUsageDetail.class.getName(),
3012cdafc6be386bb767404e42fc728a1a810aa896aJason Monk            ProcessStatsSummary.class.getName(),
302fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            DrawOverlayDetails.class.getName(),
303fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            WriteSettingsDetails.class.getName(),
304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3065a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3075a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3085a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3095a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3105a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
321263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
3244da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    updateTilesList();
325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
330990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
331990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
332853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
333d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
33441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
33541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
33641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
3373d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
338b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
3393d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
340d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
34135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
3420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
34335062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
34459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
34559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
346d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
347d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
348d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
349d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
350d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
351d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
352769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
353769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
355b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
357d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
358ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int mHomeActivitiesCount = 1;
359d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
3600698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
3610698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
36241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
36341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
36441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
36541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Override the fragment title for Wallpaper settings
36939b467482d1bf256a111c757e9b7621c6f523271Jason Monk        CharSequence title = pref.getTitle();
370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
37139b467482d1bf256a111c757e9b7621c6f523271Jason Monk            title = getString(R.string.wallpaper_settings_fragment_title);
372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
37339b467482d1bf256a111c757e9b7621c6f523271Jason Monk        startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, title,
374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
37939b467482d1bf256a111c757e9b7621c6f523271Jason Monk    public boolean onPreferenceTreeClick(Preference preference) {
380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
381263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
3866f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
387263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
390d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onStart() {
391d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        super.onStart();
392d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
393d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mNeedToRevertToInitialFragment) {
394d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            revertToInitialFragment();
395263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
399d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4003d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4013d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4023d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4033d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
404d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
405d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
406d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
407d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
408d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
409d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4109593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
4119593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
412d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
41323ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
41423ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
41523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
41623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
4178c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
4188c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
4198c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
4208c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
4219593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
422d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
423d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
424d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
425d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
426d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
427d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
428d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
429d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
430d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
431d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
432d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4330d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
4340d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
4350d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
4360d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
4370d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4385b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
4395b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
4405a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
4415a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
4425a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
4435a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
4445a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
4455a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
4465a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
4475b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
4485b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
449d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
450d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
4510d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
4520d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4530d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
4540d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
4550d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4560d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
4570d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
4580d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
459263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
464da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
4650d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
4660d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4675b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
4680d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
469da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
470e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
4715a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
472da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
4734da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        mIsShowingDashboard = className.equals(Settings.class.getName())
4744da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.WirelessSettings.class.getName())
4754da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.DeviceSettings.class.getName())
4764da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.PersonalSettings.class.getName())
4774da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || className.equals(Settings.WirelessSettings.class.getName());
4785a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
47961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
48061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
48161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
4824dfcb8208cdb49167ccf99aeaddf9e206eba87d1Jorim Jaggi        final boolean isSubSettings = this instanceof SubSettings ||
48361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
48461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
48561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
48661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
487712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
488712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
489712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
490712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
491712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
492712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
493da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
494da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
495d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
496d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
497263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
498d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        mContent = (ViewGroup) findViewById(R.id.main_content);
49959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
500263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
501263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
50235062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
503dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            // Run the Index update only if we have some space
504dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            if (!Utils.isLowStorage(this)) {
505dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Index.getInstance(getApplicationContext()).update();
506dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            } else {
507dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
508dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            }
5095cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5105cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5121800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5131800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
514d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
515d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
516263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
5170d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
5185529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
519769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
520769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
521769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
5225f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
523769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
524b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
525263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
526b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
527b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
5283d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
529ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
530ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio                    1 /* one home activity by default */);
531263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
53235062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
533ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                mDisplaySearch = false;
534ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                // UP will be shown only if it is a sub settings
5350d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
5360d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
5375a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
5385a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
53961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
54061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
541d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                }
5420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                setTitleFromIntent(intent);
543c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
5440d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
545a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                switchToFragment(initialFragmentName, initialArguments, true, false,
546a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
54710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            } else {
5485a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // No UP affordance if we are displaying the main Dashboard
549b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio                mDisplayHomeAsUpEnabled = false;
5505a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // Show Search affordance
5515a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                mDisplaySearch = true;
552a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                mInitialTitleResId = R.string.dashboard_title;
55342c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                switchToFragment(DashboardSummary.class.getName(), null, false, false,
554a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
555263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
556263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
557263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
558d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mActionBar = getActionBar();
559d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        if (mActionBar != null) {
560d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
561d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
562d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        }
56341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
56441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
565263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // see if we should show Back/Next buttons
566263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
567263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
568d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio            View buttonBar = findViewById(R.id.button_bar);
569263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (buttonBar != null) {
570263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                buttonBar.setVisibility(View.VISIBLE);
571263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
572d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button backButton = (Button)findViewById(R.id.back_button);
573263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                backButton.setOnClickListener(new OnClickListener() {
574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
5750698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_CANCELED, getResultIntentData());
576263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
579d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button skipButton = (Button)findViewById(R.id.skip_button);
580263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                skipButton.setOnClickListener(new OnClickListener() {
581263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
5820698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
584263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
585263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
586d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                mNextButton = (Button)findViewById(R.id.next_button);
587263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mNextButton.setOnClickListener(new OnClickListener() {
588263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
5890698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
590263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
591263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
592263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                // set our various button parameters
595263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
596263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
597263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setVisibility(View.GONE);
599263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setText(buttonText);
602263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
603263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
605263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
606263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
607263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setVisibility(View.GONE);
608263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
609263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
610263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setText(buttonText);
611263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
612263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
613263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
614263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    skipButton.setVisibility(View.VISIBLE);
615263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
616263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
617263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
618ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
619ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        mHomeActivitiesCount = getHomeActivitiesCount();
620ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    }
621ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
622ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int getHomeActivitiesCount() {
623ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
624ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        getPackageManager().getHomeActivities(homeApps);
625ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        return homeApps.size();
626c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    }
627c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio
628a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private void setTitleFromIntent(Intent intent) {
629a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
630a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (initialTitleResId > 0) {
631a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = null;
632a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = initialTitleResId;
63362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina
63462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            final String initialTitleResPackageName = intent.getStringExtra(
63562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
63662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            if (initialTitleResPackageName != null) {
63762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                try {
63862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Context authContext = createPackageContextAsUser(initialTitleResPackageName,
63962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                            0 /* flags */, new UserHandle(UserHandle.myUserId()));
64062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
64162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    setTitle(mInitialTitle);
64262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitleResId = -1;
64362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    return;
64462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                } catch (NameNotFoundException e) {
64562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
64662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                }
64762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            } else {
64862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                setTitle(mInitialTitleResId);
64962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            }
650a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else {
651a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = -1;
652a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
653a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
654a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitle);
655a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        }
656a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    }
657a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio
658c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    @Override
659263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onBackStackChanged() {
660d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        setTitleFromBackStack();
6618eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    }
6628eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
663b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio    private int setTitleFromBackStack() {
6648eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int count = getFragmentManager().getBackStackEntryCount();
665b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
6668eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (count == 0) {
667a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (mInitialTitleResId > 0) {
668a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitleResId);
669a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
670a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitle);
671a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
672b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio            return 0;
673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
674b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
6758eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
6768eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        setTitleFromBackStackEntry(bse);
677b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
678b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio        return count;
679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
6818eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
6825529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        final CharSequence title;
6838eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int titleRes = bse.getBreadCrumbTitleRes();
6848eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (titleRes > 0) {
6858eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = getText(titleRes);
6865529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        } else {
6878eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = bse.getBreadCrumbTitle();
6888eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        }
6898eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (title != null) {
6908eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            setTitle(title);
6915529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        }
6925529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio    }
6935529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected void onSaveInstanceState(Bundle outState) {
696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onSaveInstanceState(outState);
697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
698769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (mCategories.size() > 0) {
699769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
701d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
702b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
7033d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
7043d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7053d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (mDisplaySearch) {
7063d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // The option menus are created if the ActionBar is visible and they are also created
7073d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // asynchronously. If you launch Settings with an Intent action like
7083d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
7093d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
7103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // menu item and search view are null.
7113d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
7123d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
7133d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7143d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
7153d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
7163d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
717ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
718ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
719263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
720263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
721263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
72239b467482d1bf256a111c757e9b7621c6f523271Jason Monk    protected void onResume() {
723263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onResume();
7248a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
7258a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
7268a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
727263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
728263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
729263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            @Override
730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
7314da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                updateTilesList();
732263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
733263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        };
734263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
735263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mDevelopmentPreferencesListener);
736263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
737263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
738853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
739990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.register(this);
740a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio
7413d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
742a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            onQueryTextSubmit(mSearchQuery);
743a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
7444da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        updateTilesList();
745263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
746263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
747263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
74839b467482d1bf256a111c757e9b7621c6f523271Jason Monk    protected void onPause() {
749263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onPause();
7508a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
7518a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
7528a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
753263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        unregisterReceiver(mBatteryInfoReceiver);
754990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.unregister();
755263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
756263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
757263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
758263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onDestroy() {
759263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onDestroy();
760680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio
761680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
762680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio                mDevelopmentPreferencesListener);
763680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferencesListener = null;
764263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
765263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
766263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected boolean isValidFragment(String fragmentName) {
767263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Almost all fragments are wrapped in this,
768263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // except for a few that have their own activities.
769263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
770263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
771263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
772263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
773263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
774263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
775263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
776263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Intent getIntent() {
777263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        Intent superIntent = super.getIntent();
778263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String startingFragment = getStartingFragmentClass(superIntent);
779263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // This is called from super.onCreate, isMultiPane() is not yet reliable
780263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Do not use onIsHidingHeaders either, which relies itself on this method
781263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (startingFragment != null) {
782263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Intent modIntent = new Intent(superIntent);
783263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
784263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Bundle args = superIntent.getExtras();
785263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (args != null) {
786263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle(args);
787263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
788263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle();
789263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
790263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            args.putParcelable("intent", superIntent);
791ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy            modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
792263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            return modIntent;
793263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
794263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return superIntent;
795263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
796263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
797263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
798263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Checks if the component name in the intent is different from the Settings class and
799263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * returns the class name to load as a fragment.
800263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
801263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String getStartingFragmentClass(Intent intent) {
802263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (mFragmentClass != null) return mFragmentClass;
803263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
804263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String intentClass = intent.getComponent().getClassName();
805263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intentClass.equals(getClass().getName())) return null;
806263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
807263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if ("com.android.settings.ManageApplications".equals(intentClass)
808263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.RunningServices".equals(intentClass)
809263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.applications.StorageUse".equals(intentClass)) {
810263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // Old names of manage apps.
811263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            intentClass = com.android.settings.applications.ManageApplications.class.getName();
812263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
813263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return intentClass;
815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
817263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
81810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment containing a preference panel.  If the preferences
81910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * are being displayed in multi-pane mode, the given fragment class will
82010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * be instantiated and placed in the appropriate pane.  If running in
82110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * single-pane mode, a new activity will be launched in which to show the
82210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
82310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
82410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragmentClass Full name of the class implementing the fragment.
82510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param args Any desired arguments to supply to the fragment.
82610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleRes Optional resource identifier of the title of this
82710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
82810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleText Optional text of the title of this fragment.
82910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultTo Optional fragment that result data should be sent to.
83010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * If non-null, resultTo.onActivityResult() will be called when this
83110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * preference panel is done.  The launched panel must use
83210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
83310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultRequestCode If resultTo is non-null, this is the caller's
83458146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio     * request code to be received with the result.
83510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
83610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
837d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
838a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        String title = null;
839a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleRes < 0) {
840a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (titleText != null) {
841a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = titleText.toString();
842a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
843a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                // There not much we can do in that case
844a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = "";
845a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
846911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio        }
847a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
8480d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                titleRes, title, mIsShortcut);
84910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
85010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
85110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
8527a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * Start a new fragment in a new activity containing a preference panel for a given user. If the
8537a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * preferences are being displayed in multi-pane mode, the given fragment class will be
8547a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
8557a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * activity will be launched in which to show the fragment.
8567a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     *
8577a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param fragmentClass Full name of the class implementing the fragment.
8587a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param args Any desired arguments to supply to the fragment.
8597a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleRes Optional resource identifier of the title of this fragment.
8607a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleText Optional text of the title of this fragment.
8617a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param userHandle The user for which the panel has to be started.
8627a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     */
8637a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
8647a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            CharSequence titleText, UserHandle userHandle) {
865d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // This is a workaround.
866d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
867d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
868d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // starting the fragment could cause a native stack corruption. See b/17523189. However,
869d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // adding that flag and start the preference panel with the same UserHandler will make it
870d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // impossible to use back button to return to the previous screen. See b/20042570.
871d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
872d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
873d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
874d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // when we're calling it as the same user.
875d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
876d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
877d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        } else {
878d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            String title = null;
879d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            if (titleRes < 0) {
880d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                if (titleText != null) {
881d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = titleText.toString();
882d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                } else {
883d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    // There not much we can do in that case
884d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = "";
885d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                }
8867a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            }
887d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            Utils.startWithFragmentAsUser(this, fragmentClass, args,
888d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    titleRes, title, mIsShortcut, userHandle);
8897a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        }
8907a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    }
8917a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban
8927a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    /**
893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Called by a preference panel fragment to finish itself.
894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     *
895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param caller The fragment that is asking to be finished.
896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultCode Optional result code to send back to the original
897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultData Optional result data to send back to the original
899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
900263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        setResult(resultCode, resultData);
90358146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio        finish();
904263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
905263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
906263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
90710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment.
90810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
90910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragment The fragment to start
91010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param push If true, the current fragment will be pushed onto the back stack.  If false,
91110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * the current fragment will be replaced.
91210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
91310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferenceFragment(Fragment fragment, boolean push) {
91410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
915d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, fragment);
91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        if (push) {
91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
91810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.addToBackStack(BACK_STACK_PREFS);
91910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        } else {
92010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        }
92210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        transaction.commitAllowingStateLoss();
92310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
92410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
92510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
926d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     * Switch to a specific Fragment with taking care of validation, Title and BackStack
927d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     */
928d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
929a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
930d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (validate && !isValidFragment(fragmentName)) {
931d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            throw new IllegalArgumentException("Invalid fragment for this activity: "
932d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                    + fragmentName);
933d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
934d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        Fragment f = Fragment.instantiate(this, fragmentName, args);
935d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
936d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, f);
937d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (withTransition) {
93859a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio            TransitionManager.beginDelayedTransition(mContent);
939d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
940d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (addToBackStack) {
941d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
942d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
943a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleResId > 0) {
944a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            transaction.setBreadCrumbTitle(titleResId);
945a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else if (title != null) {
946d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.setBreadCrumbTitle(title);
947d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
948d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        transaction.commitAllowingStateLoss();
94959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio        getFragmentManager().executePendingTransactions();
950d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return f;
951d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
952d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
9534da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private void updateTilesList() {
9544da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        PackageManager pm = getPackageManager();
9554da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        final UserManager um = UserManager.get(this);
9564da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        final boolean isAdmin = um.isAdminUser();
95763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9584da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        String packageName = getPackageName();
9594da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
9604da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
96163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9624da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9634da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.BluetoothSettingsActivity.class.getName()),
9644da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
96563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9664da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9674da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.DataUsageSummaryActivity.class.getName()),
9684da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Utils.isBandwidthControlEnabled(), isAdmin, pm);
96963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9704da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9714da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.SimSettingsActivity.class.getName()),
9724da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Utils.showSimCardTile(this), isAdmin, pm);
97363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9744da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9754da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.PowerUsageSummaryActivity.class.getName()),
9764da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                mBatteryPresent, isAdmin, pm);
97763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9784da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9794da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.HomeSettingsActivity.class.getName()),
9804da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                updateHomeSettingTiles(), isAdmin, pm);
98163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9824da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9834da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.UserSettingsActivity.class.getName()),
9844da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
9854da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                && !Utils.isMonkeyRunning(), isAdmin, pm);
98663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
9874da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
9884da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9894da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        Settings.PaymentSettingsActivity.class.getName()),
9904da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_NFC)
9914da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
9924da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        && adapter != null && adapter.isEnabled(), isAdmin, pm);
9934da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
9944da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
9954da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                Settings.PrintSettingsActivity.class.getName()),
9964da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
99763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
99863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
99963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DevelopmentSettings.PREF_SHOW,
100063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                android.os.Build.TYPE.equals("eng"));
10014da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        setTileEnabled(new ComponentName(packageName,
10024da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        Settings.DevelopmentSettingsActivity.class.getName()),
10034da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
10044da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                isAdmin, pm);
10054da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
10064da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (UserHandle.MU_ENABLED && !isAdmin) {
10074da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            // When on restricted users, disable all extra categories (but only the settings ones).
10084da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            List<DashboardCategory> categories = getDashboardCategories(true);
10094da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            for (DashboardCategory category : categories) {
10104da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                for (DashboardTile tile : category.tiles) {
10114da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    ComponentName component = tile.intent.getComponent();
10124da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    if (packageName.equals(component)&& !ArrayUtils.contains(
10134da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                            SETTINGS_FOR_RESTRICTED, component.getClassName())) {
10144da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                        setTileEnabled(component, false, isAdmin, pm);
101563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
101657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
101763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
101863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
10192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
10204da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        updateDrawer();
10212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
10222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
10234da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
10244da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                                PackageManager pm) {
10254da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (UserHandle.MU_ENABLED && !isAdmin
10264da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
10274da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            enabled = false;
10282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
10294da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        int state = pm.getComponentEnabledSetting(component);
10304da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
10314da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
10324da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (isEnabled != enabled) {
10334da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            pm.setComponentEnabledSetting(component, enabled
10344da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
10354da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
10364da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk                    PackageManager.DONT_KILL_APP);
10372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
103963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10404da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    private boolean updateHomeSettingTiles() {
104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        // Once we decide to show Home settings, keep showing it forever
104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
104463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            return true;
104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
1048b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            mHomeActivitiesCount = getHomeActivitiesCount();
1049ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            if (mHomeActivitiesCount < 2) {
105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                return false;
105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (Exception e) {
105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Can't look up the home activity; bail on configuring the icon
105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Log.w(LOG_TAG, "Problem looking up home activity!", e);
105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        return true;
105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1061263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1062263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1063263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1064263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1065263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1066263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1067263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1068263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1069263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1070263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1071263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1072263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1073263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1074263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1075263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1076263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1077263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1078263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1079263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1080263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1081263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1082263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1083263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1084263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1085263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1086263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1087d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1088d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1089d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1090d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1091d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1092d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1093263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1094d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1095d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1096d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
10977e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1098a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1099a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1100a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1101d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1103d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1104d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1105d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1106d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1108d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1109d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1110d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1111bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1113d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1114d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1116d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1117d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1118d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1119bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1120d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1123d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1124d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
11264da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    @Override
11274da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    protected void onTileClicked(DashboardTile tile) {
11284da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        if (mIsShowingDashboard) {
11294da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            // If on dashboard, don't finish so the back comes back to here.
11304da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            openTile(tile);
11314da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        } else {
11324da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk            super.onTileClicked(tile);
11334da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk        }
11344da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk    }
11354da79e088f9e8d9c6123fbbb7590c779e280c893Jason Monk
1136af00109242a5766ca9418b145c4fb098360c5648Jason Monk    @Override
1137af00109242a5766ca9418b145c4fb098360c5648Jason Monk    public void onProfileTileOpen() {
1138af00109242a5766ca9418b145c4fb098360c5648Jason Monk        if (!mIsShowingDashboard) {
1139af00109242a5766ca9418b145c4fb098360c5648Jason Monk            finish();
1140af00109242a5766ca9418b145c4fb098360c5648Jason Monk        }
1141af00109242a5766ca9418b145c4fb098360c5648Jason Monk    }
1142af00109242a5766ca9418b145c4fb098360c5648Jason Monk
1143d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1144bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1145bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1147d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1148bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1149bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1150bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
1151bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1152a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1153a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1154bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1155d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1156bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1157d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1159d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1160d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1161d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1163d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1164d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1165d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1166bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1167bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1168bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
116923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
117023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
117123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
11730698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
11740698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
11750698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
11760698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
11770698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
11780698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
11790698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
11800698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1182