Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b4dbd22 authored by George Mount's avatar George Mount
Browse files

Remove panorama checks from supported operations.

 Bug 7351383
 Bug 7349438
 Move panorama support checks from getSupportedOperations so
 that calls to getSupportedOperations are consistent. Panorama
 checks are moved to only based on callbacks.

Change-Id: Id9ff138204df84c6fb0a4c971dcea59f1220aee2
parent c6ea0400
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class GalleryAppImpl extends Application implements GalleryApp {
                state, PackageManager.DONT_KILL_APP);

        mStitchingProgressManager = LightCycleHelper.createStitchingManagerInstance(this);
        mStitchingProgressManager.addChangeListener(getDataManager());
    }

    @Override
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.gallery3d.app;

import com.android.gallery3d.data.MediaObject;
import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
import com.android.gallery3d.data.PanoramaMetadataJob;
import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.FutureListener;
import com.android.gallery3d.util.LightCycleHelper.PanoramaMetadata;

import java.util.ArrayList;

/**
 * This class breaks out the off-thread panorama support checks so that the
 * complexity can be shared between UriImage and LocalImage, which need to
 * support panoramas.
 */
public class PanoramaMetadataSupport implements FutureListener<PanoramaMetadata> {
    private Object mLock = new Object();
    private Future<PanoramaMetadata> mGetPanoMetadataTask;
    private PanoramaMetadata mPanoramaMetadata;
    private ArrayList<PanoramaSupportCallback> mCallbacksWaiting;
    private MediaObject mMediaObject;

    public PanoramaMetadataSupport(MediaObject mediaObject) {
        mMediaObject = mediaObject;
    }

    public void getPanoramaSupport(GalleryApp app, PanoramaSupportCallback callback) {
        synchronized (mLock) {
            if (mPanoramaMetadata != null) {
                callback.panoramaInfoAvailable(mMediaObject, mPanoramaMetadata.mUsePanoramaViewer,
                        mPanoramaMetadata.mIsPanorama360);
            } else {
                if (mCallbacksWaiting == null) {
                    mCallbacksWaiting = new ArrayList<PanoramaSupportCallback>();
                    mGetPanoMetadataTask = app.getThreadPool().submit(
                            new PanoramaMetadataJob(app.getAndroidContext(),
                                    mMediaObject.getContentUri()), this);

                }
                mCallbacksWaiting.add(callback);
            }
        }
    }

    public void clearCachedValues() {
        synchronized (mLock) {
            if (mPanoramaMetadata != null) {
                mPanoramaMetadata = null;
            } else if (mGetPanoMetadataTask != null) {
                mGetPanoMetadataTask.cancel();
                for (PanoramaSupportCallback cb : mCallbacksWaiting) {
                    cb.panoramaInfoAvailable(mMediaObject, false, false);
                }
                mGetPanoMetadataTask = null;
                mCallbacksWaiting = null;
            }
        }
    }

    @Override
    public void onFutureDone(Future<PanoramaMetadata> future) {
        synchronized (mLock) {
            mPanoramaMetadata = future.get();
            for (PanoramaSupportCallback cb : mCallbacksWaiting) {
                cb.panoramaInfoAvailable(mMediaObject,
                        mPanoramaMetadata.mUsePanoramaViewer,
                        mPanoramaMetadata.mIsPanorama360);
            }
            mGetPanoMetadataTask = null;
            mCallbacksWaiting = null;
        }
   }
}
+120 −78
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ import com.android.gallery3d.data.LocalImage;
import com.android.gallery3d.data.MediaDetails;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaObject;
import com.android.gallery3d.data.MediaObject.SupportedOperationsListener;
import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
import com.android.gallery3d.data.MediaSet;
import com.android.gallery3d.data.MtpSource;
import com.android.gallery3d.data.Path;
@@ -91,6 +91,8 @@ public class PhotoPage extends ActivityState implements
    private static final int MSG_UPDATE_PHOTO_UI = 12;
    private static final int MSG_UPDATE_PROGRESS = 13;
    private static final int MSG_UPDATE_DEFERRED = 14;
    private static final int MSG_UPDATE_SHARE_URI = 15;
    private static final int MSG_UPDATE_PANORAMA_UI = 16;

    private static final int HIDE_BARS_TIMEOUT = 3500;
    private static final int UNFREEZE_GLROOT_TIMEOUT = 250;
