Search in sources :

Example 11 with MediaSet

use of com.android.gallery3d.data.MediaSet in project android_packages_apps_Gallery2 by LineageOS.

the class MediaSetLoader method getPathForItem.

@Override
public Object getPathForItem(Cursor item) {
    int index = item.getInt(AlbumSetLoader.INDEX_ID);
    MediaSet ms = mMediaSet.getSubMediaSet(index);
    if (ms != null) {
        return ms.getPath();
    }
    return null;
}
Also used : MediaSet(com.android.gallery3d.data.MediaSet)

Example 12 with MediaSet

use of com.android.gallery3d.data.MediaSet in project android_packages_apps_Gallery2 by LineageOS.

the class MediaSetSource method resolveAlbumPath.

private synchronized void resolveAlbumPath() {
    if (mDataManager == null)
        return;
    MediaSet mediaSet = (MediaSet) mDataManager.getMediaObject(mAlbumPath);
    if (mediaSet != null) {
        // Clear the reference instead of removing the listener
        // to get around a concurrent modification exception.
        mRootSet = null;
        mSource = new CheckedMediaSetSource(mediaSet);
        if (mListener != null) {
            mListener.onContentDirty();
            mSource.setContentListener(mListener);
            mListener = null;
        }
        mDataManager = null;
        mAlbumPath = null;
    }
}
Also used : MediaSet(com.android.gallery3d.data.MediaSet)

Example 13 with MediaSet

use of com.android.gallery3d.data.MediaSet in project android_packages_apps_Gallery2 by LineageOS.

the class SlideshowPage method findMediaItem.

private static MediaItem findMediaItem(MediaSet mediaSet, int index) {
    for (int i = 0, n = mediaSet.getSubMediaSetCount(); i < n; ++i) {
        MediaSet subset = mediaSet.getSubMediaSet(i);
        int count = subset.getTotalMediaItemCount();
        if (index < count) {
            return findMediaItem(subset, index);
        }
        index -= count;
    }
    ArrayList<MediaItem> list = mediaSet.getMediaItem(index, 1);
    return list.isEmpty() ? null : list.get(0);
}
Also used : MediaItem(com.android.gallery3d.data.MediaItem) MediaSet(com.android.gallery3d.data.MediaSet)

Example 14 with MediaSet

use of com.android.gallery3d.data.MediaSet 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();
            }
        }
    });
}
Also used : Message(android.os.Message) ThreeDimensionalActivity(com.android.gallery3d.app.dualcam3d.ThreeDimensionalActivity) Activity(android.app.Activity) FilterShowActivity(com.android.gallery3d.filtershow.FilterShowActivity) Uri(android.net.Uri) MediaSet(com.android.gallery3d.data.MediaSet) SynchronizedHandler(com.android.gallery3d.ui.SynchronizedHandler) Path(com.android.gallery3d.data.Path) SelectionManager(com.android.gallery3d.ui.SelectionManager) Intent(android.content.Intent) MenuExecutor(com.android.gallery3d.ui.MenuExecutor) GLView(com.android.gallery3d.ui.GLView) View(android.view.View) GLRootView(com.android.gallery3d.ui.GLRootView) PhotoView(com.android.gallery3d.ui.PhotoView) PhotoView(com.android.gallery3d.ui.PhotoView) GLRootView(com.android.gallery3d.ui.GLRootView) MediaItem(com.android.gallery3d.data.MediaItem) RelativeLayout(android.widget.RelativeLayout) ComboAlbum(com.android.gallery3d.data.ComboAlbum)

Example 15 with MediaSet

use of com.android.gallery3d.data.MediaSet in project android_packages_apps_Gallery2 by LineageOS.

the class TimeLinePage method onLongTap.

public void onLongTap(int slotIndex, boolean isTitle) {
    if (mGetContent)
        return;
    if (isTitle) {
        MediaSet targetSet = mAlbumDataAdapter.getMediaSet(slotIndex);
        if (targetSet == null)
            return;
        ArrayList<Path> paths = ((ClusterAlbum) targetSet).getMediaItems();
        if (paths == null || paths.size() <= 0)
            return;
        mSelectionManager.setAutoLeaveSelectionMode(true);
        mSelectionManager.toggleTimeLineSet(paths);
        mSlotView.invalidate();
    } else {
        MediaItem item = mAlbumDataAdapter.get(slotIndex);
        if (item == null)
            return;
        mSelectionManager.setAutoLeaveSelectionMode(true);
        mSelectionManager.toggle(item.getPath());
        mSlotView.invalidate();
    }
}
Also used : Path(com.android.gallery3d.data.Path) ClusterAlbum(com.android.gallery3d.data.ClusterAlbum) MediaItem(com.android.gallery3d.data.MediaItem) MediaSet(com.android.gallery3d.data.MediaSet)

Aggregations

MediaSet (com.android.gallery3d.data.MediaSet)20 MediaItem (com.android.gallery3d.data.MediaItem)9 Path (com.android.gallery3d.data.Path)9 Uri (android.net.Uri)3 DataManager (com.android.gallery3d.data.DataManager)3 ArrayList (java.util.ArrayList)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 GalleryApp (com.android.gallery3d.app.GalleryApp)2 ClusterAlbum (com.android.gallery3d.data.ClusterAlbum)2 LocalAlbum (com.android.gallery3d.data.LocalAlbum)2 MediaObject (com.android.gallery3d.data.MediaObject)2 MatrixCursor (android.database.MatrixCursor)1 Message (android.os.Message)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1