Settings new dashboard - part 1

- make the Settings dashboard definition be hierarchical (non flat) and use
categories and tiles
- code cleaning: remove mHeaderIndexMap

Change-Id: I16581a736ac5c8388a182d83159161fe3bb04f4b
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 4c3e2bc..699955a 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -76,7 +76,9 @@
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.applications.ProcessStatsUi;
 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.Header;
 import com.android.settings.dashboard.HeaderAdapter;
 import com.android.settings.dashboard.NoHomeDialogFragment;
@@ -323,10 +325,11 @@
     private String mSearchQuery;
 
     // Headers
-    protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
     private final ArrayList<Header> mHeaders = new ArrayList<Header>();
     private HeaderAdapter mHeaderAdapter;
 
+    private List<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
+
     private static final int MSG_BUILD_HEADERS = 1;
     private Handler mHandler = new Handler() {
         @Override
@@ -999,7 +1002,6 @@
         int i = 0;
 
         final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
-        mHeaderIndexMap.clear();
         while (i < target.size()) {
             Header header = target.get(i);
             // Ids are integers, so downcasting
@@ -1075,7 +1077,6 @@
 
             // Increment if the current one wasn't removed by the Utils code.
             if (i < target.size() && target.get(i) == header) {
-                mHeaderIndexMap.put(id, i);
                 i++;
             }
         }
@@ -1175,6 +1176,351 @@
         return true;
     }
 
