1263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio/*
2263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project
3263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
4263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License");
5263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * you may not use this file except in compliance with the License.
6263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * You may obtain a copy of the License at
7263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
8263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *      http://www.apache.org/licenses/LICENSE-2.0
9263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
10263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software
11263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS,
12263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * See the License for the specific language governing permissions and
14263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * limitations under the License.
15263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */
16263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
17263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopackage com.android.settings;
18263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
19263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar;
20263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity;
21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment;
22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager;
23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction;
24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver;
25d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName;
26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context;
27263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent;
28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter;
29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences;
30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo;
31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager;
32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException;
33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo;
34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration;
35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray;
36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser;
37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter;
38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle;
39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler;
40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.INetworkManagementService;
41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message;
42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException;
43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager;
44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager;
49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen;
50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
5159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet;
53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
54263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue;
55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml;
56d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
57d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
6159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
63d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
64c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock
65263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils;
67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
696d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
71d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
73263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
74263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
7563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory;
76263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary;
7763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile;
78d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment;
79d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.Memory;
81263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.UsbSettings;
82c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings;
83263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary;
84802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.NotificationAppList;
85dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglioimport com.android.settings.notification.OtherSoundSettings;
86e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglioimport com.android.settings.quicklaunch.QuickLaunchSettings;
877a6bfd132cac4dcff72e3adcdd68a7ef777cee12Fabrice Di Meglioimport com.android.settings.search.DynamicIndexableContentMonitor;
88fa7dc240e978b1b77bb5c80a78cd1f8c77648301Fabrice Di Meglioimport com.android.settings.search.Index;
89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings;
90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings;
92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList;
93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings;
94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam;
95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings;
96802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings;
97c9afadb04b00598f5988101681089290cf14f79cJohn Spurlockimport com.android.settings.notification.ConditionProviderSettings;
984a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings;
994a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings;
1004a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation;
1014a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings;
102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
1043815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
106263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
107b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackbornimport com.android.settings.voice.VoiceInputSettings;
108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings;
109263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings;
11041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar;
111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings;
1127837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings;
113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings;
114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings;
115c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock
116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser;
117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException;
118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException;
120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList;
121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List;
1220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set;
123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
124e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglioimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
125d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity
127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        implements PreferenceManager.OnPreferenceTreeClickListener,
128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        PreferenceFragment.OnPreferenceStartFragmentCallback,
129cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
130d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
131cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        MenuItem.OnActionExpandListener {
132263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String LOG_TAG = "Settings";
134263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Constants for state save/restore
136769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
137d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
138d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
139b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
1403d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
141ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity, the invoking Intent can contain this extra
145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * string to specify which fragment should be initially displayed.
146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * will call isValidFragment() to confirm that the fragment class name is valid for this
148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * activity.
149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * this extra can also be specified to supply a Bundle of arguments to pass
155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * to that fragment when it is instantiated during the initial creation
156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * of the activity.
157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
161c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
162c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     */
163c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
164c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
1656f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio    public static final String BACK_STACK_PREFS = ":settings:prefs";
1666f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio
167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // extras that allow any preference activity to be launched as part of a wizard
168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // show Back and Next buttons? takes boolean parameter
170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Back will then return RESULT_CANCELED and Next RESULT_OK
171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // add a Skip button?
174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // specify custom text for the Back or Next buttons, or cause a button to not appear
177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // at all by setting it to null
178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
183a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio     * those extra can also be specify to supply the title or title res id to be shown for
184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * that fragment.
185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
186d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
18761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
18861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_title_resid";
18961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
19061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_shortcut";
19161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
19261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
19361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_subsetting";
194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String META_DATA_KEY_FRAGMENT_CLASS =
196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        "com.android.settings.FRAGMENT_CLASS";
197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
200d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio    private static final String EMPTY_QUERY = "";
201d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static boolean sShowNoHomeNotice = false;
203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String mFragmentClass;
205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
2068eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private CharSequence mInitialTitle;
207a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private int mInitialTitleResId;
2088eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Show only these settings for restricted users
210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private int[] SETTINGS_FOR_RESTRICTED = {
211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_section,
212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wifi_settings,
213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.bluetooth_settings,
214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.data_usage_settings,
2153815561997eced7fd773062ce32eaa50bece072cPauloftheWest            R.id.sim_settings,
216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_settings,
217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.device_section,
2184e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock            R.id.notification_settings,
219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.display_settings,
220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.storage_settings,
221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.application_settings,
222263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.battery_settings,
223263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.personal_section,
224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.location_settings,
225263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.security_settings,
226263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.language_settings,
227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.user_settings,
228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.account_settings,
229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.system_section,
230263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.date_time_settings,
231263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.about_settings,
232263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.accessibility_settings,
233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.print_settings,
234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.nfc_payment_settings,
2352858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.home_settings,
2362858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.dashboard
237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String[] ENTRY_FRAGMENTS = {
240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WirelessSettings.class.getName(),
241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiSettings.class.getName(),
242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AdvancedWifiSettings.class.getName(),
2437837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest            SavedAccessPointsWifiSettings.class.getName(),
244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            BluetoothSettings.class.getName(),
2453815561997eced7fd773062ce32eaa50bece072cPauloftheWest            SimSettings.class.getName(),
246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TetherSettings.class.getName(),
247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiP2pSettings.class.getName(),
248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            VpnSettings.class.getName(),
249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DateTimeSettings.class.getName(),
250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocalePicker.class.getName(),
251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            InputMethodAndLanguageSettings.class.getName(),
252b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn            VoiceInputSettings.class.getName(),
253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
2563033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.class.getName(),
260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ProcessStatsUi.class.getName(),
261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationStation.class.getName(),
262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocationSettings.class.getName(),
263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SecuritySettings.class.getName(),
264b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn            UsageAccessSettings.class.getName(),
265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrivacySettings.class.getName(),
266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceAdminSettings.class.getName(),
267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccessibilitySettings.class.getName(),
268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CaptionPropertiesFragment.class.getName(),
269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TextToSpeechSettings.class.getName(),
271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Memory.class.getName(),
272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DevelopmentSettings.class.getName(),
273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UsbSettings.class.getName(),
274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
2786d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
284c9afadb04b00598f5988101681089290cf14f79cJohn Spurlock            ConditionProviderSettings.class.getName(),
285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
290d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
291d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            NotificationSettings.class.getName(),
292d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
293d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
294c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
295c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
296802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlock            NotificationAppList.class.getName(),
297dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
298e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
29961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            QuickLaunchSettings.class.getName(),
30061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ApnSettings.class.getName()
301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3035a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3045a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3055a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3065a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3075a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
321b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    invalidateCategories(true);
322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
327990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
328990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
329853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
330d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
33141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
33241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
33341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
3343d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
335b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
3363d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
337d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
33835062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
3390d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
34035062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
34159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
34259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
343d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
344d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
345d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
346d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
347d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
348d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
349769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
350769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
351263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
352b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
353769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final int MSG_BUILD_CATEGORIES = 1;
354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private Handler mHandler = new Handler() {
355263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void handleMessage(Message msg) {
357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            switch (msg.what) {
358769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                case MSG_BUILD_CATEGORIES: {
359b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
360b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    if (forceRefresh) {
36142c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                        buildDashboardCategories(mCategories);
36242c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                    }
363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                } break;
364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
368d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
369ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int mHomeActivitiesCount = 1;
370d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
3710698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
3720698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
37341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
37441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
37541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
37641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
377b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
378b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio        if (forceRefresh || mCategories.size() == 0) {
379769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            buildDashboardCategories(mCategories);
380769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        }
381769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        return mCategories;
382769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    }
383769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio
384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
386263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Override the fragment title for Wallpaper settings
387263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        int titleRes = pref.getTitleRes();
388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            titleRes = R.string.wallpaper_settings_fragment_title;
390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                && UserHandle.myUserId() != UserHandle.USER_OWNER) {
392263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (UserManager.get(this).isLinkedUser()) {
393263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.profile_info_settings_title;
394263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
395263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.user_info_settings_title;
396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
399263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
400263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
401263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
403263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
406263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
408b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private void invalidateCategories(boolean forceRefresh) {
409769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
410b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            Message msg = new Message();
411b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.what = MSG_BUILD_CATEGORIES;
412b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
414263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
417263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
4196f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
423d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onStart() {
424d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        super.onStart();
425d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
426d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mNeedToRevertToInitialFragment) {
427d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            revertToInitialFragment();
428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
432d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4333d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4343d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4353d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4363d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
437d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
438d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
439d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
440d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
441d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
442d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4439593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
4449593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
445d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
44623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
44723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
44823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
44923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
4508c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
4518c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
4528c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
4538c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
4549593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
455d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
456d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
457d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
462d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
463d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
464d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
465d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4660d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
4670d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
4680d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
4690d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
4700d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4715b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
4725b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
4735a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
4745a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
4755a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
4765a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
4775a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
4785a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
4795a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
4805b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
4815b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
482d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
483d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
4840d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
4850d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4860d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
4870d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
4880d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
4890d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
4900d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
4910d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
492263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
493263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
494263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
495263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
497da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
4980d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
4990d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5005b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
5010d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
502da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
503e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
5045a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
505da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
5065a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        mIsShowingDashboard = className.equals(Settings.class.getName());
5075a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
50861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
50961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
51061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
51161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        final boolean isSubSettings = className.equals(SubSettings.class.getName()) ||
51261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
51361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
51461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
51561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
516712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
517712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
518712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
519712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
520712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
521712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
522da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
523da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
524d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
525d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
526263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
527d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        mContent = (ViewGroup) findViewById(R.id.main_content);
52859a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
529263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
530263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
53135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
532dba577f8f017baac0086c185579340db1c9281d9Fabrice Di Meglio            Index.getInstance(getApplicationContext()).update();
5335cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5345cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
535d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5361800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5371800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
538d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
539d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
540263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
5410d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
5425529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
543769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
544769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
545769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
5465f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
547769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
548b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
549263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
550b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
551b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
5523d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
553ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
554ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio                    1 /* one home activity by default */);
555263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
55635062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
5570d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // Search is shown we are launched thru a Settings "shortcut". UP will be shown
5580d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // only if it is a sub settings
5590d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
5600d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
5613d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio                    mDisplaySearch = false;
5625a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
5635a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
5645a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplaySearch = true;
56561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
56661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
56761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplaySearch = false;
568d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                }
5690d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                setTitleFromIntent(intent);
570c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
5710d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
572a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                switchToFragment(initialFragmentName, initialArguments, true, false,
573a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
57410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            } else {
5755a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // No UP affordance if we are displaying the main Dashboard
576b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio                mDisplayHomeAsUpEnabled = false;
5775a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // Show Search affordance
5785a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                mDisplaySearch = true;
579a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                mInitialTitleResId = R.string.dashboard_title;
58042c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                switchToFragment(DashboardSummary.class.getName(), null, false, false,
581a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
584263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
585d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mActionBar = getActionBar();
586d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        if (mActionBar != null) {
587d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
588d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
589d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        }
59041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
59141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
592263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // see if we should show Back/Next buttons
593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
595d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio            View buttonBar = findViewById(R.id.button_bar);
596263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (buttonBar != null) {
597263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                buttonBar.setVisibility(View.VISIBLE);
598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
599d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button backButton = (Button)findViewById(R.id.back_button);
600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                backButton.setOnClickListener(new OnClickListener() {
601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6020698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_CANCELED, getResultIntentData());
603263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
605263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
606d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button skipButton = (Button)findViewById(R.id.skip_button);
607263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                skipButton.setOnClickListener(new OnClickListener() {
608263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6090698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
610263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
611263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
612263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
613d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                mNextButton = (Button)findViewById(R.id.next_button);
614263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mNextButton.setOnClickListener(new OnClickListener() {
615263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6160698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
617263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
618263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
619263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
620263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
621263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                // set our various button parameters
622263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
623263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
624263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
625263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setVisibility(View.GONE);
626263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
627263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
628263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setText(buttonText);
629263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
630263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
631263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
632263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
633263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
634263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setVisibility(View.GONE);
635263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
636263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
637263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setText(buttonText);
638263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
639263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
641263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    skipButton.setVisibility(View.VISIBLE);
642263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
643263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
645ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
646ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        mHomeActivitiesCount = getHomeActivitiesCount();
647ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    }
648ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
649ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int getHomeActivitiesCount() {
650ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
651ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        getPackageManager().getHomeActivities(homeApps);
652ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        return homeApps.size();
653c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    }
654c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio
655a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private void setTitleFromIntent(Intent intent) {
656a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
657a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (initialTitleResId > 0) {
658a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = null;
659a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = initialTitleResId;
660a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitleResId);
661a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else {
662a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = -1;
663a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
664a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
665a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitle);
666a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        }
667a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    }
668a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio
669c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    @Override
670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onBackStackChanged() {
671d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        setTitleFromBackStack();
6728eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    }
6738eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
674b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio    private int setTitleFromBackStack() {
6758eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int count = getFragmentManager().getBackStackEntryCount();
676b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
6778eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (count == 0) {
678a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (mInitialTitleResId > 0) {
679a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitleResId);
680a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
681a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitle);
682a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
683b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio            return 0;
684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
685b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
6868eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
6878eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        setTitleFromBackStackEntry(bse);
688b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
689b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio        return count;
690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
6928eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
6935529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        final CharSequence title;
6948eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int titleRes = bse.getBreadCrumbTitleRes();
6958eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (titleRes > 0) {
6968eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = getText(titleRes);
6975529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        } else {
6988eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = bse.getBreadCrumbTitle();
6998eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        }
7008eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (title != null) {
7018eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            setTitle(title);
7025529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        }
7035529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio    }
7045529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
705263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
706263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected void onSaveInstanceState(Bundle outState) {
707263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onSaveInstanceState(outState);
708263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
709769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (mCategories.size() > 0) {
710769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
711263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
712d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
713b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
7143d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
7153d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7163d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (mDisplaySearch) {
7173d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // The option menus are created if the ActionBar is visible and they are also created
7183d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // asynchronously. If you launch Settings with an Intent action like
7193d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
7203d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
7213d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // menu item and search view are null.
7223d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
7233d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
7243d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7253d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
7263d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
7273d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
728ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
729ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
731263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
732263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
733263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onResume() {
734263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onResume();
735263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
736ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final int newHomeActivityCount = getHomeActivitiesCount();
737ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        if (newHomeActivityCount != mHomeActivitiesCount) {
738ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = newHomeActivityCount;
739b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            invalidateCategories(true);
740ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        }
741ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
742263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
743263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            @Override
744263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
745b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                invalidateCategories(true);
746263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
747263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        };
748263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
749263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mDevelopmentPreferencesListener);
750263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
751263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
752853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
753990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.register(this);
754a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio
7553d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
756a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            onQueryTextSubmit(mSearchQuery);
757a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
758263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
759263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
760263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
761263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onPause() {
762263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onPause();
763263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
764263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        unregisterReceiver(mBatteryInfoReceiver);
765990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.unregister();
766263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
767263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
768263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
769263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onDestroy() {
770263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onDestroy();
771680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio
772680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
773680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio                mDevelopmentPreferencesListener);
774680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferencesListener = null;
775263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
776263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
777263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected boolean isValidFragment(String fragmentName) {
778263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Almost all fragments are wrapped in this,
779263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // except for a few that have their own activities.
780263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
781263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
782263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
783263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
784263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
785263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
786263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
787263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Intent getIntent() {
788263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        Intent superIntent = super.getIntent();
789263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String startingFragment = getStartingFragmentClass(superIntent);
790263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // This is called from super.onCreate, isMultiPane() is not yet reliable
791263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Do not use onIsHidingHeaders either, which relies itself on this method
792263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (startingFragment != null) {
793263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Intent modIntent = new Intent(superIntent);
794263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
795263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Bundle args = superIntent.getExtras();
796263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (args != null) {
797263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle(args);
798263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
799263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle();
800263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
801263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            args.putParcelable("intent", superIntent);
802ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy            modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
803263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            return modIntent;
804263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
805263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return superIntent;
806263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
807263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
808263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
809263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Checks if the component name in the intent is different from the Settings class and
810263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * returns the class name to load as a fragment.
811263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
812263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String getStartingFragmentClass(Intent intent) {
813263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (mFragmentClass != null) return mFragmentClass;
814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String intentClass = intent.getComponent().getClassName();
816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intentClass.equals(getClass().getName())) return null;
817263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
818263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if ("com.android.settings.ManageApplications".equals(intentClass)
819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.RunningServices".equals(intentClass)
820263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.applications.StorageUse".equals(intentClass)) {
821263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // Old names of manage apps.
822263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            intentClass = com.android.settings.applications.ManageApplications.class.getName();
823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
824263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
825263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return intentClass;
826263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
827263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
828263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
82910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment containing a preference panel.  If the preferences
83010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * are being displayed in multi-pane mode, the given fragment class will
83110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * be instantiated and placed in the appropriate pane.  If running in
83210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * single-pane mode, a new activity will be launched in which to show the
83310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
83410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
83510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragmentClass Full name of the class implementing the fragment.
83610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param args Any desired arguments to supply to the fragment.
83710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleRes Optional resource identifier of the title of this
83810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
83910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleText Optional text of the title of this fragment.
84010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultTo Optional fragment that result data should be sent to.
84110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * If non-null, resultTo.onActivityResult() will be called when this
84210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * preference panel is done.  The launched panel must use
84310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
84410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultRequestCode If resultTo is non-null, this is the caller's
84558146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio     * request code to be received with the result.
84610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
84710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
848d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
849a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        String title = null;
850a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleRes < 0) {
851a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (titleText != null) {
852a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = titleText.toString();
853a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
854a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                // There not much we can do in that case
855a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = "";
856a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
857911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio        }
858a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
8590d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                titleRes, title, mIsShortcut);
86010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
86110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
86210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
8637a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * Start a new fragment in a new activity containing a preference panel for a given user. If the
8647a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * preferences are being displayed in multi-pane mode, the given fragment class will be
8657a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
8667a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * activity will be launched in which to show the fragment.
8677a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     *
8687a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param fragmentClass Full name of the class implementing the fragment.
8697a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param args Any desired arguments to supply to the fragment.
8707a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleRes Optional resource identifier of the title of this fragment.
8717a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleText Optional text of the title of this fragment.
8727a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param userHandle The user for which the panel has to be started.
8737a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     */
8747a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
8757a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            CharSequence titleText, UserHandle userHandle) {
8767a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        String title = null;
8777a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        if (titleRes < 0) {
8787a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            if (titleText != null) {
8797a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban                title = titleText.toString();
8807a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            } else {
8817a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban                // There not much we can do in that case
8827a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban                title = "";
8837a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            }
8847a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        }
8857a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        Utils.startWithFragmentAsUser(this, fragmentClass, args,
8867a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban                titleRes, title, mIsShortcut, userHandle);
8877a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    }
8887a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban
8897a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    /**
890263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Called by a preference panel fragment to finish itself.
891263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     *
892263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param caller The fragment that is asking to be finished.
893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultCode Optional result code to send back to the original
894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultData Optional result data to send back to the original
896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        setResult(resultCode, resultData);
90058146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio        finish();
901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
903263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
90410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment.
90510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
90610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragment The fragment to start
90710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param push If true, the current fragment will be pushed onto the back stack.  If false,
90810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * the current fragment will be replaced.
90910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
91010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferenceFragment(Fragment fragment, boolean push) {
91110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
912d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, fragment);
91310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        if (push) {
91410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
91510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.addToBackStack(BACK_STACK_PREFS);
91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        } else {
91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
91810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        }
91910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        transaction.commitAllowingStateLoss();
92010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
92210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
923d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     * Switch to a specific Fragment with taking care of validation, Title and BackStack
924d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     */
925d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
926a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
927d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (validate && !isValidFragment(fragmentName)) {
928d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            throw new IllegalArgumentException("Invalid fragment for this activity: "
929d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                    + fragmentName);
930d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
931d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        Fragment f = Fragment.instantiate(this, fragmentName, args);
932d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
933d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, f);
934d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (withTransition) {
93559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio            TransitionManager.beginDelayedTransition(mContent);
936d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
937d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (addToBackStack) {
938d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
939d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
940a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleResId > 0) {
941a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            transaction.setBreadCrumbTitle(titleResId);
942a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else if (title != null) {
943d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.setBreadCrumbTitle(title);
944d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
945d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        transaction.commitAllowingStateLoss();
94659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio        getFragmentManager().executePendingTransactions();
947d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return f;
948d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
949d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
95063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
951769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio     * Called when the activity needs its list of categories/tiles built.
95263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
95363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param categories The list in which to place the tiles categories.
95463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
955769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private void buildDashboardCategories(List<DashboardCategory> categories) {
9565f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio        categories.clear();
95763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        loadCategoriesFromResource(R.xml.dashboard_categories, categories);
95863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        updateTilesList(categories);
95963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
96063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
96163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
96263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * Parse the given XML file as a categories description, adding each
96363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * parsed categories and tiles into the target list.
96463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
96563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param resid The XML resource to load and parse.
96663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param target The list in which the parsed categories and tiles should be placed.
96763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
96863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
96963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        XmlResourceParser parser = null;
97063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
97163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            parser = getResources().getXml(resid);
97263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            AttributeSet attrs = Xml.asAttributeSet(parser);
97363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
97463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int type;
97563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
97663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && type != XmlPullParser.START_TAG) {
97763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Parse next until start tag is found
97863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
97963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
98063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            String nodeName = parser.getName();
98163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (!"dashboard-categories".equals(nodeName)) {
98263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                throw new RuntimeException(
98363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        "XML document must start with <preference-categories> tag; found"
98463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                + nodeName + " at " + parser.getPositionDescription());
98563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
98663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
98763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Bundle curBundle = null;
98863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
98963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            final int outerDepth = parser.getDepth();
99063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
99163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
99263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
99363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    continue;
99463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
99563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
99663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                nodeName = parser.getName();
99763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if ("dashboard-category".equals(nodeName)) {
99863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    DashboardCategory category = new DashboardCategory();
99963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
100063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedArray sa = obtainStyledAttributes(
100163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            attrs, com.android.internal.R.styleable.PreferenceHeader);
100263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    category.id = sa.getResourceId(
100363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_id,
100463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            (int)DashboardCategory.CAT_ID_UNDEFINED);
100563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
100663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedValue tv = sa.peekValue(
100763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_title);
100863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
100963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (tv.resourceId != 0) {
101063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.titleRes = tv.resourceId;
101163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
101263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.title = tv.string;
101363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
101463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
101563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sa.recycle();
101663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
101763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final int innerDepth = parser.getDepth();
101863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
101963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
102063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
102163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            continue;
102263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
102363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
102463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        String innerNodeName = parser.getName();
102563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (innerNodeName.equals("dashboard-tile")) {
102663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            DashboardTile tile = new DashboardTile();
102763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
102863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa = obtainStyledAttributes(
102963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    attrs, com.android.internal.R.styleable.PreferenceHeader);
103063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.id = sa.getResourceId(
103163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_id,
1032e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio                                    (int)TILE_ID_UNDEFINED);
103363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
103463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_title);
103563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
103663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
103763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.titleRes = tv.resourceId;
103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
103963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.title = tv.string;
104063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_summary);
104463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summaryRes = tv.resourceId;
104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
104863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summary = tv.string;
104963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.iconRes = sa.getResourceId(
105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_icon, 0);
105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.fragment = sa.getString(
105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_fragment);
105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa.recycle();
105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle == null) {
105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = new Bundle();
105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            final int innerDepth2 = parser.getDepth();
106263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
106563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    continue;
106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                String innerNodeName2 = parser.getName();
106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (innerNodeName2.equals("extra")) {
107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    getResources().parseBundleExtra("extra", attrs, curBundle);
107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else if (innerNodeName2.equals("intent")) {
107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.intent = Intent.parseIntent(getResources(), parser, attrs);
107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle.size() > 0) {
108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                tile.fragmentArguments = curBundle;
108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = null;
108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
10863815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            // Show the SIM Cards setting if there are more than 2 SIMs installed.
108722a2a49b445b8721c8194eedf3608ea81c62ccefFabrice Di Meglio                            if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
10883815561997eced7fd773062ce32eaa50bece072cPauloftheWest                                category.addTile(tile);
10893815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            }
109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
109263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            XmlUtils.skipCurrentTag(parser);
109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
109463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    target.add(category);
109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else {
109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    XmlUtils.skipCurrentTag(parser);
109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (XmlPullParserException e) {
110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (IOException e) {
110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } finally {
110763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (parser != null) parser.close();
110863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
110963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
111063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
111163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void updateTilesList(List<DashboardCategory> target) {
111263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
111363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DevelopmentSettings.PREF_SHOW,
111463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                android.os.Build.TYPE.equals("eng"));
111563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
111663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
111763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final int size = target.size();
111963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        for (int i = 0; i < size; i++) {
112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            DashboardCategory category = target.get(i);
112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Ids are integers, so downcasting is ok
112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int id = (int) category.id;
112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int n = category.getTilesCount() - 1;
112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while (n >= 0) {
112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DashboardTile tile = category.getTile(n);
112957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                boolean removeTile = false;
113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                id = (int) tile.id;
113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
113257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
113357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
113457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    }
113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.wifi_settings) {
113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove WiFi Settings if WiFi service is not available.
113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
113857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.bluetooth_settings) {
114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove Bluetooth Settings if Bluetooth service is not available.
114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
114357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.data_usage_settings) {
114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove data usage when kernel module not enabled
114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final INetworkManagementService netManager = INetworkManagementService.Stub
114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    try {
115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (!netManager.isBandwidthControlEnabled()) {
115157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } catch (RemoteException e) {
115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // ignored
115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.battery_settings) {
115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove battery settings when battery is not available. (e.g. TV)
115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!mBatteryPresent) {
116057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.home_settings) {
116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!updateHomeSettingTiles(tile)) {
116457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.user_settings) {
11674093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                    boolean hasMultipleUsers =
11684093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            ((UserManager) getSystemService(Context.USER_SERVICE))
11694093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    .getUserCount() > 1;
117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!UserHandle.MU_ENABLED
11714093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            || (!UserManager.supportsMultipleUsers()
11724093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    && !hasMultipleUsers)
117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            || Utils.isMonkeyRunning()) {
117457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
117663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.nfc_payment_settings) {
117763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
117857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } else {
118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // Only show if NFC is on and we have the HCE feature
118163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1182b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                        if (adapter == null || !adapter.isEnabled() ||
1183b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                !getPackageManager().hasSystemFeature(
1184b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                        PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
118557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
118663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
118763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
1188488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                } else if (id == R.id.print_settings) {
1189488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1190488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                            PackageManager.FEATURE_PRINTING);
1191488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    if (!hasPrintingSupport) {
119257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
1193488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    }
119463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.development_settings) {
11956c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                    if (!showDev || um.hasUserRestriction(
11966c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                            UserManager.DISALLOW_DEBUGGING_FEATURES)) {
119757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
119863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
119963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
120063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
120257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
120357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    removeTile = true;
120463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
120563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                if (removeTile && n < category.getTilesCount()) {
120757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    category.removeTile(n);
120857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
120963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                n--;
121063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
121163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
121263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
121363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private boolean updateHomeSettingTiles(DashboardTile tile) {
121563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        // Once we decide to show Home settings, keep showing it forever
121663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
121763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
121863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            return true;
121963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
122063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
1222b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            mHomeActivitiesCount = getHomeActivitiesCount();
1223ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            if (mHomeActivitiesCount < 2) {
122463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // When there's only one available home app, omit this settings
122563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // category entirely at the top level UI.  If the user just
122663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // uninstalled the penultimate home app candidiate, we also
122763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // now tell them about why they aren't seeing 'Home' in the list.
122863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (sShowNoHomeNotice) {
122963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sShowNoHomeNotice = false;
123063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    NoHomeDialogFragment.show(this);
123163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
123263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                return false;
123363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            } else {
123463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Okay, we're allowing the Home settings category.  Tell it, when
123563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // invoked via this front door, that we'll need to be told about the
123663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // case when the user uninstalls all but one home app.
123763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (tile.fragmentArguments == null) {
123863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    tile.fragmentArguments = new Bundle();
123963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
124063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
124163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
124263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (Exception e) {
124363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Can't look up the home activity; bail on configuring the icon
124463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Log.w(LOG_TAG, "Problem looking up home activity!", e);
124563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
124663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
124763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
124863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        return true;
124963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
125063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static void requestHomeNotice() {
1278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        sShowNoHomeNotice = true;
1279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1281d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1282d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1283d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1284d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1285d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1286d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1288d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1289d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1290d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
12917e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1292a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1293a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1294a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1295d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1297d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1298d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1299d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1300d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1302d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1303d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1304d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1305bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1307d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1308d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1310d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1311d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1312d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1313bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1314d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1317d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1318d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1320d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1321bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1322bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1324d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1325bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1326bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1327bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
1328bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1329a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1330a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1331bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1332d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1333bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1334d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1336d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1337d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1338d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1339263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1340d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1341d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1342d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1343bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1344bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1345bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
134623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
134723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
134823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1349263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
13500698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
13510698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
13520698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
13530698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
13540698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
13550698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
13560698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
13570698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1359