From 21408b79cc7ade8f9ae01f46e92f118760bc058f Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Wed, 5 Apr 2023 08:11:09 -0700 Subject: Delete unused direct share expansion code ChooserGridAdapter#canExpandDirectShare was inlined everywhere and deleted; the code was trivially optimized and all methods that became unused has been deleted. A few IDE-suggested trivial changes along the way. Fix: 277015101 Test: manual testing Change-Id: I88462fde08842a348a5e4039a641a224476fa13e --- .../android/intentresolver/ChooserActivity.java | 91 +--------------------- .../intentresolver/grid/ChooserGridAdapter.java | 71 +++-------------- .../intentresolver/grid/DirectShareViewHolder.java | 87 +-------------------- 3 files changed, 15 insertions(+), 234 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index dc9ba5ee..75ee0648 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -57,7 +57,6 @@ import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.os.storage.StorageManager; -import android.provider.DeviceConfig; import android.service.chooser.ChooserTarget; import android.util.Log; import android.util.Slog; @@ -88,7 +87,6 @@ import com.android.intentresolver.contentpreview.HeadlineGeneratorImpl; import com.android.intentresolver.flags.FeatureFlagRepository; import com.android.intentresolver.flags.FeatureFlagRepositoryFactory; import com.android.intentresolver.grid.ChooserGridAdapter; -import com.android.intentresolver.grid.DirectShareViewHolder; import com.android.intentresolver.model.AbstractResolverComparator; import com.android.intentresolver.model.AppPredictionServiceResolverComparator; import com.android.intentresolver.model.ResolverRankerServiceResolverComparator; @@ -96,7 +94,6 @@ import com.android.intentresolver.shortcuts.AppPredictorFactory; import com.android.intentresolver.shortcuts.ShortcutLoader; import com.android.intentresolver.widget.ResolverDrawerLayout; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import com.android.internal.content.PackageMonitor; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -141,19 +138,11 @@ public class ChooserActivity extends ResolverActivity implements private static final String PREF_NUM_SHEET_EXPANSIONS = "pref_num_sheet_expansions"; - private static final String CHIP_LABEL_METADATA_KEY = "android.service.chooser.chip_label"; - private static final String CHIP_ICON_METADATA_KEY = "android.service.chooser.chip_icon"; - private static final boolean DEBUG = true; public static final String LAUNCH_LOCATION_DIRECT_SHARE = "direct_share"; private static final String SHORTCUT_TARGET = "shortcut_target"; - private static final String PLURALS_COUNT = "count"; - private static final String PLURALS_FILE_NAME = "file_name"; - - private static final String IMAGE_EDITOR_SHARED_ELEMENT = "screenshot_preview_image"; - // TODO: these data structures are for one-time use in shuttling data from where they're // populated in `ShortcutToChooserTargetConverter` to where they're consumed in // `ShortcutSelectionLogic` which packs the appropriate elements into the final `TargetInfo`. @@ -180,18 +169,6 @@ public class ChooserActivity extends ResolverActivity implements @Retention(RetentionPolicy.SOURCE) public @interface ShareTargetType {} - public static final float DIRECT_SHARE_EXPANSION_RATE = 0.78f; - - private static final int DEFAULT_SALT_EXPIRATION_DAYS = 7; - private final int mMaxHashSaltDays = DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI, - SystemUiDeviceConfigFlags.HASH_SALT_MAX_DAYS, - DEFAULT_SALT_EXPIRATION_DAYS); - - private static final int URI_PERMISSION_INTENT_FLAGS = Intent.FLAG_GRANT_READ_URI_PERMISSION - | Intent.FLAG_GRANT_WRITE_URI_PERMISSION - | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION - | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION; - private ChooserIntegratedDeviceComponents mIntegratedDeviceComponents; /* TODO: this is `nullable` because we have to defer the assignment til onCreate(). We make the @@ -329,11 +306,6 @@ public class ChooserActivity extends ResolverActivity implements if (mResolverDrawerLayout != null) { mResolverDrawerLayout.addOnLayoutChangeListener(this::handleLayoutChange); - // expand/shrink direct share 4 -> 8 viewgroup - if (mChooserRequest.isSendActionTarget()) { - mResolverDrawerLayout.setOnScrollChangeListener(this::handleScroll); - } - mResolverDrawerLayout.setOnCollapsedChangedListener( new ResolverDrawerLayout.OnCollapsedChangedListener() { @@ -1240,34 +1212,6 @@ public class ChooserActivity extends ResolverActivity implements mProfileView.setOnClickListener(ChooserActivity.this::onProfileClick); ChooserActivity.this.updateProfileViewButton(); } - - @Override - public int getValidTargetCount() { - return mChooserMultiProfilePagerAdapter - .getActiveListAdapter() - .getSelectableServiceTargetCount(); - } - - @Override - public void updateDirectShareExpansion(DirectShareViewHolder directShareGroup) { - RecyclerView activeAdapterView = - mChooserMultiProfilePagerAdapter.getActiveAdapterView(); - if (mResolverDrawerLayout.isCollapsed()) { - directShareGroup.collapse(activeAdapterView); - } else { - directShareGroup.expand(activeAdapterView); - } - } - - @Override - public void handleScrollToExpandDirectShare( - DirectShareViewHolder directShareGroup, int y, int oldy) { - directShareGroup.handleScroll( - mChooserMultiProfilePagerAdapter.getActiveAdapterView(), - y, - oldy, - mMaxTargetsPerRow); - } }, chooserListAdapter, shouldShowContentPreview(), @@ -1381,12 +1325,6 @@ public class ChooserActivity extends ResolverActivity implements }); } - private void handleScroll(View view, int x, int y, int oldx, int oldy) { - if (mChooserMultiProfilePagerAdapter.getCurrentRootAdapter() != null) { - mChooserMultiProfilePagerAdapter.getCurrentRootAdapter().handleScroll(view, y, oldy); - } - } - /* * Need to dynamically adjust how many icons can fit per row before we add them, * which also means setting the correct offset to initially show the content @@ -1455,9 +1393,7 @@ public class ChooserActivity extends ResolverActivity implements private int calculateDrawerOffset( int top, int bottom, RecyclerView recyclerView, ChooserGridAdapter gridAdapter) { - final int bottomInset = mSystemWindowInsets != null - ? mSystemWindowInsets.bottom : 0; - int offset = bottomInset; + int offset = mSystemWindowInsets != null ? mSystemWindowInsets.bottom : 0; int rowsToShow = gridAdapter.getSystemRowCount() + gridAdapter.getProfileRowCount() + gridAdapter.getServiceTargetRowCount() @@ -1487,7 +1423,6 @@ public class ChooserActivity extends ResolverActivity implements } if (recyclerView.getVisibility() == View.VISIBLE) { - int directShareHeight = 0; rowsToShow = Math.min(4, rowsToShow); boolean shouldShowExtraRow = shouldShowExtraRow(rowsToShow); mLastNumberOfChildren = recyclerView.getChildCount(); @@ -1503,29 +1438,8 @@ public class ChooserActivity extends ResolverActivity implements if (shouldShowExtraRow) { offset += height; } - - if (gridAdapter.getTargetType( - recyclerView.getChildAdapterPosition(child)) - == ChooserListAdapter.TARGET_SERVICE) { - directShareHeight = height; - } rowsToShow--; } - - boolean isPortrait = getResources().getConfiguration().orientation - == Configuration.ORIENTATION_PORTRAIT; - boolean isExpandable = isPortrait && !isInMultiWindowMode() - && gridAdapter.canExpandDirectShare(); - if (directShareHeight != 0 && shouldShowContentPreview() && isExpandable) { - // make sure to leave room for direct share 4->8 expansion, if enabled - int requiredExpansionHeight = - (int) (directShareHeight / DIRECT_SHARE_EXPANSION_RATE); - int topInset = mSystemWindowInsets != null ? mSystemWindowInsets.top : 0; - int minHeight = bottom - top - mResolverDrawerLayout.getAlwaysShowHeight() - - requiredExpansionHeight - topInset - bottomInset; - - offset = Math.min(offset, minHeight); - } } else { ViewGroup currentEmptyStateView = getActiveEmptyStateView(); if (currentEmptyStateView.getVisibility() == View.VISIBLE) { @@ -1825,9 +1739,6 @@ public class ChooserActivity extends ResolverActivity implements @Override protected void onProfileTabSelected() { - ChooserGridAdapter currentRootAdapter = - mChooserMultiProfilePagerAdapter.getCurrentRootAdapter(); - currentRootAdapter.updateDirectShareExpansion(); // This fixes an edge case where after performing a variety of gestures, vertical scrolling // ends up disabled. That's because at some point the old tab's vertical scrolling is // disabled and the new tab's is enabled. For context, see b/159997845 diff --git a/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java b/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java index 96f8c4d1..e6f70d4f 100644 --- a/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java +++ b/java/src/com/android/intentresolver/grid/ChooserGridAdapter.java @@ -89,26 +89,6 @@ public final class ChooserGridAdapter extends RecyclerView.Adapter mRows; - private int mCellCountPerRow; + private final int mCellCountPerRow; - private boolean mHideDirectShareExpansion = false; private int mDirectShareMinHeight = 0; private int mDirectShareCurrHeight = 0; - private int mDirectShareMaxHeight = 0; private final boolean[] mCellVisibility; - private final Supplier mDeferredTargetCountSupplier; - public DirectShareViewHolder( ViewGroup parent, List rows, int cellCountPerRow, - int viewType, - Supplier deferredTargetCountSupplier) { + int viewType) { super(rows.size() * cellCountPerRow, parent, viewType); this.mParent = parent; @@ -61,7 +51,6 @@ public class DirectShareViewHolder extends ItemGroupViewHolder { this.mCellCountPerRow = cellCountPerRow; this.mCellVisibility = new boolean[rows.size() * cellCountPerRow]; Arrays.fill(mCellVisibility, true); - this.mDeferredTargetCountSupplier = deferredTargetCountSupplier; } public ViewGroup addView(int index, View v) { @@ -92,7 +81,6 @@ public class DirectShareViewHolder extends ItemGroupViewHolder { mDirectShareMinHeight = getRow(0).getMeasuredHeight(); mDirectShareCurrHeight = (mDirectShareCurrHeight > 0) ? mDirectShareCurrHeight : mDirectShareMinHeight; - mDirectShareMaxHeight = 2 * mDirectShareMinHeight; } public int getMeasuredRowHeight() { @@ -123,75 +111,4 @@ public class DirectShareViewHolder extends ItemGroupViewHolder { fadeAnim.start(); } } - - public void handleScroll(RecyclerView view, int y, int oldy, int maxTargetsPerRow) { - // only exit early if fully collapsed, otherwise onListRebuilt() with shifting - // targets can lock us into an expanded mode - boolean notExpanded = mDirectShareCurrHeight == mDirectShareMinHeight; - if (notExpanded) { - if (mHideDirectShareExpansion) { - return; - } - - // only expand if we have more than maxTargetsPerRow, and delay that decision - // until they start to scroll - final int validTargets = this.mDeferredTargetCountSupplier.get(); - if (validTargets <= maxTargetsPerRow) { - mHideDirectShareExpansion = true; - return; - } - } - - int yDiff = (int) ((oldy - y) * ChooserActivity.DIRECT_SHARE_EXPANSION_RATE); - - int prevHeight = mDirectShareCurrHeight; - int newHeight = Math.min(prevHeight + yDiff, mDirectShareMaxHeight); - newHeight = Math.max(newHeight, mDirectShareMinHeight); - yDiff = newHeight - prevHeight; - - updateDirectShareRowHeight(view, yDiff, newHeight); - } - - public void expand(RecyclerView view) { - updateDirectShareRowHeight( - view, mDirectShareMaxHeight - mDirectShareCurrHeight, mDirectShareMaxHeight); - } - - public void collapse(RecyclerView view) { - updateDirectShareRowHeight( - view, mDirectShareMinHeight - mDirectShareCurrHeight, mDirectShareMinHeight); - } - - private void updateDirectShareRowHeight(RecyclerView view, int yDiff, int newHeight) { - if (view == null || view.getChildCount() == 0 || yDiff == 0) { - return; - } - - // locate the item to expand, and offset the rows below that one - boolean foundExpansion = false; - for (int i = 0; i < view.getChildCount(); i++) { - View child = view.getChildAt(i); - - if (foundExpansion) { - child.offsetTopAndBottom(yDiff); - } else { - if (child.getTag() != null && child.getTag() instanceof DirectShareViewHolder) { - int widthSpec = MeasureSpec.makeMeasureSpec(child.getWidth(), - MeasureSpec.EXACTLY); - int heightSpec = MeasureSpec.makeMeasureSpec(newHeight, - MeasureSpec.EXACTLY); - child.measure(widthSpec, heightSpec); - child.getLayoutParams().height = child.getMeasuredHeight(); - child.layout(child.getLeft(), child.getTop(), child.getRight(), - child.getTop() + child.getMeasuredHeight()); - - foundExpansion = true; - } - } - } - - if (foundExpansion) { - mDirectShareCurrHeight = newHeight; - } - } } -- cgit v1.2.3-59-g8ed1b