import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.view.ActionMode;
import com.android.gallery3d.ui.AlbumSlotRenderer;
import com.android.gallery3d.ui.DetailsHelper;
import com.android.gallery3d.ui.DetailsHelper.CloseListener;
+import com.android.gallery3d.ui.FadeTexture;
import com.android.gallery3d.ui.GLCanvas;
import com.android.gallery3d.ui.GLRoot;
import com.android.gallery3d.ui.GLView;
import com.android.gallery3d.ui.RelativePosition;
-import com.android.gallery3d.ui.ScreenNailHolder;
import com.android.gallery3d.ui.SelectionManager;
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 {
@SuppressWarnings("unused")
private static final String TAG = "AlbumPage";
+ private static final int MSG_PICK_PHOTO = 1;
+
public static final String KEY_MEDIA_PATH = "media-path";
public static final String KEY_PARENT_MEDIA_PATH = "parent-media-path";
public static final String KEY_SET_CENTER = "set-center";
private static final int BIT_LOADING_SYNC = 2;
private static final float USER_DISTANCE_METER = 0.3f;
- private static final boolean TEST_CAMERA_PREVIEW = false;
private boolean mIsActive = false;
private AlbumSlotRenderer mAlbumView;
private MediaSet mMediaSet;
private boolean mShowDetails;
private float mUserDistance; // in pixel
+ private Handler mHandler;
private Future<Integer> mSyncTask = null;
}
};
+ // This are the transitions we want:
+ //
+ // +--------+ +------------+ +-------+ +----------+
+ // | Camera |---------->| Fullscreen |--->| Album |--->| AlbumSet |
+ // | View | thumbnail | Photo | up | Page | up | Page |
+ // +--------+ +------------+ +-------+ +----------+
+ // ^ | | ^ |
+ // | | | | | close
+ // +----------back--------+ +----back----+ +--back-> app
+ //
@Override
protected void onBackPressed() {
if (mShowDetails) {
} else {
// TODO: fix this regression
// mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
+ onUpPressed();
+ }
+ }
+
+ private void onUpPressed() {
+ if (mActivity.getStateManager().getStateCount() > 1) {
super.onBackPressed();
+ } else if (mParentMediaSetString != null) {
+ Bundle data = new Bundle(getData());
+ data.putString(AlbumSetPage.KEY_MEDIA_PATH, mParentMediaSetString);
+ mActivity.getStateManager().switchState(
+ this, AlbumSetPage.class, data);
}
}
mAlbumView.setPressedIndex(index);
}
- private void onUp() {
- mAlbumView.setPressedIndex(-1);
+ private void onUp(boolean followedByLongPress) {
+ if (followedByLongPress) {
+ // Avoid showing press-up animations for long-press.
+ mAlbumView.setPressedIndex(-1);
+ } else {
+ mAlbumView.setPressedUp();
+ }
}
private void onSingleTapUp(int slotIndex) {
- MediaItem item = mAlbumDataAdapter.get(slotIndex);
- if (item == null) {
- Log.w(TAG, "item not ready yet, ignore the click");
- return;
- }
- if (mShowDetails) {
- mAlbumView.setHighlightItemPath(item.getPath());
- mDetailsHelper.reloadDetails(slotIndex);
- } else if (!mSelectionManager.inSelectionMode()) {
- if (mGetContent) {
- onGetContent(item);
- } else {
- // Get into the PhotoPage.
- Bundle data = new Bundle();
+ if (!mIsActive) return;
- // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
- data.putInt(PhotoPage.KEY_INDEX_HINT, slotIndex);
- data.putParcelable(PhotoPage.KEY_OPEN_ANIMATION_RECT,
- getSlotRect(slotIndex));
- data.putString(PhotoPage.KEY_MEDIA_SET_PATH,
- mMediaSetPath.toString());
- data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH,
- item.getPath().toString());
- if (TEST_CAMERA_PREVIEW) {
- ScreenNailHolder holder = new CameraScreenNailHolder(mActivity);
- data.putParcelable(PhotoPage.KEY_SCREENNAIL_HOLDER, holder);
- }
- mActivity.getStateManager().startStateForResult(
- PhotoPage.class, REQUEST_PHOTO, data);
- }
- } else {
+ if (mSelectionManager.inSelectionMode()) {
+ MediaItem item = mAlbumDataAdapter.get(slotIndex);
+ if (item == null) return; // Item not ready yet, ignore the click
mSelectionManager.toggle(item.getPath());
- mDetailsSource.findIndex(slotIndex);
mSlotView.invalidate();
+ } else {
+ // Show pressed-up animation for the single-tap.
+ mAlbumView.setPressedIndex(slotIndex);
+ mAlbumView.setPressedUp();
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_PICK_PHOTO, slotIndex, 0),
+ FadeTexture.DURATION);
+ }
+ }
+
+ private void pickPhoto(int slotIndex) {
+ if (!mIsActive) return;
+
+ MediaItem item = mAlbumDataAdapter.get(slotIndex);
+ if (item == null) return; // Item not ready yet, ignore the click
+ if (mGetContent) {
+ onGetContent(item);
+ } else {
+ // Get into the PhotoPage.
+ // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
+ Bundle data = new Bundle();
+ data.putInt(PhotoPage.KEY_INDEX_HINT, slotIndex);
+ data.putParcelable(PhotoPage.KEY_OPEN_ANIMATION_RECT,
+ getSlotRect(slotIndex));
+ data.putString(PhotoPage.KEY_MEDIA_SET_PATH,
+ mMediaSetPath.toString());
+ data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH,
+ item.getPath().toString());
+ mActivity.getStateManager().startStateForResult(
+ PhotoPage.class, REQUEST_PHOTO, data);
}
}
public void onLongTap(int slotIndex) {
if (mGetContent) return;
- if (mShowDetails) {
- onSingleTapUp(slotIndex);
- } else {
- MediaItem item = mAlbumDataAdapter.get(slotIndex);
- if (item == null) return;
- mSelectionManager.setAutoLeaveSelectionMode(true);
- mSelectionManager.toggle(item.getPath());
- mDetailsSource.findIndex(slotIndex);
- mSlotView.invalidate();
- }
+ MediaItem item = mAlbumDataAdapter.get(slotIndex);
+ if (item == null) return;
+ mSelectionManager.setAutoLeaveSelectionMode(true);
+ mSelectionManager.toggle(item.getPath());
+ mSlotView.invalidate();
}
@Override
mSlotView.startScatteringAnimation(mOpenCenter);
}
}
+
+ mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
+ @Override
+ public void handleMessage(Message message) {
+ switch (message.what) {
+ case MSG_PICK_PHOTO: {
+ pickPhoto(message.arg1);
+ break;
+ }
+ default: throw new AssertionError(message.what);
+ }
+ }
+ };
}
@Override
mSelectionManager = new SelectionManager(mActivity, false);
mSelectionManager.setSelectionListener(this);
Config.AlbumPage config = Config.AlbumPage.get((Context) mActivity);
- mSlotView = new SlotView((Context) mActivity, config.slotViewSpec);
+ mSlotView = new SlotView(mActivity, config.slotViewSpec);
mAlbumView = new AlbumSlotRenderer(mActivity, mSlotView, mSelectionManager);
mSlotView.setSlotRenderer(mAlbumView);
mRootPane.addComponent(mSlotView);
}
@Override
- public void onUp() {
- AlbumPage.this.onUp();
+ public void onUp(boolean followedByLongPress) {
+ AlbumPage.this.onUp(followedByLongPress);
}
@Override
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);
protected boolean onItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
- if (mActivity.getStateManager().getStateCount() > 1) {
- onBackPressed();
- } else if (mParentMediaSetString != null) {
- Bundle data = new Bundle(getData());
- data.putString(AlbumSetPage.KEY_MEDIA_PATH, mParentMediaSetString);
- mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
- }
+ onUpPressed();
return true;
}
case R.id.action_cancel:
}
return true;
}
+ case R.id.action_camera: {
+ GalleryUtils.startCameraActivity((Activity) mActivity);
+ return true;
+ }
default:
return false;
}
}
case REQUEST_PHOTO: {
if (data == null) return;
- mFocusIndex = data.getIntExtra(PhotoPage.KEY_INDEX_HINT, 0);
- mSlotView.setCenterIndex(mFocusIndex);
+ mFocusIndex = data.getIntExtra(PhotoPage.KEY_RETURN_INDEX_HINT, 0);
+ mSlotView.makeSlotVisible(mFocusIndex);
mSlotView.startRestoringAnimation(mFocusIndex);
break;
}