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
192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar;
22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity;
23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment;
24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager;
25263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction;
26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver;
27d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName;
28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context;
29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent;
30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter;
31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences;
32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo;
33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager;
34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException;
35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo;
36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration;
37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray;
38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser;
39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter;
40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle;
41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler;
42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message;
43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference;
46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen;
49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
5059a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.ArrayMap;
52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet;
53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.Pair;
55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue;
56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml;
57d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
58d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
61263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
6259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
64d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
65c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock
668a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger;
67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils;
69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
716d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
73fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lauimport com.android.settings.applications.DrawOverlayDetails;
74d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
75263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
7686a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xiaimport com.android.settings.applications.ManageAssist;
772cdafc6be386bb767404e42fc728a1a810aa896aJason Monkimport com.android.settings.applications.ProcessStatsSummary;
78263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
79d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monkimport com.android.settings.applications.UsageAccessDetails;
80fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lauimport com.android.settings.applications.WriteSettingsDetails;
81263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
8263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory;
83263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary;
8463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile;
85d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment;
86d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
87a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeForget;
88e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeSettings;
8942833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.PublicVolumeSettings;
9042833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.StorageSettings;
91c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings;
921eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monkimport com.android.settings.fuelgauge.PowerUsageDetail;
93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary;
94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings;
95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
96263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings;
97263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList;
98263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings;
99263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam;
100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings;
101802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings;
1024a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings;
1034a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings;
1044a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation;
1052ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.notification.OtherSoundSettings;
10608531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlockimport com.android.settings.notification.ZenAccessSettings;
107533a5664da21d6bf8819623673fe14b20ba23207John Spurlockimport com.android.settings.notification.ZenModeAutomationSettings;
108f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlockimport com.android.settings.notification.ZenModeEventRuleSettings;
109c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceafJohn Spurlockimport com.android.settings.notification.ZenModeExternalRuleSettings;
110c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlockimport com.android.settings.notification.ZenModePrioritySettings;
1114a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings;
11245fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlockimport com.android.settings.notification.ZenModeScheduleRuleSettings;
113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
1152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor;
1162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index;
1173815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings;
121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings;
12241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar;
123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings;
1247837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings;
125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings;
126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings;
1272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser;
129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException;
130263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
131263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException;
132263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList;
133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List;
1342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport java.util.Map;
1350d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set;
136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity
138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        implements PreferenceManager.OnPreferenceTreeClickListener,
139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        PreferenceFragment.OnPreferenceStartFragmentCallback,
140cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
141d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
142cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        MenuItem.OnActionExpandListener {
143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String LOG_TAG = "Settings";
145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Constants for state save/restore
147769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
148d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
149d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
150b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
1513d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
152ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity, the invoking Intent can contain this extra
156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * string to specify which fragment should be initially displayed.
157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * will call isValidFragment() to confirm that the fragment class name is valid for this
159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * activity.
160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * this extra can also be specified to supply a Bundle of arguments to pass
166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * to that fragment when it is instantiated during the initial creation
167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * of the activity.
168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
172c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
173c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     */
174c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
175c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
1766f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio    public static final String BACK_STACK_PREFS = ":settings:prefs";
1776f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio
178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // extras that allow any preference activity to be launched as part of a wizard
179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // show Back and Next buttons? takes boolean parameter
181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Back will then return RESULT_CANCELED and Next RESULT_OK
182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // add a Skip button?
185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // specify custom text for the Back or Next buttons, or cause a button to not appear
188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // at all by setting it to null
189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
194a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio     * those extra can also be specify to supply the title or title res id to be shown for
195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * that fragment.
196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
197d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
19862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    /**
19962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     * The package name used to resolve the title resource id.
20062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     */
20162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
20262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            ":settings:show_fragment_title_res_package_name";
20361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
20461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_title_resid";
20561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
20661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_shortcut";
20761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
20861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
20961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_subsetting";
210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String META_DATA_KEY_FRAGMENT_CLASS =
212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        "com.android.settings.FRAGMENT_CLASS";
213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
216d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio    private static final String EMPTY_QUERY = "";
217d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
2182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    /**
2192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * Settings will search for system activities of this action and add them as a top level
2202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * settings tile using the following parameters.
2212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>A category must be specified in the meta-data for the activity named
2232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * {@link #EXTRA_CATEGORY_KEY}
2242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>The title may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_TITLE}
2262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * otherwise the label for the activity will be used.
2272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>The icon may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_ICON}
2292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * otherwise the icon for the activity will be used.
2302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>A summary my be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_SUMMARY}
2322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     */
2332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private static final String EXTRA_SETTINGS_ACTION =
2342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            "com.android.settings.action.EXTRA_SETTINGS";
2352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
2362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    /**
2372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * The key used to get the category from metadata of activities of action
2382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * {@link #EXTRA_SETTINGS_ACTION}
2392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * The value must be one of:
2402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.wireless</li>
2412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.device</li>
2422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.personal</li>
2432ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.system</li>
2442ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     */
2452ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private static final String EXTRA_CATEGORY_KEY = "com.android.settings.category";
2462ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static boolean sShowNoHomeNotice = false;
248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String mFragmentClass;
250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
2518eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private CharSequence mInitialTitle;
252a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private int mInitialTitleResId;
2538eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Show only these settings for restricted users
255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private int[] SETTINGS_FOR_RESTRICTED = {
256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_section,
257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wifi_settings,
258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.bluetooth_settings,
259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.data_usage_settings,
2603815561997eced7fd773062ce32eaa50bece072cPauloftheWest            R.id.sim_settings,
261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_settings,
262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.device_section,
2634e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock            R.id.notification_settings,
264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.display_settings,
265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.storage_settings,
266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.application_settings,
267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.battery_settings,
268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.personal_section,
269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.location_settings,
270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.security_settings,
271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.language_settings,
272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.user_settings,
273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.account_settings,
274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.system_section,
275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.date_time_settings,
276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.about_settings,
277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.accessibility_settings,
278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.print_settings,
279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.nfc_payment_settings,
2802858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.home_settings,
2812858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.dashboard
282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String[] ENTRY_FRAGMENTS = {
285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WirelessSettings.class.getName(),
286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiSettings.class.getName(),
287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AdvancedWifiSettings.class.getName(),
2887837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest            SavedAccessPointsWifiSettings.class.getName(),
289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            BluetoothSettings.class.getName(),
2903815561997eced7fd773062ce32eaa50bece072cPauloftheWest            SimSettings.class.getName(),
291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TetherSettings.class.getName(),
292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiP2pSettings.class.getName(),
293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            VpnSettings.class.getName(),
294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DateTimeSettings.class.getName(),
295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocalePicker.class.getName(),
296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            InputMethodAndLanguageSettings.class.getName(),
297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
3003033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.class.getName(),
30486a554091d0705f2152fcf1d78ca1c7720d9842cXiyuan Xia            ManageAssist.class.getName(),
305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ProcessStatsUi.class.getName(),
306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationStation.class.getName(),
307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocationSettings.class.getName(),
308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SecuritySettings.class.getName(),
309d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monk            UsageAccessDetails.class.getName(),
310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrivacySettings.class.getName(),
311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceAdminSettings.class.getName(),
312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccessibilitySettings.class.getName(),
313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CaptionPropertiesFragment.class.getName(),
314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TextToSpeechSettings.class.getName(),
31642833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkey            StorageSettings.class.getName(),
317a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkey            PrivateVolumeForget.class.getName(),
318e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PrivateVolumeSettings.class.getName(),
319e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PublicVolumeSettings.class.getName(),
320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DevelopmentSettings.class.getName(),
321263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
3256d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
33108531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlock            ZenAccessSettings.class.getName(),
332263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
333263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
334263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
337d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
338d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            NotificationSettings.class.getName(),
339d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
340d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
341c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
342c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
343dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
344e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
34533acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath            ApnSettings.class.getName(),
34645fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            WifiCallingSettings.class.getName(),
347c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlock            ZenModePrioritySettings.class.getName(),
348533a5664da21d6bf8819623673fe14b20ba23207John Spurlock            ZenModeAutomationSettings.class.getName(),
34945fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            ZenModeScheduleRuleSettings.class.getName(),
350f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlock            ZenModeEventRuleSettings.class.getName(),
351c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceafJohn Spurlock            ZenModeExternalRuleSettings.class.getName(),
3522583fc1e069d0a54df46258d360499492d7e86d2Jason Monk            ProcessStatsUi.class.getName(),
3531eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monk            PowerUsageDetail.class.getName(),
3542cdafc6be386bb767404e42fc728a1a810aa896aJason Monk            ProcessStatsSummary.class.getName(),
355fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            DrawOverlayDetails.class.getName(),
356fee785645b57c519a31ed403e60e8f76dcc8abbbBilly Lau            WriteSettingsDetails.class.getName(),
357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3595a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3605a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3615a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3625a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3635a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
377b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    invalidateCategories(true);
378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
381263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
383990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
384990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
385853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
386d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
38741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
38841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
38941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
3903d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
391b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
3923d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
393d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
39435062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
3950d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
39635062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
39759a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
39859a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
399d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
400d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
401d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
402d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
403d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
404d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
405769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
406769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
408b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
409769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final int MSG_BUILD_CATEGORIES = 1;
410263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private Handler mHandler = new Handler() {
411263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void handleMessage(Message msg) {
413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            switch (msg.what) {
414769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                case MSG_BUILD_CATEGORIES: {
415b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
416b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    if (forceRefresh) {
41742c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                        buildDashboardCategories(mCategories);
41842c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                    }
419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                } break;
420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
424d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
425ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int mHomeActivitiesCount = 1;
426d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4270698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
4280698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
42941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
43041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
43141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
43241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
433b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
434b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio        if (forceRefresh || mCategories.size() == 0) {
435769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            buildDashboardCategories(mCategories);
436769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        }
437769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        return mCategories;
438769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    }
439769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio
440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Override the fragment title for Wallpaper settings
443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        int titleRes = pref.getTitleRes();
444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            titleRes = R.string.wallpaper_settings_fragment_title;
446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                && UserHandle.myUserId() != UserHandle.USER_OWNER) {
448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (UserManager.get(this).isLinkedUser()) {
449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.profile_info_settings_title;
450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.user_info_settings_title;
452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
459263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
464b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private void invalidateCategories(boolean forceRefresh) {
465769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
466b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            Message msg = new Message();
467b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.what = MSG_BUILD_CATEGORIES;
468b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
472263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
473263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
474263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
4756f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
477263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
478263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onStart() {
480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        super.onStart();
481d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
482d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mNeedToRevertToInitialFragment) {
483d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            revertToInitialFragment();
484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
485263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
486263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
487263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
488d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4893d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4903d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4913d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4923d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
493d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
494d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
495d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
496d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
497d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
498d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4999593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
5009593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
501d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
50223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
50323ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
50423ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
50523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
5068c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
5078c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
5088c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
5098c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
5109593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
512d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
513d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
514d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
515d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
516d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
517d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
518d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
519d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
520d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
521d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
5220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
5230d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
5240d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
5250d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
5260d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5275b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
5285b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
5295a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
5305a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
5315a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5325a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
5335a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
5345a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5355a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
5365b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
5375b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
538d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
539d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
5400d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
5410d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
5430d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
5440d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5450d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
5460d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
5470d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
548263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
549263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
550263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
551263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
552263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
553da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
5540d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
5550d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5565b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
5570d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
558da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
559e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
5605a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
561da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
5625a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        mIsShowingDashboard = className.equals(Settings.class.getName());
5635a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
56461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
56561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
56661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
5674dfcb8208cdb49167ccf99aeaddf9e206eba87d1Jorim Jaggi        final boolean isSubSettings = this instanceof SubSettings ||
56861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
56961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
57061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
57161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
572712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
573712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
574712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
575712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
576712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
577712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
578da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
579da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
580d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
581d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
583d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        mContent = (ViewGroup) findViewById(R.id.main_content);
58459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
585263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
586263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
58735062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
588dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            // Run the Index update only if we have some space
589dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            if (!Utils.isLowStorage(this)) {
590dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Index.getInstance(getApplicationContext()).update();
591dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            } else {
592dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
593dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            }
5945cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5955cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
596d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5971800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5981800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
599d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
600d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
6020d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
6035529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
604769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
605769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
606769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
6075f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
608769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
609b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
610263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
611b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
612b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
6133d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
614ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
615ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio                    1 /* one home activity by default */);
616263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
61735062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
618ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                mDisplaySearch = false;
619ea8b1a7dc5fa11742967923251b437a02568f021Jason Monk                // UP will be shown only if it is a sub settings
6200d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
6210d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
6225a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
6235a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
62461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
62561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
626d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                }
6270d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                setTitleFromIntent(intent);
628c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
6290d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
630a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                switchToFragment(initialFragmentName, initialArguments, true, false,
631a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
63210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            } else {
6335a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // No UP affordance if we are displaying the main Dashboard
634b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio                mDisplayHomeAsUpEnabled = false;
6355a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // Show Search affordance
6365a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                mDisplaySearch = true;
637a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                mInitialTitleResId = R.string.dashboard_title;
63842c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                switchToFragment(DashboardSummary.class.getName(), null, false, false,
639a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
641263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
642263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
643d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mActionBar = getActionBar();
644d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        if (mActionBar != null) {
645d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
646d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
647d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        }
64841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
64941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
650263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // see if we should show Back/Next buttons
651263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
652263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
653d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio            View buttonBar = findViewById(R.id.button_bar);
654263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (buttonBar != null) {
655263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                buttonBar.setVisibility(View.VISIBLE);
656263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
657d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button backButton = (Button)findViewById(R.id.back_button);
658263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                backButton.setOnClickListener(new OnClickListener() {
659263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6600698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_CANCELED, getResultIntentData());
661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
664d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button skipButton = (Button)findViewById(R.id.skip_button);
665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                skipButton.setOnClickListener(new OnClickListener() {
666263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6670698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
668263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
669263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
671d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                mNextButton = (Button)findViewById(R.id.next_button);
672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mNextButton.setOnClickListener(new OnClickListener() {
673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6740698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
676263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                // set our various button parameters
680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setVisibility(View.GONE);
684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setText(buttonText);
687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setVisibility(View.GONE);
693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setText(buttonText);
696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
699263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    skipButton.setVisibility(View.VISIBLE);
700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
701263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
702263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
703ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
704ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        mHomeActivitiesCount = getHomeActivitiesCount();
705ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    }
706ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
707ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int getHomeActivitiesCount() {
708ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
709ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        getPackageManager().getHomeActivities(homeApps);
710ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        return homeApps.size();
711c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    }
712c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio
713a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private void setTitleFromIntent(Intent intent) {
714a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
715a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (initialTitleResId > 0) {
716a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = null;
717a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = initialTitleResId;
71862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina
71962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            final String initialTitleResPackageName = intent.getStringExtra(
72062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
72162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            if (initialTitleResPackageName != null) {
72262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                try {
72362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Context authContext = createPackageContextAsUser(initialTitleResPackageName,
72462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                            0 /* flags */, new UserHandle(UserHandle.myUserId()));
72562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
72662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    setTitle(mInitialTitle);
72762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitleResId = -1;
72862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    return;
72962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                } catch (NameNotFoundException e) {
73062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
73162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                }
73262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            } else {
73362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                setTitle(mInitialTitleResId);
73462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            }
735a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else {
736a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = -1;
737a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
738a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
739a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitle);
740a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        }
741a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    }
742a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio
743c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    @Override
744263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onBackStackChanged() {
745d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        setTitleFromBackStack();
7468eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    }
7478eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
748b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio    private int setTitleFromBackStack() {
7498eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int count = getFragmentManager().getBackStackEntryCount();
750b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7518eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (count == 0) {
752a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (mInitialTitleResId > 0) {
753a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitleResId);
754a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
755a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitle);
756a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
757b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio            return 0;
758263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
759b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7608eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
7618eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        setTitleFromBackStackEntry(bse);
762b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
763b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio        return count;
764263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
765263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
7668eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
7675529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        final CharSequence title;
7688eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int titleRes = bse.getBreadCrumbTitleRes();
7698eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (titleRes > 0) {
7708eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = getText(titleRes);
7715529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        } else {
7728eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = bse.getBreadCrumbTitle();
7738eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        }
7748eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (title != null) {
7758eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            setTitle(title);
7765529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        }
7775529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio    }
7785529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
779263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
780263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected void onSaveInstanceState(Bundle outState) {
781263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onSaveInstanceState(outState);
782263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
783769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (mCategories.size() > 0) {
784769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
785263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
786d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
787b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
7883d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
7893d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7903d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (mDisplaySearch) {
7913d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // The option menus are created if the ActionBar is visible and they are also created
7923d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // asynchronously. If you launch Settings with an Intent action like
7933d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
7943d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
7953d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // menu item and search view are null.
7963d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
7973d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
7983d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7993d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
8003d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
8013d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
802ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
803ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
804263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
805263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
806263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
807263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onResume() {
808263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onResume();
8098a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
8108a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
8118a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
812263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
813ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final int newHomeActivityCount = getHomeActivitiesCount();
814ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        if (newHomeActivityCount != mHomeActivitiesCount) {
815ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = newHomeActivityCount;
816b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            invalidateCategories(true);
817ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        }
818ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
820263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            @Override
821263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
822b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                invalidateCategories(true);
823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
824263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        };
825263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
826263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mDevelopmentPreferencesListener);
827263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
828263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
829853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
830990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.register(this);
831a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio
8323d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
833a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            onQueryTextSubmit(mSearchQuery);
834a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
835263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
836263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
837263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
838263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onPause() {
839263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onPause();
8408a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
8418a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
8428a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
843263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        unregisterReceiver(mBatteryInfoReceiver);
844990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.unregister();
845263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
846263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
847263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
848263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onDestroy() {
849263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onDestroy();
850680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio
851680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
852680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio                mDevelopmentPreferencesListener);
853680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferencesListener = null;
854263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
855263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
856263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected boolean isValidFragment(String fragmentName) {
857263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Almost all fragments are wrapped in this,
858263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // except for a few that have their own activities.
859263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
860263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
861263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
862263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
863263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
864263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
865263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
866263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Intent getIntent() {
867263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        Intent superIntent = super.getIntent();
868263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String startingFragment = getStartingFragmentClass(superIntent);
869263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // This is called from super.onCreate, isMultiPane() is not yet reliable
870263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Do not use onIsHidingHeaders either, which relies itself on this method
871263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (startingFragment != null) {
872263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Intent modIntent = new Intent(superIntent);
873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Bundle args = superIntent.getExtras();
875263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (args != null) {
876263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle(args);
877263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
878263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle();
879263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
880263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            args.putParcelable("intent", superIntent);
881ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy            modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
882263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            return modIntent;
883263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
884263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return superIntent;
885263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
886263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
887263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
888263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Checks if the component name in the intent is different from the Settings class and
889263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * returns the class name to load as a fragment.
890263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
891263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String getStartingFragmentClass(Intent intent) {
892263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (mFragmentClass != null) return mFragmentClass;
893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String intentClass = intent.getComponent().getClassName();
895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intentClass.equals(getClass().getName())) return null;
896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if ("com.android.settings.ManageApplications".equals(intentClass)
898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.RunningServices".equals(intentClass)
899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.applications.StorageUse".equals(intentClass)) {
900263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // Old names of manage apps.
901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            intentClass = com.android.settings.applications.ManageApplications.class.getName();
902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
903263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
904263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return intentClass;
905263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
906263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
907263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
90810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment containing a preference panel.  If the preferences
90910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * are being displayed in multi-pane mode, the given fragment class will
91010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * be instantiated and placed in the appropriate pane.  If running in
91110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * single-pane mode, a new activity will be launched in which to show the
91210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
91310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
91410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragmentClass Full name of the class implementing the fragment.
91510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param args Any desired arguments to supply to the fragment.
91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleRes Optional resource identifier of the title of this
91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
91810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleText Optional text of the title of this fragment.
91910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultTo Optional fragment that result data should be sent to.
92010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * If non-null, resultTo.onActivityResult() will be called when this
92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * preference panel is done.  The launched panel must use
92210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
92310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultRequestCode If resultTo is non-null, this is the caller's
92458146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio     * request code to be received with the result.
92510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
92610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
927d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
928a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        String title = null;
929a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleRes < 0) {
930a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (titleText != null) {
931a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = titleText.toString();
932a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
933a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                // There not much we can do in that case
934a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = "";
935a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
936911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio        }
937a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
9380d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                titleRes, title, mIsShortcut);
93910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
94010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
94110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
9427a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * Start a new fragment in a new activity containing a preference panel for a given user. If the
9437a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * preferences are being displayed in multi-pane mode, the given fragment class will be
9447a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
9457a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * activity will be launched in which to show the fragment.
9467a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     *
9477a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param fragmentClass Full name of the class implementing the fragment.
9487a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param args Any desired arguments to supply to the fragment.
9497a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleRes Optional resource identifier of the title of this fragment.
9507a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleText Optional text of the title of this fragment.
9517a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param userHandle The user for which the panel has to be started.
9527a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     */
9537a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
9547a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            CharSequence titleText, UserHandle userHandle) {
955d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // This is a workaround.
956d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
957d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
958d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // starting the fragment could cause a native stack corruption. See b/17523189. However,
959d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // adding that flag and start the preference panel with the same UserHandler will make it
960d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // impossible to use back button to return to the previous screen. See b/20042570.
961d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
962d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
963d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
964d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // when we're calling it as the same user.
965d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
966d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
967d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        } else {
968d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            String title = null;
969d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            if (titleRes < 0) {
970d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                if (titleText != null) {
971d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = titleText.toString();
972d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                } else {
973d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    // There not much we can do in that case
974d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = "";
975d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                }
9767a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            }
977d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            Utils.startWithFragmentAsUser(this, fragmentClass, args,
978d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    titleRes, title, mIsShortcut, userHandle);
9797a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        }
9807a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    }
9817a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban
9827a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    /**
983263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Called by a preference panel fragment to finish itself.
984263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     *
985263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param caller The fragment that is asking to be finished.
986263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultCode Optional result code to send back to the original
987263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
988263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultData Optional result data to send back to the original
989263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
990263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
991263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
992263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        setResult(resultCode, resultData);
99358146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio        finish();
994263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
995263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
996263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
99710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment.
99810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
99910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragment The fragment to start
100010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param push If true, the current fragment will be pushed onto the back stack.  If false,
100110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * the current fragment will be replaced.
100210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
100310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferenceFragment(Fragment fragment, boolean push) {
100410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
1005d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, fragment);
100610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        if (push) {
100710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
100810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.addToBackStack(BACK_STACK_PREFS);
100910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        } else {
101010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
101110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        }
101210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        transaction.commitAllowingStateLoss();
101310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
101410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
101510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
1016d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     * Switch to a specific Fragment with taking care of validation, Title and BackStack
1017d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     */
1018d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
1019a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
1020d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (validate && !isValidFragment(fragmentName)) {
1021d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            throw new IllegalArgumentException("Invalid fragment for this activity: "
1022d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                    + fragmentName);
1023d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1024d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        Fragment f = Fragment.instantiate(this, fragmentName, args);
1025d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
1026d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, f);
1027d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (withTransition) {
102859a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio            TransitionManager.beginDelayedTransition(mContent);
1029d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1030d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (addToBackStack) {
1031d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1032d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1033a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleResId > 0) {
1034a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            transaction.setBreadCrumbTitle(titleResId);
1035a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else if (title != null) {
1036d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.setBreadCrumbTitle(title);
1037d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1038d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        transaction.commitAllowingStateLoss();
103959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio        getFragmentManager().executePendingTransactions();
1040d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return f;
1041d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1042d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
1044769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio     * Called when the activity needs its list of categories/tiles built.
104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param categories The list in which to place the tiles categories.
104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
1048769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private void buildDashboardCategories(List<DashboardCategory> categories) {
10495f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio        categories.clear();
10502acff556c25e788c47284c9fc837f27a1916b578Jason Monk        loadCategoriesFromResource(R.xml.dashboard_categories, categories, this);
105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        updateTilesList(categories);
105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * Parse the given XML file as a categories description, adding each
105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * parsed categories and tiles into the target list.
105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param resid The XML resource to load and parse.
105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param target The list in which the parsed categories and tiles should be placed.
106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
10612acff556c25e788c47284c9fc837f27a1916b578Jason Monk    public static void loadCategoriesFromResource(int resid, List<DashboardCategory> target,
10622acff556c25e788c47284c9fc837f27a1916b578Jason Monk            Context context) {
106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        XmlResourceParser parser = null;
106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
10652acff556c25e788c47284c9fc837f27a1916b578Jason Monk            parser = context.getResources().getXml(resid);
106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            AttributeSet attrs = Xml.asAttributeSet(parser);
106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int type;
106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && type != XmlPullParser.START_TAG) {
107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Parse next until start tag is found
107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            String nodeName = parser.getName();
107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (!"dashboard-categories".equals(nodeName)) {
107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                throw new RuntimeException(
107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        "XML document must start with <preference-categories> tag; found"
107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                + nodeName + " at " + parser.getPositionDescription());
107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Bundle curBundle = null;
108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            final int outerDepth = parser.getDepth();
108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
108663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
108763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    continue;
108863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
108963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                nodeName = parser.getName();
109163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if ("dashboard-category".equals(nodeName)) {
109263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    DashboardCategory category = new DashboardCategory();
109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10942acff556c25e788c47284c9fc837f27a1916b578Jason Monk                    TypedArray sa = context.obtainStyledAttributes(
109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            attrs, com.android.internal.R.styleable.PreferenceHeader);
109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    category.id = sa.getResourceId(
109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_id,
109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            (int)DashboardCategory.CAT_ID_UNDEFINED);
109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedValue tv = sa.peekValue(
110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_title);
110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (tv.resourceId != 0) {
110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.titleRes = tv.resourceId;
110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.title = tv.string;
110763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
110863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
110963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sa.recycle();
11102acff556c25e788c47284c9fc837f27a1916b578Jason Monk                    sa = context.obtainStyledAttributes(attrs,
11112acff556c25e788c47284c9fc837f27a1916b578Jason Monk                            com.android.internal.R.styleable.Preference);
11122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    tv = sa.peekValue(
11132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            com.android.internal.R.styleable.Preference_key);
11142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
11152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        if (tv.resourceId != 0) {
11162acff556c25e788c47284c9fc837f27a1916b578Jason Monk                            category.key = context.getString(tv.resourceId);
11172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else {
11182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.key = tv.string.toString();
11192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        }
11202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    }
11212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    sa.recycle();
112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final int innerDepth = parser.getDepth();
112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            continue;
112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        String innerNodeName = parser.getName();
113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (innerNodeName.equals("dashboard-tile")) {
113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            DashboardTile tile = new DashboardTile();
113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11342acff556c25e788c47284c9fc837f27a1916b578Jason Monk                            sa = context.obtainStyledAttributes(
113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    attrs, com.android.internal.R.styleable.PreferenceHeader);
113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.id = sa.getResourceId(
113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_id,
1138e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio                                    (int)TILE_ID_UNDEFINED);
113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_title);
114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.titleRes = tv.resourceId;
114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.title = tv.string;
114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_summary);
115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summaryRes = tv.resourceId;
115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summary = tv.string;
115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.iconRes = sa.getResourceId(
115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_icon, 0);
115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.fragment = sa.getString(
116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_fragment);
116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa.recycle();
116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle == null) {
116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = new Bundle();
116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            final int innerDepth2 = parser.getDepth();
116863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
116963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
117163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    continue;
117263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
117463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                String innerNodeName2 = parser.getName();
117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (innerNodeName2.equals("extra")) {
11762acff556c25e788c47284c9fc837f27a1916b578Jason Monk                                    context.getResources().parseBundleExtra("extra", attrs,
11772acff556c25e788c47284c9fc837f27a1916b578Jason Monk                                            curBundle);
117863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else if (innerNodeName2.equals("intent")) {
11812acff556c25e788c47284c9fc837f27a1916b578Jason Monk                                    tile.intent = Intent.parseIntent(context.getResources(), parser,
11822acff556c25e788c47284c9fc837f27a1916b578Jason Monk                                            attrs);
118363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
118563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
118663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
118763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
118863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle.size() > 0) {
119063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                tile.fragmentArguments = curBundle;
119163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = null;
119263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
119363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11943815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            // Show the SIM Cards setting if there are more than 2 SIMs installed.
11952acff556c25e788c47284c9fc837f27a1916b578Jason Monk                            if(tile.id != R.id.sim_settings || Utils.showSimCardTile(context)){
11963815561997eced7fd773062ce32eaa50bece072cPauloftheWest                                category.addTile(tile);
11973815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            }
119863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11992ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else if (innerNodeName.equals("external-tiles")) {
12002ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.externalIndex = category.getTilesCount();
120163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
120263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            XmlUtils.skipCurrentTag(parser);
120363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
120463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
120563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    target.add(category);
120763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else {
120863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    XmlUtils.skipCurrentTag(parser);
120963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
121063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
121163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (XmlPullParserException e) {
121363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
121463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (IOException e) {
121563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
121663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } finally {
121763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (parser != null) parser.close();
121863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
121963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
122063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void updateTilesList(List<DashboardCategory> target) {
122263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
122363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DevelopmentSettings.PREF_SHOW,
122463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                android.os.Build.TYPE.equals("eng"));
122563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
122763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final int size = target.size();
122963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        for (int i = 0; i < size; i++) {
123063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
123163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            DashboardCategory category = target.get(i);
123263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
123363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Ids are integers, so downcasting is ok
123463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int id = (int) category.id;
123563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int n = category.getTilesCount() - 1;
123663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while (n >= 0) {
123763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
123863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DashboardTile tile = category.getTile(n);
123957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                boolean removeTile = false;
124063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                id = (int) tile.id;
124163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
124257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
124357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    }
124563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.wifi_settings) {
124663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove WiFi Settings if WiFi service is not available.
124763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
124857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
125063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.bluetooth_settings) {
125163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove Bluetooth Settings if Bluetooth service is not available.
125263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
125357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
125463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
125563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.data_usage_settings) {
125663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove data usage when kernel module not enabled
1257b45e27bc0f52d64a71aecba661770b30f6299301Jason Monk                    if (!Utils.isBandwidthControlEnabled()) {
1258b45e27bc0f52d64a71aecba661770b30f6299301Jason Monk                        removeTile = true;
125963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
126063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.battery_settings) {
126163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove battery settings when battery is not available. (e.g. TV)
126263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
126363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!mBatteryPresent) {
126457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
126563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
126663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.home_settings) {
126763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!updateHomeSettingTiles(tile)) {
126857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
126963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
127063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.user_settings) {
12714093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                    boolean hasMultipleUsers =
12724093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            ((UserManager) getSystemService(Context.USER_SERVICE))
12734093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    .getUserCount() > 1;
127463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!UserHandle.MU_ENABLED
127536940543e98c96413168d094914810ce3ccc424fNicolas Prevot                            || !UserManager.supportsMultipleUsers()
127663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            || Utils.isMonkeyRunning()) {
127757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
127863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
127963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.nfc_payment_settings) {
128063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
128157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
128263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } else {
128363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // Only show if NFC is on and we have the HCE feature
128463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1285b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                        if (adapter == null || !adapter.isEnabled() ||
1286b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                !getPackageManager().hasSystemFeature(
1287b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                        PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
128857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
128963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
129063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
1291488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                } else if (id == R.id.print_settings) {
1292488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1293488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                            PackageManager.FEATURE_PRINTING);
1294488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    if (!hasPrintingSupport) {
129557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
1296488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    }
129763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.development_settings) {
12986c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                    if (!showDev || um.hasUserRestriction(
12996c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                            UserManager.DISALLOW_DEBUGGING_FEATURES)) {
130057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
130163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
130263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
130363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
130463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
130557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
130657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    removeTile = true;
130763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
130863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
130957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                if (removeTile && n < category.getTilesCount()) {
131057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    category.removeTile(n);
131157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
131263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                n--;
131363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
131463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
13152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        addExternalTiles(target);
13162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target) {
13192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Map<Pair<String, String>, DashboardTile> addedCache =
13202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                new ArrayMap<Pair<String, String>, DashboardTile>();
13212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        UserManager userManager = UserManager.get(this);
13222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (UserHandle user : userManager.getUserProfiles()) {
13232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            addExternalTiles(target, user, addedCache);
13242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target, UserHandle user,
13282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Map<Pair<String, String>, DashboardTile> addedCache) {
13292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        PackageManager pm = getPackageManager();
13302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Intent intent = new Intent(EXTRA_SETTINGS_ACTION);
13312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        List<ResolveInfo> results = pm.queryIntentActivitiesAsUser(intent,
13322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                PackageManager.GET_META_DATA, user.getIdentifier());
13332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (ResolveInfo resolved : results) {
13342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (!resolved.system) {
13352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                // Do not allow any app to add to settings, only system ones.
13362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            ActivityInfo activityInfo = resolved.activityInfo;
13392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Bundle metaData = activityInfo.metaData;
13402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) {
13412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action "
13422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + EXTRA_SETTINGS_ACTION + " missing metadata " +
13432ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        (metaData == null ? "" : EXTRA_CATEGORY_KEY));
13442ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13452ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13462ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY);
13472ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardCategory category = getCategory(target, categoryKey);
13482ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (category == null) {
13492ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown "
13502ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + "category key " + categoryKey);
13512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13522ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13532ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Pair<String, String> key = new Pair<String, String>(activityInfo.packageName,
13542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    activityInfo.name);
13552ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardTile tile = addedCache.get(key);
13562ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (tile == null) {
13572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile = new DashboardTile();
13582ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile.intent = new Intent().setClassName(
13592ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        activityInfo.packageName, activityInfo.name);
13602ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile);
13612ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13622ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                if (category.externalIndex == -1) {
13632ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // If no location for external tiles has been specified for this category,
13642ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // then just put them at the end.
13652ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(tile);
13662ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                } else {
13672ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(category.externalIndex, tile);
13682ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                }
13692ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                addedCache.put(key, tile);
13702ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13712ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            tile.userHandle.add(user);
13722ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13732ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13742ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13752ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private DashboardCategory getCategory(List<DashboardCategory> target, String categoryKey) {
13762ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (DashboardCategory category : target) {
13772ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (categoryKey.equals(category.key)) {
13782ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                return category;
13792ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13802ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13812ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        return null;
138263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
138363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
138463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private boolean updateHomeSettingTiles(DashboardTile tile) {
138563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        // Once we decide to show Home settings, keep showing it forever
138663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
138763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
138863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            return true;
138963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
139063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
139163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
1392b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            mHomeActivitiesCount = getHomeActivitiesCount();
1393ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            if (mHomeActivitiesCount < 2) {
139463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // When there's only one available home app, omit this settings
139563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // category entirely at the top level UI.  If the user just
139663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // uninstalled the penultimate home app candidiate, we also
139763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // now tell them about why they aren't seeing 'Home' in the list.
139863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (sShowNoHomeNotice) {
139963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sShowNoHomeNotice = false;
140063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    NoHomeDialogFragment.show(this);
140163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
140263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                return false;
140363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            } else {
140463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Okay, we're allowing the Home settings category.  Tell it, when
140563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // invoked via this front door, that we'll need to be told about the
140663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // case when the user uninstalls all but one home app.
140763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (tile.fragmentArguments == null) {
140863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    tile.fragmentArguments = new Bundle();
140963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
141063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
141163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
141263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (Exception e) {
141363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Can't look up the home activity; bail on configuring the icon
141463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Log.w(LOG_TAG, "Problem looking up home activity!", e);
141563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
141663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
141763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
141863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        return true;
141963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
142063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static void requestHomeNotice() {
1448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        sShowNoHomeNotice = true;
1449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1451d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1452d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1453d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1454d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1455d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1456d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
14617e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1462a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1463a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1464a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1465d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1466263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1467d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1468d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1469d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1470d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1472d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1473d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1474d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1475bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1477d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1478d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1479263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1481d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1482d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1483bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1484d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1485263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1486263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1487d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1488d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1489263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1491bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1492bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1493263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1494d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1495bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1496bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1497bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
1498bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1499a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1500a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1501bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1502d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1503bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1504d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1505263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1506d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1507d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1508d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1509263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1510d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1512d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1513bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1514bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1515bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
151623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
151723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
151823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1519263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
15200698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15210698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
15220698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
15230698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
15240698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15250698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
15260698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
15270698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1528263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1529