This commit is contained in:
serso 2016-01-31 09:54:14 +01:00
parent c68b6c5803
commit a67a647add
11 changed files with 13 additions and 216 deletions

View File

@ -87,7 +87,7 @@
android:label="@string/c_functions" />
<activity
android:name=".math.edit.OperatorsActivity"
android:name=".operators.OperatorsActivity"
android:label="@string/c_operators" />
<activity

View File

@ -4,7 +4,7 @@ import dagger.Component;
import org.solovyev.android.calculator.functions.EditFunctionFragment;
import org.solovyev.android.calculator.history.BaseHistoryFragment;
import org.solovyev.android.calculator.history.EditHistoryFragment;
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
import org.solovyev.android.calculator.functions.FunctionsFragment;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
import org.solovyev.android.calculator.variables.EditVariableFragment;
import org.solovyev.android.calculator.variables.VariablesFragment;

View File

@ -40,7 +40,7 @@ import org.solovyev.android.calculator.functions.CppFunction;
import org.solovyev.android.calculator.functions.EditFunctionFragment;
import org.solovyev.android.calculator.functions.FunctionsActivity;
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.math.edit.OperatorsActivity;
import org.solovyev.android.calculator.operators.OperatorsActivity;
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotter;

View File

@ -78,25 +78,9 @@ public enum CalculatorEventType {
**********************************************************************
*/
// @Nonnull IConstant
use_constant,
// @Nonnull Operator
use_operator,
// @Nonnull IConstant
constant_added,
// @Nonnull Change<IConstant>
constant_changed,
// @Nonnull IConstant
constant_removed,
// @Nonnull Function
function_removed,
/*
**********************************************************************
*

View File

@ -28,8 +28,8 @@ import org.solovyev.android.calculator.about.CalculatorAboutFragment;
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
import org.solovyev.android.calculator.history.RecentHistoryFragment;
import org.solovyev.android.calculator.history.SavedHistoryFragment;
import org.solovyev.android.calculator.math.edit.FunctionsFragment;
import org.solovyev.android.calculator.math.edit.OperatorsFragment;
import org.solovyev.android.calculator.functions.FunctionsFragment;
import org.solovyev.android.calculator.operators.OperatorsFragment;
import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;

View File

@ -56,7 +56,7 @@ public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
public static final String ANS = "ans";
@Nonnull
private static final Map<String, String> substitutes = new HashMap<String, String>();
private static final Map<String, String> substitutes = new HashMap<>();
static {
substitutes.put("π", "pi");

View File

@ -242,7 +242,7 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
}
}
public class EntitiesAdapter extends RecyclerView.Adapter<EntityViewHolder> {
private class EntitiesAdapter extends RecyclerView.Adapter<EntityViewHolder> {
@Nonnull
private final LayoutInflater inflater;
@Nonnull

View File

@ -20,7 +20,7 @@
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
package org.solovyev.android.calculator.functions;
import android.content.DialogInterface;
import android.os.Bundle;
@ -36,7 +36,6 @@ 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.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

View File

@ -1,176 +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.math.edit;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.TextView;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.EntitiesRegistry;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.common.math.MathEntity;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.math.function.IConstant;
/**
* User: serso
* Date: 12/22/11
* Time: 9:36 PM
*/
public class MathEntityRemover<T extends MathEntity> implements View.OnClickListener, DialogInterface.OnClickListener {
@Nonnull
private final T mathEntity;
@Nullable
private final DialogInterface.OnClickListener callbackOnCancel;
private final boolean confirmed;
@Nonnull
private final EntitiesRegistry<? super T> varsRegistry;
@Nonnull
private final Object source;
@Nonnull
private final Params params;
@Nonnull
private Context context;
/*
**********************************************************************
*
* CONSTRUCTORS
*
**********************************************************************
*/
private MathEntityRemover(@Nonnull T mathEntity,
@Nullable DialogInterface.OnClickListener callbackOnCancel,
boolean confirmed,
@Nonnull EntitiesRegistry<? super T> varsRegistry,
@Nonnull Context context,
@Nonnull Object source,
@Nonnull Params params) {
this.mathEntity = mathEntity;
this.callbackOnCancel = callbackOnCancel;
this.confirmed = confirmed;
this.varsRegistry = varsRegistry;
this.context = context;
this.source = source;
this.params = params;
}
public static MathEntityRemover<IConstant> newConstantRemover(@Nonnull IConstant constant,
@Nullable DialogInterface.OnClickListener callbackOnCancel,
@Nonnull Context context,
@Nonnull Object source) {
return new MathEntityRemover<IConstant>(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVariablesRegistry(), context, source, Params.newConstantInstance());
}
/*
**********************************************************************
*
* METHODS
*
**********************************************************************
*/
public void showConfirmationDialog() {
final TextView question = new TextView(context);
question.setText(String.format(context.getString(params.getRemovalConfirmationQuestionResId()), mathEntity.getName()));
question.setPadding(6, 6, 6, 6);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(true)
.setView(question)
.setTitle(params.getRemovalConfirmationTitleResId())
.setNegativeButton(R.string.c_no, callbackOnCancel)
.setPositiveButton(R.string.c_yes, new MathEntityRemover<T>(mathEntity, callbackOnCancel, true, varsRegistry, context, source, params));
builder.create().show();
}
@Override
public void onClick(@Nullable View v) {
if (!confirmed) {
showConfirmationDialog();
} else {
varsRegistry.remove(mathEntity);
varsRegistry.save();
Locator.getInstance().getCalculator().fireCalculatorEvent(params.getCalculatorEventType(), mathEntity, source);
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
onClick(null);
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private static final class Params {
private int removalConfirmationTitleResId;
private int removalConfirmationQuestionResId;
private CalculatorEventType calculatorEventType;
private Params() {
}
private static <T extends MathEntity> Params newConstantInstance() {
final Params result = new Params();
result.removalConfirmationTitleResId = R.string.removal_confirmation;
result.removalConfirmationQuestionResId = R.string.c_var_removal_confirmation_question;
result.calculatorEventType = CalculatorEventType.constant_removed;
return result;
}
public int getRemovalConfirmationTitleResId() {
return removalConfirmationTitleResId;
}
public int getRemovalConfirmationQuestionResId() {
return removalConfirmationQuestionResId;
}
public CalculatorEventType getCalculatorEventType() {
return calculatorEventType;
}
}
}

View File

@ -20,18 +20,10 @@
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
package org.solovyev.android.calculator.operators;
import android.os.Bundle;
import org.solovyev.android.calculator.BaseActivity;
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;
import org.solovyev.android.calculator.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -46,10 +38,8 @@ public class OperatorsActivity extends BaseActivity implements CalculatorEventLi
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final CalculatorFragmentType fragmentType = CalculatorFragmentType.operators;
for (OperatorCategory category : OperatorCategory.values()) {
ui.addTab(this, fragmentType.createSubFragmentTag(category.name()), fragmentType.getFragmentClass(), BaseEntitiesFragment.createBundleFor(category.name()), category.title(), R.id.main_layout);
addTab(category, CalculatorFragmentType.operators);
}
}

View File

@ -20,7 +20,7 @@
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
package org.solovyev.android.calculator.operators;
import android.support.annotation.NonNull;
import android.view.ContextMenu;