OSDN Git Service

Add camera icon for camera roll.
authorChih-Chung Chang <chihchung@google.com>
Thu, 3 May 2012 09:53:05 +0000 (17:53 +0800)
committerChih-Chung Chang <chihchung@google.com>
Thu, 3 May 2012 10:28:08 +0000 (18:28 +0800)
Bug: 6411709
Change-Id: I2476dba7edb2b763f3b7727f0034fa300cf0287a

res/menu/album.xml
src/com/android/gallery3d/app/AlbumPage.java
src/com/android/gallery3d/app/AlbumSetPage.java
src/com/android/gallery3d/util/GalleryUtils.java

index 1e1f6ef..93abcca 100644 (file)
      limitations under the License.
 -->
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:id="@+id/action_camera"
+            android:icon="@drawable/ic_menu_camera_holo_light"
+            android:title="@string/switch_to_camera"
+            android:showAsAction="ifRoom" />
     <item android:id="@+id/action_slideshow"
             android:icon="@drawable/ic_menu_slideshow_holo_light"
             android:title="@string/slideshow"
index 70831b4..3f42aee 100644 (file)
@@ -56,6 +56,7 @@ import com.android.gallery3d.ui.SlotView;
 import com.android.gallery3d.ui.SynchronizedHandler;
 import com.android.gallery3d.util.Future;
 import com.android.gallery3d.util.GalleryUtils;
+import com.android.gallery3d.util.MediaSetUtils;
 
 public class AlbumPage extends ActivityState implements GalleryActionBar.ClusterRunner,
         SelectionManager.SelectionListener, MediaSet.SyncListener {
@@ -470,13 +471,20 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
                 menu.findItem(R.id.action_slideshow).setVisible(true);
             }
 
-            MenuItem groupBy = menu.findItem(R.id.action_group_by);
             FilterUtils.setupMenuItems(actionBar, mMediaSetPath, true);
 
+            MenuItem groupBy = menu.findItem(R.id.action_group_by);
             if (groupBy != null) {
                 groupBy.setVisible(mShowClusterMenu);
             }
 
+            MenuItem switchCamera = menu.findItem(R.id.action_camera);
+            if (switchCamera != null) {
+                switchCamera.setVisible(
+                        MediaSetUtils.isCameraSource(mMediaSetPath)
+                        && GalleryUtils.isCameraAvailable(activity));
+            }
+
             actionBar.setTitle(mMediaSet.getName());
         }
         actionBar.setSubtitle(null);
@@ -519,6 +527,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
                 }
                 return true;
             }
+            case R.id.action_camera: {
+                GalleryUtils.startCameraActivity((Activity) mActivity);
+                return true;
+            }
             default:
                 return false;
         }
index f8274ca..bd88e6c 100644 (file)
@@ -485,10 +485,7 @@ public class AlbumSetPage extends ActivityState implements
                 }
                 return true;
             case R.id.action_camera: {
-                Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
-                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
-                        | Intent.FLAG_ACTIVITY_NEW_TASK);
-                activity.startActivity(intent);
+                GalleryUtils.startCameraActivity(activity);
                 return true;
             }
             case R.id.action_manage_offline: {
index 13e08f9..b9535cb 100644 (file)
@@ -206,6 +206,13 @@ public class GalleryUtils {
         return prefs.getBoolean(KEY_HAS_CAMERA, true);
     }
 
+    public static void startCameraActivity(Context context) {
+        Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
+                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
+                        | Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startActivity(intent);
+    }
+
     public static boolean isValidLocation(double latitude, double longitude) {
         // TODO: change || to && after we fix the default location issue
         return (latitude != MediaItem.INVALID_LATLNG || longitude != MediaItem.INVALID_LATLNG);