Skip to content

Commit 9543006

Browse files
committed
Disable system keyboard appearing on long-press in transaction amount edit text.
1 parent badbe14 commit 9543006

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

app/src/main/java/org/gnucash/android/ui/util/widget/CalculatorEditText.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package org.gnucash.android.ui.util.widget;
1717

18-
import android.app.Activity;
1918
import android.content.Context;
2019
import android.content.res.TypedArray;
2120
import android.inputmethodservice.KeyboardView;
21+
import android.os.Build;
2222
import android.support.annotation.Nullable;
2323
import android.support.annotation.XmlRes;
2424
import android.support.v7.widget.AppCompatEditText;
@@ -29,15 +29,13 @@
2929
import android.util.Log;
3030
import android.view.MotionEvent;
3131
import android.view.View;
32-
import android.view.inputmethod.InputMethodManager;
3332

3433
import com.crashlytics.android.Crashlytics;
3534

3635
import net.objecthunter.exp4j.Expression;
3736
import net.objecthunter.exp4j.ExpressionBuilder;
3837

3938
import org.gnucash.android.R;
40-
import org.gnucash.android.app.GnuCashApplication;
4139
import org.gnucash.android.model.Commodity;
4240
import org.gnucash.android.ui.common.FormActivity;
4341
import org.gnucash.android.util.AmountParser;
@@ -148,18 +146,12 @@ public void onClick(View v) {
148146
// Disable spell check (hex strings look like words to Android)
149147
setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
150148

151-
// FIXME: for some reason, this prevents the text selection from working
152-
setOnLongClickListener(new View.OnLongClickListener() {
153-
@Override
154-
public boolean onLongClick(View v) {
155-
if (v != null && !isInEditMode())
156-
((InputMethodManager) GnuCashApplication.getAppContext()
157-
.getSystemService(Activity.INPUT_METHOD_SERVICE))
158-
.hideSoftInputFromWindow(v.getWindowToken(), 0);
159-
160-
return false;
161-
}
162-
});
149+
// Disable system keyboard appearing on long-press, but for some reason, this prevents the text selection from working.
150+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
151+
setShowSoftInputOnFocus(false);
152+
} else {
153+
setRawInputType(InputType.TYPE_CLASS_NUMBER);
154+
}
163155

164156
// Although this handler doesn't make sense, if removed, the standard keyboard
165157
// shows up in addition to the calculator one when the EditText gets a touch event.

app/src/main/res/layout/fragment_transaction_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
android:background="@android:color/transparent"
7373
android:textColor="@color/debit_red"
7474
android:textSize="20sp"
75+
android:textIsSelectable="true"
7576
gnucash:keyboardKeysLayout="@xml/calculator_keyboard"/>
7677

7778
<ImageView android:id="@+id/btn_split_editor"

0 commit comments

Comments
 (0)