blob: d1f2f41983f992afd90160e4172ad7956944c1f1 [file] [log] [blame]
Doris Liu1c94b7d2013-11-09 19:13:44 -08001/*
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
17package com.android.camera.ui;
18
19import android.content.Context;
Doris Liu1c94b7d2013-11-09 19:13:44 -080020import android.util.AttributeSet;
21import android.view.MotionEvent;
Doris Liuf55f3c42013-11-20 00:24:46 -080022import android.view.View;
Doris Liu1c94b7d2013-11-09 19:13:44 -080023import android.widget.FrameLayout;
24
Angus Kong2bca2102014-03-11 16:27:30 -070025import com.android.camera.debug.Log;
Erin Dahlgren77295162014-01-29 17:29:18 -080026
Doris Liuf55f3c42013-11-20 00:24:46 -080027public class MainActivityLayout extends FrameLayout {
Doris Liu1c94b7d2013-11-09 19:13:44 -080028
Doris Liu1c94b7d2013-11-09 19:13:44 -080029 private MotionEvent mDown;
Angus Kong2bca2102014-03-11 16:27:30 -070030 private final Log.Tag TAG = new Log.Tag("MainActivityLayout");
Doris Liuf55f3c42013-11-20 00:24:46 -080031 private boolean mRequestToInterceptTouchEvents = false;
32 private View mTouchReceiver = null;
Doris Liu1c94b7d2013-11-09 19:13:44 -080033
34 public MainActivityLayout(Context context, AttributeSet attrs) {
35 super(context, attrs);
Sascha Haeberling8793eff2014-01-15 16:33:59 -080036 }
37
Doris Liu1c94b7d2013-11-09 19:13:44 -080038 @Override
39 public boolean onInterceptTouchEvent(MotionEvent ev) {
40 if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
Doris Liu1c94b7d2013-11-09 19:13:44 -080041 mDown = MotionEvent.obtain(ev);
Doris Liuf55f3c42013-11-20 00:24:46 -080042 mTouchReceiver = null;
43 mRequestToInterceptTouchEvents = false;
Doris Liu1c94b7d2013-11-09 19:13:44 -080044 return false;
Doris Liuf55f3c42013-11-20 00:24:46 -080045 } else if (mRequestToInterceptTouchEvents) {
46 mRequestToInterceptTouchEvents = false;
47 onTouchEvent(mDown);
48 return true;
Doris Liu1c94b7d2013-11-09 19:13:44 -080049 } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
50 // Do not intercept touch once child is in zoom mode
Doris Liu1c94b7d2013-11-09 19:13:44 -080051 return false;
Doris Liu1c94b7d2013-11-09 19:13:44 -080052 }
53 return false;
54 }
55
56 @Override
57 public boolean onTouchEvent(MotionEvent ev) {
Doris Liuf55f3c42013-11-20 00:24:46 -080058 if (mTouchReceiver != null) {
59 mTouchReceiver.setVisibility(VISIBLE);
Angus Kong166e36f2013-12-03 08:54:42 -080060 return mTouchReceiver.dispatchTouchEvent(ev);
Doris Liuf55f3c42013-11-20 00:24:46 -080061 }
62 return false;
Doris Liu1c94b7d2013-11-09 19:13:44 -080063 }
64
Doris Liuf55f3c42013-11-20 00:24:46 -080065 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 }
Doris Liu1c94b7d2013-11-09 19:13:44 -080073}