Skip to content

Commit

Permalink
Architectural changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevalpatel2106 committed Apr 13, 2018
1 parent 5c89bc8 commit 9abc927
Show file tree
Hide file tree
Showing 26 changed files with 1,180 additions and 1,277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
//REQUIRED
patternView.setPatternCell(new CirclePatternCell.Builder(patternView)
.setRadius(R.dimen.pattern_cell_radius)
.setCellColorResource(R.color.colorAccent)
.build());
.setCellColorResource(R.color.colorAccent));

patternView.setAuthenticationListener(new AuthenticationListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ protected void onCreate(Bundle savedInstanceState) {
.setKeyStrokeColorResource(R.color.colorAccent)
.setKeyStrokeWidth(R.dimen.key_stroke_width)
.setKeyTextColorResource(R.color.colorAccent)
.setKeyTextSize(R.dimen.key_text_size)
.build());
.setKeyTextSize(R.dimen.key_text_size));

//Build the desired indicator shape and pass the theme attributes.
//REQUIRED
mPinView.setIndicator(new CircleIndicator.Builder(mPinView)
.setIndicatorRadius(R.dimen.indicator_radius)
.setIndicatorFilledColorResource(R.color.colorAccent)
.setIndicatorStrokeColorResource(R.color.colorAccent)
.setIndicatorStrokeWidth(R.dimen.indicator_stroke_width)
.build());
.setIndicatorStrokeWidth(R.dimen.indicator_stroke_width));

//Set the name of the keys based on your locale.
//OPTIONAL. If not passed key names will be displayed based on english locale.
Expand Down
2 changes: 1 addition & 1 deletion passcodeview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

