diff options
author | Michael Jurka <mikejurka@google.com> | 2013-10-23 21:59:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-10-23 21:59:53 +0000 |
commit | 03a526b2766f65822ed1a12d212e9e7618a74593 (patch) | |
tree | 00b40037e952027ad50ed927f167b7cb5bd7a8a7 /src/com/android | |
parent | a718fc279d01303026bc7d77f0f55528149172ee (diff) | |
parent | 83699e56be0767bb080b5461896a99f266e7b85e (diff) | |
download | android_packages_apps_Trebuchet-03a526b2766f65822ed1a12d212e9e7618a74593.tar.gz android_packages_apps_Trebuchet-03a526b2766f65822ed1a12d212e9e7618a74593.tar.bz2 android_packages_apps_Trebuchet-03a526b2766f65822ed1a12d212e9e7618a74593.zip |
Merge "Stop using a separate ImageView for default wallpaper" into jb-ub-now-jetsonic
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/DrawableTileSource.java | 102 | ||||
-rw-r--r-- | src/com/android/launcher3/WallpaperPickerActivity.java | 33 | ||||
-rw-r--r-- | src/com/android/photos/BitmapRegionTileSource.java | 2 |
3 files changed, 116 insertions, 21 deletions
diff --git a/src/com/android/launcher3/DrawableTileSource.java b/src/com/android/launcher3/DrawableTileSource.java new file mode 100644 index 000000000..c1f2eff0f --- /dev/null +++ b/src/com/android/launcher3/DrawableTileSource.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2013 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.launcher3; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; + +import com.android.gallery3d.glrenderer.BasicTexture; +import com.android.gallery3d.glrenderer.BitmapTexture; +import com.android.photos.views.TiledImageRenderer; + +public class DrawableTileSource implements TiledImageRenderer.TileSource { + private static final int GL_SIZE_LIMIT = 2048; + // This must be no larger than half the size of the GL_SIZE_LIMIT + // due to decodePreview being allowed to be up to 2x the size of the target + public static final int MAX_PREVIEW_SIZE = GL_SIZE_LIMIT / 2; + + private int mTileSize; + private int mPreviewSize; + private Drawable mDrawable; + private BitmapTexture mPreview; + + public DrawableTileSource(Context context, Drawable d, int previewSize) { + mTileSize = TiledImageRenderer.suggestedTileSize(context); + mDrawable = d; + mPreviewSize = Math.min(previewSize, MAX_PREVIEW_SIZE); + } + + @Override + public int getTileSize() { + return mTileSize; + } + + @Override + public int getImageWidth() { + return mDrawable.getIntrinsicWidth(); + } + + @Override + public int getImageHeight() { + return mDrawable.getIntrinsicHeight(); + } + + @Override + public int getRotation() { + return 0; + } + + @Override + public BasicTexture getPreview() { + if (mPreviewSize == 0) { + return null; + } + if (mPreview == null){ + float width = getImageWidth(); + float height = getImageHeight(); + while (width > MAX_PREVIEW_SIZE || height > MAX_PREVIEW_SIZE) { + width /= 2; + height /= 2; + } + Bitmap b = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(b); + mDrawable.setBounds(new Rect(0, 0, (int) width, (int) height)); + mDrawable.draw(c); + c.setBitmap(null); + mPreview = new BitmapTexture(b); + } + return mPreview; + } + + @Override + public Bitmap getTile(int level, int x, int y, Bitmap bitmap) { + int tileSize = getTileSize(); + if (bitmap == null) { + bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888); + } + Canvas c = new Canvas(bitmap); + Rect bounds = new Rect(0, 0, getImageWidth(), getImageHeight()); + bounds.offset(-x, -y); + mDrawable.setBounds(bounds); + mDrawable.draw(c); + c.setBitmap(null); + return bitmap; + } +} diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index 9c6ee6ec0..c58d66063 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -90,7 +90,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private LinearLayout mWallpapersView; private View mWallpaperStrip; - private ImageView mDefaultWallpaperView; private ActionMode.Callback mActionModeCallback; private ActionMode mActionMode; @@ -134,8 +133,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } @Override public void onClick(WallpaperPickerActivity a) { - a.setCropViewTileSource( - new BitmapRegionTileSource.UriBitmapSource(a, mUri, 1024), true, false); + a.setCropViewTileSource(new BitmapRegionTileSource.UriBitmapSource( + a, mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE), true, false); } @Override public void onSave(final WallpaperPickerActivity a) { @@ -174,11 +173,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { @Override public void onClick(WallpaperPickerActivity a) { BitmapRegionTileSource.ResourceBitmapSource bitmapSource = - new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId, 1024); + new BitmapRegionTileSource.ResourceBitmapSource( + mResources, mResId, BitmapRegionTileSource.MAX_PREVIEW_SIZE); bitmapSource.loadInBackground(); BitmapRegionTileSource source = new BitmapRegionTileSource(a, bitmapSource); CropView v = a.getCropView(); - a.getDefaultWallpaperView().setVisibility(View.INVISIBLE); v.setTileSource(source, null); Point wallpaperSize = WallpaperCropActivity.getDefaultWallpaperSize( a.getResources(), a.getWindowManager()); @@ -210,15 +209,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } @Override public void onClick(WallpaperPickerActivity a) { - a.getCropView().setTouchEnabled(false); - ImageView defaultWallpaperView = a.getDefaultWallpaperView(); - defaultWallpaperView.setVisibility(View.VISIBLE); + CropView c = a.getCropView(); + Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable( - defaultWallpaperView.getWidth(), defaultWallpaperView.getHeight(), - false, 0.5f, 0.5f); - if (defaultWallpaper != null) { - defaultWallpaperView.setBackgroundDrawable(defaultWallpaper); - } + c.getWidth(), c.getHeight(), false, 0.5f, 0.5f); + + c.setTileSource( + new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null); + c.setScale(1f); + c.setTouchEnabled(false); } @Override public void onSave(WallpaperPickerActivity a) { @@ -248,7 +247,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { setContentView(R.layout.wallpaper_picker); mCropView = (CropView) findViewById(R.id.cropView); - mDefaultWallpaperView = (ImageView) findViewById(R.id.defaultWallpaperView); mWallpaperStrip = findViewById(R.id.wallpaper_strip); mCropView.setTouchCallback(new CropView.TouchCallback() { LauncherViewPropertyAnimator mAnim; @@ -409,7 +407,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { // Select the first item; wait for a layout pass so that we initialize the dimensions of // cropView or the defaultWallpaperView first - mDefaultWallpaperView.addOnLayoutChangeListener(new OnLayoutChangeListener() { + mCropView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { @@ -530,7 +528,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { @Override public void setCropViewTileSource(final BitmapRegionTileSource.BitmapSource bitmapSource, final boolean touchEnabled, boolean moveToLeft) { - getDefaultWallpaperView().setVisibility(View.INVISIBLE); super.setCropViewTileSource(bitmapSource, touchEnabled, moveToLeft); } @@ -899,10 +896,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { return mCropView; } - public ImageView getDefaultWallpaperView() { - return mDefaultWallpaperView; - } - public SavedWallpaperImages getSavedImages() { return mSavedImages; } diff --git a/src/com/android/photos/BitmapRegionTileSource.java b/src/com/android/photos/BitmapRegionTileSource.java index 74284b236..b5774f40a 100644 --- a/src/com/android/photos/BitmapRegionTileSource.java +++ b/src/com/android/photos/BitmapRegionTileSource.java @@ -55,7 +55,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { private static final int GL_SIZE_LIMIT = 2048; // This must be no larger than half the size of the GL_SIZE_LIMIT // due to decodePreview being allowed to be up to 2x the size of the target - private static final int MAX_PREVIEW_SIZE = 1024; + public static final int MAX_PREVIEW_SIZE = GL_SIZE_LIMIT / 2; public static abstract class BitmapSource { private BitmapRegionDecoder mDecoder; |