Android 2.3 fixes
This commit is contained in:
parent
f05d050b6c
commit
c9b39068ae
@ -41,7 +41,7 @@ android {
|
||||
zipAlignEnabled true
|
||||
}
|
||||
debug {
|
||||
minifyEnabled false
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-debug.cfg'
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class EditorView extends EditTextCompat {
|
||||
|
||||
private void init() {
|
||||
addTextChangedListener(new MyTextWatcher());
|
||||
setShowSoftInputOnFocusCompat(false);
|
||||
dontShowSoftInputOnFocusCompat();
|
||||
// changes should only be reported after the view has been set up completely, i.e. now
|
||||
reportChanges = true;
|
||||
}
|
||||
|
@ -36,25 +36,50 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.*;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.AppComponent;
|
||||
import org.solovyev.android.calculator.BaseDialogFragment;
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.FunctionsRegistry;
|
||||
import org.solovyev.android.calculator.KeyboardUi;
|
||||
import org.solovyev.android.calculator.KeyboardWindow;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.ParseException;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.VarsRegistry;
|
||||
import org.solovyev.android.calculator.math.edit.FunctionsActivity;
|
||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||
import org.solovyev.android.calculator.view.EditTextCompat;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
|
||||
import static org.solovyev.android.calculator.function.CppFunction.NO_ID;
|
||||
|
||||
@ -390,7 +415,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
bodyView.setOnClickListener(this);
|
||||
bodyView.setOnFocusChangeListener(this);
|
||||
bodyView.setOnKeyListener(this);
|
||||
bodyView.setShowSoftInputOnFocusCompat(false);
|
||||
bodyView.dontShowSoftInputOnFocusCompat();
|
||||
descriptionView.setOnFocusChangeListener(this);
|
||||
|
||||
return view;
|
||||
@ -468,6 +493,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.function_body) {
|
||||
menu.clear();
|
||||
addEntities(menu, getNamesSorted(constantsRegistry), MENU_CONSTANT);
|
||||
unregisterForContextMenu(bodyView);
|
||||
}
|
||||
@ -490,6 +516,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.function_body) {
|
||||
menu.clear();
|
||||
addEntities(menu, getNamesSorted(functionsRegistry), MENU_FUNCTION);
|
||||
unregisterForContextMenu(bodyView);
|
||||
}
|
||||
@ -511,6 +538,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.function_body) {
|
||||
menu.clear();
|
||||
// can't use sub-menus as AlertDialog doesn't support them
|
||||
menu.add(MENU_CATEGORY, MENU_CONSTANT, Menu.NONE, R.string.c_vars_and_constants).setOnMenuItemClickListener(KeyboardUser.this);
|
||||
menu.add(MENU_CATEGORY, MENU_FUNCTION, Menu.NONE, R.string.c_functions).setOnMenuItemClickListener(KeyboardUser.this);
|
||||
|
@ -3,18 +3,22 @@ package org.solovyev.android.calculator.view;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.InputType;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class EditTextCompat extends EditText {
|
||||
|
||||
@Nullable
|
||||
private Method setShowSoftInputOnFocusMethod;
|
||||
private static Method setShowSoftInputOnFocusMethod;
|
||||
private static boolean setShowSoftInputOnFocusMethodChecked;
|
||||
|
||||
public EditTextCompat(Context context) {
|
||||
super(context);
|
||||
@ -33,25 +37,51 @@ public class EditTextCompat extends EditText {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void setShowSoftInputOnFocusCompat(boolean show) {
|
||||
public void dontShowSoftInputOnFocusCompat() {
|
||||
Check.isMainThread();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
setShowSoftInputOnFocus(show);
|
||||
setShowSoftInputOnFocus(false);
|
||||
} else {
|
||||
setShowSoftInputOnFocusPreLollipop(show);
|
||||
dontShowSoftInputOnFocusPreLollipop();
|
||||
}
|
||||
}
|
||||
|
||||
private void setShowSoftInputOnFocusPreLollipop(boolean show) {
|
||||
private void dontShowSoftInputOnFocusPreLollipop() {
|
||||
final Method method = getSetShowSoftInputOnFocusMethod();
|
||||
if (method == null) {
|
||||
disableSoftInputFromAppearing();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (setShowSoftInputOnFocusMethod == null) {
|
||||
setShowSoftInputOnFocusMethod = EditText.class.getMethod("setShowSoftInputOnFocus", boolean.class);
|
||||
setShowSoftInputOnFocusMethod.setAccessible(true);
|
||||
}
|
||||
setShowSoftInputOnFocusMethod.invoke(this, show);
|
||||
method.invoke(this, false);
|
||||
} catch (Exception e) {
|
||||
Log.w("EditTextCompat", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Method getSetShowSoftInputOnFocusMethod() {
|
||||
if (setShowSoftInputOnFocusMethodChecked) {
|
||||
return setShowSoftInputOnFocusMethod;
|
||||
}
|
||||
setShowSoftInputOnFocusMethodChecked = true;
|
||||
try {
|
||||
setShowSoftInputOnFocusMethod = EditText.class.getMethod("setShowSoftInputOnFocus", boolean.class);
|
||||
setShowSoftInputOnFocusMethod.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.w("EditTextCompat", e.getMessage(), e);
|
||||
}
|
||||
return setShowSoftInputOnFocusMethod;
|
||||
}
|
||||
|
||||
public void disableSoftInputFromAppearing() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
setRawInputType(InputType.TYPE_CLASS_TEXT);
|
||||
setTextIsSelectable(true);
|
||||
} else {
|
||||
setRawInputType(InputType.TYPE_NULL);
|
||||
setFocusable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,7 @@
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:gravity">center_vertical|left</item>
|
||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||
<item name="android:background">?attr/selectableItemBackground</item>
|
||||
</style>
|
||||
|
||||
<style name="CppFab">
|
||||
|
Loading…
Reference in New Issue
Block a user