@@ -166,7 +168,7 @@ public class PhotoPage extends ActivityState implements
    private boolean mSkipUpdateCurrentPhoto = false;
    private static final long CAMERA_SWITCH_CUTOFF_THRESHOLD_MS = 300;

    private static final long DEFERRED_UPDATE_MS = 150;
    private static final long DEFERRED_UPDATE_MS = 250;
    private boolean mDeferredUpdateWaiting = false;
    private long mDeferUpdateUntil = Long.MAX_VALUE;

@@ -182,17 +184,34 @@ public class PhotoPage extends ActivityState implements
            new MyMenuVisibilityListener();
    private UpdateProgressListener mProgressListener;

    private SupportedOperationsListener mSupportedOperationsListener =
        new SupportedOperationsListener() {
    private final PanoramaSupportCallback mUpdatePanoramaMenuItemsCallback = new PanoramaSupportCallback() {
        @Override
            public void onChange(MediaObject item, int operations) {
                if (item == mCurrentPhoto) {
                    if (mPhotoView.getFilmMode()
                            && SystemClock.uptimeMillis() < mDeferUpdateUntil) {
                        requestDeferredUpdate();
                    } else {
                        mHandler.sendEmptyMessage(MSG_UPDATE_PHOTO_UI);
        public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
                boolean isPanorama360) {
            if (mediaObject == mCurrentPhoto) {
                mHandler.obtainMessage(MSG_UPDATE_PANORAMA_UI, isPanorama360 ? 1 : 0, 0,
                        mediaObject).sendToTarget();
            }
        }
    };

    private final PanoramaSupportCallback mRefreshBottomControlsCallback = new PanoramaSupportCallback() {
        @Override
        public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
                boolean isPanorama360) {
            if (mediaObject == mCurrentPhoto) {
                mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, isPanorama ? 1 : 0, 0, mediaObject).sendToTarget();
            }
        }
    };

    private final PanoramaSupportCallback mUpdateShareURICallback = new PanoramaSupportCallback() {
        @Override
        public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
                boolean isPanorama360) {
            if (mediaObject == mCurrentPhoto) {
                mHandler.obtainMessage(MSG_UPDATE_SHARE_URI, isPanorama360 ? 1 : 0, 0, mediaObject)
                        .sendToTarget();
            }
        }
    };
@@ -230,8 +249,9 @@ public class PhotoPage extends ActivityState implements
        }

        private void sendUpdate(Uri uri, int message) {
            boolean isCurrentPhoto = mCurrentPhoto instanceof LocalImage
                    && mCurrentPhoto.getContentUri().equals(uri);
            MediaObject currentPhoto = mCurrentPhoto;
            boolean isCurrentPhoto = currentPhoto instanceof LocalImage
                    && currentPhoto.getContentUri().equals(uri);
            if (isCurrentPhoto) {
                mHandler.sendEmptyMessage(message);
            }
@@ -278,7 +298,9 @@ public class PhotoPage extends ActivityState implements
                        break;
                    }
                    case MSG_REFRESH_BOTTOM_CONTROLS: {
                        if (mBottomControls != null) mBottomControls.refresh();
                        if (mCurrentPhoto == message.obj && mBottomControls != null) {
                            mBottomControls.refresh(message.arg1 != 0);
                        }
                        break;
                    }
                    case MSG_ON_FULL_SCREEN_CHANGED: {
@@ -347,6 +369,28 @@ public class PhotoPage extends ActivityState implements
                        updateProgressBar();
                        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);

                            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);
                }
            }
