use of com.android.gallery3d.data.ComboAlbum in project android_packages_apps_Gallery2 by LineageOS.
the class PhotoPage method onCreate.
@Override
public void onCreate(Bundle data, Bundle restoreState) {
super.onCreate(data, restoreState);
mActionBar = mActivity.getGalleryActionBar();
mActionBar.setBackGroundTransparent();
mSelectionManager = new SelectionManager(mActivity, false);
mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager);
mPhotoView = new PhotoView(mActivity);
mPhotoView.setListener(this);
mRootPane.addComponent(mPhotoView);
mApplication = (GalleryApp) ((Activity) mActivity).getApplication();
mOrientationManager = mActivity.getOrientationManager();
mActivity.getGLRoot().setOrientationSource(mOrientationManager);
mIsFromVideoScreen = data.getBoolean(KEY_FROM_VIDEOS_SCREEN, false);
mIsFromTimelineScreen = data.getBoolean(KEY_FROM_TIMELINE_SCREEN, false);
mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
@Override
public void handleMessage(Message message) {
switch(message.what) {
case MSG_HIDE_BARS:
{
hideBars();
break;
}
case MSG_REFRESH_BOTTOM_CONTROLS:
{
if (mCurrentPhoto == message.obj && mBottomControls != null) {
mIsPanorama = message.arg1 == 1;
mIsPanorama360 = message.arg2 == 1;
mBottomControls.refresh();
if (null != m3DButton) {
m3DButton.refresh();
}
}
break;
}
case MSG_ON_FULL_SCREEN_CHANGED:
{
if (mAppBridge != null) {
mAppBridge.onFullScreenChanged(message.arg1 == 1);
}
break;
}
case MSG_UPDATE_ACTION_BAR:
{
updateBars();
break;
}
case MSG_WANT_BARS:
{
wantBars();
break;
}
case MSG_UPDATE_DEFERRED:
{
long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis();
if (nextUpdate <= 0) {
mDeferredUpdateWaiting = false;
updateUIForCurrentPhoto();
} else {
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate);
}
break;
}
case MSG_ON_CAMERA_CENTER:
{
mSkipUpdateCurrentPhoto = false;
boolean stayedOnCamera = false;
if (!mPhotoView.getFilmMode()) {
stayedOnCamera = true;
} else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff && mMediaSet.getMediaItemCount() > 1) {
mPhotoView.switchToImage(1);
} else {
if (mAppBridge != null)
mPhotoView.setFilmMode(false);
stayedOnCamera = true;
}
if (stayedOnCamera) {
if (mAppBridge == null && mMediaSet.getTotalMediaItemCount() > 1) {
launchCamera();
/* We got here by swiping from photo 1 to the
placeholder, so make it be the thing that
is in focus when the user presses back from
the camera app */
mPhotoView.switchToImage(1);
} else {
updateBars();
updateCurrentPhoto(mModel.getMediaItem(0));
}
}
break;
}
case MSG_ON_PICTURE_CENTER:
{
if (!mPhotoView.getFilmMode() && mCurrentPhoto != null && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) {
mPhotoView.setFilmMode(true);
}
break;
}
case MSG_REFRESH_IMAGE:
{
final MediaItem photo = mCurrentPhoto;
mCurrentPhoto = null;
updateCurrentPhoto(photo);
break;
}
case MSG_UPDATE_PHOTO_UI:
{
updateUIForCurrentPhoto();
break;
}
case MSG_UPDATE_SHARE_URI:
{
if (mCurrentPhoto == message.obj) {
boolean isPanorama360 = message.arg1 != 0;
Uri contentUri = mCurrentPhoto.getContentUri();
Intent panoramaIntent = null;
if (isPanorama360) {
panoramaIntent = createSharePanoramaIntent(contentUri);
}
Intent shareIntent = createShareIntent(mCurrentPhoto);
if (shareIntent != null) {
mActionBar.setShareIntents(panoramaIntent, shareIntent);
}
setNfcBeamPushUri(contentUri);
}
break;
}
case MSG_UPDATE_PANORAMA_UI:
{
if (mCurrentPhoto == message.obj) {
boolean isPanorama360 = message.arg1 != 0;
updatePanoramaUI(isPanorama360);
}
break;
}
default:
throw new AssertionError(message.what);
}
}
};
mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
mReadOnlyView = data.getBoolean(KEY_READONLY);
mOriginalSetPathString = mSetPathString;
setupNfcBeamPush();
String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath = itemPathString != null ? Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : null;
mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false);
mIsFromWidget = data.getBoolean(KEY_IS_FROM_WIDGET, false);
mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false);
boolean inCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false);
if (restoreState == null || mSetPathString == null) {
mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0);
} else {
mCurrentIndex = restoreState.getInt(KEY_INDEX_HINT, 0);
// we only save index in onSaveState, set itemPath to null to get the right path later
itemPath = null;
}
if ((mCurrentPhoto == null) && (restoreState != null)) {
String curPath = restoreState.getString(KEY_CURRENT_PHOTO_HINT, null);
if (curPath != null)
mCurrentPhoto = (MediaItem) mActivity.getDataManager().getMediaObject(curPath);
}
if (mSetPathString != null) {
mShowSpinner = true;
mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE);
if (mAppBridge != null) {
mShowBars = false;
mHasCameraScreennailOrPlaceholder = true;
mAppBridge.setServer(this);
// Get the ScreenNail from AppBridge and register it.
int id = SnailSource.newId();
Path screenNailSetPath = SnailSource.getSetPath(id);
Path screenNailItemPath = SnailSource.getItemPath(id);
mScreenNailSet = (SnailAlbum) mActivity.getDataManager().getMediaObject(screenNailSetPath);
mScreenNailItem = (SnailItem) mActivity.getDataManager().getMediaObject(screenNailItemPath);
mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
if (data.getBoolean(KEY_SHOW_WHEN_LOCKED, false)) {
// Set the flag to be on top of the lock screen.
mFlags |= FLAG_SHOW_WHEN_LOCKED;
}
// Don't display "empty album" action item for capture intents.
if (!mSetPathString.equals("/local/all/0")) {
// Check if the path is a secure album.
if (SecureSource.isSecurePath(mSetPathString)) {
mSecureAlbum = (SecureAlbum) mActivity.getDataManager().getMediaSet(mSetPathString);
mShowSpinner = false;
}
mSetPathString = "/filter/empty/{" + mSetPathString + "}";
}
// Combine the original MediaSet with the one for ScreenNail
// from AppBridge.
mSetPathString = "/combo/item/{" + screenNailSetPath + "," + mSetPathString + "}";
// Start from the screen nail.
itemPath = screenNailItemPath;
} else if (inCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) {
mSetPathString = "/combo/item/{" + FilterSource.FILTER_CAMERA_SHORTCUT + "," + mSetPathString + "}";
mCurrentIndex++;
mHasCameraScreennailOrPlaceholder = true;
}
MediaSet originalSet = mActivity.getDataManager().getMediaSet(mSetPathString);
if (mHasCameraScreennailOrPlaceholder && originalSet instanceof ComboAlbum) {
// Use the name of the camera album rather than the default
// ComboAlbum behavior
((ComboAlbum) originalSet).useNameOfChild(1);
}
mSelectionManager.setSourceMediaSet(originalSet);
mSetPathString = "/filter/delete/{" + mSetPathString + "}";
mMediaSet = (FilterDeleteSet) mActivity.getDataManager().getMediaSet(mSetPathString);
if (mMediaSet != null && mIsFromTimelineScreen) {
mMediaSet.setShowAlbumsetTimeTitle(false);
}
if (mMediaSet == null) {
Log.w(TAG, "failed to restore " + mSetPathString);
}
if (itemPath == null) {
int mediaItemCount = mMediaSet.getMediaItemCount();
if (mediaItemCount > 0) {
if (mCurrentIndex >= mediaItemCount)
mCurrentIndex = 0;
itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1).get(0).getPath();
} else {
// Bail out, PhotoPage can't load on an empty album
return;
}
}
PhotoDataAdapter pda = new PhotoDataAdapter(mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex, mAppBridge == null ? -1 : 0, mAppBridge == null ? false : mAppBridge.isPanorama(), mAppBridge == null ? false : mAppBridge.isStaticCamera());
mModel = pda;
mPhotoView.setModel(mModel);
// If RTL and from widget, set the flag into PhotoDataAdapter.
if (View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) && mIsFromWidget) {
pda.setFromWidget(mIsFromWidget);
}
pda.setDataListener(new PhotoDataAdapter.DataListener() {
@Override
public void onPhotoChanged(int index, Path item) {
int oldIndex = mCurrentIndex;
mCurrentIndex = index;
if (mHasCameraScreennailOrPlaceholder) {
if (mCurrentIndex > 0) {
mSkipUpdateCurrentPhoto = false;
}
if (oldIndex == 0 && mCurrentIndex > 0 && !mPhotoView.getFilmMode()) {
mPhotoView.setFilmMode(true);
if (mAppBridge != null) {
UsageStatistics.onEvent("CameraToFilmstrip", UsageStatistics.TRANSITION_SWIPE, null);
}
} else if (oldIndex == 2 && mCurrentIndex == 1) {
mCameraSwitchCutoff = SystemClock.uptimeMillis() + CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
mPhotoView.stopScrolling();
} else if (oldIndex >= 1 && mCurrentIndex == 0) {
mPhotoView.setWantPictureCenterCallbacks(true);
mSkipUpdateCurrentPhoto = true;
}
}
if (!mSkipUpdateCurrentPhoto) {
if (item != null) {
MediaItem photo = mModel.getMediaItem(0);
if (photo != null) {
mActionBar.setTitle(photo.getName());
updateCurrentPhoto(photo);
}
}
updateBars();
}
// Reset the timeout for the bars after a swipe
refreshHidingMessage();
}
@Override
public void onLoadingFinished(boolean loadingFailed) {
if (!mModel.isEmpty()) {
MediaItem photo = mModel.getMediaItem(0);
if (photo != null) {
updateCurrentPhoto(photo);
} else {
mModel.resume();
}
} else if (mIsActive) {
// deletion that the user can undo.
if (mMediaSet.getNumberOfDeletions() == 0) {
onBackPressed();
}
}
}
@Override
public void onLoadingStarted() {
}
});
} else {
// Get default media set by the URI
MediaItem mediaItem = (MediaItem) mActivity.getDataManager().getMediaObject(itemPath);
mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem);
mPhotoView.setModel(mModel);
updateCurrentPhoto(mediaItem);
mShowSpinner = false;
}
mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1);
RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity).findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root);
if (galleryRoot != null) {
if (mSecureAlbum == null) {
mBottomControls = new PhotoPageBottomControls(this, mActivity, galleryRoot);
m3DButton = new ThreeDButton(this, mActivity, galleryRoot);
}
}
((GLRootView) mActivity.getGLRoot()).setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
int diff = mLastSystemUiVis ^ visibility;
mLastSystemUiVis = visibility;
if ((diff & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0 && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
showBars();
}
}
});
}
Aggregations