Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a5f747c
Updated libs and android target
arberg Oct 29, 2021
33389b1
editTextList as non-nullable list
arberg Oct 29, 2021
1a445c9
Fix null-bug, when pinLength=0 (introduced in kotlin-migration)
arberg Oct 29, 2021
5c9bb31
Avoid AndroidManifest.xml warning/error due to missing exported
arberg Oct 29, 2021
d960dc9
AndroidManifest.xml cleanup
arberg Oct 29, 2021
a29d50f
Added ability to set Typeface (Font)
arberg Oct 29, 2021
572c5a0
Added kotlin-style shorthand for PinViewEventListener
arberg Oct 29, 2021
baadae1
Public openKeyboard and updated java-doc with respect to XML disabled…
arberg Oct 29, 2021
66c028f
Allow textSize to be specified in dp
arberg Oct 29, 2021
9d3cd02
Use TextView instead of EditText, because EditText has bottom offset …
arberg Oct 29, 2021
86e073b
Cleanup params?
arberg Oct 29, 2021
a66a6c7
PinView textView fix
arberg Oct 29, 2021
073cb56
Added autoAdjustWidth parameter: Auto adjust width to available width…
arberg Oct 29, 2021
13530a9
Fix example pinViewListener and added clear
Nov 1, 2021
55455d1
Merge branch 'master' into text-view
Nov 1, 2021
d2e52fa
Removed autoAdjustToSquareFormat and instead auto-adjust pin-height w…
Nov 1, 2021
53cbc8d
Added non-square auto-adjusting example, and moved example into Scrol…
Nov 1, 2021
78aa4ef
Fixed bug in pinview.setValue() introduced in kotlin migration where …
arberg Nov 2, 2021
0234fea
Added TextSize now var with getTextSize. Added listener for changeWid…
arberg Nov 2, 2021
8dbea08
Sample code
arberg Nov 2, 2021
f000780
Open keyboard using non-deprecated method.
arberg Mar 17, 2022
66ebd16
Deprecated methods, broken when targeted API-31
arberg Mar 17, 2022
dc609ae
Merge branch 'master' into text-view
arberg Mar 17, 2022
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.70'
ext.kotlin_version = '1.5.31'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
9 changes: 4 additions & 5 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 31
defaultConfig {
applicationId "com.goodiebag.pinview.example"
minSdkVersion 15
targetSdkVersion 28
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -25,8 +24,8 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.0.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.3.1'
testImplementation 'junit:junit:4.13.2'
implementation project(':pinview')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Expand Down
5 changes: 3 additions & 2 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
55 changes: 45 additions & 10 deletions example/src/main/java/com/goodiebag/pinview/example/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
package com.goodiebag.pinview.example

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import com.goodiebag.pinview.Pinview
import com.goodiebag.pinview.Pinview.PinViewEventListener

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val scaledDensity = resources.displayMetrics.scaledDensity

setContentView(R.layout.activity_main)
val pinViews = listOf<Pinview>(
findViewById(R.id.pinview0),
findViewById(R.id.pinview1),
findViewById(R.id.pinview2),
findViewById(R.id.pinview3),
findViewById(R.id.pinview4),
findViewById(R.id.pinview5),
findViewById(R.id.pinview6),
findViewById(R.id.pinview7),
)
findViewById<Button>(R.id.clearButton).setOnClickListener {
pinViews.forEach { it.value = "" }
pinViews[0].requestPinEntryFocus() // Reopen keyboard on first pin
}

val pinview1 = findViewById<Pinview>(R.id.pinview1)
pinview1.setPinViewEventListener(object : PinViewEventListener {
override fun onDataEntered(pinview: Pinview?, fromUser: Boolean) {
Toast.makeText(this@MainActivity, pinview!!.value, Toast.LENGTH_SHORT).show()
}
})
val pinview0 = pinViews[0]
pinview0.setPinViewEventListener { pinview: Pinview, fromUser: Boolean ->
Toast.makeText(this@MainActivity, pinview.value, Toast.LENGTH_SHORT).show()
}
setFont(pinview0)
pinview0.setTextPadding(0, (4 * scaledDensity).toInt(), 0, 0)

// pinView Customize
val pinview5 = findViewById<Pinview>(R.id.pinview5)
pinview5.apply {
pinViews[4].apply {
setCursorShape(R.drawable.example_cursor)
//setCursorColor(Color.BLUE);
setTextSize(12)
textSize = 12
setTextColor(Color.BLACK)
showCursor(true)
}

val widePinview = pinViews[6]
val defaultTextSize = widePinview.textSize
val minTextSizeScalePercentage = resources.getDimension(R.dimen.minimum_text_size) / resources.getDimension(R.dimen.desired_text_size)
// Auto adjust text size for when the Pinview which is wider than screen
widePinview.setPinViewWidthUpdateListener { pinView: Pinview, width: Int ->
// Scale text, but avoid going smaller than a minimum size
val percentDownScaledWidth = (width / pinView.pinWidth.toFloat()).coerceAtLeast(minTextSizeScalePercentage)
pinView.textSize = (defaultTextSize * percentDownScaledWidth).toInt()
}
}

@SuppressLint("NewApi")
private fun setFont(pinview1: Pinview) {
// resources.getFont only available from SDK 26
val typeface = ResourcesCompat.getFont(this, R.font.poppins_semibold)
pinview1.setTypeface(typeface)
}

}
Binary file added example/src/main/res/font/poppins_semibold.ttf
Binary file not shown.
240 changes: 147 additions & 93 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,102 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e1e1e1"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e1e1e1">

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:forceKeyboard="true"
app:hint=""
app:inputType="number"
app:password="false"
app:pinBackground="@drawable/example_drawable_with_grey_disabled"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"/>

<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"/>
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:forceKeyboard="true"
app:hint=""
app:inputType="text"
app:password="false"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number-Password"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:hint="0"
app:inputType="number"
app:password="true"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text-Password"/>
<com.goodiebag.pinview.Pinview
android:id="@+id/pinview0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:forceKeyboard="true"
app:hint=""
app:inputType="number"
app:password="false"
app:pinBackground="@drawable/example_drawable_with_grey_disabled"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"
tools:hint="0" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:hint="0"
app:inputType="text"
app:password="true"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom Pin View"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="text"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"/>
<com.goodiebag.pinview.Pinview
android:id="@+id/pinview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:forceKeyboard="true"
app:hint=""
app:inputType="text"
app:password="false"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Number-Password" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:hint="0"
app:inputType="number"
app:password="true"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text-Password" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cursorVisible="false"
app:hint="0"
app:inputType="text"
app:password="true"
app:pinBackground="@drawable/example_drawable"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"
app:textSize="9sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom Pin View (with dp textSize)" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="text"
app:pinHeight="40dp"
app:pinLength="4"
app:pinWidth="40dp"
app:textSize="18dp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Auto adjusting width and to fit, and height to square" />

<!-- pinHeight 0dp means set height equal to width. Width is auto-adjusted if pin is too wide to fit screen by default, see Pinview.autoAdjustWidth -->
<com.goodiebag.pinview.Pinview
android:id="@+id/pinview5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="text"
app:pinHeight="0dp"
app:pinLength="4"
app:pinWidth="40dp"
app:textSize="@dimen/desired_text_size" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="text"
app:pinHeight="0dp"
app:pinLength="8"
app:pinWidth="40dp"
app:textSize="@dimen/desired_text_size" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Auto adjusting width, but keep fixed height (note we don't auto-adjust text-size)" />

<com.goodiebag.pinview.Pinview
android:id="@+id/pinview7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="text"
app:pinHeight="40dp"
app:pinLength="8"
app:pinWidth="40dp" />

</LinearLayout>
<Button
android:id="@+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="clear all" />
</LinearLayout>
</ScrollView>
3 changes: 3 additions & 0 deletions example/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

<dimen name="desired_text_size">22dp</dimen>
<dimen name="minimum_text_size">12dp</dimen>
</resources>
Loading