• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 
17 package com.android.internal.widget;
18 
19 import android.content.Context;
20 import android.graphics.Rect;
21 import android.util.AttributeSet;
22 import android.view.View;
23 import android.view.MotionEvent;
24 import android.widget.LinearLayout;
25 
26 
27 /**
28  * Like a normal linear layout, but supports dispatching all otherwise unhandled
29  * touch events to a particular descendant.  This is for the unlock screen, so
30  * that a wider range of touch events than just the lock pattern widget can kick
31  * off a lock pattern if the finger is eventually dragged into the bounds of the
32  * lock pattern view.
33  */
34 public class LinearLayoutWithDefaultTouchRecepient extends LinearLayout {
35 
36     private final Rect mTempRect = new Rect();
37     private View mDefaultTouchRecepient;
38 
LinearLayoutWithDefaultTouchRecepient(Context context)39     public LinearLayoutWithDefaultTouchRecepient(Context context) {
40         super(context);
41     }
42 
LinearLayoutWithDefaultTouchRecepient(Context context, AttributeSet attrs)43     public LinearLayoutWithDefaultTouchRecepient(Context context, AttributeSet attrs) {
44         super(context, attrs);
45     }
46 
setDefaultTouchRecepient(View defaultTouchRecepient)47     public void setDefaultTouchRecepient(View defaultTouchRecepient) {
48         mDefaultTouchRecepient = defaultTouchRecepient;
49     }
50 
51     @Override
dispatchTouchEvent(MotionEvent ev)52     public boolean dispatchTouchEvent(MotionEvent ev) {
53         if (mDefaultTouchRecepient == null) {
54             return super.dispatchTouchEvent(ev);
55         }
56 
57         if (super.dispatchTouchEvent(ev)) {
58             return true;
59         }
60         mTempRect.set(0, 0, 0, 0);
61         offsetRectIntoDescendantCoords(mDefaultTouchRecepient, mTempRect);
62         ev.setLocation(ev.getX() + mTempRect.left, ev.getY() + mTempRect.top);
63         return mDefaultTouchRecepient.dispatchTouchEvent(ev);
64     }
65 
66 }
67