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 8e2e77378..0781d1df9 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -1,12 +1,9 @@ package com.simplemobiletools.gallery.activities; -import android.app.WallpaperManager; import android.content.Intent; 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; @@ -31,7 +28,6 @@ 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; @@ -48,6 +44,7 @@ public class ViewPagerActivity extends SimpleActivity @BindView(R.id.view_pager) MyViewPager mPager; private static final int EDIT_IMAGE = 1; + private static final int SET_WALLPAPER = 2; private static ActionBar mActionbar; private static List mMedia; private static String mPath; @@ -140,8 +137,7 @@ public class ViewPagerActivity extends SimpleActivity @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.viewpager_menu, menu); - //menu.findItem(R.id.menu_set_as_wallpaper).setVisible(getCurrentMedium().isImage()); - menu.findItem(R.id.menu_set_as_wallpaper).setVisible(false); + menu.findItem(R.id.menu_set_as_wallpaper).setVisible(getCurrentMedium().isImage()); menu.findItem(R.id.menu_crop_rotate).setVisible(getCurrentMedium().isImage()); return true; } @@ -189,6 +185,18 @@ public class ViewPagerActivity extends SimpleActivity } } + private void setAsWallpaper() { + final Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); + intent.setDataAndType(Uri.fromFile(getCurrentFile()), "image/jpeg"); + final Intent chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with)); + + if (intent.resolveActivity(getPackageManager()) != null) { + startActivityForResult(chooser, SET_WALLPAPER); + } else { + Utils.showToast(getApplicationContext(), R.string.no_wallpaper_setter_found); + } + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == EDIT_IMAGE) { @@ -196,20 +204,14 @@ public class ViewPagerActivity extends SimpleActivity final MyPagerAdapter adapter = (MyPagerAdapter) mPager.getAdapter(); adapter.updateItems(mPos); } + } else if (requestCode == SET_WALLPAPER) { + if (resultCode == RESULT_OK) { + Utils.showToast(getApplicationContext(), R.string.wallpaper_changed_successfully); + } } super.onActivityResult(requestCode, resultCode, data); } - 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-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6a72f846b..1034ddc01 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + Über Weitere einfache Apps und Quellcode findest du auf:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 243c789b9..3f4e5c935 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + Acerca de Más aplicaciones sencillas y código fuente en:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 82b2907f4..20a569ef8 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + Informazioni Altre semplici app e codici sorgenti in:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 6b2ec1827..a21b63ddc 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + アプリについて もっとシンプルなアプリとソースコードは:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 2129edbdc..a96396dfd 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + Sobre Mais aplicações simples e código de fonte em:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index dd6b87105..b74a36ce6 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + Om Fler enkla appar och källkod här:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 88c3fe4b7..2da2f6cf8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,6 +55,11 @@ Unknown file location Could not overwrite the source file + + Set as wallpaper with: + No app capable of it has been found + Wallpaper changed successfully + About More simple apps and source code at:\nhttp://simplemobiletools.com