Skip to content

Commit

Permalink
Disable default keyboard dismiss behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Oct 20, 2023
1 parent dc898c0 commit 2ec47dd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.owncloud.android.authentication.PassCodeManager;
import com.owncloud.android.databinding.PasscodelockBinding;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.components.PassCodeEditText;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import java.util.Arrays;
Expand Down Expand Up @@ -74,7 +75,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable {
@Inject PassCodeManager passCodeManager;
@Inject ViewThemeUtils viewThemeUtils;
private PasscodelockBinding binding;
private final EditText[] passCodeEditTexts = new EditText[4];
private final PassCodeEditText[] passCodeEditTexts = new PassCodeEditText[4];
private String[] passCodeDigits = {"", "", "", ""};
private boolean confirmingPassCode;
private boolean changed = true; // to control that only one blocks jump
Expand Down Expand Up @@ -174,7 +175,7 @@ public PasscodelockBinding getBinding() {
@SuppressLint("ClickableViewAccessibility")
protected void setTextListeners() {
for (int i = 0; i < passCodeEditTexts.length; i++) {
final EditText editText = passCodeEditTexts[i];
final PassCodeEditText editText = passCodeEditTexts[i];
boolean isLast = (i == 3);

editText.addTextChangedListener(new PassCodeDigitTextWatcher(i, isLast));
Expand Down Expand Up @@ -276,8 +277,7 @@ private void hideSoftKeyboard() {
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
focusedView.getWindowToken(),
0
);
0);
}
}

Expand Down Expand Up @@ -412,7 +412,6 @@ public void run() {
}
}


@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Expand All @@ -434,6 +433,7 @@ private class PassCodeDigitTextWatcher implements TextWatcher {
PassCodeDigitTextWatcher(int index, boolean lastOne) {
mIndex = index;
mLastOne = lastOne;

if (mIndex < 0) {
throw new IllegalArgumentException(
"Invalid index in " + PassCodeDigitTextWatcher.class.getSimpleName() +
Expand All @@ -457,8 +457,13 @@ private int next() {
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
if (!confirmingPassCode) {
passCodeDigits[mIndex] = passCodeEditTexts[mIndex].getText().toString();
Editable passCodeText = passCodeEditTexts[mIndex].getText();

if (passCodeText != null) {
passCodeDigits[mIndex] = passCodeText.toString();
}
}

passCodeEditTexts[next()].requestFocus();

if (mLastOne) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Nextcloud Android client application
*
* @author Alper Ozturk
* Copyright (C) 2023 Alper Ozturk
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.components

import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import androidx.appcompat.widget.AppCompatEditText

class PassCodeEditText(context: Context, attrs: AttributeSet?): AppCompatEditText(context, attrs) {

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
val isBackButtonPressed = (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP)
if (isBackButtonPressed) {
// Override default behaviour and prevent dismissing the keyboard
return true
}
return super.dispatchKeyEvent(event)
}

}
18 changes: 5 additions & 13 deletions app/src/main/res/layout/passcodelock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,26 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal">

<com.google.android.material.textfield.TextInputEditText
<com.owncloud.android.ui.components.PassCodeEditText
android:id="@+id/txt0"
style="@style/PassCodeStyle"
android:hint="@string/hidden_character"
android:imeOptions="flagNoExtractUi"
android:importantForAutofill="no"
tools:text="123">
</com.google.android.material.textfield.TextInputEditText>
</com.owncloud.android.ui.components.PassCodeEditText>

<com.google.android.material.textfield.TextInputEditText
<com.owncloud.android.ui.components.PassCodeEditText
android:id="@+id/txt1"
style="@style/PassCodeStyle"
android:hint="@string/hidden_character"
android:imeOptions="flagNoExtractUi"
android:importantForAutofill="no" />

<com.google.android.material.textfield.TextInputEditText
<com.owncloud.android.ui.components.PassCodeEditText
android:id="@+id/txt2"
style="@style/PassCodeStyle"
android:hint="@string/hidden_character"
android:imeOptions="flagNoExtractUi"
android:importantForAutofill="no" />

<com.google.android.material.textfield.TextInputEditText
<com.owncloud.android.ui.components.PassCodeEditText
android:id="@+id/txt3"
style="@style/PassCodeStyle"
android:hint="@string/hidden_character"
android:imeOptions="flagNoExtractUi"
android:importantForAutofill="no" />
</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
</style>

<style name="PassCodeStyle">
<item name="android:hint">@string/hidden_character</item>
<item name="android:layout_width">50dp</item>
<item name="android:layout_height">50dp</item>
<item name="android:gravity">center</item>
Expand Down

0 comments on commit 2ec47dd

Please sign in to comment.