Loading WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +53 −58 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.ActionBar; import android.app.Activity; import android.app.WallpaperManager; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; Loading Loading @@ -57,20 +58,10 @@ import java.util.WeakHashMap; public class WallpaperCropActivity extends BaseActivity implements Handler.Callback { private static final String LOGTAG = "Launcher3.CropActivity"; /** * The maximum bitmap size we allow to be returned through the intent. * Intents have a maximum of 1MB in total size. However, the Bitmap seems to * have some overhead to hit so that we go way below the limit here to make * sure the intent stays below 1MB.We should consider just returning a byte * array instead of a Bitmap instance to avoid overhead. */ public static final int MAX_BMAP_IN_INTENT = 750000; private static final int MSG_LOAD_IMAGE = 1; protected CropView mCropView; protected View mProgressView; protected Uri mUri; protected View mSetWallpaperButton; private HandlerThread mLoaderThread; Loading @@ -91,7 +82,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb init(); if (!enableRotation()) { setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } Loading Loading @@ -159,6 +150,22 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb public boolean handleMessage(Message msg) { if (msg.what == MSG_LOAD_IMAGE) { final LoadRequest req = (LoadRequest) msg.obj; final boolean loadSuccess; if (req.src == null) { Drawable defaultWallpaper = WallpaperManager.getInstance(this) .getBuiltInDrawable(mCropView.getWidth(), mCropView.getHeight(), false, 0.5f, 0.5f); if (defaultWallpaper == null) { loadSuccess = false; Log.w(LOGTAG, "Null default wallpaper encountered."); } else { loadSuccess = true; req.result = new DrawableTileSource(this, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE); } } else { try { req.src.loadInBackground(new InBitmapProvider() { Loading Loading @@ -197,14 +204,17 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb } } req.result = new BitmapRegionTileSource(getContext(), req.src, mTempStorageForDecoding); req.result = new BitmapRegionTileSource(getContext(), req.src, mTempStorageForDecoding); loadSuccess = req.src.getLoadingState() == BitmapSource.State.LOADED; } runOnUiThread(new Runnable() { @Override public void run() { if (req == mCurrentLoadRequest) { onLoadRequestComplete(req, req.src.getLoadingState() == BitmapSource.State.LOADED); onLoadRequestComplete(req, loadSuccess); } else { addReusableBitmap(req.result); } Loading Loading @@ -268,21 +278,6 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb req.postExecute = postExecute; req.scaleProvider = scaleProvider; mCurrentLoadRequest = req; if (bitmapSource == null) { // Load the default wallpaper Drawable defaultWallpaper = WallpaperManager.getInstance(this) .getBuiltInDrawable(mCropView.getWidth(), mCropView.getHeight(), false, 0.5f, 0.5f); if (defaultWallpaper == null) { Log.w(LOGTAG, "Null default wallpaper encountered."); mCropView.setTileSource(null, null); return; } req.result = new DrawableTileSource(this, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE); onLoadRequestComplete(req, true); return; } // Remove any pending requests mLoaderHandler.removeMessages(MSG_LOAD_IMAGE); Loading Loading
WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +53 −58 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.ActionBar; import android.app.Activity; import android.app.WallpaperManager; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; Loading Loading @@ -57,20 +58,10 @@ import java.util.WeakHashMap; public class WallpaperCropActivity extends BaseActivity implements Handler.Callback { private static final String LOGTAG = "Launcher3.CropActivity"; /** * The maximum bitmap size we allow to be returned through the intent. * Intents have a maximum of 1MB in total size. However, the Bitmap seems to * have some overhead to hit so that we go way below the limit here to make * sure the intent stays below 1MB.We should consider just returning a byte * array instead of a Bitmap instance to avoid overhead. */ public static final int MAX_BMAP_IN_INTENT = 750000; private static final int MSG_LOAD_IMAGE = 1; protected CropView mCropView; protected View mProgressView; protected Uri mUri; protected View mSetWallpaperButton; private HandlerThread mLoaderThread; Loading @@ -91,7 +82,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb init(); if (!enableRotation()) { setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } Loading Loading @@ -159,6 +150,22 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb public boolean handleMessage(Message msg) { if (msg.what == MSG_LOAD_IMAGE) { final LoadRequest req = (LoadRequest) msg.obj; final boolean loadSuccess; if (req.src == null) { Drawable defaultWallpaper = WallpaperManager.getInstance(this) .getBuiltInDrawable(mCropView.getWidth(), mCropView.getHeight(), false, 0.5f, 0.5f); if (defaultWallpaper == null) { loadSuccess = false; Log.w(LOGTAG, "Null default wallpaper encountered."); } else { loadSuccess = true; req.result = new DrawableTileSource(this, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE); } } else { try { req.src.loadInBackground(new InBitmapProvider() { Loading Loading @@ -197,14 +204,17 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb } } req.result = new BitmapRegionTileSource(getContext(), req.src, mTempStorageForDecoding); req.result = new BitmapRegionTileSource(getContext(), req.src, mTempStorageForDecoding); loadSuccess = req.src.getLoadingState() == BitmapSource.State.LOADED; } runOnUiThread(new Runnable() { @Override public void run() { if (req == mCurrentLoadRequest) { onLoadRequestComplete(req, req.src.getLoadingState() == BitmapSource.State.LOADED); onLoadRequestComplete(req, loadSuccess); } else { addReusableBitmap(req.result); } Loading Loading @@ -268,21 +278,6 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb req.postExecute = postExecute; req.scaleProvider = scaleProvider; mCurrentLoadRequest = req; if (bitmapSource == null) { // Load the default wallpaper Drawable defaultWallpaper = WallpaperManager.getInstance(this) .getBuiltInDrawable(mCropView.getWidth(), mCropView.getHeight(), false, 0.5f, 0.5f); if (defaultWallpaper == null) { Log.w(LOGTAG, "Null default wallpaper encountered."); mCropView.setTileSource(null, null); return; } req.result = new DrawableTileSource(this, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE); onLoadRequestComplete(req, true); return; } // Remove any pending requests mLoaderHandler.removeMessages(MSG_LOAD_IMAGE); Loading