use of android.app.WallpaperManager in project ZI by yixia.
the class CropImage method onSaveClicked.
private void onSaveClicked() {
// bitmap doesn't have to be read into memory
if (mSaving)
return;
if (mCrop == null) {
return;
}
mSaving = true;
Rect r = mCrop.getCropRect();
int width = r.width();
int height = r.height();
// If we are circle cropping, we want alpha channel, which is the
// third param here.
Bitmap croppedImage = Bitmap.createBitmap(width, height, mCircleCrop ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
{
Canvas canvas = new Canvas(croppedImage);
Rect dstRect = new Rect(0, 0, width, height);
canvas.drawBitmap(mBitmap, r, dstRect, null);
}
if (mCircleCrop) {
// OK, so what's all this about?
// Bitmaps are inherently rectangular but we want to return
// something that's basically a circle. So we fill in the
// area around the circle with alpha. Note the all important
// PortDuff.Mode.CLEAR.
Canvas c = new Canvas(croppedImage);
Path p = new Path();
p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
c.clipPath(p, Region.Op.DIFFERENCE);
c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
}
/* If the output is required to a specific size then scale or fill */
if (mOutputX != 0 && mOutputY != 0) {
if (mScale) {
/* Scale the image to the required dimensions */
Bitmap old = croppedImage;
croppedImage = BitmapUtils.transform(new Matrix(), croppedImage, mOutputX, mOutputY, mScaleUp);
if (old != croppedImage) {
old.recycle();
}
} else {
/* Don't scale the image crop it to the size requested.
* Create an new image with the cropped image in the center and
* the extra space filled.
*/
// Don't scale the image but instead fill it so it's the
// required dimension
Bitmap b = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(b);
Rect srcRect = mCrop.getCropRect();
Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);
int dx = (srcRect.width() - dstRect.width()) / 2;
int dy = (srcRect.height() - dstRect.height()) / 2;
/* If the srcRect is too big, use the center part of it. */
srcRect.inset(Math.max(0, dx), Math.max(0, dy));
/* If the dstRect is too big, use the center part of it. */
dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));
/* Draw the cropped bitmap in the center */
canvas.drawBitmap(mBitmap, srcRect, dstRect, null);
/* Set the cropped bitmap as the new bitmap */
croppedImage.recycle();
croppedImage = b;
}
}
// Return the cropped image directly or save it to the specified URI.
Bundle myExtras = getIntent().getExtras();
if (myExtras != null && (myExtras.getParcelable("data") != null || myExtras.getBoolean("return-data"))) {
Bundle extras = new Bundle();
extras.putParcelable("data", croppedImage);
setResult(RESULT_OK, (new Intent()).setAction("inline-data").putExtras(extras));
finish();
} else if (myExtras != null && myExtras.getBoolean("set-wallpaper")) {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage(getString(R.string.cropimage_wallpaper_is_setting));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
new AsyncTask<Bitmap, Void, Boolean>() {
protected void onPreExecute() {
dialog.show();
}
protected void onPostExecute(Boolean result) {
reset();
if (result)
showToast(R.string.cropimage_wallpaper_success);
else
showToast(R.string.cropimage_wallpaper_failed);
CropImage.this.finish();
}
protected void onCancelled() {
reset();
}
@Override
protected Boolean doInBackground(Bitmap... image) {
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(CropImage.this);
if (image != null && image[0] != null) {
try {
myWallpaperManager.setBitmap(image[0]);
} catch (IOException e) {
return false;
}
} else {
return false;
}
return true;
}
private void reset() {
dialog.dismiss();
}
private void showToast(int resID) {
Toast.makeText(CropImage.this, getString(resID), Toast.LENGTH_SHORT).show();
}
}.execute(croppedImage);
} else {
final Bitmap b = croppedImage;
BitmapUtils.startBackgroundJob(this, null, getString(R.string.cropimage_image_saving), new Runnable() {
public void run() {
saveOutput(b);
}
}, mHandler);
}
}
use of android.app.WallpaperManager in project android_packages_apps_Launcher2 by CyanogenMod.
the class UserInitializeReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
final Resources resources = context.getResources();
// Context.getPackageName() may return the "original" package name,
// com.android.launcher2; Resources needs the real package name,
// com.android.launcher. So we ask Resources for what it thinks the
// package name should be.
final String packageName = resources.getResourcePackageName(R.array.wallpapers);
ArrayList<Integer> list = new ArrayList<Integer>();
addWallpapers(resources, packageName, R.array.wallpapers, list);
addWallpapers(resources, packageName, R.array.extra_wallpapers, list);
WallpaperManager wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
for (int i = 1; i < list.size(); i++) {
int resid = list.get(i);
if (!wpm.hasResourceWallpaper(resid)) {
try {
wpm.setResource(resid);
} catch (IOException e) {
}
return;
}
}
}
use of android.app.WallpaperManager in project android_packages_apps_Launcher2 by CyanogenMod.
the class WallpaperChooserDialogFragment method selectWallpaper.
private void selectWallpaper(int position) {
try {
WallpaperManager wpm = (WallpaperManager) getActivity().getSystemService(Context.WALLPAPER_SERVICE);
wpm.setResource(mImages.get(position));
Activity activity = getActivity();
activity.setResult(Activity.RESULT_OK);
activity.finish();
} catch (IOException e) {
Log.e(TAG, "Failed to set wallpaper: " + e);
}
}
use of android.app.WallpaperManager in project Wallpaper-Manager by Bencodes.
the class WallpaperFragment method applyImage.
public void applyImage() {
if (this.mImageDrawableSet == false) {
this.mApplyImageOnDisplay = true;
return;
}
try {
final Bitmap bitmap = getImageBitmap();
if (bitmap == null) {
Toast.makeText(getActivity(), "Something Went Wrong, Please Try Again!", Toast.LENGTH_SHORT).show();
return;
}
final WallpaperManager wpManager = WallpaperManager.getInstance(getActivity());
if (wpManager == null) {
Toast.makeText(getActivity(), "Something Went Wrong, Please Try Again!", Toast.LENGTH_SHORT).show();
return;
}
wpManager.setBitmap(bitmap);
Toast.makeText(getActivity(), "Wallpaper Set!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e(TAG, "", e);
Toast.makeText(getActivity(), "Something Went Wrong, Please Try Again!", Toast.LENGTH_SHORT).show();
}
}
use of android.app.WallpaperManager in project ADWLauncher2 by boombuler.
the class WallpaperChooser method selectWallpaper.
/*
* When using touch if you tap an image it triggers both the onItemClick and
* the onTouchEvent causing the wallpaper to be set twice. Ensure we only
* set the wallpaper once.
*/
private void selectWallpaper(int position) {
if (mIsWallpaperSet) {
return;
}
mIsWallpaperSet = true;
try {
WallpaperManager wpm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
wpm.setResource(mImages.get(position));
setResult(RESULT_OK);
finish();
} catch (IOException e) {
Log.e(TAG, "Failed to set wallpaper: " + e);
}
}
Aggregations