Skip to content

Commit

Permalink
added OnConfigurationChangedListener
Browse files Browse the repository at this point in the history
  • Loading branch information
kewl.apps.dev1 committed Nov 14, 2019
1 parent 1dc64d5 commit ac16acc
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions pinview/src/main/java/com/gamemalt/pinview/PinView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gamemalt.pinview;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class PinView extends LinearLayout {

private TextView[] pinButtons = new TextView[10];
boolean isEnabled = true;
private OnConfigurationChangedListener onConfigurationChangedListener;


public PinView(Context context) {
Expand Down Expand Up @@ -77,10 +79,10 @@ private void setDefaultAttr(AttributeSet attrs) {

buttonTextSize = typedArray.getInt(R.styleable.PinView_buttonTextSize, 24);

minButtonTextSize= typedArray.getInt(R.styleable.PinView_minButtonTextSize, -1);
maxButtonTextSize= typedArray.getInt(R.styleable.PinView_maxButtonTextSize, -1);
minButtonTextSize = typedArray.getInt(R.styleable.PinView_minButtonTextSize, -1);
maxButtonTextSize = typedArray.getInt(R.styleable.PinView_maxButtonTextSize, -1);

autoSizeStepGranularity= typedArray.getInt(R.styleable.PinView_buttonAutoSizeStepGranularity, 1);
autoSizeStepGranularity = typedArray.getInt(R.styleable.PinView_buttonAutoSizeStepGranularity, 1);

isHapticFeedBack = typedArray.getBoolean(R.styleable.PinView_isHapticFeedBack, false);
showOkButton = typedArray.getBoolean(R.styleable.PinView_showOkButton, true);
Expand Down Expand Up @@ -229,20 +231,20 @@ public void setPinButtonTextColor(int pinButtonTextColor) {
}


private void checkAndSetButtonTextSize(){
if(minButtonTextSize<0 || maxButtonTextSize<0){
private void checkAndSetButtonTextSize() {
if (minButtonTextSize < 0 || maxButtonTextSize < 0) {

setPinButtonTextSize(buttonTextSize);
}else {
setPinButtonAutoTextSize(minButtonTextSize,maxButtonTextSize,autoSizeStepGranularity);
} else {
setPinButtonAutoTextSize(minButtonTextSize, maxButtonTextSize, autoSizeStepGranularity);
}
}


/*
* Sets button text
* size in SP
* */
* Sets button text
* size in SP
* */
public void setPinButtonTextSize(int pinButtonTextSize) {
buttonTextSize = pinButtonTextSize;

Expand All @@ -252,16 +254,16 @@ public void setPinButtonTextSize(int pinButtonTextSize) {
}

/*
* Sets auto text size automatically within the range of given min and max sizes
* Size is in SP
* */
public void setPinButtonAutoTextSize(int minSize,int maxSize,int autoSizeStepGranularity){
this.minButtonTextSize=minSize;
this.maxButtonTextSize=maxSize;
this.autoSizeStepGranularity=autoSizeStepGranularity;
* Sets auto text size automatically within the range of given min and max sizes
* Size is in SP
* */
public void setPinButtonAutoTextSize(int minSize, int maxSize, int autoSizeStepGranularity) {
this.minButtonTextSize = minSize;
this.maxButtonTextSize = maxSize;
this.autoSizeStepGranularity = autoSizeStepGranularity;

for (TextView button : pinButtons) {
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(button,minSize,maxSize,autoSizeStepGranularity, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(button, minSize, maxSize, autoSizeStepGranularity, TypedValue.COMPLEX_UNIT_SP);
}


Expand Down Expand Up @@ -296,13 +298,33 @@ public void setPinViewEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}

public void setShowOkButton(boolean shouldShow){
showOkButton=shouldShow;
public void setShowOkButton(boolean shouldShow) {
showOkButton = shouldShow;
buttonOk.setVisibility(shouldShow ? VISIBLE : INVISIBLE);
}
public void setShowClearButton(boolean shouldShow){
showClearButton=shouldShow;

public void setShowClearButton(boolean shouldShow) {
showClearButton = shouldShow;
buttonClear.setVisibility(shouldShow ? VISIBLE : INVISIBLE);
}


@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

if (onConfigurationChangedListener != null)
onConfigurationChangedListener.onConfigurationChanged(newConfig);


}

public void setOnConfigurationChangedListener(OnConfigurationChangedListener onConfigurationChangedListener) {
this.onConfigurationChangedListener = onConfigurationChangedListener;

}

public interface OnConfigurationChangedListener {
void onConfigurationChanged(Configuration newConfig);
}
}

0 comments on commit ac16acc

Please sign in to comment.