@@ -540,18 +584,17 @@ public class PhotoPage extends ActivityState implements
    }

    @Override
    public boolean canDisplayBottomControl(int control) {
        if (mCurrentPhoto == null) return false;
    public boolean canDisplayBottomControl(int control, boolean isPanorama) {
        if (mCurrentPhoto == null) {
            return false;
        }
        switch(control) {
            case R.id.photopage_bottom_control_edit:
                return mHaveImageEditor && mShowBars
                        && (mCurrentPhoto.getSupportedOperations()
                        & MediaItem.SUPPORT_EDIT) != 0
                        && mCurrentPhoto.getMediaType()
                        == MediaObject.MEDIA_TYPE_IMAGE;
                        && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_EDIT) != 0
                        && mCurrentPhoto.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE;
            case R.id.photopage_bottom_control_panorama:
                return (mCurrentPhoto.getSupportedOperations()
                        & MediaItem.SUPPORT_PANORAMA) != 0;
                return isPanorama;
            default:
                return false;
        }
@@ -593,24 +636,18 @@ public class PhotoPage extends ActivityState implements
        mNfcPushUris[0] = uri;
    }

    private Intent createShareIntent(Path path) {
        DataManager manager = mActivity.getDataManager();
        int type = manager.getMediaType(path);
    private static Intent createShareIntent(MediaObject mediaObject) {
        int type = mediaObject.getMediaType();
        return new Intent(Intent.ACTION_SEND)
                .setType(MenuExecutor.getMimeType(type))
                .putExtra(Intent.EXTRA_STREAM, manager.getContentUri(path))
                .putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri())
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    private Intent createSharePanoramaIntent(Path path) {
        DataManager manager = mActivity.getDataManager();
        int supported = manager.getSupportedOperations(path);
        if ((supported & MediaObject.SUPPORT_PANORAMA360) == 0) {
            return null;
        }
    private static Intent createSharePanoramaIntent(Uri contentUri) {
        return new Intent(Intent.ACTION_SEND)
                .setType(GalleryUtils.MIME_TYPE_PANORAMA360)
                .putExtra(Intent.EXTRA_STREAM, manager.getContentUri(path))
                .putExtra(Intent.EXTRA_STREAM, contentUri)
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

@@ -634,15 +671,6 @@ public class PhotoPage extends ActivityState implements
                REQUEST_EDIT);
    }

    private void updateShareURI(Path path) {
        DataManager manager = mActivity.getDataManager();
        mActionBar.setShareIntents(
                createSharePanoramaIntent(path),
                createShareIntent(path));
        Uri uri = manager.getContentUri(path);
        setNfcBeamPushUri(uri);
    }

    private void requestDeferredUpdate() {
        mDeferUpdateUntil = SystemClock.uptimeMillis() + DEFERRED_UPDATE_MS;
        if (!mDeferredUpdateWaiting) {
@@ -663,25 +691,20 @@ public class PhotoPage extends ActivityState implements
        }

        updateMenuOperations();
        if (mBottomControls != null) mBottomControls.refresh();
        refreshBottomControlsWhenReady();
        if (mShowDetails) {
            mDetailsHelper.reloadDetails();
        }
        if ((mSecureAlbum == null)
                && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_SHARE) != 0) {
            updateShareURI(mCurrentPhoto.getPath());
            mCurrentPhoto.getPanoramaSupport(mUpdateShareURICallback);
        }
        updateProgressBar();
    }

    private void updateCurrentPhoto(MediaItem photo) {
        if (mCurrentPhoto == photo) return;
        if (mCurrentPhoto != null) {
            mCurrentPhoto.setSupportedOperationsListener(null);
        }
        mCurrentPhoto = photo;
        mCurrentPhoto.setSupportedOperationsListener(
                mSupportedOperationsListener);
        if (mPhotoView.getFilmMode()) {
            requestDeferredUpdate();
        } else {
@@ -721,22 +744,7 @@ public class PhotoPage extends ActivityState implements
            supportedOperations &= ~MediaObject.SUPPORT_EDIT;
        }
        MenuExecutor.updateMenuOperation(menu, supportedOperations);
        if ((supportedOperations & MediaObject.SUPPORT_PANORAMA360) != 0) {
            mActivity.invalidateOptionsMenu();
            item = menu.findItem(R.id.action_share);
            if (item != null) {
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                item.setTitle(
                        mActivity.getResources().getString(R.string.share_as_photo));
            }
        } else if ((supportedOperations & MediaObject.SUPPORT_SHARE) != 0) {
            item = menu.findItem(R.id.action_share);
            if (item != null) {
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                item.setTitle(
                        mActivity.getResources().getString(R.string.share));
            }
        }
        mCurrentPhoto.getPanoramaSupport(mUpdatePanoramaMenuItemsCallback);
    }

    private boolean canDoSlideShow() {
@@ -763,7 +771,7 @@ public class PhotoPage extends ActivityState implements
        mActionBar.show();
        mActivity.getGLRoot().setLightsOutMode(false);
        refreshHidingMessage();
        if (mBottomControls != null) mBottomControls.refresh();
        refreshBottomControlsWhenReady();
    }

    private void hideBars() {
@@ -772,7 +780,7 @@ public class PhotoPage extends ActivityState implements
        mActionBar.hide();
        mActivity.getGLRoot().setLightsOutMode(true);
        mHandler.removeMessages(MSG_HIDE_BARS);
        if (mBottomControls != null) mBottomControls.refresh();
        refreshBottomControlsWhenReady();
    }

    private void refreshHidingMessage() {
@@ -1283,9 +1291,7 @@ public class PhotoPage extends ActivityState implements
        mPhotoView.pause();
        mHandler.removeMessages(MSG_HIDE_BARS);
        mHandler.removeMessages(MSG_REFRESH_BOTTOM_CONTROLS);
        if (mBottomControls != null) {
            mBottomControls.refresh();
        }
        refreshBottomControlsWhenReady();
        mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener);
        if (mShowSpinner) {
            mActionBar.disableAlbumModeMenu(true);
@@ -1302,7 +1308,7 @@ public class PhotoPage extends ActivityState implements

    @Override
    public void onFilmModeChanged(boolean enabled) {
        mHandler.sendEmptyMessage(MSG_REFRESH_BOTTOM_CONTROLS);
        refreshBottomControlsWhenReady();
        if (enabled) {
            mHandler.removeMessages(MSG_HIDE_BARS);
        } else {
@@ -1362,9 +1368,7 @@ public class PhotoPage extends ActivityState implements
        mActionBar.setDisplayOptions(
                ((mSecureAlbum == null) && (mSetPathString != null)), false);
        mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
        if (mBottomControls != null) {
            mBottomControls.refresh();
        }
        refreshBottomControlsWhenReady();
        if (mShowSpinner) {
            mActionBar.enableAlbumModeMenu(
                    GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this);
@@ -1427,4 +1431,42 @@ public class PhotoPage extends ActivityState implements
            switchToGrid();
        }
    }

    @Override
    public void refreshBottomControlsWhenReady() {
        if (mBottomControls == null) {
            return;
        }
        MediaObject currentPhoto = mCurrentPhoto;
        if (currentPhoto == null) {
            mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, 0, 0, currentPhoto).sendToTarget();
        } else {
            currentPhoto.getPanoramaSupport(mRefreshBottomControlsCallback);
        }
    }

    private void updatePanoramaUI(boolean isPanorama360) {
        Menu menu = mActionBar.getMenu();

        // it could be null if onCreateActionBar has not been called yet
        if (menu == null) {
            return;
        }

        MenuExecutor.updateMenuForPanorama(menu, isPanorama360, isPanorama360);

        if (isPanorama360) {
            MenuItem item = menu.findItem(R.id.action_share);
            if (item != null) {
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                item.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
            }
        } else if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_SHARE) != 0) {
            MenuItem item = menu.findItem(R.id.action_share);
            if (item != null) {
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                item.setTitle(mActivity.getResources().getString(R.string.share));
            }
        }
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

