Fix for Android 4 soft keyboard

This commit is contained in:
Sergey Solovyev 2012-04-24 19:59:49 +04:00
parent 37e9354a5b
commit 7120ad3e61
3 changed files with 24 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="75" android:versionName="1.2.34" package="org.solovyev.android.calculator">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="78" android:versionName="1.2.38" package="org.solovyev.android.calculator">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
@ -8,7 +8,7 @@
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
<application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<application android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">

View File

@ -14,7 +14,7 @@
<org.solovyev.android.calculator.CalculatorEditor
a:id="@+id/calculatorEditor"
style="@style/editor_style"
a:editable="false"
a:textIsSelectable="true"
a:singleLine="false"
a:scrollbars="vertical"
a:hint ="@string/c_calc_editor_hint"/>

View File

@ -10,19 +10,16 @@ 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;
import org.solovyev.android.calculator.model.TextProcessor;
import org.solovyev.android.calculator.view.TextHighlighter;
import org.solovyev.common.utils.CollectionsUtils;
/**
* User: serso
@ -50,7 +47,9 @@ public class CalculatorEditor extends EditText implements SharedPreferences.OnSh
}
private void init() {
this.setOnTouchListener(new OnTouchListener() {
// NOTE: in this solution cursor is missing
/*this.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final TextView textView = (TextView)v;
@ -69,15 +68,29 @@ public class CalculatorEditor extends EditText implements SharedPreferences.OnSh
// consume touch even
return true;
}
});
});*/
}
@Override
public boolean onCheckIsTextEditor() {
if (Build.VERSION.SDK_INT >= 11) {
// NOTE: code below can be used carefully and should not be copied without special intention
// The main purpose of code is to disable soft input (virtual keyboard) but leave all the TextEdit functionality, like cursor, scrolling, copy/paste menu etc
if ( Build.VERSION.SDK_INT >= 11 ) {
// fix for missing cursor in android 3 and higher
return true;
try {
// IDEA: return false always except if method was called from TextView.isCursorVisible() method
for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) {
if ( "isCursorVisible".equals(stackTraceElement.getMethodName()) ) {
return true;
}
}
} catch (RuntimeException e) {
// just in case...
}
return false;
} else {
return false;
}