DelegateViewHelper.java revision 12e0c5ac1b837d85c78221108b0d70417199bbbb
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.systemui.statusbar; 18 19import android.util.Slog; 20import android.view.MotionEvent; 21import android.view.Surface; 22import android.view.View; 23 24import com.android.systemui.R; 25 26public class DelegateViewHelper { 27 private View mDelegateView; 28 private View mSourceView; 29 private BaseStatusBar mBar; 30 private int[] mTempPoint = new int[2]; 31 private float[] mDownPoint = new float[2]; 32 private int mOrientation; 33 private float mTriggerThreshhold; 34 35 public DelegateViewHelper(View sourceView) { 36 mSourceView = sourceView; 37 if (mSourceView != null) { 38 mTriggerThreshhold = mSourceView.getContext().getResources() 39 .getDimension(R.dimen.navbar_search_up_threshhold); 40 } 41 } 42 43 public void setDelegateView(View view) { 44 mDelegateView = view; 45 } 46 47 public void setBar(BaseStatusBar phoneStatusBar) { 48 mBar = phoneStatusBar; 49 } 50 51 public void setOrientation(int orientation) { 52 mOrientation = orientation; 53 } 54 55 public boolean onInterceptTouchEvent(MotionEvent event) { 56 if (mBar.shouldDisableNavbarGestures()) { 57 return false; 58 } 59 switch (event.getAction()) { 60 case MotionEvent.ACTION_DOWN: 61 mDownPoint[0] = event.getX(); 62 mDownPoint[1] = event.getY(); 63 break; 64 } 65 if (mDelegateView != null) { 66 if (mDelegateView.getVisibility() != View.VISIBLE 67 && event.getAction() != MotionEvent.ACTION_CANCEL) { 68 final boolean isVertical = (mOrientation == Surface.ROTATION_90 69 || mOrientation == Surface.ROTATION_270); 70 final int historySize = event.getHistorySize(); 71 for (int k = 0; k < historySize + 1; k++) { 72 float x = k < historySize ? event.getHistoricalX(k) : event.getX(); 73 float y = k < historySize ? event.getHistoricalY(k) : event.getY(); 74 final float distance = isVertical ? (mDownPoint[0] - x) : (mDownPoint[1] - y); 75 if (distance > mTriggerThreshhold) { 76 mBar.showSearchPanel(); 77 break; 78 } 79 } 80 } 81 mSourceView.getLocationOnScreen(mTempPoint); 82 float deltaX = mTempPoint[0]; 83 float deltaY = mTempPoint[1]; 84 85 mDelegateView.getLocationOnScreen(mTempPoint); 86 deltaX -= mTempPoint[0]; 87 deltaY -= mTempPoint[1]; 88 89 event.offsetLocation(deltaX, deltaY); 90 mDelegateView.dispatchTouchEvent(event); 91 event.offsetLocation(-deltaX, -deltaY); 92 } 93 return false; 94 } 95}