V1.0.3(3) 添加分开设置壁纸功能

This commit is contained in:
lihongwei 2024-08-14 14:17:29 +08:00
parent 12e254f49b
commit b1a2716ffd
4 changed files with 175 additions and 3 deletions

View File

@ -16,7 +16,7 @@ android {
minSdk = 23 minSdk = 23
targetSdk = 34 targetSdk = 34
versionCode = 2 versionCode = 2
versionName = "1.0.1" versionName = "1.0.3"
setProperty("archivesBaseName", "Shiny Wallpaper_V" + versionName + "(${versionCode})_$timestamp") setProperty("archivesBaseName", "Shiny Wallpaper_V" + versionName + "(${versionCode})_$timestamp")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -41,6 +41,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
</manifest> </manifest>

View File

@ -6,9 +6,12 @@ import android.app.WallpaperManager;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -21,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners; 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.Application.MainApplication;
import com.wallpaper.shinywallpaper.Database.AppDataBase; import com.wallpaper.shinywallpaper.Database.AppDataBase;
import com.wallpaper.shinywallpaper.Database.FavoriteImage; 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.AdManager;
import com.wallpaper.shinywallpaper.topon.onActionListener; 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 { public class FullScreenImageActivity extends AppCompatActivity {
private ImageView fullScreenImageView; private ImageView fullScreenImageView;
@ -138,8 +148,7 @@ public class FullScreenImageActivity extends AppCompatActivity {
AdManager.showTopOn(FullScreenImageActivity.this, new onActionListener() { AdManager.showTopOn(FullScreenImageActivity.this, new onActionListener() {
@Override @Override
public void onAction() { public void onAction() {
showProgress(); showCustomBottomSheetDialog();
setWallpaper();
} }
}); });
@ -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() { private void setWallpaper() {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
@ -194,6 +241,78 @@ public class FullScreenImageActivity extends AppCompatActivity {
}).start(); }).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() { private void toFullScreen() {
Intent intent = new Intent(this, SubFullScreenImageActivity.class); Intent intent = new Intent(this, SubFullScreenImageActivity.class);

View 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>