diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ccaf0b3401c..b71e964d71c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -121,6 +121,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -146,6 +178,7 @@ @@ -158,10 +191,15 @@ + + + + + - @@ -183,6 +221,7 @@ @@ -194,10 +233,13 @@ + + + + - @@ -206,13 +248,12 @@ - @@ -261,8 +303,6 @@ - @@ -270,6 +310,7 @@ @@ -282,8 +323,6 @@ - @@ -378,6 +417,7 @@ @@ -389,10 +429,13 @@ + + + + - @@ -403,8 +446,6 @@ android:clearTaskOnLaunch="true"> - @@ -438,8 +480,6 @@ - @@ -450,8 +490,6 @@ android:targetActivity="Settings$TetherSettingsActivity"> - - @@ -484,14 +521,13 @@ - @@ -503,10 +539,13 @@ + + + + - @@ -522,6 +561,7 @@ @@ -535,14 +575,13 @@ - @@ -554,10 +593,13 @@ + + + + - @@ -576,8 +618,6 @@ - - @@ -601,8 +639,6 @@ android:targetActivity="Settings$InputMethodAndLanguageSettingsActivity"> - - - @@ -685,12 +717,11 @@ android:targetActivity="Settings$UserDictionarySettingsActivity"> - @@ -704,14 +735,13 @@ - @@ -725,14 +755,13 @@ - @@ -750,8 +779,6 @@ - @@ -769,8 +796,6 @@ - @@ -788,8 +813,6 @@ - @@ -807,14 +830,13 @@ - @@ -825,16 +847,20 @@ + + + + - @@ -847,10 +873,13 @@ + + + + - @@ -862,13 +891,12 @@ android:targetActivity="Settings$DisplaySettingsActivity"> - @@ -880,10 +908,15 @@ + + + + + - @@ -902,6 +935,7 @@ @@ -914,25 +948,32 @@ + + + + - + + + + - - @@ -981,8 +1020,6 @@ android:targetActivity="Settings$ManageApplicationsActivity"> - @@ -1000,8 +1037,6 @@ android:targetActivity="Settings$ManageApplicationsActivity"> - @@ -1136,16 +1164,20 @@ + + + + - @@ -1159,10 +1191,13 @@ + + + + - @@ -1183,6 +1218,7 @@ @@ -1196,8 +1232,6 @@ - @@ -1208,12 +1242,11 @@ android:targetActivity="Settings$SecuritySettingsActivity"> - @@ -1227,10 +1260,13 @@ + + + + - @@ -1263,8 +1299,6 @@ - @@ -1274,8 +1308,6 @@ android:targetActivity="Settings$DeviceAdminSettingsActivity"> - - @@ -1340,10 +1371,13 @@ + + + + - @@ -1362,8 +1396,6 @@ - @@ -1382,8 +1414,6 @@ - @@ -1398,8 +1428,6 @@ - @@ -1555,6 +1583,7 @@ @@ -1567,10 +1596,15 @@ + + + + + - @@ -1581,8 +1615,6 @@ android:parentActivityName="Settings$StorageSettingsActivity"> - - - @@ -1673,6 +1701,7 @@ @@ -1680,16 +1709,20 @@ + + + + - @@ -1701,10 +1734,13 @@ + + + + - - @@ -1729,8 +1763,6 @@ android:targetActivity="Settings$DevelopmentSettingsActivity"> - - @@ -1876,6 +1906,7 @@ @@ -1985,6 +2016,7 @@ @@ -1995,10 +2027,13 @@ + + + + - @@ -2008,12 +2043,11 @@ android:targetActivity="Settings$PowerUsageSummaryActivity"> - @@ -2026,8 +2060,6 @@ - @@ -2045,6 +2077,7 @@ @@ -2055,6 +2088,11 @@ + + + + - @@ -2146,26 +2182,29 @@ - + + + + - @@ -2178,14 +2217,13 @@ - @@ -2195,16 +2233,20 @@ + + + + - @@ -2214,10 +2256,13 @@ + + + + - @@ -2273,8 +2318,6 @@ - - @@ -2307,10 +2349,13 @@ + + + + - @@ -2332,8 +2377,6 @@ - @@ -2345,8 +2388,6 @@ android:targetActivity="Settings$NotificationSettingsActivity"> - - @@ -2376,8 +2415,6 @@ android:taskAffinity=""> - @@ -2394,8 +2431,6 @@ - @@ -2472,6 +2507,7 @@ @@ -2481,10 +2517,13 @@ + + + + - - categories = new ArrayList<>(); - SettingsActivity.loadCategoriesFromResource(R.xml.dashboard_categories, categories, this); - for (DashboardCategory category : categories) { - for (DashboardTile tile : category.tiles) { - if (tile.id == topLevelId) { - return tile.iconRes; - } - } - } - return 0; - } - @Override protected boolean onEvaluateShowIcons() { return false; diff --git a/src/com/android/settings/HomeSettings.java b/src/com/android/settings/HomeSettings.java index fbd2ea539f3..145dec9cc4c 100644 --- a/src/com/android/settings/HomeSettings.java +++ b/src/com/android/settings/HomeSettings.java @@ -161,17 +161,6 @@ public class HomeSettings extends SettingsPreferenceFragment implements Indexabl } } } - - // If we're down to just one possible home app, back out of this settings - // fragment and show a dialog explaining to the user that they won't see - // 'Home' settings now until such time as there are multiple available. - if (mPrefs.size() < 2) { - if (mShowNotice) { - mShowNotice = false; - SettingsActivity.requestHomeNotice(); - } - finishFragment(); - } } private void buildHomeActivitiesList() { diff --git a/src/com/android/settings/ProfileSelectDialog.java b/src/com/android/settings/ProfileSelectDialog.java index 99f962fdcf7..9c45ea920c5 100644 --- a/src/com/android/settings/ProfileSelectDialog.java +++ b/src/com/android/settings/ProfileSelectDialog.java @@ -26,7 +26,7 @@ import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; -import com.android.settings.dashboard.DashboardTile; +import com.android.settingslib.drawer.DashboardTile; public class ProfileSelectDialog extends DialogFragment implements OnClickListener { diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 7b94d795edf..fdc55d7bd88 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -118,4 +118,10 @@ public class Settings extends SettingsActivity { public static class WriteSettingsActivity extends SettingsActivity { /* empty */ } public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ } public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ } + + // Categories. + public static class WirelessSettings extends SettingsActivity { /* empty */ } + public static class DeviceSettings extends SettingsActivity { /* empty */ } + public static class PersonalSettings extends SettingsActivity { /* empty */ } + public static class SystemSettings extends SettingsActivity { /* empty */ } } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index c979f76ae95..53d6024fe87 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -17,7 +17,6 @@ package com.android.settings; import android.app.ActionBar; -import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; @@ -32,12 +31,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.res.Configuration; -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; import android.nfc.NfcAdapter; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.os.UserHandle; import android.os.UserManager; import android.support.v14.preference.PreferenceFragment; @@ -45,12 +40,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceManager; import android.text.TextUtils; import android.transition.TransitionManager; -import android.util.ArrayMap; -import android.util.AttributeSet; import android.util.Log; -import android.util.Pair; -import android.util.TypedValue; -import android.util.Xml; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -59,10 +49,9 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.SearchView; - import com.android.internal.logging.MetricsLogger; import com.android.internal.util.ArrayUtils; -import com.android.internal.util.XmlUtils; +import com.android.settings.Settings.WifiSettingsActivity; import com.android.settings.accessibility.AccessibilitySettings; import com.android.settings.accessibility.CaptionPropertiesFragment; import com.android.settings.accounts.AccountSettings; @@ -76,10 +65,7 @@ import com.android.settings.applications.ProcessStatsUi; import com.android.settings.applications.UsageAccessDetails; import com.android.settings.applications.WriteSettingsDetails; import com.android.settings.bluetooth.BluetoothSettings; -import com.android.settings.dashboard.DashboardCategory; import com.android.settings.dashboard.DashboardSummary; -import com.android.settings.dashboard.DashboardTile; -import com.android.settings.dashboard.NoHomeDialogFragment; import com.android.settings.dashboard.SearchResultsSummary; import com.android.settings.deviceinfo.PrivateVolumeForget; import com.android.settings.deviceinfo.PrivateVolumeSettings; @@ -120,19 +106,15 @@ import com.android.settings.wifi.AdvancedWifiSettings; import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.WifiSettings; import com.android.settings.wifi.p2p.WifiP2pSettings; +import com.android.settingslib.drawer.DashboardCategory; +import com.android.settingslib.drawer.DashboardTile; +import com.android.settingslib.drawer.SettingsDrawerActivity; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Set; -import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED; - -public class SettingsActivity extends Activity +public class SettingsActivity extends SettingsDrawerActivity implements PreferenceManager.OnPreferenceTreeClickListener, PreferenceFragment.OnPreferenceStartFragmentCallback, ButtonBarHandler, FragmentManager.OnBackStackChangedListener, @@ -213,70 +195,38 @@ public class SettingsActivity extends Activity private static final String EMPTY_QUERY = ""; - /** - * Settings will search for system activities of this action and add them as a top level - * settings tile using the following parameters. - * - *

