Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 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; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 20 | import android.util.AttributeSet; |
| 21 | import android.view.MotionEvent; |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 22 | import android.view.View; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 23 | import android.widget.FrameLayout; |
| 24 | |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 25 | import com.android.camera.debug.Log; |
Erin Dahlgren | 7729516 | 2014-01-29 17:29:18 -0800 | [diff] [blame] | 26 | |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 27 | public class MainActivityLayout extends FrameLayout { |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 28 | |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 29 | private MotionEvent mDown; |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 30 | private final Log.Tag TAG = new Log.Tag("MainActivityLayout"); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 31 | private boolean mRequestToInterceptTouchEvents = false; |
| 32 | private View mTouchReceiver = null; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 33 | |
| 34 | public MainActivityLayout(Context context, AttributeSet attrs) { |
| 35 | super(context, attrs); |
Sascha Haeberling | 8793eff | 2014-01-15 16:33:59 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 38 | @Override |
| 39 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 40 | if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 41 | mDown = MotionEvent.obtain(ev); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 42 | mTouchReceiver = null; |
| 43 | mRequestToInterceptTouchEvents = false; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 44 | return false; |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 45 | } else if (mRequestToInterceptTouchEvents) { |
| 46 | mRequestToInterceptTouchEvents = false; |
| 47 | onTouchEvent(mDown); |
| 48 | return true; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 49 | } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { |
| 50 | // Do not intercept touch once child is in zoom mode |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 51 | return false; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public boolean onTouchEvent(MotionEvent ev) { |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 58 | if (mTouchReceiver != null) { |
| 59 | mTouchReceiver.setVisibility(VISIBLE); |
Angus Kong | 166e36f | 2013-12-03 08:54:42 -0800 | [diff] [blame] | 60 | return mTouchReceiver.dispatchTouchEvent(ev); |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 61 | } |
| 62 | return false; |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 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 | } |
Doris Liu | 1c94b7d | 2013-11-09 19:13:44 -0800 | [diff] [blame] | 73 | } |