From 925d2d4af70abb5cfc21348b6bfed2e5f8030c4e Mon Sep 17 00:00:00 2001 From: "a.artemov" Date: Wed, 26 Sep 2018 15:49:09 +0300 Subject: [PATCH] Kotlin update --- .idea/caches/build_file_checksums.ser | Bin 0 -> 590 bytes .idea/codeStyles/Project.xml | 29 ++ .idea/kotlinc.xml | 7 - app/build.gradle | 22 +- .../pincodeview/example/MainActivity.java | 180 --------- .../devs/pincodeview/example/MainActivity.kt | 136 +++++++ app/src/main/res/layout/activity_main.xml | 20 +- build.gradle | 8 +- gradle.properties | 1 + gradle/wrapper/gradle-wrapper.properties | 4 +- library/build.gradle | 20 +- .../devs/pincodeview/PinCodeView.java | 372 ------------------ .../goldenpie/devs/pincodeview/PinCodeView.kt | 352 +++++++++++++++++ .../devs/pincodeview/SinglePinView.java | 68 ---- .../devs/pincodeview/SinglePinView.kt | 52 +++ .../devs/pincodeview/core/LOCK_TYPE.java | 5 - .../devs/pincodeview/core/Listeners.java | 15 - .../devs/pincodeview/core/Listeners.kt | 15 + .../devs/pincodeview/core/LockType.kt | 5 + .../devs/pincodeview/core/Utils.ext.kt | 18 + .../devs/pincodeview/core/Utils.java | 31 -- 21 files changed, 653 insertions(+), 707 deletions(-) create mode 100644 .idea/caches/build_file_checksums.ser create mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/kotlinc.xml delete mode 100644 app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.java create mode 100644 app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.kt delete mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.java create mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.kt delete mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.java create mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.kt delete mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/LOCK_TYPE.java delete mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.java create mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.kt create mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/LockType.kt create mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.ext.kt delete mode 100644 library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.java diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000000000000000000000000000000000000..ed42579b0a26c89c70242a1d9c0ee908abaeccd3 GIT binary patch literal 590 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}a-h2eL2`N^IX#cW;tZfX zEBmd3hs6>uGBYr_F>vMNC#JY1CYR(Fc`|U8WE7`m5MJP&%JuQytsrx$Jr_-v^ce>I3`gqv8W_9H@_?fYEKLz_zO~tN-|T6OW_7x zk?pzJ&#;N*WdrAoH$R-}N*H)h{03JTD|Po2<5K%7H|~dN4|4N*fB}({pPZNjic}0! tCpYD)R_Ls~Y2-QK`=X?&`%4%E@wnlj<=w6$C(nP#jj1qFeD+?r0syGS)NTL( literal 0 HcmV?d00001 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 1c24f9a..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index de5ca2d..d4781b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,14 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 28 + defaultConfig { applicationId "com.goldenpie.devs.pincodeview" minSdkVersion 16 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,10 +22,14 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.pes.materialcolorpicker:library:1.1.+' - + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.pes.materialcolorpicker:library:1.2.4' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - compile project(':library') + implementation project(':library') } + +androidExtensions { + experimental = true +} \ No newline at end of file diff --git a/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.java b/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.java deleted file mode 100644 index 8407666..0000000 --- a/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.goldenpie.devs.pincodeview.example; - -import android.os.Bundle; -import android.support.annotation.ColorInt; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.AppCompatButton; -import android.support.v7.widget.SwitchCompat; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.SeekBar; -import android.widget.Toast; - -import com.goldenpie.devs.pincodeview.PinCodeView; -import com.goldenpie.devs.pincodeview.core.LOCK_TYPE; -import com.goldenpie.devs.pincodeview.core.Listeners; -import com.pes.androidmaterialcolorpickerdialog.ColorPicker; -import com.pes.androidmaterialcolorpickerdialog.ColorPickerCallback; - -public class MainActivity extends AppCompatActivity implements Listeners.PinEnteredListener, - Listeners.PinReEnterListener, Listeners.PinMismatchListener, View.OnClickListener { - - private PinCodeView pinCodeView; - private PinCodeView drawablePinCodeView; - - public MainActivity() { - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - initView(); - - pinCodeView.setLockType(LOCK_TYPE.ENTER_PIN); - pinCodeView.setPinEnteredListener(this); - pinCodeView.setPinReEnterListener(this); - pinCodeView.setPinMismatchListener(this); - drawablePinCodeView.setLockType(LOCK_TYPE.ENTER_PIN); - drawablePinCodeView.setPinEnteredListener(this); - drawablePinCodeView.setPinReEnterListener(this); - drawablePinCodeView.setPinMismatchListener(this); - } - - private void initView() { - pinCodeView = (PinCodeView) findViewById(R.id.ci); - AppCompatButton innerColor = (AppCompatButton) findViewById(R.id.inner_color); - AppCompatButton outerColor = (AppCompatButton) findViewById(R.id.outer_color); - AppCompatButton errorColor = (AppCompatButton) findViewById(R.id.error_color); - SeekBar seekBar = (SeekBar) findViewById(R.id.sek_bar); - drawablePinCodeView = (PinCodeView) findViewById(R.id.ci_drawable); - SeekBar alphaSekBar = (SeekBar) findViewById(R.id.alpha_sek_bar); - SwitchCompat innerTintSwitch = (SwitchCompat) findViewById(R.id.inner_tint_switch); - SwitchCompat outerTintSwitch = (SwitchCompat) findViewById(R.id.outer_tint_switch); - - seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - pinCodeView.setPinLength(progress); - drawablePinCodeView.setPinLength(progress); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - - } - }); - alphaSekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - pinCodeView.setInnerAlpha(progress / 10f); - drawablePinCodeView.setInnerAlpha(progress / 10f); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - - } - }); - innerColor.setOnClickListener(this); - outerColor.setOnClickListener(this); - errorColor.setOnClickListener(this); - SwitchCompat switchCompat = (SwitchCompat) findViewById(R.id.switch_compat); - switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - pinCodeView.setLockType(isChecked ? LOCK_TYPE.ENTER_PIN : LOCK_TYPE.UNLOCK); - drawablePinCodeView.setLockType(isChecked ? LOCK_TYPE.ENTER_PIN : LOCK_TYPE.UNLOCK); - } - }); - innerTintSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - pinCodeView.setTintInner(isChecked); - drawablePinCodeView.setTintInner(isChecked); - } - }); - outerTintSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - pinCodeView.setTintOuter(isChecked); - drawablePinCodeView.setTintOuter(isChecked); - } - }); - } - - @Override - public void onPinEntered(String pinCode) { - Toast.makeText(this, pinCode, Toast.LENGTH_SHORT).show(); - } - - @Override - public void onPinReEnterStarted() { - Toast.makeText(this, "Pin re-enter started", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onPinMismatch() { - Toast.makeText(this, "Pin mismatch", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.inner_color: - final ColorPicker cp = new ColorPicker(MainActivity.this, 255, 255, 255); - - cp.show(); - - cp.setCallback(new ColorPickerCallback() { - @Override - public void onColorChosen(@ColorInt int color) { - pinCodeView.setInnerCircleColor(color); - drawablePinCodeView.setInnerCircleColor(color); - cp.dismiss(); - } - }); - - break; - case R.id.outer_color: - final ColorPicker cp1 = new ColorPicker(MainActivity.this, 255, 255, 255); - - cp1.show(); - - cp1.setCallback(new ColorPickerCallback() { - @Override - public void onColorChosen(@ColorInt int color) { - pinCodeView.setOuterCircleColor(color); - drawablePinCodeView.setOuterCircleColor(color); - cp1.dismiss(); - } - }); - break; - case R.id.error_color: - final ColorPicker cp2 = new ColorPicker(MainActivity.this, 255, 255, 255); - - cp2.show(); - - cp2.setCallback(new ColorPickerCallback() { - @Override - public void onColorChosen(@ColorInt int color) { - pinCodeView.setErrorColor(color); - drawablePinCodeView.setErrorColor(color); - cp2.dismiss(); - } - }); - break; - } - } -} diff --git a/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.kt b/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.kt new file mode 100644 index 0000000..3aa9c09 --- /dev/null +++ b/app/src/main/java/com/goldenpie/devs/pincodeview/example/MainActivity.kt @@ -0,0 +1,136 @@ +package com.goldenpie.devs.pincodeview.example + +import android.app.Activity +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.View +import android.widget.SeekBar +import android.widget.Toast +import com.goldenpie.devs.pincodeview.core.Listeners +import com.goldenpie.devs.pincodeview.core.LockType +import com.pes.androidmaterialcolorpickerdialog.ColorPicker +import kotlinx.android.synthetic.main.activity_main.* + + +class MainActivity : AppCompatActivity(), Listeners.PinEnteredListener, Listeners.PinReEnterListener, Listeners.PinMismatchListener, View.OnClickListener { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + initView() + + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setLockType(LockType.ENTER_PIN) + it.setPinEnteredListener(this) + it.setPinReEnterListener(this) + it.setPinMismatchListener(this) + } + } + + private fun initView() { + seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setPinLength(progress) + } + } + + override fun onStartTrackingTouch(seekBar: SeekBar) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + + } + }) + + alphaSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setInnerAlpha(progress.div(10f)) + } + } + + override fun onStartTrackingTouch(seekBar: SeekBar) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + + } + }) + + listOf(innerColor, outerColor, errorColor).onEach { + it.setOnClickListener(this) + } + + switchCompat.setOnCheckedChangeListener { _, isChecked -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setLockType(if (isChecked) LockType.ENTER_PIN else LockType.UNLOCK) + } + } + + innerTintSwitch.setOnCheckedChangeListener { _, isChecked -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setTintInner(isChecked) + } + } + + outerTintSwitch.setOnCheckedChangeListener { _, isChecked -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setTintOuter(isChecked) + } + } + } + + override fun onPinEntered(pinCode: String?) { + toast(pinCode) + } + + override fun onPinReEnterStarted() { + toast("Pin re-enter started") + } + + override fun onPinMismatch() { + toast("Pin mismatch") + } + + override fun onClick(v: View) { + val cp = ColorPicker(this@MainActivity) + .apply { + show() + } + + when (v) { + innerColor -> { + cp.setCallback { color -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setInnerCircleColor(color) + } + cp.dismiss() + } + } + outerColor -> { + cp.setCallback { color -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setOuterCircleColor(color) + } + cp.dismiss() + } + } + errorColor -> { + cp.setCallback { color -> + listOf(pinCodeView, drawablePinCodeView).onEach { + it.setErrorColor(color) + } + cp.dismiss() + } + } + } + } + + private fun Activity.toast(string: String?) = + Toast.makeText(this, string, Toast.LENGTH_SHORT).show() + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 05fb073..4ffb521 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,7 +15,7 @@ tools:context="com.goldenpie.devs.pincodeview.example.MainActivity"> @@ -152,7 +152,7 @@ android:text="No tint" /> @@ -187,7 +187,7 @@ android:text="No tint" /> diff --git a/build.gradle b/build.gradle index a109c28..e46837d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.2.71' repositories { jcenter() maven { url "https://jitpack.io" } + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'com.github.dcendents:android-maven-gradle-plugin:+' + classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -18,6 +21,7 @@ allprojects { repositories { jcenter() maven { url "https://jitpack.io" } + google() } } diff --git a/gradle.properties b/gradle.properties index aac7c9b..ba38d80 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,4 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +org.gradle.configureondemand=false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05bc004..6280000 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jun 07 14:34:21 EEST 2017 +#Wed Sep 26 14:44:31 MSK 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index aef170d..3dbc376 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,13 +1,14 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' apply plugin: 'com.github.dcendents.android-maven' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 28 defaultConfig { - minSdkVersion 11 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -21,10 +22,15 @@ android { } dependencies { - ext.supportLibsVersion = "25.3.1" + ext.supportLibsVersion = "28.0.0" - compile "com.android.support:appcompat-v7:$supportLibsVersion" - compile "com.android.support:design:$supportLibsVersion" + implementation "com.android.support:appcompat-v7:$supportLibsVersion" + implementation "com.android.support:design:$supportLibsVersion" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} + +androidExtensions { + experimental = true } group='com.github.antoxa2584x' \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.java b/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.java deleted file mode 100644 index 0c03639..0000000 --- a/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.java +++ /dev/null @@ -1,372 +0,0 @@ -package com.goldenpie.devs.pincodeview; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.os.Handler; -import android.support.annotation.ColorInt; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresApi; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.AppCompatEditText; -import android.text.Editable; -import android.text.InputFilter; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -import com.goldenpie.devs.pincodeview.core.LOCK_TYPE; -import com.goldenpie.devs.pincodeview.core.Listeners; -import com.goldenpie.devs.pincodeview.core.Utils; - -import java.util.ArrayList; - -public class PinCodeView extends LinearLayout implements View.OnClickListener { - - @ColorInt - private int innerCircleColor; - @ColorInt - private int outerCircleColor; - @ColorInt - private int errorColor; - - private Drawable innerDrawable; - private Drawable outerDrawable; - private int pinCount; - private float innerAlpha; - private boolean tintInner = true; - private boolean tintOuter = true; - - private LinearLayout pinLayout; - private AppCompatEditText invisibleEditText; - private LOCK_TYPE lockType; - private String pass; - - private Listeners.PinEnteredListener pinEnteredListener; - private Listeners.PinMismatchListener pinMismatchListener; - private Listeners.PinReEnterListener pinReEnterListener; - - private ArrayList pins = new ArrayList<>(); - - public PinCodeView(Context context) { - super(context); - init(null); - } - - public PinCodeView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - init(attrs); - } - - public PinCodeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(attrs); - } - - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public PinCodeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(attrs); - } - - private void initView() { - - LayoutInflater inflater; - inflater = (LayoutInflater) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - View mView = inflater.inflate(R.layout.pin_code_view_layout, this); - - pinLayout = (LinearLayout) mView.findViewById(R.id.pin_layout); - invisibleEditText = (AppCompatEditText) mView.findViewById(R.id.invisible_edittext); - } - - private void parseAttributes(AttributeSet attrs) { - innerCircleColor = Color.WHITE; - outerCircleColor = ContextCompat.getColor(getContext(), R.color.primary_dark); - errorColor = ContextCompat.getColor(getContext(), R.color.accent); - pinCount = 4; - lockType = LOCK_TYPE.UNLOCK; - innerAlpha = 0.3f; - - if (attrs == null) - return; - - TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PinCodeView); - - innerCircleColor = a.getColor(R.styleable.PinCodeView_pcv_pin_inner_color, innerCircleColor); - outerCircleColor = a.getColor(R.styleable.PinCodeView_pcv_pin_outer_color, outerCircleColor); - errorColor = a.getColor(R.styleable.PinCodeView_pcv_pin_error_color, errorColor); - pinCount = a.getInteger(R.styleable.PinCodeView_pcv_pin_length, pinCount); - innerAlpha = a.getFloat(R.styleable.PinCodeView_pcv_pin_inner_alpha, innerAlpha); - tintInner = a.getBoolean(R.styleable.PinCodeView_pcv_pin_tint_inner, tintInner); - tintOuter = a.getBoolean(R.styleable.PinCodeView_pcv_pin_tint_outer, tintOuter); - - innerDrawable = a.getDrawable(R.styleable.PinCodeView_pcv_pin_inner_drawable); - - if (innerDrawable == null) - innerDrawable = ContextCompat.getDrawable(getContext(), R.drawable.circle); - - outerDrawable = a.getDrawable(R.styleable.PinCodeView_pcv_pin_outer_drawable); - - if (outerDrawable == null) - outerDrawable = ContextCompat.getDrawable(getContext(), R.drawable.circle); - - switch (a.getInt(R.styleable.PinCodeView_pcv_pin_type, 0)) { - case 0: - lockType = LOCK_TYPE.UNLOCK; - break; - case 1: - lockType = LOCK_TYPE.ENTER_PIN; - break; - } - - a.recycle(); - } - - private void init(AttributeSet attrs) { - initView(); - parseAttributes(attrs); - - setUpView(); - setUpPins(); - } - - private void setUpPins() { - pins.clear(); - pinLayout.removeAllViews(); - - if (pinCount <= 0) - return; - - for (int i = 0; i < pinCount; i++) { - SinglePinView singlePinView = new SinglePinView(getContext()); - singlePinView.setColors(innerCircleColor, outerCircleColor); - - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT); - lp.weight = 1; - int margin = (int) Utils.pxFromDp(getContext(), 2); - singlePinView.setGravity(Gravity.CENTER_HORIZONTAL); - - lp.setMargins(margin, margin, margin, margin); - singlePinView.setLayoutParams(lp); - - singlePinView.getInnerPinView().setImageDrawable(innerDrawable); - singlePinView.getOuterPinView().setImageDrawable(outerDrawable); - - if (!tintInner) - singlePinView.getInnerPinView().clearColorFilter(); - singlePinView.getInnerPinView().setAlpha(innerAlpha); - if (!tintOuter) - singlePinView.getOuterPinView().clearColorFilter(); - - - pins.add(singlePinView); - pinLayout.addView(singlePinView); - } - - invisibleEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(pinCount)}); - } - - private void setUpView() { - invisibleEditText.setOnFocusChangeListener(new OnFocusChangeListener() { - @Override - public void onFocusChange(View v, boolean hasFocus) { - if (hasFocus) { - Utils.showDelayedKeyboard(getContext(), v); - } - } - }); - - invisibleEditText.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - if (pinCount <= 0) - return; - - for (SinglePinView pin : pins) { - pin.getInnerPinView().setAlpha(innerAlpha); - } - - for (int i = 0; i < s.length(); i++) { - pins.get(i).getInnerPinView().setAlpha(1f); - } - - if (lockType == LOCK_TYPE.ENTER_PIN && !TextUtils.isEmpty(pass) && s.length() == 0) { - if (pinReEnterListener != null) - pinReEnterListener.onPinReEnterStarted(); - } - - if (s.length() == pinCount) { - if (lockType == LOCK_TYPE.UNLOCK) { - pass = s.toString(); - - if (pinEnteredListener != null) - pinEnteredListener.onPinEntered(pass); - return; - } - - if (TextUtils.isEmpty(pass)) { - pass = s.toString(); - invisibleEditText.getText().clear(); - } else { - if (!pass.equals(s.toString())) { - - reset(); - - if (pinMismatchListener != null) - pinMismatchListener.onPinMismatch(); - return; - } - - if (pinEnteredListener != null) - pinEnteredListener.onPinEntered(pass); - } - } - } - - @Override - public void afterTextChanged(Editable s) { - - } - }); - - pinLayout.setOnClickListener(this); - } - - /** - * Reset pin code view with error style - */ - public void reset() { - for (SinglePinView pin : pins) { - pin.getInnerPinView().setColorFilter(errorColor); - } - - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - for (SinglePinView pin : pins) { - if (tintInner) - pin.getInnerPinView().setColorFilter(innerCircleColor); - else - pin.getInnerPinView().clearColorFilter(); - - } - invisibleEditText.getText().clear(); - } - }, 500); - } - - /** - * Clear pin code view input - */ - public void clear() { - pass = null; - invisibleEditText.getText().clear(); - } - - @Override - public void onClick(View v) { - int id = v.getId(); - - if (id == R.id.pin_layout) { - invisibleEditText.clearFocus(); - invisibleEditText.requestFocus(); - } - } - - /** - * Set type of view logic - * Could be one of - * - LOCK_TYPE.UNLOCK if you need just confirm pin - * - LOCK_TYPE.ENTER_PIN if you want to save pin - * - * @param lockType - */ - public PinCodeView setLockType(LOCK_TYPE lockType) { - this.lockType = lockType; - this.pass = null; - clear(); - return this; - } - - public PinCodeView setInnerCircleColor(@ColorInt int innerCircleColor) { - this.innerCircleColor = innerCircleColor; - setUpPins(); - return this; - } - - public PinCodeView setOuterCircleColor(@ColorInt int outerCircleColor) { - this.outerCircleColor = outerCircleColor; - setUpPins(); - return this; - } - - public PinCodeView setErrorColor(@ColorInt int errorColor) { - this.errorColor = errorColor; - return this; - } - - public PinCodeView setPinLength(int pinCount) { - this.pinCount = pinCount; - setUpPins(); - return this; - } - - public PinCodeView setInnerDrawable(Drawable innerDrawable) { - this.innerDrawable = innerDrawable; - setUpPins(); - return this; - } - - public PinCodeView setOuterDrawable(Drawable outerDrawable) { - this.outerDrawable = outerDrawable; - setUpPins(); - return this; - } - - public PinCodeView setInnerAlpha(float innerAlpha) { - this.innerAlpha = innerAlpha; - setUpPins(); - return this; - } - - public PinCodeView setTintInner(boolean tintInner) { - this.tintInner = tintInner; - setUpPins(); - return this; - } - - public PinCodeView setTintOuter(boolean tintOuter) { - this.tintOuter = tintOuter; - setUpPins(); - return this; - } - - public PinCodeView setPinEnteredListener(Listeners.PinEnteredListener pinEnteredListener) { - this.pinEnteredListener = pinEnteredListener; - return this; - } - - public PinCodeView setPinMismatchListener(Listeners.PinMismatchListener pinMismatchListener) { - this.pinMismatchListener = pinMismatchListener; - return this; - } - - public PinCodeView setPinReEnterListener(Listeners.PinReEnterListener pinReEnterListener) { - this.pinReEnterListener = pinReEnterListener; - return this; - } -} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.kt b/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.kt new file mode 100644 index 0000000..b28b7fa --- /dev/null +++ b/library/src/main/java/com/goldenpie/devs/pincodeview/PinCodeView.kt @@ -0,0 +1,352 @@ +package com.goldenpie.devs.pincodeview + +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.os.Build +import android.os.Handler +import android.support.annotation.ColorInt +import android.support.annotation.RequiresApi +import android.support.v4.content.ContextCompat +import android.support.v7.widget.AppCompatEditText +import android.text.Editable +import android.text.InputFilter +import android.text.TextWatcher +import android.util.AttributeSet +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.view.View.OnFocusChangeListener +import android.view.ViewGroup +import android.widget.LinearLayout +import com.goldenpie.devs.pincodeview.core.Listeners +import com.goldenpie.devs.pincodeview.core.LockType +import com.goldenpie.devs.pincodeview.core.pxFromDp +import com.goldenpie.devs.pincodeview.core.showDelayedKeyboard +import java.util.* + +open class PinCodeView : LinearLayout, View.OnClickListener { + + @ColorInt + private var innerCircleColor: Int = 0 + @ColorInt + private var outerCircleColor: Int = 0 + @ColorInt + private var errorColor: Int = 0 + + private var innerDrawable: Drawable? = null + private var outerDrawable: Drawable? = null + private var pinCount: Int = 0 + private var innerAlpha: Float = 0.toFloat() + private var tintInner = true + private var tintOuter = true + + private lateinit var pinLayout: LinearLayout + private lateinit var invisibleEditText: AppCompatEditText + private var lockType: LockType? = null + private var pass: String? = null + + private var pinEnteredListener: Listeners.PinEnteredListener? = null + private var pinMismatchListener: Listeners.PinMismatchListener? = null + private var pinReEnterListener: Listeners.PinReEnterListener? = null + + private val pins = ArrayList() + + constructor(context: Context) : super(context) { + init(null) + } + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { + init(attrs) + } + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(attrs) + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { + init(attrs) + } + + private fun initView() { + val inflater: LayoutInflater = context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + + with(inflater.inflate(R.layout.pin_code_view_layout, this)) { + pinLayout = findViewById(R.id.pin_layout) as LinearLayout + invisibleEditText = findViewById(R.id.invisible_edittext) as AppCompatEditText + } + } + + private fun parseAttributes(attrs: AttributeSet?) { + innerCircleColor = Color.WHITE + outerCircleColor = ContextCompat.getColor(context, R.color.primary_dark) + errorColor = ContextCompat.getColor(context, R.color.accent) + pinCount = 4 + lockType = LockType.UNLOCK + innerAlpha = 0.3f + + if (attrs == null) + return + + with(context.obtainStyledAttributes(attrs, R.styleable.PinCodeView)) { + innerCircleColor = getColor(R.styleable.PinCodeView_pcv_pin_inner_color, innerCircleColor) + outerCircleColor = getColor(R.styleable.PinCodeView_pcv_pin_outer_color, outerCircleColor) + errorColor = getColor(R.styleable.PinCodeView_pcv_pin_error_color, errorColor) + pinCount = getInteger(R.styleable.PinCodeView_pcv_pin_length, pinCount) + innerAlpha = getFloat(R.styleable.PinCodeView_pcv_pin_inner_alpha, innerAlpha) + tintInner = getBoolean(R.styleable.PinCodeView_pcv_pin_tint_inner, tintInner) + tintOuter = getBoolean(R.styleable.PinCodeView_pcv_pin_tint_outer, tintOuter) + + innerDrawable = getDrawable(R.styleable.PinCodeView_pcv_pin_inner_drawable) + innerDrawable?:run { innerDrawable = ContextCompat.getDrawable(context, R.drawable.circle) } + + outerDrawable = getDrawable(R.styleable.PinCodeView_pcv_pin_outer_drawable) + outerDrawable?:run { outerDrawable = ContextCompat.getDrawable(context, R.drawable.circle) } + + when (getInt(R.styleable.PinCodeView_pcv_pin_type, 0)) { + 0 -> lockType = LockType.UNLOCK + 1 -> lockType = LockType.ENTER_PIN + } + + recycle() + } + } + + private fun init(attrs: AttributeSet?) { + initView() + parseAttributes(attrs) + + setUpView() + setUpPins() + } + + private fun setUpPins() { + pins.clear() + pinLayout.removeAllViews() + + if (pinCount <= 0) + return + + for (i in 0 until pinCount) { + val singlePinView = SinglePinView(context).apply { + setColors(innerCircleColor, outerCircleColor) + + layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT) + .apply { + weight = 1f + gravity = Gravity.CENTER_HORIZONTAL + + with(pxFromDp(2f).toInt()) { + setMargins(this, this, this, this) + } + } + + innerPinView.setImageDrawable(innerDrawable) + outerPinView.setImageDrawable(outerDrawable) + + if (!tintInner) + innerPinView.clearColorFilter() + + if (!tintOuter) + outerPinView.clearColorFilter() + + innerPinView.alpha = innerAlpha + } + + with(singlePinView) { + pins.add(this) + pinLayout.addView(this) + } + } + + invisibleEditText.filters = arrayOf(InputFilter.LengthFilter(pinCount)) + } + + private fun setUpView() { + invisibleEditText.onFocusChangeListener = OnFocusChangeListener { v, hasFocus -> + if (hasFocus) { + showDelayedKeyboard(v) + } + } + + invisibleEditText.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + + } + + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + if (pinCount <= 0) + return + + for (pin in pins) { + pin.innerPinView.alpha = innerAlpha + } + + for (i in 0 until s.length) { + pins[i].innerPinView.alpha = 1f + } + + if (lockType == LockType.ENTER_PIN && !pass.isNullOrEmpty() && s.isEmpty()) { + pinReEnterListener?.onPinReEnterStarted() + } + + if (s.length == pinCount) { + pass = s.toString() + + if (lockType == LockType.UNLOCK) { + pinEnteredListener?.onPinEntered(pass) + return + } + + if (pass.isNullOrEmpty()) { + invisibleEditText.text!!.clear() + } else { + if (pass != s.toString()) { + + reset() + + pinMismatchListener?.onPinMismatch() + + return + } + + pinEnteredListener?.onPinEntered(pass) + } + } + } + + override fun afterTextChanged(s: Editable) { + + } + }) + + pinLayout.setOnClickListener(this) + } + + /** + * Reset pin code view with error style + */ + fun reset() { + for (pin in pins) { + pin.innerPinView.setColorFilter(errorColor) + } + + Handler().postDelayed({ + for (pin in pins) { + pin.innerPinView.apply { + if (tintInner) + setColorFilter(innerCircleColor) + else + clearColorFilter() + } + + } + + invisibleEditText.text!!.clear() + }, 500) + } + + /** + * Clear pin code view input + */ + fun clear() { + pass = null + invisibleEditText.text!!.clear() + } + + override fun onClick(v: View) { + val id = v.id + + if (id == R.id.pin_layout) { + with(invisibleEditText) { + clearFocus() + requestFocus() + } + } + } + + /** + * Set type of view logic + * Could be one of + * - LockType.UNLOCK if you need just confirm pin + * - LockType.ENTER_PIN if you want to save pin + * + * @param lockType + */ + fun setLockType(lockType: LockType): PinCodeView { + this.lockType = lockType + this.pass = null + clear() + return this + } + + fun setInnerCircleColor(@ColorInt innerCircleColor: Int): PinCodeView { + this.innerCircleColor = innerCircleColor + setUpPins() + return this + } + + fun setOuterCircleColor(@ColorInt outerCircleColor: Int): PinCodeView { + this.outerCircleColor = outerCircleColor + setUpPins() + return this + } + + fun setErrorColor(@ColorInt errorColor: Int): PinCodeView { + this.errorColor = errorColor + return this + } + + fun setPinLength(pinCount: Int): PinCodeView { + this.pinCount = pinCount + setUpPins() + return this + } + + fun setInnerDrawable(innerDrawable: Drawable): PinCodeView { + this.innerDrawable = innerDrawable + setUpPins() + return this + } + + fun setOuterDrawable(outerDrawable: Drawable): PinCodeView { + this.outerDrawable = outerDrawable + setUpPins() + return this + } + + fun setInnerAlpha(innerAlpha: Float): PinCodeView { + this.innerAlpha = innerAlpha + setUpPins() + return this + } + + fun setTintInner(tintInner: Boolean): PinCodeView { + this.tintInner = tintInner + setUpPins() + return this + } + + fun setTintOuter(tintOuter: Boolean): PinCodeView { + this.tintOuter = tintOuter + setUpPins() + return this + } + + fun setPinEnteredListener(pinEnteredListener: Listeners.PinEnteredListener): PinCodeView { + this.pinEnteredListener = pinEnteredListener + return this + } + + fun setPinMismatchListener(pinMismatchListener: Listeners.PinMismatchListener): PinCodeView { + this.pinMismatchListener = pinMismatchListener + return this + } + + fun setPinReEnterListener(pinReEnterListener: Listeners.PinReEnterListener): PinCodeView { + this.pinReEnterListener = pinReEnterListener + return this + } +} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.java b/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.java deleted file mode 100644 index 2bf86fe..0000000 --- a/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.goldenpie.devs.pincodeview; - -import android.content.Context; -import android.os.Build; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresApi; -import android.support.v7.widget.AppCompatImageView; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.LinearLayout; - -/** - * Created by antoxa2584 on 07.06.17. - */ - -class SinglePinView extends LinearLayout { - private AppCompatImageView outerPinView; - private AppCompatImageView innerPinView; - - public SinglePinView(Context context) { - super(context); - initView(); - } - - public SinglePinView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - initView(); - } - - public SinglePinView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(); - } - - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public SinglePinView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - initView(); - } - - private void initView() { - LayoutInflater inflater; - inflater = (LayoutInflater) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - View mView = inflater.inflate(R.layout.single_pin_view_layout, this); - - outerPinView = (AppCompatImageView) mView.findViewById(R.id.outer_pin_view); - innerPinView = (AppCompatImageView) mView.findViewById(R.id.inner_pin_view); - - outerPinView.setImageResource(R.drawable.circle); - innerPinView.setImageResource(R.drawable.circle); - } - - public void setColors(int innerColor, int outerColor) { - outerPinView.setColorFilter(outerColor); - innerPinView.setColorFilter(innerColor); - } - - public AppCompatImageView getOuterPinView() { - return outerPinView; - } - - public AppCompatImageView getInnerPinView() { - return innerPinView; - } -} diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.kt b/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.kt new file mode 100644 index 0000000..9a54561 --- /dev/null +++ b/library/src/main/java/com/goldenpie/devs/pincodeview/SinglePinView.kt @@ -0,0 +1,52 @@ +package com.goldenpie.devs.pincodeview + +import android.content.Context +import android.os.Build +import android.support.annotation.RequiresApi +import android.support.v7.widget.AppCompatImageView +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.widget.LinearLayout + +internal class SinglePinView : LinearLayout { + lateinit var outerPinView: AppCompatImageView + private set + lateinit var innerPinView: AppCompatImageView + private set + + constructor(context: Context) : super(context) { + initView() + } + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { + initView() + } + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + initView() + } + + @Suppress("unused") + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { + initView() + } + + private fun initView() { + val inflater: LayoutInflater = context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + + with(inflater.inflate(R.layout.single_pin_view_layout, this)) { + outerPinView = findViewById(R.id.outer_pin_view) as AppCompatImageView + innerPinView = findViewById(R.id.inner_pin_view) as AppCompatImageView + } + + listOf(outerPinView, innerPinView).onEach { it.setImageResource(R.drawable.circle) } + } + + fun setColors(innerColor: Int, outerColor: Int) { + outerPinView.setColorFilter(outerColor) + innerPinView.setColorFilter(innerColor) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/LOCK_TYPE.java b/library/src/main/java/com/goldenpie/devs/pincodeview/core/LOCK_TYPE.java deleted file mode 100644 index 578c7e3..0000000 --- a/library/src/main/java/com/goldenpie/devs/pincodeview/core/LOCK_TYPE.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.goldenpie.devs.pincodeview.core; - -public enum LOCK_TYPE { - UNLOCK, ENTER_PIN -} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.java b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.java deleted file mode 100644 index 8f28fb9..0000000 --- a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.goldenpie.devs.pincodeview.core; - -public class Listeners { - public interface PinEnteredListener { - void onPinEntered(String pinCode); - } - - public interface PinMismatchListener { - void onPinMismatch(); - } - - public interface PinReEnterListener { - void onPinReEnterStarted(); - } -} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.kt b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.kt new file mode 100644 index 0000000..0e7437d --- /dev/null +++ b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Listeners.kt @@ -0,0 +1,15 @@ +package com.goldenpie.devs.pincodeview.core + +open class Listeners { + interface PinEnteredListener { + fun onPinEntered(pinCode: String?) + } + + interface PinMismatchListener { + fun onPinMismatch() + } + + interface PinReEnterListener { + fun onPinReEnterStarted() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/LockType.kt b/library/src/main/java/com/goldenpie/devs/pincodeview/core/LockType.kt new file mode 100644 index 0000000..f3c42bc --- /dev/null +++ b/library/src/main/java/com/goldenpie/devs/pincodeview/core/LockType.kt @@ -0,0 +1,5 @@ +package com.goldenpie.devs.pincodeview.core + +enum class LockType { + UNLOCK, ENTER_PIN +} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.ext.kt b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.ext.kt new file mode 100644 index 0000000..d73fc31 --- /dev/null +++ b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.ext.kt @@ -0,0 +1,18 @@ +package com.goldenpie.devs.pincodeview.core + +import android.content.Context +import android.os.Handler +import android.view.View +import android.view.inputmethod.InputMethodManager + +fun View.pxFromDp(dp: Float) = dp * resources.displayMetrics.density + +fun View.showDelayedKeyboard(view: View) = showDelayedKeyboard(view, 100) + +fun View.showDelayedKeyboard(view: View, delay: Int) { + Handler().postDelayed({ + val imm = context.getSystemService( + Context.INPUT_METHOD_SERVICE) as InputMethodManager + imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT) + }, delay.toLong()) +} \ No newline at end of file diff --git a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.java b/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.java deleted file mode 100644 index c023972..0000000 --- a/library/src/main/java/com/goldenpie/devs/pincodeview/core/Utils.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.goldenpie.devs.pincodeview.core; - -import android.content.Context; -import android.os.Handler; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -/** - * Created by antoxa2584 on 07.06.17. - */ - -public class Utils { - public static float pxFromDp(final Context context, final float dp) { - return dp * context.getResources().getDisplayMetrics().density; - } - - public static void showDelayedKeyboard(Context context, View view) { - showDelayedKeyboard(context, view, 100); - } - - public static void showDelayedKeyboard(final Context context, final View view, final int delay) { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - InputMethodManager imm = (InputMethodManager) context.getSystemService( - Context.INPUT_METHOD_SERVICE); - imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); - } - }, delay); - } -}