Search in sources :

Example 6 with MediaObject

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

the class ActionModeHandler method updateSupportedOperation.

public void updateSupportedOperation() {
    // Interrupt previous unfinished task, mMenuTask is only accessed in main thread
    if (mMenuTask != null)
        mMenuTask.cancel();
    updateSelectionMenu();
    // Disable share actions until share intent is in good shape
    if (mSharePanoramaMenuItem != null)
        mSharePanoramaMenuItem.setEnabled(false);
    if (mShareMenuItem != null)
        mShareMenuItem.setEnabled(false);
    isThreadComplete = false;
    // Generate sharing intent and update supported operations in the background
    // The task can take a long time and be canceled in the mean time.
    mMenuTask = mActivity.getThreadPool().submit(new Job<Void>() {

        @Override
        public Void run(final JobContext jc) {
            // use selected count to disable menu options and share items if need
            // to enhance performance.
            int multipleOperation = SUPPORT_MULTIPLE_MASK;
            int count = mSelectionManager.getSelectedCount();
            final int operationPre = computeMenuOptionsMultiple(multipleOperation, count);
            final boolean canSharePanoramasPre = computeCanShare(count, MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT);
            final boolean canSharePre = computeCanShare(count, MAX_SELECTED_ITEMS_FOR_SHARE_INTENT);
            mMainHandler.post(new Runnable() {

                @Override
                public void run() {
                    if (jc.isCancelled())
                        return;
                    MenuExecutor.updateMenuOperation(mMenu, operationPre);
                    if (mShareMenuItem != null && !canSharePre) {
                        mShareMenuItem.setEnabled(false);
                        showShareMaxDialogIfNeed(false);
                    }
                }
            });
            // Pass1: Deal with unexpanded media object list for menu operation.
            ArrayList<MediaObject> selected = getSelectedMediaObjects(jc);
            if (selected == null) {
                mMainHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        mMenuTask = null;
                        if (jc.isCancelled())
                            return;
                        // Disable all the operations when no item is selected
                        MenuExecutor.updateMenuOperation(mMenu, 0);
                    }
                });
                return null;
            }
            final int operation = computeMenuOptions(selected);
            if (jc.isCancelled()) {
                return null;
            }
            // use selected items to compute menu options and share items again.
            final boolean canShare = canSharePre && computeCanShare(selected, MAX_SELECTED_ITEMS_FOR_SHARE_INTENT);
            final boolean canSharePanoramas = canSharePanoramasPre && computeCanShare(selected, MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT);
            final GetAllPanoramaSupports supportCallback = canSharePanoramas ? new GetAllPanoramaSupports(selected, jc) : null;
            // Pass2: Deal with expanded media object list for sharing operation.
            final Intent share_panorama_intent = canSharePanoramas ? computePanoramaSharingIntent(jc, MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT) : new Intent();
            final Intent share_intent = canShare ? computeSharingIntent(jc, MAX_SELECTED_ITEMS_FOR_SHARE_INTENT) : new Intent();
            if (canSharePanoramas) {
                supportCallback.waitForPanoramaSupport();
            }
            if (jc.isCancelled()) {
                return null;
            }
            mMainHandler.post(new Runnable() {

                @Override
                public void run() {
                    mMenuTask = null;
                    if (jc.isCancelled())
                        return;
                    MenuExecutor.updateMenuOperation(mMenu, operation);
                    MenuExecutor.updateMenuForPanorama(mMenu, canSharePanoramas && supportCallback.mAllPanorama360, canSharePanoramas && supportCallback.mHasPanorama360);
                    if (mSharePanoramaMenuItem != null) {
                        mSharePanoramaMenuItem.setEnabled(true);
                        if (canSharePanoramas && supportCallback.mAllPanorama360) {
                            mShareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                            mShareMenuItem.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
                        } else {
                            mSharePanoramaMenuItem.setVisible(false);
                            mShareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                            mShareMenuItem.setTitle(mActivity.getResources().getString(R.string.share));
                        }
                        mSharePanoramaIntent = share_panorama_intent;
                    }
                    if (mShareMenuItem != null) {
                        showShareMaxDialogIfNeed(canShare);
                        mShareMenuItem.setEnabled(canShare);
                        isThreadComplete = true;
                        mShareIntent = share_intent;
                    }
                }
            });
            return null;
        }
    });
}
Also used : Intent(android.content.Intent) JobContext(com.android.gallery3d.util.ThreadPool.JobContext) Job(com.android.gallery3d.util.ThreadPool.Job) MediaObject(com.android.gallery3d.data.MediaObject)

Example 7 with MediaObject

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

the class ActionModeHandler method getSelectedMediaObjects.

private ArrayList<MediaObject> getSelectedMediaObjects(JobContext jc) {
    ArrayList<Path> unexpandedPaths = mSelectionManager.getSelected(false);
    if (unexpandedPaths.isEmpty()) {
        // (instead of long press a media object)
        return null;
    }
    ArrayList<MediaObject> selected = new ArrayList<MediaObject>();
    DataManager manager = mActivity.getDataManager();
    for (Path path : unexpandedPaths) {
        if (jc.isCancelled() || !mSelectionManager.inSelectionMode()) {
            return null;
        }
        MediaObject mediaObject = manager.getMediaObject(path);
        if (mediaObject != null && mediaObject.isSelectable()) {
            selected.add(mediaObject);
        }
    }
    return selected;
}
Also used : Path(com.android.gallery3d.data.Path) ArrayList(java.util.ArrayList) DataManager(com.android.gallery3d.data.DataManager) MediaObject(com.android.gallery3d.data.MediaObject)

Aggregations

MediaObject (com.android.gallery3d.data.MediaObject)7 Path (com.android.gallery3d.data.Path)3 Intent (android.content.Intent)1 MatrixCursor (android.database.MatrixCursor)1 DataManager (com.android.gallery3d.data.DataManager)1 MediaSet (com.android.gallery3d.data.MediaSet)1 Job (com.android.gallery3d.util.ThreadPool.Job)1 JobContext (com.android.gallery3d.util.ThreadPool.JobContext)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1