OSDN Git Service

d1f2f41983f992afd90160e4172ad7956944c1f1
[android-x86/packages-apps-Camera2.git] / src / com / android / camera / ui / MainActivityLayout.java
1 /*
2  * Copyright (C) 2013 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.camera.ui;
18
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.MotionEvent;
22 import android.view.View;
23 import android.widget.FrameLayout;
24
25 import com.android.camera.debug.Log;
26
27 public class MainActivityLayout extends FrameLayout {
28
29     private MotionEvent mDown;
30     private final Log.Tag TAG = new Log.Tag("MainActivityLayout");
31     private boolean mRequestToInterceptTouchEvents = false;
32     private View mTouchReceiver = null;
33
34     public MainActivityLayout(Context context, AttributeSet attrs) {
35         super(context, attrs);
36     }
37
38     @Override
39     public boolean onInterceptTouchEvent(MotionEvent ev) {
40         if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
41             mDown = MotionEvent.obtain(ev);
42             mTouchReceiver = null;
43             mRequestToInterceptTouchEvents = false;
44             return false;
45         } else if (mRequestToInterceptTouchEvents) {
46             mRequestToInterceptTouchEvents = false;
47             onTouchEvent(mDown);
48             return true;
49         } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
50             // Do not intercept touch once child is in zoom mode
51             return false;
52         }
53         return false;
54     }
55
56     @Override
57     public boolean onTouchEvent(MotionEvent ev) {
58         if (mTouchReceiver != null) {
59             mTouchReceiver.setVisibility(VISIBLE);
60             return mTouchReceiver.dispatchTouchEvent(ev);
61         }
62         return false;
63     }
64
65     public void redirectTouchEventsTo(View touchReceiver) {
66         if (touchReceiver == null) {
67             Log.e(TAG, "Cannot redirect touch to a null receiver.");
68             return;
69         }
70         mTouchReceiver = touchReceiver;
71         mRequestToInterceptTouchEvents = true;
72     }
73 }