summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout/filmstrip_bottom_controls.xml2
-rw-r--r--src/com/android/camera/app/FilmstripBottomPanel.java60
-rw-r--r--src/com/android/camera/settings/SettingsManager.java2
-rw-r--r--src/com/android/camera/widget/ExternalViewerButton.java138
4 files changed, 148 insertions, 54 deletions
diff --git a/res/layout/filmstrip_bottom_controls.xml b/res/layout/filmstrip_bottom_controls.xml
index 345b81500..4606a4251 100644
--- a/res/layout/filmstrip_bottom_controls.xml
+++ b/res/layout/filmstrip_bottom_controls.xml
@@ -61,7 +61,7 @@
android:layout_weight="1"
android:visibility="invisible" />
- <ImageButton
+ <com.android.camera.widget.ExternalViewerButton
android:id="@+id/filmstrip_bottom_control_view"
style="@style/FilmstripBottomControlButton"
android:layout_gravity="center"
diff --git a/src/com/android/camera/app/FilmstripBottomPanel.java b/src/com/android/camera/app/FilmstripBottomPanel.java
index 8285ae61a..572ab83e2 100644
--- a/src/com/android/camera/app/FilmstripBottomPanel.java
+++ b/src/com/android/camera/app/FilmstripBottomPanel.java
@@ -16,7 +16,6 @@
package com.android.camera.app;
-import android.util.SparseArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -24,8 +23,8 @@ import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
-import com.android.camera.debug.Log;
import com.android.camera.widget.Cling;
+import com.android.camera.widget.ExternalViewerButton;
import com.android.camera2.R;
/**
@@ -33,14 +32,13 @@ import com.android.camera2.R;
* sphere image and creating a tiny planet from a photo sphere image.
*/
class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
- private static final Log.Tag TAG = new Log.Tag("BottomPanel");
private final AppController mController;
private final ViewGroup mLayout;
private Listener mListener;
private final View mControlLayout;
private ImageButton mEditButton;
- private ImageButton mViewButton;
+ private ExternalViewerButton mViewButton;
private ImageButton mDeleteButton;
private ImageButton mShareButton;
private final View mMiddleFiller;
@@ -50,7 +48,6 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
private TextView mProgressErrorText;
private ProgressBar mProgressBar;
private boolean mTinyPlanetEnabled;
- private final SparseArray<Cling> mClingMap = new SparseArray<Cling>();
public FilmstripBottomPanel(AppController controller, ViewGroup bottomControlsLayout) {
mController = controller;
@@ -71,27 +68,17 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
@Override
public void setClingForViewer(int viewerType, Cling cling) {
- if (cling == null) {
- Log.w(TAG, "Cannot set a null cling for viewer");
- return;
- }
- mClingMap.put(viewerType, cling);
- cling.setReferenceView(mViewButton);
+ mViewButton.setClingForViewer(viewerType, cling);
}
@Override
public void clearClingForViewer(int viewerType) {
- Cling cling = mClingMap.get(viewerType);
- if (cling == null) {
- Log.w(TAG, "Cling does not exist for the given viewer type: " + viewerType);
- }
- cling.setReferenceView(null);
- mClingMap.remove(viewerType);
+ mViewButton.clearClingForViewer(viewerType);
}
@Override
public Cling getClingForViewer(int viewerType) {
- return mClingMap.get(viewerType);
+ return mViewButton.getClingForViewer(viewerType);
}
@Override
@@ -100,7 +87,6 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
mLayout.setVisibility(View.VISIBLE);
} else {
mLayout.setVisibility(View.INVISIBLE);
- hideClings();
}
}
@@ -117,18 +103,7 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
@Override
public void setViewerButtonVisibility(int state) {
- if (state == VIEWER_NONE) {
- mViewButton.setVisibility(View.GONE);
- hideClings();
-
- } else {
- mViewButton.setImageResource(getViewButtonResource(state));
- mViewButton.setVisibility(View.VISIBLE);
- View cling = mClingMap.get(state);
- if (cling != null) {
- cling.setVisibility(View.VISIBLE);
- }
- }
+ mViewButton.setState(state);
updateMiddleFillerLayoutVisibility();
}
@@ -206,26 +181,6 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
mControlLayout.setVisibility(View.INVISIBLE);
}
- /**
- * Sets all the clings to be invisible.
- */
- private void hideClings() {
- for (int i = 0; i < mClingMap.size(); i++) {
- mClingMap.valueAt(i).setVisibility(View.INVISIBLE);
- }
- }
-
- private int getViewButtonResource(int state) {
- switch (state) {
- case VIEWER_REFOCUS:
- return R.drawable.ic_refocus_normal;
- case VIEWER_PHOTO_SPHERE:
- return R.drawable.ic_view_photosphere;
- default:
- return R.drawable.ic_control_play;
- }
- }
-
private void setupEditButton() {
mEditButton = (ImageButton) mLayout.findViewById(R.id.filmstrip_bottom_control_edit);
mEditButton.setOnClickListener(new View.OnClickListener() {
@@ -243,7 +198,8 @@ class FilmstripBottomPanel implements CameraAppUI.BottomPanel {
}
private void setupViewButton() {
- mViewButton = (ImageButton) mLayout.findViewById(R.id.filmstrip_bottom_control_view);
+ mViewButton = (ExternalViewerButton) mLayout.findViewById(
+ R.id.filmstrip_bottom_control_view);
mViewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
diff --git a/src/com/android/camera/settings/SettingsManager.java b/src/com/android/camera/settings/SettingsManager.java
index 402af43c2..16bde79b9 100644
--- a/src/com/android/camera/settings/SettingsManager.java
+++ b/src/com/android/camera/settings/SettingsManager.java
@@ -1149,7 +1149,7 @@ public class SettingsManager {
}
public static Setting getShouldShowRefocusViewerCling(Context context) {
- return new Setting(SOURCE_MODULE, TYPE_BOOLEAN, VALUE_ON,
+ return new Setting(SOURCE_DEFAULT, TYPE_BOOLEAN, VALUE_ON,
KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING, null, FLUSH_OFF);
}
diff --git a/src/com/android/camera/widget/ExternalViewerButton.java b/src/com/android/camera/widget/ExternalViewerButton.java
new file mode 100644
index 000000000..ad467825f
--- /dev/null
+++ b/src/com/android/camera/widget/ExternalViewerButton.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+package com.android.camera.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.SparseArray;
+import android.view.View;
+import android.widget.ImageButton;
+
+import com.android.camera.app.CameraAppUI;
+import com.android.camera.debug.Log;
+import com.android.camera2.R;
+
+/**
+ * This is a custom image button that launches an external viewer. It changes its
+ * image resource based on the current viewer type (photosphere, refocus, etc).
+ * Also, it tracks whether it is shown by tracking the visibility change of all
+ * its ancestors, and keep the visibility of the clings that are registered to the
+ * button in sync.
+ */
+public class ExternalViewerButton extends ImageButton {
+ private static final Log.Tag TAG = new Log.Tag("ExternalViewerButton");
+ private int mState = CameraAppUI.BottomPanel.VIEWER_NONE;
+ private final SparseArray<Cling> mClingMap;
+
+ public ExternalViewerButton(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mClingMap = new SparseArray<Cling>();
+ updateClingVisibility();
+ }
+
+ @Override
+ protected void onVisibilityChanged(View v, int visibility) {
+ super.onVisibilityChanged(v, visibility);
+ if (mClingMap == null) {
+ return;
+ }
+ updateClingVisibility();
+ }
+
+ /**
+ * Sets cling of the given viewer type for external viewer button.
+ */
+ public void setClingForViewer(int viewerType, Cling cling) {
+ if (cling == null) {
+ Log.w(TAG, "Cannot set a null cling for viewer");
+ return;
+ }
+ mClingMap.put(viewerType, cling);
+ cling.setReferenceView(this);
+ }
+
+ /**
+ * Clears cling of the given viewer type for external viewer button.
+ */
+ public void clearClingForViewer(int viewerType) {
+ Cling cling = mClingMap.get(viewerType);
+ if (cling == null) {
+ Log.w(TAG, "Cling does not exist for the given viewer type: " + viewerType);
+ }
+ cling.setReferenceView(null);
+ mClingMap.remove(viewerType);
+ }
+
+ /**
+ * Returns a cling for the specified viewer type.
+ */
+ public Cling getClingForViewer(int viewerType) {
+ return mClingMap.get(viewerType);
+ }
+
+ /**
+ * Sets the current state of the button, which affects the visibility and image
+ * resource of the button.
+ */
+ public void setState(int state) {
+ mState = state;
+ if (state == CameraAppUI.BottomPanel.VIEWER_NONE) {
+ setVisibility(View.GONE);
+ } else {
+ setImageResource(getViewButtonResource(state));
+ setVisibility(View.VISIBLE);
+ }
+ }
+
+ /**
+ * Sets all the clings to be invisible.
+ */
+ private void hideClings() {
+ for (int i = 0; i < mClingMap.size(); i++) {
+ mClingMap.valueAt(i).setVisibility(View.INVISIBLE);
+ }
+ }
+
+ /**
+ * Gets the image resource for a specific state.
+ */
+ private int getViewButtonResource(int state) {
+ switch (state) {
+ case CameraAppUI.BottomPanel.VIEWER_REFOCUS:
+ return R.drawable.ic_refocus_normal;
+ case CameraAppUI.BottomPanel.VIEWER_PHOTO_SPHERE:
+ return R.drawable.ic_view_photosphere;
+ default:
+ return R.drawable.ic_control_play;
+ }
+ }
+
+ /**
+ * Updates the visibility of clings based on whether the button is currently
+ * shown.
+ */
+ private void updateClingVisibility() {
+ if (isShown()) {
+ View cling = mClingMap.get(mState);
+ if (cling != null) {
+ cling.setVisibility(View.VISIBLE);
+ }
+ } else {
+ hideClings();
+ }
+ }
+}