189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal/* 289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * Copyright (C) 2017 The Android Open Source Project 389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * 489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * Licensed under the Apache License, Version 2.0 (the "License"); 589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * you may not use this file except in compliance with the License. 689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * You may obtain a copy of the License at 789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * 889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * http://www.apache.org/licenses/LICENSE-2.0 989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * 1089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * Unless required by applicable law or agreed to in writing, software 1189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * distributed under the License is distributed on an "AS IS" BASIS, 1289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * See the License for the specific language governing permissions and 1489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * limitations under the License. 1589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal */ 1689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 1789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalpackage com.android.launcher3.allapps; 1889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 1989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalimport android.content.Context; 2089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalimport android.util.AttributeSet; 2189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalimport android.view.MotionEvent; 2289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 2389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalimport com.android.launcher3.views.RecyclerViewFastScroller; 2489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 2589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal/** 2689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal * Extension of {@link RecyclerViewFastScroller} to be used in landscape layout. 2789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal */ 2889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyalpublic class LandscapeFastScroller extends RecyclerViewFastScroller { 2989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 3089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public LandscapeFastScroller(Context context) { 3189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal super(context); 3289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 3389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 3489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public LandscapeFastScroller(Context context, AttributeSet attrs) { 3589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal super(context, attrs); 3689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 3789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 3889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public LandscapeFastScroller(Context context, AttributeSet attrs, int defStyleAttr) { 3989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal super(context, attrs, defStyleAttr); 4089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 4189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 4289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal @Override 4389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public boolean handleTouchEvent(MotionEvent ev) { 4489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal // We handle our own touch event, no need to handle recycler view touch delegates. 4589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal return false; 4689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 4789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 4889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal @Override 4989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public boolean onTouchEvent(MotionEvent event) { 5089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal event.offsetLocation(0, -mRv.getPaddingTop()); 5189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal if (super.handleTouchEvent(event)) { 5289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal getParent().requestDisallowInterceptTouchEvent(true); 5389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 5489d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal event.offsetLocation(0, mRv.getPaddingTop()); 5589d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal return true; 5689d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 5789d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal 5889d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal @Override 5989d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal public boolean shouldBlockIntercept(int x, int y) { 6089d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal // If the user touched the scroll bar area, block swipe 6189d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal return x >= 0 && x < getWidth() && y >= 0 && y < getHeight(); 6289d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal } 6389d5c5a31bd6cf4caf815b680ec670896b91803dSunny Goyal} 64