From ab986b5fcfad6c90ed14a7dca5ccaf5090e37234 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Wed, 10 Apr 2019 10:14:32 -0400 Subject: Sharesheet - Align spacing with spec Various fixes including: correct fonts, colors, drag handle size, as well as allowing more space for chooser grid items and text Bug: 129980360 Test: Visual inspection Change-Id: I10f78ef9c12b3444360e4ab50f7bd5900f2967f3 --- .../com/android/internal/app/ChooserActivity.java | 64 +++++++++------------- core/res/res/layout/chooser_grid.xml | 7 ++- core/res/res/layout/chooser_grid_preview_text.xml | 17 +++--- core/res/res/layout/chooser_row.xml | 4 +- core/res/res/layout/resolve_grid_item.xml | 6 +- core/res/res/values/dimens.xml | 2 +- 6 files changed, 43 insertions(+), 57 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index b51f8080569f..bfdbf4c1ec23 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -101,9 +101,7 @@ import android.view.animation.DecelerateInterpolator; import android.widget.AbsListView; import android.widget.BaseAdapter; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.Space; import android.widget.TextView; import android.widget.Toast; @@ -1604,7 +1602,7 @@ public class ChooserActivity extends ResolverActivity { private final Intent mFillInIntent; private final int mFillInFlags; private final float mModifiedScore; - private boolean mIsSuspended; + private boolean mIsSuspended = false; SelectableTargetInfo(DisplayResolveInfo sourceInfo, ChooserTarget chooserTarget, float modifiedScore) { @@ -1619,6 +1617,8 @@ public class ChooserActivity extends ResolverActivity { final PackageManager pm = getPackageManager(); mBadgeIcon = pm.getApplicationIcon(ai.applicationInfo); mBadgeContentDescription = pm.getApplicationLabel(ai.applicationInfo); + mIsSuspended = + (ai.applicationInfo.flags & ApplicationInfo.FLAG_SUSPENDED) != 0; } } } @@ -1633,8 +1633,6 @@ public class ChooserActivity extends ResolverActivity { mFillInIntent = null; mFillInFlags = 0; - ApplicationInfo ai = sourceInfo.getResolveInfo().activityInfo.applicationInfo; - mIsSuspended = (ai.flags & ApplicationInfo.FLAG_SUSPENDED) != 0; } private SelectableTargetInfo(SelectableTargetInfo other, Intent fillInIntent, int flags) { @@ -1836,7 +1834,7 @@ public class ChooserActivity extends ResolverActivity { return; } - if (mChooserRowAdapter.calculateMaxTargetsPerRow(right - left) + if (mChooserRowAdapter.calculateChooserTargetWidth(right - left) || mAdapterView.getAdapter() == null) { mAdapterView.setAdapter(mChooserRowAdapter); @@ -2325,9 +2323,9 @@ public class ChooserActivity extends ResolverActivity { class ChooserRowAdapter extends BaseAdapter { private ChooserListAdapter mChooserListAdapter; private final LayoutInflater mLayoutInflater; - private int mCalculatedMaxTargetsPerRow = MAX_TARGETS_PER_ROW_LANDSCAPE; private DirectShareViewHolder mDirectShareViewHolder; + private int mChooserTargetWidth = 0; private static final int VIEW_TYPE_DIRECT_SHARE = 0; private static final int VIEW_TYPE_NORMAL = 1; @@ -2356,25 +2354,23 @@ public class ChooserActivity extends ResolverActivity { } /** - * Determine how many targets can comfortably fit in a single row. + * Calculate the chooser target width to maximize space per item * * @param width The new row width to use for recalculation - * @return true if the numbers of targets per row has changed + * @return true if the view width has changed */ - public boolean calculateMaxTargetsPerRow(int width) { - int targetWidth = getResources().getDimensionPixelSize( + public boolean calculateChooserTargetWidth(int width) { + int targetMinWidth = getResources().getDimensionPixelSize( R.dimen.chooser_target_width); - if (targetWidth == 0 || width == 0) { + if (width == 0) { return false; } - int margin = getResources().getDimensionPixelSize( - R.dimen.chooser_edge_margin_normal); - - int newCount = (width - margin * 2) / targetWidth; - if (newCount != mCalculatedMaxTargetsPerRow) { - mCalculatedMaxTargetsPerRow = newCount; + int targetWidth = width / getMaxTargetsPerRow(); + int newWidth = Math.max(targetWidth, targetMinWidth); + if (newWidth != mChooserTargetWidth) { + mChooserTargetWidth = newWidth; return true; } @@ -2388,7 +2384,7 @@ public class ChooserActivity extends ResolverActivity { maxTargets = MAX_TARGETS_PER_ROW_LANDSCAPE; } - return Math.min(maxTargets, mCalculatedMaxTargetsPerRow); + return maxTargets; } @Override @@ -2498,6 +2494,8 @@ public class ChooserActivity extends ResolverActivity { private RowViewHolder loadViewsIntoRow(RowViewHolder holder) { final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + final int exactSpec = MeasureSpec.makeMeasureSpec(mChooserTargetWidth, + MeasureSpec.EXACTLY); int columnCount = holder.getColumnCount(); final boolean isDirectShare = holder instanceof DirectShareViewHolder; @@ -2533,20 +2531,20 @@ public class ChooserActivity extends ResolverActivity { } // Force height to be a given so we don't have visual disruption during scaling. - v.measure(spec, spec); - setViewHeight(v, v.getMeasuredHeight()); + v.measure(exactSpec, spec); + setViewBounds(v, v.getMeasuredWidth(), v.getMeasuredHeight()); } final ViewGroup viewGroup = holder.getViewGroup(); // Pre-measure and fix height so we can scale later. holder.measure(); - setViewHeight(viewGroup, holder.getMeasuredRowHeight()); + setViewBounds(viewGroup, LayoutParams.MATCH_PARENT, holder.getMeasuredRowHeight()); if (isDirectShare) { DirectShareViewHolder dsvh = (DirectShareViewHolder) holder; - setViewHeight(dsvh.getRow(0), dsvh.getMinRowHeight()); - setViewHeight(dsvh.getRow(1), dsvh.getMinRowHeight()); + setViewBounds(dsvh.getRow(0), LayoutParams.MATCH_PARENT, dsvh.getMinRowHeight()); + setViewBounds(dsvh.getRow(1), LayoutParams.MATCH_PARENT, dsvh.getMinRowHeight()); } viewGroup.setTag(holder); @@ -2554,13 +2552,14 @@ public class ChooserActivity extends ResolverActivity { return holder; } - private void setViewHeight(View view, int heightPx) { + private void setViewBounds(View view, int widthPx, int heightPx) { LayoutParams lp = view.getLayoutParams(); if (lp == null) { - lp = new LayoutParams(LayoutParams.MATCH_PARENT, heightPx); + lp = new LayoutParams(widthPx, heightPx); view.setLayoutParams(lp); } else { lp.height = heightPx; + lp.width = widthPx; } } @@ -2712,11 +2711,6 @@ public class ChooserActivity extends ResolverActivity { return mMeasuredRowHeight; } - protected void addSpacer(ViewGroup row) { - row.addView(new Space(ChooserActivity.this), - new LinearLayout.LayoutParams(0, 0, 1)); - } - public void setItemIndex(int itemIndex, int listIndex) { mItemIndices[itemIndex] = listIndex; } @@ -2756,10 +2750,6 @@ public class ChooserActivity extends ResolverActivity { mRow.addView(v); mCells[index] = v; - if (index != (mCells.length - 1)) { - addSpacer(mRow); - } - return mRow; } @@ -2794,10 +2784,6 @@ public class ChooserActivity extends ResolverActivity { row.addView(v); mCells[index] = v; - if (index % mCellCountPerRow != (mCellCountPerRow - 1)) { - addSpacer(row); - } - return row; } diff --git a/core/res/res/layout/chooser_grid.xml b/core/res/res/layout/chooser_grid.xml index 1f8041741b46..68c62a6ebf3e 100644 --- a/core/res/res/layout/chooser_grid.xml +++ b/core/res/res/layout/chooser_grid.xml @@ -32,11 +32,11 @@ @@ -61,8 +61,9 @@ android:layout_width="wrap_content" android:textAppearance="?attr/textAppearanceMedium" android:textSize="20sp" + android:textColor="?attr/textColorPrimary" android:gravity="center" - android:paddingTop="@dimen/chooser_view_spacing" + android:paddingTop="@dimen/chooser_edge_margin_thin" android:paddingBottom="@dimen/chooser_view_spacing" android:paddingLeft="24dp" android:paddingRight="24dp" diff --git a/core/res/res/layout/chooser_grid_preview_text.xml b/core/res/res/layout/chooser_grid_preview_text.xml index 6abf57a0f9f2..45287002ebf7 100644 --- a/core/res/res/layout/chooser_grid_preview_text.xml +++ b/core/res/res/layout/chooser_grid_preview_text.xml @@ -43,15 +43,16 @@ android:layout_gravity="center_vertical" android:ellipsize="end" android:gravity="start|top" - android:paddingRight="24dp" + android:paddingRight="@dimen/chooser_view_spacing" android:maxLines="2"/> -