Implement desert wallpaper
This commit is contained in:
parent
390aa570ad
commit
f01bfe683d
9 changed files with 270 additions and 117 deletions
139
.idea/codeStyles/Project.xml
Normal file
139
.idea/codeStyles/Project.xml
Normal file
|
@ -0,0 +1,139 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="java.util" alias="false" withSubpackages="false" />
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -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<Pair<Float, Float>>()
|
||||
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)
|
||||
}
|
||||
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
|
||||
)
|
22
app/src/main/res/drawable/ic_desert.xml
Normal file
22
app/src/main/res/drawable/ic_desert.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="200dp"
|
||||
android:height="100dp"
|
||||
android:viewportWidth="52.916664"
|
||||
android:viewportHeight="26.458334">
|
||||
<path
|
||||
android:pathData="m-3.6109,10.1127c6.6093,-5.082 14.4917,-0.643 21.2697,-2.0297 4.8911,-1.9091 7.3245,-0.2232 10.3845,1.0344 2.211,1.4991 8.8347,-0.5577 11.2749,-3.529 6.6276,3.7921 7.0941,5.9812 12.9829,5.3834 2.0723,-1.0409 4.1567,-3.0439 6.2568,-3.5015l9.8254,5.4432c1.2789,-0.5838 3.5008,-4.7357 4.069,-2.6308l4.6522,15.4653 -82.319,-3.4745z"
|
||||
android:strokeLineJoin="miter"
|
||||
android:strokeWidth="0.264583"
|
||||
android:fillColor="@color/colorHills"
|
||||
android:strokeColor="#00000000"
|
||||
android:fillAlpha="0.719764"
|
||||
android:strokeLineCap="butt"/>
|
||||
<path
|
||||
android:pathData="m-6.0527,-0.0511h15.308c-0.6054,4.7772 0.4986,10.4668 4.9939,13.0639 3.0278,2.0094 7.1303,2.6727 10.3923,0.8603 3.0667,0.3016 6.1555,0.8734 9.9818,1.6431 3.741,2.0321 7.814,-0.3002 11.0421,-2.2018 4.5835,-1.5662 9.4881,-1.4018 14.238,-2.0097 2.0312,1.6044 0.5516,4.4667 0.9043,6.6714l-0.4048,20.6444 -82.0517,-7.4835 2.1382,-32.8742z"
|
||||
android:strokeLineJoin="miter"
|
||||
android:strokeWidth="0.265"
|
||||
android:fillColor="@color/colorMesa"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeLineCap="butt"/>
|
||||
</vector>
|
8
app/src/main/res/drawable/ic_sun.xml
Normal file
8
app/src/main/res/drawable/ic_sun.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||
<size
|
||||
android:height="100dp"
|
||||
android:width="100dp" />
|
||||
<solid android:color="@color/colorSun" />
|
||||
|
||||
</shape>
|
8
app/src/main/res/drawable/wallpaper_sky.xml
Normal file
8
app/src/main/res/drawable/wallpaper_sky.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:startColor="@color/colorSkyStart"
|
||||
android:endColor="@color/colorSkyEnd"
|
||||
android:angle="90" />
|
||||
</shape>
|
|
@ -1,4 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="surface">#FF000000</color>
|
||||
<color name="colorSkyStart">#6060c0</color>
|
||||
<color name="colorSkyEnd">#000000</color>
|
||||
<color name="colorSun">#ffeeee</color>
|
||||
<color name="colorMesa">#493350</color>
|
||||
<color name="colorHills">#aa5a78</color>
|
||||
</resources>
|
|
@ -1,4 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="surface">#FFFFFFFF</color>
|
||||
<color name="colorSkyStart">#fce7d9</color>
|
||||
<color name="colorSkyEnd">#c2dfff</color>
|
||||
<color name="colorSun">#ffeeee</color>
|
||||
<color name="colorMesa">#e7af36</color>
|
||||
<color name="colorHills">#f0cc7f</color>
|
||||
</resources>
|
Loading…
Reference in a new issue