Merge "Fix calculation of default wallpaper size" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
04cead14b6
@@ -329,40 +329,15 @@ public class WallpaperCropActivity extends Activity {
|
|||||||
// Get the crop
|
// Get the crop
|
||||||
boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
|
boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
|
||||||
|
|
||||||
Point minDims = new Point();
|
|
||||||
Point maxDims = new Point();
|
|
||||||
Display d = getWindowManager().getDefaultDisplay();
|
Display d = getWindowManager().getDefaultDisplay();
|
||||||
d.getCurrentSizeRange(minDims, maxDims);
|
|
||||||
|
|
||||||
Point displaySize = new Point();
|
Point displaySize = new Point();
|
||||||
d.getSize(displaySize);
|
d.getSize(displaySize);
|
||||||
|
|
||||||
int maxDim = Math.max(maxDims.x, maxDims.y);
|
|
||||||
final int minDim = Math.min(minDims.x, minDims.y);
|
|
||||||
int defaultWallpaperWidth;
|
|
||||||
if (isScreenLarge(getResources())) {
|
|
||||||
defaultWallpaperWidth = (int) (maxDim *
|
|
||||||
wallpaperTravelToScreenWidthRatio(maxDim, minDim));
|
|
||||||
} else {
|
|
||||||
defaultWallpaperWidth = Math.max((int)
|
|
||||||
(minDim * WALLPAPER_SCREENS_SPAN), maxDim);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isPortrait = displaySize.x < displaySize.y;
|
boolean isPortrait = displaySize.x < displaySize.y;
|
||||||
int portraitHeight;
|
|
||||||
if (isPortrait) {
|
Point defaultWallpaperSize = getDefaultWallpaperSize(getResources(),
|
||||||
portraitHeight = mCropView.getHeight();
|
getWindowManager());
|
||||||
} else {
|
|
||||||
// TODO: how to actually get the proper portrait height?
|
|
||||||
// This is not quite right:
|
|
||||||
portraitHeight = Math.max(maxDims.x, maxDims.y);
|
|
||||||
}
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >=
|
|
||||||
android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
||||||
Point realSize = new Point();
|
|
||||||
d.getRealSize(realSize);
|
|
||||||
portraitHeight = Math.max(realSize.x, realSize.y);
|
|
||||||
}
|
|
||||||
// Get the crop
|
// Get the crop
|
||||||
RectF cropRect = mCropView.getCrop();
|
RectF cropRect = mCropView.getCrop();
|
||||||
int cropRotation = mCropView.getImageRotation();
|
int cropRotation = mCropView.getImageRotation();
|
||||||
@@ -381,7 +356,7 @@ public class WallpaperCropActivity extends Activity {
|
|||||||
// (or all the way to the left, in RTL)
|
// (or all the way to the left, in RTL)
|
||||||
float extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
|
float extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
|
||||||
// Cap the amount of extra width
|
// Cap the amount of extra width
|
||||||
float maxExtraSpace = defaultWallpaperWidth / cropScale - cropRect.width();
|
float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width();
|
||||||
extraSpace = Math.min(extraSpace, maxExtraSpace);
|
extraSpace = Math.min(extraSpace, maxExtraSpace);
|
||||||
|
|
||||||
if (ltr) {
|
if (ltr) {
|
||||||
@@ -392,10 +367,10 @@ public class WallpaperCropActivity extends Activity {
|
|||||||
|
|
||||||
// ADJUST CROP HEIGHT
|
// ADJUST CROP HEIGHT
|
||||||
if (isPortrait) {
|
if (isPortrait) {
|
||||||
cropRect.bottom = cropRect.top + portraitHeight / cropScale;
|
cropRect.bottom = cropRect.top + defaultWallpaperSize.y / cropScale;
|
||||||
} else { // LANDSCAPE
|
} else { // LANDSCAPE
|
||||||
float extraPortraitHeight =
|
float extraPortraitHeight =
|
||||||
portraitHeight / cropScale - cropRect.height();
|
defaultWallpaperSize.y / cropScale - cropRect.height();
|
||||||
float expandHeight =
|
float expandHeight =
|
||||||
Math.min(Math.min(rotatedInSize[1] - cropRect.bottom, cropRect.top),
|
Math.min(Math.min(rotatedInSize[1] - cropRect.bottom, cropRect.top),
|
||||||
extraPortraitHeight / 2);
|
extraPortraitHeight / 2);
|
||||||
@@ -763,7 +738,7 @@ public class WallpaperCropActivity extends Activity {
|
|||||||
|
|
||||||
protected void updateWallpaperDimensions(int width, int height) {
|
protected void updateWallpaperDimensions(int width, int height) {
|
||||||
String spKey = getSharedPreferencesKey();
|
String spKey = getSharedPreferencesKey();
|
||||||
SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
|
SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
if (width != 0 && height != 0) {
|
if (width != 0 && height != 0) {
|
||||||
editor.putInt(WALLPAPER_WIDTH_KEY, width);
|
editor.putInt(WALLPAPER_WIDTH_KEY, width);
|
||||||
|
|||||||
Reference in New Issue
Block a user