Settings new dashboard - part 2

Introduce the new Dashboard (a grid like presentation of
Settings top categories) per UX specification.

- the Dashboard is composed of "categories" and in each of them
you have "tiles"
- implement a new layout for showing top categories
(DashboardContainerView). This layout basically acts like a
grid
- depending on the device configuration make the grid with 1
column in portrait / 2 colums in landscape (phones) OR 2 columns
in portrait and 3 in landscape (tablets)
- take care of Accounts adding and removing (as it changes the
number of tiles to show)

Also remove all the old code related to Headers

Change-Id: Ie29944132c1b4c3f7b073d5a7d4453b8f5ec19a7
This commit is contained in:
Fabrice Di Meglio
2014-04-24 14:48:48 -07:00
parent 1102f76e58
commit 769630c895
20 changed files with 661 additions and 924 deletions

View File

@@ -16,35 +16,166 @@
package com.android.settings.dashboard;
import android.app.ListFragment;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
import android.app.Fragment;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.accounts.AuthenticatorHelper;
import com.android.settings.accounts.ManageAccountsSettings;
public class DashboardSummary extends ListFragment {
import java.util.List;
public class DashboardSummary extends Fragment implements OnAccountsUpdateListener {
private static final String LOG_TAG = "DashboardSummary";
private LayoutInflater mLayoutInflater;
private ViewGroup mContainer;
private ViewGroup mDashboard;
private AuthenticatorHelper mAuthHelper;
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 Context context = getActivity();
rebuildUI(context);
} break;
}
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.dashboard, container, false);
final Context context = getActivity();
ListView listView = (ListView) view.findViewById(android.R.id.list);
mLayoutInflater = inflater;
mContainer = container;
ListAdapter adapter = ((SettingsActivity) getActivity()).getHeaderAdapter();
listView.setAdapter(adapter);
final View rootView = inflater.inflate(R.layout.dashboard, container, false);
mDashboard = (ViewGroup) rootView.findViewById(R.id.dashboard_container);
return view;
mAuthHelper = ((SettingsActivity) context).getAuthenticatorHelper();
rebuildUI(getActivity());
return rootView;
}
private void rebuildUI(Context context) {
final Resources res = getResources();
mDashboard.removeAllViews();
List<DashboardCategory> categories =
((SettingsActivity) context).getDashboardCategories();
final int count = categories.size();
for (int n = 0; n < count; n++) {
DashboardCategory category = categories.get(n);
View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mContainer,
false);
TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);
categoryLabel.setText(category.getTitle(res));
ViewGroup categoryContent =
(ViewGroup) categoryView.findViewById(R.id.category_content);
final int tilesCount = category.getTilesCount();
for (int i = 0; i < tilesCount; i++) {
DashboardTile tile = category.getTile(i);
DashboardTileView tileView = new DashboardTileView(context);
updateTileView(context, res, tile, tileView.getImageView(),
tileView.getTitleTextView(), tileView.getStatusTextView());
tileView.setTile(tile);
categoryContent.addView(tileView);
}
// Add the category
mDashboard.addView(categoryView);
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
((SettingsActivity) getActivity()).onListItemClick(l, v, position, id);
public void onStart() {
super.onStart();
AccountManager.get(getActivity()).addOnAccountsUpdatedListener(this, null, false);
}
@Override
public void onPause() {
super.onPause();
AccountManager.get(getActivity()).removeOnAccountsUpdatedListener(this);
}
private void updateTileView(Context context, Resources res, DashboardTile tile,
ImageView tileIcon, TextView tileTextView, TextView statusTextView) {
if (tile.extras != null
&& tile.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
String accType = tile.extras.getString(ManageAccountsSettings.KEY_ACCOUNT_TYPE);
Drawable drawable = mAuthHelper.getDrawableForType(context, accType);
tileIcon.setImageDrawable(drawable);
} else {
if (tile.iconRes > 0) {
tileIcon.setImageResource(tile.iconRes);
} else {
tileIcon.setImageDrawable(null);
}
}
if (tileIcon != null) {
if (tile.iconRes > 0) {
tileIcon.setBackgroundResource(R.color.temporary_background_icon);
} else {
tileIcon.setBackground(null);
}
}
tileTextView.setText(tile.getTitle(res));
CharSequence summary = tile.getSummary(res);
if (!TextUtils.isEmpty(summary)) {
statusTextView.setVisibility(View.VISIBLE);
statusTextView.setText(summary);
} else {
statusTextView.setVisibility(View.GONE);
}
}
private void rebuildCategories() {
if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
}
}
@Override
public void onAccountsUpdated(Account[] accounts) {
final SettingsActivity sa = (SettingsActivity) getActivity();
sa.setNeedToRebuildCategories(true);
rebuildCategories();
}
}