offer third party apps at setting as wallpaper

This commit is contained in:
tibbi 2016-10-08 16:47:36 +02:00
parent f765bf7dc9
commit 8aa93491f2
8 changed files with 53 additions and 16 deletions

View File

@ -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<Medium> 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);

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">Über</string>
<string name="website">Weitere einfache Apps und Quellcode findest du auf:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">Acerca de</string>
<string name="website">Más aplicaciones sencillas y código fuente en:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">Informazioni</string>
<string name="website">Altre semplici app e codici sorgenti in:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">アプリについて</string>
<string name="website">もっとシンプルなアプリとソースコードは:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">Sobre</string>
<string name="website">Mais aplicações simples e código de fonte em:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">Om</string>
<string name="website">Fler enkla appar och källkod här:\nhttp://simplemobiletools.com</string>

View File

@ -55,6 +55,11 @@
<string name="unknown_file_location">Unknown file location</string>
<string name="error_saving_file">Could not overwrite the source file</string>
<!-- Set wallpaper -->
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<!-- About -->
<string name="about">About</string>
<string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</string>