Skip to content

Commit 2f3eef1

Browse files
committed
Setup 'Start' Project
1 parent 1b615c2 commit 2f3eef1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1396
-148
lines changed

.idea/codeStyles/Project.xml

+172
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

start/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: "kotlin-kapt"
45

56
android {
67
compileSdkVersion 28

start/src/main/AndroidManifest.xml

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="soup.codelab.darktheme">
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="soup.codelab.darktheme">
5+
6+
<uses-permission android:name="android.permission.INTERNET" />
47

58
<application
6-
android:allowBackup="true"
7-
android:icon="@mipmap/ic_launcher"
8-
android:label="@string/app_name"
9-
android:roundIcon="@mipmap/ic_launcher_round"
10-
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
9+
android:name=".CodeLabApplication"
10+
android:allowBackup="false"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme"
15+
tools:ignore="GoogleAppIndexingWarning">
16+
<activity
17+
android:name=".SplashActivity"
18+
android:theme="@style/AppTheme.Splash">
1319
<intent-filter>
14-
<action android:name="android.intent.action.MAIN"/>
20+
<action android:name="android.intent.action.MAIN" />
1521

16-
<category android:name="android.intent.category.LAUNCHER"/>
22+
<category android:name="android.intent.category.LAUNCHER" />
1723
</intent-filter>
1824
</activity>
25+
<activity android:name=".MainActivity" />
26+
<activity android:name=".DetailActivity" />
27+
<activity
28+
android:name=".WebActivity"
29+
android:theme="@style/AppTheme.Web" />
1930
</application>
20-
21-
</manifest>
31+
</manifest>

start/src/main/ic_launcher-web.png

10.7 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package soup.codelab.darktheme
2+
3+
import android.content.Context
4+
import android.graphics.Canvas
5+
import android.graphics.Color
6+
import android.graphics.Paint
7+
import android.graphics.Rect
8+
import android.util.AttributeSet
9+
import android.widget.ImageView
10+
11+
class BorderImageView @JvmOverloads constructor(
12+
context: Context,
13+
attrs: AttributeSet? = null,
14+
defStyle: Int = 0
15+
) : ImageView(context, attrs, defStyle) {
16+
17+
private val strokePaint = Paint()
18+
private var borderColor: Int = Color.TRANSPARENT
19+
private var borderWidth: Float = 0f
20+
21+
init {
22+
if (attrs != null) {
23+
val a = context.obtainStyledAttributes(attrs, R.styleable.BorderImageView, defStyle, 0)
24+
try {
25+
borderColor = a.getColor(
26+
R.styleable.BorderImageView_borderColor,
27+
Color.TRANSPARENT
28+
)
29+
borderWidth = a.getDimension(
30+
R.styleable.BorderImageView_borderWidth,
31+
0f
32+
)
33+
strokePaint.apply {
34+
color = borderColor
35+
style = Paint.Style.STROKE
36+
strokeWidth = borderWidth
37+
isAntiAlias = true
38+
}
39+
} finally {
40+
a.recycle()
41+
}
42+
}
43+
}
44+
45+
override fun draw(canvas: Canvas?) {
46+
super.draw(canvas)
47+
canvas?.borderRectangle(borderWidth.div(2).toInt())
48+
}
49+
50+
private fun Canvas.borderRectangle(halfW: Int) = clipBounds.run {
51+
drawRect(
52+
Rect(halfW, halfW, right - halfW, bottom - halfW),
53+
strokePaint
54+
)
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package soup.codelab.darktheme
2+
3+
import android.app.Application
4+
5+
class CodeLabApplication : Application() {
6+
7+
override fun onCreate() {
8+
super.onCreate()
9+
DarkTheme.apply()
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package soup.codelab.darktheme
2+
3+
import android.app.UiModeManager
4+
import android.content.Context
5+
import androidx.appcompat.app.AppCompatDelegate
6+
7+
object DarkTheme {
8+
9+
private var isEnabled = false
10+
11+
fun apply(enabled: Boolean = isEnabled) {
12+
if (isEnabled == enabled) return
13+
isEnabled = enabled
14+
val nightMode = if (enabled) {
15+
AppCompatDelegate.MODE_NIGHT_YES
16+
} else {
17+
AppCompatDelegate.MODE_NIGHT_NO
18+
}
19+
AppCompatDelegate.setDefaultNightMode(nightMode)
20+
}
21+
22+
fun isEnabled(context: Context): Boolean {
23+
return context.resources.configuration.uiMode and
24+
UiModeManager.MODE_NIGHT_YES ==
25+
UiModeManager.MODE_NIGHT_YES
26+
}
27+
}

0 commit comments

Comments
 (0)