From ea9e43c00bd3b66951cf3520dea35a57edc51eaa Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 24 Aug 2016 23:39:46 +0200 Subject: [PATCH] apply the image as wallpaper if picked so --- .../gallery/activities/ViewPagerActivity.java | 15 +++++++++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 77f4831f5..67c75077b 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -1,8 +1,11 @@ package com.simplemobiletools.gallery.activities; +import android.app.WallpaperManager; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.media.MediaScannerConnection; import android.net.Uri; import android.os.Bundle; @@ -27,6 +30,7 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment; import com.simplemobiletools.gallery.models.Medium; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -143,6 +147,7 @@ public class ViewPagerActivity extends SimpleActivity deleteFile(); switch (item.getItemId()) { case R.id.menu_set_as_wallpaper: + setAsWallpaper(); return true; case R.id.menu_share: shareMedium(); @@ -158,6 +163,16 @@ public class ViewPagerActivity extends SimpleActivity } } + private void setAsWallpaper() { + final Bitmap bitmap = BitmapFactory.decodeFile(getCurrentFile().getAbsolutePath()); + final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext()); + try { + wallpaperManager.setBitmap(bitmap); + } catch (IOException e) { + Utils.showToast(getApplicationContext(), R.string.set_as_wallpaper_failed); + } + } + private void shareMedium() { final Medium medium = getCurrentMedium(); Utils.shareMedium(medium, this); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e23efc869..73048975f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ OK Cancel Set as Wallpaper + Setting as Wallpaper failed 1 folder deleted