From 009472a6b76acbada07163b57ac2c807096b5e25 Mon Sep 17 00:00:00 2001 From: farshidroohi Date: Thu, 16 May 2019 12:59:47 +0430 Subject: [PATCH 1/3] update gradle and target sdk version --- build.gradle | 4 +++- example/build.gradle | 15 +++++++-------- gradle/wrapper/gradle-wrapper.properties | 4 ++-- pinview/build.gradle | 13 ++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index c2eea8e..7487467 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +16,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/example/build.gradle b/example/build.gradle index 480a3e5..8d93651 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 28 defaultConfig { applicationId "com.goodiebag.pinview.example" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,11 +19,11 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.1.0' - testCompile 'junit:junit:4.12' - compile project(':pinview') + implementation 'com.android.support:appcompat-v7:28.0.0' + testImplementation 'junit:junit:4.12' + implementation project(':pinview') } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 93b54f5..7ef6aa0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 04 13:07:43 IST 2018 +#Thu May 16 12:53:08 IRDT 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-5.1.1-all.zip diff --git a/pinview/build.gradle b/pinview/build.gradle index 296cca7..cdad1ce 100644 --- a/pinview/build.gradle +++ b/pinview/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 28 defaultConfig { minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 3 versionName "1.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -21,10 +20,10 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.1.0' - testCompile 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:28.0.0' + testImplementation 'junit:junit:4.12' } From cd43ec469fcabb27f247c7e04aaa9d6df883eeb1 Mon Sep 17 00:00:00 2001 From: farshidroohi Date: Thu, 16 May 2019 13:43:33 +0430 Subject: [PATCH 2/3] add method set cursor color and drawable shape add method set text Size add method set cursor visibility --- .../pinview/example/MainActivity.java | 15 ++- .../src/main/res/drawable/example_cursor.xml | 15 +++ example/src/main/res/layout/activity_main.xml | 48 +++++--- .../java/com/goodiebag/pinview/Pinview.java | 116 +++++++++++++++--- 4 files changed, 157 insertions(+), 37 deletions(-) create mode 100644 example/src/main/res/drawable/example_cursor.xml diff --git a/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java b/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java index 2f2ac1e..570d494 100644 --- a/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java +++ b/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java @@ -1,22 +1,31 @@ package com.goodiebag.pinview.example; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.widget.Toast; import com.goodiebag.pinview.Pinview; + public class MainActivity extends AppCompatActivity { - private Pinview pinview1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - pinview1= (Pinview) findViewById(R.id.pinview1); + + Pinview pinview1 = findViewById(R.id.pinview1); pinview1.setPinViewEventListener(new Pinview.PinViewEventListener() { @Override public void onDataEntered(Pinview pinview, boolean fromUser) { Toast.makeText(MainActivity.this, pinview.getValue(), Toast.LENGTH_SHORT).show(); } }); + + + // pinView Customize + Pinview pinview5 = findViewById(R.id.pinview5); + pinview5.setCursorShape(R.drawable.example_cursor); +// pinview5.setCursorColor(Color.BLUE); + pinview5.setTextSize(12); + pinview5.showCursor(true); } } diff --git a/example/src/main/res/drawable/example_cursor.xml b/example/src/main/res/drawable/example_cursor.xml new file mode 100644 index 0000000..6358c8b --- /dev/null +++ b/example/src/main/res/drawable/example_cursor.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index d525beb..254eaf0 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -1,38 +1,40 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/activity_main" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="#e1e1e1" + android:orientation="vertical" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingBottom="@dimen/activity_vertical_margin"> + + app:pinWidth="40dp"/> + + app:pinWidth="40dp"/> + + app:pinWidth="40dp"/> + + app:pinWidth="40dp"/> + + + + diff --git a/pinview/src/main/java/com/goodiebag/pinview/Pinview.java b/pinview/src/main/java/com/goodiebag/pinview/Pinview.java index 4375c43..44af77d 100644 --- a/pinview/src/main/java/com/goodiebag/pinview/Pinview.java +++ b/pinview/src/main/java/com/goodiebag/pinview/Pinview.java @@ -22,9 +22,13 @@ of this software and associated documentation files (the "Software"), to deal import android.content.Context; import android.content.res.TypedArray; +import android.graphics.PorterDuff; import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; @@ -37,7 +41,9 @@ of this software and associated documentation files (the "Software"), to deal import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.TextView; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -62,27 +68,27 @@ of this software and associated documentation files (the "Software"), to deal * @author Koushik */ public class Pinview extends LinearLayout implements TextWatcher, View.OnFocusChangeListener, View.OnKeyListener { - private final float DENSITY = getContext().getResources().getDisplayMetrics().density; + private final float DENSITY = getContext().getResources().getDisplayMetrics().density; /** * Attributes */ - private int mPinLength = 4; - private List editTextList = new ArrayList<>(); - private int mPinWidth = 50; - private int mTextSize = 12; - private int mPinHeight = 50; - private int mSplitWidth = 20; - private boolean mCursorVisible = false; - private boolean mDelPressed = false; + private int mPinLength = 4; + private List editTextList = new ArrayList<>(); + private int mPinWidth = 50; + private int mTextSize = 12; + private int mPinHeight = 50; + private int mSplitWidth = 20; + private boolean mCursorVisible = false; + private boolean mDelPressed = false; @DrawableRes - private int mPinBackground = R.drawable.sample_background; - private boolean mPassword = false; - private String mHint = ""; - private InputType inputType = InputType.TEXT; - private boolean finalNumberPin = false; - private PinViewEventListener mListener; - private boolean fromSetValue = false; - private boolean mForceKeyboard = true; + private int mPinBackground = R.drawable.sample_background; + private boolean mPassword = false; + private String mHint = ""; + private InputType inputType = InputType.TEXT; + private boolean finalNumberPin = false; + private PinViewEventListener mListener; + private boolean fromSetValue = false; + private boolean mForceKeyboard = true; public enum InputType { TEXT, NUMBER @@ -100,7 +106,7 @@ public interface PinViewEventListener { View currentFocus = null; - InputFilter filters[] = new InputFilter[1]; + InputFilter[] filters = new InputFilter[1]; LinearLayout.LayoutParams params; @@ -283,7 +289,7 @@ public String getValue() { * @return the current focused pin view. It can be used to open softkeyboard manually. */ public View requestPinEntryFocus() { - int currentTag = Math.max(0, getIndexOfCurrentFocus()); + int currentTag = Math.max(0, getIndexOfCurrentFocus()); EditText currentEditText = editTextList.get(currentTag); if (currentEditText != null) { currentEditText.requestFocus(); @@ -652,4 +658,76 @@ public void setInputType(InputType inputType) { public void setPinViewEventListener(PinViewEventListener listener) { this.mListener = listener; } + + public void showCursor(boolean status) { + mCursorVisible = status; + if (editTextList == null || editTextList.isEmpty()) { + return; + } + for (EditText edt : editTextList) { + edt.setCursorVisible(status); + } + } + + public void setTextSize(int textSize) { + mTextSize = textSize; + if (editTextList == null || editTextList.isEmpty()) { + return; + } + for (EditText edt : editTextList) { + edt.setTextSize(mTextSize); + } + } + + public void setCursorColor(@ColorInt int color) { + + if (editTextList == null || editTextList.isEmpty()) { + return; + } + for (EditText edt : editTextList) { + setCursorColor(edt, color); + } + } + + public void setCursorShape(@DrawableRes int shape) { + + if (editTextList == null || editTextList.isEmpty()) { + return; + } + for (EditText edt : editTextList) { + try { + Field f = TextView.class.getDeclaredField("mCursorDrawableRes"); + f.setAccessible(true); + f.set(edt, shape); + } catch (Exception ignored) { + } + } + } + + private void setCursorColor(EditText view, @ColorInt int color) { + try { + // Get the cursor resource id + Field field = TextView.class.getDeclaredField("mCursorDrawableRes"); + field.setAccessible(true); + int drawableResId = field.getInt(view); + + // Get the editor + field = TextView.class.getDeclaredField("mEditor"); + field.setAccessible(true); + Object editor = field.get(view); + + // Get the drawable and set a color filter + Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId); + if (drawable != null) { + drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + Drawable[] drawables = {drawable, drawable}; + + // Set the drawables + field = editor.getClass().getDeclaredField("mCursorDrawable"); + field.setAccessible(true); + field.set(editor, drawables); + } catch (Exception ignored) { + } + } } From 3ce3690949437b36ae3003892a445d265f4e7c37 Mon Sep 17 00:00:00 2001 From: farshidroohi Date: Thu, 16 May 2019 13:51:23 +0430 Subject: [PATCH 3/3] add method set text color --- .../com/goodiebag/pinview/example/MainActivity.java | 2 ++ .../src/main/java/com/goodiebag/pinview/Pinview.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java b/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java index 570d494..715de7d 100644 --- a/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java +++ b/example/src/main/java/com/goodiebag/pinview/example/MainActivity.java @@ -1,5 +1,6 @@ package com.goodiebag.pinview.example; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; @@ -26,6 +27,7 @@ public void onDataEntered(Pinview pinview, boolean fromUser) { pinview5.setCursorShape(R.drawable.example_cursor); // pinview5.setCursorColor(Color.BLUE); pinview5.setTextSize(12); + pinview5.setTextColor(Color.BLACK); pinview5.showCursor(true); } } diff --git a/pinview/src/main/java/com/goodiebag/pinview/Pinview.java b/pinview/src/main/java/com/goodiebag/pinview/Pinview.java index 44af77d..de6054a 100644 --- a/pinview/src/main/java/com/goodiebag/pinview/Pinview.java +++ b/pinview/src/main/java/com/goodiebag/pinview/Pinview.java @@ -689,6 +689,16 @@ public void setCursorColor(@ColorInt int color) { } } + public void setTextColor(@ColorInt int color) { + + if (editTextList == null || editTextList.isEmpty()) { + return; + } + for (EditText edt : editTextList) { + edt.setTextColor(color); + } + } + public void setCursorShape(@DrawableRes int shape) { if (editTextList == null || editTextList.isEmpty()) {