2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera.widget;
19 import android.content.Context;
20 import android.content.res.Configuration;
21 import android.graphics.RectF;
22 import android.util.AttributeSet;
23 import android.view.Gravity;
24 import android.view.MotionEvent;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.FrameLayout;
28 import android.widget.ImageView;
29 import android.widget.LinearLayout;
31 import com.android.camera.CaptureLayoutHelper;
32 import com.android.camera.ShutterButton;
33 import com.android.camera.debug.Log;
34 import com.android.camera.ui.PreviewOverlay;
35 import com.android.camera.ui.TouchCoordinate;
36 import com.android.camera2.R;
39 * ModeOptionsOverlay is a FrameLayout which positions mode options in
40 * in the bottom of the preview that is visible above the bottom bar.
42 public class ModeOptionsOverlay extends FrameLayout
43 implements PreviewOverlay.OnPreviewTouchedListener,
44 ShutterButton.OnShutterButtonListener {
46 private final static Log.Tag TAG = new Log.Tag("ModeOptionsOverlay");
48 private static final int BOTTOMBAR_OPTIONS_TIMEOUT_MS = 2000;
49 private static final int BOTTOM_RIGHT = Gravity.BOTTOM | Gravity.RIGHT;
50 private static final int TOP_RIGHT = Gravity.TOP | Gravity.RIGHT;
52 private ModeOptions mModeOptions;
53 // need a reference to set the onClickListener and fix the layout gravity on orientation change
54 private LinearLayout mModeOptionsToggle;
55 // need a reference to fix the rotation on orientation change
56 private ImageView mThreeDots;
57 private CaptureLayoutHelper mCaptureLayoutHelper = null;
59 public ModeOptionsOverlay(Context context, AttributeSet attrs) {
60 super(context, attrs);
64 * Whether the mode options are hidden.
66 public boolean isModeOptionsHidden() {
67 return mModeOptions.isHiddenOrHiding();
71 * Gets the current width of the mode options toggle including the three dots and various mode
74 public float getModeOptionsToggleWidth() {
75 return mModeOptionsToggle.getWidth();
79 * Sets a capture layout helper to query layout rect from.
81 public void setCaptureLayoutHelper(CaptureLayoutHelper helper) {
82 mCaptureLayoutHelper = helper;
85 public void setToggleClickable(boolean clickable) {
86 mModeOptionsToggle.setClickable(clickable);
90 * Sets the mode options listener.
92 * @param listener The listener to be set.
94 public void setModeOptionsListener(ModeOptions.Listener listener) {
95 mModeOptions.setListener(listener);
99 public void onFinishInflate() {
100 mModeOptions = (ModeOptions) findViewById(R.id.mode_options);
101 mModeOptions.setClickable(true);
102 mModeOptions.setOnClickListener(new View.OnClickListener() {
104 public void onClick(View v) {
109 mModeOptionsToggle = (LinearLayout) findViewById(R.id.mode_options_toggle);
110 mModeOptionsToggle.setOnClickListener(new View.OnClickListener() {
112 public void onClick(View v) {
113 mModeOptions.animateVisible();
116 mModeOptions.setViewToShowHide(mModeOptionsToggle);
118 mThreeDots = (ImageView) findViewById(R.id.three_dots);
122 public void onPreviewTouched(MotionEvent ev) {
127 public void onShutterButtonClick() {
132 public void onShutterCoordinate(TouchCoordinate coord) {
137 public void onShutterButtonFocus(boolean pressed) {
142 public void onShutterButtonLongPressed() {
147 * Schedule (or re-schedule) the options menu to be closed after a number
148 * of milliseconds. If the options menu is already closed, nothing is
151 public void closeModeOptions() {
152 mModeOptions.animateHidden();
156 public void onConfigurationChanged(Configuration configuration) {
157 super.onConfigurationChanged(configuration);
158 checkOrientation(configuration.orientation);
162 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
163 if (mCaptureLayoutHelper == null) {
164 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
165 Log.e(TAG, "Capture layout helper needs to be set first.");
167 RectF uncoveredPreviewRect = mCaptureLayoutHelper.getUncoveredPreviewRect();
168 super.onMeasure(MeasureSpec.makeMeasureSpec(
169 (int) uncoveredPreviewRect.width(), MeasureSpec.EXACTLY),
170 MeasureSpec.makeMeasureSpec((int) uncoveredPreviewRect.height(),
177 * Set the layout gravity of the child layout to be bottom or top right
178 * depending on orientation.
180 private void checkOrientation(int orientation) {
181 final boolean isPortrait = (Configuration.ORIENTATION_PORTRAIT == orientation);
183 final int modeOptionsDimension = (int) getResources()
184 .getDimension(R.dimen.mode_options_height);
186 FrameLayout.LayoutParams modeOptionsParams
187 = (FrameLayout.LayoutParams) mModeOptions.getLayoutParams();
188 FrameLayout.LayoutParams modeOptionsToggleParams
189 = (FrameLayout.LayoutParams) mModeOptionsToggle.getLayoutParams();
192 modeOptionsParams.height = modeOptionsDimension;
193 modeOptionsParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
194 modeOptionsParams.gravity = Gravity.BOTTOM;
196 modeOptionsToggleParams.gravity = BOTTOM_RIGHT;
198 mThreeDots.setImageResource(R.drawable.ic_options_port);
200 modeOptionsParams.width = modeOptionsDimension;
201 modeOptionsParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
202 modeOptionsParams.gravity = Gravity.RIGHT;
204 modeOptionsToggleParams.gravity = TOP_RIGHT;
206 mThreeDots.setImageResource(R.drawable.ic_options_land);