SettingsActivity.java revision 08531a81cb34dc45f0da4ca88e8530169831c7d2
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.INetworkManagementService;
43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message;
44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException;
45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager;
46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference;
49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment;
50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager;
51263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen;
52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
5359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.ArrayMap;
55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet;
56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.Pair;
58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue;
59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml;
60d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
61d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
64263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
6559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
67d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
68c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock
698a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger;
70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils;
72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
73263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
746d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
75263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
76d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
77263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
78263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
79d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monkimport com.android.settings.applications.UsageAccessDetails;
80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
8163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory;
82263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary;
8363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile;
84d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment;
85d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
86a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeForget;
87e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeSettings;
8842833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.PublicVolumeSettings;
8942833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.StorageSettings;
90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.UsbSettings;
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;
107f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlockimport com.android.settings.notification.ZenModeEventRuleSettings;
108c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceafJohn Spurlockimport com.android.settings.notification.ZenModeExternalRuleSettings;
109c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlockimport com.android.settings.notification.ZenModePrioritySettings;
1104a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings;
11145fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlockimport com.android.settings.notification.ZenModeScheduleRuleSettings;
112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
1142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor;
1152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index;
1163815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
119b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackbornimport com.android.settings.voice.VoiceInputSettings;
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(),
297b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn            VoiceInputSettings.class.getName(),
298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
3013033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.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            UsbSettings.class.getName(),
322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
3266d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
331263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
33208531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlock            ZenAccessSettings.class.getName(),
333263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
334263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
337263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
338d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
339d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            NotificationSettings.class.getName(),
340d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
341d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
342c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
343c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
344dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
345e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
34633acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath            ApnSettings.class.getName(),
34745fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            WifiCallingSettings.class.getName(),
348c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlock            ZenModePrioritySettings.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(),
354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
355263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3565a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3575a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3585a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3595a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3605a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
374b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    invalidateCategories(true);
375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
380990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
381990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
382853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
383d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
38441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
38541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
38641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
3873d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
388b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
3893d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
390d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
39135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
3920d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
39335062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
39459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
39559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
396d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
397d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
398d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
399d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
400d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
401d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
402769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
403769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
405b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
406769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final int MSG_BUILD_CATEGORIES = 1;
407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private Handler mHandler = new Handler() {
408263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
409263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void handleMessage(Message msg) {
410263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            switch (msg.what) {
411769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                case MSG_BUILD_CATEGORIES: {
412b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
413b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    if (forceRefresh) {
41442c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                        buildDashboardCategories(mCategories);
41542c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                    }
416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                } break;
417263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
421d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
422ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int mHomeActivitiesCount = 1;
423d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4240698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
4250698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
42641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
42741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
42841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
42941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
430b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
431b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio        if (forceRefresh || mCategories.size() == 0) {
432769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            buildDashboardCategories(mCategories);
433769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        }
434769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        return mCategories;
435769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    }
436769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio
437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Override the fragment title for Wallpaper settings
440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        int titleRes = pref.getTitleRes();
441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            titleRes = R.string.wallpaper_settings_fragment_title;
443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                && UserHandle.myUserId() != UserHandle.USER_OWNER) {
445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (UserManager.get(this).isLinkedUser()) {
446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.profile_info_settings_title;
447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.user_info_settings_title;
449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
459263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
461b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private void invalidateCategories(boolean forceRefresh) {
462769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
463b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            Message msg = new Message();
464b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.what = MSG_BUILD_CATEGORIES;
465b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
466263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
467263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
4726f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
473263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
474263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
475263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
476d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onStart() {
477d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        super.onStart();
478d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mNeedToRevertToInitialFragment) {
480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            revertToInitialFragment();
481263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
482263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
483263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
485d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4863d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4873d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4883d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4893d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
491d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
492d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
493d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
494d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
495d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4969593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
4979593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
498d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
49923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
50023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
50123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
50223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
5038c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
5048c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
5058c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
5068c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
5079593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
508d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
509d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
510d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
512d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
513d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
514d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
515d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
516d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
517d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
518d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
5190d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
5200d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
5210d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
5220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
5230d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5245b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
5255b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
5265a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
5275a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
5285a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5295a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
5305a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
5315a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5325a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
5335b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
5345b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
535d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
536d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
5370d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
5380d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5390d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
5400d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
5410d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
5430d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
5440d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
545263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
546263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
547263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
548263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
549263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
550da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
5510d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
5520d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5535b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
5540d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
555da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
556e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
5575a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
558da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
5595a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        mIsShowingDashboard = className.equals(Settings.class.getName());
5605a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
56161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
56261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
56361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
5644dfcb8208cdb49167ccf99aeaddf9e206eba87d1Jorim Jaggi        final boolean isSubSettings = this instanceof SubSettings ||
56561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
56661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
56761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
56861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
569712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
570712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
571712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
572712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
573712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
574712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
575da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
576da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
577d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
578d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
580d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        mContent = (ViewGroup) findViewById(R.id.main_content);
58159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
58435062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
585dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            // Run the Index update only if we have some space
586dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            if (!Utils.isLowStorage(this)) {
587dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Index.getInstance(getApplicationContext()).update();
588dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            } else {
589dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
590dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            }
5915cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5925cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
593d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5941800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5951800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
596d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
597d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
5990d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
6005529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
601769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
602769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
603769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
6045f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
605769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
606b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
607263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
608b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
609b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
6103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
611ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
612ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio                    1 /* one home activity by default */);
613263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
61435062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
6150d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // Search is shown we are launched thru a Settings "shortcut". UP will be shown
6160d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // only if it is a sub settings
6170d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
6180d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
6193d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio                    mDisplaySearch = false;
6205a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
6215a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
6225a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplaySearch = true;
62361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
62461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
62561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplaySearch = 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();
105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        loadCategoriesFromResource(R.xml.dashboard_categories, categories);
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     */
106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
106263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        XmlResourceParser parser = null;
106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            parser = getResources().getXml(resid);
106563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            AttributeSet attrs = Xml.asAttributeSet(parser);
106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int type;
106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && type != XmlPullParser.START_TAG) {
107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Parse next until start tag is found
107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            String nodeName = parser.getName();
107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (!"dashboard-categories".equals(nodeName)) {
107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                throw new RuntimeException(
107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        "XML document must start with <preference-categories> tag; found"
107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                + nodeName + " at " + parser.getPositionDescription());
107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Bundle curBundle = null;
108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            final int outerDepth = parser.getDepth();
108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
108663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    continue;
108763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
108863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                nodeName = parser.getName();
109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if ("dashboard-category".equals(nodeName)) {
109163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    DashboardCategory category = new DashboardCategory();
109263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedArray sa = obtainStyledAttributes(
109463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            attrs, com.android.internal.R.styleable.PreferenceHeader);
109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    category.id = sa.getResourceId(
109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_id,
109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            (int)DashboardCategory.CAT_ID_UNDEFINED);
109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedValue tv = sa.peekValue(
110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_title);
110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (tv.resourceId != 0) {
110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.titleRes = tv.resourceId;
110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.title = tv.string;
110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
110763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
110863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sa.recycle();
11092ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    sa = obtainStyledAttributes(attrs, com.android.internal.R.styleable.Preference);
11102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    tv = sa.peekValue(
11112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            com.android.internal.R.styleable.Preference_key);
11122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
11132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        if (tv.resourceId != 0) {
11142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.key = getString(tv.resourceId);
11152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else {
11162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.key = tv.string.toString();
11172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        }
11182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    }
11192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    sa.recycle();
112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final int innerDepth = parser.getDepth();
112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            continue;
112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        String innerNodeName = parser.getName();
112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (innerNodeName.equals("dashboard-tile")) {
113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            DashboardTile tile = new DashboardTile();
113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa = obtainStyledAttributes(
113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    attrs, com.android.internal.R.styleable.PreferenceHeader);
113463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.id = sa.getResourceId(
113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_id,
1136e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio                                    (int)TILE_ID_UNDEFINED);
113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
113863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_title);
113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.titleRes = tv.resourceId;
114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.title = tv.string;
114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_summary);
114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summaryRes = tv.resourceId;
115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summary = tv.string;
115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.iconRes = sa.getResourceId(
115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_icon, 0);
115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.fragment = sa.getString(
115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_fragment);
115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa.recycle();
116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle == null) {
116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = new Bundle();
116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            final int innerDepth2 = parser.getDepth();
116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
116763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
116863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
116963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    continue;
117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
117163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
117263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                String innerNodeName2 = parser.getName();
117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (innerNodeName2.equals("extra")) {
117463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    getResources().parseBundleExtra("extra", attrs, curBundle);
117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
117663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
117763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else if (innerNodeName2.equals("intent")) {
117863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.intent = Intent.parseIntent(getResources(), parser, attrs);
117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
118163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
118263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
118363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
118463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle.size() > 0) {
118663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                tile.fragmentArguments = curBundle;
118763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = null;
118863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
118963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11903815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            // Show the SIM Cards setting if there are more than 2 SIMs installed.
119122a2a49b445b8721c8194eedf3608ea81c62ccefFabrice Di Meglio                            if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
11923815561997eced7fd773062ce32eaa50bece072cPauloftheWest                                category.addTile(tile);
11933815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            }
119463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11952ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else if (innerNodeName.equals("external-tiles")) {
11962ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.externalIndex = category.getTilesCount();
119763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
119863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            XmlUtils.skipCurrentTag(parser);
119963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
120063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
120163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    target.add(category);
120363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else {
120463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    XmlUtils.skipCurrentTag(parser);
120563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
120663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
120763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (XmlPullParserException e) {
120963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
121063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (IOException e) {
121163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
121263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } finally {
121363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (parser != null) parser.close();
121463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
121563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
121663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void updateTilesList(List<DashboardCategory> target) {
121863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
121963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DevelopmentSettings.PREF_SHOW,
122063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                android.os.Build.TYPE.equals("eng"));
122163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
122363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final int size = target.size();
122563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        for (int i = 0; i < size; i++) {
122663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            DashboardCategory category = target.get(i);
122863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Ids are integers, so downcasting is ok
123063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int id = (int) category.id;
123163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int n = category.getTilesCount() - 1;
123263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while (n >= 0) {
123363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
123463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DashboardTile tile = category.getTile(n);
123557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                boolean removeTile = false;
123663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                id = (int) tile.id;
123763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
123857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
123957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    }
124163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.wifi_settings) {
124263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove WiFi Settings if WiFi service is not available.
124363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
124457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
124663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.bluetooth_settings) {
124763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove Bluetooth Settings if Bluetooth service is not available.
124863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
124957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
125063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
125163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.data_usage_settings) {
125263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove data usage when kernel module not enabled
125363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final INetworkManagementService netManager = INetworkManagementService.Stub
125463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
125563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    try {
125663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (!netManager.isBandwidthControlEnabled()) {
125757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
125863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
125963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } catch (RemoteException e) {
126063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // ignored
126163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
126263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.battery_settings) {
126363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove battery settings when battery is not available. (e.g. TV)
126463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
126563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!mBatteryPresent) {
126657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
126763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
126863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.home_settings) {
126963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!updateHomeSettingTiles(tile)) {
127057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
127163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
127263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.user_settings) {
12734093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                    boolean hasMultipleUsers =
12744093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            ((UserManager) getSystemService(Context.USER_SERVICE))
12754093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    .getUserCount() > 1;
127663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!UserHandle.MU_ENABLED
12774093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            || (!UserManager.supportsMultipleUsers()
12784093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    && !hasMultipleUsers)
127963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            || Utils.isMonkeyRunning()) {
128057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
128163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
128263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.nfc_payment_settings) {
128363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
128457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
128563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } else {
128663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // Only show if NFC is on and we have the HCE feature
128763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1288b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                        if (adapter == null || !adapter.isEnabled() ||
1289b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                !getPackageManager().hasSystemFeature(
1290b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                        PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
129157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
129263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
129363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
1294488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                } else if (id == R.id.print_settings) {
1295488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1296488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                            PackageManager.FEATURE_PRINTING);
1297488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    if (!hasPrintingSupport) {
129857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
1299488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    }
130063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.development_settings) {
13016c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                    if (!showDev || um.hasUserRestriction(
13026c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                            UserManager.DISALLOW_DEBUGGING_FEATURES)) {
130357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
130463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
130563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
130663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
130763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
130857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
130957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    removeTile = true;
131063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
131163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
131257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                if (removeTile && n < category.getTilesCount()) {
131357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    category.removeTile(n);
131457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
131563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                n--;
131663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
131763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
13182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        addExternalTiles(target);
13192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target) {
13222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Map<Pair<String, String>, DashboardTile> addedCache =
13232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                new ArrayMap<Pair<String, String>, DashboardTile>();
13242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        UserManager userManager = UserManager.get(this);
13252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (UserHandle user : userManager.getUserProfiles()) {
13262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            addExternalTiles(target, user, addedCache);
13272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target, UserHandle user,
13312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Map<Pair<String, String>, DashboardTile> addedCache) {
13322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        PackageManager pm = getPackageManager();
13332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Intent intent = new Intent(EXTRA_SETTINGS_ACTION);
13342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        List<ResolveInfo> results = pm.queryIntentActivitiesAsUser(intent,
13352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                PackageManager.GET_META_DATA, user.getIdentifier());
13362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (ResolveInfo resolved : results) {
13372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (!resolved.system) {
13382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                // Do not allow any app to add to settings, only system ones.
13392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            ActivityInfo activityInfo = resolved.activityInfo;
13422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Bundle metaData = activityInfo.metaData;
13432ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) {
13442ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action "
13452ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + EXTRA_SETTINGS_ACTION + " missing metadata " +
13462ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        (metaData == null ? "" : EXTRA_CATEGORY_KEY));
13472ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13482ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13492ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY);
13502ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardCategory category = getCategory(target, categoryKey);
13512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (category == null) {
13522ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown "
13532ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + "category key " + categoryKey);
13542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13552ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13562ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Pair<String, String> key = new Pair<String, String>(activityInfo.packageName,
13572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    activityInfo.name);
13582ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardTile tile = addedCache.get(key);
13592ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (tile == null) {
13602ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile = new DashboardTile();
13612ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile.intent = new Intent().setClassName(
13622ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        activityInfo.packageName, activityInfo.name);
13632ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile);
13642ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13652ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                if (category.externalIndex == -1) {
13662ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // If no location for external tiles has been specified for this category,
13672ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // then just put them at the end.
13682ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(tile);
13692ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                } else {
13702ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(category.externalIndex, tile);
13712ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                }
13722ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                addedCache.put(key, tile);
13732ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13742ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            tile.userHandle.add(user);
13752ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13762ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13772ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13782ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private DashboardCategory getCategory(List<DashboardCategory> target, String categoryKey) {
13792ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (DashboardCategory category : target) {
13802ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (categoryKey.equals(category.key)) {
13812ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                return category;
13822ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13832ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13842ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        return null;
138563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
138663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
138763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private boolean updateHomeSettingTiles(DashboardTile tile) {
138863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        // Once we decide to show Home settings, keep showing it forever
138963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
139063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
139163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            return true;
139263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
139363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
139463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
1395b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            mHomeActivitiesCount = getHomeActivitiesCount();
1396ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            if (mHomeActivitiesCount < 2) {
139763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // When there's only one available home app, omit this settings
139863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // category entirely at the top level UI.  If the user just
139963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // uninstalled the penultimate home app candidiate, we also
140063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // now tell them about why they aren't seeing 'Home' in the list.
140163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (sShowNoHomeNotice) {
140263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sShowNoHomeNotice = false;
140363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    NoHomeDialogFragment.show(this);
140463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
140563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                return false;
140663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            } else {
140763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Okay, we're allowing the Home settings category.  Tell it, when
140863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // invoked via this front door, that we'll need to be told about the
140963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // case when the user uninstalls all but one home app.
141063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (tile.fragmentArguments == null) {
141163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    tile.fragmentArguments = new Bundle();
141263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
141363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
141463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
141563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (Exception e) {
141663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Can't look up the home activity; bail on configuring the icon
141763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Log.w(LOG_TAG, "Problem looking up home activity!", e);
141863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
141963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
142063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
142163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        return true;
142263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
142363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static void requestHomeNotice() {
1451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        sShowNoHomeNotice = true;
1452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1454d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1455d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1456d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1457d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1462d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1463d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
14647e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1465a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1466a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1467a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1468d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1470d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1471d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1472d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1473d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1474263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1475d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1476d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1477d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1478bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1479263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1481d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1482263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1483d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1484d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1485d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1486bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1487d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1488263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1489263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1491d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1492263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1493d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1494bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1495bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1497d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1498bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1499bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1500bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
1501bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1502a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1503a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1504bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1505d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1506bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1507d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1508263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1509d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1510d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1512263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1513d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1514d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1515d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1516bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1517bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1518bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
151923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
152023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
152123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1522263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
15230698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15240698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
15250698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
15260698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
15270698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15280698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
15290698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
15300698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1531263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1532