am 8af8b1c1: am b0e2221f: am 03a526b2: Merge "Stop using a separate ImageView for default wallpaper" into jb-ub-now-jetsonic
* commit '8af8b1c189b83f5178131592a27b99978198f417': Stop using a separate ImageView for default wallpaper
This commit is contained in:
@@ -27,11 +27,6 @@
|
|||||||
android:id="@+id/cropView"
|
android:id="@+id/cropView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
<ImageView
|
|
||||||
android:id="@+id/defaultWallpaperView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="invisible" />
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/loading"
|
android:id="@+id/loading"
|
||||||
style="@android:style/Widget.Holo.ProgressBar.Large"
|
style="@android:style/Widget.Holo.ProgressBar.Large"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,7 +90,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
|
|
||||||
private LinearLayout mWallpapersView;
|
private LinearLayout mWallpapersView;
|
||||||
private View mWallpaperStrip;
|
private View mWallpaperStrip;
|
||||||
private ImageView mDefaultWallpaperView;
|
|
||||||
|
|
||||||
private ActionMode.Callback mActionModeCallback;
|
private ActionMode.Callback mActionModeCallback;
|
||||||
private ActionMode mActionMode;
|
private ActionMode mActionMode;
|
||||||
@@ -134,8 +133,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onClick(WallpaperPickerActivity a) {
|
public void onClick(WallpaperPickerActivity a) {
|
||||||
a.setCropViewTileSource(
|
a.setCropViewTileSource(new BitmapRegionTileSource.UriBitmapSource(
|
||||||
new BitmapRegionTileSource.UriBitmapSource(a, mUri, 1024), true, false);
|
a, mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE), true, false);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onSave(final WallpaperPickerActivity a) {
|
public void onSave(final WallpaperPickerActivity a) {
|
||||||
@@ -174,11 +173,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(WallpaperPickerActivity a) {
|
public void onClick(WallpaperPickerActivity a) {
|
||||||
BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
|
BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
|
||||||
new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId, 1024);
|
new BitmapRegionTileSource.ResourceBitmapSource(
|
||||||
|
mResources, mResId, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
|
||||||
bitmapSource.loadInBackground();
|
bitmapSource.loadInBackground();
|
||||||
BitmapRegionTileSource source = new BitmapRegionTileSource(a, bitmapSource);
|
BitmapRegionTileSource source = new BitmapRegionTileSource(a, bitmapSource);
|
||||||
CropView v = a.getCropView();
|
CropView v = a.getCropView();
|
||||||
a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
|
|
||||||
v.setTileSource(source, null);
|
v.setTileSource(source, null);
|
||||||
Point wallpaperSize = WallpaperCropActivity.getDefaultWallpaperSize(
|
Point wallpaperSize = WallpaperCropActivity.getDefaultWallpaperSize(
|
||||||
a.getResources(), a.getWindowManager());
|
a.getResources(), a.getWindowManager());
|
||||||
@@ -210,15 +209,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onClick(WallpaperPickerActivity a) {
|
public void onClick(WallpaperPickerActivity a) {
|
||||||
a.getCropView().setTouchEnabled(false);
|
CropView c = a.getCropView();
|
||||||
ImageView defaultWallpaperView = a.getDefaultWallpaperView();
|
|
||||||
defaultWallpaperView.setVisibility(View.VISIBLE);
|
|
||||||
Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable(
|
Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable(
|
||||||
defaultWallpaperView.getWidth(), defaultWallpaperView.getHeight(),
|
c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
|
||||||
false, 0.5f, 0.5f);
|
|
||||||
if (defaultWallpaper != null) {
|
c.setTileSource(
|
||||||
defaultWallpaperView.setBackgroundDrawable(defaultWallpaper);
|
new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null);
|
||||||
}
|
c.setScale(1f);
|
||||||
|
c.setTouchEnabled(false);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onSave(WallpaperPickerActivity a) {
|
public void onSave(WallpaperPickerActivity a) {
|
||||||
@@ -248,7 +247,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
setContentView(R.layout.wallpaper_picker);
|
setContentView(R.layout.wallpaper_picker);
|
||||||
|
|
||||||
mCropView = (CropView) findViewById(R.id.cropView);
|
mCropView = (CropView) findViewById(R.id.cropView);
|
||||||
mDefaultWallpaperView = (ImageView) findViewById(R.id.defaultWallpaperView);
|
|
||||||
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
|
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
|
||||||
mCropView.setTouchCallback(new CropView.TouchCallback() {
|
mCropView.setTouchCallback(new CropView.TouchCallback() {
|
||||||
LauncherViewPropertyAnimator mAnim;
|
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
|
// Select the first item; wait for a layout pass so that we initialize the dimensions of
|
||||||
// cropView or the defaultWallpaperView first
|
// cropView or the defaultWallpaperView first
|
||||||
mDefaultWallpaperView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
mCropView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
||||||
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||||
@@ -530,7 +528,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void setCropViewTileSource(final BitmapRegionTileSource.BitmapSource bitmapSource,
|
public void setCropViewTileSource(final BitmapRegionTileSource.BitmapSource bitmapSource,
|
||||||
final boolean touchEnabled, boolean moveToLeft) {
|
final boolean touchEnabled, boolean moveToLeft) {
|
||||||
getDefaultWallpaperView().setVisibility(View.INVISIBLE);
|
|
||||||
super.setCropViewTileSource(bitmapSource, touchEnabled, moveToLeft);
|
super.setCropViewTileSource(bitmapSource, touchEnabled, moveToLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -899,10 +896,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
|
|||||||
return mCropView;
|
return mCropView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageView getDefaultWallpaperView() {
|
|
||||||
return mDefaultWallpaperView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SavedWallpaperImages getSavedImages() {
|
public SavedWallpaperImages getSavedImages() {
|
||||||
return mSavedImages;
|
return mSavedImages;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource {
|
|||||||
private static final int GL_SIZE_LIMIT = 2048;
|
private static final int GL_SIZE_LIMIT = 2048;
|
||||||
// This must be no larger than half the size of the GL_SIZE_LIMIT
|
// 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
|
// 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 {
|
public static abstract class BitmapSource {
|
||||||
private BitmapRegionDecoder mDecoder;
|
private BitmapRegionDecoder mDecoder;
|
||||||
|
|||||||
Reference in New Issue
Block a user