From 56288e5a892f1174504fd4fcb5807af6d31c33f2 Mon Sep 17 00:00:00 2001 From: askar Date: Mon, 1 Apr 2019 23:03:18 +0600 Subject: [PATCH] some changes --- app/build.gradle | 8 +-- build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 4 +- library/build.gradle | 4 +- .../java/kz/mobdev/library/KazCharsView.kt | 63 ++++++++++--------- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e6cc8ba..21588f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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') diff --git a/build.gradle b/build.gradle index 4b5e4ff..6da7e75 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0103a59..85d6298 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index 307df61..78de917 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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" } diff --git a/library/src/main/java/kz/mobdev/library/KazCharsView.kt b/library/src/main/java/kz/mobdev/library/KazCharsView.kt index 989cb58..1b3260a 100644 --- a/library/src/main/java/kz/mobdev/library/KazCharsView.kt +++ b/library/src/main/java/kz/mobdev/library/KazCharsView.kt @@ -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 @@ -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 @@ -36,13 +40,12 @@ 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 @@ -50,13 +53,18 @@ class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr: } } - 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) { @@ -64,13 +72,11 @@ class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr: } 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 @@ -100,8 +106,8 @@ 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) } @@ -109,21 +115,16 @@ class KazCharsView(context: Context, attrs: AttributeSet? = null, defStyleAttr: } } - 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 } + } + } }