@@ -4,6 +4,7 @@ import android.os.Bundle
4
4
import androidx.activity.ComponentActivity
5
5
import androidx.activity.compose.setContent
6
6
import androidx.compose.foundation.BorderStroke
7
+ import androidx.compose.foundation.background
7
8
import androidx.compose.foundation.border
8
9
import androidx.compose.foundation.layout.*
9
10
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -16,6 +17,7 @@ import androidx.compose.runtime.mutableStateOf
16
17
import androidx.compose.runtime.remember
17
18
import androidx.compose.ui.Alignment
18
19
import androidx.compose.ui.Modifier
20
+ import androidx.compose.ui.draw.clip
19
21
import androidx.compose.ui.graphics.Color
20
22
import androidx.compose.ui.unit.dp
21
23
import com.yogeshpaliyal.speld.ui.theme.AndroidComposeOTPViewTheme
@@ -30,7 +32,8 @@ class MainActivity : ComponentActivity() {
30
32
val text = remember { mutableStateOf(" " ) }
31
33
val length = 5 // Define the length of the PIN here
32
34
33
- Column (modifier = Modifier .fillMaxSize(),
35
+ Column (
36
+ modifier = Modifier .fillMaxSize(),
34
37
Arrangement .Center , Alignment .CenterHorizontally
35
38
) {
36
39
@@ -45,10 +48,18 @@ class MainActivity : ComponentActivity() {
45
48
46
49
// Bordered PIN View
47
50
PinInput (
48
- cellModifier = Modifier .border(
49
- BorderStroke (2 .dp, Color .Red ),
50
- shape = RoundedCornerShape (3 .dp)
51
- ), value = text.value,
51
+ cellModifier = Modifier
52
+ .size(width = 45 .dp, height = 45 .dp)
53
+ .clip(MaterialTheme .shapes.large)
54
+ .background(
55
+ MaterialTheme .colors.primary.copy(alpha = 0.1f ),
56
+ shape = RoundedCornerShape (3 .dp)
57
+ )
58
+ .border(
59
+ BorderStroke (2 .dp, Color .Red ),
60
+ shape = RoundedCornerShape (3 .dp)
61
+ ),
62
+ value = text.value,
52
63
obscureText = " *" ,
53
64
length = length, // Use the number defined here
54
65
disableKeypad = true , // Do not open the android keypad
@@ -57,7 +68,7 @@ class MainActivity : ComponentActivity() {
57
68
}
58
69
59
70
Spacer (modifier = Modifier .height(20 .dp))
60
-
71
+
61
72
KeyPad (input = text, length)
62
73
63
74
}
@@ -69,9 +80,9 @@ class MainActivity : ComponentActivity() {
69
80
}
70
81
71
82
@Composable
72
- fun KeyPad (input : MutableState <String >, length : Int ){
73
- val callback = {
74
- text : String -> handleButtonClick(text, input, length)
83
+ fun KeyPad (input : MutableState <String >, length : Int ) {
84
+ val callback = { text : String ->
85
+ handleButtonClick(text, input, length)
75
86
}
76
87
77
88
Column (
@@ -115,7 +126,7 @@ class MainActivity : ComponentActivity() {
115
126
.padding(2 .dp, 2 .dp)
116
127
) {
117
128
for (i in texts.indices) {
118
- val useIcon = texts[i]== " ←"
129
+ val useIcon = texts[i] == " ←"
119
130
MyButton (
120
131
text = texts[i],
121
132
callback = callback,
@@ -155,7 +166,7 @@ class MainActivity : ComponentActivity() {
155
166
contentDescription = " Favorite" ,
156
167
modifier = Modifier .size(ButtonDefaults .IconSize )
157
168
)
158
- }else Text (text)
169
+ } else Text (text)
159
170
}
160
171
}
161
172
@@ -168,8 +179,9 @@ class MainActivity : ComponentActivity() {
168
179
" ←" -> if (inputTextView.value.isNotEmpty()) {
169
180
inputTextView.value = inputTextView.value.dropLast(1 ) // remove last char
170
181
}
182
+
171
183
" C" -> inputTextView.value = " " // clear all text
172
- else -> if (inputTextView.value.length< length) inputTextView.value + = txt // handles key input here
184
+ else -> if (inputTextView.value.length < length) inputTextView.value + = txt // handles key input here
173
185
}
174
186
}
175
187
}
0 commit comments