Possible fix for disabling virtual keyboard

This commit is contained in:
Sergey Solovyev 2012-04-24 15:49:46 +04:00
parent 391fe95df9
commit 315a2eb604

View File

@ -10,10 +10,14 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.text.Html;
import android.text.InputType;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.calculator.model.CalculatorParseException;
@ -37,20 +41,40 @@ public class CalculatorEditor extends EditText implements SharedPreferences.OnSh
public CalculatorEditor(Context context) {
super(context);
init();
}
public CalculatorEditor(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CalculatorEditor(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
private void init() {
this.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final TextView textView = (TextView)v;
// backup the input type
int inputType = textView.getInputType();
// disable soft input
textView.setInputType(InputType.TYPE_NULL);
// call native handler
textView.onTouchEvent(event);
// restore input type
textView.setInputType(inputType);
// consume touch even
return true;
}
});
}
@Override
public boolean onCheckIsTextEditor() {
// Main goal of this implementation is to hide android soft keyboard from appearing when working with text input
if (Build.VERSION.SDK_INT >= 11) {
// fix for missing cursor in android 3 and higher
return true;
@ -59,6 +83,11 @@ public class CalculatorEditor extends EditText implements SharedPreferences.OnSh
}
}
public CalculatorEditor(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
@Override
protected void onCreateContextMenu(ContextMenu menu) {
super.onCreateContextMenu(menu);