summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-11-09 00:08:42 -0800
committerMichael Bestas <mikeioannina@gmail.com>2017-01-04 22:00:40 +0200
commitaa0ed8c3c2985f1f2efcc1d40717c18f509cfb5c (patch)
tree6bd03d6ff4f7fcb7053808cb437f7abe0779f628
parent13ca178c2f1c614bc6c615b29986fc6002a89d5a (diff)
downloadandroid_packages_apps_Snap-aa0ed8c3c2985f1f2efcc1d40717c18f509cfb5c.zip
android_packages_apps_Snap-aa0ed8c3c2985f1f2efcc1d40717c18f509cfb5c.tar.gz
android_packages_apps_Snap-aa0ed8c3c2985f1f2efcc1d40717c18f509cfb5c.tar.bz2
snap: UX improvements v1
* Make the camera controls do sane things- get rid of the manual placement of every widget and use layouts * Animate everything correctly * Show ripples when clicking the shutter * Clean up a metric ton of dead code * Moved more code into BaseUI * Make setting up the camera controls less verbose and magical * Fixed up panorama layout Change-Id: Iaed44ca0201a2e2641e1c2460d3ff9ec3eae2d85
-rw-r--r--res/anim/switcher_enter.xml18
-rw-r--r--res/anim/switcher_exit.xml18
-rw-r--r--res/drawable/camera_controls_bg_opaque.xml6
-rw-r--r--res/drawable/camera_controls_bg_translucent.xml6
-rw-r--r--res/drawable/camera_controls_bg_transparent.xml6
-rw-r--r--res/layout/camera_controls.xml182
-rw-r--r--res/layout/list_menu.xml1
-rw-r--r--res/layout/pano_module_capture.xml2
-rw-r--r--res/values/colors.xml7
-rw-r--r--res/values/dimens.xml4
-rw-r--r--res/values/styles.xml2
-rw-r--r--src/com/android/camera/BaseUI.java97
-rw-r--r--src/com/android/camera/CameraActivity.java13
-rwxr-xr-xsrc/com/android/camera/CaptureModule.java20
-rw-r--r--src/com/android/camera/CaptureUI.java104
-rw-r--r--[-rwxr-xr-x]src/com/android/camera/PhotoMenu.java101
-rw-r--r--[-rwxr-xr-x]src/com/android/camera/PhotoModule.java5
-rw-r--r--src/com/android/camera/PhotoUI.java140
-rw-r--r--src/com/android/camera/ShutterButton.java38
-rw-r--r--src/com/android/camera/VideoMenu.java59
-rw-r--r--src/com/android/camera/VideoModule.java11
-rw-r--r--src/com/android/camera/VideoUI.java118
-rw-r--r--src/com/android/camera/WideAnglePanoramaModule.java12
-rw-r--r--src/com/android/camera/WideAnglePanoramaUI.java116
-rw-r--r--src/com/android/camera/ui/CameraControls.java1052
-rw-r--r--src/com/android/camera/ui/ModuleSwitcher.java260
-rw-r--r--src/com/android/camera/util/CameraUtil.java2
27 files changed, 797 insertions, 1603 deletions
diff --git a/res/anim/switcher_enter.xml b/res/anim/switcher_enter.xml
new file mode 100644
index 0000000..91653a2
--- /dev/null
+++ b/res/anim/switcher_enter.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2009, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/decelerate_interpolator"
+ android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="400" />
diff --git a/res/anim/switcher_exit.xml b/res/anim/switcher_exit.xml
new file mode 100644
index 0000000..2525816
--- /dev/null
+++ b/res/anim/switcher_exit.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2009, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/accelerate_interpolator"
+ android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="400" />
diff --git a/res/drawable/camera_controls_bg_opaque.xml b/res/drawable/camera_controls_bg_opaque.xml
new file mode 100644
index 0000000..b86cd04
--- /dev/null
+++ b/res/drawable/camera_controls_bg_opaque.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="@color/camera_controls_ripple"
+ android:radius="@dimen/bottom_bar_ripple_radius">
+ <item android:drawable="@color/camera_controls_bg_opaque" />
+</ripple>
diff --git a/res/drawable/camera_controls_bg_translucent.xml b/res/drawable/camera_controls_bg_translucent.xml
new file mode 100644
index 0000000..a03ebe0
--- /dev/null
+++ b/res/drawable/camera_controls_bg_translucent.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="@color/camera_controls_ripple"
+ android:radius="@dimen/bottom_bar_ripple_radius">
+ <item android:drawable="@color/camera_controls_bg_translucent" />
+</ripple>
diff --git a/res/drawable/camera_controls_bg_transparent.xml b/res/drawable/camera_controls_bg_transparent.xml
new file mode 100644
index 0000000..4900285
--- /dev/null
+++ b/res/drawable/camera_controls_bg_transparent.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="@color/camera_controls_ripple"
+ android:radius="@dimen/bottom_bar_ripple_radius">
+ <item android:drawable="@color/camera_controls_bg_transparent" />
+</ripple>
diff --git a/res/layout/camera_controls.xml b/res/layout/camera_controls.xml
index 3f09742..5241987 100644
--- a/res/layout/camera_controls.xml
+++ b/res/layout/camera_controls.xml
@@ -18,12 +18,53 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
- <View
- android:id="@+id/blocker"
+ <LinearLayout
+ android:id="@+id/top_bar"
android:layout_width="match_parent"
- android:layout_height="@dimen/switcher_size"
- android:layout_gravity="bottom"
- android:clickable="true" />
+ android:layout_height="0dp"
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/menu"
+ style="@style/MenuButton"
+ android:contentDescription="@string/accessibility_menu_button"
+ android:layout_weight="1"
+ android:src="@drawable/ic_settings" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/front_back_switcher"
+ android:layout_weight="1"
+ style="@style/MenuButton" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/hdr_switcher"
+ android:layout_weight="1"
+ style="@style/MenuButton" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/ts_makeup_switcher"
+ android:layout_weight="1"
+ style="@style/MenuButton" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/filter_mode_switcher"
+ android:layout_weight="1"
+ style="@style/MenuButton" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/mute_button"
+ android:layout_weight="1"
+ style="@style/MenuButton"
+ android:contentDescription="@string/mute_button_desc"
+ android:src="@drawable/ic_unmuted_button" />
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/scene_mode_switcher"
+ android:layout_weight="1"
+ style="@style/MenuButton" />
+
+ </LinearLayout>
<include
android:layout_width="64dip"
@@ -33,80 +74,63 @@
android:layout_marginRight="-8dip"
layout="@layout/menu_indicators" />
- <com.android.camera.ui.RotateImageView
- android:id="@+id/filter_mode_switcher"
- style="@style/ToggleButton" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/mute_button"
- style="@style/MenuButton"
- android:contentDescription="@string/mute_button_desc"
- android:src="@drawable/ic_unmuted_button" />
-
- <com.android.camera.ui.ModuleSwitcher
- android:id="@+id/camera_switcher"
- style="@style/SwitcherButton"
- android:layout_gravity="bottom|left"
- android:layout_marginBottom="2dip"
- android:scaleType="center"
- android:contentDescription="@string/accessibility_mode_picker" />
-
- <com.android.camera.ShutterButton
- android:id="@+id/shutter_button"
- android:layout_width="@dimen/shutter_size"
- android:layout_height="@dimen/shutter_size"
- android:layout_gravity="bottom|center_horizontal"
- android:layout_marginBottom="@dimen/shutter_offset"
- android:layout_marginTop="@dimen/shutter_offset_top"
- android:clickable="true"
- android:contentDescription="@string/accessibility_shutter_button"
- android:focusable="true"
- android:scaleType="fitCenter"
- android:src="@drawable/btn_new_shutter" />
-
- <ImageView
- android:id="@+id/video_button"
- android:visibility="invisible"
- android:layout_width="@dimen/shutter_size"
- android:layout_height="@dimen/shutter_size"
- android:layout_gravity="bottom|center_horizontal"
- android:layout_marginBottom="@dimen/shutter_offset"
- android:clickable="true"
- android:contentDescription="@string/accessibility_shutter_button"
- android:focusable="true"
- android:scaleType="fitCenter"
- android:src="@drawable/btn_new_shutter_video" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/preview_thumb"
- android:layout_width="@dimen/capture_size"
- android:layout_height="@dimen/capture_size"
- android:layout_gravity="top|right"
- android:background="@android:color/transparent"
- android:contentDescription="@string/switch_photo_filmstrip"
- android:scaleType="fitCenter" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/front_back_switcher"
- style="@style/ToggleButton" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/hdr_switcher"
- style="@style/ToggleButton" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/scene_mode_switcher"
- style="@style/ToggleButton" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/menu"
- style="@style/MenuButton"
- android:contentDescription="@string/accessibility_menu_button"
- android:src="@drawable/ic_settings" />
-
- <com.android.camera.ui.RotateImageView
- android:id="@+id/ts_makeup_switcher"
- style="@style/ToggleButton" />
+ <LinearLayout
+ android:id="@+id/bottom_bar"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:gravity="center_vertical"
+ android:weightSum="3"
+ android:orientation="horizontal">
+
+ <com.android.camera.ui.RotateImageView
+ android:id="@+id/preview_thumb"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:background="@android:color/transparent"
+ android:contentDescription="@string/switch_photo_filmstrip"
+ android:elevation="1dp"
+ android:scaleType="fitCenter" />
+
+ <com.android.camera.ShutterButton
+ android:id="@+id/shutter_button"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:clickable="true"
+ android:contentDescription="@string/accessibility_shutter_button"
+ android:focusable="true"
+ android:scaleType="fitCenter"
+ android:layout_weight="1"
+ android:elevation="1dp"
+ android:src="@drawable/btn_new_shutter" />
+
+ <ImageView
+ android:id="@+id/video_button"
+ android:visibility="gone"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:clickable="true"
+ android:contentDescription="@string/accessibility_shutter_button"
+ android:focusable="true"
+ android:scaleType="fitCenter"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:elevation="1dp"
+ android:src="@drawable/btn_new_shutter_video" />
+
+ <com.android.camera.ui.ModuleSwitcher
+ android:id="@+id/camera_switcher"
+ style="@style/SwitcherButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:scaleType="center"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:elevation="1dp"
+ android:contentDescription="@string/accessibility_mode_picker" />
+ </LinearLayout>
<LinearLayout
android:id="@+id/remaining_photos"
diff --git a/res/layout/list_menu.xml b/res/layout/list_menu.xml
index dd43544..636e080 100644
--- a/res/layout/list_menu.xml
+++ b/res/layout/list_menu.xml
@@ -30,6 +30,7 @@
android:layout_width="@dimen/big_setting_popup_window_width"
android:layout_height="wrap_content"
android:background="@color/popup_background"
+ android:elevation="10dp"
android:scrollbars="none" >
</com.android.camera.ui.ListMenu>
diff --git a/res/layout/pano_module_capture.xml b/res/layout/pano_module_capture.xml
index ad34cf8..9f53ff1 100644
--- a/res/layout/pano_module_capture.xml
+++ b/res/layout/pano_module_capture.xml
@@ -23,7 +23,7 @@
android:id="@+id/pano_preview_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_gravity="center" >
+ android:layout_gravity="center_vertical|center_horizontal" >
<TextureView
android:id="@+id/pano_preview_textureview"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 2f9ff10..05c7834 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -70,15 +70,16 @@
<color name="face_detect_fail">@color/red</color>
<color name="focus_color">#ffffffff</color>
<color name="gray">@color/grey</color>
+ <color name="camera_controls_bg_opaque">#1b1b1b</color>
+ <color name="camera_controls_bg_translucent">#401b1b1b</color>
+ <color name="camera_controls_bg_transparent">#101b1b1b</color>
+ <color name="camera_controls_ripple">#ff4285f4</color>
<color name="setting_list_selected">#40fafafa</color>
<color name="setting_list_pressed">#60fafafa</color>
<color name="list_divider_color">#e0212121</color>
<color name="scene_item_selected">@color/setting_list_selected</color>
- <color name="camera_control_bg_opaque">@color/black</color>
- <color name="camera_control_bg_transparent">#40212121</color>
-
<color name="refocus_indicator_1">#a0ffffff</color>
<color name="refocus_indicator_2">#ff29b6f6</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 96f1560..c8c1896 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -172,7 +172,7 @@
<dimen name="filter_mode_width">100dp</dimen>
<dimen name="filter_mode_padding">10dp</dimen>
- <dimen name="remaining_photos_margin">67dp</dimen>
+ <dimen name="remaining_photos_margin">70dp</dimen>
<dimen name="tsmakeup_mode_paddingBottom">96dp</dimen>
<dimen name="tsmakeup_mode_level_size">96dp</dimen>
@@ -185,4 +185,6 @@
<dimen name="refocus_circle_diameter_3">95dp</dimen>
<dimen name="refocus_cross_length">19dp</dimen>
<dimen name="refocus_stroke_width">2dp</dimen>
+
+ <dimen name="bottom_bar_ripple_radius">30dp</dimen>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 58fb260..2528546 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -246,11 +246,13 @@
<item name="android:layout_width">@dimen/switcher_size</item>
<item name="android:layout_height">@dimen/switcher_size</item>
<item name="android:background">@drawable/bg_pressed_exit_fading</item>
+ <item name="android:elevation">1dp</item>
</style>
<style name="MenuButton">
<item name="android:layout_width">@dimen/menu_outer_size</item>
<item name="android:layout_height">@dimen/menu_outer_size</item>
<item name="android:scaleType">center</item>
+ <item name="android:elevation">1dp</item>
</style>
<style name="MuteButton">
<item name="android:layout_width">@dimen/mute_outer_size</item>
diff --git a/src/com/android/camera/BaseUI.java b/src/com/android/camera/BaseUI.java
index 7587c05..3721062 100644
--- a/src/com/android/camera/BaseUI.java
+++ b/src/com/android/camera/BaseUI.java
@@ -1,11 +1,52 @@
package com.android.camera;
+import android.graphics.Point;
import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.camera.ui.CameraControls;
+import com.android.camera.ui.ModuleSwitcher;
+import com.android.camera.util.CameraUtil;
+
+import org.codeaurora.snapcam.R;
/** we can start accumulating common code between UI classes here
* toward an eventual unification - WF */
public abstract class BaseUI {
- protected View mPreviewCover;
+
+ protected final CameraControls mCameraControls;
+ protected final View mPreviewCover;
+
+ protected final CameraActivity mActivity;
+ protected final ViewGroup mRootView;
+
+ protected int mTopMargin = 0;
+ protected int mBottomMargin = 0;
+ protected int mScreenRatio = CameraUtil.RATIO_UNKNOWN;
+
+ public BaseUI(CameraActivity activity, ViewGroup rootView, int layout) {
+ mActivity = activity;
+ mRootView = rootView;
+
+ mActivity.getLayoutInflater().inflate(layout, mRootView, true);
+
+ mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
+ mPreviewCover = mRootView.findViewById(R.id.preview_cover);
+
+ Point size = new Point();
+ mActivity.getWindowManager().getDefaultDisplay().getRealSize(size);
+ mScreenRatio = CameraUtil.determineRatio(size.x, size.y);
+ calculateMargins(size);
+ mCameraControls.setMargins(mTopMargin, mBottomMargin);
+ }
+
+ private void calculateMargins(Point size) {
+ int l = size.x > size.y ? size.x : size.y;
+ int tm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_top_margin);
+ int bm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_bottom_margin);
+ mTopMargin = l / 4 * tm / (tm + bm);
+ mBottomMargin = l / 4 - mTopMargin;
+ }
public void showPreviewCover() {
if (mPreviewCover != null && mPreviewCover.getVisibility() != View.VISIBLE) {
@@ -24,4 +65,58 @@ public abstract class BaseUI {
mPreviewCover.setAlpha(alpha);
}
}
+
+ public boolean isPreviewCoverVisible() {
+ return mPreviewCover != null && mPreviewCover.getVisibility() == View.VISIBLE;
+ }
+
+ public void hideUI() {
+ hideUI(false);
+ }
+
+ protected void hideUI(boolean toBlack) {
+ if (mCameraControls != null) {
+ mCameraControls.hideUI(toBlack);
+ }
+ }
+
+ protected void showUI() {
+ if (mCameraControls != null) {
+ mCameraControls.showUI();
+ }
+ }
+
+ public boolean arePreviewControlsVisible() {
+ return mCameraControls != null && mCameraControls.arePreviewControlsVisible();
+ }
+
+ public void hideSwitcher() {
+ if (mCameraControls != null) {
+ mCameraControls.hideSwitcher();
+ }
+ }
+
+ public void showSwitcher() {
+ if (mCameraControls != null) {
+ mCameraControls.showSwitcher();
+ }
+ }
+
+ public void removeControlView(View v) {
+ if (mCameraControls != null) {
+ mCameraControls.removeFromViewList(v);
+ }
+ }
+
+ public void setSwitcherIndex() {
+ int module = ModuleSwitcher.PHOTO_MODULE_INDEX;
+ if (this instanceof WideAnglePanoramaUI) {
+ module = ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX;
+ } else if (this instanceof VideoUI) {
+ module = ModuleSwitcher.VIDEO_MODULE_INDEX;
+ } else if (this instanceof CaptureUI) {
+ module = ModuleSwitcher.CAPTURE_MODULE_INDEX;
+ }
+ mCameraControls.setModuleIndex(module);
+ }
}
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 87ebe60..4e58afa 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -119,6 +119,7 @@ import org.codeaurora.snapcam.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.MemoryCategory;
+import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor;
import java.io.File;
@@ -1620,10 +1621,18 @@ public class CameraActivity extends Activity
registerSDcardMountedReceiver();
if (!Glide.isSetup()) {
- Glide.setup(new GlideBuilder(getApplicationContext())
+ Context context = getApplicationContext();
+ Glide.setup(new GlideBuilder(context)
+ .setDecodeFormat(DecodeFormat.ALWAYS_ARGB_8888)
.setResizeService(new FifoPriorityThreadPoolExecutor(2)));
- Glide.get(getApplicationContext()).setMemoryCategory(MemoryCategory.HIGH);
+
+ Glide glide = Glide.get(context);
+
+ // As a camera we will use a large amount of memory
+ // for displaying images.
+ glide.setMemoryCategory(MemoryCategory.HIGH);
}
+
}
private void setRotationAnimation() {
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 7c6ccf8..718f55f 100755
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -71,6 +71,7 @@ import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.Toast;
import com.android.camera.exif.ExifInterface;
@@ -955,7 +956,7 @@ public class CaptureModule implements CameraModule, PhotoController,
setCurrentMode();
mContentResolver = mActivity.getContentResolver();
- mUI = new CaptureUI(activity, this, parent);
+ mUI = new CaptureUI(activity, this, (ViewGroup) parent);
mUI.initializeControlByIntent();
mFocusStateListener = new FocusStateListener(mUI);
@@ -1171,14 +1172,6 @@ public class CaptureModule implements CameraModule, PhotoController,
CaptureRequest request,
TotalCaptureResult result) {
Log.d(TAG, "captureStillPicture Longshot onCaptureCompleted: " + id);
- if (mLongshotActive) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mUI.doShutterAnimation();
- }
- });
- }
}
@Override
@@ -1186,14 +1179,6 @@ public class CaptureModule implements CameraModule, PhotoController,
CaptureRequest request,
CaptureFailure result) {
Log.d(TAG, "captureStillPicture Longshot onCaptureFailed: " + id);
- if (mLongshotActive) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mUI.doShutterAnimation();
- }
- });
- }
}
@Override
@@ -1848,7 +1833,6 @@ public class CaptureModule implements CameraModule, PhotoController,
initializeValues();
updatePreviewSize();
mUI.showSurfaceView();
- mUI.setSwitcherIndex();
mCameraIdList = new ArrayList<>();
if (mSound == null) {
diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java
index 0fb0bdc..b418ffe 100644
--- a/src/com/android/camera/CaptureUI.java
+++ b/src/com/android/camera/CaptureUI.java
@@ -136,8 +136,6 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
SettingsManager.KEY_AUTO_VIDEOSNAP_SIZE
};
private final FocusRing mFocusRing;
- private CameraActivity mActivity;
- private View mRootView;
private CaptureModule mModule;
private AutoFitSurfaceView mSurfaceView;
private AutoFitSurfaceView mSurfaceViewMono;
@@ -209,18 +207,13 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
private ImageView mVideoButton;
private RenderOverlay mRenderOverlay;
private View mMenuButton;
- private ModuleSwitcher mSwitcher;
private CountDownView mCountDownView;
- private CameraControls mCameraControls;
private PieRenderer mPieRenderer;
private ZoomRenderer mZoomRenderer;
private Allocation mMonoDummyAllocation;
private Allocation mMonoDummyOutputAllocation;
private boolean mIsMonoDummyAllocationEverUsed = false;
- private int mScreenRatio = CameraUtil.RATIO_UNKNOWN;
- private int mTopMargin = 0;
- private int mBottomMargin = 0;
private LinearLayout mSceneAndFilterLayout;
private int mSceneAndFilterMenuSize;
@@ -256,15 +249,12 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
return mDisplaySize;
}
- public CaptureUI(CameraActivity activity, CaptureModule module, View parent) {
- mActivity = activity;
+ public CaptureUI(CameraActivity activity, CaptureModule module, ViewGroup parent) {
+ super(activity, parent, R.layout.capture_module);
mModule = module;
- mRootView = parent;
mSettingsManager = activity.getSettingsManager();
mSettingsManager.registerListener(this);
- mActivity.getLayoutInflater().inflate(R.layout.capture_module,
- (ViewGroup) mRootView, true);
- mPreviewCover = mRootView.findViewById(R.id.preview_cover);
+
// display the view
mSurfaceView = (AutoFitSurfaceView) mRootView.findViewById(R.id.mdp_preview_content);
mSurfaceHolder = mSurfaceView.getHolder();
@@ -308,19 +298,6 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
mTrackingFocusRenderer.setVisible(false);
}
- mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
- mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
- mSwitcher.setSwitchListener(mActivity);
- mSwitcher.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mModule.getCameraState() == PhotoController.LONGSHOT) {
- return;
- }
- mSwitcher.showPopup();
- mSwitcher.setOrientation(mOrientation, false);
- }
- });
mMenuButton = mRootView.findViewById(R.id.menu);
mRecordingTimeView = (TextView) mRootView.findViewById(R.id.recording_time);
@@ -352,20 +329,8 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
RotateImageView muteButton = (RotateImageView) mRootView.findViewById(R.id.mute_button);
muteButton.setVisibility(View.GONE);
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
mFaceView = (Camera2FaceView) mRootView.findViewById(R.id.face_view);
- mActivity.getWindowManager().getDefaultDisplay().getSize(mDisplaySize);
- mScreenRatio = CameraUtil.determineRatio(mDisplaySize.x, mDisplaySize.y);
- if (mScreenRatio == CameraUtil.RATIO_16_9) {
- int l = mDisplaySize.x > mDisplaySize.y ? mDisplaySize.x : mDisplaySize.y;
- int tm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_top_margin);
- int bm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_bottom_margin);
- mTopMargin = l / 4 * tm / (tm + bm);
- mBottomMargin = l / 4 - mTopMargin;
- }
- mCameraControls.setMargins(mTopMargin, mBottomMargin);
-
if (mPieRenderer == null) {
mPieRenderer = new PieRenderer(mActivity);
mRenderOverlay.addRenderer(mPieRenderer);
@@ -420,15 +385,8 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
// called from onResume but only the first time
public void initializeFirstTime() {
// Initialize shutter button.
- mShutterButton.setImageResource(R.drawable.shutter_button_anim);
- mShutterButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!isCameraControlsAnimating())
- doShutterAnimation();
- }
- });
- mShutterButton.setOnShutterButtonListener(mModule);
+ mShutterButton.setImageResource(R.drawable.btn_new_shutter);
+ mShutterButton.addOnShutterButtonListener(mModule);
mShutterButton.setVisibility(View.VISIBLE);
mVideoButton.setVisibility(View.VISIBLE);
mVideoButton.setOnClickListener(new View.OnClickListener() {
@@ -581,19 +539,6 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
mSceneModeSwitcher.setVisibility(View.VISIBLE);
}
- public void hideSwitcher() {
- mSwitcher.closePopup();
- mSwitcher.setVisibility(View.INVISIBLE);
- }
-
- public void showSwitcher() {
- mSwitcher.setVisibility(View.VISIBLE);
- }
-
- public void setSwitcherIndex() {
- mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
- }
-
public void addSceneMode() {
String value = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE);
if (value == null) return;
@@ -1167,7 +1112,11 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
if (mFrontBackSwitcher != null) mFrontBackSwitcher.setVisibility(status);
if (mSceneModeSwitcher != null) mSceneModeSwitcher.setVisibility(status);
if (mFilterModeSwitcher != null) mFilterModeSwitcher.setVisibility(status);
- if (mSwitcher != null) mSwitcher.setVisibility(status);
+ if (hide) {
+ mCameraControls.hideSwitcher();
+ } else {
+ mCameraControls.showSwitcher();
+ }
}
public boolean isCameraControlsAnimating() {
@@ -1193,27 +1142,6 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
});
}
- public void doShutterAnimation() {
- AnimationDrawable frameAnimation = (AnimationDrawable) mShutterButton.getDrawable();
- frameAnimation.stop();
- frameAnimation.start();
- }
-
- public void showUI() {
- if (!mUIhidden || isMenuBeingShown())
- return;
- mUIhidden = false;
- mCameraControls.showUI();
- }
-
- public void hideUI() {
- mSwitcher.closePopup();
- if (mUIhidden)
- return;
- mUIhidden = true;
- mCameraControls.hideUI();
- }
-
public void cleanUpMenus() {
showUI();
mActivity.setSystemBarsVisibility(false);
@@ -1307,12 +1235,8 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
// ignore backs while we're taking a picture
return true;
}
- if (mSwitcher != null && mSwitcher.showsPopup()) {
- mSwitcher.closePopup();
- return true;
- } else {
- return false;
- }
+ mCameraControls.collapse();
+ return false;
}
public SurfaceHolder getSurfaceHolder() {
@@ -1420,7 +1344,7 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
}
public boolean collapseCameraControls() {
- mSwitcher.closePopup();
+ mCameraControls.collapse();
// Remove all the popups/dialog boxes
boolean ret = false;
removeAllMenu();
@@ -1539,7 +1463,7 @@ public class CaptureUI extends BaseUI implements PreviewGestures.SingleTapListen
if (previewFocused) {
showUI();
} else {
- hideUI();
+ hideUI(true);
}
if (mFaceView != null) {
mFaceView.setBlockDraw(!previewFocused);
diff --git a/src/com/android/camera/PhotoMenu.java b/src/com/android/camera/PhotoMenu.java
index 38a81c8..63851e4 100755..100644
--- a/src/com/android/camera/PhotoMenu.java
+++ b/src/com/android/camera/PhotoMenu.java
@@ -118,7 +118,6 @@ public class PhotoMenu extends MenuController
private MakeupLevelListener mMakeupListener;
private MakeupHandler mHandler = new MakeupHandler();
private static final int MAKEUP_MESSAGE_ID = 0;
- private HashSet<View> mWasVisibleSet = new HashSet<View>();
public PhotoMenu(CameraActivity activity, PhotoUI ui, MakeupLevelListener makeupListener) {
super(activity);
@@ -160,20 +159,18 @@ public class PhotoMenu extends MenuController
initSceneModeButton(mSceneModeSwitcher);
initFilterModeButton(mFilterModeSwitcher);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- initMakeupModeButton(mTsMakeupSwitcher);
- } else {
- mHdrSwitcher.setVisibility(View.INVISIBLE);
+ if (TsMakeupManager.HAS_TS_MAKEUP) {
+ if (initMakeupModeButton(mTsMakeupSwitcher)) {
+ mUI.removeControlView(mHdrSwitcher);
+ }
}
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
if(!TsMakeupManager.HAS_TS_MAKEUP) {
// HDR.
if (group.findPreference(CameraSettings.KEY_CAMERA_HDR) != null) {
- mHdrSwitcher.setVisibility(View.VISIBLE);
initSwitchItem(CameraSettings.KEY_CAMERA_HDR, mHdrSwitcher);
} else {
- mHdrSwitcher.setVisibility(View.INVISIBLE);
+ mUI.removeControlView(mHdrSwitcher);
}
}
@@ -789,11 +786,8 @@ public class PhotoMenu extends MenuController
}
}
- if ((autohdr != null) && autohdr.equals("enable")) {
- mHdrSwitcher.setVisibility(View.GONE);
- mUI.getCameraControls().removeFromViewList(mHdrSwitcher);
- } else {
- mHdrSwitcher.setVisibility(View.VISIBLE);
+ if (mHdrSwitcher.getVisibility() == View.VISIBLE && autohdr != null) {
+ buttonSetEnabled(mHdrSwitcher, autohdr.equals("enable"));
}
if (mListener != null) {
@@ -819,8 +813,10 @@ public class PhotoMenu extends MenuController
public void initSwitchItem(final String prefKey, View switcher) {
final IconListPreference pref =
(IconListPreference) mPreferenceGroup.findPreference(prefKey);
- if (pref == null)
+ if (pref == null) {
+ mUI.removeControlView(switcher);
return;
+ }
int[] iconIds = pref.getLargeIconIds();
int resid = -1;
@@ -833,7 +829,6 @@ public class PhotoMenu extends MenuController
resid = pref.getSingleIcon();
}
((ImageView) switcher).setImageResource(resid);
- switcher.setVisibility(View.VISIBLE);
mPreferences.add(pref);
mPreferenceMap.put(pref, switcher);
switcher.setOnClickListener(new OnClickListener() {
@@ -863,15 +858,16 @@ public class PhotoMenu extends MenuController
});
}
- public void initMakeupModeButton(View button) {
+ public boolean initMakeupModeButton(View button) {
if(!TsMakeupManager.HAS_TS_MAKEUP) {
- return;
+ return false;
}
- button.setVisibility(View.INVISIBLE);
final IconListPreference pref = (IconListPreference) mPreferenceGroup
.findPreference(CameraSettings.KEY_TS_MAKEUP_UILABLE);
- if (pref == null)
- return;
+ if (pref == null) {
+ mUI.removeControlView(button);
+ return false;
+ }
int[] iconIds = pref.getLargeIconIds();
int resid = -1;
@@ -886,8 +882,6 @@ public class PhotoMenu extends MenuController
ImageView iv = (ImageView) mTsMakeupSwitcher;
iv.setImageResource(resid);
- button.setVisibility(View.VISIBLE);
-
String makeupOn = pref.getValue();
Log.d(TAG, "PhotoMenu.initMakeupModeButton():current init makeupOn is " + makeupOn);
@@ -904,6 +898,7 @@ public class PhotoMenu extends MenuController
}
}
});
+ return true;
}
private void initMakeupMenu() {
@@ -959,13 +954,13 @@ public class PhotoMenu extends MenuController
}
public void initSceneModeButton(View button) {
- button.setVisibility(View.INVISIBLE);
final IconListPreference pref = (IconListPreference) mPreferenceGroup
.findPreference(CameraSettings.KEY_SCENE_MODE);
- if (pref == null)
+ if (pref == null) {
+ mUI.removeControlView(button);
return;
+ }
updateSceneModeIcon(pref);
- button.setVisibility(View.VISIBLE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -1090,13 +1085,12 @@ public class PhotoMenu extends MenuController
label.setText(entries[i]);
layout.addView(layout2);
- // ASD only available when developer options are enabled.
if(entryValues[i].equals("asd")) {
- layout2.setVisibility(mActivity.isDeveloperMenuEnabled()?View.VISIBLE:View.GONE);
+ layout2.setVisibility(View.VISIBLE);
} else if(entryValues[i].equals("hdr")) {
ListPreference autoHdrPref = mPreferenceGroup.findPreference(CameraSettings.KEY_AUTO_HDR);
if (autoHdrPref != null && autoHdrPref.getValue().equalsIgnoreCase("enable")) {
- layout2.setVisibility(View.GONE);
+ layout2.setEnabled(false);
}
} else if(CameraApp.mIsLowMemoryDevice &&
(entryValues[i].equals(mActivity.getResources().getString(R.string.pref_camera_advanced_feature_value_refocus_on))
@@ -1118,13 +1112,13 @@ public class PhotoMenu extends MenuController
}
public void initFilterModeButton(View button) {
- button.setVisibility(View.INVISIBLE);
final IconListPreference pref = (IconListPreference) mPreferenceGroup
.findPreference(CameraSettings.KEY_COLOR_EFFECT);
- if (pref == null || pref.getValue() == null)
+ if (pref == null || pref.getValue() == null) {
+ mUI.removeControlView(button);
return;
+ }
changeFilterModeControlIcon(pref.getValue());
- button.setVisibility(View.VISIBLE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -1503,11 +1497,13 @@ public class PhotoMenu extends MenuController
}
ListPreference autoHdrPref = mPreferenceGroup.findPreference(CameraSettings.KEY_AUTO_HDR);
- if (autoHdrPref != null && autoHdrPref.getValue().equalsIgnoreCase("enable")) {
+ if (autoHdrPref == null) {
mHdrSwitcher.setVisibility(View.GONE);
mUI.getCameraControls().removeFromViewList(mHdrSwitcher);
+ } else if (autoHdrPref.getValue().equalsIgnoreCase("enable")) {
+ mHdrSwitcher.setEnabled(false);
} else {
- mHdrSwitcher.setVisibility(View.VISIBLE);
+ mHdrSwitcher.setEnabled(true);
}
updateFilterModeIcon(pref, pref);
@@ -1526,43 +1522,4 @@ public class PhotoMenu extends MenuController
public int getOrientation() {
return mUI == null ? 0 : mUI.getOrientation();
}
-
- public void hideTopMenu(boolean hide) {
- if (hide) {
- mSceneModeSwitcher.setVisibility(View.GONE);
- mFilterModeSwitcher.setVisibility(View.GONE);
- mFrontBackSwitcher.setVisibility(View.GONE);
- mTsMakeupSwitcher.setVisibility(View.GONE);
- } else {
- mSceneModeSwitcher.setVisibility(View.VISIBLE);
- mFilterModeSwitcher.setVisibility(View.VISIBLE);
- mFrontBackSwitcher.setVisibility(View.VISIBLE);
- mTsMakeupSwitcher.setVisibility(View.VISIBLE);
- }
- }
-
- public void hideCameraControls(boolean hide) {
- final int status = (hide) ? View.INVISIBLE : View.VISIBLE;
- mSettingMenu.setVisibility(status);
- mFrontBackSwitcher.setVisibility(status);
- if (TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(status);
- } else {
- mHdrSwitcher.setVisibility(status);
- }
- mSceneModeSwitcher.setVisibility(status);
- mFilterModeSwitcher.setVisibility(status);
- if(status == View.INVISIBLE) {
- if(mCameraSwitcher.getVisibility() == View.VISIBLE) {
- mWasVisibleSet.add(mCameraSwitcher);
- }
- mCameraSwitcher.setVisibility(status);
- } else {
- if(mWasVisibleSet.contains(mCameraSwitcher)) {
- mCameraSwitcher.setVisibility(status);
- mWasVisibleSet.remove(mCameraSwitcher);
- }
- }
- mPreviewThumbnail.setVisibility(status);
- }
}
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 55dfbaa..d6f23e3 100755..100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -578,7 +578,7 @@ public class PhotoModule
mPreferences.setLocalId(mActivity, mCameraId);
CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
- mUI = new PhotoUI(activity, this, parent);
+ mUI = new PhotoUI(activity, this, (ViewGroup) parent);
// Power shutter
mActivity.initPowerShutter(mPreferences);
@@ -1095,8 +1095,6 @@ public class PhotoModule
return;
}
- mUI.doShutterAnimation();
-
Location loc = getLocationAccordPictureFormat(mParameters.get(KEY_PICTURE_FORMAT));
mLongShotCaptureCount++;
@@ -2356,7 +2354,6 @@ public class PhotoModule
Log.v(TAG, "onShutterButtonClick: mCameraState=" + mCameraState);
if (mSceneMode == CameraUtil.SCENE_MODE_HDR) {
- mUI.hideSwitcher();
mUI.setSwipingEnabled(false);
}
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index 3683c7a..5aeccac 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -17,21 +17,13 @@
package com.android.camera;
-import java.util.List;
-
-import org.codeaurora.snapcam.R;
-
import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnDismissListener;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.RectF;
-import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera;
import android.hardware.Camera.Face;
@@ -66,8 +58,8 @@ import com.android.camera.ui.CountDownView;
import com.android.camera.ui.CountDownView.OnCountDownFinishedListener;
import com.android.camera.ui.FaceView;
import com.android.camera.ui.ListSubMenu;
-import com.android.camera.ui.ModuleSwitcher;
import com.android.camera.ui.MenuHelp;
+import com.android.camera.ui.ModuleSwitcher;
import com.android.camera.ui.PieRenderer;
import com.android.camera.ui.PieRenderer.PieListener;
import com.android.camera.ui.RenderOverlay;
@@ -79,6 +71,10 @@ import com.android.camera.ui.ZoomRenderer;
import com.android.camera.ui.focus.FocusRing;
import com.android.camera.util.CameraUtil;
+import org.codeaurora.snapcam.R;
+
+import java.util.List;
+
public class PhotoUI extends BaseUI implements PieListener,
PreviewGestures.SingleTapListener,
SurfaceHolder.Callback,
@@ -89,11 +85,9 @@ public class PhotoUI extends BaseUI implements PieListener,
private int mDownSampleFactor = 4;
private final AnimationManager mAnimationManager;
private final FocusRing mFocusRing;
- private CameraActivity mActivity;
private PhotoController mController;
private PreviewGestures mGestures;
- private View mRootView;
private SurfaceHolder mSurfaceHolder;
private PopupWindow mPopup;
@@ -111,8 +105,6 @@ public class PhotoUI extends BaseUI implements PieListener,
private View mMenuButton;
private PhotoMenu mMenu;
- private ModuleSwitcher mSwitcher;
- private CameraControls mCameraControls;
private MenuHelp mMenuHelp;
private AlertDialog mLocationDialog;
@@ -147,12 +139,8 @@ public class PhotoUI extends BaseUI implements PieListener,
private RotateLayout mSubMenuLayout;
private LinearLayout mPreviewMenuLayout;
private LinearLayout mMakeupMenuLayout;
- private boolean mUIhidden = false;
private int mPreviewOrientation = -1;
- private int mScreenRatio = CameraUtil.RATIO_UNKNOWN;
- private int mTopMargin = 0;
- private int mBottomMargin = 0;
private boolean mIsLayoutInitializedAlready = false;
private int mOrientation;
@@ -228,13 +216,10 @@ public class PhotoUI extends BaseUI implements PieListener,
mSurfaceView.setVisibility(View.VISIBLE);
}
- public PhotoUI(CameraActivity activity, PhotoController controller, View parent) {
- mActivity = activity;
+ public PhotoUI(CameraActivity activity, PhotoController controller, ViewGroup parent) {
+ super(activity, parent, R.layout.photo_module);
mController = controller;
- mRootView = parent;
- mActivity.getLayoutInflater().inflate(R.layout.photo_module,
- (ViewGroup) mRootView, true);
- mPreviewCover = mRootView.findViewById(R.id.preview_cover);
+
// display the view
mSurfaceView = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content);
mSurfaceView.setVisibility(View.VISIBLE);
@@ -268,25 +253,10 @@ public class PhotoUI extends BaseUI implements PieListener,
mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay);
mFlashOverlay = mRootView.findViewById(R.id.flash_overlay);
mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
- mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
- mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
- mSwitcher.setSwitchListener(mActivity);
- mSwitcher.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mController.getCameraState() == PhotoController.LONGSHOT) {
- return;
- }
- mSwitcher.showPopup();
- mSwitcher.setOrientation(mOrientation, false);
- }
- });
mMenuButton = mRootView.findViewById(R.id.menu);
- RotateImageView muteButton = (RotateImageView)mRootView.findViewById(R.id.mute_button);
- muteButton.setVisibility(View.GONE);
+ mCameraControls.disableMuteButton();
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
ViewStub faceViewStub = (ViewStub) mRootView
.findViewById(R.id.face_view_stub);
if (faceViewStub != null) {
@@ -300,22 +270,9 @@ public class PhotoUI extends BaseUI implements PieListener,
mOrientationResize = false;
mPrevOrientationResize = false;
- Point size = new Point();
- mActivity.getWindowManager().getDefaultDisplay().getRealSize(size);
- mScreenRatio = CameraUtil.determineRatio(size.x, size.y);
- calculateMargins(size);
- mCameraControls.setMargins(mTopMargin, mBottomMargin);
showFirstTimeHelp();
}
- private void calculateMargins(Point size) {
- int l = size.x > size.y ? size.x : size.y;
- int tm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_top_margin);
- int bm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_bottom_margin);
- mTopMargin = l / 4 * tm / (tm + bm);
- mBottomMargin = l / 4 - mTopMargin;
- }
-
public void setDownFactor(int factor) {
mDownSampleFactor = factor;
}
@@ -478,8 +435,6 @@ public class PhotoUI extends BaseUI implements PieListener,
RectF r = new RectF(mSurfaceView.getLeft(), mSurfaceView.getTop(),
mSurfaceView.getRight(), mSurfaceView.getBottom());
mController.onPreviewRectChanged(CameraUtil.rectFToRect(r));
- // Make sure preview cover is hidden if preview data is available.
- hidePreviewCover();
}
@Override
@@ -589,9 +544,8 @@ public class PhotoUI extends BaseUI implements PieListener,
}
});
if (mController.isImageCaptureIntent()) {
- hideSwitcher();
mCameraControls.hideRemainingPhotoCnt();
- mSwitcher.setSwitcherVisibility(false);
+ mCameraControls.hideSwitcher();
ViewGroup cameraControls = (ViewGroup) mRootView.findViewById(R.id.camera_controls);
mActivity.getLayoutInflater().inflate(R.layout.review_module_control, cameraControls);
@@ -626,47 +580,15 @@ public class PhotoUI extends BaseUI implements PieListener,
}
}
- public void hideUI() {
- mSwitcher.closePopup();
- if (mUIhidden)
- return;
- mUIhidden = true;
- mCameraControls.hideUI();
- }
-
- public void showUI() {
- if (!mUIhidden || (mMenu != null && mMenu.isMenuBeingShown()))
- return;
- mUIhidden = false;
- mCameraControls.showUI();
- }
-
- public boolean arePreviewControlsVisible() {
- return !mUIhidden;
- }
-
- public void hideSwitcher() {
- mSwitcher.closePopup();
- mSwitcher.setVisibility(View.INVISIBLE);
- }
-
- public void showSwitcher() {
- mSwitcher.setVisibility(View.VISIBLE);
- }
-
- public void setSwitcherIndex() {
- mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
- }
-
// called from onResume but only the first time
public void initializeFirstTime() {
// Initialize shutter button.
mShutterButton.setImageResource(R.drawable.shutter_button_anim);
+ mShutterButton.setImageResource(R.drawable.btn_new_shutter);
mShutterButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!isCameraControlsAnimating()) {
- doShutterAnimation();
if (mController.isImageCaptureIntent()) {
mCameraControls.setTitleBarVisibility(View.VISIBLE);
}
@@ -674,16 +596,10 @@ public class PhotoUI extends BaseUI implements PieListener,
}
});
- mShutterButton.setOnShutterButtonListener(mController);
+ mShutterButton.addOnShutterButtonListener(mController);
mShutterButton.setVisibility(View.VISIBLE);
}
- public void doShutterAnimation() {
- AnimationDrawable frameAnimation = (AnimationDrawable) mShutterButton.getDrawable();
- frameAnimation.stop();
- frameAnimation.start();
- }
-
// called from onResume every other time
public void initializeSecondTime(Camera.Parameters params) {
initializeZoom(params);
@@ -790,19 +706,16 @@ public class PhotoUI extends BaseUI implements PieListener,
} else if (!mController.isCameraIdle()) {
// ignore backs while we're taking a picture
return true;
- } if (mSwitcher != null && mSwitcher.showsPopup()) {
- mSwitcher.closePopup();
- return true;
- } else {
- return false;
}
+ mCameraControls.collapse();
+ return false;
}
public void onPreviewFocusChanged(boolean previewFocused) {
if (previewFocused) {
showUI();
} else {
- hideUI();
+ hideUI(true);
}
if (mFaceView != null) {
mFaceView.setBlockDraw(!previewFocused);
@@ -1014,7 +927,7 @@ public class PhotoUI extends BaseUI implements PieListener,
public boolean collapseCameraControls() {
// TODO: Mode switcher should behave like a popup and should hide itself when there
// is a touch outside of it.
- mSwitcher.closePopup();
+ mCameraControls.collapse();
// Remove all the popups/dialog boxes
boolean ret = false;
if (mMenu != null) {
@@ -1034,11 +947,9 @@ public class PhotoUI extends BaseUI implements PieListener,
mDecodeTaskForReview = new DecodeImageForReview(jpegData, orientation, mirror);
mDecodeTaskForReview.execute();
mOnScreenIndicators.setVisibility(View.GONE);
- mMenuButton.setVisibility(View.GONE);
CameraUtil.fadeIn(mReviewDoneButton);
mShutterButton.setVisibility(View.INVISIBLE);
CameraUtil.fadeIn(mReviewRetakeButton);
- mMenu.hideTopMenu(true);
}
protected void hidePostCaptureAlert() {
@@ -1048,10 +959,6 @@ public class PhotoUI extends BaseUI implements PieListener,
}
mReviewImage.setVisibility(View.GONE);
mOnScreenIndicators.setVisibility(View.VISIBLE);
- mMenuButton.setVisibility(View.VISIBLE);
- if (mMenu != null) {
- mMenu.hideTopMenu(false);
- }
CameraUtil.fadeOut(mReviewDoneButton);
mShutterButton.setVisibility(View.VISIBLE);
CameraUtil.fadeOut(mReviewRetakeButton);
@@ -1130,7 +1037,7 @@ public class PhotoUI extends BaseUI implements PieListener,
mFaceView.setBlockDraw(true);
}
// Close module selection menu when pie menu is opened.
- mSwitcher.closePopup();
+ mCameraControls.collapse();
}
@Override
@@ -1217,15 +1124,6 @@ public class PhotoUI extends BaseUI implements PieListener,
mNotSelectableToast.show();
}
- public boolean isPreviewCoverVisible() {
- if ((mPreviewCover != null) &&
- (mPreviewCover.getVisibility() == View.VISIBLE)) {
- return true;
- } else {
- return false;
- }
- }
-
public void onPause() {
cancelCountDown();
@@ -1399,12 +1297,12 @@ public class PhotoUI extends BaseUI implements PieListener,
}
public void hideUIWhileCountDown() {
- mMenu.hideCameraControls(true);
+ mCameraControls.hideCameraSettings();
mGestures.setZoomOnly(true);
}
public void showUIAfterCountDown() {
- mMenu.hideCameraControls(false);
+ mCameraControls.showCameraSettings();
mGestures.setZoomOnly(false);
}
}
diff --git a/src/com/android/camera/ShutterButton.java b/src/com/android/camera/ShutterButton.java
index 1a98db4..9ee1bc6 100644
--- a/src/com/android/camera/ShutterButton.java
+++ b/src/com/android/camera/ShutterButton.java
@@ -17,6 +17,7 @@
package com.android.camera;
import android.content.Context;
+import android.util.ArraySet;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -31,10 +32,14 @@ import android.widget.ImageView;
*/
public class ShutterButton extends ImageView {
+ private final ArraySet<OnShutterButtonListener> mListeners = new ArraySet<>();
+
private class LongClickListener implements View.OnLongClickListener {
public boolean onLongClick(View v) {
- if ( null != mListener ) {
- mListener.onShutterButtonLongClick();
+ if (mListeners.size() > 0) {
+ for (OnShutterButtonListener l : mListeners) {
+ l.onShutterButtonLongClick();
+ }
return true;
}
return false;
@@ -58,16 +63,25 @@ public class ShutterButton extends ImageView {
void onShutterButtonLongClick();
}
- private OnShutterButtonListener mListener;
private boolean mOldPressed;
public ShutterButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
- public void setOnShutterButtonListener(OnShutterButtonListener listener) {
- mListener = listener;
- setOnLongClickListener(mLongClick);
+ public void addOnShutterButtonListener(OnShutterButtonListener listener) {
+ mListeners.add(listener);
+ if (mListeners.size() == 1) {
+ setOnLongClickListener(mLongClick);
+ }
+ }
+
+ public void removeOnShutterButtonListener(OnShutterButtonListener listener) {
+ boolean hadListeners = mListeners.size() == 1;
+ mListeners.remove(listener);
+ if (hadListeners && mListeners.size() == 0) {
+ setOnLongClickListener(null);
+ }
}
@Override
@@ -130,16 +144,20 @@ public class ShutterButton extends ImageView {
}
private void callShutterButtonFocus(boolean pressed) {
- if (mListener != null) {
- mListener.onShutterButtonFocus(pressed);
+ if (mListeners.size() > 0) {
+ for (OnShutterButtonListener l : mListeners) {
+ l.onShutterButtonFocus(pressed);
+ }
}
}
@Override
public boolean performClick() {
boolean result = super.performClick();
- if (mListener != null && getVisibility() == View.VISIBLE) {
- mListener.onShutterButtonClick();
+ if (mListeners.size() > 0 && getVisibility() == View.VISIBLE) {
+ for (OnShutterButtonListener l : mListeners) {
+ l.onShutterButtonClick();
+ }
}
return result;
}
diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java
index 6b06a11..82d8c8a 100644
--- a/src/com/android/camera/VideoMenu.java
+++ b/src/com/android/camera/VideoMenu.java
@@ -21,37 +21,33 @@ import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.content.Context;
import android.content.res.Resources;
-import android.content.SharedPreferences;
import android.graphics.Rect;
-import android.preference.PreferenceManager;
-import android.util.Log;
+import android.text.TextUtils;
+import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
-import android.widget.ListView;
-import android.widget.TextView;
-import android.widget.GridView;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
+import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
-import com.android.camera.ui.ListSubMenu;
import com.android.camera.ui.ListMenu;
-import com.android.camera.ui.TimeIntervalPopup;
-import com.android.camera.ui.RotateImageView;
-import com.android.camera.ui.RotateTextToast;
-import org.codeaurora.snapcam.R;
-import android.widget.HorizontalScrollView;
-import android.widget.Toast;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.Display;
+import com.android.camera.ui.ListSubMenu;
import com.android.camera.ui.RotateLayout;
+import com.android.camera.ui.RotateTextToast;
+import com.android.camera.ui.TimeIntervalPopup;
import com.android.camera.util.CameraUtil;
-import android.text.TextUtils;
+
+import org.codeaurora.snapcam.R;
+
import java.util.Locale;
public class VideoMenu extends MenuController
@@ -151,7 +147,6 @@ public class VideoMenu extends MenuController
CameraSettings.KEY_VIDEO_TNR_MODE,
CameraSettings.KEY_VIDEO_SNAPSHOT_SIZE
};
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
initSwitchItem(CameraSettings.KEY_CAMERA_ID, mFrontBackSwitcher);
}
@@ -474,8 +469,10 @@ public class VideoMenu extends MenuController
public void initSwitchItem(final String prefKey, View switcher) {
final IconListPreference pref =
(IconListPreference) mPreferenceGroup.findPreference(prefKey);
- if (pref == null)
+ if (pref == null) {
+ mUI.removeControlView(switcher);
return;
+ }
int[] iconIds = pref.getLargeIconIds();
int resid = -1;
@@ -488,7 +485,6 @@ public class VideoMenu extends MenuController
resid = pref.getSingleIcon();
}
((ImageView) switcher).setImageResource(resid);
- switcher.setVisibility(View.VISIBLE);
mPreferences.add(pref);
mPreferenceMap.put(pref, switcher);
switcher.setOnClickListener(new OnClickListener() {
@@ -513,14 +509,14 @@ public class VideoMenu extends MenuController
}
public void initFilterModeButton(View button) {
- button.setVisibility(View.INVISIBLE);
final IconListPreference pref = (IconListPreference) mPreferenceGroup
.findPreference(CameraSettings.KEY_VIDEOCAMERA_COLOR_EFFECT);
- if (pref == null || pref.getValue() == null)
+ if (pref == null || pref.getValue() == null) {
+ mUI.removeControlView(button);
return;
+ }
changeFilterModeControlIcon(pref.getValue());
- button.setVisibility(View.VISIBLE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -813,19 +809,6 @@ public class VideoMenu extends MenuController
}
}
- public void hideUI() {
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
- mFilterModeSwitcher.setVisibility(View.INVISIBLE);
- }
-
- public void showUI() {
- mFrontBackSwitcher.setVisibility(View.VISIBLE);
- final IconListPreference pref = (IconListPreference) mPreferenceGroup
- .findPreference(CameraSettings.KEY_FILTER_MODE);
- if (pref != null) {
- mFilterModeSwitcher.setVisibility(View.VISIBLE);
- }
- }
@Override
// Hit when an item in the first-level popup gets selected, then bring up
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 401e4d7..8f57777 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -56,6 +56,7 @@ import android.view.KeyEvent;
import android.view.OrientationEventListener;
import android.view.SurfaceHolder;
import android.view.View;
+import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;
import android.media.EncoderCapabilities;
@@ -509,7 +510,7 @@ public class VideoModule implements CameraModule,
@Override
public void init(CameraActivity activity, View root) {
mActivity = activity;
- mUI = new VideoUI(activity, this, root);
+ mUI = new VideoUI(activity, this, (ViewGroup) root);
mPreferences = ComboPreferences.get(mActivity);
if (mPreferences == null) {
mPreferences = new ComboPreferences(mActivity);
@@ -1500,11 +1501,8 @@ public class VideoModule implements CameraModule,
if (mMediaRecorderRecording) {
onStopVideoRecording();
return true;
- } else if (mUI.hideSwitcherPopup()) {
- return true;
- } else {
- return mUI.onBackPressed();
}
+ return mUI.onBackPressed();
}
@Override
@@ -2179,9 +2177,6 @@ public class VideoModule implements CameraModule,
Log.v(TAG, "stopVideoRecording");
mStopRecPending = true;
mUI.setSwipingEnabled(true);
- if (!isVideoCaptureIntent()) {
- mUI.showSwitcher();
- }
boolean fail = false;
if (mMediaRecorderRecording) {
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index 5dd51b5..4107af2 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -73,8 +73,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
private static final String TAG = "CAM_VideoUI";
// module fields
private final FocusRing mFocusRing;
- private CameraActivity mActivity;
- private View mRootView;
private SurfaceHolder mSurfaceHolder;
// An review image having same size as preview. It is displayed when
// recording is stopped in capture intent.
@@ -84,14 +82,12 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
private View mReviewPlayButton;
private ShutterButton mShutterButton;
private PauseButton mPauseButton;
- private ModuleSwitcher mSwitcher;
private TextView mRecordingTimeView;
private LinearLayout mLabelsLinearLayout;
private View mTimeLapseLabel;
private RenderOverlay mRenderOverlay;
private PieRenderer mPieRenderer;
private VideoMenu mVideoMenu;
- private CameraControls mCameraControls;
private SettingsPopup mPopup;
private ZoomRenderer mZoomRenderer;
private PreviewGestures mGestures;
@@ -117,13 +113,9 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
private float mAspectRatio = 4f / 3f;
private boolean mAspectRatioResize;
private final AnimationManager mAnimationManager;
- private boolean mUIhidden = false;
private int mPreviewOrientation = -1;
private int mOrientation;
- private int mScreenRatio = CameraUtil.RATIO_UNKNOWN;
- private int mTopMargin = 0;
- private int mBottomMargin = 0;
private RotateImageView mMuteButton;
//Face detection
@@ -137,15 +129,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
SURFACE_VIEW;
}
- public boolean isPreviewCoverVisible() {
- if ((mPreviewCover != null) &&
- (mPreviewCover.getVisibility() == View.VISIBLE)) {
- return true;
- } else {
- return false;
- }
- }
-
private class SettingsPopup extends PopupWindow {
public SettingsPopup(View popup) {
super(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
@@ -183,13 +166,9 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mSurfaceView.setVisibility(View.VISIBLE);
}
- public VideoUI(CameraActivity activity, VideoController controller, View parent) {
- mActivity = activity;
+ public VideoUI(CameraActivity activity, VideoController controller, ViewGroup parent) {
+ super(activity, parent, R.layout.video_module);
mController = controller;
- mRootView = parent;
- mActivity.getLayoutInflater().inflate(R.layout.video_module,
- (ViewGroup) mRootView, true);
- mPreviewCover = mRootView.findViewById(R.id.preview_cover);
// display the view
mSurfaceView = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content);
mSurfaceView.setVisibility(View.VISIBLE);
@@ -238,16 +217,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mFocusRing = (FocusRing) mRootView.findViewById(R.id.focus_ring);
mFlashOverlay = mRootView.findViewById(R.id.flash_overlay);
mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
- mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
- mSwitcher.setCurrentIndex(ModuleSwitcher.VIDEO_MODULE_INDEX);
- mSwitcher.setSwitchListener(mActivity);
- mSwitcher.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- mSwitcher.showPopup();
- mSwitcher.setOrientation(mOrientation, false);
- }
- });
mMuteButton = (RotateImageView)mRootView.findViewById(R.id.mute_button);
mMuteButton.setVisibility(View.VISIBLE);
@@ -273,7 +242,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
initializeControlByIntent();
initializePauseButton();
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
ViewStub faceViewStub = (ViewStub) mRootView
.findViewById(R.id.face_view_stub);
if (faceViewStub != null) {
@@ -285,20 +253,9 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mOrientationResize = false;
mPrevOrientationResize = false;
- Point size = new Point();
- mActivity.getWindowManager().getDefaultDisplay().getRealSize(size);
- mScreenRatio = CameraUtil.determineRatio(size.x, size.y);
- calculateMargins(size);
- mCameraControls.setMargins(mTopMargin, mBottomMargin);
- ((ViewGroup)mRootView).removeView(mRecordingTimeRect);
- }
+ mCameraControls.disableSceneModes();
- private void calculateMargins(Point size) {
- int l = size.x > size.y ? size.x : size.y;
- int tm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_top_margin);
- int bm = mActivity.getResources().getDimensionPixelSize(R.dimen.preview_bottom_margin);
- mTopMargin = l / 4 * tm / (tm + bm);
- mBottomMargin = l / 4 - mTopMargin;
+ ((ViewGroup)mRootView).removeView(mRecordingTimeRect);
}
public void cameraOrientationPreviewResize(boolean orientation){
@@ -328,12 +285,11 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
}
});
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
mOnScreenIndicators = new OnScreenIndicators(mActivity,
mRootView.findViewById(R.id.on_screen_indicators));
mOnScreenIndicators.resetToDefault();
if (mController.isVideoCaptureIntent()) {
- hideSwitcher();
+ mCameraControls.hideSwitcher();
mActivity.getLayoutInflater().inflate(R.layout.review_module_control,
(ViewGroup) mCameraControls);
// Cannot use RotateImageView for "done" and "cancel" button because
@@ -535,41 +491,9 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mAnimationManager.cancelAnimations();
}
- public void hideUI() {
- mSwitcher.closePopup();
- if (mUIhidden)
- return;
- mUIhidden = true;
- mCameraControls.hideUI();
- }
-
- public void showUI() {
- if (!mUIhidden || (mVideoMenu != null && mVideoMenu.isMenuBeingShown()))
- return;
- mUIhidden = false;
- mCameraControls.showUI();
- }
-
- public boolean arePreviewControlsVisible() {
- return !mUIhidden;
- }
-
- public void hideSwitcher() {
- mSwitcher.closePopup();
- mSwitcher.setVisibility(View.INVISIBLE);
- }
-
- public void showSwitcher() {
- mSwitcher.setVisibility(View.VISIBLE);
- }
-
- public void setSwitcherIndex() {
- mSwitcher.setCurrentIndex(ModuleSwitcher.VIDEO_MODULE_INDEX);
- }
-
public boolean collapseCameraControls() {
boolean ret = false;
- mSwitcher.closePopup();
+ mCameraControls.collapse();
if (mVideoMenu != null) {
mVideoMenu.closeAllView();
}
@@ -701,8 +625,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
private void initializeMiscControls() {
mReviewImage = (ImageView) mRootView.findViewById(R.id.review_image);
mShutterButton.setImageResource(R.drawable.btn_new_shutter_video);
- mShutterButton.setOnShutterButtonListener(mController);
- mShutterButton.setVisibility(View.VISIBLE);
+ mShutterButton.addOnShutterButtonListener(mController);
mShutterButton.requestFocus();
mShutterButton.enableTouch(true);
mRecordingTimeView = (TextView) mRootView.findViewById(R.id.recording_time);
@@ -955,7 +878,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
public void onPieOpened(int centerX, int centerY) {
setSwipingEnabled(false);
// Close module selection menu when pie menu is opened.
- mSwitcher.closePopup();
+ mCameraControls.collapse();
}
@Override
@@ -984,28 +907,24 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mOnScreenIndicators.setVisibility(recording ? View.GONE : View.VISIBLE);
if (recording) {
mShutterButton.setImageResource(R.drawable.shutter_button_video_stop);
- hideSwitcher();
+ mCameraControls.hideSwitcher();
mRecordingTimeView.setText("");
((ViewGroup)mRootView).addView(mRecordingTimeRect);
} else {
mShutterButton.setImageResource(R.drawable.btn_new_shutter_video);
if (!mController.isVideoCaptureIntent()) {
- showSwitcher();
+ mCameraControls.showSwitcher();
}
((ViewGroup)mRootView).removeView(mRecordingTimeRect);
}
}
public void hideUIwhileRecording() {
- mCameraControls.setWillNotDraw(true);
- mVideoMenu.hideUI();
+ mCameraControls.hideCameraSettings();
}
public void showUIafterRecording() {
- mCameraControls.setWillNotDraw(false);
- if (!mController.isVideoCaptureIntent()) {
- mVideoMenu.showUI();
- }
+ mCameraControls.showCameraSettings();
}
public void showReviewImage(Bitmap bitmap) {
@@ -1044,7 +963,7 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
if (previewFocused) {
showUI();
} else {
- hideUI();
+ hideUI(true);
}
if (mGestures != null) {
mGestures.setEnabled(previewFocused);
@@ -1147,9 +1066,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.v(TAG, "surfaceChanged: width = " + width + ", height = " + height);
-
- // Make sure preview cover is hidden if preview data is available.
- hidePreviewCover();
}
@Override
@@ -1195,14 +1111,6 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
mVideoMenu.setPreference(key, value);
}
- public boolean hideSwitcherPopup() {
- if (mSwitcher != null && mSwitcher.showsPopup()) {
- mSwitcher.closePopup();
- return true;
- }
- return false;
- }
-
public void setOrientation(int orientation, boolean animation) {
mCameraControls.setOrientation(orientation, animation);
if (mMenuLayout != null)
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index de26670..9b712c6 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -45,7 +45,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;
-import com.android.camera.PhotoModule;
+
import com.android.camera.CameraManager.CameraProxy;
import com.android.camera.app.OrientationManager;
import com.android.camera.data.LocalData;
@@ -53,6 +53,7 @@ import com.android.camera.exif.ExifInterface;
import com.android.camera.ui.RotateTextToast;
import com.android.camera.util.CameraUtil;
import com.android.camera.util.UsageStatistics;
+
import org.codeaurora.snapcam.R;
import java.io.ByteArrayOutputStream;
@@ -70,7 +71,7 @@ public class WideAnglePanoramaModule
public static final int DEFAULT_SWEEP_ANGLE = 160;
public static final int DEFAULT_BLEND_MODE = Mosaic.BLENDTYPE_HORIZONTAL;
- public static final int DEFAULT_CAPTURE_PIXELS = 960 * 720;
+ public static final int DEFAULT_CAPTURE_PIXELS = 1440 * 1080;
private static final int MSG_LOW_RES_FINAL_MOSAIC_READY = 1;
private static final int MSG_GENERATE_FINAL_MOSAIC_ERROR = 2;
@@ -430,7 +431,7 @@ public class WideAnglePanoramaModule
int w = size.width;
// we only want 4:3 format.
int d = DEFAULT_CAPTURE_PIXELS - h * w;
- if (needSmaller && d < 0) { // no bigger preview than 960x720.
+ if (needSmaller && d < 0) {
continue;
}
if (need4To3 && (h * 4 != w * 3)) {
@@ -459,6 +460,7 @@ public class WideAnglePanoramaModule
Log.d(TAG, "camera preview h = "
+ mCameraPreviewHeight + " , w = " + mCameraPreviewWidth);
parameters.setPreviewSize(mCameraPreviewWidth, mCameraPreviewHeight);
+ mUI.setPreviewSize(mCameraPreviewWidth, mCameraPreviewHeight);
List<int[]> frameRates = parameters.getSupportedPreviewFpsRange();
int last = frameRates.size() - 1;
@@ -1161,10 +1163,6 @@ public class WideAnglePanoramaModule
// If panorama is generating low res or high res mosaic, ignore back
// key. So the activity will not be destroyed.
if (mThreadRunning) return true;
-
- if (mUI.hideSwitcherPopup())
- return true;
-
return false;
}
diff --git a/src/com/android/camera/WideAnglePanoramaUI.java b/src/com/android/camera/WideAnglePanoramaUI.java
index 183c2aa..4d48d95 100644
--- a/src/com/android/camera/WideAnglePanoramaUI.java
+++ b/src/com/android/camera/WideAnglePanoramaUI.java
@@ -16,12 +16,7 @@
package com.android.camera;
-import java.lang.reflect.Method;
-
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -34,8 +29,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
-import android.view.Gravity;
import android.view.Display;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
@@ -44,18 +39,19 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.camera.ui.CameraControls;
import com.android.camera.ui.CameraRootView;
import com.android.camera.ui.ModuleSwitcher;
-import com.android.camera.ui.RotateImageView;
import com.android.camera.ui.RotateLayout;
import com.android.camera.ui.RotateTextToast;
import com.android.camera.util.CameraUtil;
+
import org.codeaurora.snapcam.R;
+import java.lang.reflect.Method;
+
/**
* The UI of {@link WideAnglePanoramaModule}.
*/
@@ -68,11 +64,8 @@ public class WideAnglePanoramaUI extends BaseUI implements
@SuppressWarnings("unused")
private static final String TAG = "CAM_WidePanoramaUI";
- private CameraActivity mActivity;
private WideAnglePanoramaController mController;
- private ViewGroup mRootView;
- private ModuleSwitcher mSwitcher;
private FrameLayout mCaptureLayout;
private View mReviewLayout;
private ImageView mReview;
@@ -87,7 +80,6 @@ public class WideAnglePanoramaUI extends BaseUI implements
private ViewGroup mReviewControl;
private TextureView mTextureView;
private ShutterButton mShutterButton;
- private CameraControls mCameraControls;
private ImageView mThumbnail;
private Bitmap mThumbnailBitmap;
@@ -108,19 +100,20 @@ public class WideAnglePanoramaUI extends BaseUI implements
private RotateLayout mPanoFailedDialog;
private Button mPanoFailedButton;
+ private float mAspectRatio = 1.0f;
+
/** Constructor. */
public WideAnglePanoramaUI(
CameraActivity activity,
WideAnglePanoramaController controller,
ViewGroup root) {
- mActivity = activity;
+ super(activity, root, R.layout.panorama_module);
mController = controller;
- mRootView = root;
createContentView();
- mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
- mSwitcher.setCurrentIndex(ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX);
- mSwitcher.setSwitchListener(mActivity);
+
+ mCameraControls.setModuleIndex(ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX);
+
if (!mActivity.isSecureCamera()) {
mThumbnail = (ImageView) mRootView.findViewById(R.id.preview_thumb);
mThumbnail.setOnClickListener(new OnClickListener() {
@@ -132,20 +125,11 @@ public class WideAnglePanoramaUI extends BaseUI implements
});
}
- mSwitcher.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mSwitcher.showPopup();
- mSwitcher.setOrientation(mOrientation, false);
- }
- });
-
- RotateImageView muteButton = (RotateImageView)mRootView.findViewById(R.id.mute_button);
- muteButton.setVisibility(View.GONE);
+ mCameraControls.hideCameraSettings();
}
public void onStartCapture() {
- hideSwitcher();
+ mCameraControls.hideSwitcher();
mShutterButton.setImageResource(R.drawable.shutter_button_stop);
mCaptureIndicator.setVisibility(View.VISIBLE);
showDirectionIndicators(PanoProgressBar.DIRECTION_NONE);
@@ -162,21 +146,6 @@ public class WideAnglePanoramaUI extends BaseUI implements
hideDirectionIndicators();
}
- public void hideSwitcher() {
- mSwitcher.closePopup();
- mSwitcher.setVisibility(View.INVISIBLE);
- }
-
- public void hideUI() {
- hideSwitcher();
- mCameraControls.setVisibility(View.INVISIBLE);
- }
-
- public void showUI() {
- showSwitcher();
- mCameraControls.setVisibility(View.VISIBLE);
- }
-
public void onPreviewFocusChanged(boolean previewFocused) {
if (previewFocused) {
showUI();
@@ -185,18 +154,6 @@ public class WideAnglePanoramaUI extends BaseUI implements
}
}
- public boolean arePreviewControlsVisible() {
- return (mCameraControls.getVisibility() == View.VISIBLE);
- }
-
- public void showSwitcher() {
- mSwitcher.setVisibility(View.VISIBLE);
- }
-
- public void setSwitcherIndex() {
- mSwitcher.setCurrentIndex(ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX);
- }
-
public void setCaptureProgressOnDirectionChangeListener(
PanoProgressBar.OnDirectionChangeListener listener) {
mCaptureProgressBar.setOnDirectionChangeListener(listener);
@@ -353,14 +310,14 @@ public class WideAnglePanoramaUI extends BaseUI implements
}
}
- private void setPanoramaPreviewView() {
+ private void layoutPreview() {
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
Display display = mActivity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
- int height = size.y;
+ int height = size.y - mTopMargin - mBottomMargin;
int xOffset = 0;
int yOffset = 0;
int w = width;
@@ -368,6 +325,7 @@ public class WideAnglePanoramaUI extends BaseUI implements
h = w * 4 / 3;
yOffset = (height - h) / 2;
+ yOffset += mTopMargin;
FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(w, h);
mTextureView.setLayoutParams(param);
@@ -378,12 +336,7 @@ public class WideAnglePanoramaUI extends BaseUI implements
mPreviewBorder.setY(yOffset);
mPreviewYOffset = yOffset;
- int t = mPreviewYOffset;
- int b1 = mTextureView.getBottom() - mPreviewYOffset;
- int r = mTextureView.getRight();
- int b2 = mTextureView.getBottom();
-
- mCameraControls.setPreviewRatio(1.0f, true);
+ mTextureView.layout(0, mPreviewYOffset, mTextureView.getRight(), mTextureView.getBottom());
}
public void resetSavingProgress() {
@@ -430,16 +383,11 @@ public class WideAnglePanoramaUI extends BaseUI implements
}
private void createContentView() {
- LayoutInflater inflator = (LayoutInflater) mActivity
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- inflator.inflate(R.layout.panorama_module, mRootView, true);
-
Resources appRes = mActivity.getResources();
mIndicatorColor = appRes.getColor(R.color.pano_progress_indication);
mReviewBackground = appRes.getColor(R.color.review_background);
mIndicatorColorFast = appRes.getColor(R.color.pano_progress_indication_fast);
- mPreviewCover = mRootView.findViewById(R.id.preview_cover);
mPreviewLayout = mRootView.findViewById(R.id.pano_preview_layout);
mReviewControl = (ViewGroup) mRootView.findViewById(R.id.pano_review_control);
mReviewLayout = mRootView.findViewById(R.id.pano_review_layout);
@@ -462,7 +410,7 @@ public class WideAnglePanoramaUI extends BaseUI implements
mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
mShutterButton.setImageResource(R.drawable.btn_new_shutter);
- mShutterButton.setOnShutterButtonListener(this);
+ mShutterButton.addOnShutterButtonListener(this);
// Hide menu and indicators.
mRootView.findViewById(R.id.menu).setVisibility(View.GONE);
mRootView.findViewById(R.id.on_screen_indicators).setVisibility(View.GONE);
@@ -473,8 +421,6 @@ public class WideAnglePanoramaUI extends BaseUI implements
mTextureView = (TextureView) mRootView.findViewById(R.id.pano_preview_textureview);
mTextureView.setSurfaceTextureListener(this);
mTextureView.addOnLayoutChangeListener(this);
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
- setPanoramaPreviewView();
mWaitingDialog = (RotateLayout) mRootView.findViewById(R.id.waitingDialog);
mPanoFailedDialog = (RotateLayout) mRootView.findViewById(R.id.pano_dialog_layout);
@@ -600,14 +546,6 @@ public class WideAnglePanoramaUI extends BaseUI implements
}
}
- public boolean hideSwitcherPopup() {
- if (mSwitcher != null && mSwitcher.showsPopup()) {
- mSwitcher.closePopup();
- return true;
- }
- return false;
- }
-
public void setOrientation(int orientation, boolean animation) {
mOrientation = orientation;
// '---------`
@@ -698,4 +636,24 @@ public class WideAnglePanoramaUI extends BaseUI implements
mCameraControls.setOrientation(orientation, animation);
RotateTextToast.setOrientation(orientation);
}
+
+ public void setPreviewSize(int width, int height) {
+ if (width == 0 || height == 0) {
+ Log.w(TAG, "Preview size should not be 0.");
+ return;
+ }
+ float ratio;
+ if (width > height) {
+ ratio = (float) width / height;
+ } else {
+ ratio = (float) height / width;
+ }
+
+ if (ratio != mAspectRatio) {
+ mAspectRatio = ratio;
+ }
+
+ layoutPreview();
+ mCameraControls.setPreviewRatio(mAspectRatio, false);
+ }
}
diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java
index a93b417..a5f7db6 100644
--- a/src/com/android/camera/ui/CameraControls.java
+++ b/src/com/android/camera/ui/CameraControls.java
@@ -18,81 +18,68 @@ package com.android.camera.ui;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.drawable.AnimationDrawable;
-import android.graphics.Paint;
-import android.graphics.Rect;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.util.Log;
-import android.view.Gravity;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewPropertyAnimator;
-import android.widget.FrameLayout;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.TextView;
-import java.util.ArrayList;
-import org.codeaurora.snapcam.R;
+import com.android.camera.CameraActivity;
import com.android.camera.CameraManager;
-import com.android.camera.ui.ModuleSwitcher;
-import com.android.camera.ui.RotateImageView;
import com.android.camera.ShutterButton;
import com.android.camera.Storage;
-import com.android.camera.util.CameraUtil;
import com.android.camera.TsMakeupManager;
+import com.android.camera.util.CameraUtil;
+
+import org.codeaurora.snapcam.R;
+
+import java.util.ArrayList;
+import java.util.List;
public class CameraControls extends RotatableLayout {
private static final String TAG = "CAM_Controls";
- private View mBackgroundView;
- private View mShutter;
+ private LinearLayout mTopBar;
+ private LinearLayout mBottomBar;
+
+ private ShutterButton mShutter;
private View mVideoShutter;
- private View mSwitcher;
- private View mMenu;
- private View mMute;
- private View mFrontBackSwitcher;
- private View mHdrSwitcher;
+ private ModuleSwitcher mSwitcher;
private View mTsMakeupSwitcher;
- private View mIndicators;
private View mPreview;
- private View mSceneModeSwitcher;
- private View mFilterModeSwitcher;
- private View mReviewDoneButton;
- private View mReviewCancelButton;
- private View mReviewRetakeButton;
private View mAutoHdrNotice;
private HistogramView mHistogramView;
private ArrowTextView mRefocusToast;
- private int mSize;
+ private View mReviewDoneButton;
+ private View mReviewCancelButton;
+ private View mReviewRetakeButton;
+
+ private final List<View> mViews = new ArrayList<>();
+ private final List<View> mFreeList = new ArrayList<>();
+
private static final int WIDTH_GRID = 5;
private static final int HEIGHT_GRID = 7;
- private boolean mAnimating = false;
- private ArrayList<View> mViewList;
- private static final int FRONT_BACK_INDEX = 0;
- private static final int HDR_INDEX = 1;
- private static final int TS_MAKEUP_INDEX = 1;
- private static final int SCENE_MODE_INDEX = 2;
- private static final int FILTER_MODE_INDEX = 3;
- private static final int MENU_INDEX = 4;
- private static final int SWITCHER_INDEX = 5;
- private static final int SHUTTER_INDEX = 6;
- private static final int PREVIEW_INDEX = 7;
- private static final int INDICATOR_INDEX = 8;
- private static final int MUTE_INDEX = 9;
- private static final int VIDEO_SHUTTER_INDEX = 10;
- private static final int HISTOGRAM_INDEX = 11;
- private static final int AUTO_HDR_INDEX = 12;
+ private boolean mHidden = false;
+ private AnimatorSet mAnimator = null;
+ private boolean mFullyHidden = false;
+
private static final int ANIME_DURATION = 300;
- private float[][] mLocX = new float[4][13];
- private float[][] mLocY = new float[4][13];
- private boolean mLocSet = false;
+
private boolean mHideRemainingPhoto = false;
private LinearLayout mRemainingPhotos;
private TextView mRemainingPhotosText;
@@ -100,94 +87,37 @@ public class CameraControls extends RotatableLayout {
private int mOrientation;
private int mPreviewRatio;
- private static int mTopMargin = 0;
- private static int mBottomMargin = 0;
-
- private Paint mPaint;
+ private int mTopMargin = 0;
+ private int mBottomMargin = 0;
private static final int LOW_REMAINING_PHOTOS = 20;
private static final int HIGH_REMAINING_PHOTOS = 1000000;
- AnimatorListener outlistener = new AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
+ private int mModuleIndex = -1;
+ AnimatorListener outlistener = new AnimatorListenerAdapter() {
@Override
- public void onAnimationRepeat(Animator animation) {
-
+ public void onAnimationStart(Animator animation) {
+ enableTouch(false);
}
-
@Override
public void onAnimationEnd(Animator animation) {
- resetLocation(0, 0);
-
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(View.INVISIBLE);
- } else {
- mHdrSwitcher.setVisibility(View.INVISIBLE);
- }
- mSceneModeSwitcher.setVisibility(View.INVISIBLE);
- mFilterModeSwitcher.setVisibility(View.INVISIBLE);
-
- mSwitcher.setVisibility(View.INVISIBLE);
- mShutter.setVisibility(View.INVISIBLE);
- mVideoShutter.setVisibility(View.INVISIBLE);
- mMenu.setVisibility(View.INVISIBLE);
- mMute.setVisibility(View.INVISIBLE);
- mIndicators.setVisibility(View.INVISIBLE);
- mPreview.setVisibility(View.INVISIBLE);
- mAnimating = false;
- enableTouch(true);
- }
-
- @Override
- public void onAnimationCancel(Animator animation) {
- resetLocation(0, 0);
-
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(View.INVISIBLE);
- } else {
- mHdrSwitcher.setVisibility(View.INVISIBLE);
+ if (mFullyHidden) {
+ setVisibility(View.INVISIBLE);
}
- mSceneModeSwitcher.setVisibility(View.INVISIBLE);
- mFilterModeSwitcher.setVisibility(View.INVISIBLE);
-
- mSwitcher.setVisibility(View.INVISIBLE);
- mShutter.setVisibility(View.INVISIBLE);
- mVideoShutter.setVisibility(View.INVISIBLE);
- mMenu.setVisibility(View.INVISIBLE);
- mMute.setVisibility(View.INVISIBLE);
- mIndicators.setVisibility(View.INVISIBLE);
- mPreview.setVisibility(View.INVISIBLE);
- mAnimating = false;
- enableTouch(true);
}
};
- AnimatorListener inlistener = new AnimatorListener() {
+ AnimatorListener inlistener = new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
+ if (mFullyHidden) {
+ setVisibility(View.VISIBLE);
+ mFullyHidden = false;
+ }
}
-
- @Override
- public void onAnimationRepeat(Animator animation) {
-
- }
-
@Override
public void onAnimationEnd(Animator animation) {
- mAnimating = false;
- resetLocation(0, 0);
- enableTouch(true);
- }
-
- @Override
- public void onAnimationCancel(Animator animation) {
- mAnimating = false;
- resetLocation(0, 0);
enableTouch(true);
}
};
@@ -195,9 +125,6 @@ public class CameraControls extends RotatableLayout {
public CameraControls(Context context, AttributeSet attrs) {
super(context, attrs);
- mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- setWillNotDraw(false);
-
mRefocusToast = new ArrowTextView(context);
addView(mRefocusToast);
setClipChildren(false);
@@ -210,108 +137,150 @@ public class CameraControls extends RotatableLayout {
}
public boolean isAnimating() {
- return mAnimating;
+ return mAnimator != null && mAnimator.isRunning();
}
public void enableTouch(boolean enable) {
- if (enable) {
- ((ShutterButton) mShutter).setPressed(false);
- mVideoShutter.setPressed(false);
- mSwitcher.setPressed(false);
- mMenu.setPressed(false);
- mMute.setPressed(false);
- mFrontBackSwitcher.setPressed(false);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setPressed(false);
- } else {
- mHdrSwitcher.setPressed(false);
+ Log.d(TAG, "ENABLE TOUCH " + enable + " mViews.size=" + mViews.size());
+ for (View v : mViews) {
+ if (v.getVisibility() != View.GONE) {
+ if (enable) {
+ v.setPressed(false);
+ }
+ v.setEnabled(enable);
}
- mSceneModeSwitcher.setPressed(false);
}
-
((ShutterButton) mShutter).enableTouch(enable);
mVideoShutter.setClickable(enable);
- ((ModuleSwitcher) mSwitcher).enableTouch(enable);
- mMenu.setEnabled(enable);
- mMute.setEnabled(enable);
- mFrontBackSwitcher.setEnabled(enable);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setEnabled(enable);
- } else {
- mHdrSwitcher.setEnabled(enable);
- }
- mSceneModeSwitcher.setEnabled(enable);
- mPreview.setEnabled(enable);
-
- }
-
- private void markVisibility() {
- mViewList = new ArrayList<View>();
- if (mFrontBackSwitcher.getVisibility() == View.VISIBLE)
- mViewList.add(mFrontBackSwitcher);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- if (mTsMakeupSwitcher.getVisibility() == View.VISIBLE)
- mViewList.add(mTsMakeupSwitcher);
- } else {
- if (mHdrSwitcher.getVisibility() == View.VISIBLE)
- mViewList.add(mHdrSwitcher);
- }
- if (mSceneModeSwitcher.getVisibility() == View.VISIBLE)
- mViewList.add(mSceneModeSwitcher);
- if (mFilterModeSwitcher.getVisibility() == View.VISIBLE)
- mViewList.add(mFilterModeSwitcher);
- if (mShutter.getVisibility() == View.VISIBLE)
- mViewList.add(mShutter);
- if (mVideoShutter.getVisibility() == View.VISIBLE)
- mViewList.add(mVideoShutter);
- if (mMenu.getVisibility() == View.VISIBLE)
- mViewList.add(mMenu);
- if (mMute.getVisibility() == View.VISIBLE)
- mViewList.add(mMute);
- if (mIndicators.getVisibility() == View.VISIBLE)
- mViewList.add(mIndicators);
- if (mMute.getVisibility() == View.VISIBLE)
- mViewList.add(mMute);
+ mTopBar.setEnabled(enable);
+ mBottomBar.setEnabled(enable);
}
public void removeFromViewList(View view) {
- if(mViewList != null) {
- mViewList.remove(view);
+ synchronized (mFreeList) {
+ if (view == null || !mViews.contains(view)) {
+ return;
+ }
+ mFreeList.add(view);
+ requestLayout();
}
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
- mBackgroundView = findViewById(R.id.blocker);
- mSwitcher = findViewById(R.id.camera_switcher);
- mShutter = findViewById(R.id.shutter_button);
+ mTopBar = (LinearLayout) findViewById(R.id.top_bar);
+ mBottomBar = (LinearLayout) findViewById(R.id.bottom_bar);
+ mSwitcher = (ModuleSwitcher) findViewById(R.id.camera_switcher);
+ mShutter = (ShutterButton) findViewById(R.id.shutter_button);
mVideoShutter = findViewById(R.id.video_button);
- mFrontBackSwitcher = findViewById(R.id.front_back_switcher);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher = findViewById(R.id.ts_makeup_switcher);
- } else {
- mHdrSwitcher = findViewById(R.id.hdr_switcher);
- }
- mMenu = findViewById(R.id.menu);
- mMute = findViewById(R.id.mute_button);
- mIndicators = findViewById(R.id.on_screen_indicators);
+ mTsMakeupSwitcher = findViewById(R.id.ts_makeup_switcher);
mPreview = findViewById(R.id.preview_thumb);
- mSceneModeSwitcher = findViewById(R.id.scene_mode_switcher);
- mFilterModeSwitcher = findViewById(R.id.filter_mode_switcher);
mRemainingPhotos = (LinearLayout) findViewById(R.id.remaining_photos);
mRemainingPhotosText = (TextView) findViewById(R.id.remaining_photos_text);
mAutoHdrNotice = (TextView) findViewById(R.id.auto_hdr_notice);
mHistogramView = (HistogramView) findViewById(R.id.histogram);
+
+ if (!TsMakeupManager.HAS_TS_MAKEUP) {
+ mTopBar.removeView(mTsMakeupSwitcher);
+ }
+
+ for (int i = 0; i < mTopBar.getChildCount(); i++) {
+ mViews.add(mTopBar.getChildAt(i));
+ }
+
+ for (int i = 0; i < mBottomBar.getChildCount(); i++) {
+ mViews.add(mBottomBar.getChildAt(i));
+ }
+
+ mViews.add(mAutoHdrNotice);
+ mViews.add(mHistogramView);
+
+ mShutter.addOnShutterButtonListener(mShutterListener);
+
+ mSwitcher.setSwitchListener((CameraActivity)getContext());
+ mSwitcher.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mSwitcher.showPopup();
+ mSwitcher.setOrientation(mOrientation, false);
+ }
+ });
+ if (mModuleIndex >= 0) {
+ mSwitcher.setCurrentIndex(mModuleIndex);
+ }
+ }
+
+ public void setModuleIndex(int index) {
+ mModuleIndex = index;
+ if (mSwitcher != null) {
+ mSwitcher.setCurrentIndex(index);
+ }
+ }
+
+ public void hideSwitcher() {
+ if (mSwitcher != null) {
+ mSwitcher.closePopup();
+ mSwitcher.setVisibility(View.INVISIBLE);
+ }
+ }
+
+ public void showSwitcher() {
+ if (mSwitcher != null) {
+ mSwitcher.setVisibility(View.VISIBLE);
+ }
+ }
+
+ public void collapse() {
+ if (mSwitcher != null) {
+ mSwitcher.closePopup();
+ }
+ }
+
+ private ShutterButton.OnShutterButtonListener mShutterListener = new ShutterButton.OnShutterButtonListener() {
+ @Override
+ public void onShutterButtonFocus(boolean pressed) {
+ if (pressed) {
+ showRipples(mBottomBar, true);
+ } else {
+ showRipples(mBottomBar, false);
+ }
+ }
+
+ @Override
+ public void onShutterButtonClick() {
+ showRipples(mBottomBar, true);
+ showRipples(mBottomBar, false);
+ }
+
+ @Override
+ public void onShutterButtonLongClick() {
+
+ }
+ };
+
+ public void disableMuteButton() {
+ removeFromViewList(findViewById(R.id.mute_button));
+ }
+
+ public void disableSceneModes() {
+ removeFromViewList(findViewById(R.id.scene_mode_switcher));
+ removeFromViewList(findViewById(R.id.hdr_switcher));
}
@Override
public void onLayout(boolean changed, int l, int t, int r, int b) {
- int orientation = getResources().getConfiguration().orientation;
- int size = getResources().getDimensionPixelSize(R.dimen.camera_controls_size);
- int rotation = getUnifiedRotation();
- adjustBackground();
+ synchronized (mFreeList) {
+ if (mFreeList.size() > 0) {
+ for (View v : mFreeList) {
+ v.setVisibility(View.GONE);
+ removeView(v);
+ mViews.remove(v);
+ }
+ }
+ }
+
// As l,t,r,b are positions relative to parents, we need to convert them
// to child's coordinates
r = r - l;
@@ -322,19 +291,24 @@ public class CameraControls extends RotatableLayout {
View v = getChildAt(i);
v.layout(l, t, r, b);
}
- Rect shutter = new Rect();
- center(mShutter, l, t, r, b, orientation, rotation, shutter, SHUTTER_INDEX);
- mSize = (int) (Math.max(shutter.right - shutter.left, shutter.bottom - shutter.top) * 1.2f);
- center(mBackgroundView, l, t, r, b, orientation, rotation, new Rect(), -1);
- mBackgroundView.setVisibility(View.GONE);
+
+ ViewGroup.LayoutParams lpTop = mTopBar.getLayoutParams();
+ lpTop.height = mTopMargin;
+ mTopBar.setLayoutParams(lpTop);
+ mTopBar.layout(l, t, r, mTopMargin);
+
+ ViewGroup.LayoutParams lpBottom = mBottomBar.getLayoutParams();
+ lpBottom.height = mBottomMargin;
+ mBottomBar.setLayoutParams(lpBottom);
+ mBottomBar.layout(l, b - mBottomMargin, r, b);
+
setLocation(r - l, b - t);
- center(mAutoHdrNotice, l, t + mSize, r,
- t + mSize + mAutoHdrNotice.getMeasuredHeight(),
- orientation, rotation, new Rect(), AUTO_HDR_INDEX);
- center(mHistogramView, l, t + mSize,
- r, t + mSize + mHistogramView.getMeasuredHeight(),
- orientation, rotation, new Rect(), HISTOGRAM_INDEX);
+ mAutoHdrNotice.layout(l, t + mTopMargin,
+ r, t + mTopMargin + mAutoHdrNotice.getMeasuredHeight());
+
+ mHistogramView.layout(l, b - mBottomMargin - mHistogramView.getMeasuredHeight(),
+ r, b - mBottomMargin);
View retake = findViewById(R.id.btn_retake);
if (retake != null) {
@@ -342,9 +316,11 @@ public class CameraControls extends RotatableLayout {
mReviewCancelButton = findViewById(R.id.btn_cancel);
mReviewDoneButton = findViewById(R.id.btn_done);
+ /*
center(mReviewRetakeButton, shutter, rotation);
toLeft(mReviewCancelButton, shutter, rotation);
toRight(mReviewDoneButton, shutter, rotation);
+ */
} else {
mReviewRetakeButton = null;
mReviewCancelButton = null;
@@ -353,48 +329,25 @@ public class CameraControls extends RotatableLayout {
layoutRemaingPhotos();
}
- @Override
- protected void onDraw(Canvas canvas) {
- if (mTopMargin != 0) {
- int rotation = getUnifiedRotation();
- int w = canvas.getWidth(), h = canvas.getHeight();
- switch (rotation) {
- case 90:
- canvas.drawRect(0, 0, mTopMargin, h, mPaint);
- canvas.drawRect(w - mBottomMargin, 0, w, h, mPaint);
- break;
- case 180:
- canvas.drawRect(0, 0, w, mBottomMargin, mPaint);
- canvas.drawRect(0, h - mTopMargin, w, h, mPaint);
- break;
- case 270:
- canvas.drawRect(0, 0, mBottomMargin, h, mPaint);
- canvas.drawRect(w - mTopMargin, 0, w, h, mPaint);
- break;
- default:
- canvas.drawRect(0, 0, w, mTopMargin, mPaint);
- canvas.drawRect(0, h - mBottomMargin, w, h, mPaint);
- break;
+ private void showRipples(final View v, final boolean enable) {
+ v.post(new Runnable() {
+ @Override
+ public void run() {
+ Drawable background = v.getBackground();
+ if (background instanceof RippleDrawable) {
+ RippleDrawable ripple = (RippleDrawable) background;
+ if (enable) {
+ ripple.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
+ } else {
+ ripple.setState(new int[]{});
+ }
+ }
}
- }
+ });
}
private void setLocation(int w, int h) {
int rotation = getUnifiedRotation();
- toIndex(mSwitcher, w, h, rotation, 4, 6, SWITCHER_INDEX);
- toIndex(mVideoShutter, w, h, rotation, 3, 6, VIDEO_SHUTTER_INDEX);
- toIndex(mSceneModeSwitcher, w, h, rotation, 4, 0, SCENE_MODE_INDEX);
- toIndex(mMute, w, h, rotation, 3, 0, MUTE_INDEX);
- toIndex(mIndicators, w, h, rotation, 0, 6, INDICATOR_INDEX);
- toIndex(mFrontBackSwitcher, w, h, rotation, 2, 0, FRONT_BACK_INDEX);
- toIndex(mPreview, w, h, rotation, 0, 6, PREVIEW_INDEX);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- toIndex(mTsMakeupSwitcher, w, h, rotation, 3, 0, TS_MAKEUP_INDEX);
- } else {
- toIndex(mHdrSwitcher, w, h, rotation, 3, 0, HDR_INDEX);
- }
- toIndex(mFilterModeSwitcher, w, h, rotation, 1, 0, FILTER_MODE_INDEX);
- toIndex(mMenu, w, h, rotation, 0, 0, MENU_INDEX);
layoutToast(mRefocusToast, w, h, rotation);
}
@@ -416,7 +369,7 @@ public class CameraControls extends RotatableLayout {
b = t + th;
r = (int) (w / WIDTH_GRID * (WIDTH_GRID - 0.25));
l = r - tw;
- mRefocusToast.setArrow(tw - th / 2, 0, tw, 0, tw, - th / 2);
+ mRefocusToast.setArrow(tw - th / 2, 0, tw, 0, tw, -th / 2);
break;
case 270:
c = (int) (h / WIDTH_GRID * 0.5);
@@ -424,7 +377,7 @@ public class CameraControls extends RotatableLayout {
b = c + th / 2;
l = (int) (w / HEIGHT_GRID * 1.25);
r = l + tw;
- mRefocusToast.setArrow(0, 0, 0, th / 2, - th / 2, 0);
+ mRefocusToast.setArrow(0, 0, 0, th / 2, -th / 2, 0);
break;
default:
l = w / WIDTH_GRID / 4;
@@ -437,512 +390,106 @@ public class CameraControls extends RotatableLayout {
mRefocusToast.layout(l, t, r, b);
}
- private void center(View v, int l, int t, int r, int b, int orientation, int rotation,
- Rect result, int idx) {
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
- int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
- int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
- switch (rotation) {
- case 0:
- // phone portrait; controls bottom
- result.left = (r + l) / 2 - tw / 2 + lp.leftMargin;
- result.right = (r + l) / 2 + tw / 2 - lp.rightMargin;
- result.bottom = b - lp.bottomMargin;
- result.top = b - th + lp.topMargin;
- break;
- case 90:
- // phone landscape: controls right
- result.right = r - lp.rightMargin;
- result.left = r - tw + lp.leftMargin;
- result.top = (b + t) / 2 - th / 2 + lp.topMargin;
- result.bottom = (b + t) / 2 + th / 2 - lp.bottomMargin;
- break;
- case 180:
- // phone upside down: controls top
- result.left = (r + l) / 2 - tw / 2 + lp.leftMargin;
- result.right = (r + l) / 2 + tw / 2 - lp.rightMargin;
- result.top = t + lp.topMargin;
- result.bottom = t + th - lp.bottomMargin;
- break;
- case 270:
- // reverse landscape: controls left
- result.left = l + lp.leftMargin;
- result.right = l + tw - lp.rightMargin;
- result.top = (b + t) / 2 - th / 2 + lp.topMargin;
- result.bottom = (b + t) / 2 + th / 2 - lp.bottomMargin;
- break;
- }
- v.layout(result.left, result.top, result.right, result.bottom);
- if (idx != -1) {
- int idx1 = rotation / 90;
- int idx2 = idx;
- mLocX[idx1][idx2] = result.left;
- mLocY[idx1][idx2] = result.top;
- }
- }
-
- private void resetLocation(float x, float y) {
- int rotation = getUnifiedRotation();
- int idx1 = rotation / 90;
-
- mFrontBackSwitcher.setX(mLocX[idx1][FRONT_BACK_INDEX] + x);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setX(mLocX[idx1][TS_MAKEUP_INDEX] + x);
- } else {
- mHdrSwitcher.setX(mLocX[idx1][HDR_INDEX] + x);
- }
- mSceneModeSwitcher.setX(mLocX[idx1][SCENE_MODE_INDEX] + x);
- mFilterModeSwitcher.setX(mLocX[idx1][FILTER_MODE_INDEX] + x);
- mMenu.setX(mLocX[idx1][MENU_INDEX] + x);
- mMute.setX(mLocX[idx1][MUTE_INDEX] + x);
- mSwitcher.setX(mLocX[idx1][SWITCHER_INDEX] - x);
- mShutter.setX(mLocX[idx1][SHUTTER_INDEX] - x);
- mVideoShutter.setX(mLocX[idx1][VIDEO_SHUTTER_INDEX] - x);
- mIndicators.setX(mLocX[idx1][INDICATOR_INDEX] - x);
- mPreview.setX(mLocX[idx1][PREVIEW_INDEX] - x);
-
- mFrontBackSwitcher.setY(mLocY[idx1][FRONT_BACK_INDEX] + y);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setY(mLocY[idx1][TS_MAKEUP_INDEX] + y);
- } else {
- mHdrSwitcher.setY(mLocY[idx1][HDR_INDEX] + y);
- }
- mSceneModeSwitcher.setY(mLocY[idx1][SCENE_MODE_INDEX] + y);
- mFilterModeSwitcher.setY(mLocY[idx1][FILTER_MODE_INDEX] + y);
- mMenu.setY(mLocY[idx1][MENU_INDEX] + y);
- mMute.setY(mLocY[idx1][MUTE_INDEX] + y);
- mSwitcher.setY(mLocY[idx1][SWITCHER_INDEX] - y);
- mShutter.setY(mLocY[idx1][SHUTTER_INDEX] - y);
- mVideoShutter.setY(mLocY[idx1][VIDEO_SHUTTER_INDEX] - y);
- mIndicators.setY(mLocY[idx1][INDICATOR_INDEX] - y);
- mPreview.setY(mLocY[idx1][PREVIEW_INDEX] - y);
- }
-
- public void setTitleBarVisibility(int status){
- mFrontBackSwitcher.setVisibility(status);
- mMenu.setVisibility(status);
- mSceneModeSwitcher.setVisibility(status);
- mFilterModeSwitcher.setVisibility(status);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(status);
- } else {
- mHdrSwitcher.setVisibility(status);
- }
+ public void setTitleBarVisibility(int status) {
+ mTopBar.setVisibility(status);
}
public void setAutoHdrEnabled(boolean enabled) {
mAutoHdrNotice.setVisibility(enabled ? View.VISIBLE : View.GONE);
}
- public void hideUI() {
- if (!mAnimating)
- enableTouch(false);
- mAnimating = true;
+ private ObjectAnimator getViewAnimation(View v, float distance, boolean vertical) {
+ final ObjectAnimator anim = ObjectAnimator.ofFloat(v,
+ (vertical ? "translationY" : "translationX"), distance);
+ anim.setDuration(ANIME_DURATION);
+ return anim;
+ }
+
+ private void animateViews(boolean enabled, boolean full, AnimatorListener listener) {
int rotation = getUnifiedRotation();
- mFrontBackSwitcher.animate().cancel();
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().cancel();
- } else {
- mHdrSwitcher.animate().cancel();
- }
- mSceneModeSwitcher.animate().cancel();
- mFilterModeSwitcher.animate().cancel();
- mSwitcher.animate().cancel();
- mShutter.animate().cancel();
- mVideoShutter.animate().cancel();
- mMenu.animate().cancel();
- mMute.animate().cancel();
- mIndicators.animate().cancel();
- mPreview.animate().cancel();
- mFrontBackSwitcher.animate().setListener(outlistener);
- ((ModuleSwitcher) mSwitcher).removePopup();
- resetLocation(0, 0);
- markVisibility();
+ int topSize = enabled ? 0 : -mTopMargin;
+ int bottomSize = enabled ? 0 : mBottomMargin;
+ boolean vertical = true;
switch (rotation) {
case 0:
- mFrontBackSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
break;
case 90:
- mFrontBackSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
+ vertical = false;
break;
case 180:
- mFrontBackSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
+ topSize = -topSize;
+ bottomSize = -bottomSize;
break;
case 270:
- mFrontBackSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
+ topSize = -topSize;
+ bottomSize = -bottomSize;
+ vertical = false;
break;
}
- //mRemainingPhotos.setVisibility(View.INVISIBLE);
- mRefocusToast.setVisibility(View.GONE);
- }
- public void showUI() {
- if (!mAnimating)
- enableTouch(false);
- mAnimating = true;
- int rotation = getUnifiedRotation();
- mFrontBackSwitcher.animate().cancel();
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().cancel();
+ mAnimator = new AnimatorSet();
+ mAnimator.addListener(listener);
+ mAnimator.setDuration(ANIME_DURATION);
+ mAnimator.setInterpolator(enabled ?
+ new DecelerateInterpolator() :
+ new AccelerateInterpolator());
+
+ if (full) {
+ mAnimator.playTogether(getViewAnimation(mTopBar, topSize, vertical),
+ getViewAnimation(mBottomBar, bottomSize, vertical));
} else {
- mHdrSwitcher.animate().cancel();
- }
- mSceneModeSwitcher.animate().cancel();
- mFilterModeSwitcher.animate().cancel();
- mSwitcher.animate().cancel();
- mShutter.animate().cancel();
- mVideoShutter.animate().cancel();
- mMenu.animate().cancel();
- mMute.animate().cancel();
- mIndicators.animate().cancel();
- mPreview.animate().cancel();
- if (mViewList != null)
- for (View v : mViewList) {
- v.setVisibility(View.VISIBLE);
+ final ArrayList<ObjectAnimator> anims = new ArrayList<>();
+ for (int i = 0; i < mBottomBar.getChildCount(); i++) {
+ View v = mBottomBar.getChildAt(i);
+ if (v.getVisibility() != View.GONE) {
+ anims.add(getViewAnimation(v, bottomSize, vertical));
+ }
}
- ((ModuleSwitcher) mSwitcher).removePopup();
- AnimationDrawable shutterAnim = (AnimationDrawable) mShutter.getBackground();
- if (shutterAnim != null)
- shutterAnim.stop();
+ if (anims.size() > 0) {
+ mAnimator.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
+ }
+ }
+ mAnimator.start();
+ }
- mMenu.setVisibility(View.VISIBLE);
- mIndicators.setVisibility(View.VISIBLE);
- mPreview.setVisibility(View.VISIBLE);
+ public void hideUI(boolean toBlack) {
+ if (mHidden) {
+ return;
+ }
- mFrontBackSwitcher.animate().setListener(inlistener);
- switch (rotation) {
- case 0:
- resetLocation(0, -mSize);
+ mHidden = true;
+ mFullyHidden = toBlack;
- mFrontBackSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- break;
- case 90:
- resetLocation(-mSize, 0);
+ if (isAnimating()) {
+ mAnimator.cancel();
+ }
- mFrontBackSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- break;
- case 180:
- resetLocation(0, mSize);
+ collapse();
- mFrontBackSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationYBy(-mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationYBy(mSize).setDuration(ANIME_DURATION);
- break;
- case 270:
- resetLocation(mSize, 0);
+ animateViews(false, toBlack, outlistener);
- mFrontBackSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- } else {
- mHdrSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- }
- mSceneModeSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mFilterModeSwitcher.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mMenu.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
- mMute.animate().translationXBy(-mSize).setDuration(ANIME_DURATION);
-
- mSwitcher.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mShutter.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mVideoShutter.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mIndicators.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- mPreview.animate().translationXBy(mSize).setDuration(ANIME_DURATION);
- break;
- }
- if ((mRemainingPhotos.getVisibility() == View.INVISIBLE) &&
- !mHideRemainingPhoto){
- mRemainingPhotos.setVisibility(View.VISIBLE);
- }
+ mRemainingPhotos.setVisibility(View.INVISIBLE);
mRefocusToast.setVisibility(View.GONE);
}
- private void center(View v, Rect other, int rotation) {
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
- int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
- int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
- int cx = (other.left + other.right) / 2;
- int cy = (other.top + other.bottom) / 2;
- v.layout(cx - tw / 2 + lp.leftMargin,
- cy - th / 2 + lp.topMargin,
- cx + tw / 2 - lp.rightMargin,
- cy + th / 2 - lp.bottomMargin);
- }
-
- private void toIndex(View v, int w, int h, int rotation, int index, int index2, int index3) {
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
- int tw = v.getMeasuredWidth();
- int th = v.getMeasuredHeight();
- int l = 0, r = 0, t = 0, b = 0;
-
- int wnumber = WIDTH_GRID;
- int hnumber = HEIGHT_GRID;
- int windex = 0;
- int hindex = 0;
- switch (rotation) {
- case 0:
- // portrait, to left of anchor at bottom
- wnumber = WIDTH_GRID;
- hnumber = HEIGHT_GRID;
- windex = index;
- hindex = index2;
- break;
- case 90:
- // phone landscape: below anchor on right
- wnumber = HEIGHT_GRID;
- hnumber = WIDTH_GRID;
- windex = index2;
- hindex = hnumber - index - 1;
- break;
- case 180:
- // phone upside down: right of anchor at top
- wnumber = WIDTH_GRID;
- hnumber = HEIGHT_GRID;
- windex = wnumber - index - 1;
- hindex = hnumber - index2 - 1;
- break;
- case 270:
- // reverse landscape: above anchor on left
- wnumber = HEIGHT_GRID;
- hnumber = WIDTH_GRID;
- windex = wnumber - index2 - 1;
- hindex = index;
- break;
- }
- int boxh = h / hnumber;
- int boxw = w / wnumber;
- int cx = (2 * windex + 1) * boxw / 2;
- int cy = (2 * hindex + 1) * boxh / 2;
-
- if (index2 == 0 && mTopMargin != 0) {
- switch (rotation) {
- case 90:
- cx = mTopMargin / 2;
- break;
- case 180:
- cy = h - mTopMargin / 2;
- break;
- case 270:
- cx = w - mTopMargin / 2;
- break;
- default:
- cy = mTopMargin / 2;
- break;
- }
+ public void showUI() {
+ if (!mHidden) {
+ return;
}
- l = cx - tw / 2;
- r = cx + tw / 2;
- t = cy - th / 2;
- b = cy + th / 2;
+ mHidden = false;
- if (index3 != -1) {
- int idx1 = rotation / 90;
- int idx2 = index3;
- mLocX[idx1][idx2] = l;
- mLocY[idx1][idx2] = t;
+ if (isAnimating()) {
+ mAnimator.cancel();
}
- v.layout(l, t, r, b);
- }
- private void toLeft(View v, Rect other, int rotation) {
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
- int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
- int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
- int cx = (other.left + other.right) / 2;
- int cy = (other.top + other.bottom) / 2;
- int l = 0, r = 0, t = 0, b = 0;
- switch (rotation) {
- case 0:
- // portrait, to left of anchor at bottom
- l = other.left - tw + lp.leftMargin;
- r = other.left - lp.rightMargin;
- t = cy - th / 2 + lp.topMargin;
- b = cy + th / 2 - lp.bottomMargin;
- break;
- case 90:
- // phone landscape: below anchor on right
- l = cx - tw / 2 + lp.leftMargin;
- r = cx + tw / 2 - lp.rightMargin;
- t = other.bottom + lp.topMargin;
- b = other.bottom + th - lp.bottomMargin;
- break;
- case 180:
- // phone upside down: right of anchor at top
- l = other.right + lp.leftMargin;
- r = other.right + tw - lp.rightMargin;
- t = cy - th / 2 + lp.topMargin;
- b = cy + th / 2 - lp.bottomMargin;
- break;
- case 270:
- // reverse landscape: above anchor on left
- l = cx - tw / 2 + lp.leftMargin;
- r = cx + tw / 2 - lp.rightMargin;
- t = other.top - th + lp.topMargin;
- b = other.top - lp.bottomMargin;
- break;
- }
- v.layout(l, t, r, b);
- }
+ animateViews(true, mFullyHidden, inlistener);
- private void toRight(View v, Rect other, int rotation) {
- FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
- int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
- int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
- int cx = (other.left + other.right) / 2;
- int cy = (other.top + other.bottom) / 2;
- int l = 0, r = 0, t = 0, b = 0;
- switch (rotation) {
- case 0:
- l = other.right + lp.leftMargin;
- r = other.right + tw - lp.rightMargin;
- t = cy - th / 2 + lp.topMargin;
- b = cy + th / 2 - lp.bottomMargin;
- break;
- case 90:
- l = cx - tw / 2 + lp.leftMargin;
- r = cx + tw / 2 - lp.rightMargin;
- t = other.top - th + lp.topMargin;
- b = other.top - lp.bottomMargin;
- break;
- case 180:
- l = other.left - tw + lp.leftMargin;
- r = other.left - lp.rightMargin;
- t = cy - th / 2 + lp.topMargin;
- b = cy + th / 2 - lp.bottomMargin;
- break;
- case 270:
- l = cx - tw / 2 + lp.leftMargin;
- r = cx + tw / 2 - lp.rightMargin;
- t = other.bottom + lp.topMargin;
- b = other.bottom + th - lp.bottomMargin;
- break;
- }
- v.layout(l, t, r, b);
- }
-
- private void adjustBackground() {
- int rotation = getUnifiedRotation();
- // remove current drawable and reset rotation
- mBackgroundView.setBackgroundDrawable(null);
- mBackgroundView.setRotationX(0);
- mBackgroundView.setRotationY(0);
- // if the switcher background is top aligned we need to flip the
- // background
- // drawable vertically; if left aligned, flip horizontally
- switch (rotation) {
- case 180:
- mBackgroundView.setRotationX(180);
- break;
- case 270:
- mBackgroundView.setRotationY(180);
- break;
- default:
- break;
+ if ((mRemainingPhotos.getVisibility() == View.INVISIBLE) &&
+ !mHideRemainingPhoto) {
+ mRemainingPhotos.setVisibility(View.VISIBLE);
}
- mBackgroundView.setBackgroundResource(R.drawable.switcher_bg);
+ mRefocusToast.setVisibility(View.GONE);
}
private void layoutRemaingPhotos() {
@@ -959,7 +506,7 @@ public class CameraControls extends RotatableLayout {
if (mOrientation == 90 || mOrientation == 270) {
vc -= w / 2;
}
- if(hc < w/2) {
+ if (hc < w / 2) {
mRemainingPhotos.layout(0, vc - h / 2, w, vc + h / 2);
} else {
mRemainingPhotos.layout(hc - w / 2, vc - h / 2, hc + w / 2, vc + h / 2);
@@ -986,29 +533,34 @@ public class CameraControls extends RotatableLayout {
mCurrentRemaining = remaining;
}
+ public boolean arePreviewControlsVisible() {
+ return !mHidden;
+ }
+
public void setMargins(int top, int bottom) {
mTopMargin = top;
mBottomMargin = bottom;
}
+ private void setBarsBackground(int resId) {
+ mTopBar.setBackgroundResource(resId);
+ mBottomBar.setBackgroundResource(resId);
+ }
+
public void setPreviewRatio(float ratio, boolean panorama) {
- if (panorama) {
- mPaint.setColor(Color.TRANSPARENT);
+ int r = CameraUtil.determineRatio(ratio);
+ mPreviewRatio = r;
+ if (mPreviewRatio == CameraUtil.RATIO_4_3 && mTopMargin != 0) {
+ setBarsBackground(R.drawable.camera_controls_bg_opaque);
} else {
- int r = CameraUtil.determineRatio(ratio);
- mPreviewRatio = r;
- if (mPreviewRatio == CameraUtil.RATIO_4_3 && mTopMargin != 0) {
- mPaint.setColor(getResources().getColor(R.color.camera_control_bg_opaque));
- } else {
- mPaint.setColor(getResources().getColor(R.color.camera_control_bg_transparent));
- }
+ setBarsBackground(R.drawable.camera_controls_bg_translucent);
}
- invalidate();
+ requestLayout();
}
public void showRefocusToast(boolean show) {
mRefocusToast.setVisibility(show ? View.VISIBLE : View.GONE);
- if ((mCurrentRemaining > 0 ) && !mHideRemainingPhoto) {
+ if ((mCurrentRemaining > 0) && !mHideRemainingPhoto) {
mRemainingPhotos.setVisibility(show ? View.GONE : View.VISIBLE);
}
}
@@ -1024,47 +576,33 @@ public class CameraControls extends RotatableLayout {
public void setOrientation(int orientation, boolean animation) {
mOrientation = orientation;
- View[] views = {
- mSceneModeSwitcher, mFilterModeSwitcher, mFrontBackSwitcher,
- TsMakeupManager.HAS_TS_MAKEUP ? mTsMakeupSwitcher : mHdrSwitcher,
- mMenu, mShutter, mPreview, mSwitcher, mMute, mReviewRetakeButton,
- mReviewCancelButton, mReviewDoneButton, mAutoHdrNotice, mHistogramView
- };
- for (View v : views) {
- if (v != null) {
- if (v instanceof RotateImageView) {
- ((RotateImageView) v).setOrientation(orientation,
- animation);
- } else if (v instanceof HistogramView) {
- ((HistogramView) v).setRotation(-orientation);
- }
+
+ for (View v : mViews) {
+ if (v instanceof RotateImageView) {
+ ((RotateImageView) v).setOrientation(orientation, animation);
+ } else if (v instanceof HistogramView) {
+ ((HistogramView) v).setRotation(-orientation);
}
}
layoutRemaingPhotos();
}
public void hideCameraSettings() {
- mFrontBackSwitcher.setVisibility(View.INVISIBLE);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(View.INVISIBLE);
- } else {
- mHdrSwitcher.setVisibility(View.INVISIBLE);
+ for (int i = 0; i < mTopBar.getChildCount(); i++) {
+ View v = mTopBar.getChildAt(i);
+ if (v.getVisibility() == View.VISIBLE) {
+ mTopBar.getChildAt(i).setVisibility(View.INVISIBLE);
+ }
}
- mSceneModeSwitcher.setVisibility(View.INVISIBLE);
- mFilterModeSwitcher.setVisibility(View.INVISIBLE);
- mMenu.setVisibility(View.INVISIBLE);
}
public void showCameraSettings() {
- mFrontBackSwitcher.setVisibility(View.VISIBLE);
- if(TsMakeupManager.HAS_TS_MAKEUP) {
- mTsMakeupSwitcher.setVisibility(View.VISIBLE);
- } else {
- mHdrSwitcher.setVisibility(View.VISIBLE);
+ for (int i = 0; i < mTopBar.getChildCount(); i++) {
+ View v = mTopBar.getChildAt(i);
+ if (v.getVisibility() == View.INVISIBLE) {
+ mTopBar.getChildAt(i).setVisibility(View.VISIBLE);
+ }
}
- mSceneModeSwitcher.setVisibility(View.VISIBLE);
- mFilterModeSwitcher.setVisibility(View.VISIBLE);
- mMenu.setVisibility(View.VISIBLE);
}
public void hideRemainingPhotoCnt() {
@@ -1088,8 +626,8 @@ public class CameraControls extends RotatableLayout {
setBackgroundColor(BACKGROUND);
setVisibility(View.GONE);
setLayoutParams(new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT));
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
setTextSize(TEXT_SIZE);
setPadding(PADDING_SIZE, PADDING_SIZE, PADDING_SIZE, PADDING_SIZE);
diff --git a/src/com/android/camera/ui/ModuleSwitcher.java b/src/com/android/camera/ui/ModuleSwitcher.java
index 33f20da..a5c1f7c 100644
--- a/src/com/android/camera/ui/ModuleSwitcher.java
+++ b/src/com/android/camera/ui/ModuleSwitcher.java
@@ -16,33 +16,28 @@
package com.android.camera.ui;
-import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
-import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
+import android.view.Gravity;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.View.OnTouchListener;
import android.view.ViewGroup;
-import android.widget.FrameLayout.LayoutParams;
-import android.widget.LinearLayout;
+import android.view.WindowManager;
import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.PopupWindow;
import com.android.camera.util.CameraUtil;
-import com.android.camera.util.GcamHelper;
import com.android.camera.util.PhotoSphereHelper;
import com.android.camera.util.UsageStatistics;
+
import org.codeaurora.snapcam.R;
-public class ModuleSwitcher extends RotateImageView
- implements OnTouchListener {
+public class ModuleSwitcher extends RotateImageView {
@SuppressWarnings("unused")
private static final String TAG = "CAM_Switcher";
@@ -55,9 +50,6 @@ public class ModuleSwitcher extends RotateImageView
public static final int GCAM_MODULE_INDEX = 4;
public static final int CAPTURE_MODULE_INDEX = 5;
- private boolean mTouchEnabled = true;
- private boolean mIsVisible = true;
-
private static final int[] DRAW_IDS = {
R.drawable.ic_switch_camera,
R.drawable.ic_switch_video,
@@ -77,17 +69,11 @@ public class ModuleSwitcher extends RotateImageView
private int[] mModuleIds;
private int[] mDrawIds;
private int mItemSize;
- private View mPopup;
- private View mParent;
- private boolean mShowingPopup;
- private boolean mNeedsAnimationSetup;
- private Drawable mIndicator;
-
- private float mTranslationX = 0;
- private float mTranslationY = 0;
+ private PopupWindow mPopup;
+ private LinearLayout mContent;
- private AnimatorListener mHideAnimationListener;
- private AnimatorListener mShowAnimationListener;
+ private float mTranslationX;
+ private float mTranslationY;
public ModuleSwitcher(Context context) {
super(context);
@@ -101,8 +87,8 @@ public class ModuleSwitcher extends RotateImageView
private void init(Context context) {
mItemSize = context.getResources().getDimensionPixelSize(R.dimen.switcher_size);
- mIndicator = context.getResources().getDrawable(R.color.transparent);
initializeDrawables(context);
+ initPopup();
}
public void initializeDrawables(Context context) {
@@ -149,27 +135,13 @@ public class ModuleSwitcher extends RotateImageView
mListener = l;
}
- @Override
- public boolean dispatchTouchEvent(MotionEvent m) {
- if (mTouchEnabled) {
- return super.dispatchTouchEvent(m);
- } else {
- setBackground(null);
- return false;
- }
- }
-
- public void enableTouch(boolean enable) {
- mTouchEnabled = enable;
- }
-
public void showPopup() {
showSwitcher();
mListener.onShowSwitcherPopup();
}
private void onModuleSelected(int ix) {
- hidePopup();
+ closePopup();
if ((ix != mCurrentIndex) && (mListener != null)) {
UsageStatistics.onEvent("CameraModeSwitch", null, null);
UsageStatistics.setPendingTransitionCause(
@@ -179,28 +151,23 @@ public class ModuleSwitcher extends RotateImageView
}
}
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- mIndicator.setBounds(getDrawable().getBounds());
- mIndicator.draw(canvas);
+ private PopupWindow getPopup() {
+ PopupWindow popup = new PopupWindow(mContent);
+ popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
+ popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
+ // Closes the popup window when touch outside of it - when looses focus
+ popup.setOutsideTouchable(true);
+ popup.setFocusable(true);
+ popup.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
+ popup.setAnimationStyle(android.R.style.Animation_Dialog);
+ return popup;
}
private void initPopup() {
- mParent = LayoutInflater.from(getContext()).inflate(R.layout.switcher_popup,
- (ViewGroup) getParent());
- LinearLayout content = (LinearLayout) mParent.findViewById(R.id.content);
- mPopup = content;
- // Set the gravity of the popup, so that it shows up at the right
- // position
- // on screen
- LayoutParams lp = ((LayoutParams) mPopup.getLayoutParams());
- lp.gravity = ((LayoutParams) mParent.findViewById(R.id.camera_switcher)
- .getLayoutParams()).gravity;
- mPopup.setLayoutParams(lp);
-
- mPopup.setVisibility(View.INVISIBLE);
- mNeedsAnimationSetup = true;
+ mContent = (LinearLayout) LayoutInflater.from(getContext()).inflate(
+ R.layout.switcher_popup, null);
+ mContent.setElevation(6);
+
for (int i = mDrawIds.length - 1; i >= 0; i--) {
RotateImageView item = new RotateImageView(getContext());
item.setImageResource(mDrawIds[i]);
@@ -210,7 +177,7 @@ public class ModuleSwitcher extends RotateImageView
item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- if (showsPopup()) {
+ if (mPopup != null) {
onModuleSelected(index);
}
}
@@ -239,94 +206,37 @@ public class ModuleSwitcher extends RotateImageView
default:
break;
}
- content.addView(item, new LinearLayout.LayoutParams(mItemSize, mItemSize));
- }
- mPopup.measure(MeasureSpec.makeMeasureSpec(mParent.getWidth(), MeasureSpec.AT_MOST),
- MeasureSpec.makeMeasureSpec(mParent.getHeight(), MeasureSpec.AT_MOST));
- }
-
- public boolean showsPopup() {
- return mShowingPopup;
- }
-
- public boolean isInsidePopup(MotionEvent evt) {
- if (!showsPopup()) {
- return false;
+ mContent.addView(item, new LinearLayout.LayoutParams(mItemSize, mItemSize));
}
- int topLeft[] = new int[2];
- mPopup.getLocationOnScreen(topLeft);
- int left = topLeft[0];
- int top = topLeft[1];
- int bottom = top + mPopup.getHeight();
- int right = left + mPopup.getWidth();
- return evt.getX() >= left && evt.getX() < right
- && evt.getY() >= top && evt.getY() < bottom;
- }
-
- private void hidePopup() {
- mShowingPopup = false;
- setVisibility(View.VISIBLE);
- if (mPopup != null && !animateHidePopup()) {
- mPopup.setVisibility(View.INVISIBLE);
- }
- mParent.setOnTouchListener(null);
- }
-
- public void setSwitcherVisibility(boolean isVisible) {
- mIsVisible = isVisible;
- }
-
- public void removePopup() {
- mShowingPopup = false;
- if (mIsVisible) {
- setVisibility(View.VISIBLE);
- }
- if (mPopup != null) {
- ((ViewGroup) mParent).removeView(mPopup);
- mPopup = null;
- }
- setAlpha(1f);
+ mContent.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
}
@Override
public void onConfigurationChanged(Configuration config) {
- if (showsPopup()) {
- ((ViewGroup) mParent).removeView(mPopup);
- mPopup = null;
- initPopup();
- mPopup.setVisibility(View.VISIBLE);
- }
+ closePopup();
}
private void showSwitcher() {
- mShowingPopup = true;
- if (mPopup == null) {
- initPopup();
- }
- layoutPopup();
- mPopup.setVisibility(View.VISIBLE);
- if (!animateShowPopup()) {
- setVisibility(View.INVISIBLE);
- }
- mParent.setOnTouchListener(this);
- }
-
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- closePopup();
- return true;
+ mPopup = getPopup();
+ mPopup.showAsDropDown(this, ((getWidth() / 2) - (mContent.getMeasuredWidth() / 2)),
+ -(mContent.getMeasuredHeight() + Math.round(0.75f * getHeight())),
+ Gravity.TOP);
}
public void closePopup() {
- if (showsPopup()) {
- hidePopup();
+ if (mPopup != null) {
+ mPopup.dismiss();
+ mPopup = null;
}
}
@Override
public void setOrientation(int degree, boolean animate) {
super.setOrientation(degree, animate);
- ViewGroup content = (ViewGroup) mPopup;
+ if (mPopup == null) {
+ return;
+ }
+ ViewGroup content = (ViewGroup) mPopup.getContentView();
if (content == null) {
return;
}
@@ -337,98 +247,36 @@ public class ModuleSwitcher extends RotateImageView
}
private void layoutPopup() {
+ if (mContent == null) {
+ return;
+ }
+
int orientation = CameraUtil.getDisplayRotation((Activity) getContext());
- int w = mPopup.getMeasuredWidth();
- int h = mPopup.getMeasuredHeight();
+ int w = mContent.getMeasuredWidth();
+ int h = mContent.getMeasuredHeight();
+
if (orientation == 0) {
- mPopup.layout(getRight() - w, getBottom() - h, getRight(), getBottom());
+ mContent.layout(getRight() - w, getBottom() - h, getRight(), getBottom());
mTranslationX = 0;
mTranslationY = h / 3;
} else if (orientation == 90) {
mTranslationX = w / 3;
mTranslationY = -h / 3;
- mPopup.layout(getRight() - w, getTop(), getRight(), getTop() + h);
+ mContent.layout(getRight() - w, getTop(), getRight(), getTop() + h);
} else if (orientation == 180) {
mTranslationX = -w / 3;
mTranslationY = -h / 3;
- mPopup.layout(getLeft(), getTop(), getLeft() + w, getTop() + h);
+ mContent.layout(getLeft(), getTop(), getLeft() + w, getTop() + h);
} else {
mTranslationX = -w / 3;
mTranslationY = h - getHeight();
- mPopup.layout(getLeft(), getBottom() - h, getLeft() + w, getBottom());
+ mContent.layout(getLeft(), getBottom() - h, getLeft() + w, getBottom());
}
}
@Override
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
- if (mPopup != null) {
- layoutPopup();
- }
- }
-
- private void popupAnimationSetup() {
layoutPopup();
- mPopup.setScaleX(0.3f);
- mPopup.setScaleY(0.3f);
- mPopup.setTranslationX(mTranslationX);
- mPopup.setTranslationY(mTranslationY);
- mNeedsAnimationSetup = false;
- }
-
- private boolean animateHidePopup() {
- if (mHideAnimationListener == null) {
- mHideAnimationListener = new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- // Verify that we weren't canceled
- if (!showsPopup() && mPopup != null) {
- mPopup.setVisibility(View.INVISIBLE);
- ((ViewGroup) mParent).removeView(mPopup);
- mPopup = null;
- }
- }
- };
- }
- mPopup.animate()
- .alpha(0f)
- .scaleX(0.3f).scaleY(0.3f)
- .translationX(mTranslationX)
- .translationY(mTranslationY)
- .setDuration(SWITCHER_POPUP_ANIM_DURATION)
- .setListener(mHideAnimationListener);
- animate().alpha(1f).setDuration(SWITCHER_POPUP_ANIM_DURATION)
- .setListener(null);
- return true;
- }
-
- private boolean animateShowPopup() {
- if (mNeedsAnimationSetup) {
- popupAnimationSetup();
- }
- if (mShowAnimationListener == null) {
- mShowAnimationListener = new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- // Verify that we weren't canceled
- if (showsPopup()) {
- setVisibility(View.INVISIBLE);
- // request layout to make sure popup is laid out
- // correctly on ICS
- mPopup.requestLayout();
- }
- }
- };
- }
- mPopup.animate()
- .alpha(1f)
- .scaleX(1f).scaleY(1f)
- .translationX(0)
- .translationY(0)
- .setDuration(SWITCHER_POPUP_ANIM_DURATION)
- .setListener(null);
- animate().alpha(0f).setDuration(SWITCHER_POPUP_ANIM_DURATION)
- .setListener(mShowAnimationListener);
- return true;
}
}
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index ba6768e..653cc9a 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -525,7 +525,7 @@ public class CameraUtil {
return orientationHistory;
}
- private static Point getDefaultDisplaySize(Activity activity, Point size) {
+ public static Point getDefaultDisplaySize(Activity activity, Point size) {
activity.getWindowManager().getDefaultDisplay().getSize(size);
//cap the display resolution given to getOptimalPreviewSize if the below properties
//are set. For example if the properties are set as below :