Merge "Only allow scroll in one direction at a time" into rvc-dev am: 5f7043db84
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11691616 Change-Id: I33ca2bb04b4ec2c9a6369de4a88b0219b6b985bd
This commit is contained in:
@@ -151,6 +151,13 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
|||||||
mOnProfileSelectedListener.onProfileSelected(position);
|
mOnProfileSelectedListener.onProfileSelected(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
if (mOnProfileSelectedListener != null) {
|
||||||
|
mOnProfileSelectedListener.onProfilePageStateChanged(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
viewPager.setAdapter(this);
|
viewPager.setAdapter(this);
|
||||||
viewPager.setCurrentItem(mCurrentPage);
|
viewPager.setCurrentItem(mCurrentPage);
|
||||||
@@ -606,6 +613,17 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
|||||||
* {@link #PROFILE_WORK} if the work profile was selected.
|
* {@link #PROFILE_WORK} if the work profile was selected.
|
||||||
*/
|
*/
|
||||||
void onProfileSelected(int profileIndex);
|
void onProfileSelected(int profileIndex);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when the scroll state changes. Useful for discovering when the user begins
|
||||||
|
* dragging, when the pager is automatically settling to the current page, or when it is
|
||||||
|
* fully stopped/idle.
|
||||||
|
* @param state {@link ViewPager#SCROLL_STATE_IDLE}, {@link ViewPager#SCROLL_STATE_DRAGGING}
|
||||||
|
* or {@link ViewPager#SCROLL_STATE_SETTLING}
|
||||||
|
* @see ViewPager.OnPageChangeListener#onPageScrollStateChanged
|
||||||
|
*/
|
||||||
|
void onProfilePageStateChanged(int state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ import com.android.internal.util.FrameworkStatsLog;
|
|||||||
import com.android.internal.widget.GridLayoutManager;
|
import com.android.internal.widget.GridLayoutManager;
|
||||||
import com.android.internal.widget.RecyclerView;
|
import com.android.internal.widget.RecyclerView;
|
||||||
import com.android.internal.widget.ResolverDrawerLayout;
|
import com.android.internal.widget.ResolverDrawerLayout;
|
||||||
|
import com.android.internal.widget.ViewPager;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
|
|
||||||
@@ -205,6 +206,10 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
public static final int SELECTION_TYPE_STANDARD = 3;
|
public static final int SELECTION_TYPE_STANDARD = 3;
|
||||||
public static final int SELECTION_TYPE_COPY = 4;
|
public static final int SELECTION_TYPE_COPY = 4;
|
||||||
|
|
||||||
|
private static final int SCROLL_STATUS_IDLE = 0;
|
||||||
|
private static final int SCROLL_STATUS_SCROLLING_VERTICAL = 1;
|
||||||
|
private static final int SCROLL_STATUS_SCROLLING_HORIZONTAL = 2;
|
||||||
|
|
||||||
// statsd logger wrapper
|
// statsd logger wrapper
|
||||||
protected ChooserActivityLogger mChooserActivityLogger;
|
protected ChooserActivityLogger mChooserActivityLogger;
|
||||||
|
|
||||||
@@ -294,6 +299,7 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
protected MetricsLogger mMetricsLogger;
|
protected MetricsLogger mMetricsLogger;
|
||||||
|
|
||||||
private ContentPreviewCoordinator mPreviewCoord;
|
private ContentPreviewCoordinator mPreviewCoord;
|
||||||
|
private int mScrollStatus = SCROLL_STATUS_IDLE;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected ChooserMultiProfilePagerAdapter mChooserMultiProfilePagerAdapter;
|
protected ChooserMultiProfilePagerAdapter mChooserMultiProfilePagerAdapter;
|
||||||
@@ -2823,10 +2829,20 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
final float defaultElevation = elevatedView.getElevation();
|
final float defaultElevation = elevatedView.getElevation();
|
||||||
final float chooserHeaderScrollElevation =
|
final float chooserHeaderScrollElevation =
|
||||||
getResources().getDimensionPixelSize(R.dimen.chooser_header_scroll_elevation);
|
getResources().getDimensionPixelSize(R.dimen.chooser_header_scroll_elevation);
|
||||||
|
|
||||||
mChooserMultiProfilePagerAdapter.getActiveAdapterView().addOnScrollListener(
|
mChooserMultiProfilePagerAdapter.getActiveAdapterView().addOnScrollListener(
|
||||||
new RecyclerView.OnScrollListener() {
|
new RecyclerView.OnScrollListener() {
|
||||||
public void onScrollStateChanged(RecyclerView view, int scrollState) {
|
public void onScrollStateChanged(RecyclerView view, int scrollState) {
|
||||||
|
if (scrollState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
|
if (mScrollStatus == SCROLL_STATUS_SCROLLING_VERTICAL) {
|
||||||
|
mScrollStatus = SCROLL_STATUS_IDLE;
|
||||||
|
setHorizontalScrollingEnabled(true);
|
||||||
|
}
|
||||||
|
} else if (scrollState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||||
|
if (mScrollStatus == SCROLL_STATUS_IDLE) {
|
||||||
|
mScrollStatus = SCROLL_STATUS_SCROLLING_VERTICAL;
|
||||||
|
setHorizontalScrollingEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onScrolled(RecyclerView view, int dx, int dy) {
|
public void onScrolled(RecyclerView view, int dx, int dy) {
|
||||||
@@ -3042,6 +3058,33 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
return super.onApplyWindowInsets(v, insets);
|
return super.onApplyWindowInsets(v, insets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setHorizontalScrollingEnabled(boolean enabled) {
|
||||||
|
ResolverViewPager viewPager = findViewById(R.id.profile_pager);
|
||||||
|
viewPager.setSwipingEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setVerticalScrollEnabled(boolean enabled) {
|
||||||
|
ChooserGridLayoutManager layoutManager =
|
||||||
|
(ChooserGridLayoutManager) mChooserMultiProfilePagerAdapter.getActiveAdapterView()
|
||||||
|
.getLayoutManager();
|
||||||
|
layoutManager.setVerticalScrollEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onHorizontalSwipeStateChanged(int state) {
|
||||||
|
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
|
||||||
|
if (mScrollStatus == SCROLL_STATUS_IDLE) {
|
||||||
|
mScrollStatus = SCROLL_STATUS_SCROLLING_HORIZONTAL;
|
||||||
|
setVerticalScrollEnabled(false);
|
||||||
|
}
|
||||||
|
} else if (state == ViewPager.SCROLL_STATE_IDLE) {
|
||||||
|
if (mScrollStatus == SCROLL_STATUS_SCROLLING_VERTICAL) {
|
||||||
|
mScrollStatus = SCROLL_STATUS_IDLE;
|
||||||
|
setVerticalScrollEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for all types of items and targets in ShareSheet.
|
* Adapter for all types of items and targets in ShareSheet.
|
||||||
* Note that ranked sections like Direct Share - while appearing grid-like - are handled on the
|
* Note that ranked sections like Direct Share - while appearing grid-like - are handled on the
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import com.android.internal.widget.RecyclerView;
|
|||||||
*/
|
*/
|
||||||
public class ChooserGridLayoutManager extends GridLayoutManager {
|
public class ChooserGridLayoutManager extends GridLayoutManager {
|
||||||
|
|
||||||
|
private boolean mVerticalScrollEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor used when layout manager is set in XML by RecyclerView attribute
|
* Constructor used when layout manager is set in XML by RecyclerView attribute
|
||||||
* "layoutManager". If spanCount is not specified in the XML, it defaults to a
|
* "layoutManager". If spanCount is not specified in the XML, it defaults to a
|
||||||
@@ -67,4 +69,13 @@ public class ChooserGridLayoutManager extends GridLayoutManager {
|
|||||||
// Do not count the footer view in the official count
|
// Do not count the footer view in the official count
|
||||||
return super.getRowCountForAccessibility(recycler, state) - 1;
|
return super.getRowCountForAccessibility(recycler, state) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setVerticalScrollEnabled(boolean verticalScrollEnabled) {
|
||||||
|
mVerticalScrollEnabled = verticalScrollEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canScrollVertically() {
|
||||||
|
return mVerticalScrollEnabled && super.canScrollVertically();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1653,10 +1653,18 @@ public class ResolverActivity extends Activity implements
|
|||||||
viewPager.setVisibility(View.VISIBLE);
|
viewPager.setVisibility(View.VISIBLE);
|
||||||
tabHost.setCurrentTab(mMultiProfilePagerAdapter.getCurrentPage());
|
tabHost.setCurrentTab(mMultiProfilePagerAdapter.getCurrentPage());
|
||||||
mMultiProfilePagerAdapter.setOnProfileSelectedListener(
|
mMultiProfilePagerAdapter.setOnProfileSelectedListener(
|
||||||
index -> {
|
new AbstractMultiProfilePagerAdapter.OnProfileSelectedListener() {
|
||||||
tabHost.setCurrentTab(index);
|
@Override
|
||||||
resetButtonBar();
|
public void onProfileSelected(int index) {
|
||||||
resetCheckedItem();
|
tabHost.setCurrentTab(index);
|
||||||
|
resetButtonBar();
|
||||||
|
resetCheckedItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProfilePageStateChanged(int state) {
|
||||||
|
onHorizontalSwipeStateChanged(state);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mMultiProfilePagerAdapter.setOnSwitchOnWorkSelectedListener(
|
mMultiProfilePagerAdapter.setOnSwitchOnWorkSelectedListener(
|
||||||
() -> {
|
() -> {
|
||||||
@@ -1668,6 +1676,8 @@ public class ResolverActivity extends Activity implements
|
|||||||
findViewById(R.id.resolver_tab_divider).setVisibility(View.VISIBLE);
|
findViewById(R.id.resolver_tab_divider).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onHorizontalSwipeStateChanged(int state) {}
|
||||||
|
|
||||||
private void maybeHideDivider() {
|
private void maybeHideDivider() {
|
||||||
if (!isIntentPicker()) {
|
if (!isIntentPicker()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.internal.app;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.internal.widget.ViewPager;
|
import com.android.internal.widget.ViewPager;
|
||||||
@@ -30,6 +31,8 @@ import com.android.internal.widget.ViewPager;
|
|||||||
*/
|
*/
|
||||||
public class ResolverViewPager extends ViewPager {
|
public class ResolverViewPager extends ViewPager {
|
||||||
|
|
||||||
|
private boolean mSwipingEnabled = true;
|
||||||
|
|
||||||
public ResolverViewPager(Context context) {
|
public ResolverViewPager(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@@ -70,4 +73,13 @@ public class ResolverViewPager extends ViewPager {
|
|||||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSwipingEnabled(boolean swipingEnabled) {
|
||||||
|
mSwipingEnabled = swipingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
|
return mSwipingEnabled && super.onInterceptTouchEvent(ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user