protected void cropImageAndSetWallpaper(Uri uri,
OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) {
- // Get the crop
+ // Get the crop
Point inSize = mCropView.getSourceDimensions();
+ boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
+
Point minDims = new Point();
Point maxDims = new Point();
Display d = getWindowManager().getDefaultDisplay();
int maxDim = Math.max(maxDims.x, maxDims.y);
final int minDim = Math.min(minDims.x, minDims.y);
- int defaultWidth;
+ int defaultWallpaperWidth;
if (isScreenLarge(getResources())) {
- defaultWidth = (int) (maxDim *
+ defaultWallpaperWidth = (int) (maxDim *
wallpaperTravelToScreenWidthRatio(maxDim, minDim));
} else {
- defaultWidth = Math.max((int)
+ defaultWallpaperWidth = Math.max((int)
(minDim * WALLPAPER_SCREENS_SPAN), maxDim);
}
// ADJUST CROP WIDTH
// Extend the crop all the way to the right, for parallax
- float extraSpaceToRight = inSize.x - cropRect.right;
+ // (or all the way to the left, in RTL)
+ float extraSpace = ltr ? inSize.x - cropRect.right : cropRect.left;
// Cap the amount of extra width
- float maxExtraSpace = defaultWidth / cropScale - cropRect.width();
- extraSpaceToRight = Math.min(extraSpaceToRight, maxExtraSpace);
+ float maxExtraSpace = defaultWallpaperWidth / cropScale - cropRect.width();
+ extraSpace = Math.min(extraSpace, maxExtraSpace);
- cropRect.right += extraSpaceToRight;
+ if (ltr) {
+ cropRect.right += extraSpace;
+ } else {
+ cropRect.left -= extraSpace;
+ }
// ADJUST CROP HEIGHT
if (isPortrait) {
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
+import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
public void onChanged() {
liveWallpapersView.removeAllViews();
populateWallpapersFromAdapter(liveWallpapersView, a, false, false);
+ initializeScrollForRtl();
}
});
galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto());
int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray);
galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP);
+
}
PickImageInfo pickImageInfo = new PickImageInfo();
galleryThumbnail.setTag(pickImageInfo);
galleryThumbnail.setOnClickListener(mThumbnailOnClickListener);
+ // Update the scroll for RTL
+ initializeScrollForRtl();
+
// Create smooth layout transitions for when items are deleted
final LayoutTransition transitioner = new LayoutTransition();
transitioner.setDuration(200);
};
}
+ private void initializeScrollForRtl() {
+ final HorizontalScrollView scroll =
+ (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);
+
+ if (scroll.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
+ final ViewTreeObserver observer = scroll.getViewTreeObserver();
+ observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
+ public void onGlobalLayout() {
+ LinearLayout masterWallpaperList =
+ (LinearLayout) findViewById(R.id.master_wallpaper_list);
+ scroll.scrollTo(masterWallpaperList.getWidth(), 0);
+ scroll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
+ });
+ }
+ }
+
public boolean enableRotation() {
return super.enableRotation() || Launcher.sForceEnableRotation;
}
public boolean hasExtraEmptyScreen() {
int nScreens = getChildCount();
- nScreens = hasCustomContent() ? nScreens - 1 : nScreens;
+ nScreens = nScreens - numCustomPages();
return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1;
}
// We enforce at least one page to add new items to. In the case that we remove the last
// such screen, we convert the last screen to the empty screen
- int minScreens = hasCustomContent() ? 2 : 1;
+ int minScreens = 1 + numCustomPages();
int pageShift = 0;
for (Long id: removeScreens) {
float mAnimationStartOffset;
private final int ANIMATION_DURATION = 250;
// Don't use all the wallpaper for parallax until you have at least this many pages
- private final int MIN_PARALLAX_PAGE_SPAN = 4;
+ private final int MIN_PARALLAX_PAGE_SPAN = 3;
int mNumScreens;
public WallpaperOffsetInterpolator() {
}
// Exclude the leftmost page
- final int startPage = hasCustomContent() ? 1 : 0;
- final int firstIndex = isLayoutRtl() ? getChildCount() - 1 - startPage : startPage;
+ int emptyExtraPages = numEmptyScreensToIgnore();
+ int firstIndex = numCustomPages();
// Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages)
- int emptyExtraPages = numExtraScreensToIgnore();
- final int lastIndex =
- isLayoutRtl() ? 0 + emptyExtraPages : getChildCount() - 1 - emptyExtraPages;
+ int lastIndex = getChildCount() - 1 - emptyExtraPages;
+ if (isLayoutRtl()) {
+ int temp = firstIndex;
+ firstIndex = lastIndex;
+ lastIndex = temp;
+ }
int firstPageScrollX = getScrollForPage(firstIndex);
int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX;
return 0;
} else {
// TODO: do different behavior if it's a live wallpaper?
- float offset = Math.min(1, (getScrollX() - firstPageScrollX) / (float) scrollRange);
+ // Sometimes the left parameter of the pages is animated during a layout transition;
+ // this parameter offsets it to keep the wallpaper from animating as well
+ int offsetForLayoutTransitionAnimation = isLayoutRtl() ?
+ getPageAt(getChildCount() - 1).getLeft() - getFirstChildLeft() : 0;
+ int adjustedScroll =
+ getScrollX() - firstPageScrollX - offsetForLayoutTransitionAnimation;
+ float offset = Math.min(1, adjustedScroll / (float) scrollRange);
offset = Math.max(0, offset);
// Don't use up all the wallpaper parallax until you have at least
// MIN_PARALLAX_PAGE_SPAN pages
- int numScrollingPages = getNumScreensExcludingExtraEmptyScreenAndLeftmost();
- int parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages) - 1;
- return offset * (numScrollingPages - 1) / parallaxPageSpan;
+ int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
+ int parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1);
+ // On RTL devices, push the wallpaper offset to the right if we don't have enough
+ // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN)
+ int padding = isLayoutRtl() ? parallaxPageSpan - numScrollingPages + 1 : 0;
+ return offset * (padding + numScrollingPages - 1) / parallaxPageSpan;
}
}
- private int numExtraScreensToIgnore() {
- int numScrollingPages = getChildCount() - 1;
- if (numScrollingPages > MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) {
+ private int numEmptyScreensToIgnore() {
+ int numScrollingPages = getChildCount() - numCustomPages();
+ if (numScrollingPages >= MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) {
return 1;
} else {
return 0;
}
}
- private int getNumScreensExcludingExtraEmptyScreenAndLeftmost() {
- int numScrollingPages = getChildCount() - numExtraScreensToIgnore();
- if (hasCustomContent()) numScrollingPages -= 1;
+ private int getNumScreensExcludingEmptyAndCustom() {
+ int numScrollingPages = getChildCount() - numEmptyScreensToIgnore() - numCustomPages();
return numScrollingPages;
}
public void setFinalX(float x) {
scheduleUpdate();
mFinalOffset = Math.max(0f, Math.min(x, 1.0f));
- if (getNumScreensExcludingExtraEmptyScreenAndLeftmost() != mNumScreens) {
+ if (getNumScreensExcludingEmptyAndCustom() != mNumScreens) {
if (mNumScreens > 0) {
// Don't animate if we're going from 0 screens
animateToFinal();
}
- mNumScreens = getNumScreensExcludingExtraEmptyScreenAndLeftmost();
+ mNumScreens = getNumScreensExcludingEmptyAndCustom();
}
}
return (mScreenOrder.size() > 0 && mScreenOrder.get(0) == CUSTOM_CONTENT_SCREEN_ID);
}
+ public int numCustomPages() {
+ return hasCustomContent() ? 1 : 0;
+ }
+
public boolean isOnOrMovingToCustomContent() {
return hasCustomContent() && getNextPage() == 0;
}
@Override
protected void getOverviewModePages(int[] range) {
- int count = mScreenOrder.size();
-
- int start = hasCustomContent() ? 1 : 0;
+ int start = numCustomPages();
int end = getChildCount() - 1;
range[0] = Math.max(0, Math.min(start, getChildCount() - 1));
protected PageIndicator.PageMarkerResources getPageIndicatorMarker(int pageIndex) {
long screenId = getScreenIdForPageIndex(pageIndex);
if (screenId == EXTRA_EMPTY_SCREEN_ID) {
- int count = mScreenOrder.size() - (hasCustomContent() ? 1 : 0);
+ int count = mScreenOrder.size() - numCustomPages();
if (count > 1) {
return new PageIndicator.PageMarkerResources(R.drawable.ic_pageindicator_current,
R.drawable.ic_pageindicator_add);