基本实现背景图层更换,操作流程与图片资源管理部分未完善。
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Fri Nov 21 12:03:39 GMT 2025
|
#Fri Nov 21 13:17:50 GMT 2025
|
||||||
stageCount=7
|
stageCount=7
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.6
|
publishVersion=15.11.6
|
||||||
buildCount=17
|
buildCount=26
|
||||||
baseBetaVersion=15.11.7
|
baseBetaVersion=15.11.7
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class MainActivity extends WinBoLLActivity {
|
|||||||
public static void reloadBackground() {
|
public static void reloadBackground() {
|
||||||
// 修复:添加非空校验,避免Activity已销毁时调用
|
// 修复:添加非空校验,避免Activity已销毁时调用
|
||||||
if (_mMainActivity != null && !_mMainActivity.isFinishing() && !_mMainActivity.isDestroyed()) {
|
if (_mMainActivity != null && !_mMainActivity.isFinishing() && !_mMainActivity.isDestroyed()) {
|
||||||
_mMainActivity.mMainViewFragment.loadBackground();
|
_mMainActivity.mMainViewFragment.reloadBackground();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ 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.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||||
import cc.winboll.studio.libaes.views.AToolbar;
|
import cc.winboll.studio.libaes.views.AToolbar;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
@@ -24,16 +24,17 @@ import cc.winboll.studio.powerbell.App;
|
|||||||
import cc.winboll.studio.powerbell.R;
|
import cc.winboll.studio.powerbell.R;
|
||||||
import cc.winboll.studio.powerbell.beans.BackgroundPictureBean;
|
import cc.winboll.studio.powerbell.beans.BackgroundPictureBean;
|
||||||
import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog;
|
import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog;
|
||||||
|
import cc.winboll.studio.powerbell.dialogs.NetworkBackgroundDialog;
|
||||||
import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils;
|
import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.FileUtils;
|
import cc.winboll.studio.powerbell.utils.FileUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.UriUtil;
|
import cc.winboll.studio.powerbell.utils.UriUtil;
|
||||||
|
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import cc.winboll.studio.powerbell.dialogs.NetworkBackgroundDialog;
|
|
||||||
|
|
||||||
public class BackgroundPictureActivity extends WinBoLLActivity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener {
|
public class BackgroundPictureActivity extends WinBoLLActivity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener {
|
||||||
|
|
||||||
@@ -54,6 +55,10 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
|
|||||||
private File mfTempCropPicture; // 剪裁临时文件
|
private File mfTempCropPicture; // 剪裁临时文件
|
||||||
private File mfRecivedCropPicture; // 剪裁后的目标文件
|
private File mfRecivedCropPicture; // 剪裁后的目标文件
|
||||||
|
|
||||||
|
private String preViewFileBackgroundView = "";
|
||||||
|
BackgroundView bvPreviewBackground;
|
||||||
|
boolean isCommitSettings = false;
|
||||||
|
|
||||||
// 静态变量
|
// 静态变量
|
||||||
public static String _mszRecivedCropPicture = "RecivedCrop.jpg";
|
public static String _mszRecivedCropPicture = "RecivedCrop.jpg";
|
||||||
private static String _mszCommonFileType = "jpeg";
|
private static String _mszCommonFileType = "jpeg";
|
||||||
@@ -103,7 +108,7 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
|
|||||||
mAToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
mAToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
finish();
|
finish(); // 点击导航栏返回按钮,触发 finish()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -158,31 +163,36 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
|
|||||||
*/
|
*/
|
||||||
public void updatePreviewBackground() {
|
public void updatePreviewBackground() {
|
||||||
LogUtils.d(TAG, "updatePreviewBackground");
|
LogUtils.d(TAG, "updatePreviewBackground");
|
||||||
ImageView ivPreviewBackground = (ImageView) findViewById(R.id.activitybackgroundpictureImageView1);
|
//ImageView ivPreviewBackground = (ImageView) findViewById(R.id.activitybackgroundpictureImageView1);
|
||||||
|
bvPreviewBackground = (BackgroundView) findViewById(R.id.activitybackgroundpictureBackgroundView1);
|
||||||
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(this);
|
BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(this);
|
||||||
utils.loadBackgroundPictureBean();
|
utils.loadBackgroundPictureBean();
|
||||||
|
|
||||||
boolean isUseBackgroundFile = utils.getBackgroundPictureBean().isUseBackgroundFile();
|
boolean isUseBackgroundFile = utils.getBackgroundPictureBean().isUseBackgroundFile();
|
||||||
if (isUseBackgroundFile && mfRecivedCropPicture.exists()) {
|
if (isUseBackgroundFile && mfRecivedCropPicture.exists()) {
|
||||||
try {
|
//try {
|
||||||
String filePath = utils.getBackgroundDir() + getBackgroundFileName();
|
String filePath = utils.getBackgroundDir() + getBackgroundFileName();
|
||||||
Drawable drawable = FileUtils.getImageDrawable(filePath);
|
preViewFileBackgroundView = filePath;
|
||||||
|
bvPreviewBackground.previewBackgroundImage(preViewFileBackgroundView);
|
||||||
|
/*Drawable drawable = FileUtils.getImageDrawable(filePath);
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
//drawable.setAlpha(120);
|
//drawable.setAlpha(120);
|
||||||
ivPreviewBackground.setImageDrawable(drawable);
|
//bvPreviewBackground.setImageDrawable(drawable);
|
||||||
}
|
}*/
|
||||||
//ToastUtils.show("背景图片已更新");
|
//ToastUtils.show("背景图片已更新");
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
ToastUtils.show("背景图片加载失败");
|
// ToastUtils.show("背景图片加载失败");
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show("未使用背景图片");
|
ToastUtils.show("未使用背景图片");
|
||||||
Drawable drawable = getResources().getDrawable(R.drawable.blank10x10);
|
preViewFileBackgroundView = "";
|
||||||
if (drawable != null) {
|
bvPreviewBackground.previewBackgroundImage(preViewFileBackgroundView);
|
||||||
drawable.setAlpha(120);
|
// Drawable drawable = getResources().getDrawable(R.drawable.blank10x10);
|
||||||
ivPreviewBackground.setImageDrawable(drawable);
|
// if (drawable != null) {
|
||||||
}
|
// drawable.setAlpha(120);
|
||||||
|
// bvPreviewBackground.setImageDrawable(drawable);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,5 +629,31 @@ public class BackgroundPictureActivity extends WinBoLLActivity implements Backgr
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写finish方法,确保所有退出场景都触发Toast
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
|
if (!isCommitSettings) {
|
||||||
|
YesNoAlertDialog.show(this, "应用背景更改提示:", "是否应用预览图片?", new YesNoAlertDialog.OnDialogResultListener(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNo() {
|
||||||
|
isCommitSettings = true;
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onYes() {
|
||||||
|
bvPreviewBackground.saveToBackgroundSources(preViewFileBackgroundView);
|
||||||
|
isCommitSettings = true;
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
super.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import android.os.Message;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -20,15 +19,12 @@ import android.widget.TextView;
|
|||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.powerbell.App;
|
import cc.winboll.studio.powerbell.App;
|
||||||
import cc.winboll.studio.powerbell.R;
|
import cc.winboll.studio.powerbell.R;
|
||||||
import cc.winboll.studio.powerbell.activities.BackgroundPictureActivity;
|
|
||||||
import cc.winboll.studio.powerbell.beans.BackgroundPictureBean;
|
|
||||||
import cc.winboll.studio.powerbell.services.ControlCenterService;
|
import cc.winboll.studio.powerbell.services.ControlCenterService;
|
||||||
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
|
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils;
|
|
||||||
import cc.winboll.studio.powerbell.utils.ServiceUtils;
|
import cc.winboll.studio.powerbell.utils.ServiceUtils;
|
||||||
|
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||||
import cc.winboll.studio.powerbell.views.BatteryDrawable;
|
import cc.winboll.studio.powerbell.views.BatteryDrawable;
|
||||||
import cc.winboll.studio.powerbell.views.VerticalSeekBar;
|
import cc.winboll.studio.powerbell.views.VerticalSeekBar;
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class MainViewFragment extends Fragment {
|
public class MainViewFragment extends Fragment {
|
||||||
|
|
||||||
@@ -72,6 +68,7 @@ public class MainViewFragment extends Fragment {
|
|||||||
TextView mtvUsegeReminderValue;
|
TextView mtvUsegeReminderValue;
|
||||||
CheckBox mcbUsegeReminderValue;
|
CheckBox mcbUsegeReminderValue;
|
||||||
TextView mtvCurrentValue;
|
TextView mtvCurrentValue;
|
||||||
|
BackgroundView bvPreviewBackground;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -81,7 +78,8 @@ public class MainViewFragment extends Fragment {
|
|||||||
mAppConfigUtils = App.getAppConfigUtils(getActivity());
|
mAppConfigUtils = App.getAppConfigUtils(getActivity());
|
||||||
|
|
||||||
// 获取指定ID的View实例
|
// 获取指定ID的View实例
|
||||||
final View mainImageView = mView.findViewById(R.id.fragmentmainviewImageView1);
|
bvPreviewBackground = mView.findViewById(R.id.fragmentmainviewBackgroundView1);
|
||||||
|
/*final View mainImageView = mView.findViewById(R.id.fragmentmainviewImageView1);
|
||||||
|
|
||||||
// 注册OnGlobalLayoutListener
|
// 注册OnGlobalLayoutListener
|
||||||
mainImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
mainImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@@ -99,7 +97,7 @@ public class MainViewFragment extends Fragment {
|
|||||||
// 移除监听器以避免内存泄漏
|
// 移除监听器以避免内存泄漏
|
||||||
mainImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
mainImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
|
|
||||||
mDrawableFrame = getActivity().getDrawable(R.drawable.bg_frame);
|
mDrawableFrame = getActivity().getDrawable(R.drawable.bg_frame);
|
||||||
mllLeftSeekBar = (LinearLayout) mView.findViewById(R.id.fragmentmainviewLinearLayout1);
|
mllLeftSeekBar = (LinearLayout) mView.findViewById(R.id.fragmentmainviewLinearLayout1);
|
||||||
@@ -302,22 +300,23 @@ public class MainViewFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBackground() {
|
public void reloadBackground() {
|
||||||
BackgroundPictureBean bean = BackgroundPictureUtils.getInstance(getActivity()).getBackgroundPictureBean();
|
bvPreviewBackground.reloadBackgroundImage();
|
||||||
ImageView imageView = mView.findViewById(R.id.fragmentmainviewImageView1);
|
// BackgroundPictureBean bean = BackgroundPictureUtils.getInstance(getActivity()).getBackgroundPictureBean();
|
||||||
String szBackgroundFilePath = BackgroundPictureUtils.getInstance(getActivity()).getBackgroundDir() + BackgroundPictureActivity.getBackgroundFileName();
|
// ImageView imageView = mView.findViewById(R.id.fragmentmainviewImageView1);
|
||||||
File fBackgroundFilePath = new File(szBackgroundFilePath);
|
// String szBackgroundFilePath = BackgroundPictureUtils.getInstance(getActivity()).getBackgroundDir() + BackgroundPictureActivity.getBackgroundFileName();
|
||||||
LogUtils.d(TAG, "szBackgroundFilePath : " + szBackgroundFilePath);
|
// File fBackgroundFilePath = new File(szBackgroundFilePath);
|
||||||
LogUtils.d(TAG, String.format("fBackgroundFilePath.exists() %s", fBackgroundFilePath.exists()));
|
// LogUtils.d(TAG, "szBackgroundFilePath : " + szBackgroundFilePath);
|
||||||
if (bean.isUseBackgroundFile() && fBackgroundFilePath.exists()) {
|
// LogUtils.d(TAG, String.format("fBackgroundFilePath.exists() %s", fBackgroundFilePath.exists()));
|
||||||
Drawable drawableBackground = Drawable.createFromPath(szBackgroundFilePath);
|
// if (bean.isUseBackgroundFile() && fBackgroundFilePath.exists()) {
|
||||||
//drawableBackground.setAlpha(120);
|
// Drawable drawableBackground = Drawable.createFromPath(szBackgroundFilePath);
|
||||||
imageView.setImageDrawable(drawableBackground);
|
// //drawableBackground.setAlpha(120);
|
||||||
} else {
|
// imageView.setImageDrawable(drawableBackground);
|
||||||
Drawable drawableBackground = getActivity().getDrawable(R.drawable.blank10x10);
|
// } else {
|
||||||
//drawableBackground.setAlpha(120);
|
// Drawable drawableBackground = getActivity().getDrawable(R.drawable.blank10x10);
|
||||||
imageView.setImageDrawable(drawableBackground);
|
// //drawableBackground.setAlpha(120);
|
||||||
}
|
// imageView.setImageDrawable(drawableBackground);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
Handler mHandler = new Handler(){
|
Handler mHandler = new Handler(){
|
||||||
|
|||||||
@@ -21,13 +21,15 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/activitybackgroundpictureRelativeLayout1"/>
|
android:id="@+id/activitybackgroundpictureRelativeLayout1"/>
|
||||||
|
|
||||||
<ImageView
|
<cc.winboll.studio.powerbell.views.BackgroundView
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/activitybackgroundpictureImageView1"
|
android:background="#FF7381FF"
|
||||||
android:layout_below="@id/toolbar">
|
android:id="@+id/activitybackgroundpictureBackgroundView1">
|
||||||
|
|
||||||
</ImageView>
|
</cc.winboll.studio.powerbell.views.BackgroundView>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ImageView
|
<cc.winboll.studio.powerbell.views.BackgroundView
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/fragmentmainviewImageView1">
|
android:background="#FF7381FF"
|
||||||
|
android:id="@+id/fragmentmainviewBackgroundView1"/>
|
||||||
</ImageView>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|||||||
Reference in New Issue
Block a user