diff --git a/powerbell/build.gradle b/powerbell/build.gradle index 9e8f4f3..28c9e16 100644 --- a/powerbell/build.gradle +++ b/powerbell/build.gradle @@ -45,9 +45,9 @@ android { dependencies { api fileTree(dir: 'libs', include: ['*.jar']) - api 'cc.winboll.studio:libaes:15.8.0' - api 'cc.winboll.studio:libapputils:15.8.2' - api 'cc.winboll.studio:libappbase:15.8.2' + api 'cc.winboll.studio:libaes:15.9.1' + api 'cc.winboll.studio:libapputils:15.8.4' + api 'cc.winboll.studio:libappbase:15.8.4' // 吐司提示库 api 'com.github.getActivity:ToastUtils:10.5' diff --git a/powerbell/build.properties b/powerbell/build.properties index 3ab111d..c8b7d3f 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Thu Jun 19 21:16:18 HKT 2025 +#Sun Jun 22 08:17:22 GMT 2025 stageCount=4 libraryProject= baseVersion=15.4 publishVersion=15.4.3 -buildCount=0 +buildCount=22 baseBetaVersion=15.4.4 diff --git a/powerbell/src/main/AndroidManifest.xml b/powerbell/src/main/AndroidManifest.xml index 93ad2bc..1bfaabd 100644 --- a/powerbell/src/main/AndroidManifest.xml +++ b/powerbell/src/main/AndroidManifest.xml @@ -121,6 +121,8 @@ + + - + \ No newline at end of file diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java index faa9c5d..b0cce7c 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java @@ -1,5 +1,6 @@ package cc.winboll.studio.powerbell; +import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; @@ -9,6 +10,7 @@ import android.os.Bundle; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; +import android.widget.RelativeLayout; import android.widget.Toast; import cc.winboll.studio.libaes.views.AToolbar; import cc.winboll.studio.libappbase.LogUtils; @@ -18,11 +20,12 @@ import cc.winboll.studio.powerbell.activities.BackgroundPictureActivity; import cc.winboll.studio.powerbell.activities.BatteryReporterActivity; import cc.winboll.studio.powerbell.activities.ClearRecordActivity; import cc.winboll.studio.powerbell.activities.WinBoLLActivity; +import cc.winboll.studio.powerbell.beans.BackgroundPictureBean; import cc.winboll.studio.powerbell.fragments.MainViewFragment; -import android.app.Activity; +import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils; public class MainActivity extends WinBoLLActivity { - + public static final String TAG = "MainActivity"; public static final int BACKGROUND_PICTURE_REQUEST_CODE = 0; @@ -45,7 +48,7 @@ public class MainActivity extends WinBoLLActivity { public String getTag() { return TAG; } - + @Override protected void onCreate(Bundle savedInstanceState) { //LogUtils.d(TAG, "onCreate(...)"); @@ -128,8 +131,8 @@ public class MainActivity extends WinBoLLActivity { super.onResume(); // 回到窗口自动取消提醒消息 //NotificationHelper.cancelRemindNotification(this); - reloadBackground(); + setBackgroundColor(); } // Menu icons are inflated just as they were with actionbar @@ -206,4 +209,12 @@ public class MainActivity extends WinBoLLActivity { moveTaskToBack(true); } } + + void setBackgroundColor() { + BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(MainActivity.this); + BackgroundPictureBean bean = utils.getBackgroundPictureBean(); + int nPixelColor = bean.getPixelColor(); + RelativeLayout mainLayout = findViewById(R.id.activitymainRelativeLayout1); + mainLayout.setBackgroundColor(nPixelColor); + } } diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundPictureActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundPictureActivity.java index 0aa5766..ba7e79b 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundPictureActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundPictureActivity.java @@ -32,6 +32,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import android.service.quickaccesswallet.GetWalletCardsError; +import android.widget.RelativeLayout; public class BackgroundPictureActivity extends Activity implements BackgroundPicturePreviewDialog.IOnRecivedPictureListener { @@ -102,7 +104,9 @@ public class BackgroundPictureActivity extends Activity implements BackgroundPic findViewById(R.id.activitybackgroundpictureAButton2).setOnClickListener(onSelectPictureClickListener); findViewById(R.id.activitybackgroundpictureAButton3).setOnClickListener(onCropPictureClickListener); findViewById(R.id.activitybackgroundpictureAButton6).setOnClickListener(onCropFreePictureClickListener); - + findViewById(R.id.activitybackgroundpictureAButton7).setOnClickListener(onPixelPickerClickListener); + findViewById(R.id.activitybackgroundpictureAButton8).setOnClickListener(onCleanPixelClickListener); + updatePreviewBackground(); // 处理分享的图片 @@ -154,7 +158,7 @@ public class BackgroundPictureActivity extends Activity implements BackgroundPic String filePath = utils.getBackgroundDir() + getBackgroundFileName(); Drawable drawable = FileUtils.getImageDrawable(filePath); if (drawable != null) { - drawable.setAlpha(120); + //drawable.setAlpha(120); ivPreviewBackground.setImageDrawable(drawable); } ToastUtils.show("背景图片已更新"); @@ -251,6 +255,30 @@ public class BackgroundPictureActivity extends Activity implements BackgroundPic updatePreviewBackground(); } }; + + private View.OnClickListener onPixelPickerClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + // 从文件路径启动像素拾取活动 + //String imagePath = "/storage/emulated/0/DCIM/Camera/sample.jpg"; + String imagePath = mfRecivedCropPicture.toString(); + Intent intent = new Intent(getApplicationContext(), PixelPickerActivity.class); + intent.putExtra("imagePath", imagePath); + //startActivity(intent); + App.getWinBoLLActivityManager().startWinBoLLActivity(getApplicationContext(), intent, PixelPickerActivity.class); + } + }; + + private View.OnClickListener onCleanPixelClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(BackgroundPictureActivity.this); + BackgroundPictureBean bean = utils.getBackgroundPictureBean(); + bean.setPixelColor(0); + utils.saveData(); + setBackgroundColor(); + } + }; /** * 压缩图片并保存到接收文件 @@ -538,5 +566,19 @@ public class BackgroundPictureActivity extends Activity implements BackgroundPic } } } + + void setBackgroundColor() { + BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(BackgroundPictureActivity.this); + BackgroundPictureBean bean = utils.getBackgroundPictureBean(); + int nPixelColor = bean.getPixelColor(); + RelativeLayout mainLayout = findViewById(R.id.activitybackgroundpictureRelativeLayout1); + mainLayout.setBackgroundColor(nPixelColor); + } + + @Override + protected void onResume() { + super.onResume(); + setBackgroundColor(); + } } diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/PixelPickerActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/PixelPickerActivity.java new file mode 100644 index 0000000..be5cc1d --- /dev/null +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/PixelPickerActivity.java @@ -0,0 +1,203 @@ +package cc.winboll.studio.powerbell.activities; + +/** + * @Author ZhanGSKen + * @Date 2025/06/22 14:15 + */ +import android.app.Activity; +import android.app.Dialog; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.os.Bundle; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; +import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity; +import cc.winboll.studio.powerbell.R; +import cc.winboll.studio.powerbell.activities.BackgroundPictureActivity; +import cc.winboll.studio.powerbell.activities.PixelPickerActivity; +import cc.winboll.studio.powerbell.beans.BackgroundPictureBean; +import cc.winboll.studio.powerbell.utils.BackgroundPictureUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class PixelPickerActivity extends WinBoLLActivity implements IWinBoLLActivity { + + public static final String TAG = "PixelPickerActivity"; + + @Override + public Activity getActivity() { + return this; + } + + @Override + public String getTag() { + return TAG; + } + + + + + private ImageView imageView; + private Bitmap originalBitmap; + private TextView infoText; + private ViewGroup imageContainer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_pixelpicker); + + imageView = findViewById(R.id.imageView); + infoText = findViewById(R.id.infoText); + imageContainer = findViewById(R.id.imageContainer); + + // 从Intent获取图片路径并加载 + String imagePath = getIntent().getStringExtra("imagePath"); + if (imagePath != null) { + loadImage(imagePath); + } else { + infoText.setText("未找到图片路径"); + } + + // 设置图片点击事件 + imageContainer.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN && originalBitmap != null) { + // 计算点击位置在图片上的实际坐标 + float touchX = event.getX(); + float touchY = event.getY(); + + int pixelX = -1, pixelY = -1; + try { + // 获取图片在容器中的实际位置和尺寸 + int[] imageLocation = new int[2]; + imageView.getLocationInWindow(imageLocation); + int imageWidth = imageView.getWidth(); + int imageHeight = imageView.getHeight(); + + // 计算缩放比例 + float scaleX = (float) originalBitmap.getWidth() / imageWidth; + float scaleY = (float) originalBitmap.getHeight() / imageHeight; + + // 调整触摸坐标到图片坐标系 + float adjustedX = touchX - imageLocation[0]; + float adjustedY = touchY - imageLocation[1]; + + // 检查是否在图片范围内 + if (adjustedX >= 0 && adjustedX <= imageWidth && adjustedY >= 0 && adjustedY <= imageHeight) { + // 计算实际像素坐标 + pixelX = (int) (adjustedX * scaleX); + pixelY = (int) (adjustedY * scaleY); + + // 再次检查像素坐标是否在有效范围内 + if (pixelX >= 0 && pixelX < originalBitmap.getWidth() && + pixelY >= 0 && pixelY < originalBitmap.getHeight()) { + int pixelColor = originalBitmap.getPixel(pixelX, pixelY); + showPixelDialog(pixelColor, pixelX, pixelY); + } else { + Toast.makeText(PixelPickerActivity.this, "像素坐标超出范围", Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(PixelPickerActivity.this, "点击位置超出图片显示范围", Toast.LENGTH_SHORT).show(); + } + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText(PixelPickerActivity.this, "计算像素位置失败", Toast.LENGTH_SHORT).show(); + } + } + return true; + } + }); + } + + /** + * 加载图片 + */ + private void loadImage(String imagePath) { + try { + File file = new File(imagePath); + if (file.exists()) { + // 解码图片 + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = 1; // 加载原图 + originalBitmap = BitmapFactory.decodeStream(new FileInputStream(file), null, options); + + if (originalBitmap != null) { + imageView.setImageBitmap(originalBitmap); + infoText.setText("图片已加载,点击获取像素值"); + } else { + infoText.setText("图片加载失败"); + } + } else { + infoText.setText("图片文件不存在"); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + infoText.setText("图片文件未找到"); + } + } + + /** + * 显示像素对话框 + */ + private void showPixelDialog(final int pixelColor, int x, int y) { + Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.dialog_pixel); + dialog.setCancelable(true); + + // 设置像素颜色视图背景 + TextView colorView = dialog.findViewById(R.id.pixelColorView); + colorView.setBackgroundColor(pixelColor); + + // 显示颜色信息 + TextView infoText = dialog.findViewById(R.id.colorInfoText); + String colorInfo = String.format( + "RGB: (%d, %d, %d)\n" + + "ARGB: #%08X\n" + + "实际像素位置: (%d, %d)", + Color.red(pixelColor), + Color.green(pixelColor), + Color.blue(pixelColor), + pixelColor, + x, y); + infoText.setText(colorInfo); + + // 设置确定按钮点击事件 + Button confirmButton = dialog.findViewById(R.id.confirmButton); + confirmButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + // 可以在这里添加确定后的回调逻辑 + BackgroundPictureUtils utils = BackgroundPictureUtils.getInstance(PixelPickerActivity.this); + BackgroundPictureBean bean = utils.getBackgroundPictureBean(); + bean.setPixelColor(pixelColor); + utils.saveData(); + Toast.makeText(PixelPickerActivity.this, "已记录像素值", Toast.LENGTH_SHORT).show(); + } + }); + + dialog.show(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + // 回收Bitmap资源 + if (originalBitmap != null && !originalBitmap.isRecycled()) { + originalBitmap.recycle(); + originalBitmap = null; + } + } +} + + + diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/beans/BackgroundPictureBean.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/beans/BackgroundPictureBean.java index ae818a8..b2eb8f4 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/beans/BackgroundPictureBean.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/beans/BackgroundPictureBean.java @@ -17,6 +17,8 @@ public class BackgroundPictureBean extends BaseBean { int backgroundWidth = 100; int backgroundHeight = 100; boolean isUseBackgroundFile = false; + // 图片拾取像素颜色 + int pixelColor = 0; public BackgroundPictureBean() { } @@ -25,6 +27,14 @@ public class BackgroundPictureBean extends BaseBean { this.isUseBackgroundFile = isUseBackgroundFile; } + public void setPixelColor(int pixelColor) { + this.pixelColor = pixelColor; + } + + public int getPixelColor() { + return pixelColor; + } + public void setBackgroundWidth(int backgroundWidth) { this.backgroundWidth = backgroundWidth; } @@ -61,6 +71,7 @@ public class BackgroundPictureBean extends BaseBean { jsonWriter.name("backgroundWidth").value(bean.getBackgroundWidth()); jsonWriter.name("backgroundHeight").value(bean.getBackgroundHeight()); jsonWriter.name("isUseBackgroundFile").value(bean.isUseBackgroundFile()); + jsonWriter.name("pixelColor").value(bean.getPixelColor()); } @Override @@ -75,6 +86,8 @@ public class BackgroundPictureBean extends BaseBean { bean.setBackgroundHeight(jsonReader.nextInt()); } else if (name.equals("isUseBackgroundFile")) { bean.setIsUseBackgroundFile(jsonReader.nextBoolean()); + } else if (name.equals("pixelColor")) { + bean.setPixelColor(jsonReader.nextInt()); } else { jsonReader.skipValue(); } diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/fragments/MainViewFragment.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/fragments/MainViewFragment.java index 0e63a91..6819a65 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/fragments/MainViewFragment.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/fragments/MainViewFragment.java @@ -311,11 +311,11 @@ public class MainViewFragment extends Fragment { LogUtils.d(TAG, String.format("fBackgroundFilePath.exists() %s", fBackgroundFilePath.exists())); if (bean.isUseBackgroundFile() && fBackgroundFilePath.exists()) { Drawable drawableBackground = Drawable.createFromPath(szBackgroundFilePath); - drawableBackground.setAlpha(120); + //drawableBackground.setAlpha(120); imageView.setImageDrawable(drawableBackground); } else { Drawable drawableBackground = getActivity().getDrawable(R.drawable.blank10x10); - drawableBackground.setAlpha(120); + //drawableBackground.setAlpha(120); imageView.setImageDrawable(drawableBackground); } } diff --git a/powerbell/src/main/res/layout/activity_backgroundpicture.xml b/powerbell/src/main/res/layout/activity_backgroundpicture.xml index 32197b4..d3f329a 100644 --- a/powerbell/src/main/res/layout/activity_backgroundpicture.xml +++ b/powerbell/src/main/res/layout/activity_backgroundpicture.xml @@ -1,5 +1,5 @@ - - - - - - + + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/activitybackgroundpictureRelativeLayout1"/> - - + - + + android:layout_below="@id/toolbar"> - + - + - + - + + + + + + + + + + + + + + + + + - - - + + diff --git a/powerbell/src/main/res/layout/activity_main.xml b/powerbell/src/main/res/layout/activity_main.xml index 213ee82..54bf752 100644 --- a/powerbell/src/main/res/layout/activity_main.xml +++ b/powerbell/src/main/res/layout/activity_main.xml @@ -2,36 +2,34 @@ - + android:layout_height="@dimen/toolbar_height" + android:id="@+id/toolbar" + android:gravity="center_vertical" + style="@style/DefaultAToolbar"/> - - - - - + + - + diff --git a/powerbell/src/main/res/layout/activity_pixelpicker.xml b/powerbell/src/main/res/layout/activity_pixelpicker.xml new file mode 100644 index 0000000..4bce86b --- /dev/null +++ b/powerbell/src/main/res/layout/activity_pixelpicker.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/powerbell/src/main/res/layout/dialog_pixel.xml b/powerbell/src/main/res/layout/dialog_pixel.xml new file mode 100644 index 0000000..182ee4a --- /dev/null +++ b/powerbell/src/main/res/layout/dialog_pixel.xml @@ -0,0 +1,32 @@ + + + + + + + +