Search in sources :

Example 11 with Path

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

the class MenuExecutor method startAction.

public void startAction(int action, int title, ProgressListener listener, boolean waitOnStop, boolean showDialog) {
    ArrayList<Path> ids = mSelectionManager.getSelected(false);
    stopTaskAndDismissDialog();
    Activity activity = mActivity;
    if (showDialog) {
        mDialog = createProgressDialog(activity, title, ids.size());
        mDialog.show();
    } else {
        mDialog = null;
    }
    MediaOperation operation = new MediaOperation(action, ids, listener);
    mTask = mActivity.getBatchServiceThreadPoolIfAvailable().submit(operation, null);
    mWaitOnStop = waitOnStop;
}
Also used : Path(com.android.gallery3d.data.Path) CropActivity(com.android.gallery3d.filtershow.crop.CropActivity) AbstractGalleryActivity(com.android.gallery3d.app.AbstractGalleryActivity) Activity(android.app.Activity)

Example 12 with Path

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

the class WidgetConfigure method setChoosenAlbum.

private void setChoosenAlbum(Intent data) {
    String albumPath = data.getStringExtra(AlbumPicker.KEY_ALBUM_PATH);
    WidgetDatabaseHelper helper = new WidgetDatabaseHelper(this);
    try {
        String relativePath = null;
        GalleryApp galleryApp = (GalleryApp) getApplicationContext();
        DataManager manager = galleryApp.getDataManager();
        Path path = Path.fromString(albumPath);
        MediaSet mediaSet = (MediaSet) manager.getMediaObject(path);
        if (mediaSet instanceof LocalAlbum) {
            int bucketId = Integer.parseInt(path.getSuffix());
            // If the chosen album is a local album, find relative path
            // Otherwise, leave the relative path field empty
            relativePath = LocalAlbum.getRelativePath(bucketId);
            Log.i(TAG, "Setting widget, album path: " + albumPath + ", relative path: " + relativePath);
        }
        helper.setWidget(mAppWidgetId, WidgetDatabaseHelper.TYPE_ALBUM, albumPath, relativePath);
        updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
    } finally {
        helper.close();
    }
}
Also used : Path(com.android.gallery3d.data.Path) MediaSet(com.android.gallery3d.data.MediaSet) LocalAlbum(com.android.gallery3d.data.LocalAlbum) DataManager(com.android.gallery3d.data.DataManager) GalleryApp(com.android.gallery3d.app.GalleryApp)

Example 13 with Path

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

the class ManageCachePage method onClick.

@Override
public void onClick(View view) {
    Utils.assertTrue(view.getId() == R.id.done);
    GLRoot root = mActivity.getGLRoot();
    root.lockRenderThread();
    try {
        ArrayList<Path> ids = mSelectionManager.getSelected(false);
        if (ids.size() == 0) {
            onBackPressed();
            return;
        }
        showToast();
        MenuExecutor menuExecutor = new MenuExecutor(mActivity, mSelectionManager);
        menuExecutor.startAction(R.id.action_toggle_full_caching, R.string.process_caching_requests, this);
    } finally {
        root.unlockRenderThread();
    }
}
Also used : Path(com.android.gallery3d.data.Path) GLRoot(com.android.gallery3d.ui.GLRoot) MenuExecutor(com.android.gallery3d.ui.MenuExecutor)

Example 14 with Path

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

the class PhotoPage method onItemSelected.

