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.View;
22import android.widget.ImageButton;
23import android.widget.RelativeLayout;
24
25import com.android.camera.CameraActivity;
26import com.android.camera2.R;
27
28/**
29 * Shows controls at the bottom of the screen for editing, viewing a photo
30 * sphere image and creating a tiny planet from a photo sphere image.
31 */
32public class FilmstripBottomControls extends RelativeLayout
33    implements CameraActivity.OnActionBarVisibilityListener {
34
35    /**
36     * Classes implementing this interface can listen for events on the bottom
37     * controls.
38     */
39    public static interface BottomControlsListener {
40        /**
41         * Called when the user pressed the "view photosphere" button.
42         */
43        public void onViewPhotoSphere();
44
45        /**
46         * Called when the user pressed the "edit" button.
47         */
48        public void onEdit();
49
50        /**
51         * Called when the user pressed the "tiny planet" button.
52         */
53        public void onTinyPlanet();
54    }
55
56    private BottomControlsListener mListener;
57    private ImageButton mEditButton;
58    private ImageButton mViewPhotoSphereButton;
59    private ImageButton mTinyPlanetButton;
60
61    public FilmstripBottomControls(Context context, AttributeSet attrs) {
62        super(context, attrs);
63    }
64
65    @Override
66    protected void onFinishInflate() {
67        super.onFinishInflate();
68        mEditButton = (ImageButton)
69                findViewById(R.id.filmstrip_bottom_control_edit);
70        mEditButton.setOnClickListener(new OnClickListener() {
71            @Override
72            public void onClick(View view) {
73                if (mListener != null) {
74                    mListener.onEdit();
75                }
76            }
77        });
78
79        mViewPhotoSphereButton = (ImageButton)
80                findViewById(R.id.filmstrip_bottom_control_panorama);
81        mViewPhotoSphereButton.setOnClickListener(new OnClickListener() {
82            @Override
83            public void onClick(View view) {
84                if (mListener != null) {
85                    mListener.onViewPhotoSphere();
86                }
87            }
88        });
89
90        mTinyPlanetButton = (ImageButton)
91                findViewById(R.id.filmstrip_bottom_control_tiny_planet);
92        mTinyPlanetButton.setOnClickListener(new OnClickListener() {
93            @Override
94            public void onClick(View view) {
95                if (mListener != null) {
96                    mListener.onTinyPlanet();
97                }
98            }
99        });
100    }
101
102    /**
103     * Sets a new or replaces an existing listener for bottom control events.
104     */
105    public void setListener(BottomControlsListener listener) {
106        mListener = listener;
107    }
108
109    /**
110     * Sets the visibility of the edit button.
111     */
112    public void setEditButtonVisibility(boolean visible) {
113        setVisibility(mEditButton, visible);
114    }
115
116    /**
117     * Sets the visibility of the view-photosphere button.
118     */
119    public void setViewPhotoSphereButtonVisibility(boolean visible) {
120        setVisibility(mViewPhotoSphereButton, visible);
121    }
122
123    /**
124     * Sets the visibility of the tiny-planet button.
125     */
126    public void setTinyPlanetButtonVisibility(final boolean visible) {
127        setVisibility(mTinyPlanetButton, visible);
128    }
129
130    /**
131     * Sets the visibility of the given view.
132     */
133    private static void setVisibility(final View view, final boolean visible) {
134        view.post(new Runnable() {
135            @Override
136            public void run() {
137                view.setVisibility(visible ? View.VISIBLE
138                        : View.INVISIBLE);
139            }
140        });
141    }
142
143    @Override
144    public void onActionBarVisibilityChanged(boolean isVisible) {
145        // TODO: Fade in and out
146        setVisibility(isVisible ? VISIBLE : INVISIBLE);
147    }
148}
149