import com.android.gallery3d.R;
@@ -34,8 +33,9 @@ import java.util.Map;
public class PhotoPageBottomControls implements OnClickListener {
    public interface Delegate {
        public boolean canDisplayBottomControls();
        public boolean canDisplayBottomControl(int control);
        public boolean canDisplayBottomControl(int control, boolean isPanorama);
        public void onBottomControlClicked(int control);
        public void refreshBottomControlsWhenReady();
    }

    private Delegate mDelegate;
@@ -76,7 +76,7 @@ public class PhotoPageBottomControls implements OnClickListener {
        mContainerAnimIn.setDuration(CONTAINER_ANIM_DURATION_MS);
        mContainerAnimOut.setDuration(CONTAINER_ANIM_DURATION_MS);

        refresh();
        mDelegate.refreshBottomControlsWhenReady();
    }

    private void hide() {
@@ -93,7 +93,7 @@ public class PhotoPageBottomControls implements OnClickListener {
        mContainer.setVisibility(View.VISIBLE);
    }

    public void refresh() {
    public void refresh(boolean isPanorama) {
        boolean visible = mDelegate.canDisplayBottomControls();
        boolean containerVisibilityChanged = (visible != mContainerVisible);
        if (containerVisibilityChanged) {
@@ -109,7 +109,7 @@ public class PhotoPageBottomControls implements OnClickListener {
        }
        for (View control : mControlsVisible.keySet()) {
            Boolean prevVisibility = mControlsVisible.get(control);
            boolean curVisibility = mDelegate.canDisplayBottomControl(control.getId());
            boolean curVisibility = mDelegate.canDisplayBottomControl(control.getId(), isPanorama);
            if (prevVisibility.booleanValue() != curVisibility) {
                if (!containerVisibilityChanged) {
                    control.clearAnimation();
+26 −7
Original line number Diff line number Diff line
@@ -16,15 +16,15 @@

package com.android.gallery3d.data;

import android.content.Intent;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;

import com.android.gallery3d.app.GalleryApp;
import com.android.gallery3d.app.StitchingChangeListener;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
import com.android.gallery3d.data.MediaSet.ItemConsumer;
import com.android.gallery3d.data.MediaSource.PathId;
import com.android.gallery3d.picasasource.PicasaSource;
@@ -49,7 +49,7 @@ import java.util.WeakHashMap;
// path. And it's used to identify a specific media set even if the process is
// killed and re-created, so child keys should be stable identifiers.

public class DataManager {
public class DataManager implements StitchingChangeListener {
    public static final int INCLUDE_IMAGE = 1;
    public static final int INCLUDE_VIDEO = 2;
    public static final int INCLUDE_ALL = INCLUDE_IMAGE | INCLUDE_VIDEO;
@@ -247,10 +247,8 @@ public class DataManager {
        return getMediaObject(path).getSupportedOperations();
    }

    // getAll will cause this call to wait if any of the operations
    // are expensive to compute. Do not call in UI thread.
    public int getSupportedOperations(Path path, boolean getAll) {
        return getMediaObject(path).getSupportedOperations(getAll);
    public void getPanoramaSupport(Path path, PanoramaSupportCallback callback) {
        getMediaObject(path).getPanoramaSupport(callback);
    }

    public void delete(Path path) {
@@ -351,4 +349,25 @@ public class DataManager {
            }
        }
    }

    @Override
    public void onStitchingQueued(Uri uri) {
        // Do nothing.
    }

    @Override
    public void onStitchingResult(Uri uri) {
        Path path = findPathByUri(uri, null);
        if (path != null) {
            MediaObject mediaObject = getMediaObject(path);
            if (mediaObject != null) {
                mediaObject.clearCachedPanoramaSupport();
            }
        }
    }

    @Override
    public void onStitchingProgress(Uri uri, int progress) {
        // Do nothing.
    }
}
Loading