Skip to content

Commit

Permalink
v1.26_beta
Browse files Browse the repository at this point in the history
  - Added option to adjust hue for the wallpapers (#10)
  • Loading branch information
Hamza417 committed Jan 18, 2024
1 parent 1105c23 commit 24145d7
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId "app.simple.peri"
minSdk 24
targetSdk 34
versionCode 125
versionName "1.25_beta"
versionCode 126
versionName "1.26_beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ object BundleConstants {
const val SATURATION_VALUE: String = "saturation_value"
const val BRIGHTNESS_VALUE: String = "brightness_value"
const val CONTRAST_VALUE: String = "contrast_value"
const val HUE_VALUE: String = "hue_value"
const val SELECTION_MODE = "selection_mode"
const val FAB_TRANSITION = "fab_transition"
const val WALLPAPER = "wallpaper"
Expand Down
41 changes: 40 additions & 1 deletion app/src/main/java/app/simple/peri/ui/WallpaperScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class WallpaperScreen : Fragment() {
wallpaperEditBinding.saturationSlider.value = requireArguments().getFloat(BundleConstants.SATURATION_VALUE, DEFAULT_SATURATION)
wallpaperEditBinding.contrastSlider.value = requireArguments().getFloat(BundleConstants.CONTRAST_VALUE, DEFAULT_CONTRAST)
wallpaperEditBinding.brightnessSlider.value = requireArguments().getFloat(BundleConstants.BRIGHTNESS_VALUE, DEFAULT_BRIGHTNESS)
wallpaperEditBinding.hueSlider.value = requireArguments().getFloat(BundleConstants.HUE_VALUE, DEFAULT_HUE)
wallpaperEditBinding.blurSlider.value = requireArguments().getFloat(BundleConstants.BLUR_VALUE, DEFAULT_BLUR)

wallpaperEditBinding.saturationSlider.addOnChangeListener { _, value, fromUser ->
Expand Down Expand Up @@ -195,6 +196,15 @@ class WallpaperScreen : Fragment() {
}
}

wallpaperEditBinding.hueSlider.addOnChangeListener { _, value, fromUser ->
if (fromUser) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
requireArguments().putFloat(BundleConstants.HUE_VALUE, value)
setRenderEffectOnWallpaper()
}
}
}

