diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 7bfef59..37a7509 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ed395ff..f57f9b7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,8 +13,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" - app:buttonTextColor="#FFEB3B" + app:buttonTextColor="#000000" + + app:buttonAutoSizeStepGranularity="1" + app:buttonTextSize="30" + + app:minButtonTextSize="10" + app:maxButtonTextSize="30" + app:isHapticFeedBack="true" app:buttonOkBackground="@drawable/v_tick" app:buttonClearBackground="@drawable/v_back" /> diff --git a/pinview/src/main/java/com/gamemalt/pinview/PinView.java b/pinview/src/main/java/com/gamemalt/pinview/PinView.java index ca0ab4b..9ff1fe8 100644 --- a/pinview/src/main/java/com/gamemalt/pinview/PinView.java +++ b/pinview/src/main/java/com/gamemalt/pinview/PinView.java @@ -5,12 +5,16 @@ import android.graphics.Color; import android.graphics.PorterDuff; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.HapticFeedbackConstants; import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.core.widget.TextViewCompat; + import java.util.Arrays; import java.util.Collections; @@ -27,6 +31,10 @@ public class PinView extends LinearLayout { private int buttonTextColor; private int buttonTextSize; + private int minButtonTextSize; + private int maxButtonTextSize; + + private int autoSizeStepGranularity; private ImageButton buttonClear; private ImageButton buttonOk; @@ -66,7 +74,14 @@ private void setDefaultAttr(AttributeSet attrs) { buttonOkBackground = typedArray.getResourceId(R.styleable.PinView_buttonOkBackground, R.drawable.v_tick); pinButtonBackground = typedArray.getResourceId(R.styleable.PinView_pinButtonBackground, android.R.color.transparent); buttonTextColor = typedArray.getColor(R.styleable.PinView_buttonTextColor, Color.WHITE); + buttonTextSize = typedArray.getInt(R.styleable.PinView_buttonTextSize, 24); + + minButtonTextSize= typedArray.getInt(R.styleable.PinView_minButtonTextSize, -1); + maxButtonTextSize= typedArray.getInt(R.styleable.PinView_maxButtonTextSize, -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); showClearButton = typedArray.getBoolean(R.styleable.PinView_showClearButton, true); @@ -141,8 +156,7 @@ private void findAllViews() { } setPinButtonTextColor(buttonTextColor); - setPinButtonTextSize(buttonTextSize); - + checkAndSetButtonTextSize(); } @@ -215,6 +229,20 @@ public void setPinButtonTextColor(int pinButtonTextColor) { } + private void checkAndSetButtonTextSize(){ + if(minButtonTextSize<0 || maxButtonTextSize<0){ + + setPinButtonTextSize(buttonTextSize); + }else { + setPinButtonAutoTextSize(minButtonTextSize,maxButtonTextSize,autoSizeStepGranularity); + } + } + + + /* + * Sets button text + * size in SP + * */ public void setPinButtonTextSize(int pinButtonTextSize) { buttonTextSize = pinButtonTextSize; @@ -223,6 +251,22 @@ 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; + + for (TextView button : pinButtons) { + TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(button,minSize,maxSize,autoSizeStepGranularity, TypedValue.COMPLEX_UNIT_SP); + } + + + } + /* * Provide resource ID diff --git a/pinview/src/main/res/layout/pin_view.xml b/pinview/src/main/res/layout/pin_view.xml index d31c51d..f2fc1a1 100644 --- a/pinview/src/main/res/layout/pin_view.xml +++ b/pinview/src/main/res/layout/pin_view.xml @@ -13,7 +13,7 @@ android:weightSum="3"> - - - - - - - - - - + + + + +