blob: e074a8080fa4cb8d76e567c66f8ad05167079f96 [file] [log] [blame]
Jim Millere898ac52012-04-06 17:10:57 -07001/*
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
Jim Miller354619c2012-04-27 17:33:44 -070019import android.util.Slog;
Jim Millere898ac52012-04-06 17:10:57 -070020import android.view.MotionEvent;
21import android.view.Surface;
Jim Millere898ac52012-04-06 17:10:57 -070022import android.view.View;
23
Jim Miller354619c2012-04-27 17:33:44 -070024import com.android.systemui.R;
25
Jim Millere898ac52012-04-06 17:10:57 -070026public class DelegateViewHelper {
Jim Millere898ac52012-04-06 17:10:57 -070027 private View mDelegateView;
28 private View mSourceView;
29 private BaseStatusBar mBar;
30 private int[] mTempPoint = new int[2];
Jim Miller354619c2012-04-27 17:33:44 -070031 private float[] mDownPoint = new float[2];
Jim Millere898ac52012-04-06 17:10:57 -070032 private int mOrientation;
Jim Miller354619c2012-04-27 17:33:44 -070033 private float mTriggerThreshhold;
Jim Millere898ac52012-04-06 17:10:57 -070034
35 public DelegateViewHelper(View sourceView) {
36 mSourceView = sourceView;
Jim Miller354619c2012-04-27 17:33:44 -070037 if (mSourceView != null) {
38 mTriggerThreshhold = mSourceView.getContext().getResources()
39 .getDimension(R.dimen.navbar_search_up_threshhold);
40 }
Jim Millere898ac52012-04-06 17:10:57 -070041 }
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 switch (event.getAction()) {
57 case MotionEvent.ACTION_DOWN:
Jim Miller354619c2012-04-27 17:33:44 -070058 mDownPoint[0] = event.getX();
59 mDownPoint[1] = event.getY();
Jim Millere898ac52012-04-06 17:10:57 -070060 break;
61 }
Jim Miller354619c2012-04-27 17:33:44 -070062 if (mDelegateView != null) {
63 if (mDelegateView.getVisibility() != View.VISIBLE && event.getAction() != MotionEvent.ACTION_CANCEL) {
Jim Millere898ac52012-04-06 17:10:57 -070064 final boolean isVertical = (mOrientation == Surface.ROTATION_90
65 || mOrientation == Surface.ROTATION_270);
Jim Miller354619c2012-04-27 17:33:44 -070066 final int historySize = event.getHistorySize();
67 for (int k = 0; k < historySize + 1; k++) {
68 float x = k < historySize ? event.getHistoricalX(k) : event.getX();
69 float y = k < historySize ? event.getHistoricalY(k) : event.getY();
70 final float distance = isVertical ? (mDownPoint[0] - x) : (mDownPoint[1] - y);
71 if (distance > mTriggerThreshhold) {
Jim Millere898ac52012-04-06 17:10:57 -070072 mBar.showSearchPanel();
Jim Miller354619c2012-04-27 17:33:44 -070073 break;
Jim Millere898ac52012-04-06 17:10:57 -070074 }
75 }
76 }
Jim Millere898ac52012-04-06 17:10:57 -070077 mSourceView.getLocationOnScreen(mTempPoint);
78 float deltaX = mTempPoint[0];
79 float deltaY = mTempPoint[1];
80
81 mDelegateView.getLocationOnScreen(mTempPoint);
82 deltaX -= mTempPoint[0];
83 deltaY -= mTempPoint[1];
84
85 event.offsetLocation(deltaX, deltaY);
86 mDelegateView.dispatchTouchEvent(event);
87 event.offsetLocation(-deltaX, -deltaY);
88 }
89 return false;
90 }
91}