V1.0.3(3) 添加分开设置壁纸功能
This commit is contained in:
parent
12e254f49b
commit
b1a2716ffd
@ -16,7 +16,7 @@ android {
|
||||
minSdk = 23
|
||||
targetSdk = 34
|
||||
versionCode = 2
|
||||
versionName = "1.0.1"
|
||||
versionName = "1.0.3"
|
||||
setProperty("archivesBaseName", "Shiny Wallpaper_V" + versionName + "(${versionCode})_$timestamp")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -6,9 +6,12 @@ import android.app.WallpaperManager;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
@ -21,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.wallpaper.shinywallpaper.Application.MainApplication;
|
||||
import com.wallpaper.shinywallpaper.Database.AppDataBase;
|
||||
import com.wallpaper.shinywallpaper.Database.FavoriteImage;
|
||||
@ -32,6 +36,12 @@ import com.wallpaper.shinywallpaper.Utils.GallerySaver;
|
||||
import com.wallpaper.shinywallpaper.topon.AdManager;
|
||||
import com.wallpaper.shinywallpaper.topon.onActionListener;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class FullScreenImageActivity extends AppCompatActivity {
|
||||
|
||||
private ImageView fullScreenImageView;
|
||||
@ -138,8 +148,7 @@ public class FullScreenImageActivity extends AppCompatActivity {
|
||||
AdManager.showTopOn(FullScreenImageActivity.this, new onActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
showProgress();
|
||||
setWallpaper();
|
||||
showCustomBottomSheetDialog();
|
||||
}
|
||||
});
|
||||
|
||||
@ -162,6 +171,44 @@ public class FullScreenImageActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
|
||||
private void showCustomBottomSheetDialog() {
|
||||
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
|
||||
View dialogView = LayoutInflater.from(this).inflate(R.layout.set_dialog, null);
|
||||
|
||||
bottomSheetDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
dialogView.findViewById(R.id.both).setOnClickListener(v -> {
|
||||
// 处理选项 1
|
||||
showProgress();
|
||||
setWallpaper();
|
||||
//销毁BottomSheetDialog对象
|
||||
bottomSheetDialog.dismiss();
|
||||
});
|
||||
|
||||
dialogView.findViewById(R.id.lock).setOnClickListener(v -> {
|
||||
// 处理选项 2
|
||||
showProgress();
|
||||
setWallpaperLock();
|
||||
bottomSheetDialog.dismiss();
|
||||
});
|
||||
|
||||
dialogView.findViewById(R.id.desktop).setOnClickListener(v -> {
|
||||
// 处理取消按钮
|
||||
showProgress();
|
||||
setWallpaperDeskTop();
|
||||
bottomSheetDialog.dismiss();
|
||||
});
|
||||
|
||||
dialogView.findViewById(R.id.cancel).setOnClickListener(v -> {
|
||||
|
||||
// 处理取消按钮
|
||||
bottomSheetDialog.dismiss();
|
||||
});
|
||||
|
||||
bottomSheetDialog.setContentView(dialogView);
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
|
||||
private void setWallpaper() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
@ -194,6 +241,78 @@ public class FullScreenImageActivity extends AppCompatActivity {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void setWallpaperLock() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
fullScreenImageView.setDrawingCacheEnabled(true);
|
||||
Bitmap bitmap = ((BitmapDrawable) fullScreenImageView.getDrawable()).getBitmap();
|
||||
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
|
||||
//判断版本,高于24可以单独设置,否则全部设置
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);
|
||||
}else {
|
||||
wallpaperManager.setBitmap(bitmap);
|
||||
}
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideProgress();
|
||||
setWallpaperButton.setEnabled(true); // Re-enable the button
|
||||
Toast.makeText(getApplicationContext(), StaticValue.key_wallpaper_setting_is_successful, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideProgress();
|
||||
Toast.makeText(getApplicationContext(), StaticValue.key_failed_to_set_wallpaper, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void setWallpaperDeskTop() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
fullScreenImageView.setDrawingCacheEnabled(true);
|
||||
Bitmap bitmap = ((BitmapDrawable) fullScreenImageView.getDrawable()).getBitmap();
|
||||
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
|
||||
//判断版本,高于24可以单独设置,否则全部设置
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_SYSTEM);
|
||||
}else {
|
||||
wallpaperManager.setBitmap(bitmap);
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideProgress();
|
||||
setWallpaperButton.setEnabled(true); // Re-enable the button
|
||||
Toast.makeText(getApplicationContext(), StaticValue.key_wallpaper_setting_is_successful, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hideProgress();
|
||||
Toast.makeText(getApplicationContext(), StaticValue.key_failed_to_set_wallpaper, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void toFullScreen() {
|
||||
Intent intent = new Intent(this, SubFullScreenImageActivity.class);
|
||||
|
||||
52
app/src/main/res/layout/set_dialog.xml
Normal file
52
app/src/main/res/layout/set_dialog.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:id="@+id/both"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:gravity="center"
|
||||
android:text="Both" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/lock"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/both"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:gravity="center"
|
||||
android:text="Lock" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/desktop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/lock"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="100dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:layout_marginBottom="35dp"
|
||||
android:gravity="center"
|
||||
android:text="Desktop" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="25dp"
|
||||
android:src="@drawable/back" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
Loading…
Reference in New Issue
Block a user