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
17package com.android.camera.ui;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.MotionEvent;
22import android.view.View;
23
24public class PieMenuButton extends View {
25    private boolean mPressed;
26    private boolean mReadyToClick = false;
27    public PieMenuButton(Context context, AttributeSet attrs) {
28        super(context, attrs);
29    }
30
31    @Override
32    protected void drawableStateChanged() {
33        super.drawableStateChanged();
34        mPressed = isPressed();
35    }
36
37    @Override
38    public boolean onTouchEvent(MotionEvent event) {
39        boolean handled = super.onTouchEvent(event);
40        if (MotionEvent.ACTION_UP == event.getAction() && mPressed) {
41            // Perform a customized click as soon as the ACTION_UP event
42            // is received. The reason for doing this is that Framework
43            // delays the performClick() call after ACTION_UP. But we do not
44            // want the delay because it affects an important state change
45            // for PieRenderer.
46            mReadyToClick = true;
47            performClick();
48        }
49        return handled;
50    }
51
52    @Override
53    public boolean performClick() {
54        if (mReadyToClick) {
55            // We only respond to our customized click which happens right
56            // after ACTION_UP event is received, with no delay.
57            mReadyToClick = false;
58            return super.performClick();
59        }
60        return false;
61    }
62};
63