Skip to content

Commit

Permalink
Merge pull request #22 from Steve-Mr/wheel
Browse files Browse the repository at this point in the history
细节调整
  • Loading branch information
Steve-Mr authored Apr 12, 2024
2 parents adcac1f + 1e1866c commit e6eef12
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 16 additions & 18 deletions app/src/main/java/com/maary/shareas/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ;

Expand Down Expand Up @@ -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()));
}


});
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/maary/shareas/activity/StartActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,24 @@ class StartActivity : AppCompatActivity(){

// some dirty hack
pickerBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
pickerBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
pickerBottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED

insets
}

val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri->
if (uri != null) {
val intent = Intent(application, MainActivity::class.java).apply {
action = Intent.ACTION_SEND
setDataAndType(uri, "image/*")
putExtra("mimeType", "image/*")
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(intent)
}

}

val wallpaperManager: WallpaperManager = WallpaperManager.getInstance(this)
val homePFD:ParcelFileDescriptor?
Expand Down Expand Up @@ -105,6 +117,8 @@ class StartActivity : AppCompatActivity(){
binding.homeContainer.setImageBitmap(homeBitmap)
binding.lockContainer.setImageBitmap(lockBitmap)

pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))

var isHomeSaved = false
var isLockSaved = false

Expand All @@ -130,19 +144,7 @@ class StartActivity : AppCompatActivity(){
binding.systemWallpContainer.visibility = View.INVISIBLE
}

val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri->
if (uri != null) {
val intent = Intent(application, MainActivity::class.java).apply {
action = Intent.ACTION_SEND
setDataAndType(uri, "image/*")
putExtra("mimeType", "image/*")
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(intent)
}

}

binding.buttonPicker.setOnClickListener {
pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/layout_dialog_adjustment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:padding="8dp"
android:text="@string/blur"
android:textStyle="bold"
android:textColor="?attr/colorOnSurface"
android:textSize="24sp"
/>

Expand All @@ -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"
/>
Expand Down

0 comments on commit e6eef12

Please sign in to comment.