aboutsummaryrefslogtreecommitdiff
path: root/sample/src
diff options
context:
space:
mode:
Diffstat (limited to 'sample/src')
-rw-r--r--sample/src/main/AndroidManifest.xml3
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt1
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt83
-rw-r--r--sample/src/main/res/layout/activity_main.xml9
-rw-r--r--sample/src/main/res/values/strings.xml4
-rw-r--r--sample/src/main/res/values/styles.xml5
6 files changed, 56 insertions, 49 deletions
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 4b31b50..1934e71 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -12,7 +12,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
- android:label="@string/title_activity_main">
+ android:label="@string/title_activity_main"
+ android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
index a752ea2..96c7c71 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
@@ -9,6 +9,7 @@ import ca.allanwang.kau.kpref.kpref
*/
object KPrefSample : KPref() {
var textColor: Int by kpref("TEXT_COLOR", Color.WHITE)
+ var accentColor: Int by kpref("ACCENT_COLOR", 0xffff4081.toInt())
var bgColor: Int by kpref("BG_COLOR", 0xff303030.toInt())
var check1: Boolean by kpref("check1", true)
var check2: Boolean by kpref("check2", false)
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index 6c36626..db42f9b 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -1,56 +1,61 @@
package ca.allanwang.kau.sample
import android.os.Bundle
-import android.support.v7.app.AppCompatActivity
-import android.support.v7.widget.RecyclerView
import android.view.Menu
import android.view.MenuItem
-import android.view.ViewGroup
+import ca.allanwang.kau.kpref.KPrefActivity
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
-import ca.allanwang.kau.kpref.items.KPrefItemCore
-import ca.allanwang.kau.kpref.setKPrefAdapter
+import ca.allanwang.kau.utils.darken
+import ca.allanwang.kau.utils.navigationBarColor
import ca.allanwang.kau.utils.showChangelog
import ca.allanwang.kau.views.RippleCanvas
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
-class MainActivity : AppCompatActivity() {
- lateinit var adapter: FastItemAdapter<KPrefItemCore>
- lateinit var builder: KPrefAdapterBuilder
+class MainActivity : KPrefActivity() {
+
+ override fun onCreateKPrefs(savedInstanceState: android.os.Bundle?): KPrefAdapterBuilder.() -> Unit = {
+ textColorGetter = { KPrefSample.textColor }
+ accentColorGetter = { KPrefSample.accentColor }
+ header(R.string.header)
+ checkbox(title = R.string.checkbox_1, description = R.string.desc,
+ getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it })
+ checkbox(title = R.string.checkbox_2,
+ getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it })
+ checkbox(title = R.string.checkbox_3, description = R.string.desc_disabled, enabled = false,
+ getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it })
+ colorPicker(title = R.string.text_color, description = R.string.color_custom,
+ getter = { KPrefSample.textColor }, setter = {
+ KPrefSample.textColor = it
+ adapter.notifyAdapterDataSetChanged()
+ },
+ configs = {
+ allowCustom = true
+ })
+ colorPicker(title = R.string.accent_color, description = R.string.color_no_custom,
+ getter = { KPrefSample.accentColor }, setter = {
+ KPrefSample.accentColor = it
+ adapter.notifyAdapterDataSetChanged()
+ val darkerColor = it.darken()
+ this@MainActivity.navigationBarColor = darkerColor
+ toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500)
+ },
+ configs = {
+ allowCustom = false
+ })
+ colorPicker(title = R.string.background_color, description = R.string.color_custom_alpha,
+ getter = { KPrefSample.bgColor }, setter = { KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500) },
+ configs = {
+ allowCustomAlpha = true
+ allowCustom = true
+ })
+ }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- val recycler = RecyclerView(this)
- val bgCanvas = RippleCanvas(this)
- setContentView(bgCanvas)
- addContentView(recycler, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
bgCanvas.set(KPrefSample.bgColor)
- adapter = recycler.setKPrefAdapter {
- builder = this
- textColor = KPrefSample.textColor
- header(R.string.header)
- checkbox(title = R.string.checkbox_1, description = R.string.desc,
- getter = { KPrefSample.check1 }, setter = { KPrefSample.check1 = it })
- checkbox(title = R.string.checkbox_2,
- getter = { KPrefSample.check2 }, setter = { KPrefSample.check2 = it })
- checkbox(title = R.string.checkbox_3, description = R.string.desc_disabled, enabled = false,
- getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it })
- colorPicker(title = R.string.text_color,
- getter = { KPrefSample.textColor }, setter = { KPrefSample.textColor = it; builder.textColor = it; refresh() },
- configs = {
- allowCustom = false
- })
- colorPicker(title = R.string.background_color,
- getter = { KPrefSample.bgColor }, setter = { KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500) },
- configs = {
- allowCustomAlpha = true
- allowCustom = true
- })
- }
- }
-
- fun refresh() {
- adapter.notifyAdapterDataSetChanged()
+ val darkAccent = KPrefSample.accentColor.darken()
+ toolbarCanvas.set(darkAccent)
+ this.navigationBarColor = darkAccent
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
deleted file mode 100644
index 7254add..0000000
--- a/sample/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="ca.allanwang.kau.sample.MainActivity">
-
-</android.support.constraint.ConstraintLayout>
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
index 44421fe..1246baf 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/sample/src/main/res/values/strings.xml
@@ -8,5 +8,9 @@
<string name="checkbox_3">Checkbox 3</string>
<string name="desc_disabled">I am disabled</string>
<string name="text_color">Text Color</string>
+ <string name="accent_color">Accent Color</string>
<string name="background_color">Background Color</string>
+ <string name="color_custom">This selector allows custom colors</string>
+ <string name="color_no_custom">This selector does not allow custom colors</string>
+ <string name="color_custom_alpha">This selector allows for custom colors with alpha values</string>
</resources>
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
index 8a4c98f..7867278 100644
--- a/sample/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -10,4 +10,9 @@
<item name="android:windowBackground">@android:color/transparent</item>
</style>
+ <style name="AppTheme.NoActionBar">
+ <item name="windowActionBar">false</item>
+ <item name="windowNoTitle">true</item>
+ </style>
+
</resources>