Categories removed
This commit is contained in:
parent
18b7ac83c1
commit
0b5bc2b621
@ -34,13 +34,12 @@ import android.support.v4.app.FragmentManager;
|
|||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.solovyev.android.Activities;
|
import org.solovyev.android.Activities;
|
||||||
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.language.Language;
|
import org.solovyev.android.calculator.language.Language;
|
||||||
import org.solovyev.android.calculator.language.Languages;
|
import org.solovyev.android.calculator.language.Languages;
|
||||||
@ -227,6 +226,7 @@ public class ActivityUi extends BaseUi {
|
|||||||
int captionResId,
|
int captionResId,
|
||||||
int parentViewId) {
|
int parentViewId) {
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
|
Check.isNotNull(actionBar);
|
||||||
|
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
final ActionBar.Tab tab = actionBar.newTab();
|
||||||
tab.setTag(tag);
|
tab.setTag(tag);
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 serso aka se.solovyev
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
* Contact details
|
|
||||||
*
|
|
||||||
* Email: se.solovyev@gmail.com
|
|
||||||
* Site: http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 10/7/12
|
|
||||||
* Time: 7:17 PM
|
|
||||||
*/
|
|
||||||
public enum AndroidFunctionCategory {
|
|
||||||
|
|
||||||
trigonometric(R.string.c_fun_category_trig),
|
|
||||||
hyperbolic_trigonometric(R.string.c_fun_category_hyper_trig),
|
|
||||||
comparison(R.string.c_fun_category_comparison),
|
|
||||||
my(R.string.c_fun_category_my),
|
|
||||||
common(R.string.c_fun_category_common);
|
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
AndroidFunctionCategory(int captionId) {
|
|
||||||
this.captionId = captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static AndroidFunctionCategory valueOf(@Nonnull FunctionCategory functionCategory) {
|
|
||||||
for (AndroidFunctionCategory androidFunctionCategory : values()) {
|
|
||||||
if (androidFunctionCategory.name().equals(functionCategory.name())) {
|
|
||||||
return androidFunctionCategory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 serso aka se.solovyev
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
* Contact details
|
|
||||||
*
|
|
||||||
* Email: se.solovyev@gmail.com
|
|
||||||
* Site: http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 10/7/12
|
|
||||||
* Time: 7:41 PM
|
|
||||||
*/
|
|
||||||
public enum AndroidOperatorCategory {
|
|
||||||
|
|
||||||
derivatives(R.string.derivatives),
|
|
||||||
other(R.string.other),
|
|
||||||
my(R.string.c_fun_category_my),
|
|
||||||
common(R.string.c_fun_category_common);
|
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
AndroidOperatorCategory(int captionId) {
|
|
||||||
this.captionId = captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static AndroidOperatorCategory valueOf(@Nonnull OperatorCategory operatorCategory) {
|
|
||||||
for (AndroidOperatorCategory androidOperatorCategory : values()) {
|
|
||||||
if (androidOperatorCategory.name().equals(operatorCategory.name())) {
|
|
||||||
return androidOperatorCategory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 serso aka se.solovyev
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
* Contact details
|
|
||||||
*
|
|
||||||
* Email: se.solovyev@gmail.com
|
|
||||||
* Site: http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 10/7/12
|
|
||||||
* Time: 7:56 PM
|
|
||||||
*/
|
|
||||||
public enum AndroidVarCategory {
|
|
||||||
|
|
||||||
system(R.string.c_var_system),
|
|
||||||
my(R.string.c_var_my);
|
|
||||||
|
|
||||||
private final int captionId;
|
|
||||||
|
|
||||||
AndroidVarCategory(int captionId) {
|
|
||||||
this.captionId = captionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static AndroidVarCategory valueOf(@Nonnull VarCategory varCategory) {
|
|
||||||
for (AndroidVarCategory androidVarCategory : values()) {
|
|
||||||
if (androidVarCategory.name().equals(varCategory.name())) {
|
|
||||||
return androidVarCategory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCaptionId() {
|
|
||||||
return captionId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public interface Category {
|
||||||
|
|
||||||
|
int ordinal();
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
String name();
|
||||||
|
|
||||||
|
@StringRes
|
||||||
|
int title();
|
||||||
|
}
|
@ -28,27 +28,18 @@ import android.os.Build;
|
|||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
|
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
|
||||||
|
import org.solovyev.android.calculator.view.EditTextCompat;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class EditorView extends EditText {
|
public class EditorView extends EditTextCompat {
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private static final String TAG = App.subTag("EditorView");
|
|
||||||
|
|
||||||
private boolean reportChanges;
|
private boolean reportChanges;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Method setShowSoftInputOnFocusMethod;
|
|
||||||
@Nullable
|
|
||||||
private Editor editor;
|
private Editor editor;
|
||||||
|
|
||||||
public EditorView(Context context) {
|
public EditorView(Context context) {
|
||||||
@ -123,28 +114,6 @@ public class EditorView extends EditText {
|
|||||||
editor.setSelection(start);
|
editor.setSelection(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowSoftInputOnFocusCompat(boolean show) {
|
|
||||||
Check.isMainThread();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
setShowSoftInputOnFocus(show);
|
|
||||||
} else {
|
|
||||||
setShowSoftInputOnFocusPreLollipop(show);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setShowSoftInputOnFocusPreLollipop(boolean show) {
|
|
||||||
try {
|
|
||||||
if (setShowSoftInputOnFocusMethod == null) {
|
|
||||||
setShowSoftInputOnFocusMethod = EditText.class.getMethod("setShowSoftInputOnFocus", boolean.class);
|
|
||||||
setShowSoftInputOnFocusMethod.setAccessible(true);
|
|
||||||
}
|
|
||||||
setShowSoftInputOnFocusMethod.invoke(this, show);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(TAG, e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MyTextWatcher implements TextWatcher {
|
private class MyTextWatcher implements TextWatcher {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
@ -23,9 +23,12 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
import jscl.AngleUnit;
|
||||||
|
import jscl.JsclMathEngine;
|
||||||
|
import jscl.MathEngine;
|
||||||
|
import jscl.NumeralBase;
|
||||||
|
import jscl.math.operator.Operator;
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.calculator.model.EntityDao;
|
import org.solovyev.android.calculator.model.EntityDao;
|
||||||
import org.solovyev.android.calculator.model.Vars;
|
import org.solovyev.android.calculator.model.Vars;
|
||||||
@ -37,29 +40,21 @@ import org.solovyev.common.text.EnumMapper;
|
|||||||
import org.solovyev.common.text.NumberMapper;
|
import org.solovyev.common.text.NumberMapper;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import jscl.AngleUnit;
|
|
||||||
import jscl.JsclMathEngine;
|
|
||||||
import jscl.MathEngine;
|
|
||||||
import jscl.NumeralBase;
|
|
||||||
import jscl.math.function.IConstant;
|
|
||||||
import jscl.math.operator.Operator;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final MathEngine mathEngine;
|
private final MathEngine mathEngine;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final EntitiesRegistry<IConstant> varsRegistry;
|
private final VarsRegistry varsRegistry;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final EntitiesRegistry<Operator> operatorsRegistry;
|
private final EntitiesRegistry<Operator> operatorsRegistry;
|
||||||
@ -76,7 +71,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue();
|
private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue();
|
||||||
|
|
||||||
public Engine(@Nonnull MathEngine mathEngine, @Nonnull EntitiesRegistry<IConstant> varsRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
|
public Engine(@Nonnull MathEngine mathEngine, @Nonnull VarsRegistry varsRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
|
||||||
this.mathEngine = mathEngine;
|
this.mathEngine = mathEngine;
|
||||||
this.varsRegistry = varsRegistry;
|
this.varsRegistry = varsRegistry;
|
||||||
this.functionsRegistry = functionsRegistry;
|
this.functionsRegistry = functionsRegistry;
|
||||||
@ -111,7 +106,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public EntitiesRegistry<IConstant> getVarsRegistry() {
|
public VarsRegistry getVarsRegistry() {
|
||||||
return varsRegistry;
|
return varsRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public interface EntitiesRegistry<E extends MathEntity> extends MathRegistry<E>
|
|||||||
String getDescription(@Nonnull String name);
|
String getDescription(@Nonnull String name);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String getCategory(@Nonnull E entity);
|
Category getCategory(@Nonnull E entity);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import jscl.math.function.ArcTrigonometric;
|
import jscl.math.function.ArcTrigonometric;
|
||||||
import jscl.math.function.Comparison;
|
import jscl.math.function.Comparison;
|
||||||
import jscl.math.function.Function;
|
import jscl.math.function.Function;
|
||||||
@ -31,21 +32,16 @@ import org.solovyev.common.collections.Collections;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
public enum FunctionCategory implements Category {
|
||||||
* User: serso
|
|
||||||
* Date: 10/7/12
|
|
||||||
* Time: 7:15 PM
|
|
||||||
*/
|
|
||||||
public enum FunctionCategory {
|
|
||||||
|
|
||||||
trigonometric(100) {
|
trigonometric(100, R.string.c_fun_category_trig) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Function function) {
|
public boolean isInCategory(@Nonnull Function function) {
|
||||||
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
|
return (function instanceof Trigonometric || function instanceof ArcTrigonometric) && !hyperbolic_trigonometric.isInCategory(function);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hyperbolic_trigonometric(300) {
|
hyperbolic_trigonometric(300, R.string.c_fun_category_hyper_trig) {
|
||||||
|
|
||||||
private final Set<String> names = new HashSet<>(Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth"));
|
private final Set<String> names = new HashSet<>(Arrays.asList("sinh", "cosh", "tanh", "coth", "asinh", "acosh", "atanh", "acoth"));
|
||||||
|
|
||||||
@ -55,21 +51,21 @@ public enum FunctionCategory {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
comparison(200) {
|
comparison(200, R.string.c_fun_category_comparison) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Function function) {
|
public boolean isInCategory(@Nonnull Function function) {
|
||||||
return function instanceof Comparison;
|
return function instanceof Comparison;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
my(0) {
|
my(0, R.string.c_fun_category_my) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Function function) {
|
public boolean isInCategory(@Nonnull Function function) {
|
||||||
return !function.isSystem();
|
return !function.isSystem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
common(50) {
|
common(50, R.string.c_fun_category_common) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Function function) {
|
public boolean isInCategory(@Nonnull Function function) {
|
||||||
for (FunctionCategory category : values()) {
|
for (FunctionCategory category : values()) {
|
||||||
@ -84,10 +80,12 @@ public enum FunctionCategory {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int tabOrder;
|
public final int tabOrder;
|
||||||
|
public final int title;
|
||||||
|
|
||||||
FunctionCategory(int tabOrder) {
|
FunctionCategory(int tabOrder, @StringRes int title) {
|
||||||
this.tabOrder = tabOrder;
|
this.tabOrder = tabOrder;
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -104,5 +102,10 @@ public enum FunctionCategory {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean isInCategory(@Nonnull Function function);
|
public abstract boolean isInCategory(@Nonnull Function function);
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,10 @@ import android.app.Application;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
import jscl.JsclMathEngine;
|
||||||
|
import jscl.math.function.CustomFunction;
|
||||||
|
import jscl.math.function.Function;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.simpleframework.xml.Serializer;
|
import org.simpleframework.xml.Serializer;
|
||||||
@ -42,25 +43,15 @@ import org.solovyev.android.io.FileSaver;
|
|||||||
import org.solovyev.common.JBuilder;
|
import org.solovyev.common.JBuilder;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import java.io.File;
|
||||||
import jscl.JsclMathEngine;
|
import java.io.IOException;
|
||||||
import jscl.math.function.CustomFunction;
|
import java.util.*;
|
||||||
import jscl.math.function.Function;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static android.text.TextUtils.isEmpty;
|
import static android.text.TextUtils.isEmpty;
|
||||||
|
|
||||||
@ -186,10 +177,10 @@ public class FunctionsRegistry extends BaseEntitiesRegistry<Function, OldFunctio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@Nonnull Function function) {
|
public Category getCategory(@Nonnull Function function) {
|
||||||
for (FunctionCategory category : FunctionCategory.values()) {
|
for (FunctionCategory category : FunctionCategory.values()) {
|
||||||
if (category.isInCategory(function)) {
|
if (category.isInCategory(function)) {
|
||||||
return category.name();
|
return category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ public class KeyboardWindow {
|
|||||||
private static void hideIme(@NonNull View view) {
|
private static void hideIme(@NonNull View view) {
|
||||||
final IBinder token = view.getWindowToken();
|
final IBinder token = view.getWindowToken();
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
|
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
Context.INPUT_METHOD_SERVICE);
|
|
||||||
imm.hideSoftInputFromWindow(token, 0);
|
imm.hideSoftInputFromWindow(token, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,12 +44,13 @@ public class KeyboardWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show(@NonNull KeyboardUi.User user, @Nullable Dialog dialog, @NonNull List<String> parameterNames) {
|
public void show(@NonNull KeyboardUi.User user, @Nullable Dialog dialog, @NonNull List<String> parameterNames) {
|
||||||
|
final EditText editor = user.getEditor();
|
||||||
if (isShown()) {
|
if (isShown()) {
|
||||||
|
hideIme(editor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
moveDialog(Gravity.TOP);
|
moveDialog(Gravity.TOP);
|
||||||
final EditText editor = user.getEditor();
|
|
||||||
hideIme(editor);
|
hideIme(editor);
|
||||||
final Context context = editor.getContext();
|
final Context context = editor.getContext();
|
||||||
final LinearLayout view = new LinearLayout(context);
|
final LinearLayout view = new LinearLayout(context);
|
||||||
|
@ -22,49 +22,38 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
import jscl.math.operator.*;
|
||||||
import org.solovyev.common.collections.Collections;
|
import org.solovyev.common.collections.Collections;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
public enum OperatorCategory implements Category {
|
||||||
|
|
||||||
import jscl.math.operator.Derivative;
|
derivatives(100, R.string.derivatives) {
|
||||||
import jscl.math.operator.IndefiniteIntegral;
|
|
||||||
import jscl.math.operator.Integral;
|
|
||||||
import jscl.math.operator.Operator;
|
|
||||||
import jscl.math.operator.Product;
|
|
||||||
import jscl.math.operator.Sum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 10/7/12
|
|
||||||
* Time: 7:40 PM
|
|
||||||
*/
|
|
||||||
public enum OperatorCategory {
|
|
||||||
|
|
||||||
derivatives(100) {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
public boolean isInCategory(@Nonnull Operator operator) {
|
||||||
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
return operator instanceof Derivative || operator instanceof Integral || operator instanceof IndefiniteIntegral;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
other(200) {
|
other(200, R.string.other) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
public boolean isInCategory(@Nonnull Operator operator) {
|
||||||
return operator instanceof Sum || operator instanceof Product;
|
return operator instanceof Sum || operator instanceof Product;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
my(0) {
|
my(0, R.string.c_fun_category_my) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
public boolean isInCategory(@Nonnull Operator operator) {
|
||||||
return !operator.isSystem();
|
return !operator.isSystem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
common(50) {
|
common(50, R.string.c_fun_category_common) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
public boolean isInCategory(@Nonnull Operator operator) {
|
||||||
for (OperatorCategory category : values()) {
|
for (OperatorCategory category : values()) {
|
||||||
@ -80,9 +69,12 @@ public enum OperatorCategory {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final int tabOrder;
|
private final int tabOrder;
|
||||||
|
@StringRes
|
||||||
|
private final int title;
|
||||||
|
|
||||||
OperatorCategory(int tabOrder) {
|
OperatorCategory(int tabOrder, @StringRes int title) {
|
||||||
this.tabOrder = tabOrder;
|
this.tabOrder = tabOrder;
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -102,5 +94,12 @@ public enum OperatorCategory {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public abstract boolean isInCategory(@Nonnull Operator operator);
|
public abstract boolean isInCategory(@Nonnull Operator operator);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,10 @@ public class OperatorsRegistry extends BaseEntitiesRegistry<Operator, PersistedE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@Nonnull Operator operator) {
|
public Category getCategory(@Nonnull Operator operator) {
|
||||||
for (OperatorCategory category : OperatorCategory.values()) {
|
for (OperatorCategory category : OperatorCategory.values()) {
|
||||||
if (category.isInCategory(operator)) {
|
if (category.isInCategory(operator)) {
|
||||||
return category.name();
|
return category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -55,10 +55,10 @@ public class PostfixFunctionsRegistry extends BaseEntitiesRegistry<Operator, Per
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@Nonnull Operator operator) {
|
public Category getCategory(@Nonnull Operator operator) {
|
||||||
for (OperatorCategory category : OperatorCategory.values()) {
|
for (OperatorCategory category : OperatorCategory.values()) {
|
||||||
if (category.isInCategory(operator)) {
|
if (category.isInCategory(operator)) {
|
||||||
return category.name();
|
return category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,30 +22,24 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
import jscl.math.function.IConstant;
|
||||||
import org.solovyev.common.collections.Collections;
|
import org.solovyev.common.collections.Collections;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
public enum VarCategory implements Category {
|
||||||
|
|
||||||
import jscl.math.function.IConstant;
|
system(100, R.string.c_var_system) {
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 12/22/11
|
|
||||||
* Time: 4:25 PM
|
|
||||||
*/
|
|
||||||
public enum VarCategory {
|
|
||||||
|
|
||||||
system(100) {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull IConstant var) {
|
public boolean isInCategory(@Nonnull IConstant var) {
|
||||||
return var.isSystem();
|
return var.isSystem();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
my(0) {
|
my(0, R.string.c_var_my) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull IConstant var) {
|
public boolean isInCategory(@Nonnull IConstant var) {
|
||||||
return !var.isSystem();
|
return !var.isSystem();
|
||||||
@ -53,9 +47,12 @@ public enum VarCategory {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final int tabOrder;
|
private final int tabOrder;
|
||||||
|
@StringRes
|
||||||
|
private final int title;
|
||||||
|
|
||||||
VarCategory(int tabOrder) {
|
VarCategory(int tabOrder, @StringRes int title) {
|
||||||
this.tabOrder = tabOrder;
|
this.tabOrder = tabOrder;
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -73,4 +70,10 @@ public enum VarCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isInCategory(@Nonnull IConstant var);
|
public abstract boolean isInCategory(@Nonnull IConstant var);
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,10 +129,10 @@ public class VarsRegistry extends BaseEntitiesRegistry<IConstant, Var> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@Nonnull IConstant var) {
|
public Category getCategory(@Nonnull IConstant var) {
|
||||||
for (VarCategory category : VarCategory.values()) {
|
for (VarCategory category : VarCategory.values()) {
|
||||||
if (category.isInCategory(var)) {
|
if (category.isInCategory(var)) {
|
||||||
return category.name();
|
return category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,12 @@ import butterknife.Bind;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jscl.math.function.CustomFunction;
|
import jscl.math.function.CustomFunction;
|
||||||
import jscl.math.function.Function;
|
import jscl.math.function.Function;
|
||||||
import jscl.math.function.IConstant;
|
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
|
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
|
||||||
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
|
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
|
||||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||||
|
import org.solovyev.android.calculator.view.EditTextCompat;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -67,9 +67,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
private static final int MENU_CATEGORY = Menu.FIRST + 2;
|
private static final int MENU_CATEGORY = Menu.FIRST + 2;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final MathRegistry<Function> functionsRegistry = Locator.getInstance().getEngine().getFunctionsRegistry();
|
private final VarsRegistry constantsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
|
||||||
@NonNull
|
|
||||||
private final MathRegistry<IConstant> constantsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final KeyboardWindow keyboardWindow = new KeyboardWindow();
|
private final KeyboardWindow keyboardWindow = new KeyboardWindow();
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -83,13 +81,13 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
@Bind(R.id.function_body_label)
|
@Bind(R.id.function_body_label)
|
||||||
TextInputLayout bodyLabel;
|
TextInputLayout bodyLabel;
|
||||||
@Bind(R.id.function_body)
|
@Bind(R.id.function_body)
|
||||||
EditText bodyView;
|
EditTextCompat bodyView;
|
||||||
@Bind(R.id.function_description)
|
@Bind(R.id.function_description)
|
||||||
EditText descriptionView;
|
EditText descriptionView;
|
||||||
@Inject
|
@Inject
|
||||||
Calculator calculator;
|
Calculator calculator;
|
||||||
@Inject
|
@Inject
|
||||||
FunctionsRegistry registry;
|
FunctionsRegistry functionsRegistry;
|
||||||
@Nullable
|
@Nullable
|
||||||
private CppFunction function;
|
private CppFunction function;
|
||||||
|
|
||||||
@ -175,6 +173,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!isNewFunction()) {
|
if (!isNewFunction()) {
|
||||||
|
Check.isNotNull(function);
|
||||||
final Button neutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
|
final Button neutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
|
||||||
neutral.setOnClickListener(new View.OnClickListener() {
|
neutral.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -191,7 +190,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final CustomFunction entity = function.toCustomFunctionBuilder().create();
|
final CustomFunction entity = function.toCustomFunctionBuilder().create();
|
||||||
registry.remove(entity);
|
functionsRegistry.remove(entity);
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.function_removed, entity, this);
|
calculator.fireCalculatorEvent(CalculatorEventType.function_removed, entity, this);
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
@ -293,8 +292,8 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
.withId(isNewFunction() ? NO_ID : function.id)
|
.withId(isNewFunction() ? NO_ID : function.id)
|
||||||
.withParameters(collectParameters())
|
.withParameters(collectParameters())
|
||||||
.withDescription(descriptionView.getText().toString()).build();
|
.withDescription(descriptionView.getText().toString()).build();
|
||||||
final Function oldFunction = isNewFunction() ? null : registry.getById(function.id);
|
final Function oldFunction = isNewFunction() ? null : functionsRegistry.getById(function.id);
|
||||||
registry.add(newFunction.toCustomFunctionBuilder(), oldFunction);
|
functionsRegistry.add(newFunction.toCustomFunctionBuilder(), oldFunction);
|
||||||
return true;
|
return true;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
setError(bodyLabel, e.getLocalizedMessage());
|
setError(bodyLabel, e.getLocalizedMessage());
|
||||||
@ -312,7 +311,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
setError(nameLabel, getString(R.string.function_name_is_not_valid));
|
setError(nameLabel, getString(R.string.function_name_is_not_valid));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Function existingFunction = registry.get(name);
|
final Function existingFunction = functionsRegistry.get(name);
|
||||||
if (existingFunction != null) {
|
if (existingFunction != null) {
|
||||||
if (!existingFunction.isIdDefined()) {
|
if (!existingFunction.isIdDefined()) {
|
||||||
Check.shouldNotHappen();
|
Check.shouldNotHappen();
|
||||||
@ -385,6 +384,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
bodyView.setOnClickListener(this);
|
bodyView.setOnClickListener(this);
|
||||||
bodyView.setOnFocusChangeListener(this);
|
bodyView.setOnFocusChangeListener(this);
|
||||||
bodyView.setOnKeyListener(this);
|
bodyView.setOnKeyListener(this);
|
||||||
|
bodyView.setShowSoftInputOnFocusCompat(false);
|
||||||
descriptionView.setOnFocusChangeListener(this);
|
descriptionView.setOnFocusChangeListener(this);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
@ -564,9 +564,10 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
bodyView.post(new Runnable() {
|
bodyView.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (item.getItemId() == MENU_FUNCTION) {
|
final int itemId = item.getItemId();
|
||||||
|
if (itemId == MENU_FUNCTION) {
|
||||||
showFunctions(bodyView);
|
showFunctions(bodyView);
|
||||||
} else {
|
} else if (itemId == MENU_CONSTANT) {
|
||||||
showConstants(bodyView);
|
showConstants(bodyView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,34 +31,27 @@ import android.support.v7.widget.LinearLayoutManager;
|
|||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.ContextMenu;
|
import android.view.*;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import com.melnykov.fab.FloatingActionButton;
|
import com.melnykov.fab.FloatingActionButton;
|
||||||
|
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.calculator.BaseFragment;
|
import org.solovyev.android.calculator.BaseFragment;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
|
import org.solovyev.android.calculator.Category;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.views.llm.DividerItemDecoration;
|
import org.solovyev.android.views.llm.DividerItemDecoration;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import butterknife.Bind;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFragment {
|
public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFragment {
|
||||||
|
|
||||||
@ -140,14 +133,18 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInCategory(@NonNull E entity, @NonNull String category) {
|
private boolean isInCategory(@NonNull E entity, @NonNull String category) {
|
||||||
return TextUtils.equals(getCategory(entity), category);
|
final Category entityCategory = getCategory(entity);
|
||||||
|
if (entityCategory == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return TextUtils.equals(entityCategory.name(), category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected abstract List<E> getEntities();
|
protected abstract List<E> getEntities();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
abstract String getCategory(@Nonnull E e);
|
abstract Category getCategory(@Nonnull E e);
|
||||||
|
|
||||||
protected EntitiesAdapter getAdapter() {
|
protected EntitiesAdapter getAdapter() {
|
||||||
return adapter;
|
return adapter;
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.solovyev.android.calculator.AndroidFunctionCategory;
|
|
||||||
import org.solovyev.android.calculator.BaseActivity;
|
import org.solovyev.android.calculator.BaseActivity;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.FunctionCategory;
|
import org.solovyev.android.calculator.FunctionCategory;
|
||||||
@ -48,22 +45,16 @@ public class CalculatorFunctionsActivity extends BaseActivity {
|
|||||||
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.functions;
|
||||||
|
|
||||||
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
|
for (FunctionCategory category : FunctionCategory.getCategoriesByTabOrder()) {
|
||||||
final AndroidFunctionCategory androidCategory = AndroidFunctionCategory.valueOf(category);
|
final Bundle fragmentParameters;
|
||||||
if (androidCategory != null) {
|
|
||||||
|
|
||||||
final Bundle fragmentParameters;
|
if (category == FunctionCategory.my && bundle != null) {
|
||||||
|
BaseEntitiesFragment.putCategory(bundle, category.name());
|
||||||
if (category == FunctionCategory.my && bundle != null) {
|
fragmentParameters = bundle;
|
||||||
BaseEntitiesFragment.putCategory(bundle, category.name());
|
|
||||||
fragmentParameters = bundle;
|
|
||||||
} else {
|
|
||||||
fragmentParameters = BaseEntitiesFragment.createBundleFor(category.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidCategory.getCaptionId(), R.id.main_layout);
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(CalculatorFunctionsActivity.class.getSimpleName(), "Unable to find android function category for " + category);
|
fragmentParameters = BaseEntitiesFragment.createBundleFor(category.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.title, R.id.main_layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ package org.solovyev.android.calculator.math.edit;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.AndroidOperatorCategory;
|
|
||||||
import org.solovyev.android.calculator.BaseActivity;
|
import org.solovyev.android.calculator.BaseActivity;
|
||||||
import org.solovyev.android.calculator.CalculatorEventData;
|
import org.solovyev.android.calculator.CalculatorEventData;
|
||||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||||
@ -49,12 +48,7 @@ public class CalculatorOperatorsActivity extends BaseActivity implements Calcula
|
|||||||
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
|
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
|
||||||
|
|
||||||
for (OperatorCategory category : OperatorCategory.getCategoriesByTabOrder()) {
|
for (OperatorCategory category : OperatorCategory.getCategoriesByTabOrder()) {
|
||||||
final AndroidOperatorCategory androidCategory = AndroidOperatorCategory.valueOf(category);
|
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), BaseEntitiesFragment.createBundleFor(category.name()), category.title(), R.id.main_layout);
|
||||||
if (androidCategory != null) {
|
|
||||||
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), BaseEntitiesFragment.createBundleFor(category.name()), androidCategory.getCaptionId(), R.id.main_layout);
|
|
||||||
} else {
|
|
||||||
ui.logError("Unable to find android operator category for " + category);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ package org.solovyev.android.calculator.math.edit;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.AndroidVarCategory;
|
|
||||||
import org.solovyev.android.calculator.BaseActivity;
|
import org.solovyev.android.calculator.BaseActivity;
|
||||||
import org.solovyev.android.calculator.CalculatorEventData;
|
import org.solovyev.android.calculator.CalculatorEventData;
|
||||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||||
@ -68,15 +67,7 @@ public class CalculatorVarsActivity extends BaseActivity implements CalculatorEv
|
|||||||
} else {
|
} else {
|
||||||
fragmentParameters = BaseEntitiesFragment.createBundleFor(category.name());
|
fragmentParameters = BaseEntitiesFragment.createBundleFor(category.name());
|
||||||
}
|
}
|
||||||
|
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, category.title(), R.id.main_layout);
|
||||||
|
|
||||||
final AndroidVarCategory androidVarCategory = AndroidVarCategory.valueOf(category);
|
|
||||||
|
|
||||||
if (androidVarCategory != null) {
|
|
||||||
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), fragmentParameters, androidVarCategory.getCaptionId(), R.id.main_layout);
|
|
||||||
} else {
|
|
||||||
ui.logError("Unable to find android var category for " + category);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,13 +34,7 @@ import android.view.ViewGroup;
|
|||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.AppComponent;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.Calculator;
|
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
|
||||||
import org.solovyev.android.calculator.EntitiesRegistry;
|
|
||||||
import org.solovyev.android.calculator.FunctionsRegistry;
|
|
||||||
import org.solovyev.android.calculator.Keyboard;
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.android.calculator.function.CppFunction;
|
import org.solovyev.android.calculator.function.CppFunction;
|
||||||
import org.solovyev.android.calculator.function.EditFunctionFragment;
|
import org.solovyev.android.calculator.function.EditFunctionFragment;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
@ -165,7 +159,7 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCategory(@Nonnull Function function) {
|
protected Category getCategory(@Nonnull Function function) {
|
||||||
return registry.getCategory(function);
|
return registry.getCategory(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,24 +23,16 @@
|
|||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import jscl.math.operator.Operator;
|
||||||
import org.solovyev.android.calculator.CalculatorEventType;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
|
||||||
import org.solovyev.android.calculator.EntitiesRegistry;
|
|
||||||
import org.solovyev.android.calculator.Locator;
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import jscl.math.operator.Operator;
|
import java.util.List;
|
||||||
|
|
||||||
public class OperatorsFragment extends BaseEntitiesFragment<Operator> {
|
public class OperatorsFragment extends BaseEntitiesFragment<Operator> {
|
||||||
|
|
||||||
@ -70,9 +62,9 @@ public class OperatorsFragment extends BaseEntitiesFragment<Operator> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCategory(@Nonnull Operator operator) {
|
protected Category getCategory(@Nonnull Operator operator) {
|
||||||
final String result = operatorsRegistry.getCategory(operator);
|
final Category result = operatorsRegistry.getCategory(operator);
|
||||||
if (!TextUtils.isEmpty(result)) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return postfixFunctionsRegistry.getCategory(operator);
|
return postfixFunctionsRegistry.getCategory(operator);
|
||||||
|
@ -120,7 +120,7 @@ public class VarsFragment extends BaseEntitiesFragment<IConstant>implements Calc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCategory(@Nonnull IConstant var) {
|
protected Category getCategory(@Nonnull IConstant var) {
|
||||||
return registry.getCategory(var);
|
return registry.getCategory(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package org.solovyev.android.calculator.view;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class EditTextCompat extends EditText {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Method setShowSoftInputOnFocusMethod;
|
||||||
|
|
||||||
|
public EditTextCompat(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditTextCompat(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditTextCompat(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
public EditTextCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowSoftInputOnFocusCompat(boolean show) {
|
||||||
|
Check.isMainThread();
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
setShowSoftInputOnFocus(show);
|
||||||
|
} else {
|
||||||
|
setShowSoftInputOnFocusPreLollipop(show);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setShowSoftInputOnFocusPreLollipop(boolean show) {
|
||||||
|
try {
|
||||||
|
if (setShowSoftInputOnFocusMethod == null) {
|
||||||
|
setShowSoftInputOnFocusMethod = EditText.class.getMethod("setShowSoftInputOnFocus", boolean.class);
|
||||||
|
setShowSoftInputOnFocusMethod.setAccessible(true);
|
||||||
|
}
|
||||||
|
setShowSoftInputOnFocusMethod.invoke(this, show);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w("EditTextCompat", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -55,11 +55,12 @@
|
|||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content">
|
a:layout_height="wrap_content">
|
||||||
|
|
||||||
<EditText
|
<org.solovyev.android.calculator.view.EditTextCompat
|
||||||
a:id="@+id/function_body"
|
a:id="@+id/function_body"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:hint="@string/c_function_value"
|
a:hint="@string/c_function_value"
|
||||||
|
a:imeOptions="flagNoExtractUi"
|
||||||
a:inputType="text" />
|
a:inputType="text" />
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user