From c68b6c58036fb345daa97d70288e8b939814950a Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 30 Jan 2016 22:43:06 +0100 Subject: [PATCH] Changes --- .../android/calculator/ActivityUi.java | 13 ++++++++-- .../android/calculator/BaseActivity.java | 17 ++++++++++++ .../BaseEntitiesFragment.java | 26 +++++-------------- .../functions/FunctionsActivity.java | 19 +++++--------- .../math/edit/FunctionsFragment.java | 1 + .../math/edit/OperatorsActivity.java | 1 + .../math/edit/OperatorsFragment.java | 1 + .../operators/OperatorCategory.java | 16 +----------- .../variables/VariablesActivity.java | 13 +--------- .../variables/VariablesFragment.java | 7 ++--- jscl/src/main/java/jscl/text/ParserUtils.java | 13 +++++----- 11 files changed, 53 insertions(+), 74 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/{math/edit => entities}/BaseEntitiesFragment.java (93%) diff --git a/app/src/main/java/org/solovyev/android/calculator/ActivityUi.java b/app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index cc13194d..292ca93c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/ActivityUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -223,14 +223,23 @@ public class ActivityUi extends BaseUi { @Nonnull String tag, @Nonnull Class fragmentClass, @Nullable Bundle fragmentArgs, - int captionResId, + int title, + int parentViewId) { + addTab(activity, tag, fragmentClass, fragmentArgs, activity.getString(title), parentViewId); + } + + public void addTab(@Nonnull AppCompatActivity activity, + @Nonnull String tag, + @Nonnull Class fragmentClass, + @Nullable Bundle fragmentArgs, + @Nullable CharSequence title, int parentViewId) { final ActionBar actionBar = activity.getSupportActionBar(); Check.isNotNull(actionBar); final ActionBar.Tab tab = actionBar.newTab(); tab.setTag(tag); - tab.setText(captionResId); + tab.setText(title); final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId); tab.setTabListener(listener); diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java index d0e848c5..47b7ef85 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -2,11 +2,15 @@ package org.solovyev.android.calculator; import android.os.Bundle; import android.support.annotation.LayoutRes; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import android.view.MenuItem; +import org.solovyev.android.calculator.entities.Category; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class BaseActivity extends AppCompatActivity { @@ -92,4 +96,17 @@ public class BaseActivity extends AppCompatActivity { } return super.onOptionsItemSelected(item); } + + protected final void addTab(@Nonnull Category category, @Nonnull CalculatorFragmentType type) { + final CharSequence title = getString(category.title()); + addTab(category, type, title); + } + + protected final void addTab(@Nonnull Category category, @Nonnull CalculatorFragmentType type, @Nullable CharSequence title) { + final Bundle arguments = new Bundle(1); + arguments.putString(BaseEntitiesFragment.ARG_CATEGORY, category.name()); + final String fragmentTag = type.createSubFragmentTag(category.name()); + final Class fragmentClass = type.getFragmentClass(); + ui.addTab(this, fragmentTag, fragmentClass, arguments, title, R.id.main_layout); + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/BaseEntitiesFragment.java b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java similarity index 93% rename from app/src/main/java/org/solovyev/android/calculator/math/edit/BaseEntitiesFragment.java rename to app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java index 8e0f6be7..b9156799 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/BaseEntitiesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java @@ -20,12 +20,11 @@ * Site: http://se.solovyev.org */ -package org.solovyev.android.calculator.math.edit; +package org.solovyev.android.calculator.entities; import android.app.Activity; import android.content.Context; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.NonNull; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -40,7 +39,6 @@ import org.solovyev.android.Check; import org.solovyev.android.calculator.BaseFragment; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.views.llm.DividerItemDecoration; import org.solovyev.common.math.MathEntity; import org.solovyev.common.text.Strings; @@ -63,8 +61,6 @@ public abstract class BaseEntitiesFragment extends BaseFra } }; - @Nonnull - private final Handler uiHandler = new Handler(); @Bind(R.id.entities_fab) public FloatingActionButton fab; @Bind(R.id.entities_recyclerview) @@ -150,18 +146,13 @@ public abstract class BaseEntitiesFragment extends BaseFra return adapter; } - @Nonnull - protected Handler getUiHandler() { - return uiHandler; - } - @SuppressWarnings("deprecation") - protected final void copyDescription(@Nonnull E entity) { - final String description = getDescription(entity); - if (!Strings.isEmpty(description)) { - final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE); - clipboard.setText(description); + protected final void copyText(@Nullable String text) { + if (!Strings.isEmpty(text)) { + return; } + final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE); + clipboard.setText(text); } protected void onEntityAdded(@NonNull E entity) { @@ -288,11 +279,6 @@ public abstract class BaseEntitiesFragment extends BaseFra list.set(position, entity); } - public void sort() { - Collections.sort(list, COMPARATOR); - notifyDataSetChanged(); - } - public void add(@Nonnull E entity) { final int itemCount = getItemCount(); for (int i = 0; i < itemCount; i++) { diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java index 0e1cc0ff..71e335ac 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java @@ -23,19 +23,16 @@ package org.solovyev.android.calculator.functions; import android.os.Bundle; -import android.support.v4.app.Fragment; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; -import org.solovyev.android.calculator.math.edit.FunctionsFragment; +import org.solovyev.android.calculator.operators.OperatorCategory; -import javax.annotation.Nonnull; import javax.annotation.Nullable; public class FunctionsActivity extends BaseActivity { public static final String EXTRA_FUNCTION = "function"; - private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.functions; public FunctionsActivity() { super(R.layout.main_empty, FunctionsActivity.class.getSimpleName()); @@ -46,7 +43,11 @@ public class FunctionsActivity extends BaseActivity { super.onCreate(savedInstanceState); for (FunctionCategory category : FunctionCategory.values()) { - addTab(category); + addTab(category, CalculatorFragmentType.functions); + } + + for (OperatorCategory category : OperatorCategory.values()) { + addTab(category, CalculatorFragmentType.operators, getString(R.string.c_operators) + ": " + getString(category.title())); } if (savedInstanceState == null) { @@ -57,12 +58,4 @@ public class FunctionsActivity extends BaseActivity { } } } - - private void addTab(@Nonnull FunctionCategory category) { - final Bundle arguments = new Bundle(1); - arguments.putString(FunctionsFragment.ARG_CATEGORY, category.name()); - final String fragmentTag = FRAGMENT_TYPE.createSubFragmentTag(category.name()); - final Class fragmentClass = FRAGMENT_TYPE.getFragmentClass(); - ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title, R.id.main_layout); - } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/FunctionsFragment.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/FunctionsFragment.java index 877e15dc..c8329d16 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/FunctionsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/FunctionsFragment.java @@ -33,6 +33,7 @@ import jscl.math.function.Function; import jscl.math.function.IFunction; import org.solovyev.android.Check; import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.entities.EntityRemovalDialog; import org.solovyev.android.calculator.functions.*; diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsActivity.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsActivity.java index 5cca9877..32c17e4d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsActivity.java @@ -29,6 +29,7 @@ import org.solovyev.android.calculator.CalculatorEventData; import org.solovyev.android.calculator.CalculatorEventListener; import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.android.calculator.CalculatorFragmentType; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.operators.OperatorCategory; import org.solovyev.android.calculator.R; diff --git a/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsFragment.java b/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsFragment.java index f4eda90c..5497d0ee 100644 --- a/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/math/edit/OperatorsFragment.java @@ -27,6 +27,7 @@ import android.view.ContextMenu; import android.view.MenuItem; import jscl.math.operator.Operator; import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.Category; import org.solovyev.common.text.Strings; diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorCategory.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorCategory.java index 20c9eb90..e546a883 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorCategory.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorCategory.java @@ -23,28 +23,14 @@ package org.solovyev.android.calculator.operators; import android.support.annotation.StringRes; - +import jscl.math.operator.*; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.entities.Category; import javax.annotation.Nonnull; -import jscl.math.operator.Derivative; -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; - public enum OperatorCategory implements Category { - my(R.string.c_fun_category_my) { - @Override - public boolean isInCategory(@Nonnull Operator operator) { - return !operator.isSystem(); - } - }, - common(R.string.c_fun_category_common) { @Override public boolean isInCategory(@Nonnull Operator operator) { diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java index 9c1edd88..66109359 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java @@ -23,18 +23,15 @@ package org.solovyev.android.calculator.variables; import android.os.Bundle; -import android.support.v4.app.Fragment; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.R; -import javax.annotation.Nonnull; import javax.annotation.Nullable; public class VariablesActivity extends BaseActivity { public static final String EXTRA_VARIABLE = "variable"; - private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.variables; public VariablesActivity() { super(R.layout.main_empty, VariablesActivity.class.getSimpleName()); @@ -45,7 +42,7 @@ public class VariablesActivity extends BaseActivity { super.onCreate(savedInstanceState); for (VariableCategory category : VariableCategory.values()) { - addTab(category); + addTab(category, CalculatorFragmentType.variables); } if (savedInstanceState == null) { @@ -56,12 +53,4 @@ public class VariablesActivity extends BaseActivity { } } } - - private void addTab(@Nonnull VariableCategory category) { - final Bundle arguments = new Bundle(1); - arguments.putString(VariablesFragment.ARG_CATEGORY, category.name()); - final String fragmentTag = FRAGMENT_TYPE.createSubFragmentTag(category.name()); - final Class fragmentClass = FRAGMENT_TYPE.getFragmentClass(); - ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title(), R.id.main_layout); - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java index 77d9769d..69f63100 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java @@ -35,7 +35,7 @@ import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.entities.EntityRemovalDialog; import org.solovyev.android.calculator.math.MathType; -import org.solovyev.android.calculator.math.edit.BaseEntitiesFragment; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.common.JPredicate; import org.solovyev.common.collections.Collections; import org.solovyev.common.text.Strings; @@ -160,10 +160,7 @@ public class VariablesFragment extends BaseEntitiesFragment { }); return true; case R.string.c_copy_value: - final String value = constant.getValue(); - if (!Strings.isEmpty(value)) { - Locator.getInstance().getClipboard().setText(value); - } + copyText(constant.getValue()); return true; } return false; diff --git a/jscl/src/main/java/jscl/text/ParserUtils.java b/jscl/src/main/java/jscl/text/ParserUtils.java index a5f39710..86b67cc7 100644 --- a/jscl/src/main/java/jscl/text/ParserUtils.java +++ b/jscl/src/main/java/jscl/text/ParserUtils.java @@ -1,14 +1,13 @@ package jscl.text; -import java.lang.reflect.Array; -import java.util.Collections; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import jscl.math.Generic; import jscl.text.msg.Messages; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.lang.reflect.Array; +import java.util.Collections; + /** * User: serso * Date: 10/27/11 @@ -130,7 +129,7 @@ public class ParserUtils { } public static T[] copyOf(U[] array, int newLength, Class newType) { - T[] copy = (newType == Object[].class) + T[] copy = ((Object) newType == (Object) Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength);