-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project converted to a library, parameters list handling added, gener…
…ating Tweaks class from list of params added
- Loading branch information
1 parent
667eb2b
commit cf3daf3
Showing
73 changed files
with
479 additions
and
88 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: "org.codehaus.groovy.android" | ||
|
||
buildscript { | ||
dependencies { | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.20" | ||
classpath "gradle.plugin.org.codehaus.groovy:groovy-android-gradle-plugin:2.0.0" | ||
classpath 'com.android.tools.build:gradle:3.0.1' | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
maven { url "https://plugins.gradle.org/m2/" } | ||
maven { url 'https://maven.google.com' } | ||
maven { url "https://repo1.maven.org/maven2"} | ||
} | ||
} | ||
|
||
|
||
android { | ||
compileSdkVersion 26 | ||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.yaml:snakeyaml:1.19" | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.20" | ||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
|
||
testImplementation 'org.codehaus.groovy:groovy:2.4.7:grooid' | ||
testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4' | ||
|
||
implementation 'com.squareup:kotlinpoet:0.6.0' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.polidea.androidtweaks"> | ||
|
||
<application> | ||
<activity android:name=".TweaksActivity"/> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
param_tag1: 1.0 | ||
param_tag2: 1.5 | ||
param_tag3: "testValue" | ||
int_param: 1 | ||
boolean_param: true |
20 changes: 20 additions & 0 deletions
20
androidtweaks/src/main/java/com/polidea/androidtweaks/TweaksActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.polidea.androidtweaks | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import com.polidea.androidtweaks.manager.TweaksGenerator | ||
import com.polidea.androidtweaks.manager.TweaksManager | ||
|
||
class TweaksActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_tweaks) | ||
|
||
val settingsManager = TweaksManager.getInstance(this.applicationContext) | ||
System.out.println(settingsManager.params) | ||
settingsManager.setParamValue("param_tag1", 1.4) | ||
System.out.println(settingsManager.params) | ||
TweaksGenerator().generate(TweaksManager.getInstance(this.applicationContext).params) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
androidtweaks/src/main/java/com/polidea/androidtweaks/manager/TweaksGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.polidea.androidtweaks.manager | ||
|
||
import com.polidea.androidtweaks.model.* | ||
import com.squareup.kotlinpoet.FileSpec | ||
import com.squareup.kotlinpoet.KModifier | ||
import com.squareup.kotlinpoet.PropertySpec | ||
import com.squareup.kotlinpoet.TypeSpec | ||
|
||
|
||
class TweaksGenerator { | ||
fun generate(params: List<Param<*>>) { | ||
val propertySpecs: ArrayList<PropertySpec> = ArrayList() | ||
for (p in params) { | ||
when (p) { | ||
is BooleanParam -> propertySpecs.add(PropertySpec.builder(p.name, Boolean::class, KModifier.PUBLIC).build()) | ||
is DoubleParam -> propertySpecs.add(PropertySpec.builder(p.name, Double::class, KModifier.PUBLIC).build()) | ||
is IntegerParam -> propertySpecs.add(PropertySpec.builder(p.name, Int::class, KModifier.PUBLIC).build()) | ||
is StringParam -> propertySpecs.add(PropertySpec.builder(p.name, String::class, KModifier.PUBLIC).build()) | ||
} | ||
} | ||
|
||
val tweaksFile = FileSpec.builder("com.polidea.androidtweaks.tweaks", "Tweaks") | ||
.addType(TypeSpec.classBuilder("Tweaks") | ||
.addProperties(propertySpecs) | ||
.build()) | ||
|
||
tweaksFile.build().writeTo(System.out) // todo write to the actual file | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
androidtweaks/src/main/java/com/polidea/androidtweaks/manager/TweaksManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.polidea.androidtweaks.manager | ||
|
||
import android.content.Context | ||
import com.polidea.androidtweaks.model.Param | ||
|
||
|
||
class TweaksManager private constructor(context: Context) { | ||
val params: List<Param<*>> = YamlParser().parseYaml("tweaks.yml", context) | ||
|
||
companion object { | ||
@Volatile | ||
private var INSTANCE: TweaksManager? = null | ||
|
||
@JvmStatic | ||
fun getInstance(context: Context): TweaksManager { | ||
if (INSTANCE == null) { | ||
INSTANCE = TweaksManager(context) | ||
} | ||
|
||
return INSTANCE as TweaksManager | ||
} | ||
} | ||
|
||
fun <T> getParamValue(key: String): T? = getParam<T>(key)?.value | ||
|
||
fun <T> setParamValue(key: String, value: T) { | ||
val param = getParam<T>(key) | ||
param ?: throw IllegalArgumentException("Param with name $key undefined!") | ||
param.value = value | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
private fun <T> getParam(key: String): Param<T>? = params.find { it.name == key } as Param<T>? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
androidtweaks/src/main/java/com/polidea/androidtweaks/model/BooleanParam.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.polidea.androidtweaks.model | ||
|
||
|
||
data class BooleanParam(override var name: String, override var value: Boolean) : Param<Boolean> |
4 changes: 4 additions & 0 deletions
4
androidtweaks/src/main/java/com/polidea/androidtweaks/model/DoubleParam.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.polidea.androidtweaks.model | ||
|
||
|
||
data class DoubleParam(override var name: String, override var value: Double) : Param<Double> |
4 changes: 4 additions & 0 deletions
4
androidtweaks/src/main/java/com/polidea/androidtweaks/model/IntegerParam.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.polidea.androidtweaks.model | ||
|
||
|
||
data class IntegerParam(override var name: String, override var value: Int) : Param<Int> |
7 changes: 7 additions & 0 deletions
7
androidtweaks/src/main/java/com/polidea/androidtweaks/model/Param.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.polidea.androidtweaks.model | ||
|
||
|
||
interface Param<T> { | ||
val name: String | ||
var value: T | ||
} |
4 changes: 4 additions & 0 deletions
4
androidtweaks/src/main/java/com/polidea/androidtweaks/model/StringParam.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.polidea.androidtweaks.model | ||
|
||
|
||
data class StringParam(override var name: String, override var value: String) : Param<String> |
6 changes: 6 additions & 0 deletions
6
androidtweaks/src/main/java/com/polidea/androidtweaks/utils/Logger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.polidea.androidtweaks.utils | ||
|
||
|
||
class Logger { | ||
// todo | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
app/src/main/java/com/polidea/androidtweaks/TweaksActivity.kt
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
app/src/main/java/com/polidea/androidtweaks/manager/SettingsManager.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/polidea/androidtweaks/model/BooleanParam.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/polidea/androidtweaks/model/DoubleParam.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/polidea/androidtweaks/model/GenericParam.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/polidea/androidtweaks/model/IntegerParam.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/com/polidea/androidtweaks/model/StringParam.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
|
||
|
||
|
||
defaultConfig { | ||
applicationId "com.polidea.androidtweaks" | ||
applicationId "com.polidea.sample" | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
compile files('libs/snakeyaml-1.19-android.jar') | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
compile "org.jetbrains.kotlin:kotlin-reflect:1.2.10" | ||
implementation 'com.jakewharton.timber:timber:4.6.0' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | ||
|
||
implementation project(":android-tweaks") | ||
} |
Oops, something went wrong.