diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..3c7772a
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,139 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fdae1d0..d5d35ec 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/app/src/main/java/com/wbrawner/materialive/MaterialiveService.kt b/app/src/main/java/com/wbrawner/materialive/MaterialiveService.kt
index 1950986..3fbf480 100644
--- a/app/src/main/java/com/wbrawner/materialive/MaterialiveService.kt
+++ b/app/src/main/java/com/wbrawner/materialive/MaterialiveService.kt
@@ -1,140 +1,101 @@
- package com.wbrawner.materialive
+package com.wbrawner.materialive
-import android.app.WallpaperColors
-import android.content.Context
+import android.content.res.Configuration
+import android.content.res.Resources
import android.graphics.Canvas
-import android.graphics.Color
-import android.os.Bundle
+import android.graphics.Rect
import android.service.wallpaper.WallpaperService
import android.util.Log
-import android.view.MotionEvent
+import android.util.TypedValue
import android.view.SurfaceHolder
-import android.view.WindowInsets
-import java.io.FileDescriptor
-import java.io.PrintWriter
+import androidx.core.content.ContextCompat
+import kotlin.math.max
+import kotlin.random.Random
class MaterialiveService : WallpaperService() {
override fun onCreateEngine() = Engine()
- inner class Engine: WallpaperService.Engine() {
- override fun getDesiredMinimumWidth(): Int {
- return super.getDesiredMinimumWidth()
- }
-
- override fun getDesiredMinimumHeight(): Int {
- return super.getDesiredMinimumHeight()
- }
-
- override fun isVisible(): Boolean {
- return super.isVisible()
- }
-
- override fun isPreview(): Boolean {
- return super.isPreview()
- }
-
- override fun setTouchEventsEnabled(enabled: Boolean) {
- super.setTouchEventsEnabled(enabled)
- }
-
- override fun setOffsetNotificationsEnabled(enabled: Boolean) {
- super.setOffsetNotificationsEnabled(enabled)
- }
-
- override fun onCreate(surfaceHolder: SurfaceHolder?) {
- Log.d("Materialize", "onCreate")
- super.onCreate(surfaceHolder)
- }
-
- override fun onDestroy() {
- super.onDestroy()
- }
-
- override fun onVisibilityChanged(visible: Boolean) {
- super.onVisibilityChanged(visible)
- }
-
- override fun onApplyWindowInsets(insets: WindowInsets?) {
- super.onApplyWindowInsets(insets)
- }
-
- override fun onTouchEvent(event: MotionEvent?) {
- super.onTouchEvent(event)
- }
-
- override fun onOffsetsChanged(
- xOffset: Float,
- yOffset: Float,
- xOffsetStep: Float,
- yOffsetStep: Float,
- xPixelOffset: Int,
- yPixelOffset: Int
- ) {
- super.onOffsetsChanged(
- xOffset,
- yOffset,
- xOffsetStep,
- yOffsetStep,
- xPixelOffset,
- yPixelOffset
- )
- }
-
- override fun onCommand(
- action: String?,
- x: Int,
- y: Int,
- z: Int,
- extras: Bundle?,
- resultRequested: Boolean
- ): Bundle {
- return super.onCommand(action, x, y, z, extras, resultRequested)
- }
-
- override fun onDesiredSizeChanged(desiredWidth: Int, desiredHeight: Int) {
- super.onDesiredSizeChanged(desiredWidth, desiredHeight)
- }
-
- override fun onSurfaceChanged(
- holder: SurfaceHolder?,
- format: Int,
- width: Int,
- height: Int
- ) {
- Log.d("Materialize", "onSurfaceChanged")
- super.onSurfaceChanged(holder, format, width, height)
- }
+ inner class Engine : WallpaperService.Engine() {
+ private val translations = mutableListOf>()
+ private val random = Random(System.currentTimeMillis())
override fun onSurfaceRedrawNeeded(holder: SurfaceHolder?) {
Log.d("Materialize", "onSurfaceRedrawNeeded")
super.onSurfaceRedrawNeeded(holder)
holder?.draw { canvas ->
- canvas.drawColor(getColor(R.color.surface))
+ val canvasRect = Rect(0, 0, canvas.width, canvas.height)
+ ContextCompat.getDrawable(applicationContext, R.drawable.wallpaper_sky)
+ ?.apply {
+ bounds = canvasRect
+ draw(canvas)
+ }
+
+ when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
+ Configuration.UI_MODE_NIGHT_YES -> drawStars(canvas)
+ else -> drawSun(canvas)
+ }
+
+ ContextCompat.getDrawable(applicationContext, R.drawable.ic_desert)
+ ?.apply {
+ bounds = Rect(0, 0, canvas.width, canvas.width / 2)
+ canvas.save()
+ canvas.translate(0f, (canvas.height - bounds.bottom).toFloat())
+ draw(canvas)
+ canvas.restore()
+ }
}
}
- override fun onSurfaceCreated(holder: SurfaceHolder?) {
- Log.d("Materialize", "onSurfaceCreated")
- super.onSurfaceCreated(holder)
+ private fun drawStars(canvas: Canvas) {
+ ContextCompat.getDrawable(applicationContext, R.drawable.ic_sun)?.apply {
+ val padding = 5f.toDp()
+ bounds = Rect(0, 0, padding.toInt(), padding.toInt())
+ canvas.save()
+ val stepMin = canvas.width.toFloat() / 4
+ val stepMax = canvas.width.toFloat()
+ var totalY = 0f
+ while (totalY < canvas.height) {
+ var returnX = 0f
+ while (true) {
+ val x = ((stepMax - stepMin) * random.nextFloat())
+ if (returnX + x >= canvas.width) break
+ canvas.translate(x, 0f)
+ draw(canvas)
+ returnX += x
+ }
+ val y = 10f.toDp()
+ canvas.translate(returnX * -1, y)
+ totalY += y
+ }
+ canvas.restore()
+ }
}
- override fun onSurfaceDestroyed(holder: SurfaceHolder?) {
- super.onSurfaceDestroyed(holder)
- }
-
- override fun onZoomChanged(zoom: Float) {
- super.onZoomChanged(zoom)
- }
-
- override fun notifyColorsChanged() {
- super.notifyColorsChanged()
+ private fun drawSun(canvas: Canvas) {
+ ContextCompat.getDrawable(applicationContext, R.drawable.ic_sun)?.apply {
+ val padding = 50f.toDp()
+ bounds = Rect(0, 0, padding.toInt(), padding.toInt())
+ canvas.save()
+ canvas.translate(
+ max(padding, (canvas.width - intrinsicWidth - padding) * random.nextFloat()),
+ intrinsicHeight + padding
+ )
+ draw(canvas)
+ canvas.restore()
+ }
}
}
}
- fun SurfaceHolder.draw(block: (canvas: Canvas) -> Unit) {
- val canvas = lockCanvas()
- block(canvas)
- unlockCanvasAndPost(canvas)
- }
\ No newline at end of file
+fun SurfaceHolder.draw(block: (canvas: Canvas) -> Unit) {
+ val canvas = lockCanvas()
+ block(canvas)
+ unlockCanvasAndPost(canvas)
+}
+
+fun Float.toDp(): Float = TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP,
+ this,
+ Resources.getSystem().displayMetrics
+)
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_desert.xml b/app/src/main/res/drawable/ic_desert.xml
new file mode 100644
index 0000000..63c79ad
--- /dev/null
+++ b/app/src/main/res/drawable/ic_desert.xml
@@ -0,0 +1,22 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_sun.xml b/app/src/main/res/drawable/ic_sun.xml
new file mode 100644
index 0000000..cf5efcd
--- /dev/null
+++ b/app/src/main/res/drawable/ic_sun.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/wallpaper_sky.xml b/app/src/main/res/drawable/wallpaper_sky.xml
new file mode 100644
index 0000000..ce2bb48
--- /dev/null
+++ b/app/src/main/res/drawable/wallpaper_sky.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index 05f7083..30a2ee3 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -1,4 +1,9 @@
#FF000000
+ #6060c0
+ #000000
+ #ffeeee
+ #493350
+ #aa5a78
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index f0706bb..dab0ae2 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,4 +1,9 @@
#FFFFFFFF
+ #fce7d9
+ #c2dfff
+ #ffeeee
+ #e7af36
+ #f0cc7f
\ No newline at end of file