Changes
This commit is contained in:
parent
3797f26330
commit
c68b6c5803
@ -223,14 +223,23 @@ public class ActivityUi extends BaseUi {
|
|||||||
@Nonnull String tag,
|
@Nonnull String tag,
|
||||||
@Nonnull Class<? extends Fragment> fragmentClass,
|
@Nonnull Class<? extends Fragment> fragmentClass,
|
||||||
@Nullable Bundle fragmentArgs,
|
@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<? extends Fragment> fragmentClass,
|
||||||
|
@Nullable Bundle fragmentArgs,
|
||||||
|
@Nullable CharSequence title,
|
||||||
int parentViewId) {
|
int parentViewId) {
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
Check.isNotNull(actionBar);
|
Check.isNotNull(actionBar);
|
||||||
|
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
final ActionBar.Tab tab = actionBar.newTab();
|
||||||
tab.setTag(tag);
|
tab.setTag(tag);
|
||||||
tab.setText(captionResId);
|
tab.setText(title);
|
||||||
|
|
||||||
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
|
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
|
||||||
tab.setTabListener(listener);
|
tab.setTabListener(listener);
|
||||||
|
@ -2,11 +2,15 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MenuItem;
|
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.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BaseActivity extends AppCompatActivity {
|
public class BaseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -92,4 +96,17 @@ public class BaseActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
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<? extends Fragment> fragmentClass = type.getFragmentClass();
|
||||||
|
ui.addTab(this, fragmentTag, fragmentClass, arguments, title, R.id.main_layout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.entities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
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.BaseFragment;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.entities.Category;
|
|
||||||
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;
|
||||||
@ -63,8 +61,6 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private final Handler uiHandler = new Handler();
|
|
||||||
@Bind(R.id.entities_fab)
|
@Bind(R.id.entities_fab)
|
||||||
public FloatingActionButton fab;
|
public FloatingActionButton fab;
|
||||||
@Bind(R.id.entities_recyclerview)
|
@Bind(R.id.entities_recyclerview)
|
||||||
@ -150,18 +146,13 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
|
|||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
protected Handler getUiHandler() {
|
|
||||||
return uiHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
protected final void copyDescription(@Nonnull E entity) {
|
protected final void copyText(@Nullable String text) {
|
||||||
final String description = getDescription(entity);
|
if (!Strings.isEmpty(text)) {
|
||||||
if (!Strings.isEmpty(description)) {
|
return;
|
||||||
final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(description);
|
|
||||||
}
|
}
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onEntityAdded(@NonNull E entity) {
|
protected void onEntityAdded(@NonNull E entity) {
|
||||||
@ -288,11 +279,6 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
|
|||||||
list.set(position, entity);
|
list.set(position, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort() {
|
|
||||||
Collections.sort(list, COMPARATOR);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(@Nonnull E entity) {
|
public void add(@Nonnull E entity) {
|
||||||
final int itemCount = getItemCount();
|
final int itemCount = getItemCount();
|
||||||
for (int i = 0; i < itemCount; i++) {
|
for (int i = 0; i < itemCount; i++) {
|
@ -23,19 +23,16 @@
|
|||||||
package org.solovyev.android.calculator.functions;
|
package org.solovyev.android.calculator.functions;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
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.R;
|
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;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class FunctionsActivity extends BaseActivity {
|
public class FunctionsActivity extends BaseActivity {
|
||||||
|
|
||||||
public static final String EXTRA_FUNCTION = "function";
|
public static final String EXTRA_FUNCTION = "function";
|
||||||
private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.functions;
|
|
||||||
|
|
||||||
public FunctionsActivity() {
|
public FunctionsActivity() {
|
||||||
super(R.layout.main_empty, FunctionsActivity.class.getSimpleName());
|
super(R.layout.main_empty, FunctionsActivity.class.getSimpleName());
|
||||||
@ -46,7 +43,11 @@ public class FunctionsActivity extends BaseActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
for (FunctionCategory category : FunctionCategory.values()) {
|
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) {
|
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<? extends Fragment> fragmentClass = FRAGMENT_TYPE.getFragmentClass();
|
|
||||||
ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title, R.id.main_layout);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -33,6 +33,7 @@ import jscl.math.function.Function;
|
|||||||
import jscl.math.function.IFunction;
|
import jscl.math.function.IFunction;
|
||||||
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.entities.BaseEntitiesFragment;
|
||||||
import org.solovyev.android.calculator.entities.Category;
|
import org.solovyev.android.calculator.entities.Category;
|
||||||
import org.solovyev.android.calculator.entities.EntityRemovalDialog;
|
import org.solovyev.android.calculator.entities.EntityRemovalDialog;
|
||||||
import org.solovyev.android.calculator.functions.*;
|
import org.solovyev.android.calculator.functions.*;
|
||||||
|
@ -29,6 +29,7 @@ import org.solovyev.android.calculator.CalculatorEventData;
|
|||||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||||
import org.solovyev.android.calculator.CalculatorEventType;
|
import org.solovyev.android.calculator.CalculatorEventType;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
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.operators.OperatorCategory;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import android.view.ContextMenu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import jscl.math.operator.Operator;
|
import jscl.math.operator.Operator;
|
||||||
import org.solovyev.android.calculator.*;
|
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.Category;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
|
@ -23,28 +23,14 @@
|
|||||||
package org.solovyev.android.calculator.operators;
|
package org.solovyev.android.calculator.operators;
|
||||||
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
|
import jscl.math.operator.*;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.entities.Category;
|
import org.solovyev.android.calculator.entities.Category;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
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<Operator> {
|
public enum OperatorCategory implements Category<Operator> {
|
||||||
|
|
||||||
my(R.string.c_fun_category_my) {
|
|
||||||
@Override
|
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
|
||||||
return !operator.isSystem();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
common(R.string.c_fun_category_common) {
|
common(R.string.c_fun_category_common) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInCategory(@Nonnull Operator operator) {
|
public boolean isInCategory(@Nonnull Operator operator) {
|
||||||
|
@ -23,18 +23,15 @@
|
|||||||
package org.solovyev.android.calculator.variables;
|
package org.solovyev.android.calculator.variables;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
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.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class VariablesActivity extends BaseActivity {
|
public class VariablesActivity extends BaseActivity {
|
||||||
|
|
||||||
public static final String EXTRA_VARIABLE = "variable";
|
public static final String EXTRA_VARIABLE = "variable";
|
||||||
private static final CalculatorFragmentType FRAGMENT_TYPE = CalculatorFragmentType.variables;
|
|
||||||
|
|
||||||
public VariablesActivity() {
|
public VariablesActivity() {
|
||||||
super(R.layout.main_empty, VariablesActivity.class.getSimpleName());
|
super(R.layout.main_empty, VariablesActivity.class.getSimpleName());
|
||||||
@ -45,7 +42,7 @@ public class VariablesActivity extends BaseActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
for (VariableCategory category : VariableCategory.values()) {
|
for (VariableCategory category : VariableCategory.values()) {
|
||||||
addTab(category);
|
addTab(category, CalculatorFragmentType.variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
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<? extends Fragment> fragmentClass = FRAGMENT_TYPE.getFragmentClass();
|
|
||||||
ui.addTab(this, fragmentTag, fragmentClass, arguments, category.title(), R.id.main_layout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ import org.solovyev.android.calculator.*;
|
|||||||
import org.solovyev.android.calculator.entities.Category;
|
import org.solovyev.android.calculator.entities.Category;
|
||||||
import org.solovyev.android.calculator.entities.EntityRemovalDialog;
|
import org.solovyev.android.calculator.entities.EntityRemovalDialog;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
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.JPredicate;
|
||||||
import org.solovyev.common.collections.Collections;
|
import org.solovyev.common.collections.Collections;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
@ -160,10 +160,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
case R.string.c_copy_value:
|
case R.string.c_copy_value:
|
||||||
final String value = constant.getValue();
|
copyText(constant.getValue());
|
||||||
if (!Strings.isEmpty(value)) {
|
|
||||||
Locator.getInstance().getClipboard().setText(value);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package jscl.text;
|
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.math.Generic;
|
||||||
import jscl.text.msg.Messages;
|
import jscl.text.msg.Messages;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/27/11
|
* Date: 10/27/11
|
||||||
@ -130,7 +129,7 @@ public class ParserUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U> T[] copyOf(U[] array, int newLength, Class<? extends T[]> newType) {
|
public static <T, U> T[] copyOf(U[] array, int newLength, Class<? extends T[]> newType) {
|
||||||
T[] copy = (newType == Object[].class)
|
T[] copy = ((Object) newType == (Object) Object[].class)
|
||||||
? (T[]) new Object[newLength]
|
? (T[]) new Object[newLength]
|
||||||
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user