Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented possibility to highlight filled items #37

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 3 additions & 3 deletions pinview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'

implementation "com.android.support:appcompat-v7:28.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use androidx.

implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constraint-layout is not needed in pinview module.

testImplementation 'junit:junit:4.12'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

apply from: 'publish.gradle'
2 changes: 1 addition & 1 deletion pinview/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def issueUrl = 'https://github.com/ChaosLeong/PinView/issues'
def gitUrl = '[email protected]:ChaosLeong/PinView.git'

group = "com.chaos.view"
version = "1.4.2"
version = "1.4.6"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to change the library version.


install {
repositories.mavenInstaller {
Expand Down
25 changes: 14 additions & 11 deletions pinview/src/main/java/com/chaos/view/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.Px;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.InputFilter;
import android.text.TextPaint;
import android.text.TextUtils;
Expand All @@ -40,14 +48,6 @@
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.ViewCompat;

/**
* Provides a widget for enter PIN/OTP/password etc.
*
Expand Down Expand Up @@ -109,6 +109,7 @@ public class PinView extends AppCompatEditText {
private Drawable mItemBackground;

private boolean mHideLineWhenFilled;
private boolean mHighlightLineWhenFilled;

public PinView(Context context) {
this(context, null);
Expand Down Expand Up @@ -151,6 +152,7 @@ public PinView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)

mItemBackground = a.getDrawable(R.styleable.PinView_android_itemBackground);
mHideLineWhenFilled = a.getBoolean(R.styleable.PinView_hideLineWhenFilled, false);
mHighlightLineWhenFilled = a.getBoolean(R.styleable.PinView_highlightLineWhenFilled, false);

a.recycle();

Expand Down Expand Up @@ -325,7 +327,8 @@ private void drawPinView(Canvas canvas) {
int highlightIdx = getText().length();
for (int i = 0; i < mPinItemCount; i++) {
boolean highlight = isFocused() && highlightIdx == i;
mPaint.setColor(highlight ? getLineColorForState(HIGHLIGHT_STATES) : mCurLineColor);

mPaint.setColor(highlight || (mHighlightLineWhenFilled && i < highlightIdx) ? getLineColorForState(HIGHLIGHT_STATES) : mCurLineColor);

updateItemRectF(i);
updateCenterPoint();
Expand Down Expand Up @@ -654,7 +657,7 @@ protected MovementMethod getDefaultMovementMethod() {
*
* @param color A color value in the form 0xAARRGGBB.
* Do not pass a resource ID. To get a color value from a resource ID, call
* {@link androidx.core.content.ContextCompat#getColor(Context, int) getColor}.
* {@link ContextCompat#getColor(Context, int) getColor}.
* @attr ref R.styleable#PinView_lineColor
* @see #setLineColor(ColorStateList)
* @see #getLineColors()
Expand Down Expand Up @@ -927,7 +930,7 @@ public int getCursorWidth() {
*
* @param color A color value in the form 0xAARRGGBB.
* Do not pass a resource ID. To get a color value from a resource ID, call
* {@link androidx.core.content.ContextCompat#getColor(Context, int) getColor}.
* {@link ContextCompat#getColor(Context, int) getColor}.
* @attr ref R.styleable#PinView_cursorColor
* @see #getCursorColor()
*/
Expand Down
1 change: 1 addition & 0 deletions pinview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<attr name="cursorColor" format="reference|color" />
<attr name="android:itemBackground" />
<attr name="hideLineWhenFilled" format="boolean" />
<attr name="highlightLineWhenFilled" format="boolean" />
</declare-styleable>
</resources>
6 changes: 2 additions & 4 deletions simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.android.support:appcompat-v7:28.0.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as mentioned above.

implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused library.


testImplementation 'junit:junit:4.12'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

implementation project(':pinview')
}
5 changes: 2 additions & 3 deletions simple/src/main/java/com/chaos/view/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
Expand All @@ -27,9 +29,6 @@

import com.chaos.view.PinView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package com.chaos.view.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.chaos.view.PinView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
* @author Chaos Leong
* 07/04/2017
Expand Down