Browse Source

hide EditText context menu (#3)

bug_fix
JunZhang 5 years ago
committed by GitHub
parent
commit
cd598b0615
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/src/main/java/com/cobo/cold/ui/fragment/main/ReceiveCoinFragment.java
  2. 112
      app/src/main/java/com/cobo/cold/ui/views/MenuHidingEditText.java
  3. 4
      app/src/main/res/layout/add_white_list.xml
  4. 2
      app/src/main/res/layout/address_item.xml
  5. 2
      app/src/main/res/layout/asset_fragment.xml
  6. 2
      app/src/main/res/layout/input_modal.xml
  7. 2
      app/src/main/res/layout/passphrase.xml
  8. 2
      app/src/main/res/layout/password_input_modal.xml
  9. 54
      app/src/main/res/layout/receive_fragment.xml

16
app/src/main/java/com/cobo/cold/ui/fragment/main/ReceiveCoinFragment.java

@ -17,11 +17,8 @@
package com.cobo.cold.ui.fragment.main;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.cobo.cold.R;
import com.cobo.cold.databinding.ReceiveFragmentBinding;
@ -48,19 +45,6 @@ public class ReceiveCoinFragment extends BaseFragment<ReceiveFragmentBinding> {
mBinding.setAddressName(data.getString(KEY_ADDRESS_NAME));
mBinding.setCoinCode(data.getString(KEY_COIN_CODE));
mBinding.qrcode.setData(data.getString(KEY_ADDRESS));
mBinding.amount.setOnEditorActionListener((textView, i, keyEvent) -> {
String text = textView.getText().toString();
if (!TextUtils.isEmpty(text)) {
mBinding.qrcode.setData(data.getString(KEY_ADDRESS) + "?amount=" + textView.getText());
}
textView.clearFocus();
final InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);
}
return false;
});
}
@Override

112
app/src/main/java/com/cobo/cold/ui/views/MenuHidingEditText.java

@ -0,0 +1,112 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.cold.ui.views;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.EditText;
import android.widget.TextView;
import java.lang.reflect.Field;
@SuppressLint("AppCompatCustomView")
public class MenuHidingEditText extends EditText {
private final Context mContext;
public MenuHidingEditText(Context context) {
super(context);
this.mContext = context;
blockContextMenu();
}
public MenuHidingEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
blockContextMenu();
}
public MenuHidingEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mContext = context;
blockContextMenu();
}
private void blockContextMenu() {
this.setCustomSelectionActionModeCallback(new BlockedActionModeCallback());
this.setLongClickable(false);
this.setOnTouchListener((v, event) -> {
MenuHidingEditText.this.clearFocus();
return false;
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// setInsertionDisabled when user touches the view
this.setInsertionDisabled();
}
return super.onTouchEvent(event);
}
private void setInsertionDisabled() {
try {
Field editorField = TextView.class.getDeclaredField("mEditor");
editorField.setAccessible(true);
Object editorObject = editorField.get(this);
Class editorClass = Class.forName("android.widget.Editor");
Field mInsertionControllerEnabledField = editorClass.getDeclaredField("mInsertionControllerEnabled");
mInsertionControllerEnabledField.setAccessible(true);
mInsertionControllerEnabledField.set(editorObject, false);
}
catch (Exception ignored) {
// ignore exception here
}
}
@Override
public boolean isSuggestionsEnabled() {
return false;
}
private class BlockedActionModeCallback implements ActionMode.Callback {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
}
}

4
app/src/main/res/layout/add_white_list.xml

@ -87,7 +87,7 @@
android:textSize="16sp"
android:textStyle="bold" />
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/addr"
android:layout_width="match_parent"
android:layout_height="60dp"
@ -104,7 +104,7 @@
android:importantForAutofill="no"
android:inputType="text" />
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/memo_edit"
android:layout_width="match_parent"
android:layout_height="60dp"

2
app/src/main/res/layout/address_item.xml

@ -42,7 +42,7 @@
android:layout_height="63dp"
android:focusable="true">
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

2
app/src/main/res/layout/asset_fragment.xml

@ -79,7 +79,7 @@
android:background="#000000"
android:visibility="invisible">
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="match_parent"

2
app/src/main/res/layout/input_modal.xml

@ -57,7 +57,7 @@
android:textStyle="bold" />
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/input_box"
android:layout_width="match_parent"
android:layout_height="48dp"

2
app/src/main/res/layout/passphrase.xml

@ -92,7 +92,7 @@
android:alpha="@{eye.checked ? 1f : 0.4f}"
android:button="@drawable/eye" />
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="match_parent"

2
app/src/main/res/layout/password_input_modal.xml

@ -73,7 +73,7 @@
android:text="@string/factory_reset_hint"
android:textSize="12sp" />
<EditText
<com.cobo.cold.ui.views.MenuHidingEditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="48dp"

54
app/src/main/res/layout/receive_fragment.xml

@ -128,59 +128,5 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="53dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:gravity="center"
android:text="@string/amount_hint"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<EditText
android:id="@+id/amount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:gravity="center|end"
android:hint="0.00"
android:imeOptions="actionDone"
android:textColorHint="@color/white40"
android:inputType="numberDecimal"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:background="@null"
tools:text="0.00"
android:importantForAutofill="no" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:gravity="center"
android:text="@{coinCode}"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
tools:text="BTC" />
</LinearLayout>
</LinearLayout>
</layout>
Loading…
Cancel
Save