From ac16acc94397b5650a96276aa2a6842b37b83f09 Mon Sep 17 00:00:00 2001 From: "kewl.apps.dev1" Date: Thu, 14 Nov 2019 12:54:18 +0500 Subject: [PATCH] added OnConfigurationChangedListener --- .../java/com/gamemalt/pinview/PinView.java | 66 ++++++++++++------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/pinview/src/main/java/com/gamemalt/pinview/PinView.java b/pinview/src/main/java/com/gamemalt/pinview/PinView.java index 9ff1fe8..3d80cd1 100644 --- a/pinview/src/main/java/com/gamemalt/pinview/PinView.java +++ b/pinview/src/main/java/com/gamemalt/pinview/PinView.java @@ -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; @@ -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) { @@ -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); @@ -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; @@ -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); } @@ -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); + } }