@Override public void onResume() { super.onResume(); mIsActive = true; setContentPane(mRootPane); // Set the reload bit here to prevent it exit this page in clearLoadingBit(). setLoadingBit(BIT_LOADING_RELOAD); mAlbumSetDataAdapter.resume(); mAlbumSetView.resume(); mEyePosition.resume(); mActionModeHandler.resume(); if (mShowClusterMenu) { mActionBar.enableClusterMenu(mSelectedAction, this); } if (!mInitialSynced) { setLoadingBit(BIT_LOADING_SYNC); mSyncTask = mMediaSet.requestSync(AlbumSetPage.this); } // jiangxd add for dockbar if (mActivity instanceof Gallery) { ((Gallery) mActivity).setDockBarVisible(false); } // end }
private void clearLoadingBit(int loadingBit) { mLoadingBits &= ~loadingBit; if (mLoadingBits == 0 && mIsActive) { if (mAlbumSetDataAdapter.size() == 0) { // 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) { Intent result = new Intent(); result.putExtra(AlbumPage.KEY_EMPTY_ALBUM, true); setStateResult(Activity.RESULT_OK, result); mActivity.getStateManager().finishState(this); } else { mShowedEmptyToastForSelf = true; showEmptyAlbumToast(Toast.LENGTH_LONG); mSlotView.invalidate(); showCameraButton(); } return; } } // 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(); hideCameraButton(); } }
private void initializeData(Bundle data) { String mediaPath = data.getString(AlbumSetPage.KEY_MEDIA_PATH); mMediaSet = mActivity.getDataManager().getMediaSet(mediaPath); mSelectionManager.setSourceMediaSet(mMediaSet); mAlbumSetDataAdapter = new AlbumSetDataLoader(mActivity, mMediaSet, DATA_CACHE_SIZE); mAlbumSetDataAdapter.setLoadingListener(new MyLoadingListener()); mAlbumSetView.setModel(mAlbumSetDataAdapter); }
public void onLongTap(int slotIndex) { if (mGetContent || mGetAlbum) return; MediaSet set = mAlbumSetDataAdapter.getMediaSet(slotIndex); if (set == null) return; mSelectionManager.setAutoLeaveSelectionMode(true); mSelectionManager.toggle(set.getPath()); mSlotView.invalidate(); }
@Override protected boolean onItemSelected(MenuItem item) { Activity activity = mActivity; switch (item.getItemId()) { case R.id.action_more_image: Uri moreUri = Uri.parse(mActivity.getString(R.string.website_for_more_image)); Intent moreIntent = new Intent(Intent.ACTION_VIEW, moreUri); mActivity.startActivity(moreIntent); return true; case R.id.action_cancel: activity.setResult(Activity.RESULT_CANCELED); activity.finish(); return true; case R.id.action_select: mSelectionManager.setAutoLeaveSelectionMode(false); mSelectionManager.enterSelectionMode(); return true; case R.id.action_details: if (mAlbumSetDataAdapter.size() != 0) { if (mShowDetails) { hideDetails(); } else { showDetails(); } } else { Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT) .show(); } return true; case R.id.action_camera: { GalleryUtils.startCameraActivity(activity); return true; } case R.id.action_manage_offline: { Bundle data = new Bundle(); String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL); data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath); mActivity.getStateManager().startState(ManageCachePage.class, data); return true; } case R.id.action_sync_picasa_albums: { PicasaSource.requestSync(activity); return true; } case R.id.action_settings: { activity.startActivity(new Intent(activity, GallerySettings.class)); return true; } default: return false; } }
@Override protected boolean onItemSelected(MenuItem item) { Activity activity = mActivity; switch (item.getItemId()) { case R.id.action_cancel: activity.setResult(Activity.RESULT_CANCELED); activity.finish(); return true; case R.id.action_select: mSelectionManager.setAutoLeaveSelectionMode(false); mSelectionManager.enterSelectionMode(); return true; case R.id.action_details: if (mAlbumSetDataAdapter.size() != 0) { if (mShowDetails) { hideDetails(); } else { showDetails(); } } else { Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT) .show(); } return true; case R.id.action_camera: { GalleryUtils.startCameraActivity(activity); return true; } case R.id.action_manage_offline: { Bundle data = new Bundle(); String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL); data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath); mActivity.getStateManager().startState(ManageCachePage.class, data); return true; } case R.id.action_sync_picasa_albums: { PicasaSource.requestSync(activity); return true; } /* Comment out to enable Settings in menu. This should be done when GallerySettings.java has content, as it is currently empty. Also comment out the settings item at albumset.xml menu. case R.id.action_settings: { activity.startActivity(new Intent(activity, GallerySettings.class)); return true; } */ default: return false; } }
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()); int[] center = new int[2]; getSlotCenter(slotIndex, center); data.putIntArray(AlbumPage.KEY_SET_CENTER, center); if (mGetAlbum && targetSet.isLeafAlbum()) { Activity activity = mActivity; Intent result = new Intent().putExtra(AlbumPicker.KEY_ALBUM_PATH, targetSet.getPath().toString()); activity.setResult(Activity.RESULT_OK, result); activity.finish(); } else if (targetSet.getSubMediaSetCount() > 0) { data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath); mActivity .getStateManager() .startStateForResult(AlbumSetPage.class, REQUEST_DO_ANIMATION, data); } else { if (!mGetContent && (targetSet.getSupportedOperations() & MediaObject.SUPPORT_IMPORT) != 0) { data.putBoolean(AlbumPage.KEY_AUTO_SELECT_ALL, true); } else if (!mGetContent && albumShouldOpenInFilmstrip(targetSet)) { data.putParcelable( PhotoPage.KEY_OPEN_ANIMATION_RECT, mSlotView.getSlotRect(slotIndex, mRootPane)); data.putInt(PhotoPage.KEY_INDEX_HINT, 0); data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mediaPath); data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, true); data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, targetSet.isCameraRoll()); mActivity .getStateManager() .startStateForResult(PhotoPage.class, AlbumPage.REQUEST_PHOTO, data); return; } data.putString(AlbumPage.KEY_MEDIA_PATH, mediaPath); // We only show cluster menu in the first AlbumPage in stack boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class); data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum); mActivity.getStateManager().startStateForResult(AlbumPage.class, REQUEST_DO_ANIMATION, data); } }
public void onSingleTapUp(int slotIndex) { if (!mIsActive) return; if (mSelectionManager.inSelectionMode()) { MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex); if (targetSet == null) return; // Content is dirty, we shall reload soon mSelectionManager.toggle(targetSet.getPath()); mSlotView.invalidate(); } else { // Show pressed-up animation for the single-tap. mAlbumSetView.setPressedIndex(slotIndex); mAlbumSetView.setPressedUp(); mHandler.sendMessageDelayed( mHandler.obtainMessage(MSG_PICK_ALBUM, slotIndex, 0), FadeTexture.DURATION); } }
@Override public void onPause() { super.onPause(); mIsActive = false; mAlbumSetDataAdapter.pause(); mAlbumSetView.pause(); mActionModeHandler.pause(); mEyePosition.pause(); DetailsHelper.pause(); // Call disableClusterMenu to avoid receiving callback after paused. // Don't hide menu here otherwise the list menu will disappear earlier than // the action bar, which is janky and unwanted behavior. mActionBar.disableClusterMenu(false); if (mSyncTask != null) { mSyncTask.cancel(); mSyncTask = null; clearLoadingBit(BIT_LOADING_SYNC); } }