1919import androidx .biometric .BiometricManager ;
2020import androidx .biometric .BiometricPrompt ;
2121import androidx .core .content .ContextCompat ;
22+ import androidx .core .content .res .ResourcesCompat ;
23+ import androidx .recyclerview .widget .GridLayoutManager ;
2224
2325import com .bitflaker .lucidsourcekit .data .datastore .DataStoreKeys ;
2426import com .bitflaker .lucidsourcekit .data .datastore .DataStoreManager ;
4749import com .bitflaker .lucidsourcekit .databinding .ActivityMainBinding ;
4850import com .bitflaker .lucidsourcekit .main .MainViewer ;
4951import com .bitflaker .lucidsourcekit .main .alarms .AlarmHandler ;
52+ import com .bitflaker .lucidsourcekit .main .notification .visual .KeypadAdapter ;
53+ import com .bitflaker .lucidsourcekit .main .notification .visual .KeypadButtonModel ;
5054import com .bitflaker .lucidsourcekit .setup .SetupViewer ;
5155import com .bitflaker .lucidsourcekit .utils .Crypt ;
5256import com .bitflaker .lucidsourcekit .utils .Tools ;
5660
5761import java .io .File ;
5862import java .util .ArrayList ;
63+ import java .util .Arrays ;
5964import java .util .Calendar ;
6065import java .util .GregorianCalendar ;
6166import java .util .List ;
6267import java .util .TimeZone ;
6368import java .util .concurrent .Executor ;
6469import java .util .concurrent .TimeUnit ;
70+ import java .util .stream .Collectors ;
6571
6672import io .reactivex .rxjava3 .core .Maybe ;
73+ import kotlin .Unit ;
6774
6875public class MainActivity extends AppCompatActivity {
6976 private final char [] pinLayout = new char [] { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ' ' , '0' , '<' };
@@ -75,6 +82,11 @@ public class MainActivity extends AppCompatActivity {
7582
7683 @ Override
7784 protected void onCreate (Bundle savedInstanceState ) {
85+ DataStoreManager .initialize (this );
86+ DataStoreMigrator .migrateSharedPreferencesToDataStore (this );
87+ DataStoreMigrator .migrateSetupFinishedToDataStore (this );
88+ Tools .loadLanguage (this );
89+
7890 // TODO: remove enforce dark mode
7991 AppCompatDelegate .setDefaultNightMode (AppCompatDelegate .MODE_NIGHT_YES );
8092 int currentNightMode = getResources ().getConfiguration ().uiMode & Configuration .UI_MODE_NIGHT_MASK ;
@@ -91,19 +103,11 @@ protected void onCreate(Bundle savedInstanceState) {
91103 super .onCreate (savedInstanceState );
92104 binding = ActivityMainBinding .inflate (getLayoutInflater ());
93105 setContentView (binding .getRoot ());
94-
95- DataStoreManager .initialize (this );
96- DataStoreMigrator .migrateSharedPreferencesToDataStore (this );
97- DataStoreMigrator .migrateSetupFinishedToDataStore (this );
98-
99- Tools .loadLanguage (MainActivity .this );
100106 Tools .makeStatusBarTransparent (MainActivity .this );
101107
102108 binding .btnFingerprintUnlock .setOnClickListener (e -> startBiometricAuthentication ());
103109 pinButtonSize = getResources ().getBoolean (R .bool .is_h720dp ) ? 68 : 54 ;
104110
105- // TODO: set language of controls
106-
107111 Calendar cldrStored = new GregorianCalendar (TimeZone .getDefault ());
108112 Calendar cldrNow = new GregorianCalendar (TimeZone .getDefault ());
109113 cldrNow .setTime (Calendar .getInstance ().getTime ());
@@ -340,38 +344,34 @@ public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationRes
340344 private void setupPinAuthentication () {
341345 binding .llPwAuthContainer .setVisibility (View .GONE );
342346 binding .llPinAuthContainer .setVisibility (View .VISIBLE );
343- for (int y = 0 ; y < 4 ; y ++) {
344- FlexboxLayout hFlxBx = new FlexboxLayout (this );
345- hFlxBx .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
346- hFlxBx .setJustifyContent (JustifyContent .SPACE_AROUND );
347- for (int x = 0 ; x < 3 ; x ++) {
348- hFlxBx .addView (generatePinButton (y *3 +x ));
349- }
350- binding .llPinLayout .addView (hFlxBx );
351- }
352- }
353347
354- private View generatePinButton (int pos ) {
355- MaterialButton pinButton = new MaterialButton (this );
356- char currentType = pinLayout [pos ];
357- LinearLayout .LayoutParams lParams = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT );
358- pinButton .setLayoutParams (lParams );
359- pinButton .setMinimumHeight (Tools .dpToPx (this , pinButtonSize ));
360- pinButton .setMinimumWidth (Tools .dpToPx (this , pinButtonSize ));
361- pinButton .setMinHeight (Tools .dpToPx (this , pinButtonSize ));
362- pinButton .setMinWidth (Tools .dpToPx (this , pinButtonSize ));
363- pinButton .setHeight (Tools .dpToPx (this , pinButtonSize ));
364- pinButton .setWidth (Tools .dpToPx (this , pinButtonSize ));
365- pinButton .setPadding (0 ,0 ,0 ,0 );
366- pinButton .setTextColor (Tools .getAttrColor (R .attr .primaryTextColor , getTheme ()));
367- pinButton .setTextSize (TypedValue .COMPLEX_UNIT_SP , 30 );
368- pinButton .setBackgroundResource (R .drawable .ripple_round_clear );
369- if (Character .isDigit (currentType )) {
370- pinButton .setText (Character .toString (currentType ));
371- int buttonVal = Integer .parseInt (Character .toString (currentType ));
372- pinButton .setOnClickListener (e -> {
348+ // Generate the keypad
349+ List <KeypadButtonModel > buttons = Arrays .stream (new Character [] {
350+ '1' , '2' , '3' ,
351+ '4' , '5' , '6' ,
352+ '7' , '8' , '9' ,
353+ null , '0' , '#'
354+ }).map (c -> new KeypadButtonModel (c , null )).collect (Collectors .toList ());
355+
356+ // Set the icon for delete
357+ buttons .get (buttons .size () - 1 ).setButtonIcon (ResourcesCompat .getDrawable (getResources (), R .drawable .rounded_backspace_24 , getTheme ()));
358+
359+ // Configure keypad adapter
360+ KeypadAdapter keypadAdapter = new KeypadAdapter (this , buttons );
361+ binding .rcvKeypad .setAdapter (keypadAdapter );
362+ binding .rcvKeypad .setLayoutManager (new GridLayoutManager (this , 3 ));
363+ keypadAdapter .setOnButtonClick (value -> {
364+ if (value == '#' ) {
365+ if (enteredPin .length () > 0 ) {
366+ enteredPin .deleteCharAt (enteredPin .length () - 1 );
367+ StringBuilder pinText = new StringBuilder ();
368+ for (int i = 0 ; i < enteredPin .length (); i ++) { pinText .append ("\u2022 " ); }
369+ binding .txtEnteredPin .setText (pinText .toString ());
370+ }
371+ }
372+ else {
373373 binding .txtEnteredPin .setText (binding .txtEnteredPin .getText () + "•" );
374- enteredPin .append (buttonVal );
374+ enteredPin .append (value );
375375 new Thread (() -> {
376376 boolean success = isPinSuccess ();
377377 if (success || enteredPin .length () > 7 ){
@@ -388,22 +388,9 @@ private View generatePinButton(int pos) {
388388 });
389389 }
390390 }).start ();
391- });
392- return pinButton ;
393- }
394- else if (currentType == '<' ) {
395- pinButton .setText ("⌫" );
396- pinButton .setOnClickListener (e -> {
397- if (enteredPin .length () > 0 ) {
398- enteredPin .deleteCharAt (enteredPin .length ()-1 );
399- StringBuilder pinText = new StringBuilder ();
400- for (int i = 0 ; i < enteredPin .length (); i ++) { pinText .append ("\u2022 " ); }
401- binding .txtEnteredPin .setText (pinText .toString ());
402- }
403- });
404- return pinButton ;
405- }
406- return generateSpace ();
391+ }
392+ return Unit .INSTANCE ;
393+ });
407394 }
408395
409396 private void startLoadingAnimation () {
0 commit comments