use of com.android.gallery3d.data.MediaItem 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;
}
}
use of com.android.gallery3d.data.MediaItem in project android_packages_apps_Gallery2 by LineageOS.
the class PhotoPage method launchSimpleEditor.
private void launchSimpleEditor() {
MediaItem current = mModel.getMediaItem(0);
if (current == null || (current.getSupportedOperations() & MediaObject.SUPPORT_EDIT) == 0) {
return;
}
Intent intent = new Intent(ACTION_SIMPLE_EDIT);
intent.setDataAndType(current.getContentUri(), current.getMimeType()).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) {
intent.setAction(Intent.ACTION_EDIT);
}
intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, mActivity.isFullscreen());
((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), REQUEST_EDIT);
overrideTransitionToEditor();
}
use of com.android.gallery3d.data.MediaItem 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();
}
}
});
}
use of com.android.gallery3d.data.MediaItem in project android_packages_apps_Gallery2 by LineageOS.
the class PhotoDataAdapter method updateImageCache.
private void updateImageCache() {
HashSet<Path> toBeRemoved = new HashSet<Path>(mImageCache.keySet());
for (int i = mActiveStart; i < mActiveEnd; ++i) {
MediaItem item = mData[i % DATA_CACHE_SIZE];
if (item == null)
continue;
Path path = item.getPath();
ImageEntry entry = mImageCache.get(path);
toBeRemoved.remove(path);
if (entry != null) {
if (Math.abs(i - mCurrentIndex) > 1) {
if (entry.fullImageTask != null) {
entry.fullImageTask.cancel();
entry.fullImageTask = null;
}
entry.fullImage = null;
entry.requestedFullImage = MediaObject.INVALID_DATA_VERSION;
}
if (entry.requestedScreenNail != item.getDataVersion()) {
// still a placeholder.
if (entry.screenNail instanceof TiledScreenNail) {
TiledScreenNail s = (TiledScreenNail) entry.screenNail;
s.updatePlaceholderSize(item.getWidth(), item.getHeight());
}
}
if (Math.abs(i - mCurrentIndex) > 0) {
if (entry.gifDecoderTask != null) {
entry.gifDecoderTask.cancel();
entry.gifDecoderTask = null;
}
entry.gifDecoder = null;
entry.requestedGif = MediaItem.INVALID_DATA_VERSION;
if (null != entry.currentGifFrame) {
// recycle cached gif frame
entry.currentGifFrame.recycle();
entry.currentGifFrame = null;
}
}
} else {
entry = new ImageEntry();
mImageCache.put(path, entry);
}
}
// Clear the data and requests for ImageEntries outside the new window.
for (Path path : toBeRemoved) {
ImageEntry entry = mImageCache.remove(path);
if (entry.fullImageTask != null)
entry.fullImageTask.cancel();
if (entry.screenNailTask != null)
entry.screenNailTask.cancel();
if (entry.screenNail != null)
entry.screenNail.recycle();
}
updateScreenNailUploadQueue();
}
use of com.android.gallery3d.data.MediaItem in project android_packages_apps_Gallery2 by LineageOS.
the class PhotoDataAdapter method updateImageRequests.
private void updateImageRequests() {
if (!mIsActive)
return;
int currentIndex = mCurrentIndex;
MediaItem item = mData[currentIndex % DATA_CACHE_SIZE];
if (item == null || item.getPath() != mItemPath) {
// current item mismatch - don't request image
return;
}
// 1. Find the most wanted request and start it (if not already started).
Future<?> task = null;
for (int i = 0; i < sImageFetchSeq.length; i++) {
int offset = sImageFetchSeq[i].indexOffset;
int bit = sImageFetchSeq[i].imageBit;
if (bit == BIT_FULL_IMAGE && !mNeedFullImage)
continue;
task = startTaskIfNeeded(currentIndex + offset, bit);
if (task != null)
break;
}
// 2. Cancel everything else.
for (ImageEntry entry : mImageCache.values()) {
if (entry.screenNailTask != null && entry.screenNailTask != task) {
entry.screenNailTask.cancel();
entry.screenNailTask = null;
entry.requestedScreenNail = MediaObject.INVALID_DATA_VERSION;
}
if (entry.fullImageTask != null && entry.fullImageTask != task) {
entry.fullImageTask.cancel();
entry.fullImageTask = null;
entry.requestedFullImage = MediaObject.INVALID_DATA_VERSION;
}
if (entry.gifDecoderTask != null && entry.gifDecoderTask != task) {
entry.gifDecoderTask.cancel();
entry.gifDecoderTask = null;
entry.requestedGif = MediaObject.INVALID_DATA_VERSION;
}
}
}
Aggregations