Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c134937

Browse files
committedMar 31, 2020
text color added
1 parent f6203d7 commit c134937

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed
 

‎app/src/main/java/com/gne/www/pinviewlibrary/MainActivity.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
3232
// pinView.setPinSize(20);
3333
pinView.setPinTextSize(13);
3434
pinView.setPasswordToggleSize(20);
35+
// pinView.setTextColor(getResources().getColor(R.color.colorPrimary));
3536

3637

3738
pinView.setOnPinCompletionListener(new OnPinCompletedListener() {

‎app/src/main/res/layout/activity_main.xml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
android:id="@+id/pinview"
1111
android:layout_width="match_parent"
1212
android:layout_height="wrap_content"
13+
app:textColor="@color/colorAccent"
14+
app:cursorColor="@color/colorPrimary"
1315
app:pinCount="5"
1416
app:inputType="number"
1517
app:isPassword="false"

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77

88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.0'
10+
classpath 'com.android.tools.build:gradle:3.6.1'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Sep 15 14:26:25 IST 2019
1+
#Tue Mar 31 14:45:36 IST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

‎pinview/src/main/java/com/gne/www/lib/PinView.java

+58-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import android.content.ClipboardManager;
44
import android.content.Context;
55
import android.content.res.TypedArray;
6-
import androidx.databinding.InverseBindingMethod;
7-
import androidx.databinding.InverseBindingMethods;
6+
7+
import androidx.annotation.ColorInt;
8+
import androidx.core.content.ContextCompat;
9+
810
import android.graphics.PorterDuff;
911
import android.graphics.drawable.Drawable;
1012
import androidx.appcompat.widget.LinearLayoutCompat;
@@ -16,8 +18,10 @@
1618
import android.view.MenuItem;
1719
import android.view.View;
1820
import android.widget.EditText;
21+
import android.widget.TextView;
1922

2023

24+
import java.lang.reflect.Field;
2125
import java.util.ArrayList;
2226

2327

@@ -30,6 +34,8 @@ public class PinView extends LinearLayoutCompat {
3034
private int pinSize =getResources().getDimensionPixelSize(R.dimen.pin_size), passwordToggleSize=getResources().getDimensionPixelSize(R.dimen.password_toggle_size);
3135
private int passwordToggleColor=getResources().getColor(android.R.color.black);
3236
private float pinTextSize=DEFAULT_PIN_TEXT_SIZE;
37+
private int pinTextColor=getResources().getColor(android.R.color.black);
38+
// private int pinCursorColor =getResources().getColor(android.R.color.holo_orange_dark);
3339
private short pinCount=DEFAULT_PIN_COUNT, inputType= com.gne.www.lib.InputType.TYPE_NUMBER;
3440
private boolean isPassword=false, showPasswordToggle=false, isToggleAdded=false;
3541
private Drawable background;
@@ -78,6 +84,8 @@ private void setStyleAndPins(AttributeSet attrs){
7884
pinTextSize =a.getDimension(R.styleable.PinView_pinTextSize,DEFAULT_PIN_TEXT_SIZE);
7985
passwordToggleSize =a.getDimensionPixelSize(R.styleable.PinView_passwordToggleSize,passwordToggleSize);
8086
passwordToggleColor =a.getColor(R.styleable.PinView_passwordToggleColor,passwordToggleColor);
87+
pinTextColor =a.getColor(R.styleable.PinView_textColor,pinTextColor);
88+
// pinCursorColor =a.getColor(R.styleable.PinView_cursorColor,pinCursorColor);
8189

8290
if(a.hasValue(R.styleable.PinView_pinBackground)){
8391
background=a.getDrawable(R.styleable.PinView_pinBackground);
@@ -114,6 +122,8 @@ private void addPins(){
114122
getResources().getDimensionPixelSize(R.dimen.margin_pin_edit_text),getResources().getDimensionPixelSize(R.dimen.margin_pin_edit_text));
115123
editText.setLayoutParams(layoutParams);
116124
editText.setTextSize(pinTextSize);
125+
editText.setTextColor(pinTextColor);
126+
// setCursorColor(editText,pinCursorColor);
117127
editText.setMaxLines(1);
118128
editText.setLines(1);
119129
editText.setPadding(0,0,0,0);
@@ -391,6 +401,28 @@ public void setPinTextSize(float textSize){
391401
}
392402
}
393403

404+
/**
405+
* Text color of the pins
406+
* @param textColor
407+
*/
408+
public void setTextColor(int textColor){
409+
pinTextColor=textColor;
410+
for (int i=0; i<getPinCount(); i++){
411+
editTextsArrayList.get(i).setTextColor(pinTextColor);
412+
}
413+
}
414+
415+
/**
416+
* Cursor color of the pins
417+
* @param cursorColor
418+
*/
419+
// public void setCursorColor(int cursorColor){
420+
// pinCursorColor=cursorColor;
421+
// for (int i=0; i<getPinCount(); i++){
422+
// setCursorColor(editTextsArrayList.get(i),pinCursorColor);
423+
// }
424+
// }
425+
394426
/**
395427
* Size of the toggle view
396428
* @param toggleSize size in pixels
@@ -419,5 +451,28 @@ public void setPasswordToggleColor(int color){
419451
}
420452
}
421453

422-
454+
private void setCursorColor(EditText view, @ColorInt int color) {
455+
try {
456+
// Get the cursor resource id
457+
Field field = TextView.class.getDeclaredField("mCursorDrawableRes");
458+
field.setAccessible(true);
459+
int drawableResId = field.getInt(view);
460+
461+
// Get the editor
462+
field = TextView.class.getDeclaredField("mEditor");
463+
field.setAccessible(true);
464+
Object editor = field.get(view);
465+
466+
// Get the drawable and set a color filter
467+
Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId);
468+
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
469+
Drawable[] drawables = {drawable, drawable};
470+
471+
// Set the drawables
472+
field = editor.getClass().getDeclaredField("mCursorDrawable");
473+
field.setAccessible(true);
474+
field.set(editor, drawables);
475+
} catch (Exception ignored) {
476+
}
477+
}
423478
}

‎pinview/src/main/res/values/attr.xml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<attr name="pinTextSize" format="dimension"/>
1717
<attr name="passwordToggleSize" format="dimension"/>
1818
<attr name="passwordToggleColor" format="color"/>
19+
<attr name="textColor" format="color"/>
20+
<!-- <attr name="cursorColor" format="color"/>-->
1921
<attr name="pinSize" format="dimension"/>
2022
</declare-styleable>
2123
</resources>

0 commit comments

Comments
 (0)
Failed to load comments.