Loading core/java/com/android/internal/app/ChooserActivity.java +80 −41 Original line number Diff line number Diff line Loading @@ -877,10 +877,17 @@ public class ChooserActivity extends ResolverActivity { } mChooserRowAdapter = new ChooserRowAdapter(mChooserListAdapter); mChooserRowAdapter.registerDataSetObserver(new OffsetDataSetObserver(adapterView)); adapterView.setAdapter(mChooserRowAdapter); if (listView != null) { listView.setItemsCanFocus(true); listView.addOnLayoutChangeListener( (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { if (mChooserRowAdapter.calculateMaxTargetsPerRow(right - left)) { adapterView.setAdapter(mChooserRowAdapter); } }); } adapterView.setAdapter(mChooserRowAdapter); } @Override Loading Loading @@ -2063,7 +2070,7 @@ public class ChooserActivity extends ResolverActivity { class ChooserRowAdapter extends BaseAdapter { private ChooserListAdapter mChooserListAdapter; private final LayoutInflater mLayoutInflater; private int mAnimationCount = 0; private int mCalculatedMaxTargetsPerRow = MAX_TARGETS_PER_ROW_LANDSCAPE; private DirectShareViewHolder mDirectShareViewHolder; Loading @@ -2071,6 +2078,9 @@ public class ChooserActivity extends ResolverActivity { private static final int VIEW_TYPE_NORMAL = 1; private static final int VIEW_TYPE_CONTENT_PREVIEW = 2; private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4; private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8; public ChooserRowAdapter(ChooserListAdapter wrappedAdapter) { mChooserListAdapter = wrappedAdapter; mLayoutInflater = LayoutInflater.from(ChooserActivity.this); Loading @@ -2090,9 +2100,40 @@ public class ChooserActivity extends ResolverActivity { }); } /** * Determine how many targets can comfortably fit in a single row. * * @param width The new row width to use for recalculation * @return true if the numbers of targets per row has changed */ public boolean calculateMaxTargetsPerRow(int width) { int targetWidth = getResources().getDimensionPixelSize( R.dimen.chooser_target_width); if (targetWidth == 0 || 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; return true; } return false; } private int getMaxTargetsPerRow() { // this will soon hold logic for portrait/landscape return 4; int maxTargets = MAX_TARGETS_PER_ROW_PORTRAIT; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { maxTargets = MAX_TARGETS_PER_ROW_LANDSCAPE; } return Math.min(maxTargets, mCalculatedMaxTargetsPerRow); } @Override Loading Loading @@ -2159,9 +2200,7 @@ public class ChooserActivity extends ResolverActivity { holder = (RowViewHolder) convertView.getTag(); } bindViewHolder(position, holder, viewType == VIEW_TYPE_DIRECT_SHARE ? ChooserListAdapter.MAX_SERVICE_TARGETS : getMaxTargetsPerRow()); bindViewHolder(position, holder); return holder.getViewGroup(); } Loading Loading @@ -2278,7 +2317,7 @@ public class ChooserActivity extends ResolverActivity { } } void bindViewHolder(int rowPosition, RowViewHolder holder, int columnCount) { void bindViewHolder(int rowPosition, RowViewHolder holder) { final int start = getFirstRowPosition(rowPosition); final int startType = mChooserListAdapter.getPositionTargetType(start); Loading @@ -2295,6 +2334,7 @@ public class ChooserActivity extends ResolverActivity { setVertPadding(row, 0, 0); } int columnCount = holder.getColumnCount(); int end = start + columnCount - 1; while (mChooserListAdapter.getPositionTargetType(end) != startType && end >= start) { end--; Loading Loading @@ -2329,36 +2369,15 @@ public class ChooserActivity extends ResolverActivity { for (int i = 0; i < columnCount; i++) { final View v = holder.getView(i); if (start + i <= end) { setCellVisibility(holder, i, View.VISIBLE); holder.setViewVisibility(i, View.VISIBLE); holder.setItemIndex(i, start + i); mChooserListAdapter.bindView(holder.getItemIndex(i), v); } else { setCellVisibility(holder, i, View.INVISIBLE); holder.setViewVisibility(i, View.INVISIBLE); } } } private void setCellVisibility(RowViewHolder holder, int i, int visibility) { final View v = holder.getView(i); if (visibility == View.VISIBLE) { holder.setViewVisibility(i, true); v.setVisibility(visibility); v.setAlpha(1.0f); } else if (visibility == View.INVISIBLE && holder.getViewVisibility(i)) { holder.setViewVisibility(i, false); ValueAnimator fadeAnim = ObjectAnimator.ofFloat(v, "alpha", 1.0f, 0f); fadeAnim.setDuration(NO_DIRECT_SHARE_ANIM_IN_MILLIS); fadeAnim.setInterpolator(new AccelerateInterpolator(1.0f)); fadeAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { v.setVisibility(View.INVISIBLE); } }); fadeAnim.start(); } } private void setVertPadding(ViewGroup row, int top, int bottom) { row.setPadding(row.getPaddingLeft(), top, row.getPaddingRight(), bottom); } Loading Loading @@ -2394,13 +2413,11 @@ public class ChooserActivity extends ResolverActivity { protected int mMeasuredRowHeight; private int[] mItemIndices; protected final View[] mCells; private final boolean[] mCellVisibility; private final int mColumnCount; RowViewHolder(int cellCount) { this.mCells = new View[cellCount]; this.mItemIndices = new int[cellCount]; this.mCellVisibility = new boolean[cellCount]; this.mColumnCount = cellCount; } Loading @@ -2410,18 +2427,12 @@ public class ChooserActivity extends ResolverActivity { abstract ViewGroup getRow(int index); abstract void setViewVisibility(int i, int visibility); public int getColumnCount() { return mColumnCount; } public void setViewVisibility(int index, boolean visibility) { mCellVisibility[index] = visibility; } public boolean getViewVisibility(int index) { return mCellVisibility[index]; } public void measure() { final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); getViewGroup().measure(spec, spec); Loading Loading @@ -2477,6 +2488,10 @@ public class ChooserActivity extends ResolverActivity { return mRow; } public void setViewVisibility(int i, int visibility) { getView(i).setVisibility(visibility); } } class DirectShareViewHolder extends RowViewHolder { Loading @@ -2489,12 +2504,15 @@ public class ChooserActivity extends ResolverActivity { private int mDirectShareCurrHeight = 0; private int mDirectShareMaxHeight = 0; private final boolean[] mCellVisibility; DirectShareViewHolder(ViewGroup parent, List<ViewGroup> rows, int cellCountPerRow) { super(rows.size() * cellCountPerRow); this.mParent = parent; this.mRows = rows; this.mCellCountPerRow = cellCountPerRow; this.mCellVisibility = new boolean[rows.size() * cellCountPerRow]; } public ViewGroup addView(int index, View v) { Loading Loading @@ -2533,6 +2551,27 @@ public class ChooserActivity extends ResolverActivity { return mDirectShareCurrHeight; } public void setViewVisibility(int i, int visibility) { final View v = getView(i); if (visibility == View.VISIBLE) { mCellVisibility[i] = true; v.setVisibility(visibility); v.setAlpha(1.0f); } else if (visibility == View.INVISIBLE && mCellVisibility[i]) { mCellVisibility[i] = false; ValueAnimator fadeAnim = ObjectAnimator.ofFloat(v, "alpha", 1.0f, 0f); fadeAnim.setDuration(NO_DIRECT_SHARE_ANIM_IN_MILLIS); fadeAnim.setInterpolator(new AccelerateInterpolator(1.0f)); fadeAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { v.setVisibility(View.INVISIBLE); } }); fadeAnim.start(); } } public void handleScroll(AbsListView view, int y, int oldy, int maxTargetsPerRow) { // only expand if we have more than 4 targets, and delay that decision until // they start to scroll Loading core/res/res/layout/chooser_row.xml +2 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,8 @@ android:layout_width="match_parent" android:layout_height="100dp" android:gravity="start|top" android:paddingStart="@dimen/chooser_grid_padding" android:paddingEnd="@dimen/chooser_grid_padding"> android:paddingStart="@dimen/chooser_edge_margin_normal" android:paddingEnd="@dimen/chooser_edge_margin_normal"> <TextView android:id="@+id/chooser_row_text_option" android:layout_width="match_parent" Loading core/res/res/layout/resolve_grid_item.xml +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="76dp" android:layout_width="@dimen/chooser_target_width" android:layout_height="wrap_content" android:minHeight="100dp" android:gravity="center" Loading core/res/res/values/dimens.xml +1 −1 Original line number Diff line number Diff line Loading @@ -578,7 +578,6 @@ <dimen name="default_magnifier_horizontal_offset">0dp</dimen> <item type="dimen" format="float" name="default_magnifier_zoom">1.25</item> <dimen name="chooser_grid_padding">0dp</dimen> <!-- Spacing around the background change frome service to non-service --> <dimen name="chooser_service_spacing">8dp</dimen> Loading Loading @@ -725,4 +724,5 @@ <dimen name="chooser_preview_width">-1px</dimen> <dimen name="resolver_icon_size">42dp</dimen> <dimen name="resolver_badge_size">18dp</dimen> <dimen name="chooser_target_width">76dp</dimen> </resources> core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -2762,6 +2762,7 @@ <java-symbol type="string" name="chooser_no_direct_share_targets" /> <java-symbol type="drawable" name="chooser_row_layer_list" /> <java-symbol type="dimen" name="chooser_view_spacing" /> <java-symbol type="dimen" name="chooser_target_width" /> <java-symbol type="dimen" name="chooser_edge_margin_thin" /> <java-symbol type="dimen" name="chooser_edge_margin_normal" /> <java-symbol type="dimen" name="chooser_preview_image_font_size"/> Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +80 −41 Original line number Diff line number Diff line Loading @@ -877,10 +877,17 @@ public class ChooserActivity extends ResolverActivity { } mChooserRowAdapter = new ChooserRowAdapter(mChooserListAdapter); mChooserRowAdapter.registerDataSetObserver(new OffsetDataSetObserver(adapterView)); adapterView.setAdapter(mChooserRowAdapter); if (listView != null) { listView.setItemsCanFocus(true); listView.addOnLayoutChangeListener( (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { if (mChooserRowAdapter.calculateMaxTargetsPerRow(right - left)) { adapterView.setAdapter(mChooserRowAdapter); } }); } adapterView.setAdapter(mChooserRowAdapter); } @Override Loading Loading @@ -2063,7 +2070,7 @@ public class ChooserActivity extends ResolverActivity { class ChooserRowAdapter extends BaseAdapter { private ChooserListAdapter mChooserListAdapter; private final LayoutInflater mLayoutInflater; private int mAnimationCount = 0; private int mCalculatedMaxTargetsPerRow = MAX_TARGETS_PER_ROW_LANDSCAPE; private DirectShareViewHolder mDirectShareViewHolder; Loading @@ -2071,6 +2078,9 @@ public class ChooserActivity extends ResolverActivity { private static final int VIEW_TYPE_NORMAL = 1; private static final int VIEW_TYPE_CONTENT_PREVIEW = 2; private static final int MAX_TARGETS_PER_ROW_PORTRAIT = 4; private static final int MAX_TARGETS_PER_ROW_LANDSCAPE = 8; public ChooserRowAdapter(ChooserListAdapter wrappedAdapter) { mChooserListAdapter = wrappedAdapter; mLayoutInflater = LayoutInflater.from(ChooserActivity.this); Loading @@ -2090,9 +2100,40 @@ public class ChooserActivity extends ResolverActivity { }); } /** * Determine how many targets can comfortably fit in a single row. * * @param width The new row width to use for recalculation * @return true if the numbers of targets per row has changed */ public boolean calculateMaxTargetsPerRow(int width) { int targetWidth = getResources().getDimensionPixelSize( R.dimen.chooser_target_width); if (targetWidth == 0 || 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; return true; } return false; } private int getMaxTargetsPerRow() { // this will soon hold logic for portrait/landscape return 4; int maxTargets = MAX_TARGETS_PER_ROW_PORTRAIT; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { maxTargets = MAX_TARGETS_PER_ROW_LANDSCAPE; } return Math.min(maxTargets, mCalculatedMaxTargetsPerRow); } @Override Loading Loading @@ -2159,9 +2200,7 @@ public class ChooserActivity extends ResolverActivity { holder = (RowViewHolder) convertView.getTag(); } bindViewHolder(position, holder, viewType == VIEW_TYPE_DIRECT_SHARE ? ChooserListAdapter.MAX_SERVICE_TARGETS : getMaxTargetsPerRow()); bindViewHolder(position, holder); return holder.getViewGroup(); } Loading Loading @@ -2278,7 +2317,7 @@ public class ChooserActivity extends ResolverActivity { } } void bindViewHolder(int rowPosition, RowViewHolder holder, int columnCount) { void bindViewHolder(int rowPosition, RowViewHolder holder) { final int start = getFirstRowPosition(rowPosition); final int startType = mChooserListAdapter.getPositionTargetType(start); Loading @@ -2295,6 +2334,7 @@ public class ChooserActivity extends ResolverActivity { setVertPadding(row, 0, 0); } int columnCount = holder.getColumnCount(); int end = start + columnCount - 1; while (mChooserListAdapter.getPositionTargetType(end) != startType && end >= start) { end--; Loading Loading @@ -2329,36 +2369,15 @@ public class ChooserActivity extends ResolverActivity { for (int i = 0; i < columnCount; i++) { final View v = holder.getView(i); if (start + i <= end) { setCellVisibility(holder, i, View.VISIBLE); holder.setViewVisibility(i, View.VISIBLE); holder.setItemIndex(i, start + i); mChooserListAdapter.bindView(holder.getItemIndex(i), v); } else { setCellVisibility(holder, i, View.INVISIBLE); holder.setViewVisibility(i, View.INVISIBLE); } } } private void setCellVisibility(RowViewHolder holder, int i, int visibility) { final View v = holder.getView(i); if (visibility == View.VISIBLE) { holder.setViewVisibility(i, true); v.setVisibility(visibility); v.setAlpha(1.0f); } else if (visibility == View.INVISIBLE && holder.getViewVisibility(i)) { holder.setViewVisibility(i, false); ValueAnimator fadeAnim = ObjectAnimator.ofFloat(v, "alpha", 1.0f, 0f); fadeAnim.setDuration(NO_DIRECT_SHARE_ANIM_IN_MILLIS); fadeAnim.setInterpolator(new AccelerateInterpolator(1.0f)); fadeAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { v.setVisibility(View.INVISIBLE); } }); fadeAnim.start(); } } private void setVertPadding(ViewGroup row, int top, int bottom) { row.setPadding(row.getPaddingLeft(), top, row.getPaddingRight(), bottom); } Loading Loading @@ -2394,13 +2413,11 @@ public class ChooserActivity extends ResolverActivity { protected int mMeasuredRowHeight; private int[] mItemIndices; protected final View[] mCells; private final boolean[] mCellVisibility; private final int mColumnCount; RowViewHolder(int cellCount) { this.mCells = new View[cellCount]; this.mItemIndices = new int[cellCount]; this.mCellVisibility = new boolean[cellCount]; this.mColumnCount = cellCount; } Loading @@ -2410,18 +2427,12 @@ public class ChooserActivity extends ResolverActivity { abstract ViewGroup getRow(int index); abstract void setViewVisibility(int i, int visibility); public int getColumnCount() { return mColumnCount; } public void setViewVisibility(int index, boolean visibility) { mCellVisibility[index] = visibility; } public boolean getViewVisibility(int index) { return mCellVisibility[index]; } public void measure() { final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); getViewGroup().measure(spec, spec); Loading Loading @@ -2477,6 +2488,10 @@ public class ChooserActivity extends ResolverActivity { return mRow; } public void setViewVisibility(int i, int visibility) { getView(i).setVisibility(visibility); } } class DirectShareViewHolder extends RowViewHolder { Loading @@ -2489,12 +2504,15 @@ public class ChooserActivity extends ResolverActivity { private int mDirectShareCurrHeight = 0; private int mDirectShareMaxHeight = 0; private final boolean[] mCellVisibility; DirectShareViewHolder(ViewGroup parent, List<ViewGroup> rows, int cellCountPerRow) { super(rows.size() * cellCountPerRow); this.mParent = parent; this.mRows = rows; this.mCellCountPerRow = cellCountPerRow; this.mCellVisibility = new boolean[rows.size() * cellCountPerRow]; } public ViewGroup addView(int index, View v) { Loading Loading @@ -2533,6 +2551,27 @@ public class ChooserActivity extends ResolverActivity { return mDirectShareCurrHeight; } public void setViewVisibility(int i, int visibility) { final View v = getView(i); if (visibility == View.VISIBLE) { mCellVisibility[i] = true; v.setVisibility(visibility); v.setAlpha(1.0f); } else if (visibility == View.INVISIBLE && mCellVisibility[i]) { mCellVisibility[i] = false; ValueAnimator fadeAnim = ObjectAnimator.ofFloat(v, "alpha", 1.0f, 0f); fadeAnim.setDuration(NO_DIRECT_SHARE_ANIM_IN_MILLIS); fadeAnim.setInterpolator(new AccelerateInterpolator(1.0f)); fadeAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { v.setVisibility(View.INVISIBLE); } }); fadeAnim.start(); } } public void handleScroll(AbsListView view, int y, int oldy, int maxTargetsPerRow) { // only expand if we have more than 4 targets, and delay that decision until // they start to scroll Loading
core/res/res/layout/chooser_row.xml +2 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,8 @@ android:layout_width="match_parent" android:layout_height="100dp" android:gravity="start|top" android:paddingStart="@dimen/chooser_grid_padding" android:paddingEnd="@dimen/chooser_grid_padding"> android:paddingStart="@dimen/chooser_edge_margin_normal" android:paddingEnd="@dimen/chooser_edge_margin_normal"> <TextView android:id="@+id/chooser_row_text_option" android:layout_width="match_parent" Loading
core/res/res/layout/resolve_grid_item.xml +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="76dp" android:layout_width="@dimen/chooser_target_width" android:layout_height="wrap_content" android:minHeight="100dp" android:gravity="center" Loading
core/res/res/values/dimens.xml +1 −1 Original line number Diff line number Diff line Loading @@ -578,7 +578,6 @@ <dimen name="default_magnifier_horizontal_offset">0dp</dimen> <item type="dimen" format="float" name="default_magnifier_zoom">1.25</item> <dimen name="chooser_grid_padding">0dp</dimen> <!-- Spacing around the background change frome service to non-service --> <dimen name="chooser_service_spacing">8dp</dimen> Loading Loading @@ -725,4 +724,5 @@ <dimen name="chooser_preview_width">-1px</dimen> <dimen name="resolver_icon_size">42dp</dimen> <dimen name="resolver_badge_size">18dp</dimen> <dimen name="chooser_target_width">76dp</dimen> </resources>
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -2762,6 +2762,7 @@ <java-symbol type="string" name="chooser_no_direct_share_targets" /> <java-symbol type="drawable" name="chooser_row_layer_list" /> <java-symbol type="dimen" name="chooser_view_spacing" /> <java-symbol type="dimen" name="chooser_target_width" /> <java-symbol type="dimen" name="chooser_edge_margin_thin" /> <java-symbol type="dimen" name="chooser_edge_margin_normal" /> <java-symbol type="dimen" name="chooser_preview_image_font_size"/> Loading