summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBobby Georgescu <georgescu@google.com>2012-09-09 15:15:45 -0700
committerBobby Georgescu <georgescu@google.com>2012-09-10 15:55:54 -0700
commite840cafb77fd7019dc0b7bd41f81289e6ce18600 (patch)
treeb2532d694f7a3a7d059310507b9547974a2b2c44 /src
parent464b7559175f45b488bb24be3d16843f1bf80cd4 (diff)
downloadandroid_packages_apps_Snap-e840cafb77fd7019dc0b7bd41f81289e6ce18600.tar.gz
android_packages_apps_Snap-e840cafb77fd7019dc0b7bd41f81289e6ce18600.tar.bz2
android_packages_apps_Snap-e840cafb77fd7019dc0b7bd41f81289e6ce18600.zip
Improvements to empty album behavior in Gallery
Bug: 7131332 Bug: 7009464 Toasts are now immediately dismissed if a non-empty album is selected, and dismissed once Picasa Albums load at an otherwise empty gallery root. The alert added in a previous prompt has been replaced with a Toast also. Change-Id: Icca79ab264b94979eedcf78e5c3899af745d8813
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/AlbumPage.java8
-rw-r--r--src/com/android/gallery3d/app/AlbumSetPage.java91
2 files changed, 56 insertions, 43 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index f99c95a6d..d9e8d7ee1 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -66,6 +66,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
public static final String KEY_SET_CENTER = "set-center";
public static final String KEY_AUTO_SELECT_ALL = "auto-select-all";
public static final String KEY_SHOW_CLUSTER_MENU = "cluster-menu";
+ public static final String KEY_EMPTY_ALBUM = "empty-album";
public static final String KEY_RESUME_ANIMATION = "resume_animation";
public static final String KEY_FADE_TEXTURE = "fade_texture";
@@ -713,9 +714,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
mLoadingBits &= ~loadTaskBit;
if (mLoadingBits == 0 && mIsActive) {
if (mAlbumDataAdapter.size() == 0) {
- Toast.makeText(mActivity,
- R.string.empty_album, Toast.LENGTH_LONG).show();
- mActivity.getStateManager().finishState(AlbumPage.this);
+ Intent result = new Intent();
+ result.putExtra(KEY_EMPTY_ALBUM, true);
+ setStateResult(Activity.RESULT_OK, result);
+ mActivity.getStateManager().finishState(this);
}
}
}
diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java
index 6a2433870..8dee15431 100644
--- a/src/com/android/gallery3d/app/AlbumSetPage.java
+++ b/src/com/android/gallery3d/app/AlbumSetPage.java
@@ -17,10 +17,7 @@
package com.android.gallery3d.app;
import android.app.Activity;
-import android.app.AlertDialog;
import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
@@ -58,6 +55,8 @@ import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.HelpUtils;
import com.android.gallery3d.util.MediaSetUtils;
+import java.lang.ref.WeakReference;
+
public class AlbumSetPage extends ActivityState implements
SelectionManager.SelectionListener, GalleryActionBar.ClusterRunner,
EyePosition.EyePositionListener, MediaSet.SyncListener {
@@ -207,11 +206,40 @@ public class AlbumSetPage extends ActivityState implements
return album.isCameraRoll() && album.getMediaItemCount() > 0;
}
+ WeakReference<Toast> mEmptyAlbumToast = null;
+
+ private void showEmptyAlbumToast(int toastLength) {
+ Toast toast;
+ if (mEmptyAlbumToast != null) {
+ toast = mEmptyAlbumToast.get();
+ if (toast != null) {
+ toast.show();
+ return;
+ }
+ }
+ toast = Toast.makeText(mActivity, R.string.empty_album, toastLength);
+ mEmptyAlbumToast = new WeakReference<Toast>(toast);
+ toast.show();
+ }
+
+ private void hideEmptyAlbumToast() {
+ if (mEmptyAlbumToast != null) {
+ Toast toast = mEmptyAlbumToast.get();
+ if (toast != null) toast.cancel();
+ }
+ }
+
private void pickAlbum(int slotIndex) {
if (!mIsActive) return;
MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
if (targetSet == null) return; // Content is dirty, we shall reload soon
+ if (targetSet.getTotalMediaItemCount() == 0) {
+ showEmptyAlbumToast(Toast.LENGTH_SHORT);
+ return;
+ }
+ hideEmptyAlbumToast();
+
String mediaPath = targetSet.getPath().toString();
Bundle data = new Bundle(getData());
@@ -314,53 +342,34 @@ public class AlbumSetPage extends ActivityState implements
};
}
+ private boolean mShowedEmptyToastForSelf = false;
private void clearLoadingBit(int loadingBit) {
mLoadingBits &= ~loadingBit;
if (mLoadingBits == 0 && mIsActive) {
if ((mAlbumSetDataAdapter.size() == 0)) {
- // Only show toast when there's no album and we are going to
- // finish, otherwise prompt user to add some pictures
+ // If this is not the top of the gallery folder hierarchy,
+ // tell the parent AlbumSetPage instance to handle displaying
+ // the empty album toast, otherwise show it within this
+ // instance
if (mActivity.getStateManager().getStateCount() > 1) {
- Toast.makeText(mActivity,
- R.string.empty_album, Toast.LENGTH_LONG).show();
+ Intent result = new Intent();
+ result.putExtra(AlbumPage.KEY_EMPTY_ALBUM, true);
+ setStateResult(Activity.RESULT_OK, result);
mActivity.getStateManager().finishState(this);
} else {
- emptyGalleryPrompt(mActivity);
+ mShowedEmptyToastForSelf = true;
+ showEmptyAlbumToast(Toast.LENGTH_LONG);
}
- } else if (mEmptyGalleryPrompt != null) {
- mEmptyGalleryPrompt = null;
+ return;
}
}
- }
-
- private AlertDialog mEmptyGalleryPrompt;
-
- private void emptyGalleryPrompt(final Context c) {
- if (mEmptyGalleryPrompt != null) {
- mEmptyGalleryPrompt.show();
- return;
- }
-
- AlertDialog.Builder builder = new AlertDialog.Builder(c);
- builder.setTitle(R.string.empty_album);
- builder.setNegativeButton(android.R.string.ok, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- if(GalleryUtils.isCameraAvailable(c)) {
- builder.setPositiveButton(R.string.switch_to_camera,
- new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- GalleryUtils.startCameraActivity(c);
- }
- });
+ // Hide the empty album toast if we are in the root instance of
+ // AlbumSetPage and the album is no longer empty (for instance,
+ // after a sync is completed and web albums have been synced)
+ if (mShowedEmptyToastForSelf) {
+ mShowedEmptyToastForSelf = false;
+ hideEmptyAlbumToast();
}
- mEmptyGalleryPrompt = builder.create();
- mEmptyGalleryPrompt.show();
}
private void setLoadingBit(int loadingBit) {
@@ -369,7 +378,6 @@ public class AlbumSetPage extends ActivityState implements
@Override
public void onPause() {
- if (mEmptyGalleryPrompt != null) mEmptyGalleryPrompt.dismiss();
super.onPause();
mIsActive = false;
mActionModeHandler.pause();
@@ -554,6 +562,9 @@ public class AlbumSetPage extends ActivityState implements
@Override
protected void onStateResult(int requestCode, int resultCode, Intent data) {
+ if (data != null && data.getBooleanExtra(AlbumPage.KEY_EMPTY_ALBUM, false)) {
+ showEmptyAlbumToast(Toast.LENGTH_SHORT);
+ }
switch (requestCode) {
case REQUEST_DO_ANIMATION: {
mSlotView.startRisingAnimation();