SettingsActivity.java revision b45e27bc0f52d64a71aecba661770b30f6299301
1263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio/*
2263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project
3263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
4263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License");
5263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * you may not use this file except in compliance with the License.
6263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * You may obtain a copy of the License at
7263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
8263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *      http://www.apache.org/licenses/LICENSE-2.0
9263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio *
10263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software
11263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS,
12263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * See the License for the specific language governing permissions and
14263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * limitations under the License.
15263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */
16263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
17263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopackage com.android.settings;
18263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar;
22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity;
23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment;
24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager;
25263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction;
26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver;
27d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName;
28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context;
29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent;
30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter;
31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences;
32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo;
33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager;
34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException;
35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo;
36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration;
37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray;
38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser;
39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter;
40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle;
41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler;
42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message;
43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle;
44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager;
45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference;
46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment;
47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager;
48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen;
49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils;
5059a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager;
512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.ArrayMap;
52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet;
53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log;
542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.Pair;
55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue;
56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml;
57d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu;
58d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater;
59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem;
60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View;
61263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener;
6259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup;
63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button;
64d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView;
65c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock
668a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger;
67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils;
68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils;
69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings;
70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment;
716d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings;
72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings;
73d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails;
74263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications;
75263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi;
76d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monkimport com.android.settings.applications.UsageAccessDetails;
77263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings;
7863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory;
79263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary;
8063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile;
81d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment;
82d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary;
83a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeForget;
84e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkeyimport com.android.settings.deviceinfo.PrivateVolumeSettings;
8542833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.PublicVolumeSettings;
8642833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkeyimport com.android.settings.deviceinfo.StorageSettings;
87c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings;
881eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monkimport com.android.settings.fuelgauge.PowerUsageDetail;
89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary;
90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings;
91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings;
93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList;
94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings;
95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam;
96263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings;
97802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings;
984a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings;
994a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings;
1004a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation;
1012ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.notification.OtherSoundSettings;
10208531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlockimport com.android.settings.notification.ZenAccessSettings;
103f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlockimport com.android.settings.notification.ZenModeEventRuleSettings;
104c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceafJohn Spurlockimport com.android.settings.notification.ZenModeExternalRuleSettings;
105c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlockimport com.android.settings.notification.ZenModePrioritySettings;
1064a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings;
10745fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlockimport com.android.settings.notification.ZenModeScheduleRuleSettings;
108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment;
109263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment;
1102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor;
1112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index;
1123815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings;
113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings;
114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings;
115b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackbornimport com.android.settings.voice.VoiceInputSettings;
116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings;
117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings;
11841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar;
119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings;
1207837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings;
121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings;
122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings;
1232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser;
125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException;
126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException;
128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList;
129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List;
1302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport java.util.Map;
1310d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set;
132263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity
134263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        implements PreferenceManager.OnPreferenceTreeClickListener,
135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        PreferenceFragment.OnPreferenceStartFragmentCallback,
136cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
137d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
138cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina        MenuItem.OnActionExpandListener {
139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String LOG_TAG = "Settings";
141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Constants for state save/restore
143769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
144d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
145d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
146b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
1473d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
148ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity, the invoking Intent can contain this extra
152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * string to specify which fragment should be initially displayed.
153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * will call isValidFragment() to confirm that the fragment class name is valid for this
155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * activity.
156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * this extra can also be specified to supply a Bundle of arguments to pass
162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * to that fragment when it is instantiated during the initial creation
163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * of the activity.
164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
168c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
169c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio     */
170c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio    public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
171c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
1726f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio    public static final String BACK_STACK_PREFS = ":settings:prefs";
1736f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio
174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // extras that allow any preference activity to be launched as part of a wizard
175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // show Back and Next buttons? takes boolean parameter
177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Back will then return RESULT_CANCELED and Next RESULT_OK
178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // add a Skip button?
181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // specify custom text for the Back or Next buttons, or cause a button to not appear
184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // at all by setting it to null
185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
190a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio     * those extra can also be specify to supply the title or title res id to be shown for
191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * that fragment.
192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
193d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
19462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    /**
19562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     * The package name used to resolve the title resource id.
19662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina     */
19762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
19862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            ":settings:show_fragment_title_res_package_name";
19961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
20061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_title_resid";
20161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
20261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_shortcut";
20361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
20461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
20561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio            ":settings:show_fragment_as_subsetting";
206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String META_DATA_KEY_FRAGMENT_CLASS =
208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        "com.android.settings.FRAGMENT_CLASS";
209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
212d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio    private static final String EMPTY_QUERY = "";
213d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
2142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    /**
2152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * Settings will search for system activities of this action and add them as a top level
2162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * settings tile using the following parameters.
2172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>A category must be specified in the meta-data for the activity named
2192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * {@link #EXTRA_CATEGORY_KEY}
2202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>The title may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_TITLE}
2222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * otherwise the label for the activity will be used.
2232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>The icon may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_ICON}
2252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * otherwise the icon for the activity will be used.
2262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     *
2272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <p>A summary my be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_SUMMARY}
2282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     */
2292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private static final String EXTRA_SETTINGS_ACTION =
2302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            "com.android.settings.action.EXTRA_SETTINGS";
2312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
2322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    /**
2332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * The key used to get the category from metadata of activities of action
2342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * {@link #EXTRA_SETTINGS_ACTION}
2352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * The value must be one of:
2362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.wireless</li>
2372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.device</li>
2382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.personal</li>
2392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     * <li>com.android.settings.category.system</li>
2402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk     */
2412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private static final String EXTRA_CATEGORY_KEY = "com.android.settings.category";
2422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static boolean sShowNoHomeNotice = false;
244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String mFragmentClass;
246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
2478eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private CharSequence mInitialTitle;
248a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private int mInitialTitleResId;
2498eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // Show only these settings for restricted users
251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private int[] SETTINGS_FOR_RESTRICTED = {
252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_section,
253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wifi_settings,
254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.bluetooth_settings,
255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.data_usage_settings,
2563815561997eced7fd773062ce32eaa50bece072cPauloftheWest            R.id.sim_settings,
257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.wireless_settings,
258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.device_section,
2594e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock            R.id.notification_settings,
260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.display_settings,
261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.storage_settings,
262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.application_settings,
263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.battery_settings,
264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.personal_section,
265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.location_settings,
266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.security_settings,
267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.language_settings,
268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.user_settings,
269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.account_settings,
270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.system_section,
271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.date_time_settings,
272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.about_settings,
273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.accessibility_settings,
274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.print_settings,
275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            R.id.nfc_payment_settings,
2762858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.home_settings,
2772858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio            R.id.dashboard
278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private static final String[] ENTRY_FRAGMENTS = {
281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WirelessSettings.class.getName(),
282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiSettings.class.getName(),
283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AdvancedWifiSettings.class.getName(),
2847837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest            SavedAccessPointsWifiSettings.class.getName(),
285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            BluetoothSettings.class.getName(),
2863815561997eced7fd773062ce32eaa50bece072cPauloftheWest            SimSettings.class.getName(),
287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TetherSettings.class.getName(),
288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiP2pSettings.class.getName(),
289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            VpnSettings.class.getName(),
290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DateTimeSettings.class.getName(),
291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocalePicker.class.getName(),
292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            InputMethodAndLanguageSettings.class.getName(),
293b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn            VoiceInputSettings.class.getName(),
294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SpellCheckersSettings.class.getName(),
295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionaryList.class.getName(),
296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserDictionarySettings.class.getName(),
2973033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani            HomeSettings.class.getName(),
298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DisplaySettings.class.getName(),
299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceInfoSettings.class.getName(),
300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ManageApplications.class.getName(),
301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ProcessStatsUi.class.getName(),
302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationStation.class.getName(),
303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            LocationSettings.class.getName(),
304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            SecuritySettings.class.getName(),
305d8da51ccfecf16f2c06f788e6bcbc232d1f0cb32Jason Monk            UsageAccessDetails.class.getName(),
306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrivacySettings.class.getName(),
307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DeviceAdminSettings.class.getName(),
308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccessibilitySettings.class.getName(),
309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CaptionPropertiesFragment.class.getName(),
310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TextToSpeechSettings.class.getName(),
31242833b2ff4d7a26dd9a609d2fd4436d9a26f28b5Jeff Sharkey            StorageSettings.class.getName(),
313a16257dbd5599135320f4263a2cb438b7a469084Jeff Sharkey            PrivateVolumeForget.class.getName(),
314e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PrivateVolumeSettings.class.getName(),
315e77f0687dd424ccfdc2b1061221c6c8ba4d6ac8dJeff Sharkey            PublicVolumeSettings.class.getName(),
316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DevelopmentSettings.class.getName(),
317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AndroidBeam.class.getName(),
318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            WifiDisplaySettings.class.getName(),
319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PowerUsageSummary.class.getName(),
320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            AccountSyncSettings.class.getName(),
3216d839875b74f1570e8807005c586298beb677413Alexandra Gherghina            AccountSettings.class.getName(),
322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            CryptKeeperSettings.class.getName(),
323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DataUsageSummary.class.getName(),
324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            DreamSettings.class.getName(),
325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            UserSettings.class.getName(),
326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            NotificationAccessSettings.class.getName(),
32708531a81cb34dc45f0da4ca88e8530169831c7d2John Spurlock            ZenAccessSettings.class.getName(),
328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintSettingsFragment.class.getName(),
329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PrintJobSettingsFragment.class.getName(),
330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            TrustedCredentialsSettings.class.getName(),
331263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            PaymentSettings.class.getName(),
332263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            KeyboardLayoutPickerFragment.class.getName(),
333d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ZenModeSettings.class.getName(),
334d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            NotificationSettings.class.getName(),
335d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
336d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
337c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            InstalledAppDetails.class.getName(),
338c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock            BatterySaverSettings.class.getName(),
339dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio            AppNotificationSettings.class.getName(),
340e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio            OtherSoundSettings.class.getName(),
34133acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath            ApnSettings.class.getName(),
34245fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            WifiCallingSettings.class.getName(),
343c1df2aa9639a27fa6d759b21a760b6b63e38a1c2John Spurlock            ZenModePrioritySettings.class.getName(),
34445fa140b8c6846b4546fdeabebf989ae9102cebbJohn Spurlock            ZenModeScheduleRuleSettings.class.getName(),
345f57bad7d5b0f9044231fc52351ed27e14013f491John Spurlock            ZenModeEventRuleSettings.class.getName(),
346c96a5dcbfc3f37f71e8b3e8b962f9571b1e7ceafJohn Spurlock            ZenModeExternalRuleSettings.class.getName(),
3472583fc1e069d0a54df46258d360499492d7e86d2Jason Monk            ProcessStatsUi.class.getName(),
3481eb54eb2ff250eccdd700601011bd6457ddcbec1Jason Monk            PowerUsageDetail.class.getName(),
349263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
350263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
3515a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
3525a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
3535a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            "android.settings.APPLICATION_DETAILS_SETTINGS"
3545a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio    };
3555a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences mDevelopmentPreferences;
357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
359263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private boolean mBatteryPresent = true;
360263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void onReceive(Context context, Intent intent) {
363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            String action = intent.getAction();
364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                boolean batteryPresent = Utils.isBatteryPresent(intent);
366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (mBatteryPresent != batteryPresent) {
368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    mBatteryPresent = batteryPresent;
369b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    invalidateCategories(true);
370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
375990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav    private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
376990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav            new DynamicIndexableContentMonitor();
377853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
378d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private ActionBar mActionBar;
37941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private SwitchBar mSwitchBar;
38041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
38141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private Button mNextButton;
3823d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
383b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio    private boolean mDisplayHomeAsUpEnabled;
3843d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio    private boolean mDisplaySearch;
385d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
38635062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio    private boolean mIsShowingDashboard;
3870d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private boolean mIsShortcut;
38835062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio
38959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio    private ViewGroup mContent;
39059a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
391d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchView mSearchView;
392d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private MenuItem mSearchMenuItem;
393d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mSearchMenuItemExpanded = false;
394d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private SearchResultsSummary mSearchResultsFragment;
395d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private String mSearchQuery;
396d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
397769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    // Categories
398769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
399263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
400b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
401769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private static final int MSG_BUILD_CATEGORIES = 1;
402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private Handler mHandler = new Handler() {
403263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        @Override
404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        public void handleMessage(Message msg) {
405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            switch (msg.what) {
406769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                case MSG_BUILD_CATEGORIES: {
407b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
408b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                    if (forceRefresh) {
40942c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                        buildDashboardCategories(mCategories);
41042c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                    }
411263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                } break;
412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
414263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    };
415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
416d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private boolean mNeedToRevertToInitialFragment = false;
417ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int mHomeActivitiesCount = 1;
418d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4190698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    private Intent mResultIntentData;
4200698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
42141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar getSwitchBar() {
42241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitchBar;
42341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
42441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
425b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
426b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio        if (forceRefresh || mCategories.size() == 0) {
427769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            buildDashboardCategories(mCategories);
428769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        }
429769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        return mCategories;
430769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    }
431769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio
432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Override the fragment title for Wallpaper settings
435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        int titleRes = pref.getTitleRes();
436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            titleRes = R.string.wallpaper_settings_fragment_title;
438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                && UserHandle.myUserId() != UserHandle.USER_OWNER) {
440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (UserManager.get(this).isLinkedUser()) {
441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.profile_info_settings_title;
442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                titleRes = R.string.user_info_settings_title;
444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                null, 0);
448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return true;
449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
456b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio    private void invalidateCategories(boolean forceRefresh) {
457769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
458b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            Message msg = new Message();
459b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.what = MSG_BUILD_CATEGORIES;
460b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
464263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
465263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onConfigurationChanged(Configuration newConfig) {
466263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onConfigurationChanged(newConfig);
4676f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio        Index.getInstance(this).update();
468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
471d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onStart() {
472d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        super.onStart();
473d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
474d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mNeedToRevertToInitialFragment) {
475d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            revertToInitialFragment();
476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
477263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
478263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
479263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
480d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onCreateOptionsMenu(Menu menu) {
4813d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (!mDisplaySearch) {
4823d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            return false;
4833d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
4843d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
485d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        MenuInflater inflater = getMenuInflater();
486d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        inflater.inflate(R.menu.options_menu, menu);
487d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
488d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        // Cache the search query (can be overriden by the OnQueryTextListener)
489d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        final String query = mSearchQuery;
490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
4919593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem = menu.findItem(R.id.search);
4929593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchView = (SearchView) mSearchMenuItem.getActionView();
493d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
49423ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem == null || mSearchView == null) {
49523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            return false;
49623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
49723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio
4988c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        if (mSearchResultsFragment != null) {
4998c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio            mSearchResultsFragment.setSearchView(mSearchView);
5008c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio        }
5018c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio
5029593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio        mSearchMenuItem.setOnActionExpandListener(this);
503d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnQueryTextListener(this);
504d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setOnCloseListener(this);
505d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
506d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (mSearchMenuItemExpanded) {
507d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItem.expandActionView();
508d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
509d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchView.setQuery(query, true /* submit */);
510d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
511d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
512d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
513d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
5140d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    private static boolean isShortCutIntent(final Intent intent) {
5150d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        Set<String> categories = intent.getCategories();
5160d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
5170d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio    }
5180d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5195b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio    private static boolean isLikeShortCutIntent(final Intent intent) {
5205b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio        String action = intent.getAction();
5215a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        if (action == null) {
5225a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            return false;
5235a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5245a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
5255a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio            if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
5265a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        }
5275a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        return false;
5285b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio    }
5295b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio
530d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
531d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    protected void onCreate(Bundle savedState) {
5320d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        super.onCreate(savedState);
5330d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5340d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        // Should happen before any call to getIntent()
5350d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        getMetaData();
5360d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5370d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final Intent intent = getIntent();
5380d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
5390d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
540263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
541263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
542263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
543263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                Context.MODE_PRIVATE);
544263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
545da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        // Getting Intent properties can only be done after the super.onCreate(...)
5460d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio        final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
5470d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio
5485b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio        mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
5490d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
550da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
551e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio        final ComponentName cn = intent.getComponent();
5525a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        final String className = cn.getClassName();
553da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
5545a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio        mIsShowingDashboard = className.equals(Settings.class.getName());
5555a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio
55661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // This is a "Sub Settings" when:
55761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - this is a real SubSettings
55861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // - or :settings:show_fragment_as_subsetting is passed to the Intent
5594dfcb8208cdb49167ccf99aeaddf9e206eba87d1Jorim Jaggi        final boolean isSubSettings = this instanceof SubSettings ||
56061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
56161a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio
56261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
56361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio        if (isSubSettings) {
564712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            // Check also that we are not a Theme Dialog as we don't want to override them
565712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            final int themeResId = getThemeResId();
566712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            if (themeResId != R.style.Theme_DialogWhenLarge &&
567712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                    themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
568712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio                setTheme(R.style.Theme_SubSettings);
569712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio            }
570da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio        }
571da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio
572d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        setContentView(mIsShowingDashboard ?
573d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio                R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
575d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        mContent = (ViewGroup) findViewById(R.id.main_content);
57659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio
577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        getFragmentManager().addOnBackStackChangedListener(this);
578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
57935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio        if (mIsShowingDashboard) {
580dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            // Run the Index update only if we have some space
581dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            if (!Utils.isLowStorage(this)) {
582dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Index.getInstance(getApplicationContext()).update();
583dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            } else {
584dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio                Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
585dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio            }
5865cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio        }
5875cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio
588d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (savedState != null) {
5891800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // We are restarting from a previous saved state; used that to initialize, instead
5901800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio            // of starting fresh.
591d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
592d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
5940d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio            setTitleFromIntent(intent);
5955529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
596769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            ArrayList<DashboardCategory> categories =
597769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
598769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            if (categories != null) {
5995f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio                mCategories.clear();
600769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio                mCategories.addAll(categories);
601b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio                setTitleFromBackStack();
602263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
603b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio
604b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
6053d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
606ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
607ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio                    1 /* one home activity by default */);
608263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } else {
60935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio            if (!mIsShowingDashboard) {
6100d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // Search is shown we are launched thru a Settings "shortcut". UP will be shown
6110d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                // only if it is a sub settings
6120d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                if (mIsShortcut) {
6130d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                    mDisplayHomeAsUpEnabled = isSubSettings;
6143d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio                    mDisplaySearch = false;
6155a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                } else if (isSubSettings) {
6165a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplayHomeAsUpEnabled = true;
6175a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                    mDisplaySearch = true;
61861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                } else {
61961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplayHomeAsUpEnabled = false;
62061a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio                    mDisplaySearch = false;
621d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                }
6220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                setTitleFromIntent(intent);
623c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio
6240d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
625a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                switchToFragment(initialFragmentName, initialArguments, true, false,
626a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
62710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            } else {
6285a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // No UP affordance if we are displaying the main Dashboard
629b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio                mDisplayHomeAsUpEnabled = false;
6305a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                // Show Search affordance
6315a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio                mDisplaySearch = true;
632a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                mInitialTitleResId = R.string.dashboard_title;
63342c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio                switchToFragment(DashboardSummary.class.getName(), null, false, false,
634a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                        mInitialTitleResId, mInitialTitle, false);
635263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
636263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
637263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
638d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mActionBar = getActionBar();
639d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        if (mActionBar != null) {
640d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
641d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
642d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio        }
64341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
64441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
645263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // see if we should show Back/Next buttons
646263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
647263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
648d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio            View buttonBar = findViewById(R.id.button_bar);
649263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (buttonBar != null) {
650263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                buttonBar.setVisibility(View.VISIBLE);
651263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
652d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button backButton = (Button)findViewById(R.id.back_button);
653263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                backButton.setOnClickListener(new OnClickListener() {
654263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6550698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_CANCELED, getResultIntentData());
656263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
657263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
658263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
659d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                Button skipButton = (Button)findViewById(R.id.skip_button);
660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                skipButton.setOnClickListener(new OnClickListener() {
661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6620698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
666d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio                mNextButton = (Button)findViewById(R.id.next_button);
667263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mNextButton.setOnClickListener(new OnClickListener() {
668263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    public void onClick(View v) {
6690698a216311acd9ab52224602d1a75c08bf89f04Jim Miller                        setResult(RESULT_OK, getResultIntentData());
670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        finish();
671263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                });
673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
674263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                // set our various button parameters
675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
676263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setVisibility(View.GONE);
679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        mNextButton.setText(buttonText);
682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    if (TextUtils.isEmpty(buttonText)) {
687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setVisibility(View.GONE);
688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    else {
690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                        backButton.setText(buttonText);
691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    }
692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    skipButton.setVisibility(View.VISIBLE);
695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                }
696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
698ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
699ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        mHomeActivitiesCount = getHomeActivitiesCount();
700ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    }
701ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
702ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio    private int getHomeActivitiesCount() {
703ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
704ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        getPackageManager().getHomeActivities(homeApps);
705ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        return homeApps.size();
706c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    }
707c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio
708a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    private void setTitleFromIntent(Intent intent) {
709a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
710a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (initialTitleResId > 0) {
711a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = null;
712a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = initialTitleResId;
71362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina
71462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            final String initialTitleResPackageName = intent.getStringExtra(
71562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
71662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            if (initialTitleResPackageName != null) {
71762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                try {
71862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Context authContext = createPackageContextAsUser(initialTitleResPackageName,
71962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                            0 /* flags */, new UserHandle(UserHandle.myUserId()));
72062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
72162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    setTitle(mInitialTitle);
72262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    mInitialTitleResId = -1;
72362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    return;
72462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                } catch (NameNotFoundException e) {
72562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                    Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
72662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                }
72762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            } else {
72862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina                setTitle(mInitialTitleResId);
72962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina            }
730a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else {
731a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitleResId = -1;
732a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
733a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
734a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            setTitle(mInitialTitle);
735a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        }
736a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio    }
737a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio
738c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio    @Override
739263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onBackStackChanged() {
740d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        setTitleFromBackStack();
7418eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    }
7428eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio
743b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio    private int setTitleFromBackStack() {
7448eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int count = getFragmentManager().getBackStackEntryCount();
745b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7468eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (count == 0) {
747a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (mInitialTitleResId > 0) {
748a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitleResId);
749a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
750a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                setTitle(mInitialTitle);
751a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
752b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio            return 0;
753263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
754b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
7558eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
7568eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        setTitleFromBackStackEntry(bse);
757b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio
758b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio        return count;
759263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
760263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
7618eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio    private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
7625529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        final CharSequence title;
7638eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        final int titleRes = bse.getBreadCrumbTitleRes();
7648eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (titleRes > 0) {
7658eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = getText(titleRes);
7665529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        } else {
7678eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            title = bse.getBreadCrumbTitle();
7688eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        }
7698eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio        if (title != null) {
7708eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio            setTitle(title);
7715529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio        }
7725529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio    }
7735529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio
774263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
775263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected void onSaveInstanceState(Bundle outState) {
776263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onSaveInstanceState(outState);
777263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
778769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio        if (mCategories.size() > 0) {
779769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio            outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
780263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
781d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio
782b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
7833d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
7843d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7853d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if (mDisplaySearch) {
7863d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // The option menus are created if the ActionBar is visible and they are also created
7873d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // asynchronously. If you launch Settings with an Intent action like
7883d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
7893d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
7903d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            // menu item and search view are null.
7913d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
7923d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
7933d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio
7943d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
7953d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
7963d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        }
797ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
798ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
799263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
800263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
801263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
802263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onResume() {
803263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onResume();
8048a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
8058a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
8068a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
807263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
808ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        final int newHomeActivityCount = getHomeActivitiesCount();
809ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        if (newHomeActivityCount != mHomeActivitiesCount) {
810ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            mHomeActivitiesCount = newHomeActivityCount;
811b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            invalidateCategories(true);
812ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio        }
813ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio
814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            @Override
816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
817b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio                invalidateCategories(true);
818263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        };
820263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
821263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                mDevelopmentPreferencesListener);
822263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
824853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav
825990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.register(this);
826a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio
8273d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
828a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            onQueryTextSubmit(mSearchQuery);
829a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
830263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
831263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
832263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
833263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onPause() {
834263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onPause();
8358a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        if (mIsShowingDashboard) {
8368a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren            MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
8378a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren        }
838263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        unregisterReceiver(mBatteryInfoReceiver);
839990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav        mDynamicIndexableContentMonitor.unregister();
840263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
841263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
842263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
843263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void onDestroy() {
844263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        super.onDestroy();
845680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio
846680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
847680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio                mDevelopmentPreferencesListener);
848680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio        mDevelopmentPreferencesListener = null;
849263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
850263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
851263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    protected boolean isValidFragment(String fragmentName) {
852263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Almost all fragments are wrapped in this,
853263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // except for a few that have their own activities.
854263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
855263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
856263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
857263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return false;
858263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
859263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
860263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
861263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Intent getIntent() {
862263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        Intent superIntent = super.getIntent();
863263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String startingFragment = getStartingFragmentClass(superIntent);
864263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // This is called from super.onCreate, isMultiPane() is not yet reliable
865263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        // Do not use onIsHidingHeaders either, which relies itself on this method
866263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (startingFragment != null) {
867263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Intent modIntent = new Intent(superIntent);
868263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
869263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Bundle args = superIntent.getExtras();
870263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (args != null) {
871263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle(args);
872263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            } else {
873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                args = new Bundle();
874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
875263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            args.putParcelable("intent", superIntent);
876ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy            modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
877263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            return modIntent;
878263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
879263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return superIntent;
880263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
881263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
882263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
883263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Checks if the component name in the intent is different from the Settings class and
884263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * returns the class name to load as a fragment.
885263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
886263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private String getStartingFragmentClass(Intent intent) {
887263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (mFragmentClass != null) return mFragmentClass;
888263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
889263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        String intentClass = intent.getComponent().getClassName();
890263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if (intentClass.equals(getClass().getName())) return null;
891263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
892263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        if ("com.android.settings.ManageApplications".equals(intentClass)
893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.RunningServices".equals(intentClass)
894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                || "com.android.settings.applications.StorageUse".equals(intentClass)) {
895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // Old names of manage apps.
896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            intentClass = com.android.settings.applications.ManageApplications.class.getName();
897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return intentClass;
900263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
90310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment containing a preference panel.  If the preferences
90410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * are being displayed in multi-pane mode, the given fragment class will
90510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * be instantiated and placed in the appropriate pane.  If running in
90610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * single-pane mode, a new activity will be launched in which to show the
90710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
90810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
90910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragmentClass Full name of the class implementing the fragment.
91010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param args Any desired arguments to supply to the fragment.
91110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleRes Optional resource identifier of the title of this
91210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * fragment.
91310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param titleText Optional text of the title of this fragment.
91410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultTo Optional fragment that result data should be sent to.
91510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * If non-null, resultTo.onActivityResult() will be called when this
91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * preference panel is done.  The launched panel must use
91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
91810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param resultRequestCode If resultTo is non-null, this is the caller's
91958146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio     * request code to be received with the result.
92010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
922d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
923a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        String title = null;
924a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleRes < 0) {
925a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            if (titleText != null) {
926a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = titleText.toString();
927a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            } else {
928a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                // There not much we can do in that case
929a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                title = "";
930a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            }
931911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio        }
932a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
9330d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio                titleRes, title, mIsShortcut);
93410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
93510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
93610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
9377a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * Start a new fragment in a new activity containing a preference panel for a given user. If the
9387a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * preferences are being displayed in multi-pane mode, the given fragment class will be
9397a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
9407a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * activity will be launched in which to show the fragment.
9417a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     *
9427a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param fragmentClass Full name of the class implementing the fragment.
9437a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param args Any desired arguments to supply to the fragment.
9447a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleRes Optional resource identifier of the title of this fragment.
9457a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param titleText Optional text of the title of this fragment.
9467a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     * @param userHandle The user for which the panel has to be started.
9477a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban     */
9487a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
9497a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            CharSequence titleText, UserHandle userHandle) {
950d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // This is a workaround.
951d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
952d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
953d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // starting the fragment could cause a native stack corruption. See b/17523189. However,
954d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // adding that flag and start the preference panel with the same UserHandler will make it
955d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // impossible to use back button to return to the previous screen. See b/20042570.
956d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        //
957d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
958d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
959d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        // when we're calling it as the same user.
960d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        if (userHandle.getIdentifier() == UserHandle.myUserId()) {
961d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
962d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang        } else {
963d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            String title = null;
964d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            if (titleRes < 0) {
965d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                if (titleText != null) {
966d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = titleText.toString();
967d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                } else {
968d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    // There not much we can do in that case
969d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    title = "";
970d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                }
9717a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban            }
972d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang            Utils.startWithFragmentAsUser(this, fragmentClass, args,
973d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang                    titleRes, title, mIsShortcut, userHandle);
9747a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban        }
9757a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    }
9767a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban
9777a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban    /**
978263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * Called by a preference panel fragment to finish itself.
979263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     *
980263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param caller The fragment that is asking to be finished.
981263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultCode Optional result code to send back to the original
982263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
983263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * @param resultData Optional result data to send back to the original
984263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     * launching fragment.
985263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio     */
986263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
987263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        setResult(resultCode, resultData);
98858146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio        finish();
989263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
990263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
991263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    /**
99210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * Start a new fragment.
99310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     *
99410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param fragment The fragment to start
99510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * @param push If true, the current fragment will be pushed onto the back stack.  If false,
99610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     * the current fragment will be replaced.
99710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio     */
99810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    public void startPreferenceFragment(Fragment fragment, boolean push) {
99910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
1000d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, fragment);
100110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        if (push) {
100210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
100310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.addToBackStack(BACK_STACK_PREFS);
100410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        } else {
100510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
100610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        }
100710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio        transaction.commitAllowingStateLoss();
100810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    }
100910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio
101010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio    /**
1011d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     * Switch to a specific Fragment with taking care of validation, Title and BackStack
1012d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio     */
1013d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
1014a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
1015d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (validate && !isValidFragment(fragmentName)) {
1016d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            throw new IllegalArgumentException("Invalid fragment for this activity: "
1017d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                    + fragmentName);
1018d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1019d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        Fragment f = Fragment.instantiate(this, fragmentName, args);
1020d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        FragmentTransaction transaction = getFragmentManager().beginTransaction();
1021d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        transaction.replace(R.id.main_content, f);
1022d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (withTransition) {
102359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio            TransitionManager.beginDelayedTransition(mContent);
1024d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1025d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (addToBackStack) {
1026d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1027d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1028a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        if (titleResId > 0) {
1029a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio            transaction.setBreadCrumbTitle(titleResId);
1030a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio        } else if (title != null) {
1031d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio            transaction.setBreadCrumbTitle(title);
1032d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        }
1033d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        transaction.commitAllowingStateLoss();
103459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio        getFragmentManager().executePendingTransactions();
1035d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return f;
1036d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1037d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio
103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
1039769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio     * Called when the activity needs its list of categories/tiles built.
104063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param categories The list in which to place the tiles categories.
104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
1043769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio    private void buildDashboardCategories(List<DashboardCategory> categories) {
10445f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio        categories.clear();
104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        loadCategoriesFromResource(R.xml.dashboard_categories, categories);
104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        updateTilesList(categories);
104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
104863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
104963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    /**
105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * Parse the given XML file as a categories description, adding each
105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * parsed categories and tiles into the target list.
105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     *
105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param resid The XML resource to load and parse.
105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     * @param target The list in which the parsed categories and tiles should be placed.
105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio     */
105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        XmlResourceParser parser = null;
105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            parser = getResources().getXml(resid);
106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            AttributeSet attrs = Xml.asAttributeSet(parser);
106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int type;
106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && type != XmlPullParser.START_TAG) {
106563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Parse next until start tag is found
106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            String nodeName = parser.getName();
106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (!"dashboard-categories".equals(nodeName)) {
107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                throw new RuntimeException(
107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        "XML document must start with <preference-categories> tag; found"
107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                + nodeName + " at " + parser.getPositionDescription());
107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Bundle curBundle = null;
107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            final int outerDepth = parser.getDepth();
107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    continue;
108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                nodeName = parser.getName();
108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if ("dashboard-category".equals(nodeName)) {
108663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    DashboardCategory category = new DashboardCategory();
108763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
108863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedArray sa = obtainStyledAttributes(
108963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            attrs, com.android.internal.R.styleable.PreferenceHeader);
109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    category.id = sa.getResourceId(
109163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_id,
109263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            (int)DashboardCategory.CAT_ID_UNDEFINED);
109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
109463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    TypedValue tv = sa.peekValue(
109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            com.android.internal.R.styleable.PreferenceHeader_title);
109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (tv.resourceId != 0) {
109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.titleRes = tv.resourceId;
109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            category.title = tv.string;
110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sa.recycle();
11042ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    sa = obtainStyledAttributes(attrs, com.android.internal.R.styleable.Preference);
11052ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    tv = sa.peekValue(
11062ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            com.android.internal.R.styleable.Preference_key);
11072ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
11082ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        if (tv.resourceId != 0) {
11092ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.key = getString(tv.resourceId);
11102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else {
11112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.key = tv.string.toString();
11122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        }
11132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    }
11142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    sa.recycle();
111563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
111663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    final int innerDepth = parser.getDepth();
111763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
111963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            continue;
112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        String innerNodeName = parser.getName();
112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        if (innerNodeName.equals("dashboard-tile")) {
112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            DashboardTile tile = new DashboardTile();
112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa = obtainStyledAttributes(
112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    attrs, com.android.internal.R.styleable.PreferenceHeader);
112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.id = sa.getResourceId(
113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_id,
1131e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio                                    (int)TILE_ID_UNDEFINED);
113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_title);
113463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.titleRes = tv.resourceId;
113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
113863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.title = tv.string;
113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tv = sa.peekValue(
114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_summary);
114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (tv != null && tv.type == TypedValue.TYPE_STRING) {
114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (tv.resourceId != 0) {
114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summaryRes = tv.resourceId;
114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.summary = tv.string;
114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.iconRes = sa.getResourceId(
115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_icon, 0);
115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            tile.fragment = sa.getString(
115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    com.android.internal.R.styleable.PreferenceHeader_fragment);
115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            sa.recycle();
115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle == null) {
115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = new Bundle();
115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            final int innerDepth2 = parser.getDepth();
116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    continue;
116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
116763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                String innerNodeName2 = parser.getName();
116863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                if (innerNodeName2.equals("extra")) {
116963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    getResources().parseBundleExtra("extra", attrs, curBundle);
117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
117163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
117263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else if (innerNodeName2.equals("intent")) {
117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    tile.intent = Intent.parseIntent(getResources(), parser, attrs);
117463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                } else {
117663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                    XmlUtils.skipCurrentTag(parser);
117763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                }
117863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            if (curBundle.size() > 0) {
118163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                tile.fragmentArguments = curBundle;
118263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                                curBundle = null;
118363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            }
118463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11853815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            // Show the SIM Cards setting if there are more than 2 SIMs installed.
118622a2a49b445b8721c8194eedf3608ea81c62ccefFabrice Di Meglio                            if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
11873815561997eced7fd773062ce32eaa50bece072cPauloftheWest                                category.addTile(tile);
11883815561997eced7fd773062ce32eaa50bece072cPauloftheWest                            }
118963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
11902ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        } else if (innerNodeName.equals("external-tiles")) {
11912ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                            category.externalIndex = category.getTilesCount();
119263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        } else {
119363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            XmlUtils.skipCurrentTag(parser);
119463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
119563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
119663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
119763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    target.add(category);
119863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else {
119963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    XmlUtils.skipCurrentTag(parser);
120063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
120163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
120263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
120363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (XmlPullParserException e) {
120463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
120563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (IOException e) {
120663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            throw new RuntimeException("Error parsing categories", e);
120763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } finally {
120863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            if (parser != null) parser.close();
120963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
121063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
121163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private void updateTilesList(List<DashboardCategory> target) {
121363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final boolean showDev = mDevelopmentPreferences.getBoolean(
121463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DevelopmentSettings.PREF_SHOW,
121563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                android.os.Build.TYPE.equals("eng"));
121663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
121863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
121963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        final int size = target.size();
122063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        for (int i = 0; i < size; i++) {
122163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            DashboardCategory category = target.get(i);
122363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Ids are integers, so downcasting is ok
122563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int id = (int) category.id;
122663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            int n = category.getTilesCount() - 1;
122763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            while (n >= 0) {
122863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
122963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                DashboardTile tile = category.getTile(n);
123057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                boolean removeTile = false;
123163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                id = (int) tile.id;
123263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
123357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
123457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
123557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    }
123663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.wifi_settings) {
123763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove WiFi Settings if WiFi service is not available.
123863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
123957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
124163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.bluetooth_settings) {
124263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove Bluetooth Settings if Bluetooth service is not available.
124363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
124457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
124563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
124663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.data_usage_settings) {
124763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove data usage when kernel module not enabled
1248b45e27bc0f52d64a71aecba661770b30f6299301Jason Monk                    if (!Utils.isBandwidthControlEnabled()) {
1249b45e27bc0f52d64a71aecba661770b30f6299301Jason Monk                        removeTile = true;
125063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
125163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.battery_settings) {
125263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    // Remove battery settings when battery is not available. (e.g. TV)
125363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
125463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!mBatteryPresent) {
125557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
125663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
125763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.home_settings) {
125863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!updateHomeSettingTiles(tile)) {
125957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
126063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
126163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.user_settings) {
12624093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                    boolean hasMultipleUsers =
12634093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                            ((UserManager) getSystemService(Context.USER_SERVICE))
12644093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani                                    .getUserCount() > 1;
126563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!UserHandle.MU_ENABLED
126636940543e98c96413168d094914810ce3ccc424fNicolas Prevot                            || !UserManager.supportsMultipleUsers()
126763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                            || Utils.isMonkeyRunning()) {
126857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
126963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
127063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.nfc_payment_settings) {
127163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
127257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
127363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    } else {
127463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        // Only show if NFC is on and we have the HCE feature
127563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1276b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                        if (adapter == null || !adapter.isEnabled() ||
1277b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                !getPackageManager().hasSystemFeature(
1278b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio                                        PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
127957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                            removeTile = true;
128063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                        }
128163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
1282488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                } else if (id == R.id.print_settings) {
1283488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1284488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                            PackageManager.FEATURE_PRINTING);
1285488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    if (!hasPrintingSupport) {
128657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
1287488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio                    }
128863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                } else if (id == R.id.development_settings) {
12896c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                    if (!showDev || um.hasUserRestriction(
12906c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds                            UserManager.DISALLOW_DEBUGGING_FEATURES)) {
129157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        removeTile = true;
129263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    }
129363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
129463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
129563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
129657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                        && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
129757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    removeTile = true;
129863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
129963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
130057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                if (removeTile && n < category.getTilesCount()) {
130157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                    category.removeTile(n);
130257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani                }
130363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                n--;
130463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
130563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
13062ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        addExternalTiles(target);
13072ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13082ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13092ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target) {
13102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Map<Pair<String, String>, DashboardTile> addedCache =
13112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                new ArrayMap<Pair<String, String>, DashboardTile>();
13122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        UserManager userManager = UserManager.get(this);
13132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (UserHandle user : userManager.getUserProfiles()) {
13142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            addExternalTiles(target, user, addedCache);
13152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private void addExternalTiles(List<DashboardCategory> target, UserHandle user,
13192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Map<Pair<String, String>, DashboardTile> addedCache) {
13202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        PackageManager pm = getPackageManager();
13212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        Intent intent = new Intent(EXTRA_SETTINGS_ACTION);
13222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        List<ResolveInfo> results = pm.queryIntentActivitiesAsUser(intent,
13232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                PackageManager.GET_META_DATA, user.getIdentifier());
13242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (ResolveInfo resolved : results) {
13252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (!resolved.system) {
13262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                // Do not allow any app to add to settings, only system ones.
13272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            ActivityInfo activityInfo = resolved.activityInfo;
13302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Bundle metaData = activityInfo.metaData;
13312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) {
13322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action "
13332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + EXTRA_SETTINGS_ACTION + " missing metadata " +
13342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        (metaData == null ? "" : EXTRA_CATEGORY_KEY));
13352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY);
13382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardCategory category = getCategory(target, categoryKey);
13392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (category == null) {
13402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown "
13412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        + "category key " + categoryKey);
13422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                continue;
13432ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13442ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            Pair<String, String> key = new Pair<String, String>(activityInfo.packageName,
13452ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    activityInfo.name);
13462ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            DashboardTile tile = addedCache.get(key);
13472ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (tile == null) {
13482ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile = new DashboardTile();
13492ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                tile.intent = new Intent().setClassName(
13502ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                        activityInfo.packageName, activityInfo.name);
13512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile);
13522ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13532ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                if (category.externalIndex == -1) {
13542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // If no location for external tiles has been specified for this category,
13552ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    // then just put them at the end.
13562ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(tile);
13572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                } else {
13582ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                    category.addTile(category.externalIndex, tile);
13592ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                }
13602ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                addedCache.put(key, tile);
13612ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13622ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            tile.userHandle.add(user);
13632ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13642ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    }
13652ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk
13662ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk    private DashboardCategory getCategory(List<DashboardCategory> target, String categoryKey) {
13672ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        for (DashboardCategory category : target) {
13682ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            if (categoryKey.equals(category.key)) {
13692ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk                return category;
13702ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk            }
13712ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        }
13722ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk        return null;
137363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
137463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
137563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    private boolean updateHomeSettingTiles(DashboardTile tile) {
137663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        // Once we decide to show Home settings, keep showing it forever
137763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
137863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
137963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            return true;
138063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
138163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
138263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        try {
1383b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio            mHomeActivitiesCount = getHomeActivitiesCount();
1384ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio            if (mHomeActivitiesCount < 2) {
138563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // When there's only one available home app, omit this settings
138663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // category entirely at the top level UI.  If the user just
138763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // uninstalled the penultimate home app candidiate, we also
138863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // now tell them about why they aren't seeing 'Home' in the list.
138963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (sShowNoHomeNotice) {
139063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    sShowNoHomeNotice = false;
139163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    NoHomeDialogFragment.show(this);
139263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
139363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                return false;
139463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            } else {
139563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // Okay, we're allowing the Home settings category.  Tell it, when
139663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // invoked via this front door, that we'll need to be told about the
139763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                // case when the user uninstalls all but one home app.
139863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                if (tile.fragmentArguments == null) {
139963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                    tile.fragmentArguments = new Bundle();
140063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                }
140163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio                tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
140263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            }
140363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        } catch (Exception e) {
140463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            // Can't look up the home activity; bail on configuring the icon
140563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio            Log.w(LOG_TAG, "Problem looking up home activity!", e);
140663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        }
140763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
140863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
140963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio        return true;
141063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio    }
141163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio
1412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    private void getMetaData() {
1413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        try {
1414263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio                    PackageManager.GET_META_DATA);
1416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            if (ai == null || ai.metaData == null) return;
1417263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        } catch (NameNotFoundException nnfe) {
1419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            // No recovery
1420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    // give subclasses access to the Next button
1425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean hasNextButton() {
1426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton != null;
1427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public Button getNextButton() {
1430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return mNextButton;
1431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    @Override
1434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public boolean shouldUpRecreateTask(Intent targetIntent) {
1435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    public static void requestHomeNotice() {
1439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        sShowNoHomeNotice = true;
1440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
1441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1442d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1443d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextSubmit(String query) {
1444d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        switchToSearchResultsFragmentIfNeeded();
1445d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = query;
1446d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextSubmit(query);
1447d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1449d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1450d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onQueryTextChange(String newText) {
1451d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchQuery = newText;
14527e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio        if (mSearchResultsFragment == null) {
1453a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio            return false;
1454a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        }
1455a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio        return mSearchResultsFragment.onQueryTextChange(newText);
1456d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onClose() {
1460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return false;
1461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1463d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1464d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionExpand(MenuItem item) {
1465d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1466bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            switchToSearchResultsFragmentIfNeeded();
1467263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1468d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1469d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1471d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    @Override
1472d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public boolean onMenuItemActionCollapse(MenuItem item) {
1473d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        if (item.getItemId() == mSearchMenuItem.getItemId()) {
1474bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            if (mSearchMenuItemExpanded) {
1475d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio                revertToInitialFragment();
1476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio            }
1477263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1478d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        return true;
1479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1480263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1481d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void switchToSearchResultsFragmentIfNeeded() {
1482bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (mSearchResultsFragment != null) {
1483bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            return;
1484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio        }
1485d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio        Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
1486bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        if (current != null && current instanceof SearchResultsSummary) {
1487bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) current;
1488bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        } else {
1489bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio            mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
1490a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    SearchResultsSummary.class.getName(), null, false, true,
1491a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio                    R.string.search_results_title, null, true);
1492bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        }
1493d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio        mSearchResultsFragment.setSearchView(mSearchView);
1494bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = true;
1495d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1497d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    public void needToRevertToInitialFragment() {
1498d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = true;
1499d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    }
1500263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio
1501d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio    private void revertToInitialFragment() {
1502d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mNeedToRevertToInitialFragment = false;
1503d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio        mSearchResultsFragment = null;
1504bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        mSearchMenuItemExpanded = false;
1505bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio        getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1506bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio                FragmentManager.POP_BACK_STACK_INCLUSIVE);
150723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        if (mSearchMenuItem != null) {
150823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio            mSearchMenuItem.collapseActionView();
150923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio        }
1510263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio    }
15110698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15120698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public Intent getResultIntentData() {
15130698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        return mResultIntentData;
15140698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
15150698a216311acd9ab52224602d1a75c08bf89f04Jim Miller
15160698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    public void setResultIntentData(Intent resultIntentData) {
15170698a216311acd9ab52224602d1a75c08bf89f04Jim Miller        mResultIntentData = resultIntentData;
15180698a216311acd9ab52224602d1a75c08bf89f04Jim Miller    }
1519263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio}
1520