diff options
author | kaiyiz <kaiyiz@codeaurora.org> | 2014-10-15 10:10:13 +0800 |
---|---|---|
committer | Xiaojing Zhang <zhangx@codeaurora.org> | 2014-11-04 20:38:31 -0800 |
commit | ed2687a7d84b0d5ab9bf6eb1b20be2ec745444c6 (patch) | |
tree | 1ab20afe035d3361697c6cce674319655435102e /src/com/android/gallery3d/app/AlbumPage.java | |
parent | 57261ec71cf73b073cc0cd2858730d60d3c4cad3 (diff) | |
download | android_packages_apps_Gallery2-ed2687a7d84b0d5ab9bf6eb1b20be2ec745444c6.tar.gz android_packages_apps_Gallery2-ed2687a7d84b0d5ab9bf6eb1b20be2ec745444c6.tar.bz2 android_packages_apps_Gallery2-ed2687a7d84b0d5ab9bf6eb1b20be2ec745444c6.zip |
Gallery2: Reginal requirement for RTL
Add RTL logic in load picture, pick picture, show picture, delete
picture, load album, pick album, show album, show widget, pick
widget, scroll timebar. Change Camera setting to support RTL.
Change-Id: Ica264f624e0f20153280066264943882ad22f2db
Diffstat (limited to 'src/com/android/gallery3d/app/AlbumPage.java')
-rw-r--r-- | src/com/android/gallery3d/app/AlbumPage.java | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 44f24043b..0614eef86 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -25,10 +25,12 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; +import android.text.TextUtils; import android.view.HapticFeedbackConstants; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import android.widget.Toast; import com.android.gallery3d.R; @@ -59,6 +61,7 @@ import com.android.gallery3d.util.Future; import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.MediaSetUtils; +import java.util.Locale; public class AlbumPage extends ActivityState implements GalleryActionBar.ClusterRunner, SelectionManager.SelectionListener, MediaSet.SyncListener, GalleryActionBar.OnAlbumModeSelectedListener { @@ -82,6 +85,9 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private static final float USER_DISTANCE_METER = 0.3f; + // Data cache size, equal to AlbumDataLoader.DATA_CACHE_SIZE + private static final int DATA_CACHE_SIZE = 256; + private boolean mIsActive = false; private AlbumSlotRenderer mAlbumView; private Path mMediaSetPath; @@ -266,6 +272,17 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void pickPhoto(int slotIndex) { + if ((View.LAYOUT_DIRECTION_RTL == TextUtils + .getLayoutDirectionFromLocale(Locale.getDefault())) + && !mGetContent) { + // Fetch corresponding slotIndex from another side, (RTL) + if (slotIndex > DATA_CACHE_SIZE / 2 + && slotIndex < mAlbumDataAdapter.size() - DATA_CACHE_SIZE / 2) { + slotIndex = mAlbumDataAdapter.size() - slotIndex - 2; + } else { + slotIndex = mAlbumDataAdapter.size() - slotIndex - 1; + } + } pickPhoto(slotIndex, false); } @@ -278,10 +295,25 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } MediaItem item = mAlbumDataAdapter.get(slotIndex); - if (item == null) return; // Item not ready yet, ignore the click + + // Checking it is RTL or not + boolean isLayoutRtl = (View.LAYOUT_DIRECTION_RTL == TextUtils + .getLayoutDirectionFromLocale(Locale.getDefault())) ? true : false; + + // When not RTL, return directly to ignore the click + if (!isLayoutRtl && item == null) { + return; + } + if (mGetContent) { + if (isLayoutRtl && item == null) { + return; // Item not ready yet, ignore the click + } onGetContent(item); } else if (mLaunchedFromPhotoPage) { + if (isLayoutRtl && item == null) { + return; // Item not ready yet, ignore the click + } TransitionStore transitions = mActivity.getTransitionStore(); transitions.put( PhotoPage.KEY_ALBUMPAGE_TRANSITION, @@ -297,8 +329,12 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mSlotView.getSlotRect(slotIndex, mRootPane)); data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mMediaSetPath.toString()); - data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, - item.getPath().toString()); + + // Item not ready yet, don't pass the photo path to bundle + if (!isLayoutRtl && item != null) { + data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, + item.getPath().toString()); + } data.putInt(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_STARTED); data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, @@ -574,8 +610,17 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void switchToFilmstrip() { - if (mAlbumDataAdapter.size() < 1) return; + // Invalid album, return back directly. + if (mAlbumDataAdapter.size() < 1) { + return; + } + int targetPhoto = mSlotView.getVisibleStart(); + if (View.LAYOUT_DIRECTION_RTL == TextUtils + .getLayoutDirectionFromLocale(Locale.getDefault())) { + // Fetch corresponding index from another side, only in RTL + targetPhoto = mAlbumDataAdapter.size() - targetPhoto - 1; + } prepareAnimationBackToFilmstrip(targetPhoto); if(mLaunchedFromPhotoPage) { onBackPressed(); @@ -642,7 +687,22 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster case REQUEST_PHOTO: { if (data == null) return; mFocusIndex = data.getIntExtra(PhotoPage.KEY_RETURN_INDEX_HINT, 0); + if (View.LAYOUT_DIRECTION_RTL == TextUtils + .getLayoutDirectionFromLocale(Locale.getDefault())) { + // Fetch corresponding index from another side, only in RTL + mFocusIndex = mAlbumDataAdapter.size() - mFocusIndex - 1; + // Prepare to jump to mFocusIndex position, only enabled in RTL + mSlotView.setIsFromPhotoPage(true); + } + + // Let picture of mFocusIndex visible mSlotView.makeSlotVisible(mFocusIndex); + + if (View.LAYOUT_DIRECTION_RTL == TextUtils + .getLayoutDirectionFromLocale(Locale.getDefault())) { + // Reset variable + mSlotView.setIsFromPhotoPage(false); + } break; } case REQUEST_DO_ANIMATION: { |