@Override
protected boolean onItemSelected(MenuItem item) {
    if (mModel == null)
        return true;
    refreshHidingMessage();
    MediaItem current = mModel.getMediaItem(0);
    // menu when transitioning from filmstrip to camera
    if (current instanceof SnailItem)
        return true;
    // after PhotoPage being refactored.
    if (current == null) {
        // item is not ready, ignore
        return true;
    }
    int currentIndex = mModel.getCurrentIndex();
    // If RTL, the current index need be revised.
    if (View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())) {
        currentIndex = mMediaSet.getMediaItemCount() - currentIndex - 1;
    }
    Path path = current.getPath();
    DataManager manager = mActivity.getDataManager();
    int action = item.getItemId();
    String confirmMsg = null;
    switch(action) {
        case android.R.id.home:
            {
                onUpPressed();
                return true;
            }
        case R.id.action_slideshow:
            {
                Bundle data = new Bundle();
                data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString());
                data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString());
                data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex);
                data.putBoolean(SlideshowPage.KEY_REPEAT, true);
                mActivity.getStateManager().startStateForResult(SlideshowPage.class, REQUEST_SLIDESHOW, data);
                return true;
            }
        /*case R.id.action_crop: {
                Activity activity = mActivity;
                Intent intent = new Intent(CropActivity.CROP_ACTION);
                intent.setClass(activity, CropActivity.class);
                intent.setDataAndType(manager.getContentUri(path), current.getMimeType())
                    .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                activity.startActivityForResult(intent, PicasaSource.isPicasaImage(current)
                        ? REQUEST_CROP_PICASA
                        : REQUEST_CROP);
                return true;
            }*/
        case R.id.action_trim:
            {
                Intent intent = new Intent(mActivity, TrimVideo.class);
                intent.setData(manager.getContentUri(path));
                // We need the file path to wrap this into a RandomAccessFile.
                String str = current.getMimeType();
                if ("video/mp4".equals(str) || "video/mpeg4".equals(str) || "video/3gpp".equals(str) || "video/3gpp2".equals(str)) {
                    intent.putExtra(KEY_MEDIA_ITEM_PATH, current.getFilePath());
                    mActivity.startActivityForResult(intent, REQUEST_TRIM);
                } else {
                    Toast.makeText(mActivity, mActivity.getString(R.string.can_not_trim), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        case R.id.action_mute:
            {
                MuteVideo muteVideo = new MuteVideo(current.getFilePath(), manager.getContentUri(path), mActivity);
                muteVideo.muteInBackground();
                return true;
            }
        case R.id.action_edit:
            {
                launchPhotoEditor();
                return true;
            }
        /*case R.id.action_simple_edit: {
                launchSimpleEditor();
                return true;
            }*/
        case R.id.action_details:
            {
                if (mShowDetails) {
                    hideDetails();
                } else {
                    showDetails();
                }
                return true;
            }
        case R.id.print:
            {
                try {
                    mActivity.printSelectedImage(manager.getContentUri(path));
                } catch (SecurityException e) {
                    e.printStackTrace();
                    mActivity.finish();
                }
                return true;
            }
        case R.id.action_delete:
            confirmMsg = mActivity.getResources().getQuantityString(R.plurals.delete_selection, 1);
        case R.id.action_setas:
        // case R.id.action_rotate_cw:
        case R.id.action_show_on_map:
            mSelectionManager.deSelectAll();
            mSelectionManager.toggle(path);
            mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener);
            return true;
        // return true;
        default:
            return false;
    }
}
Also used : Path(com.android.gallery3d.data.Path) SnailItem(com.android.gallery3d.data.SnailItem) MediaItem(com.android.gallery3d.data.MediaItem) Bundle(android.os.Bundle) DataManager(com.android.gallery3d.data.DataManager) Intent(android.content.Intent)

Example 15 with Path

use of com.android.gallery3d.data.Path 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)

Aggregations

Path (com.android.gallery3d.data.Path)25 MediaSet (com.android.gallery3d.data.MediaSet)9 DataManager (com.android.gallery3d.data.DataManager)8 MediaItem (com.android.gallery3d.data.MediaItem)8 Intent (android.content.Intent)6 Uri (android.net.Uri)6 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 MediaObject (com.android.gallery3d.data.MediaObject)3 Activity (android.app.Activity)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 MenuExecutor (com.android.gallery3d.ui.MenuExecutor)2 Message (android.os.Message)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 MenuItem (android.view.MenuItem)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1