-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.2" | ||
|
||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.core:core-ktx:1.1.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.dmytroporoshyn.answerselectorview | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.dmytroporoshyn.answerselectorview.test", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.dmytroporoshyn.answerselectorview" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/******************************************************************************* | ||
* Developed by Dimitry Poroshyn on 7/31/19 1:47 PM | ||
* Last modified 7/31/19 1:47 PM | ||
* Copyright (c) 2019. All rights reserved. | ||
******************************************************************************/ | ||
|
||
package com.dmytroporoshyn.answerselectorview | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.widget.Checkable | ||
import android.widget.FrameLayout | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import androidx.appcompat.content.res.AppCompatResources | ||
|
||
class AnswerItemView(context: Context, attributes: AttributeSet?) : FrameLayout(context, attributes), | ||
Checkable { | ||
|
||
private var selectorText: TextView | ||
private var viewBackground: FrameLayout | ||
private var checkedSelector: Boolean = false | ||
var baseId: Int = 0 | ||
private var listener: ((Int, Boolean) -> Unit?)? = null | ||
|
||
|
||
init { | ||
val view = LinearLayout.inflate(context, R.layout.view_answer_item, this) | ||
selectorText = view.findViewById(R.id.selectorText) | ||
viewBackground = view.findViewById(R.id.viewBackground) | ||
} | ||
|
||
fun setText(string: String) { | ||
selectorText.text = string | ||
} | ||
|
||
override fun isChecked(): Boolean { | ||
return checkedSelector | ||
} | ||
|
||
override fun toggle() { | ||
if (!isChecked) { | ||
isChecked = !checkedSelector | ||
refreshDrawableState() | ||
} | ||
} | ||
|
||
override fun performClick(): Boolean { | ||
toggle() | ||
return super.performClick() | ||
} | ||
|
||
override fun setChecked(boolean: Boolean) { | ||
checkedSelector = boolean | ||
listener?.invoke(baseId, checkedSelector) | ||
refreshDrawableState() | ||
} | ||
|
||
override fun onCreateDrawableState(extraSpace: Int): IntArray { | ||
val drawableState = super.onCreateDrawableState(extraSpace + 1) | ||
if (isChecked) { | ||
selectorText.setTextColor( | ||
AppCompatResources.getColorStateList( | ||
this.context, | ||
R.color.colorAccent | ||
) | ||
) | ||
viewBackground.background = | ||
AppCompatResources.getDrawable( | ||
this.context, | ||
R.drawable.ic_answer_view_background_checked | ||
) | ||
} else { | ||
selectorText.setTextColor( | ||
AppCompatResources.getColorStateList( | ||
this.context, | ||
R.color.blackText | ||
) | ||
) | ||
viewBackground.background = | ||
AppCompatResources.getDrawable(this.context, R.drawable.ic_answer_view_background) | ||
} | ||
return drawableState | ||
} | ||
|
||
fun listener(listener: (Int, Boolean) -> Unit) { | ||
this.listener = listener | ||
} | ||
} |