Merge "Sharesheet - Align spacing with spec" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-12 13:01:47 +00:00
committed by Android (Google) Code Review
6 changed files with 43 additions and 57 deletions

View File

@@ -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;
}