wallpaperEditBinding.blurSlider.addOnChangeListener { _, value, fromUser ->
if (fromUser) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Expand Down Expand Up @@ -235,6 +245,7 @@ class WallpaperScreen : Fragment() {
val contrast = requireArguments().getFloat(BundleConstants.CONTRAST_VALUE, DEFAULT_CONTRAST)
val brightness = requireArguments().getFloat(BundleConstants.BRIGHTNESS_VALUE, DEFAULT_BRIGHTNESS)
val saturation = requireArguments().getFloat(BundleConstants.SATURATION_VALUE, DEFAULT_SATURATION)
val hue = requireArguments().getFloat(BundleConstants.HUE_VALUE, DEFAULT_HUE)
val blur = requireArguments().getFloat(BundleConstants.BLUR_VALUE, DEFAULT_BLUR)

val blurEffect = RenderEffect.createBlurEffect(blur.toBlur(), blur.toBlur(), Shader.TileMode.MIRROR)
Expand All @@ -246,6 +257,28 @@ class WallpaperScreen : Fragment() {
0f, 0f, 0f, 1f, 0f
))

// Set the hue
val hueValue = hue.toHue()
postConcat(ColorMatrix().apply {
setRotate(0, hueValue)
setRotate(1, hueValue)
setRotate(2, hueValue)
})

// val cos = cos(hueValue.toDouble())
// val sin = sin(hueValue.toDouble())
// val lumR = 0.213
// val lumG = 0.715
// val lumB = 0.072
// val mat = floatArrayOf(
// ((lumR + cos * (1 - lumR) + sin * (-lumR)).toFloat()), ((lumG + cos * (-lumG) + sin * (-lumG)).toFloat()), ((lumB + cos * (-lumB) + sin * (1 - lumB)).toFloat()), 0f, 0f,
// ((lumR + cos * (-lumR) + sin * (0.143)).toFloat()), ((lumG + cos * (1 - lumG) + sin * (0.140)).toFloat()), ((lumB + cos * (-lumB) + sin * (-0.283)).toFloat()), 0f, 0f,
// ((lumR + cos * (-lumR) + sin * (-(1 - lumR))).toFloat()), ((lumG + cos * (-lumG) + sin * (lumG)).toFloat()), ((lumB + cos * (1 - lumB) + sin * (lumB)).toFloat()), 0f, 0f,
// 0f, 0f, 0f, 1f, 0f
// )
//
// postConcat(ColorMatrix(mat))

postConcat(ColorMatrix().apply {
setSaturation(saturation.toSaturation())
})
Expand All @@ -267,10 +300,11 @@ class WallpaperScreen : Fragment() {
val contrast = requireArguments().getFloat(BundleConstants.CONTRAST_VALUE, DEFAULT_CONTRAST).toContrast()
val brightness = requireArguments().getFloat(BundleConstants.BRIGHTNESS_VALUE, DEFAULT_BRIGHTNESS).toBrightness()
val saturation = requireArguments().getFloat(BundleConstants.SATURATION_VALUE, DEFAULT_SATURATION).toSaturation()
val hue = requireArguments().getFloat(BundleConstants.HUE_VALUE, DEFAULT_HUE).toHue()
val blur = requireArguments().getFloat(BundleConstants.BLUR_VALUE, DEFAULT_BLUR).toBlur()

val bitmap = binding?.composeView?.drawToBitmap()
?.changeBitmapContrastBrightness(contrast, brightness, saturation)
?.changeBitmapContrastBrightness(contrast, brightness, saturation, hue)

bitmap?.let {
StackBlur().blurRgb(it, blur.toInt())
Expand Down Expand Up @@ -324,6 +358,10 @@ class WallpaperScreen : Fragment() {
return this * 10
}

private fun Float.toHue(): Float {
return this * 360
}

private fun Float.toBlur(): Float {
return (this * 100).coerceAtLeast(1F)
}
Expand Down Expand Up @@ -409,6 +447,7 @@ class WallpaperScreen : Fragment() {
private const val DEFAULT_SATURATION = 0.5F
private const val DEFAULT_BRIGHTNESS = 0.5F
private const val DEFAULT_CONTRAST = 0.1F
private const val DEFAULT_HUE = 0F
private const val DEFAULT_BLUR = 0F

}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/app/simple/peri/utils/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object BitmapUtils {
* @param brightness -255..255 0 is default
* @return new bitmap
*/
fun Bitmap.changeBitmapContrastBrightness(contrast: Float, brightness: Float, saturation: Float): Bitmap {
fun Bitmap.changeBitmapContrastBrightness(contrast: Float, brightness: Float, saturation: Float, hue: Float): Bitmap {
val colorMatrix = ColorMatrix().apply {
set(floatArrayOf(
contrast, 0f, 0f, 0f, brightness,
Expand All @@ -25,6 +25,12 @@ object BitmapUtils {
))
}

colorMatrix.postConcat(ColorMatrix().apply {
setRotate(0, hue)
setRotate(1, hue)
setRotate(2, hue)
})

colorMatrix.postConcat(ColorMatrix().apply {
setSaturation(saturation)
})
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/wallpaper_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
android:layout_gravity="center_vertical"
app:thumbColor="?attr/colorPrimary" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hue"
android:textColor="@color/textWhite" />

<com.google.android.material.slider.Slider
android:id="@+id/hue_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:thumbColor="?attr/colorPrimary" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@
<string name="swipe_to_delete">Swipe to Delete</string>
<string name="inure_url">https://github.com/Hamza417/Inure</string>
<string name="positional_url">https://github.com/Hamza417/Positional</string>
<string name="hue">Hue</string>
</resources>
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/126.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added option to adjust hue

0 comments on commit 24145d7

Please sign in to comment.