summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/allapps/FloatingHeaderView.java
diff options
context:
space:
mode:
authorMario Bertschler <bmario@google.com>2017-12-06 13:03:54 -0800
committerMario Bertschler <bmario@google.com>2017-12-07 08:54:36 -0800
commitea0eb4bb4bd7979c3bfbd0c03bee640da29d0c4a (patch)
tree41866d832882ba63c4bff9eb1f7a0ed3c434b3bb /src/com/android/launcher3/allapps/FloatingHeaderView.java
parent92731d48d20fceb99a25b70fa72a867699d09f74 (diff)
downloadandroid_packages_apps_Trebuchet-ea0eb4bb4bd7979c3bfbd0c03bee640da29d0c4a.tar.gz
android_packages_apps_Trebuchet-ea0eb4bb4bd7979c3bfbd0c03bee640da29d0c4a.tar.bz2
android_packages_apps_Trebuchet-ea0eb4bb4bd7979c3bfbd0c03bee640da29d0c4a.zip
Forwarding touch events from floating header to recyclerview.
Additionally adds little sidepadding to the tabs buttons and fixes yPos calculations for the scrollbar. Bug: 69966700 Change-Id: I9d236ce7a782090f5d17931839f24b65b4ce7019
Diffstat (limited to 'src/com/android/launcher3/allapps/FloatingHeaderView.java')
-rw-r--r--src/com/android/launcher3/allapps/FloatingHeaderView.java42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/com/android/launcher3/allapps/FloatingHeaderView.java b/src/com/android/launcher3/allapps/FloatingHeaderView.java
index 39e681886..4f1a0d568 100644
--- a/src/com/android/launcher3/allapps/FloatingHeaderView.java
+++ b/src/com/android/launcher3/allapps/FloatingHeaderView.java
@@ -19,11 +19,13 @@ package com.android.launcher3.allapps;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Point;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
@@ -37,6 +39,7 @@ public class FloatingHeaderView extends RelativeLayout implements
private final Rect mClip = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
private final ValueAnimator mAnimator = ValueAnimator.ofInt(0, 0);
+ private final Point mTempOffset = new Point();
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
@@ -76,6 +79,7 @@ public class FloatingHeaderView extends RelativeLayout implements
private View mDivider;
private AllAppsRecyclerView mMainRV;
private AllAppsRecyclerView mWorkRV;
+ private ViewGroup mParent;
private boolean mTopOnlyMode;
private boolean mHeaderHidden;
private int mMaxTranslation;
@@ -83,7 +87,8 @@ public class FloatingHeaderView extends RelativeLayout implements
private int mTranslationY;
private int mMainScrolledY;
private int mWorkScrolledY;
- private boolean mMainRVActive;
+ private boolean mMainRVActive = true;
+ private boolean mForwardToRecyclerView;
public FloatingHeaderView(@NonNull Context context) {
this(context, null);
@@ -109,6 +114,7 @@ public class FloatingHeaderView extends RelativeLayout implements
mMaxTranslation = predictionRowHeight;
mMainRV = setupRV(mMainRV, personalRV);
mWorkRV = setupRV(mWorkRV, workRV);
+ mParent = (ViewGroup) getRV().getParent();
setMainActive(true);
setupDivider();
}
@@ -228,6 +234,40 @@ public class FloatingHeaderView extends RelativeLayout implements
apply();
}
+ private AllAppsRecyclerView getRV() {
+ return mMainRVActive ? mMainRV : mWorkRV;
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ calcOffset(mTempOffset);
+ ev.offsetLocation(mTempOffset.x, mTempOffset.y);
+ mForwardToRecyclerView = getRV().onInterceptTouchEvent(ev);
+ ev.offsetLocation(-mTempOffset.x, -mTempOffset.y);
+ return mForwardToRecyclerView || super.onInterceptTouchEvent(ev);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (mForwardToRecyclerView) {
+ // take this view's and parent view's (view pager) location into account
+ calcOffset(mTempOffset);
+ event.offsetLocation(mTempOffset.x, mTempOffset.y);
+ try {
+ return getRV().onTouchEvent(event);
+ } finally {
+ event.offsetLocation(-mTempOffset.x, -mTempOffset.y);
+ }
+ } else {
+ return super.onTouchEvent(event);
+ }
+ }
+
+ private void calcOffset(Point p) {
+ p.x = getLeft() - getRV().getLeft() - mParent.getLeft();
+ p.y = getTop() - getRV().getTop() - mParent.getTop();
+ }
+
}