From 1e1866cb40f97685e872d7ab2345f7e886986813 Mon Sep 17 00:00:00 2001 From: Maary <24504742+Steve-Mr@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:23:40 +0800 Subject: [PATCH] visual changes new md3 style slider less color from image in MainActivity --- app/build.gradle | 3 +- .../maary/shareas/activity/MainActivity.java | 34 +++++++++---------- .../res/layout/layout_dialog_adjustment.xml | 2 ++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 187205c..daca588 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -105,9 +105,8 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' -// implementation 'com.hoko:hoko-blur:1.3.5' implementation 'io.github.hokofly:hoko-blur:1.5.3' - implementation 'com.google.android.material:material:1.11.0' + implementation 'com.google.android.material:material:1.12.0-rc01' implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0" implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.7.0" diff --git a/app/src/main/java/com/maary/shareas/activity/MainActivity.java b/app/src/main/java/com/maary/shareas/activity/MainActivity.java index 758f84c..dfdb467 100644 --- a/app/src/main/java/com/maary/shareas/activity/MainActivity.java +++ b/app/src/main/java/com/maary/shareas/activity/MainActivity.java @@ -12,7 +12,9 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; @@ -89,6 +91,7 @@ public class MainActivity extends AppCompatActivity { int device_height, device_width; Palette.Swatch vibrant; + Palette.Swatch darkVibrant; Palette.Swatch dominant; Palette.Swatch muted ; @@ -230,15 +233,14 @@ protected void onCreate(Bundle savedInstanceState) { vibrant = palette.getVibrantSwatch(); muted = palette.getMutedSwatch(); dominant = palette.getDominantSwatch(); + darkVibrant = palette.getDarkVibrantSwatch(); + if (vibrant != null) { fab.setBackgroundTintList(ColorStateList.valueOf(vibrant.getRgb())); } else { fab.setBackgroundColor(palette.getVibrantColor(getColor(R.color.colorAccent))); } - if (muted != null) { - bottomAppBar.setBackgroundTint(ColorStateList.valueOf(muted.getRgb())); - } }); @@ -298,21 +300,22 @@ public void onColorsChanged(@Nullable WallpaperColors colors, int which) { // 获取 Drawable 对象 Drawable drawable = AppCompatResources.getDrawable(this, R.drawable.dialog_background); - // 复制 Drawable 对象,以便进行修改 assert drawable != null; - Drawable modifiedDrawable = drawable.getConstantState().newDrawable().mutate(); - modifiedDrawable.setTint(muted.getRgb()); + Drawable modifiedDrawable = Objects.requireNonNull(drawable.getConstantState()).newDrawable().mutate(); + // 复制 Drawable 对象,以便进行修改 + int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + switch (currentNightMode) { + case Configuration.UI_MODE_NIGHT_NO: + modifiedDrawable.setTint(Color.WHITE); + break; + case Configuration.UI_MODE_NIGHT_YES: + modifiedDrawable.setTint(Color.BLACK); + break; + } dialog.getWindow().setBackgroundDrawable(modifiedDrawable); dialog.show(); - TextView title_blur_view = dialog.findViewById(R.id.title_blur); - TextView title_brightness_view = dialog.findViewById(R.id.title_brightness); - assert title_blur_view != null; - title_blur_view.setTextColor(muted.getBodyTextColor()); - assert title_brightness_view != null; - title_brightness_view.setTextColor(muted.getBodyTextColor()); - Slider sliderBlur = dialog.findViewById(R.id.dialog_slider_blur); assert sliderBlur != null; sliderBlur.setLabelBehavior(LABEL_GONE); @@ -336,15 +339,10 @@ public void onColorsChanged(@Nullable WallpaperColors colors, int which) { sliderBrightness.setTrackActiveTintList(ColorStateList.valueOf(vibrant.getRgb())); } - dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(muted.getTitleTextColor()); - dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(muted.getTitleTextColor()); - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(muted.getTitleTextColor()); - chipLock.setChecked(applyEditToLock); chipHome.setChecked(applyEditToHome); chipLock.setOnCheckedChangeListener((buttonView, isChecked) -> applyEditToLock = isChecked); - chipHome.setOnCheckedChangeListener((buttonView, isChecked) -> applyEditToHome = isChecked); sliderBlur.setValueFrom(0); diff --git a/app/src/main/res/layout/layout_dialog_adjustment.xml b/app/src/main/res/layout/layout_dialog_adjustment.xml index e8a4b87..1502a34 100644 --- a/app/src/main/res/layout/layout_dialog_adjustment.xml +++ b/app/src/main/res/layout/layout_dialog_adjustment.xml @@ -18,6 +18,7 @@ android:padding="8dp" android:text="@string/blur" android:textStyle="bold" + android:textColor="?attr/colorOnSurface" android:textSize="24sp" /> @@ -37,6 +38,7 @@ app:layout_constraintStart_toStartOf="parent" android:padding="8dp" android:text="@string/brightness" + android:textColor="?attr/colorOnSurface" android:textStyle="bold" android:textSize="24sp" />