+    /**
+     * Called when the activity needs its list of categories/tiles build.
+     *
+     * @param categories The list in which to place the tiles categories.
+     */
+    private void onBuildDashboardCategories(List<DashboardCategory> categories) {
+        loadCategoriesFromResource(R.xml.dashboard_categories, categories);
+        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.
+     */
+    private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
+        XmlResourceParser parser = null;
+        try {
+            parser = 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 <preference-categories> 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 = 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();
+
+                    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 = obtainStyledAttributes(
+                                    attrs, com.android.internal.R.styleable.PreferenceHeader);
+                            tile.id = sa.getResourceId(
+                                    com.android.internal.R.styleable.PreferenceHeader_id,
+                                    (int)HEADER_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")) {
+                                    getResources().parseBundleExtra("extra", attrs, curBundle);
+                                    XmlUtils.skipCurrentTag(parser);
+
+                                } else if (innerNodeName2.equals("intent")) {
+                                    tile.intent = Intent.parseIntent(getResources(), parser, attrs);
+
+                                } else {
+                                    XmlUtils.skipCurrentTag(parser);
+                                }
+                            }
+
+                            if (curBundle.size() > 0) {
+                                tile.fragmentArguments = curBundle;
+                                curBundle = null;
+                            }
+
+                            category.addTile(tile);
+
+                        } 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<DashboardCategory> target) {
+        final boolean showDev = mDevelopmentPreferences.getBoolean(
+                DevelopmentSettings.PREF_SHOW,
+                android.os.Build.TYPE.equals("eng"));
+
+        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
+
+        final int size = target.size();
+        for (int i = 0; i < size; i++) {
+
+            DashboardCategory category = target.get(i);
+
+            // Ids are integers, so downcasting is ok
+            int id = (int) category.id;
+            if (id == R.id.account_settings) {
+                insertAccountsTiles(category);
+                continue;
+            }
+            int n = category.getTilesCount() - 1;
+            while (n >= 0) {
+
+                DashboardTile tile = category.getTile(n);
+
+                id = (int) tile.id;
+                if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
+                    Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
+                } else if (id == R.id.wifi_settings) {
+                    // Remove WiFi Settings if WiFi service is not available.
+                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.bluetooth_settings) {
+                    // Remove Bluetooth Settings if Bluetooth service is not available.
+                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.data_usage_settings) {
+                    // Remove data usage when kernel module not enabled
+                    final INetworkManagementService netManager = INetworkManagementService.Stub
+                            .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
+                    try {
+                        if (!netManager.isBandwidthControlEnabled()) {
+                            category.removeTile(n);
+                        }
+                    } catch (RemoteException e) {
+                        // ignored
+                    }
+                } else if (id == R.id.battery_settings) {
+                    // Remove battery settings when battery is not available. (e.g. TV)
+
+                    if (!mBatteryPresent) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.home_settings) {
+                    if (!updateHomeSettingTiles(tile)) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.user_settings) {
+                    if (!UserHandle.MU_ENABLED
+                            || !UserManager.supportsMultipleUsers()
+                            || Utils.isMonkeyRunning()) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.nfc_payment_settings) {
+                    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
+                        category.removeTile(n);
+                    } else {
+                        // Only show if NFC is on and we have the HCE feature
+                        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
+                        if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
+                                PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
+                            category.removeTile(n);
+                        }
+                    }
+                } else if (id == R.id.development_settings) {
+                    if (!showDev) {
+                        category.removeTile(n);
+                    }
+                } else if (id == R.id.account_add) {
+                    if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
+                        category.removeTile(n);
+                    }
+                }
+
+                if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
+                        && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
+                    category.removeTile(n);
+                }
+
+                n--;
+            }
+        }
+    }
+
+    private boolean updateHomeSettingTiles(DashboardTile tile) {
+        // 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)) {
+            return true;
+        }
+
+        try {
+            final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
+            getPackageManager().getHomeActivities(homeApps);
+            if (homeApps.size() < 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
+            Log.w(LOG_TAG, "Problem looking up home activity!", e);
+        }
+
+        sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
+        return true;
+    }
+
+    private void insertAccountsTiles(DashboardCategory target) {
+        String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
+        List<DashboardTile> dashboardTiles = new ArrayList<DashboardTile>(accountTypes.length);
+        for (String accountType : accountTypes) {
+            CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType);
+            if (label == null) {
+                continue;
+            }
+
+            Account[] accounts = AccountManager.get(this).getAccountsByType(accountType);
+            boolean skipToAccount = accounts.length == 1
+                    && !mAuthenticatorHelper.hasAccountPreferences(accountType);
+            DashboardTile accountTile = new DashboardTile();
+            accountTile.title = label;
+            if (accountTile.extras == null) {
+                accountTile.extras = new Bundle();
+            }
+            if (skipToAccount) {
+                accountTile.fragment = AccountSyncSettings.class.getName();
+                accountTile.fragmentArguments = new Bundle();
+                // Need this for the icon
+                accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
+                accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]);
+                accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
+                        accounts[0]);
+            } else {
+                accountTile.fragment = ManageAccountsSettings.class.getName();
+                accountTile.fragmentArguments = new Bundle();
+                accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
+                accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE,
+                        accountType);
+                accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
+                        label.toString());
+            }
+            dashboardTiles.add(accountTile);
+            mAuthenticatorHelper.preloadDrawableForType(this, accountType);
+        }
+
+        // Sort by label
+        Collections.sort(dashboardTiles, new Comparator<DashboardTile>() {
+            @Override
+            public int compare(DashboardTile t1, DashboardTile t2) {
+                return t1.title.toString().compareTo(t2.title.toString());
+            }
+        });
+        int index = 0;
+        for (DashboardTile tile : dashboardTiles) {
+            target.addTile(index, tile);
+            index++;
+        }
+        if (!mListeningToAccountUpdates) {
+            AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
+            mListeningToAccountUpdates = true;
+        }
+    }
+
     private void getMetaData() {
         try {
             ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 1ae0829..d743b6f 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -55,6 +55,8 @@
 import android.view.ViewGroup;
 import android.widget.ListView;
 import android.widget.TabWidget;
+import com.android.settings.dashboard.DashboardCategory;
+import com.android.settings.dashboard.DashboardTile;
 import com.android.settings.dashboard.Header;
 
 import java.io.IOException;
@@ -297,6 +299,66 @@
         return false;
     }
 
+    public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context,
+            DashboardCategory target, DashboardTile tile) {
+
+        Intent intent = tile.intent;
+        if (intent != null) {
+            // Find the activity that is in the system image
+            PackageManager pm = context.getPackageManager();
+            List<ResolveInfo> list = 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) {
+                    Drawable icon = null;
+                    String 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) {
+                            icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON));
+                            title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
+                            summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
+                        }
+                    } catch (NameNotFoundException e) {
+                        // Ignore
+                    } catch (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();
+                    }
+
+                    // Set icon, title and summary for the preference
+                    // TODO:
+                    //tile.icon = icon;
+                    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;
+                }
+            }
+        }
+
+        // Did not find a matching activity, so remove the preference
+        target.removeTile(tile);
+
+        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
new file mode 100644
index 0000000..2d08599
--- /dev/null
+++ b/src/com/android/settings/dashboard/DashboardCategory.java
@@ -0,0 +1,130 @@
+/*
+ * 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;
+
+    /**
+     * List of the category's children
+     */
+    public List<DashboardTile> tiles = new ArrayList<DashboardTile>();
+
+
+    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 <var>res</var> 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);
+        TextUtils.writeToParcel(title, dest, flags);
+
+        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();
+        title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
+
+        final int count = in.readInt();
+
+        for (int n = 0; n < count; n++) {
+            DashboardTile tile = DashboardTile.CREATOR.createFromParcel(in);
+            tiles.add(tile);
+        }
+    }
+}
diff --git a/src/com/android/settings/dashboard/DashboardTile.java b/src/com/android/settings/dashboard/DashboardTile.java
new file mode 100644
index 0000000..1f1d9c2
--- /dev/null
+++ b/src/com/android/settings/dashboard/DashboardTile.java
@@ -0,0 +1,177 @@
+/*
+ * 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.text.TextUtils;
+
+/**
+ * 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;
+
+    /**
+     * 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 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 <var>res</var> 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 <var>res</var> 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(fragment);
+        dest.writeBundle(fragmentArguments);
+        if (intent != null) {
+            dest.writeInt(1);
+            intent.writeToParcel(dest, flags);
+        } else {
+            dest.writeInt(0);
+        }
+        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();
+        fragment = in.readString();
+        fragmentArguments = in.readBundle();
+        if (in.readInt() != 0) {
+            intent = Intent.CREATOR.createFromParcel(in);
+        }
+        extras = in.readBundle();
+    }
+
+    DashboardTile(Parcel in) {
+        readFromParcel(in);
+    }
+
+    public static final Creator<DashboardTile> CREATOR = new Creator<DashboardTile>() {
+        public DashboardTile createFromParcel(Parcel source) {
+            return new DashboardTile(source);
+        }
+        public DashboardTile[] newArray(int size) {
+            return new DashboardTile[size];
+        }
+    };
+}