// This is important, it will run lint checks but won't abort build
// This is important, it will run lint checks but won't abort buildInternal
lintOptions {
abortOnError false
}
Expand Down
2 changes: 1 addition & 1 deletion passcodeview/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# By default, the flags in this file are appended to flags specified
# in C:\Users\Keval\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
# directive in buildInternal.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,70 @@
public abstract class BasePasscodeView extends View implements PasscodeViewLifeCycle {

/**
* Context of the view.
* {@link Context} of the view.
*/
@NonNull
protected final Context mContext;

/**
* Finger print box.
*
* @see BoxFingerprint
*/
@NonNull
private final BoxFingerprint mBoxFingerprint;
/**
* Bounds of the divider between the title and the keypad or the pattern box.
*/
@NonNull
private final Rect mDividerBound = new Rect();
/**
* Bounds of the whole {@link BasePasscodeView}.
*/
@NonNull
protected Rect mRootViewBound = new Rect(); //Bounds for the root view

/**
* A listener to notify the user when the authentication successful or ffailed.
* A listener to notify the user when the authentication successful or failed.
*
* @see AuthenticationListener
*/
protected AuthenticationListener mAuthenticationListener;

/**
* Finger print box.
* Integer color of the divider between title and divider.
*/
private BoxFingerprint mBoxFingerprint; //Fingerprint box

//Title divider
@ColorInt
private int mDividerColor; //Horizontal divider color
private Paint mDividerPaint; //Horizontal divider paint color
private Rect mDividerBound = new Rect(); //Divider bound
private boolean mIsTactileFeedbackEnabled = true; //Bool to indicate weather to enable tactile feedback
private int mDividerColor;
/**
* {@link Paint} of the horizontal divider within the view.
*/
private Paint mDividerPaint;
/**
* Boolean to set true of the tactile feedback on the key is press is enabled or not?
*/
private boolean mIsTactileFeedbackEnabled = true;

///////////////////////////////////////////////////////////////
// CONSTRUCTORS
///////////////////////////////////////////////////////////////

public BasePasscodeView(Context context) {
public BasePasscodeView(@NonNull final Context context) {
super(context);
mContext = context;
mBoxFingerprint = new BoxFingerprint(this);

init(null);
}

public BasePasscodeView(Context context, @Nullable AttributeSet attrs) {
public BasePasscodeView(@NonNull final Context context, @Nullable final AttributeSet attrs) {
super(context, attrs);
mContext = context;
mBoxFingerprint = new BoxFingerprint(this);

init(attrs);
}

public BasePasscodeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public BasePasscodeView(@NonNull final Context context,
@Nullable final AttributeSet attrs,
final int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
mBoxFingerprint = new BoxFingerprint(this);
Expand All @@ -98,7 +113,10 @@ public BasePasscodeView(Context context, @Nullable AttributeSet attrs, int defSt
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public BasePasscodeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
public BasePasscodeView(@NonNull final Context context,
@Nullable final AttributeSet attrs,
final int defStyleAttr,
final int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
mBoxFingerprint = new BoxFingerprint(this);
Expand Down Expand Up @@ -126,9 +144,9 @@ public BasePasscodeView(Context context, @Nullable AttributeSet attrs, int defSt
*
* @param attrs {@link AttributeSet}
*/
private void init(@Nullable AttributeSet attrs) {
private void init(@Nullable final AttributeSet attrs) {
mBoxFingerprint.init();
init();
init(); //Call init for the concrete class

if (attrs != null) { //Parse all the params from the arguments.
TypedArray a = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.BasePasscodeView, 0, 0);
Expand Down Expand Up @@ -188,7 +206,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//Measure the finger print
mBoxFingerprint.measureView(mRootViewBound);

//Pass it to the implementation box
//Pass it to the implementation class
measureView(mRootViewBound);

setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
Expand Down Expand Up @@ -223,10 +241,15 @@ protected void onDraw(Canvas canvas) {
//Draw the finger print box
mBoxFingerprint.drawView(canvas);

//Pass it to the implementation
//Pass it to the implementation class
drawView(canvas);
}

/**
* Draw the divider between title and the keyboard/pin box.
*
* @param canvas {@link Canvas} on which the divider is to draw.
*/
private void drawDivider(Canvas canvas) {
canvas.drawLine(mDividerBound.left,
mDividerBound.top,
Expand All @@ -246,12 +269,18 @@ protected void onDetachedFromWindow() {
@Override
@CallSuper
public void onAuthenticationSuccess() {
if (isTactileFeedbackEnable())
Utils.giveTactileFeedbackForAuthSuccess(mContext); //Give tactile feedback.

if (mAuthenticationListener != null) mAuthenticationListener.onAuthenticationSuccessful();
}

@Override
@CallSuper
public void onAuthenticationFail() {
if (isTactileFeedbackEnable())
Utils.giveTactileFeedbackForAuthFail(mContext); //Give tactile feedback.

if (mAuthenticationListener != null) mAuthenticationListener.onAuthenticationFailed();
}

Expand All @@ -266,7 +295,7 @@ public void reset() {
///////////////////////////////////////////////////////////////


public void setAuthenticationListener(@NonNull AuthenticationListener authenticationListener) {
public void setAuthenticationListener(@NonNull final AuthenticationListener authenticationListener) {
mAuthenticationListener = authenticationListener;
}

Expand All @@ -278,13 +307,13 @@ public int getDividerColor() {
return mDividerColor;
}

public void setDividerColor(@ColorInt int dividerColor) {
public void setDividerColor(@ColorInt final int dividerColor) {
mDividerColor = dividerColor;
prepareDividerPaint();
invalidate();
}

public void setDividerColorRes(@ColorRes int dividerColor) {
public void setDividerColorRes(@ColorRes final int dividerColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setDividerColor(mContext.getColor(dividerColor));
} else {
Expand All @@ -296,7 +325,7 @@ public boolean isTactileFeedbackEnable() {
return mIsTactileFeedbackEnabled;
}

public void setTactileFeedback(boolean enable) {
public void setTactileFeedback(final boolean enable) {
mIsTactileFeedbackEnabled = enable;
}

Expand All @@ -305,7 +334,7 @@ public Boolean isFingerPrintEnable() {
return mBoxFingerprint.isFingerPrintEnable();
}

public void setIsFingerPrintEnable(boolean isEnable) {
public void setIsFingerPrintEnable(final boolean isEnable) {
mBoxFingerprint.setFingerPrintEnable(isEnable);
requestLayout();
invalidate();
Expand All @@ -316,7 +345,7 @@ public String getFingerPrintStatusText() {
return mBoxFingerprint.getStatusText();
}

public void setFingerPrintStatusText(@NonNull String statusText) {
public void setFingerPrintStatusText(@NonNull final String statusText) {
mBoxFingerprint.setStatusText(statusText);
invalidate();
}
Expand All @@ -325,12 +354,12 @@ public int getFingerPrintStatusTextColor() {
return mBoxFingerprint.getStatusTextColor();
}

public void setFingerPrintStatusTextColor(@ColorInt int statusTextColor) {
public void setFingerPrintStatusTextColor(@ColorInt final int statusTextColor) {
mBoxFingerprint.setStatusTextColor(statusTextColor);
invalidate();
}

public void setFingerPrintStatusTextColorRes(@ColorRes int statusTextColor) {
public void setFingerPrintStatusTextColorRes(@ColorRes final int statusTextColor) {
mBoxFingerprint.setStatusTextColor(mContext.getResources().getColor(statusTextColor));
invalidate();
}
Expand All @@ -339,12 +368,12 @@ public float getFingerPrintStatusTextSize() {
return mBoxFingerprint.getStatusTextSize();
}

public void setFingerPrintStatusTextSize(@Dimension float statusTextSize) {
public void setFingerPrintStatusTextSize(@Dimension final float statusTextSize) {
mBoxFingerprint.setStatusTextSize(statusTextSize);
invalidate();
}

public void setFingerPrintStatusTextSize(@DimenRes int statusTextSize) {
public void setFingerPrintStatusTextSize(@DimenRes final int statusTextSize) {
mBoxFingerprint.setStatusTextSize(getResources().getDimension(statusTextSize));
invalidate();
}
Expand Down
Loading

0 comments on commit 9abc927

Please sign in to comment.