From 75dd060f2c265a069a0794ed659d780909df92ec Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 10 Jun 2017 16:11:24 -0700 Subject: init --- sample/.gitignore | 1 + sample/build.gradle | 38 +++++++++++++++ sample/proguard-rules.pro | 25 ++++++++++ .../allanwang/kprefs/ExampleInstrumentedTest.java | 26 ++++++++++ sample/src/main/AndroidManifest.xml | 23 +++++++++ .../kotlin/ca/allanwang/kau/sample/KPrefSample.kt | 16 +++++++ .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 53 +++++++++++++++++++++ .../kotlin/ca/allanwang/kau/sample/SampleApp.kt | 15 ++++++ sample/src/main/res/layout/activity_main.xml | 9 ++++ sample/src/main/res/menu/menu_main.xml | 31 ++++++++++++ sample/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes sample/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes sample/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes sample/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../main/res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes sample/src/main/res/values/colors.xml | 6 +++ sample/src/main/res/values/strings.xml | 10 ++++ sample/src/main/res/values/styles.xml | 11 +++++ sample/src/main/res/xml/changelog.xml | 20 ++++++++ .../java/ca/allanwang/kprefs/ExampleUnitTest.java | 17 +++++++ 25 files changed, 301 insertions(+) create mode 100644 sample/.gitignore create mode 100644 sample/build.gradle create mode 100644 sample/proguard-rules.pro create mode 100644 sample/src/androidTest/java/ca/allanwang/kprefs/ExampleInstrumentedTest.java create mode 100644 sample/src/main/AndroidManifest.xml create mode 100644 sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt create mode 100644 sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt create mode 100644 sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt create mode 100644 sample/src/main/res/layout/activity_main.xml create mode 100644 sample/src/main/res/menu/menu_main.xml create mode 100644 sample/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 sample/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 sample/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 sample/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 sample/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 sample/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 sample/src/main/res/values/colors.xml create mode 100644 sample/src/main/res/values/strings.xml create mode 100644 sample/src/main/res/values/styles.xml create mode 100644 sample/src/main/res/xml/changelog.xml create mode 100644 sample/src/test/java/ca/allanwang/kprefs/ExampleUnitTest.java (limited to 'sample') diff --git a/sample/.gitignore b/sample/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/sample/.gitignore @@ -0,0 +1 @@ +/build diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 0000000..9a349e6 --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,38 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion Integer.parseInt(project.TARGET_SDK) + buildToolsVersion project.BUILD_TOOLS + + defaultConfig { + applicationId "${project.APP_GROUP}." + project.APP_ID.toLowerCase() + ".sample" + minSdkVersion Integer.parseInt(project.MIN_SDK) + targetSdkVersion Integer.parseInt(project.TARGET_SDK) + versionCode Integer.parseInt(project.VERSION_CODE) + versionName project.VERSION_NAME + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + test.java.srcDirs += 'src/test/kotlin' + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile project(':library') + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + testCompile 'junit:junit:4.12' + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" +} diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro new file mode 100644 index 0000000..2b766bc --- /dev/null +++ b/sample/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\User7681\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/sample/src/androidTest/java/ca/allanwang/kprefs/ExampleInstrumentedTest.java b/sample/src/androidTest/java/ca/allanwang/kprefs/ExampleInstrumentedTest.java new file mode 100644 index 0000000..e3d17e9 --- /dev/null +++ b/sample/src/androidTest/java/ca/allanwang/kprefs/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package ca.allanwang.kprefs; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("ca.allanwang.kprefs", appContext.getPackageName()); + } +} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4b31b50 --- /dev/null +++ b/sample/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt new file mode 100644 index 0000000..d63e533 --- /dev/null +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt @@ -0,0 +1,16 @@ +package ca.allanwang.kau.sample + +import android.graphics.Color +import ca.allanwang.kau.kpref.KPref +import ca.allanwang.kau.kpref.kpref + +/** + * Created by Allan Wang on 2017-06-07. + */ +object KPrefSample : KPref() { + var textColor: Int by kpref("TEXT_COLOR", Color.WHITE) + var bgColor: Int by kpref("BG_COLOR", Color.BLACK) + var check1: Boolean by kpref("check1", true) + var check2: Boolean by kpref("check2", false) + var check3: Boolean by kpref("check3", false) +} \ No newline at end of file diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt new file mode 100644 index 0000000..c8207a3 --- /dev/null +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -0,0 +1,53 @@ +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 ca.allanwang.kau.kpref.setKPrefAdapter +import ca.allanwang.kau.utils.showChangelog + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val recycler = RecyclerView(this) +// recycler.matchParent() + setContentView(recycler) + recycler.setKPrefAdapter { + 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, enabled = false, + getter = { KPrefSample.check3 }, setter = { KPrefSample.check3 = it }) + colorPicker(title = R.string.text_color, + getter = { KPrefSample.textColor }, setter = { KPrefSample.textColor = it }) + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.menu_main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_settings -> { + + } + R.id.action_changelog -> showChangelog(R.xml.kau_changelog) + R.id.action_call -> { + } + R.id.action_db -> { + } + R.id.action_restart -> { + } + else -> return super.onOptionsItemSelected(item) + } + return true + } + +} diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt new file mode 100644 index 0000000..7fdc83d --- /dev/null +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt @@ -0,0 +1,15 @@ +package ca.allanwang.kau.sample + +import android.app.Application +import timber.log.Timber + +/** + * Created by Allan Wang on 2017-06-08. + */ +class SampleApp : Application() { + override fun onCreate() { + super.onCreate() + Timber.plant(Timber.DebugTree()) + KPrefSample.initialize(this, "pref_sample") + } +} \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..7254add --- /dev/null +++ b/sample/src/main/res/layout/activity_main.xml @@ -0,0 +1,9 @@ + + + + diff --git a/sample/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..5562ea4 --- /dev/null +++ b/sample/src/main/res/menu/menu_main.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/sample/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..9a078e3 Binary files /dev/null and b/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/sample/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..efc028a Binary files /dev/null and b/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..3af2608 Binary files /dev/null and b/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..9bec2e6 Binary files /dev/null and b/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..34947cd Binary files /dev/null and b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/sample/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml new file mode 100644 index 0000000..ea9712f --- /dev/null +++ b/sample/src/main/res/values/strings.xml @@ -0,0 +1,10 @@ + + KPrefs + MainActivity + This is a header + This is a description + Checkbox 1 + Checkbox 2 + Checkbox 3 + Text Color + diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml new file mode 100644 index 0000000..daa2a5c --- /dev/null +++ b/sample/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/sample/src/main/res/xml/changelog.xml b/sample/src/main/res/xml/changelog.xml new file mode 100644 index 0000000..7569fb2 --- /dev/null +++ b/sample/src/main/res/xml/changelog.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/test/java/ca/allanwang/kprefs/ExampleUnitTest.java b/sample/src/test/java/ca/allanwang/kprefs/ExampleUnitTest.java new file mode 100644 index 0000000..4c029fd --- /dev/null +++ b/sample/src/test/java/ca/allanwang/kprefs/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package ca.allanwang.kprefs; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file -- cgit v1.2.3