Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
askarsyzdykov committed Apr 1, 2019
1 parent 9751573 commit 56288e5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation project(path: ':library')

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.30'
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 24 17:30:32 ALMT 2018
#Mon Apr 01 22:46:30 ALMT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies {

implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

}
Expand Down
63 changes: 32 additions & 31 deletions library/src/main/java/kz/mobdev/library/KazCharsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kz.mobdev.library
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.Gravity
import android.view.View
Expand All @@ -15,10 +14,15 @@ import android.widget.TextView
* Created by Askar Syzdykov on 4/24/18.
*/

class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : LinearLayout(context, attrs) {
class KazCharsView(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : LinearLayout(context, attrs) {

private val cyrillicChars = arrayOf("ә", "ө", "қ", "ғ", "і", "һ", "ң", "ұ", "ү")
private val latinChars = arrayOf("á", "ó", "q", "ǵ", "i", "h", "ń", "u", "ú")
private val cyrillicChars = arrayOf("ә", "і", "ң", "ғ", "ү", "ұ", "қ", "ө", "һ")
private val latinChars = arrayOf("á", "i", "ń", "ǵ", "ú", "u", "q", "ó", "h")

var kazCharsClickListener: KazCharsClickListener? = null

Expand All @@ -36,41 +40,43 @@ class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr:
}
}

var type: Type? = Type.CYRILLIC
var type: Type = Type.CYRILLIC
set(value) {
field = value
val chars = when (type) {
Type.CYRILLIC -> cyrillicChars
Type.LATIN -> latinChars
else -> cyrillicChars
}
(0 until childCount).forEachIndexed { index, it ->
val b = getChildAt(it) as TextView
b.text = chars[index]
}
}

enum class Type(val type: Int) {
CYRILLIC(0),
LATIN(1);

companion object {
fun valueOf(value: Int): Type? = Type.values().find { it.type == value }
init {
val a = context.obtainStyledAttributes(attrs, R.styleable.KazCharsView, defStyleAttr, defStyleRes)
(0 until a.indexCount).forEach { i ->
val attr = a.getIndex(i)
when (attr) {
R.styleable.KazCharsView_kcv_allCaps -> isAllCaps = a.getBoolean(attr, false)
R.styleable.KazCharsView_kcv_fontSize -> fontSize = a.getDimensionPixelSize(attr, 14)
R.styleable.KazCharsView_kcv_textColor -> textColor = a.getColor(attr, Color.WHITE)
R.styleable.KazCharsView_kcv_type -> type = Type.valueOf(a.getInt(attr, Type.CYRILLIC.type))!!
}
}
a.recycle()
}

constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0, 0) {
init()
}

private fun init() {
Log.d("KazCharsView", "Initialization")

val density = context.resources.displayMetrics.density
val paddingPixel = (8 * density).toInt()

val layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)
val marginPixel = (1 * density).toInt()
val marginPixel = density.toInt()
layoutParams.leftMargin = marginPixel
layoutParams.rightMargin = marginPixel

Expand Down Expand Up @@ -100,30 +106,25 @@ class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr:
}
text = focusedView.text.toString()
val newText = text.substring(0, cursorPosition) +
char.toString() +
text.substring(cursorPosition, text.length)
char.toString() +
text.substring(cursorPosition, text.length)
focusedView.setText(newText)
focusedView.setSelection(cursorPosition + 1)
}
}
}
}

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.KazCharsView, defStyleAttr, defStyleRes)
(0 until a.indexCount).forEach { i ->
val attr = a.getIndex(i)
when (attr) {
R.styleable.KazCharsView_kcv_allCaps -> isAllCaps = a.getBoolean(attr, false)
R.styleable.KazCharsView_kcv_fontSize -> fontSize = a.getDimensionPixelSize(attr, 14)
R.styleable.KazCharsView_kcv_textColor -> textColor = a.getColor(attr, Color.WHITE)
R.styleable.KazCharsView_kcv_type -> type = Type.valueOf(a.getInt(attr, Type.CYRILLIC.type))
}
}
a.recycle()
}

interface KazCharsClickListener {
fun onKazakhCharClick(view: View, letter: Char)
}

enum class Type(val type: Int) {
CYRILLIC(0),
LATIN(1);

companion object {
fun valueOf(value: Int): Type? = Type.values().find { it.type == value }
}
}
}

0 comments on commit 56288e5

Please sign in to comment.