Skip to content

Commit

Permalink
text color added
Browse files Browse the repository at this point in the history
  • Loading branch information
darshan-miskin committed Mar 31, 2020
1 parent f6203d7 commit c134937
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
// pinView.setPinSize(20);
pinView.setPinTextSize(13);
pinView.setPasswordToggleSize(20);
// pinView.setTextColor(getResources().getColor(R.color.colorPrimary));


pinView.setOnPinCompletionListener(new OnPinCompletedListener() {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
android:id="@+id/pinview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textColor="@color/colorAccent"
app:cursorColor="@color/colorPrimary"
app:pinCount="5"
app:inputType="number"
app:isPassword="false"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.6.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
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 @@
#Sun Sep 15 14:26:25 IST 2019
#Tue Mar 31 14:45:36 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
61 changes: 58 additions & 3 deletions pinview/src/main/java/com/gne/www/lib/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.TypedArray;
import androidx.databinding.InverseBindingMethod;
import androidx.databinding.InverseBindingMethods;

import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.appcompat.widget.LinearLayoutCompat;
Expand All @@ -16,8 +18,10 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


import java.lang.reflect.Field;
import java.util.ArrayList;


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

if(a.hasValue(R.styleable.PinView_pinBackground)){
background=a.getDrawable(R.styleable.PinView_pinBackground);
Expand Down Expand Up @@ -114,6 +122,8 @@ private void addPins(){
getResources().getDimensionPixelSize(R.dimen.margin_pin_edit_text),getResources().getDimensionPixelSize(R.dimen.margin_pin_edit_text));
editText.setLayoutParams(layoutParams);
editText.setTextSize(pinTextSize);
editText.setTextColor(pinTextColor);
// setCursorColor(editText,pinCursorColor);
editText.setMaxLines(1);
editText.setLines(1);
editText.setPadding(0,0,0,0);
Expand Down Expand Up @@ -391,6 +401,28 @@ public void setPinTextSize(float textSize){
}
}

/**
* Text color of the pins
* @param textColor
*/
public void setTextColor(int textColor){
pinTextColor=textColor;
for (int i=0; i<getPinCount(); i++){
editTextsArrayList.get(i).setTextColor(pinTextColor);
}
}

/**
* Cursor color of the pins
* @param cursorColor
*/
// public void setCursorColor(int cursorColor){
// pinCursorColor=cursorColor;
// for (int i=0; i<getPinCount(); i++){
// setCursorColor(editTextsArrayList.get(i),pinCursorColor);
// }
// }

/**
* Size of the toggle view
* @param toggleSize size in pixels
Expand Down Expand Up @@ -419,5 +451,28 @@ public void setPasswordToggleColor(int color){
}
}


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);
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) {
}
}
}
2 changes: 2 additions & 0 deletions pinview/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<attr name="pinTextSize" format="dimension"/>
<attr name="passwordToggleSize" format="dimension"/>
<attr name="passwordToggleColor" format="color"/>
<attr name="textColor" format="color"/>
<!-- <attr name="cursorColor" format="color"/>-->
<attr name="pinSize" format="dimension"/>
</declare-styleable>
</resources>

0 comments on commit c134937

Please sign in to comment.