diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 27f95db18..288627520 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android">
+
+
+
+
+
+
mDirs;
private static Snackbar mSnackbar;
@@ -60,6 +61,7 @@ public class MainActivity extends AppCompatActivity
private static boolean mIsSnackbarShown;
private static boolean mIsPickImageIntent;
private static boolean mIsPickVideoIntent;
+ private static boolean mIsSetWallpaperIntent;
private static int mSelectedItemsCnt;
@Override
@@ -67,12 +69,18 @@ public class MainActivity extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
- mIsPickImageIntent = isPickImageIntent(getIntent());
- mIsPickVideoIntent = isPickVideoIntent(getIntent());
+
+ final Intent intent = getIntent();
+ mIsPickImageIntent = isPickImageIntent(intent);
+ mIsPickVideoIntent = isPickVideoIntent(intent);
+ mIsSetWallpaperIntent = isSetWallpaperIntent(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
+ if (mIsSetWallpaperIntent)
+ return false;
+
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@@ -352,13 +360,22 @@ public class MainActivity extends AppCompatActivity
return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK) && intent.getData() != null;
}
+ private boolean isSetWallpaperIntent(Intent intent) {
+ return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_SET_WALLPAPER);
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == PICK_MEDIA && resultCode == RESULT_OK && data != null) {
- final Intent result = new Intent();
- result.setData(data.getData());
- setResult(RESULT_OK, result);
- finish();
+ if (resultCode == RESULT_OK) {
+ if (requestCode == PICK_MEDIA && data != null) {
+ final Intent result = new Intent();
+ result.setData(data.getData());
+ setResult(RESULT_OK, result);
+ finish();
+ } else if (requestCode == PICK_WALLPAPER) {
+ setResult(RESULT_OK);
+ finish();
+ }
}
super.onActivityResult(requestCode, resultCode, data);
}
@@ -367,9 +384,15 @@ public class MainActivity extends AppCompatActivity
public void onItemClick(AdapterView> parent, View view, int position, long id) {
final Intent intent = new Intent(this, MediaActivity.class);
intent.putExtra(Constants.DIRECTORY, mDirs.get(position).getPath());
- intent.putExtra(Constants.PICK_IMAGE_INTENT, mIsPickImageIntent);
- intent.putExtra(Constants.PICK_VIDEO_INTENT, mIsPickVideoIntent);
- startActivityForResult(intent, PICK_MEDIA);
+
+ if (mIsSetWallpaperIntent) {
+ intent.putExtra(Constants.SET_WALLPAPER_INTENT, true);
+ startActivityForResult(intent, PICK_WALLPAPER);
+ } else {
+ intent.putExtra(Constants.PICK_IMAGE_INTENT, mIsPickImageIntent);
+ intent.putExtra(Constants.PICK_VIDEO_INTENT, mIsPickVideoIntent);
+ startActivityForResult(intent, PICK_MEDIA);
+ }
}
@Override
diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
index ea4ddfac1..849c78c87 100644
--- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
+++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java
@@ -1,8 +1,10 @@
package com.simplemobiletools.gallery.activities;
+import android.app.WallpaperManager;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
+import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.MediaScannerConnection;
import android.net.Uri;
@@ -12,6 +14,7 @@ import android.provider.MediaStore;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Menu;
@@ -22,6 +25,9 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.animation.GlideAnimation;
+import com.bumptech.glide.request.target.SimpleTarget;
import com.simplemobiletools.gallery.Constants;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.Utils;
@@ -29,6 +35,7 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter;
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;
@@ -39,6 +46,7 @@ import butterknife.ButterKnife;
public class MediaActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
+ private static final String TAG = MediaActivity.class.getSimpleName();
@BindView(R.id.media_grid) GridView mGridView;
private static List mMedia;
@@ -247,16 +255,44 @@ public class MediaActivity extends AppCompatActivity
}
}
+ private boolean isSetWallpaperIntent() {
+ return getIntent().getBooleanExtra(Constants.SET_WALLPAPER_INTENT, false);
+ }
+
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- if (mIsPickImageIntent || mIsPickVideoIntent) {
+ final String curItemPath = mMedia.get(position).getPath();
+ if (isSetWallpaperIntent()) {
+ Utils.showToast(this, R.string.setting_wallpaper);
+
+ final int wantedWidth = getWallpaperDesiredMinimumWidth();
+ final int wantedHeight = getWallpaperDesiredMinimumHeight();
+ final float ratio = (float) wantedWidth / wantedHeight;
+ Glide.with(this)
+ .load(new File(curItemPath))
+ .asBitmap()
+ .override((int) (wantedWidth * ratio), wantedHeight)
+ .fitCenter()
+ .into(new SimpleTarget() {
+ @Override
+ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
+ try {
+ WallpaperManager.getInstance(getApplicationContext()).setBitmap(bitmap);
+ setResult(RESULT_OK);
+ } catch (IOException e) {
+ Log.e(TAG, "item click " + e.getMessage());
+ }
+ finish();
+ }
+ });
+ } else if (mIsPickImageIntent || mIsPickVideoIntent) {
final Intent result = new Intent();
- result.setData(Uri.parse(mMedia.get(position).getPath()));
+ result.setData(Uri.parse(curItemPath));
setResult(RESULT_OK, result);
finish();
} else {
final Intent intent = new Intent(this, ViewPagerActivity.class);
- intent.putExtra(Constants.MEDIUM, mMedia.get(position).getPath());
+ intent.putExtra(Constants.MEDIUM, curItemPath);
startActivity(intent);
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c5efca46a..784d74c67 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -17,6 +17,7 @@
Renaming folder
Extension
File deleted
+ Setting wallpaper
- 1 folder deleted