A category must be specified in the meta-data for the activity named - * {@link #EXTRA_CATEGORY_KEY} - * - *

The title may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_TITLE} - * otherwise the label for the activity will be used. - * - *

The icon may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_ICON} - * otherwise the icon for the activity will be used. - * - *

A summary my be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_SUMMARY} - */ - private static final String EXTRA_SETTINGS_ACTION = - "com.android.settings.action.EXTRA_SETTINGS"; - - /** - * The key used to get the category from metadata of activities of action - * {@link #EXTRA_SETTINGS_ACTION} - * The value must be one of: - *

  • com.android.settings.category.wireless
  • - *
  • com.android.settings.category.device
  • - *
  • com.android.settings.category.personal
  • - *
  • com.android.settings.category.system
  • - */ - private static final String EXTRA_CATEGORY_KEY = "com.android.settings.category"; - - private static boolean sShowNoHomeNotice = false; - private String mFragmentClass; private CharSequence mInitialTitle; private int mInitialTitleResId; // Show only these settings for restricted users - private int[] SETTINGS_FOR_RESTRICTED = { - R.id.wireless_section, - R.id.wifi_settings, - R.id.bluetooth_settings, - R.id.data_usage_settings, - R.id.sim_settings, - R.id.wireless_settings, - R.id.device_section, - R.id.notification_settings, - R.id.display_settings, - R.id.storage_settings, - R.id.application_settings, - R.id.battery_settings, - R.id.personal_section, - R.id.location_settings, - R.id.security_settings, - R.id.language_settings, - R.id.user_settings, - R.id.account_settings, - R.id.system_section, - R.id.date_time_settings, - R.id.about_settings, - R.id.accessibility_settings, - R.id.print_settings, - R.id.nfc_payment_settings, - R.id.home_settings, - R.id.dashboard + private String[] SETTINGS_FOR_RESTRICTED = { + //wireless_section + WifiSettingsActivity.class.getName(), + Settings.BluetoothSettingsActivity.class.getName(), + Settings.DataUsageSummaryActivity.class.getName(), + Settings.SimSettingsActivity.class.getName(), + Settings.WirelessSettingsActivity.class.getName(), + //device_section + Settings.HomeSettingsActivity.class.getName(), + Settings.NotificationSettingsActivity.class.getName(), + Settings.DisplaySettingsActivity.class.getName(), + Settings.StorageSettingsActivity.class.getName(), + Settings.ManageApplicationsActivity.class.getName(), + Settings.PowerUsageSummaryActivity.class.getName(), + //personal_section + Settings.LocationSettingsActivity.class.getName(), + Settings.SecuritySettingsActivity.class.getName(), + Settings.InputMethodAndLanguageSettingsActivity.class.getName(), + Settings.UserSettingsActivity.class.getName(), + Settings.AccountSettingsActivity.class.getName(), + //system_section + Settings.DateTimeSettingsActivity.class.getName(), + Settings.DeviceInfoSettingsActivity.class.getName(), + Settings.AccessibilitySettingsActivity.class.getName(), + Settings.PrintSettingsActivity.class.getName(), + Settings.PaymentSettingsActivity.class.getName(), }; private static final String[] ENTRY_FRAGMENTS = { @@ -371,7 +321,7 @@ public class SettingsActivity extends Activity if (mBatteryPresent != batteryPresent) { mBatteryPresent = batteryPresent; - invalidateCategories(true); + updateTilesList(); } } } @@ -403,20 +353,6 @@ public class SettingsActivity extends Activity private ArrayList mCategories = new ArrayList(); private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh"; - private static final int MSG_BUILD_CATEGORIES = 1; - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_BUILD_CATEGORIES: { - final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH); - if (forceRefresh) { - buildDashboardCategories(mCategories); - } - } break; - } - } - }; private boolean mNeedToRevertToInitialFragment = false; private int mHomeActivitiesCount = 1; @@ -427,13 +363,6 @@ public class SettingsActivity extends Activity return mSwitchBar; } - public List getDashboardCategories(boolean forceRefresh) { - if (forceRefresh || mCategories.size() == 0) { - buildDashboardCategories(mCategories); - } - return mCategories; - } - @Override public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { // Override the fragment title for Wallpaper settings @@ -451,14 +380,6 @@ public class SettingsActivity extends Activity return false; } - private void invalidateCategories(boolean forceRefresh) { - if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) { - Message msg = new Message(); - msg.what = MSG_BUILD_CATEGORIES; - msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh); - } - } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -549,7 +470,11 @@ public class SettingsActivity extends Activity final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); - mIsShowingDashboard = className.equals(Settings.class.getName()); + mIsShowingDashboard = className.equals(Settings.class.getName()) + || className.equals(Settings.WirelessSettings.class.getName()) + || className.equals(Settings.DeviceSettings.class.getName()) + || className.equals(Settings.PersonalSettings.class.getName()) + || className.equals(Settings.WirelessSettings.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings @@ -800,16 +725,10 @@ public class SettingsActivity extends Activity MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS); } - final int newHomeActivityCount = getHomeActivitiesCount(); - if (newHomeActivityCount != mHomeActivitiesCount) { - mHomeActivitiesCount = newHomeActivityCount; - invalidateCategories(true); - } - mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - invalidateCategories(true); + updateTilesList(); } }; mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( @@ -822,6 +741,7 @@ public class SettingsActivity extends Activity if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { onQueryTextSubmit(mSearchQuery); } + updateTilesList(); } @Override @@ -1030,346 +950,94 @@ public class SettingsActivity extends Activity return f; } - /** - * Called when the activity needs its list of categories/tiles built. - * - * @param categories The list in which to place the tiles categories. - */ - private void buildDashboardCategories(List categories) { - categories.clear(); - loadCategoriesFromResource(R.xml.dashboard_categories, categories, this); - updateTilesList(categories); - } - - /** - * Parse the given XML file as a categories description, adding each - * parsed categories and tiles into the target list. - * - * @param resid The XML resource to load and parse. - * @param target The list in which the parsed categories and tiles should be placed. - */ - public static void loadCategoriesFromResource(int resid, List target, - Context context) { - XmlResourceParser parser = null; - try { - parser = context.getResources().getXml(resid); - AttributeSet attrs = Xml.asAttributeSet(parser); - - int type; - while ((type=parser.next()) != XmlPullParser.END_DOCUMENT - && type != XmlPullParser.START_TAG) { - // Parse next until start tag is found - } - - String nodeName = parser.getName(); - if (!"dashboard-categories".equals(nodeName)) { - throw new RuntimeException( - "XML document must start with tag; found" - + nodeName + " at " + parser.getPositionDescription()); - } - - Bundle curBundle = null; - - final int outerDepth = parser.getDepth(); - while ((type=parser.next()) != XmlPullParser.END_DOCUMENT - && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { - if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { - continue; - } - - nodeName = parser.getName(); - if ("dashboard-category".equals(nodeName)) { - DashboardCategory category = new DashboardCategory(); - - TypedArray sa = context.obtainStyledAttributes( - attrs, com.android.internal.R.styleable.PreferenceHeader); - category.id = sa.getResourceId( - com.android.internal.R.styleable.PreferenceHeader_id, - (int)DashboardCategory.CAT_ID_UNDEFINED); - - TypedValue tv = sa.peekValue( - com.android.internal.R.styleable.PreferenceHeader_title); - if (tv != null && tv.type == TypedValue.TYPE_STRING) { - if (tv.resourceId != 0) { - category.titleRes = tv.resourceId; - } else { - category.title = tv.string; - } - } - sa.recycle(); - sa = context.obtainStyledAttributes(attrs, - com.android.internal.R.styleable.Preference); - tv = sa.peekValue( - com.android.internal.R.styleable.Preference_key); - if (tv != null && tv.type == TypedValue.TYPE_STRING) { - if (tv.resourceId != 0) { - category.key = context.getString(tv.resourceId); - } else { - category.key = tv.string.toString(); - } - } - sa.recycle(); - - final int innerDepth = parser.getDepth(); - while ((type=parser.next()) != XmlPullParser.END_DOCUMENT - && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { - if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { - continue; - } - - String innerNodeName = parser.getName(); - if (innerNodeName.equals("dashboard-tile")) { - DashboardTile tile = new DashboardTile(); - - sa = context.obtainStyledAttributes( - attrs, com.android.internal.R.styleable.PreferenceHeader); - tile.id = sa.getResourceId( - com.android.internal.R.styleable.PreferenceHeader_id, - (int)TILE_ID_UNDEFINED); - tv = sa.peekValue( - com.android.internal.R.styleable.PreferenceHeader_title); - if (tv != null && tv.type == TypedValue.TYPE_STRING) { - if (tv.resourceId != 0) { - tile.titleRes = tv.resourceId; - } else { - tile.title = tv.string; - } - } - tv = sa.peekValue( - com.android.internal.R.styleable.PreferenceHeader_summary); - if (tv != null && tv.type == TypedValue.TYPE_STRING) { - if (tv.resourceId != 0) { - tile.summaryRes = tv.resourceId; - } else { - tile.summary = tv.string; - } - } - tile.iconRes = sa.getResourceId( - com.android.internal.R.styleable.PreferenceHeader_icon, 0); - tile.fragment = sa.getString( - com.android.internal.R.styleable.PreferenceHeader_fragment); - sa.recycle(); - - if (curBundle == null) { - curBundle = new Bundle(); - } - - final int innerDepth2 = parser.getDepth(); - while ((type=parser.next()) != XmlPullParser.END_DOCUMENT - && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) { - if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { - continue; - } - - String innerNodeName2 = parser.getName(); - if (innerNodeName2.equals("extra")) { - context.getResources().parseBundleExtra("extra", attrs, - curBundle); - XmlUtils.skipCurrentTag(parser); - - } else if (innerNodeName2.equals("intent")) { - tile.intent = Intent.parseIntent(context.getResources(), parser, - attrs); - - } else { - XmlUtils.skipCurrentTag(parser); - } - } - - if (curBundle.size() > 0) { - tile.fragmentArguments = curBundle; - curBundle = null; - } - - // Show the SIM Cards setting if there are more than 2 SIMs installed. - if(tile.id != R.id.sim_settings || Utils.showSimCardTile(context)){ - category.addTile(tile); - } - - } else if (innerNodeName.equals("external-tiles")) { - category.externalIndex = category.getTilesCount(); - } else { - XmlUtils.skipCurrentTag(parser); - } - } - - target.add(category); - } else { - XmlUtils.skipCurrentTag(parser); - } - } - - } catch (XmlPullParserException e) { - throw new RuntimeException("Error parsing categories", e); - } catch (IOException e) { - throw new RuntimeException("Error parsing categories", e); - } finally { - if (parser != null) parser.close(); - } - } - - private void updateTilesList(List target) { - final boolean showDev = mDevelopmentPreferences.getBoolean( - DevelopmentSettings.PREF_SHOW, - android.os.Build.TYPE.equals("eng")); - + private void updateTilesList() { + PackageManager pm = getPackageManager(); final UserManager um = UserManager.get(this); final boolean isAdmin = um.isAdminUser(); - final int size = target.size(); - for (int i = 0; i < size; i++) { + String packageName = getPackageName(); + setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()), + pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm); - DashboardCategory category = target.get(i); + setTileEnabled(new ComponentName(packageName, + Settings.BluetoothSettingsActivity.class.getName()), + pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm); - // Ids are integers, so downcasting is ok - int id = (int) category.id; - int n = category.getTilesCount() - 1; - while (n >= 0) { + setTileEnabled(new ComponentName(packageName, + Settings.DataUsageSummaryActivity.class.getName()), + Utils.isBandwidthControlEnabled(), isAdmin, pm); - DashboardTile tile = category.getTile(n); - boolean removeTile = false; - id = (int) tile.id; - if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { - if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) { - removeTile = true; - } - } else if (id == R.id.wifi_settings) { - // Remove WiFi Settings if WiFi service is not available. - if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { - removeTile = true; - } - } else if (id == R.id.bluetooth_settings) { - // Remove Bluetooth Settings if Bluetooth service is not available. - if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { - removeTile = true; - } - } else if (id == R.id.data_usage_settings) { - // Remove data usage when kernel module not enabled - if (!Utils.isBandwidthControlEnabled()) { - removeTile = true; - } - } else if (id == R.id.battery_settings) { - // Remove battery settings when battery is not available. (e.g. TV) + setTileEnabled(new ComponentName(packageName, + Settings.SimSettingsActivity.class.getName()), + Utils.showSimCardTile(this), isAdmin, pm); - if (!mBatteryPresent) { - removeTile = true; - } - } else if (id == R.id.home_settings) { - if (!updateHomeSettingTiles(tile)) { - removeTile = true; - } - } else if (id == R.id.user_settings) { - if (!UserHandle.MU_ENABLED - || !UserManager.supportsMultipleUsers() - || Utils.isMonkeyRunning()) { - removeTile = true; - } - } else if (id == R.id.nfc_payment_settings) { - if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { - removeTile = true; - } else { - // Only show if NFC is on and we have the HCE feature - NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); - if (adapter == null || !adapter.isEnabled() || - !getPackageManager().hasSystemFeature( - PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { - removeTile = true; - } - } - } else if (id == R.id.print_settings) { - boolean hasPrintingSupport = getPackageManager().hasSystemFeature( - PackageManager.FEATURE_PRINTING); - if (!hasPrintingSupport) { - removeTile = true; - } - } else if (id == R.id.development_settings) { - if (!showDev || um.hasUserRestriction( - UserManager.DISALLOW_DEBUGGING_FEATURES)) { - removeTile = true; + setTileEnabled(new ComponentName(packageName, + Settings.PowerUsageSummaryActivity.class.getName()), + mBatteryPresent, isAdmin, pm); + + setTileEnabled(new ComponentName(packageName, + Settings.HomeSettingsActivity.class.getName()), + updateHomeSettingTiles(), isAdmin, pm); + + setTileEnabled(new ComponentName(packageName, + Settings.UserSettingsActivity.class.getName()), + UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() + && !Utils.isMonkeyRunning(), isAdmin, pm); + + NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); + setTileEnabled(new ComponentName(packageName, + Settings.PaymentSettingsActivity.class.getName()), + pm.hasSystemFeature(PackageManager.FEATURE_NFC) + && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION) + && adapter != null && adapter.isEnabled(), isAdmin, pm); + + setTileEnabled(new ComponentName(packageName, + Settings.PrintSettingsActivity.class.getName()), + pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm); + + final boolean showDev = mDevelopmentPreferences.getBoolean( + DevelopmentSettings.PREF_SHOW, + android.os.Build.TYPE.equals("eng")); + setTileEnabled(new ComponentName(packageName, + Settings.DevelopmentSettingsActivity.class.getName()), + showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES), + isAdmin, pm); + + if (UserHandle.MU_ENABLED && !isAdmin) { + // When on restricted users, disable all extra categories (but only the settings ones). + List categories = getDashboardCategories(true); + for (DashboardCategory category : categories) { + for (DashboardTile tile : category.tiles) { + ComponentName component = tile.intent.getComponent(); + if (packageName.equals(component)&& !ArrayUtils.contains( + SETTINGS_FOR_RESTRICTED, component.getClassName())) { + setTileEnabled(component, false, isAdmin, pm); } } - - if (UserHandle.MU_ENABLED && !isAdmin - && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { - removeTile = true; - } - - if (removeTile && n < category.getTilesCount()) { - category.removeTile(n); - } - n--; } } - addExternalTiles(target); + + updateDrawer(); } - private void addExternalTiles(List target) { - Map, DashboardTile> addedCache = - new ArrayMap, DashboardTile>(); - UserManager userManager = UserManager.get(this); - for (UserHandle user : userManager.getUserProfiles()) { - addExternalTiles(target, user, addedCache); + private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin, + PackageManager pm) { + if (UserHandle.MU_ENABLED && !isAdmin + && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) { + enabled = false; + } + int state = pm.getComponentEnabledSetting(component); + boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT + || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; + if (isEnabled != enabled) { + pm.setComponentEnabledSetting(component, enabled + ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED + : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); } } - private void addExternalTiles(List target, UserHandle user, - Map, DashboardTile> addedCache) { - PackageManager pm = getPackageManager(); - Intent intent = new Intent(EXTRA_SETTINGS_ACTION); - List results = pm.queryIntentActivitiesAsUser(intent, - PackageManager.GET_META_DATA, user.getIdentifier()); - for (ResolveInfo resolved : results) { - if (!resolved.system) { - // Do not allow any app to add to settings, only system ones. - continue; - } - ActivityInfo activityInfo = resolved.activityInfo; - Bundle metaData = activityInfo.metaData; - if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) { - Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action " - + EXTRA_SETTINGS_ACTION + " missing metadata " + - (metaData == null ? "" : EXTRA_CATEGORY_KEY)); - continue; - } - String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY); - DashboardCategory category = getCategory(target, categoryKey); - if (category == null) { - Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown " - + "category key " + categoryKey); - continue; - } - Pair key = new Pair(activityInfo.packageName, - activityInfo.name); - DashboardTile tile = addedCache.get(key); - if (tile == null) { - tile = new DashboardTile(); - tile.intent = new Intent().setClassName( - activityInfo.packageName, activityInfo.name); - Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile); - - if (category.externalIndex == -1) { - // If no location for external tiles has been specified for this category, - // then just put them at the end. - category.addTile(tile); - } else { - category.addTile(category.externalIndex, tile); - } - addedCache.put(key, tile); - } - tile.userHandle.add(user); - } - } - - private DashboardCategory getCategory(List target, String categoryKey) { - for (DashboardCategory category : target) { - if (categoryKey.equals(category.key)) { - return category; - } - } - return null; - } - - private boolean updateHomeSettingTiles(DashboardTile tile) { + private boolean updateHomeSettingTiles() { // Once we decide to show Home settings, keep showing it forever SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { @@ -1379,23 +1047,7 @@ public class SettingsActivity extends Activity try { mHomeActivitiesCount = getHomeActivitiesCount(); if (mHomeActivitiesCount < 2) { - // When there's only one available home app, omit this settings - // category entirely at the top level UI. If the user just - // uninstalled the penultimate home app candidiate, we also - // now tell them about why they aren't seeing 'Home' in the list. - if (sShowNoHomeNotice) { - sShowNoHomeNotice = false; - NoHomeDialogFragment.show(this); - } return false; - } else { - // Okay, we're allowing the Home settings category. Tell it, when - // invoked via this front door, that we'll need to be told about the - // case when the user uninstalls all but one home app. - if (tile.fragmentArguments == null) { - tile.fragmentArguments = new Bundle(); - } - tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); } } catch (Exception e) { // Can't look up the home activity; bail on configuring the icon @@ -1432,10 +1084,6 @@ public class SettingsActivity extends Activity return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); } - public static void requestHomeNotice() { - sShowNoHomeNotice = true; - } - @Override public boolean onQueryTextSubmit(String query) { switchToSearchResultsFragmentIfNeeded(); @@ -1475,6 +1123,16 @@ public class SettingsActivity extends Activity return true; } + @Override + protected void onTileClicked(DashboardTile tile) { + if (mIsShowingDashboard) { + // If on dashboard, don't finish so the back comes back to here. + openTile(tile); + } else { + super.onTileClicked(tile); + } + } + private void switchToSearchResultsFragmentIfNeeded() { if (mSearchResultsFragment != null) { return; diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 7129a814ae8..a9d2c8a3963 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -41,12 +41,10 @@ import android.content.pm.ResolveInfo; import android.content.pm.Signature; import android.content.pm.UserInfo; import android.content.res.Resources; -import android.content.res.Resources.NotFoundException; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.hardware.usb.IUsbManager; import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Uri; @@ -84,11 +82,8 @@ import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.ListView; import android.widget.TabWidget; - import com.android.internal.util.UserIcons; import com.android.settings.UserAdapter.UserDetails; -import com.android.settings.dashboard.DashboardTile; -import com.android.settingslib.applications.ApplicationsState; import java.io.IOException; import java.io.InputStream; @@ -123,24 +118,6 @@ public final class Utils { 0xfffabf2c, 0xff679e37, 0xff0a7f42 }; - /** - * Name of the meta-data item that should be set in the AndroidManifest.xml - * to specify the icon that should be displayed for the preference. - */ - public static final String META_DATA_PREFERENCE_ICON = "com.android.settings.icon"; - - /** - * Name of the meta-data item that should be set in the AndroidManifest.xml - * to specify the title that should be displayed for the preference. - */ - public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; - - /** - * Name of the meta-data item that should be set in the AndroidManifest.xml - * to specify the summary text that should be displayed for the preference. - */ - public static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary"; - private static final String SETTINGS_PACKAGE_NAME = "com.android.settings"; private static final int SECONDS_PER_MINUTE = 60; @@ -206,74 +183,6 @@ public final class Utils { return false; } - public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context, - DashboardTile tile) { - - Intent intent = tile.intent; - if (intent != null) { - // Find the activity that is in the system image - PackageManager pm = context.getPackageManager(); - List list = tile.userHandle.size() != 0 - ? pm.queryIntentActivitiesAsUser(intent, PackageManager.GET_META_DATA, - tile.userHandle.get(0).getIdentifier()) - : pm.queryIntentActivities(intent, PackageManager.GET_META_DATA); - int listSize = list.size(); - for (int i = 0; i < listSize; i++) { - ResolveInfo resolveInfo = list.get(i); - if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) - != 0) { - int icon = 0; - CharSequence title = null; - String summary = null; - - // Get the activity's meta-data - try { - Resources res = pm.getResourcesForApplication( - resolveInfo.activityInfo.packageName); - Bundle metaData = resolveInfo.activityInfo.metaData; - - if (res != null && metaData != null) { - if (metaData.containsKey(META_DATA_PREFERENCE_ICON)) { - icon = metaData.getInt(META_DATA_PREFERENCE_ICON); - } - if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { - title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); - } - if (metaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) { - summary = res.getString( - metaData.getInt(META_DATA_PREFERENCE_SUMMARY)); - } - } - } catch (NameNotFoundException | NotFoundException e) { - // Ignore - } - - // Set the preference title to the activity's label if no - // meta-data is found - if (TextUtils.isEmpty(title)) { - title = resolveInfo.loadLabel(pm).toString(); - } - if (icon == 0) { - icon = resolveInfo.activityInfo.icon; - } - - // Set icon, title and summary for the preference - tile.iconRes = icon; - tile.iconPkg = resolveInfo.activityInfo.packageName; - tile.title = title; - tile.summary = summary; - // Replace the intent with this specific activity - tile.intent = new Intent().setClassName(resolveInfo.activityInfo.packageName, - resolveInfo.activityInfo.name); - - return true; - } - } - } - - return false; - } - /** * Returns true if Monkey is running. */ diff --git a/src/com/android/settings/dashboard/DashboardCategory.java b/src/com/android/settings/dashboard/DashboardCategory.java deleted file mode 100644 index 69d0316f761..00000000000 --- a/src/com/android/settings/dashboard/DashboardCategory.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.dashboard; - -import android.content.res.Resources; -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; - -import java.util.ArrayList; -import java.util.List; - -public class DashboardCategory implements Parcelable { - - /** - * Default value for {@link com.android.settings.dashboard.DashboardCategory#id DashboardCategory.id} - * indicating that no identifier value is set. All other values (including those below -1) - * are valid. - */ - public static final long CAT_ID_UNDEFINED = -1; - - /** - * Identifier for this tile, to correlate with a new list when - * it is updated. The default value is - * {@link com.android.settings.dashboard.DashboardTile#TILE_ID_UNDEFINED}, meaning no id. - * @attr ref android.R.styleable#PreferenceHeader_id - */ - public long id = CAT_ID_UNDEFINED; - - /** - * Resource ID of title of the category that is shown to the user. - */ - public int titleRes; - - /** - * Title of the category that is shown to the user. - */ - public CharSequence title; - - /** - * Key used for placing external tiles. - */ - public String key; - - /** - * Optional index of where to place tiles specified by system apps. - */ - public int externalIndex = -1; - - /** - * List of the category's children - */ - public List tiles = new ArrayList(); - - - public DashboardCategory() { - // Empty - } - - public void addTile(DashboardTile tile) { - tiles.add(tile); - } - - public void addTile(int n, DashboardTile tile) { - tiles.add(n, tile); - } - - public void removeTile(DashboardTile tile) { - tiles.remove(tile); - } - - public void removeTile(int n) { - tiles.remove(n); - } - - public int getTilesCount() { - return tiles.size(); - } - - public DashboardTile getTile(int n) { - return tiles.get(n); - } - - /** - * Return the currently set title. If {@link #titleRes} is set, - * this resource is loaded from res and returned. Otherwise - * {@link #title} is returned. - */ - public CharSequence getTitle(Resources res) { - if (titleRes != 0) { - return res.getText(titleRes); - } - return title; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(titleRes); - dest.writeInt(externalIndex); - TextUtils.writeToParcel(title, dest, flags); - dest.writeString(key); - - final int count = tiles.size(); - dest.writeInt(count); - - for (int n = 0; n < count; n++) { - DashboardTile tile = tiles.get(n); - tile.writeToParcel(dest, flags); - } - } - - public void readFromParcel(Parcel in) { - titleRes = in.readInt(); - externalIndex = in.readInt(); - title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - key = in.readString(); - - final int count = in.readInt(); - - for (int n = 0; n < count; n++) { - DashboardTile tile = DashboardTile.CREATOR.createFromParcel(in); - tiles.add(tile); - } - } - - DashboardCategory(Parcel in) { - readFromParcel(in); - } - - public static final Creator CREATOR = new Creator() { - public DashboardCategory createFromParcel(Parcel source) { - return new DashboardCategory(source); - } - - public DashboardCategory[] newArray(int size) { - return new DashboardCategory[size]; - } - }; -} diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index 6408636f0ac..6f10ac67c76 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -20,7 +20,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -42,6 +41,8 @@ import com.android.settings.HelpUtils; import com.android.settings.InstrumentedFragment; import com.android.settings.R; import com.android.settings.SettingsActivity; +import com.android.settingslib.drawer.DashboardCategory; +import com.android.settingslib.drawer.DashboardTile; import java.util.List; @@ -147,7 +148,7 @@ public class DashboardSummary extends InstrumentedFragment { false); TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title); - categoryLabel.setText(category.getTitle(res)); + categoryLabel.setText(category.title); ViewGroup categoryContent = (ViewGroup) categoryView.findViewById(R.id.category_content); @@ -175,11 +176,11 @@ public class DashboardSummary extends InstrumentedFragment { private void updateTileView(Context context, Resources res, DashboardTile tile, ImageView tileIcon, TextView tileTextView, TextView statusTextView) { - if (!TextUtils.isEmpty(tile.iconPkg)) { - try { - Drawable drawable = context.getPackageManager() - .getResourcesForApplication(tile.iconPkg).getDrawable(tile.iconRes, null); - if (!tile.iconPkg.equals(context.getPackageName()) && drawable != null) { + if (tile.icon != null) { + if (!TextUtils.isEmpty(tile.icon.getResPackage())) { + Drawable drawable = tile.icon.loadDrawable(context); + if (!tile.icon.getResPackage().equals(context.getPackageName()) + && drawable != null) { // If this drawable is coming from outside Settings, tint it to match the color. TypedValue tintColor = new TypedValue(); context.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent, @@ -187,20 +188,17 @@ public class DashboardSummary extends InstrumentedFragment { drawable.setTint(tintColor.data); } tileIcon.setImageDrawable(drawable); - } catch (NameNotFoundException | Resources.NotFoundException e) { - tileIcon.setImageDrawable(null); - tileIcon.setBackground(null); + } else { + tileIcon.setImageIcon(tile.icon); } - } else if (tile.iconRes > 0) { - tileIcon.setImageResource(tile.iconRes); } else { tileIcon.setImageDrawable(null); tileIcon.setBackground(null); } - tileTextView.setText(tile.getTitle(res)); + tileTextView.setText(tile.title); - CharSequence summary = tile.getSummary(res); + CharSequence summary = tile.summary; if (!TextUtils.isEmpty(summary)) { statusTextView.setVisibility(View.VISIBLE); statusTextView.setText(summary); diff --git a/src/com/android/settings/dashboard/DashboardTile.java b/src/com/android/settings/dashboard/DashboardTile.java deleted file mode 100644 index 5e7e49a7cb0..00000000000 --- a/src/com/android/settings/dashboard/DashboardTile.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.dashboard; - -import android.content.Intent; -import android.content.res.Resources; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.os.UserHandle; -import android.text.TextUtils; - -import java.util.ArrayList; - -/** - * Description of a single dashboard tile that the user can select. - */ -public class DashboardTile implements Parcelable { - /** - * Default value for {@link com.android.settings.dashboard.DashboardTile#id DashboardTile.id} - * indicating that no identifier value is set. All other values (including those below -1) - * are valid. - */ - public static final long TILE_ID_UNDEFINED = -1; - - /** - * Identifier for this tile, to correlate with a new list when - * it is updated. The default value is - * {@link com.android.settings.dashboard.DashboardTile#TILE_ID_UNDEFINED}, meaning no id. - * @attr ref android.R.styleable#PreferenceHeader_id - */ - public long id = TILE_ID_UNDEFINED; - - /** - * Resource ID of title of the tile that is shown to the user. - * @attr ref android.R.styleable#PreferenceHeader_title - */ - public int titleRes; - - /** - * Title of the tile that is shown to the user. - * @attr ref android.R.styleable#PreferenceHeader_title - */ - public CharSequence title; - - /** - * Resource ID of optional summary describing what this tile controls. - * @attr ref android.R.styleable#PreferenceHeader_summary - */ - public int summaryRes; - - /** - * Optional summary describing what this tile controls. - * @attr ref android.R.styleable#PreferenceHeader_summary - */ - public CharSequence summary; - - /** - * Optional icon resource to show for this tile. - * @attr ref android.R.styleable#PreferenceHeader_icon - */ - public int iconRes; - - /** - * Optional package to pull the icon resource from. - */ - public String iconPkg; - - /** - * Full class name of the fragment to display when this tile is - * selected. - * @attr ref android.R.styleable#PreferenceHeader_fragment - */ - public String fragment; - - /** - * Optional arguments to supply to the fragment when it is - * instantiated. - */ - public Bundle fragmentArguments; - - /** - * Intent to launch when the preference is selected. - */ - public Intent intent; - - /** - * Optional list of user handles which the intent should be launched on. - */ - public ArrayList userHandle = new ArrayList<>(); - - /** - * Optional additional data for use by subclasses of the activity - */ - public Bundle extras; - - public DashboardTile() { - // Empty - } - - /** - * Return the currently set title. If {@link #titleRes} is set, - * this resource is loaded from res and returned. Otherwise - * {@link #title} is returned. - */ - public CharSequence getTitle(Resources res) { - if (titleRes != 0) { - return res.getText(titleRes); - } - return title; - } - - /** - * Return the currently set summary. If {@link #summaryRes} is set, - * this resource is loaded from res and returned. Otherwise - * {@link #summary} is returned. - */ - public CharSequence getSummary(Resources res) { - if (summaryRes != 0) { - return res.getText(summaryRes); - } - return summary; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(id); - dest.writeInt(titleRes); - TextUtils.writeToParcel(title, dest, flags); - dest.writeInt(summaryRes); - TextUtils.writeToParcel(summary, dest, flags); - dest.writeInt(iconRes); - dest.writeString(iconPkg); - dest.writeString(fragment); - dest.writeBundle(fragmentArguments); - if (intent != null) { - dest.writeInt(1); - intent.writeToParcel(dest, flags); - } else { - dest.writeInt(0); - } - final int N = userHandle.size(); - dest.writeInt(N); - for (int i = 0; i < N; i++) { - userHandle.get(i).writeToParcel(dest, flags); - } - dest.writeBundle(extras); - } - - public void readFromParcel(Parcel in) { - id = in.readLong(); - titleRes = in.readInt(); - title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - summaryRes = in.readInt(); - summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - iconRes = in.readInt(); - iconPkg = in.readString(); - fragment = in.readString(); - fragmentArguments = in.readBundle(); - if (in.readInt() != 0) { - intent = Intent.CREATOR.createFromParcel(in); - } - final int N = in.readInt(); - for (int i = 0; i < N; i++) { - userHandle.add(UserHandle.CREATOR.createFromParcel(in)); - } - extras = in.readBundle(); - } - - DashboardTile(Parcel in) { - readFromParcel(in); - } - - public static final Creator CREATOR = new Creator() { - public DashboardTile createFromParcel(Parcel source) { - return new DashboardTile(source); - } - public DashboardTile[] newArray(int size) { - return new DashboardTile[size]; - } - }; -} diff --git a/src/com/android/settings/dashboard/DashboardTileView.java b/src/com/android/settings/dashboard/DashboardTileView.java index 0896b826296..94219d2e83f 100644 --- a/src/com/android/settings/dashboard/DashboardTileView.java +++ b/src/com/android/settings/dashboard/DashboardTileView.java @@ -28,6 +28,7 @@ import android.widget.TextView; import com.android.settings.ProfileSelectDialog; import com.android.settings.R; import com.android.settings.Utils; +import com.android.settingslib.drawer.DashboardTile; public class DashboardTileView extends FrameLayout implements View.OnClickListener { @@ -91,17 +92,21 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen @Override public void onClick(View v) { - if (mTile.fragment != null) { - Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0, - mTile.titleRes, mTile.getTitle(getResources())); - } else if (mTile.intent != null) { - int numUserHandles = mTile.userHandle.size(); + clickTile(getContext(), mTile); + } + + public static void clickTile(Context context, DashboardTile tile) { + if (tile.fragment != null) { + Utils.startWithFragment(context, tile.fragment, tile.fragmentArguments, null, 0, + 0, tile.title); + } else if (tile.intent != null) { + int numUserHandles = tile.userHandle.size(); if (numUserHandles > 1) { - ProfileSelectDialog.show(((Activity) getContext()).getFragmentManager(), mTile); + ProfileSelectDialog.show(((Activity) context).getFragmentManager(), tile); } else if (numUserHandles == 1) { - getContext().startActivityAsUser(mTile.intent, mTile.userHandle.get(0)); + context.startActivityAsUser(tile.intent, tile.userHandle.get(0)); } else { - getContext().startActivity(mTile.intent); + context.startActivity(tile.intent); } } }