Update Dashboard layout again

- follow UX spec
- update also the Search Panels (suggestions / results) to
follow the same specs

See bug: #15384992 Setting Dashboard - padding updates

Change-Id: I3d27a3b3d9779644f8ea123990a0c7bed8d4ba74
This commit is contained in:
Fabrice Di Meglio
2014-06-19 20:16:20 -07:00
parent 8b2655cfbb
commit 47a25e7640
16 changed files with 208 additions and 61 deletions

View File

@@ -25,14 +25,18 @@ import com.android.settings.R;
public class DashboardContainerView extends ViewGroup {
private float mCellGapX;
private float mCellGapY;
private int mNumRows;
private int mNumColumns;
private float mCellGap;
public DashboardContainerView(Context context, AttributeSet attrs) {
super(context, attrs);
final Resources res = context.getResources();
mCellGap = res.getDimension(R.dimen.dashboard_cell_gap);
mCellGapX = res.getDimension(R.dimen.dashboard_cell_gap_x);
mCellGapY = res.getDimension(R.dimen.dashboard_cell_gap_y);
mNumColumns = res.getInteger(R.integer.dashboard_num_columns);
}
@@ -40,7 +44,7 @@ public class DashboardContainerView extends ViewGroup {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int availableWidth = (int) (width - getPaddingLeft() - getPaddingRight() -
(mNumColumns - 1) * mCellGap);
(mNumColumns - 1) * mCellGapX);
float cellWidth = (float) Math.ceil(((float) availableWidth) / mNumColumns);
final int N = getChildCount();
@@ -55,7 +59,7 @@ public class DashboardContainerView extends ViewGroup {
ViewGroup.LayoutParams lp = v.getLayoutParams();
int colSpan = v.getColumnSpan();
lp.width = (int) ((colSpan * cellWidth) + (colSpan - 1) * mCellGap);
lp.width = (int) ((colSpan * cellWidth) + (colSpan - 1) * mCellGapX);
// Measure the child
int newWidthSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
@@ -72,8 +76,8 @@ public class DashboardContainerView extends ViewGroup {
cursor += colSpan;
}
final int numRows = (int) Math.ceil((float) cursor / mNumColumns);
final int newHeight = (int) ((numRows * cellHeight) + ((numRows - 1) * mCellGap)) +
mNumRows = (int) Math.ceil((float) cursor / mNumColumns);
final int newHeight = (int) ((mNumRows * cellHeight) + ((mNumRows - 1) * mCellGapY)) +
getPaddingTop() + getPaddingBottom();
setMeasuredDimension(width, newHeight);
@@ -104,10 +108,14 @@ public class DashboardContainerView extends ViewGroup {
int row = cursor / mNumColumns;
if (row == mNumRows - 1) {
child.setDividerVisibility(false);
}
// Push the item to the next row if it can't fit on this one
if ((col + colSpan) > mNumColumns) {
x = getPaddingStart();
y += childHeight + mCellGap;
y += childHeight + mCellGapY;
row++;
}
@@ -124,10 +132,10 @@ public class DashboardContainerView extends ViewGroup {
// reach the end of the row
cursor += child.getColumnSpan();
if (cursor < (((row + 1) * mNumColumns))) {
x += childWidth + mCellGap;
x += childWidth + mCellGapX;
} else {
x = getPaddingStart();
y += childHeight + mCellGap;
y += childHeight + mCellGapY;
}
}
}

View File

@@ -44,7 +44,6 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
private static final String LOG_TAG = "DashboardSummary";
private LayoutInflater mLayoutInflater;
private ViewGroup mContainer;
private ViewGroup mDashboard;
private AuthenticatorHelper mAuthHelper;
private boolean mAccountListenerAdded;
@@ -69,7 +68,6 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
final Context context = getActivity();
mLayoutInflater = inflater;
mContainer = container;
final View rootView = inflater.inflate(R.layout.dashboard, container, false);
mDashboard = (ViewGroup) rootView.findViewById(R.id.dashboard_container);
@@ -98,7 +96,7 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
for (int n = 0; n < count; n++) {
DashboardCategory category = categories.get(n);
View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mContainer,
View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboard,
false);
TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);

View File

@@ -34,6 +34,7 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
private ImageView mImageView;
private TextView mTitleTextView;
private TextView mStatusTextView;
private View mDivider;
private int mColSpan = DEFAULT_COL_SPAN;
@@ -51,6 +52,7 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
mImageView = (ImageView) view.findViewById(R.id.icon);
mTitleTextView = (TextView) view.findViewById(R.id.title);
mStatusTextView = (TextView) view.findViewById(R.id.status);
mDivider = view.findViewById(R.id.tile_divider);
setOnClickListener(this);
setBackgroundResource(R.drawable.dashboard_tile_background);
@@ -73,6 +75,10 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
mTile = tile;
}
public void setDividerVisibility(boolean visible) {
mDivider.setVisibility(visible ? View.VISIBLE : View.GONE);
}
void setColumnSpan(int span) {
mColSpan = span;
}

View File

@@ -207,7 +207,8 @@ public class SearchResultsSummary extends Fragment {
});
mResultsListView.addHeaderView(
LayoutInflater.from(getActivity()).inflate(
R.layout.search_panel_results_header, mResultsListView, false));
R.layout.search_panel_results_header, mResultsListView, false),
null, false);
mSuggestionsListView = (ListView) view.findViewById(R.id.list_suggestions);
mSuggestionsListView.setAdapter(mSuggestionsAdapter);
@@ -231,7 +232,8 @@ public class SearchResultsSummary extends Fragment {
});
mSuggestionsListView.addHeaderView(
LayoutInflater.from(getActivity()).inflate(
R.layout.search_panel_suggestions_header, mSuggestionsListView, false));
R.layout.search_panel_suggestions_header, mSuggestionsListView, false),
null, false);
return view;
}