Greek keyboard
This commit is contained in:
parent
f914704a9c
commit
37c40001d7
@ -29,37 +29,34 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import jscl.math.Generic;
|
||||||
|
import jscl.math.function.Constant;
|
||||||
import org.solovyev.android.Activities;
|
import org.solovyev.android.Activities;
|
||||||
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
||||||
import org.solovyev.android.calculator.functions.CppFunction;
|
import org.solovyev.android.calculator.functions.CppFunction;
|
||||||
import org.solovyev.android.calculator.functions.EditFunctionFragment;
|
import org.solovyev.android.calculator.functions.EditFunctionFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
|
||||||
import org.solovyev.android.calculator.functions.FunctionsActivity;
|
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.math.edit.OperatorsActivity;
|
||||||
import org.solovyev.android.calculator.variables.VariablesActivity;
|
|
||||||
import org.solovyev.android.calculator.variables.EditVariableFragment;
|
|
||||||
import org.solovyev.android.calculator.variables.VariablesFragment;
|
|
||||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||||
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
import org.solovyev.android.calculator.preferences.PreferencesActivity;
|
||||||
|
import org.solovyev.android.calculator.variables.CppVariable;
|
||||||
|
import org.solovyev.android.calculator.variables.EditVariableFragment;
|
||||||
|
import org.solovyev.android.calculator.variables.VariablesActivity;
|
||||||
|
import org.solovyev.android.calculator.variables.VariablesFragment;
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.common.msg.Message;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
import jscl.math.Generic;
|
import java.util.Set;
|
||||||
import jscl.math.function.Constant;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -140,19 +137,12 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
|
|||||||
|
|
||||||
public static void tryCreateVar(@Nonnull final Context context) {
|
public static void tryCreateVar(@Nonnull final Context context) {
|
||||||
final Display display = App.getDisplay();
|
final Display display = App.getDisplay();
|
||||||
final DisplayState viewState = display.getState();
|
final DisplayState state = display.getState();
|
||||||
if (viewState.valid) {
|
if (state.valid) {
|
||||||
final String varValue = viewState.text;
|
final String value = state.text;
|
||||||
if (!Strings.isEmpty(varValue)) {
|
if (!Strings.isEmpty(value)) {
|
||||||
if (VariablesFragment.isValidValue(varValue)) {
|
if (VariablesFragment.isValidValue(value)) {
|
||||||
if (context instanceof AppCompatActivity) {
|
EditVariableFragment.showDialog(CppVariable.builder("").withValue(value).build(), context);
|
||||||
EditVariableFragment.showDialog(EditVariableFragment.Input.newFromValue(varValue), ((AppCompatActivity) context).getSupportFragmentManager());
|
|
||||||
} else {
|
|
||||||
final Intent intent = new Intent(context, VariablesActivity.class);
|
|
||||||
intent.putExtra(VariablesFragment.CREATE_VAR_EXTRA_STRING, varValue);
|
|
||||||
Activities.addIntentFlags(intent, false, context);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
getNotifier().showMessage(R.string.c_value_is_not_a_number, MessageType.error);
|
getNotifier().showMessage(R.string.c_value_is_not_a_number, MessageType.error);
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,16 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.os.Build;
|
|
||||||
import android.support.annotation.ColorInt;
|
|
||||||
import android.support.annotation.DrawableRes;
|
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard;
|
||||||
|
import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
|
||||||
import org.solovyev.android.calculator.view.EditTextLongClickEraser;
|
import org.solovyev.android.calculator.view.EditTextLongClickEraser;
|
||||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||||
import org.solovyev.android.views.dragbutton.DragButton;
|
import org.solovyev.android.views.dragbutton.DragButton;
|
||||||
@ -33,35 +23,20 @@ import static org.solovyev.android.views.dragbutton.DirectionDragButton.Directio
|
|||||||
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.up;
|
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.up;
|
||||||
|
|
||||||
|
|
||||||
public class KeyboardUi {
|
public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ButtonHandler buttonHandler = new ButtonHandler();
|
private final ButtonHandler buttonHandler = new ButtonHandler();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final User user;
|
|
||||||
@NonNull
|
|
||||||
private final List<String> parameterNames;
|
private final List<String> parameterNames;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SimpleDragListener dragListener;
|
private final SimpleDragListener dragListener;
|
||||||
@ColorInt
|
|
||||||
private final int textColor;
|
|
||||||
@ColorInt
|
|
||||||
private final int textColorSecondary;
|
|
||||||
private final int sidePadding;
|
|
||||||
@DrawableRes
|
|
||||||
private final int buttonBackground;
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String multiplicationSign = Locator.getInstance().getEngine().getMultiplicationSign();
|
private final String multiplicationSign = Locator.getInstance().getEngine().getMultiplicationSign();
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
public FloatingCalculatorKeyboard(@NonNull User user, @NonNull List<String> parameterNames) {
|
||||||
public KeyboardUi(@NonNull User user, @NonNull List<String> parameterNames) {
|
super(user);
|
||||||
this.user = user;
|
|
||||||
this.parameterNames = parameterNames;
|
this.parameterNames = parameterNames;
|
||||||
this.dragListener = new SimpleDragListener(buttonHandler, user.getContext());
|
this.dragListener = new SimpleDragListener(buttonHandler, user.getContext());
|
||||||
final Resources resources = user.getResources();
|
|
||||||
textColor = resources.getColor(R.color.cpp_kb_button_text);
|
|
||||||
textColorSecondary = resources.getColor(R.color.cpp_kb_button_text);
|
|
||||||
sidePadding = resources.getDimensionPixelSize(R.dimen.cpp_button_padding);
|
|
||||||
buttonBackground = App.getTheme().light ? R.drawable.material_button_light : R.drawable.material_button_dark;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makeView(boolean landscape) {
|
public void makeView(boolean landscape) {
|
||||||
@ -72,6 +47,26 @@ public class KeyboardUi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public User getUser() {
|
||||||
|
return (User) super.getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void fillButton(@NonNull View button, @IdRes int id) {
|
||||||
|
super.fillButton(button, id);
|
||||||
|
button.setOnClickListener(buttonHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected DirectionDragButton makeButton(@IdRes int id, @NonNull String text) {
|
||||||
|
final DirectionDragButton button = super.makeButton(id, text);
|
||||||
|
button.setOnDragListener(dragListener);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
private void makeViewLand() {
|
private void makeViewLand() {
|
||||||
final int parametersCount = parameterNames.size();
|
final int parametersCount = parameterNames.size();
|
||||||
|
|
||||||
@ -146,74 +141,6 @@ public class KeyboardUi {
|
|||||||
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
|
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private View addImageButton(@NonNull LinearLayout row, @IdRes int id, @DrawableRes int icon) {
|
|
||||||
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
lp.weight = 1f;
|
|
||||||
final View view = makeImageButton(id, icon);
|
|
||||||
row.addView(view, lp);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private DirectionDragButton addOperationButton(@NonNull LinearLayout row, @IdRes int id, @NonNull String text) {
|
|
||||||
final DirectionDragButton button = addButton(row, id, text);
|
|
||||||
button.setBackgroundResource(R.drawable.material_button_light_primary);
|
|
||||||
button.setTextColor(Color.WHITE);
|
|
||||||
button.setDirectionTextColor(Color.WHITE);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private DirectionDragButton addButton(@NonNull LinearLayout row, @IdRes int id, @NonNull String text) {
|
|
||||||
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
lp.weight = 1f;
|
|
||||||
final DirectionDragButton view = makeButton(id, text);
|
|
||||||
row.addView(view, lp);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private LinearLayout makeRow() {
|
|
||||||
final LinearLayout row = new LinearLayout(user.getContext());
|
|
||||||
row.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
|
||||||
lp.weight = 1f;
|
|
||||||
user.getKeyboard().addView(row, lp);
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private DirectionDragButton makeButton(@IdRes int id, @NonNull String text) {
|
|
||||||
final DirectionDragButton button = new DirectionDragButton(user.getContext());
|
|
||||||
fillButton(button, id);
|
|
||||||
button.setText(text);
|
|
||||||
button.setTextColor(textColor);
|
|
||||||
button.setDirectionTextColor(textColorSecondary);
|
|
||||||
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
|
|
||||||
button.setOnDragListener(dragListener);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillButton(@NonNull View button, @IdRes int id) {
|
|
||||||
button.setOnClickListener(buttonHandler);
|
|
||||||
button.setId(id);
|
|
||||||
button.setBackgroundResource(buttonBackground);
|
|
||||||
button.setPadding(sidePadding, 1, sidePadding, 1);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
button.setStateListAnimator(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private View makeImageButton(@IdRes int id, @DrawableRes int icon) {
|
|
||||||
final ImageButton button = new ImageButton(user.getContext());
|
|
||||||
fillButton(button, id);
|
|
||||||
button.setImageResource(icon);
|
|
||||||
button.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRowsCount(boolean landscape) {
|
public int getRowsCount(boolean landscape) {
|
||||||
return landscape ? 3 : 5;
|
return landscape ? 3 : 5;
|
||||||
}
|
}
|
||||||
@ -222,18 +149,7 @@ public class KeyboardUi {
|
|||||||
return landscape ? 8 : 5;
|
return landscape ? 8 : 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface User {
|
public interface User extends FloatingKeyboard.User {
|
||||||
@NonNull
|
|
||||||
Context getContext();
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
Resources getResources();
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
EditText getEditor();
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
ViewGroup getKeyboard();
|
|
||||||
|
|
||||||
void insertOperator(char operator);
|
void insertOperator(char operator);
|
||||||
|
|
||||||
@ -243,16 +159,17 @@ public class KeyboardUi {
|
|||||||
|
|
||||||
void showConstants(@NonNull View v);
|
void showConstants(@NonNull View v);
|
||||||
|
|
||||||
|
void showFunctionsConstants(@NonNull View v);
|
||||||
|
|
||||||
void insertText(@NonNull CharSequence text, int offset);
|
void insertText(@NonNull CharSequence text, int offset);
|
||||||
|
|
||||||
void done();
|
|
||||||
|
|
||||||
void showIme();
|
|
||||||
|
|
||||||
void showFunctionsConstants(@NonNull View v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ButtonHandler implements View.OnClickListener, SimpleDragListener.DragProcessor {
|
private class ButtonHandler implements View.OnClickListener, SimpleDragListener.DragProcessor {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final User user = getUser();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NonNull View v) {
|
public void onClick(@NonNull View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
@ -33,7 +33,6 @@ import android.support.design.widget.TextInputLayout;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
@ -43,8 +42,10 @@ import android.widget.EditText;
|
|||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jscl.math.function.Function;
|
import jscl.math.function.Function;
|
||||||
|
import org.solovyev.android.Activities;
|
||||||
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.keyboard.FloatingKeyboardWindow;
|
||||||
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.android.calculator.view.EditTextCompat;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
@ -66,7 +67,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final VariablesRegistry constantsRegistry = Locator.getInstance().getEngine().getVariablesRegistry();
|
private final VariablesRegistry constantsRegistry = Locator.getInstance().getEngine().getVariablesRegistry();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final KeyboardWindow keyboardWindow = new KeyboardWindow();
|
private final FloatingKeyboardWindow keyboardWindow = new FloatingKeyboardWindow();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final KeyboardUser keyboardUser = new KeyboardUser();
|
private final KeyboardUser keyboardUser = new KeyboardUser();
|
||||||
@Bind(R.id.function_params)
|
@Bind(R.id.function_params)
|
||||||
@ -103,14 +104,14 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
EditFunctionFragment.showDialog(null, activity.getSupportFragmentManager());
|
EditFunctionFragment.showDialog(null, activity.getSupportFragmentManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showDialog(@Nonnull CppFunction function, @Nonnull Context context) {
|
public static void showDialog(@Nullable CppFunction function, @Nonnull Context context) {
|
||||||
if (!(context instanceof FunctionsActivity)) {
|
if (!(context instanceof FunctionsActivity)) {
|
||||||
final Intent intent = new Intent(context, FunctionsActivity.class);
|
final Intent intent = new Intent(context, FunctionsActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
Activities.addIntentFlags(intent, false, context);
|
||||||
intent.putExtra(FunctionsActivity.EXTRA_FUNCTION, function);
|
intent.putExtra(FunctionsActivity.EXTRA_FUNCTION, function);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
EditFunctionFragment.showDialog(function, ((AppCompatActivity) context).getSupportFragmentManager());
|
EditFunctionFragment.showDialog(function, ((FunctionsActivity) context).getSupportFragmentManager());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +229,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showKeyboard() {
|
private void showKeyboard() {
|
||||||
keyboardWindow.show(keyboardUser, getDialog(), collectParameters());
|
keyboardWindow.show(new FloatingCalculatorKeyboard(keyboardUser, collectParameters()), getDialog());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -379,7 +380,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KeyboardUser implements KeyboardUi.User, MenuItem.OnMenuItemClickListener {
|
private class KeyboardUser implements FloatingCalculatorKeyboard.User, MenuItem.OnMenuItemClickListener {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
|
@ -52,7 +52,7 @@ public class FunctionsActivity extends BaseActivity {
|
|||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
final Bundle extras = getIntent().getExtras();
|
final Bundle extras = getIntent().getExtras();
|
||||||
final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null;
|
final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null;
|
||||||
EditFunctionFragment.showDialog(function, getSupportFragmentManager());
|
EditFunctionFragment.showDialog(function, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,117 @@
|
|||||||
|
package org.solovyev.android.calculator.keyboard;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.IdRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import org.solovyev.android.calculator.App;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||||
|
|
||||||
|
public abstract class BaseFloatingKeyboard implements FloatingKeyboard {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final User user;
|
||||||
|
@ColorInt
|
||||||
|
private final int textColor;
|
||||||
|
@ColorInt
|
||||||
|
private final int textColorSecondary;
|
||||||
|
private final int sidePadding;
|
||||||
|
@DrawableRes
|
||||||
|
private final int buttonBackground;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
protected BaseFloatingKeyboard(@NonNull User user) {
|
||||||
|
this.user = user;
|
||||||
|
final Resources resources = user.getResources();
|
||||||
|
textColor = resources.getColor(R.color.cpp_kb_button_text);
|
||||||
|
textColorSecondary = resources.getColor(R.color.cpp_kb_button_text);
|
||||||
|
sidePadding = resources.getDimensionPixelSize(R.dimen.cpp_button_padding);
|
||||||
|
buttonBackground = App.getTheme().light ? R.drawable.material_button_light : R.drawable.material_button_dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final LinearLayout makeRow() {
|
||||||
|
final LinearLayout row = new LinearLayout(user.getContext());
|
||||||
|
row.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
||||||
|
lp.weight = 1f;
|
||||||
|
user.getKeyboard().addView(row, lp);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected DirectionDragButton makeButton(@IdRes int id, @NonNull String text) {
|
||||||
|
final DirectionDragButton button = new DirectionDragButton(user.getContext());
|
||||||
|
fillButton(button, id);
|
||||||
|
button.setText(text);
|
||||||
|
button.setTextColor(textColor);
|
||||||
|
button.setDirectionTextColor(textColorSecondary);
|
||||||
|
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
|
||||||
|
if (TextUtils.isEmpty(text)) {
|
||||||
|
button.setEnabled(false);
|
||||||
|
}
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillButton(@NonNull View button, @IdRes int id) {
|
||||||
|
button.setId(id);
|
||||||
|
button.setBackgroundResource(buttonBackground);
|
||||||
|
button.setPadding(sidePadding, 1, sidePadding, 1);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
button.setStateListAnimator(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final View makeImageButton(@IdRes int id, @DrawableRes int icon) {
|
||||||
|
final ImageButton button = new ImageButton(user.getContext());
|
||||||
|
fillButton(button, id);
|
||||||
|
button.setImageResource(icon);
|
||||||
|
button.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final View addImageButton(@NonNull LinearLayout row, @IdRes int id, @DrawableRes int icon) {
|
||||||
|
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
lp.weight = 1f;
|
||||||
|
final View view = makeImageButton(id, icon);
|
||||||
|
row.addView(view, lp);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final DirectionDragButton addOperationButton(@NonNull LinearLayout row, @IdRes int id, @NonNull String text) {
|
||||||
|
final DirectionDragButton button = addButton(row, id, text);
|
||||||
|
button.setBackgroundResource(R.drawable.material_button_light_primary);
|
||||||
|
button.setTextColor(Color.WHITE);
|
||||||
|
button.setDirectionTextColor(Color.WHITE);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected final DirectionDragButton addButton(@NonNull LinearLayout row, @IdRes int id, @NonNull String text) {
|
||||||
|
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
lp.weight = 1f;
|
||||||
|
final DirectionDragButton view = makeButton(id, text);
|
||||||
|
row.addView(view, lp);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package org.solovyev.android.calculator.keyboard;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
public interface FloatingKeyboard {
|
||||||
|
int getRowsCount(boolean landscape);
|
||||||
|
|
||||||
|
int getColumnsCount(boolean landscape);
|
||||||
|
|
||||||
|
void makeView(boolean landscape);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
User getUser();
|
||||||
|
|
||||||
|
interface User {
|
||||||
|
@NonNull
|
||||||
|
Context getContext();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
Resources getResources();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
EditText getEditor();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
ViewGroup getKeyboard();
|
||||||
|
|
||||||
|
void done();
|
||||||
|
|
||||||
|
void showIme();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator.keyboard;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -15,10 +15,9 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import java.util.List;
|
public class FloatingKeyboardWindow {
|
||||||
|
|
||||||
public class KeyboardWindow {
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private PopupWindow window;
|
private PopupWindow window;
|
||||||
@ -43,8 +42,8 @@ public class KeyboardWindow {
|
|||||||
dialog = null;
|
dialog = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(@NonNull KeyboardUi.User user, @Nullable Dialog dialog, @NonNull List<String> parameterNames) {
|
public void show(@NonNull FloatingKeyboard keyboard, @Nullable Dialog dialog) {
|
||||||
final EditText editor = user.getEditor();
|
final EditText editor = keyboard.getUser().getEditor();
|
||||||
if (isShown()) {
|
if (isShown()) {
|
||||||
hideIme(editor);
|
hideIme(editor);
|
||||||
return;
|
return;
|
||||||
@ -58,10 +57,9 @@ public class KeyboardWindow {
|
|||||||
|
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
final int buttonSize = resources.getDimensionPixelSize(R.dimen.cpp_clickable_area_size);
|
final int buttonSize = resources.getDimensionPixelSize(R.dimen.cpp_clickable_area_size);
|
||||||
final KeyboardUi keyboardUi = new KeyboardUi(user, parameterNames);
|
|
||||||
final boolean landscape = resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
final boolean landscape = resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||||
final int keyboardWidth = keyboardUi.getColumnsCount(landscape) * buttonSize;
|
final int keyboardWidth = keyboard.getColumnsCount(landscape) * buttonSize;
|
||||||
final int keyboardHeight = keyboardUi.getRowsCount(landscape) * buttonSize;
|
final int keyboardHeight = keyboard.getRowsCount(landscape) * buttonSize;
|
||||||
|
|
||||||
window = new PopupWindow(view, keyboardWidth, keyboardHeight);
|
window = new PopupWindow(view, keyboardWidth, keyboardHeight);
|
||||||
window.setClippingEnabled(false);
|
window.setClippingEnabled(false);
|
||||||
@ -89,7 +87,7 @@ public class KeyboardWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
keyboardUi.makeView(landscape);
|
keyboard.makeView(landscape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShown() {
|
public boolean isShown() {
|
@ -44,7 +44,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class FunctionsFragment extends BaseEntitiesFragment<Function> {
|
public class FunctionsFragment extends BaseEntitiesFragment<Function> {
|
||||||
|
|
||||||
public static final String ARG_FUNCTION = "function";
|
|
||||||
@Inject
|
@Inject
|
||||||
FunctionsRegistry registry;
|
FunctionsRegistry registry;
|
||||||
@Inject
|
@Inject
|
||||||
@ -58,21 +57,6 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
|
|||||||
super(CalculatorFragmentType.functions);
|
super(CalculatorFragmentType.functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
final Bundle bundle = getArguments();
|
|
||||||
if (bundle != null) {
|
|
||||||
final CppFunction function = bundle.getParcelable(ARG_FUNCTION);
|
|
||||||
if (function != null) {
|
|
||||||
EditFunctionFragment.showDialog(function, getFragmentManager());
|
|
||||||
// don't want to show it again
|
|
||||||
bundle.remove(ARG_FUNCTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(@Nonnull AppComponent component) {
|
protected void inject(@Nonnull AppComponent component) {
|
||||||
super.inject(component);
|
super.inject(component);
|
||||||
|
@ -87,13 +87,13 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final Integer error;
|
final Integer error;
|
||||||
|
|
||||||
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
|
final EditText editName = (EditText) editView.findViewById(R.id.variable_name);
|
||||||
String name = editName.getText().toString();
|
String name = editName.getText().toString();
|
||||||
|
|
||||||
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
|
final EditText editValue = (EditText) editView.findViewById(R.id.variable_value);
|
||||||
String value = editValue.getText().toString();
|
String value = editValue.getText().toString();
|
||||||
|
|
||||||
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
|
final EditText editDescription = (EditText) editView.findViewById(R.id.variable_description);
|
||||||
String description = editDescription.getText().toString();
|
String description = editDescription.getText().toString();
|
||||||
|
|
||||||
if (isValidName(name)) {
|
if (isValidName(name)) {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package org.solovyev.android.calculator.variables;
|
package org.solovyev.android.calculator.variables;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import jscl.math.function.IConstant;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.solovyev.android.Check;
|
import org.solovyev.android.Check;
|
||||||
@ -13,11 +15,9 @@ import org.solovyev.common.JBuilder;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import jscl.math.function.IConstant;
|
|
||||||
|
|
||||||
import static com.google.common.base.Strings.nullToEmpty;
|
import static com.google.common.base.Strings.nullToEmpty;
|
||||||
|
|
||||||
public class CppVariable implements Jsonable {
|
public class CppVariable implements Jsonable, Parcelable {
|
||||||
|
|
||||||
public static final Json.Creator<CppVariable> JSON_CREATOR = new Json.Creator<CppVariable>() {
|
public static final Json.Creator<CppVariable> JSON_CREATOR = new Json.Creator<CppVariable>() {
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -26,11 +26,20 @@ public class CppVariable implements Jsonable {
|
|||||||
return new CppVariable(json);
|
return new CppVariable(json);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
public static final Creator<CppVariable> CREATOR = new Creator<CppVariable>() {
|
||||||
|
@Override
|
||||||
|
public CppVariable createFromParcel(Parcel in) {
|
||||||
|
return new CppVariable(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CppVariable[] newArray(int size) {
|
||||||
|
return new CppVariable[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
private static final String JSON_NAME = "n";
|
private static final String JSON_NAME = "n";
|
||||||
private static final String JSON_VALUE = "v";
|
private static final String JSON_VALUE = "v";
|
||||||
private static final String JSON_DESCRIPTION = "d";
|
private static final String JSON_DESCRIPTION = "d";
|
||||||
|
|
||||||
protected int id = CppFunction.NO_ID;
|
protected int id = CppFunction.NO_ID;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected String name;
|
protected String name;
|
||||||
@ -66,6 +75,14 @@ public class CppVariable implements Jsonable {
|
|||||||
this.description = json.optString(JSON_DESCRIPTION);
|
this.description = json.optString(JSON_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CppVariable(Parcel in) {
|
||||||
|
id = in.readInt();
|
||||||
|
name = in.readString();
|
||||||
|
value = in.readString();
|
||||||
|
description = in.readString();
|
||||||
|
system = in.readByte() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static CppVariable.Builder builder(@NonNull String name) {
|
public static CppVariable.Builder builder(@NonNull String name) {
|
||||||
return new Builder(name);
|
return new Builder(name);
|
||||||
@ -121,6 +138,20 @@ public class CppVariable implements Jsonable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(id);
|
||||||
|
dest.writeString(name);
|
||||||
|
dest.writeString(value);
|
||||||
|
dest.writeString(description);
|
||||||
|
dest.writeByte((byte) (system ? 1 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CppVariable variable;
|
private final CppVariable variable;
|
||||||
|
@ -22,64 +22,180 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.variables;
|
package org.solovyev.android.calculator.variables;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.design.widget.TextInputLayout;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.*;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import jscl.math.function.IConstant;
|
import android.widget.Button;
|
||||||
import org.solovyev.android.Views;
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import org.solovyev.android.Activities;
|
||||||
|
import org.solovyev.android.Check;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.math.edit.MathEntityRemover;
|
import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
|
||||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
import org.solovyev.android.calculator.keyboard.FloatingKeyboardWindow;
|
||||||
|
import org.solovyev.android.calculator.view.EditTextCompat;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static android.graphics.Paint.UNDERLINE_TEXT_FLAG;
|
import static org.solovyev.android.calculator.functions.CppFunction.NO_ID;
|
||||||
import static android.view.View.GONE;
|
|
||||||
import static android.view.View.VISIBLE;
|
|
||||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
||||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
|
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
|
||||||
|
|
||||||
public class EditVariableFragment extends DialogFragment implements CalculatorEventListener {
|
public class EditVariableFragment extends BaseDialogFragment implements CalculatorEventListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnClickListener {
|
||||||
|
|
||||||
|
private static final String ARG_VARIABLE = "variable";
|
||||||
private final static String greekAlphabet = "αβγδεζηθικλμνξοπρστυφχψω";
|
private final static String greekAlphabet = "αβγδεζηθικλμνξοπρστυφχψω";
|
||||||
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects(("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_" + greekAlphabet).toCharArray()));
|
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects(("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_" + greekAlphabet).toCharArray()));
|
||||||
|
@NonNull
|
||||||
private Input input;
|
private final FloatingKeyboardWindow keyboardWindow = new FloatingKeyboardWindow();
|
||||||
|
@NonNull
|
||||||
|
private final KeyboardUser keyboardUser = new KeyboardUser();
|
||||||
|
@Bind(R.id.variable_name_label)
|
||||||
|
TextInputLayout nameLabel;
|
||||||
|
@Bind(R.id.variable_name)
|
||||||
|
EditTextCompat nameView;
|
||||||
|
@Bind(R.id.variable_keyboard_button)
|
||||||
|
Button keyboardButton;
|
||||||
|
@Bind(R.id.variable_value_label)
|
||||||
|
TextInputLayout valueLabel;
|
||||||
|
@Bind(R.id.variable_value)
|
||||||
|
EditText valueView;
|
||||||
|
@Bind(R.id.variable_description)
|
||||||
|
EditText descriptionView;
|
||||||
|
@Nullable
|
||||||
|
private CppVariable variable;
|
||||||
|
|
||||||
public EditVariableFragment() {
|
public EditVariableFragment() {
|
||||||
input = Input.newInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static EditVariableFragment create(@Nonnull Input input) {
|
public static EditVariableFragment create(@Nullable CppVariable variable) {
|
||||||
final EditVariableFragment fragment = new EditVariableFragment();
|
final EditVariableFragment fragment = new EditVariableFragment();
|
||||||
fragment.input = input;
|
if (variable != null) {
|
||||||
|
final Bundle args = new Bundle();
|
||||||
|
args.putParcelable(ARG_VARIABLE, variable);
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showDialog(@Nonnull Input input, @Nonnull FragmentManager fm) {
|
public static void showDialog(@Nonnull FragmentActivity activity) {
|
||||||
App.showDialog(create(input), "constant-editor", fm);
|
EditVariableFragment.showDialog(null, activity.getSupportFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDialog(@Nullable CppVariable variable, @Nonnull Context context) {
|
||||||
|
if (!(context instanceof VariablesActivity)) {
|
||||||
|
final Intent intent = new Intent(context, VariablesActivity.class);
|
||||||
|
Activities.addIntentFlags(intent, false, context);
|
||||||
|
intent.putExtra(VariablesActivity.EXTRA_VARIABLE, variable);
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
EditVariableFragment.showDialog(variable, ((VariablesActivity) context).getSupportFragmentManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDialog(@Nullable CppVariable variable, @Nonnull FragmentManager fm) {
|
||||||
|
App.showDialog(create(variable), "variable-editor", fm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public void onCreate(@android.support.annotation.Nullable Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.var_edit, container, false);
|
super.onCreate(savedInstanceState);
|
||||||
|
final Bundle arguments = getArguments();
|
||||||
|
if (arguments != null) {
|
||||||
|
variable = arguments.getParcelable(ARG_VARIABLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPrepareDialog(@NonNull AlertDialog.Builder builder) {
|
||||||
|
builder.setNegativeButton(R.string.c_cancel, null);
|
||||||
|
builder.setPositiveButton(R.string.ok, null);
|
||||||
|
builder.setTitle(isNewVariable() ? R.string.c_var_create_var : R.string.c_var_edit_var);
|
||||||
|
if (!isNewVariable()) {
|
||||||
|
builder.setNeutralButton(R.string.c_remove, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNewVariable() {
|
||||||
|
return variable == null || variable.id == NO_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final AlertDialog dialog = super.onCreateDialog(savedInstanceState);
|
||||||
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onShowDialog(@NonNull AlertDialog dialog) {
|
||||||
|
super.onShowDialog(dialog);
|
||||||
|
|
||||||
|
nameView.selectAll();
|
||||||
|
showIme(nameView);
|
||||||
|
|
||||||
|
final Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
ok.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
tryClose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!isNewVariable()) {
|
||||||
|
Check.isNotNull(variable);
|
||||||
|
final Button neutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
|
||||||
|
neutral.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// FIXME: 2016-01-30 removal dialog
|
||||||
|
// showRemovalDialog(function);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryClose() {
|
||||||
|
if (validate() && applyData()) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean applyData() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return validateName() & validateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validateValue() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validateName() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
@ -96,14 +212,90 @@ public class EditVariableFragment extends DialogFragment implements CalculatorEv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@Nonnull View root, Bundle savedInstanceState) {
|
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
super.onViewCreated(root, savedInstanceState);
|
switch (calculatorEventType) {
|
||||||
|
case constant_removed:
|
||||||
|
case constant_added:
|
||||||
|
case constant_changed:
|
||||||
|
if (calculatorEventData.getSource() == this) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
final String errorMsg = this.getString(R.string.c_char_is_not_accepted);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final EditText editName = (EditText) root.findViewById(R.id.var_edit_name);
|
@NonNull
|
||||||
editName.setText(input.getName());
|
@Override
|
||||||
editName.addTextChangedListener(new TextWatcher() {
|
protected View onCreateDialogView(@NonNull Context context, @NonNull LayoutInflater inflater, @android.support.annotation.Nullable Bundle savedInstanceState) {
|
||||||
|
final View view = inflater.inflate(R.layout.fragment_variable_edit, null);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
|
if (savedInstanceState == null && variable != null) {
|
||||||
|
nameView.setText(variable.name);
|
||||||
|
valueView.setText(variable.value);
|
||||||
|
descriptionView.setText(variable.description);
|
||||||
|
}
|
||||||
|
nameView.setOnFocusChangeListener(this);
|
||||||
|
nameView.setOnKeyListener(this);
|
||||||
|
valueView.setOnFocusChangeListener(this);
|
||||||
|
descriptionView.setOnFocusChangeListener(this);
|
||||||
|
keyboardButton.setOnClickListener(this);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.variable_name:
|
||||||
|
if (hasFocus) {
|
||||||
|
clearError(nameLabel);
|
||||||
|
} else {
|
||||||
|
keyboardUser.done();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case R.id.variable_value:
|
||||||
|
if (hasFocus) {
|
||||||
|
clearError(valueLabel);
|
||||||
|
} else {
|
||||||
|
validateValue();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
if (v.getId() == R.id.variable_name) {
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK && keyboardWindow.isShown()) {
|
||||||
|
keyboardUser.done();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.variable_keyboard_button:
|
||||||
|
if (keyboardWindow.isShown()) {
|
||||||
|
keyboardUser.showIme();
|
||||||
|
} else {
|
||||||
|
showKeyboard();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showKeyboard() {
|
||||||
|
nameView.dontShowSoftInputOnFocusCompat();
|
||||||
|
keyboardWindow.show(new GreekFloatingKeyboard(keyboardUser), getDialog());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NameWatcher 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) {
|
||||||
@ -119,211 +311,51 @@ public class EditVariableFragment extends DialogFragment implements CalculatorEv
|
|||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
if (!acceptableChars.contains(Character.toLowerCase(c))) {
|
if (!acceptableChars.contains(Character.toLowerCase(c))) {
|
||||||
s.delete(i, i + 1);
|
s.delete(i, i + 1);
|
||||||
Toast.makeText(getActivity(), String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), String.format(getString(R.string.c_char_is_not_accepted), c), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
fillGreekKeyboard(root, editName);
|
|
||||||
|
|
||||||
// show soft keyboard automatically
|
|
||||||
editName.requestFocus();
|
|
||||||
getDialog().getWindow().setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);
|
|
||||||
|
|
||||||
final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value);
|
|
||||||
editValue.setText(input.getValue());
|
|
||||||
|
|
||||||
final EditText editDescription = (EditText) root.findViewById(R.id.var_edit_description);
|
|
||||||
editDescription.setText(input.getDescription());
|
|
||||||
|
|
||||||
final OldVar.Builder varBuilder;
|
|
||||||
final IConstant constant = input.getConstant();
|
|
||||||
if (constant != null) {
|
|
||||||
varBuilder = new OldVar.Builder(constant);
|
|
||||||
} else {
|
|
||||||
varBuilder = new OldVar.Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
|
private class KeyboardUser implements FloatingKeyboard.User {
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public Context getContext() {
|
||||||
dismiss();
|
return getActivity();
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver<IConstant>(varBuilder, constant, root, Locator.getInstance().getEngine().getVariablesRegistry(), this));
|
|
||||||
|
|
||||||
if (constant == null) {
|
|
||||||
// CREATE MODE
|
|
||||||
getDialog().setTitle(R.string.c_var_create_var);
|
|
||||||
|
|
||||||
root.findViewById(R.id.remove_button).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
// EDIT MODE
|
|
||||||
getDialog().setTitle(R.string.c_var_edit_var);
|
|
||||||
|
|
||||||
root.findViewById(R.id.remove_button).setOnClickListener(MathEntityRemover.newConstantRemover(constant, null, getActivity(), EditVariableFragment.this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillGreekKeyboard(View root, final EditText editName) {
|
@NonNull
|
||||||
final TextView greekKeyboardToggle = (TextView) root.findViewById(R.id.var_toggle_greek_keyboard);
|
|
||||||
final ViewGroup greekKeyboard = (ViewGroup) root.findViewById(R.id.var_greek_keyboard);
|
|
||||||
greekKeyboardToggle.setPaintFlags(greekKeyboardToggle.getPaintFlags() | UNDERLINE_TEXT_FLAG);
|
|
||||||
greekKeyboardToggle.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public Resources getResources() {
|
||||||
if (greekKeyboard.getVisibility() == VISIBLE) {
|
return EditVariableFragment.this.getResources();
|
||||||
greekKeyboard.setVisibility(GONE);
|
|
||||||
greekKeyboardToggle.setText(R.string.cpp_var_show_greek_keyboard);
|
|
||||||
} else {
|
|
||||||
greekKeyboard.setVisibility(VISIBLE);
|
|
||||||
greekKeyboardToggle.setText(R.string.cpp_var_hide_greek_keyboard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
LinearLayout keyboardRow = null;
|
|
||||||
final View.OnClickListener buttonOnClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
if (!(view instanceof Button)) throw new AssertionError();
|
|
||||||
editName.append(((Button) view).getText());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
for (int i = 0; i < greekAlphabet.length(); i++) {
|
|
||||||
if (i % 5 == 0) {
|
|
||||||
keyboardRow = new LinearLayout(getActivity());
|
|
||||||
keyboardRow.setOrientation(HORIZONTAL);
|
|
||||||
greekKeyboard.addView(keyboardRow, new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
|
||||||
}
|
|
||||||
final Button button = new Button(getActivity());
|
|
||||||
button.setText(String.valueOf(greekAlphabet.charAt(i)));
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
||||||
fixCapitalization(button);
|
|
||||||
}
|
|
||||||
button.setOnClickListener(buttonOnClickListener);
|
|
||||||
assert keyboardRow != null;
|
|
||||||
keyboardRow.addView(button, new LinearLayout.LayoutParams(0, WRAP_CONTENT, 1F));
|
|
||||||
}
|
|
||||||
final Button button = new Button(getActivity());
|
|
||||||
button.setText("↑");
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
final boolean upperCase = button.getText().equals("↑");
|
|
||||||
Views.processViewsOfType(greekKeyboard, Button.class, new Views.ViewProcessor<Button>() {
|
|
||||||
@Override
|
|
||||||
public void process(@Nonnull Button key) {
|
|
||||||
final String letter = key.getText().toString();
|
|
||||||
if (upperCase) {
|
|
||||||
key.setText(letter.toUpperCase(Locale.US));
|
|
||||||
} else {
|
|
||||||
key.setText(letter.toLowerCase(Locale.US));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (upperCase) {
|
|
||||||
button.setText("↓");
|
|
||||||
} else {
|
|
||||||
button.setText("↑");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
keyboardRow.addView(button, new LinearLayout.LayoutParams(0, WRAP_CONTENT, 1F));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
@NonNull
|
||||||
private void fixCapitalization(Button button) {
|
@Override
|
||||||
button.setAllCaps(false);
|
public EditText getEditor() {
|
||||||
|
return nameView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@NonNull
|
||||||
**********************************************************************
|
@Override
|
||||||
*
|
public ViewGroup getKeyboard() {
|
||||||
* STATIC
|
return keyboardWindow.getContentView();
|
||||||
*
|
}
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
public void done() {
|
||||||
switch (calculatorEventType) {
|
if (keyboardWindow.isShown()) {
|
||||||
case constant_removed:
|
keyboardWindow.hide();
|
||||||
case constant_added:
|
|
||||||
case constant_changed:
|
|
||||||
if (calculatorEventData.getSource() == this) {
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
validateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Input {
|
@Override
|
||||||
|
public void showIme() {
|
||||||
@Nullable
|
final InputMethodManager keyboard = (InputMethodManager)
|
||||||
private IConstant constant;
|
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
keyboard.showSoftInput(getEditor(), InputMethodManager.SHOW_FORCED);
|
||||||
@Nullable
|
keyboardWindow.hide();
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private Input() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static Input newInstance() {
|
|
||||||
return new Input();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static Input newFromConstant(@Nonnull IConstant constant) {
|
|
||||||
final Input result = new Input();
|
|
||||||
result.constant = constant;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static Input newFromValue(@Nullable String value) {
|
|
||||||
final Input result = new Input();
|
|
||||||
result.value = value;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static Input newInstance(@Nullable IConstant constant, @Nullable String name, @Nullable String value, @Nullable String description) {
|
|
||||||
final Input result = new Input();
|
|
||||||
result.constant = constant;
|
|
||||||
result.name = name;
|
|
||||||
result.value = value;
|
|
||||||
result.description = description;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public IConstant getConstant() {
|
|
||||||
return constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getName() {
|
|
||||||
return name == null ? (constant == null ? null : constant.getName()) : name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getValue() {
|
|
||||||
return value == null ? (constant == null ? null : constant.getValue()) : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getDescription() {
|
|
||||||
return description == null ? (constant == null ? null : constant.getDescription()) : description;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,165 @@
|
|||||||
|
package org.solovyev.android.calculator.variables;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.annotation.IdRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.view.HapticFeedbackConstants;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import org.solovyev.android.Views;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard;
|
||||||
|
import org.solovyev.android.calculator.view.EditTextLongClickEraser;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
|
public class GreekFloatingKeyboard extends BaseFloatingKeyboard implements View.OnClickListener {
|
||||||
|
private final static String GREEK_ALPHABET = "αβγδεζηθικλμνξοπρστυφχψω";
|
||||||
|
|
||||||
|
public GreekFloatingKeyboard(@NonNull User user) {
|
||||||
|
super(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeView(boolean landscape) {
|
||||||
|
LinearLayout rowView = null;
|
||||||
|
final int columns = getColumnsCount(landscape);
|
||||||
|
final int rows = getRowsCount(landscape);
|
||||||
|
for (int i = 0, letter = 0; i < columns * rows; i++) {
|
||||||
|
final int column = i % columns;
|
||||||
|
final int row = i / columns;
|
||||||
|
if (column == 0) {
|
||||||
|
rowView = makeRow();
|
||||||
|
}
|
||||||
|
if (column == columns - 1) {
|
||||||
|
if (!landscape) {
|
||||||
|
makeLastColumnPort(rowView, row);
|
||||||
|
} else {
|
||||||
|
makeLastColumnLand(rowView, row);
|
||||||
|
}
|
||||||
|
} else if (letter < GREEK_ALPHABET.length()) {
|
||||||
|
final Button button = addButton(rowView, View.NO_ID, String.valueOf(GREEK_ALPHABET.charAt(letter)));
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
|
fixCapitalization(button);
|
||||||
|
}
|
||||||
|
letter++;
|
||||||
|
} else {
|
||||||
|
addButton(rowView, View.NO_ID, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeLastColumnLand(@NonNull LinearLayout rowView, int row) {
|
||||||
|
switch (row) {
|
||||||
|
case 0:
|
||||||
|
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
|
||||||
|
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
addButton(rowView, R.id.cpp_kb_button_change_case, "↑");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
addButton(rowView, View.NO_ID, "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeLastColumnPort(@NonNull LinearLayout rowView, int row) {
|
||||||
|
switch (row) {
|
||||||
|
case 0:
|
||||||
|
addButton(rowView, R.id.cpp_kb_button_clear, "C");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
|
||||||
|
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
addButton(rowView, R.id.cpp_kb_button_change_case, "↑");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
addButton(rowView, View.NO_ID, "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||||
|
private void fixCapitalization(Button button) {
|
||||||
|
button.setAllCaps(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillButton(@NonNull View button, @IdRes int id) {
|
||||||
|
super.fillButton(button, id);
|
||||||
|
button.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowsCount(boolean landscape) {
|
||||||
|
return landscape ? 4 : 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumnsCount(boolean landscape) {
|
||||||
|
return landscape ? 7 : 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.cpp_kb_button_close:
|
||||||
|
user.done();
|
||||||
|
break;
|
||||||
|
case R.id.cpp_kb_button_change_case:
|
||||||
|
changeCase((Button) v);
|
||||||
|
break;
|
||||||
|
case R.id.cpp_kb_button_keyboard:
|
||||||
|
user.showIme();
|
||||||
|
break;
|
||||||
|
case R.id.cpp_kb_button_clear:
|
||||||
|
user.getEditor().setText("");
|
||||||
|
user.getEditor().setSelection(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
user.getEditor().append(((TextView) v).getText());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
user.getEditor().requestFocus();
|
||||||
|
v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeCase(@NonNull Button button) {
|
||||||
|
final boolean upperCase = button.getText().equals("↑");
|
||||||
|
Views.processViewsOfType(user.getKeyboard(), Button.class, new Views.ViewProcessor<Button>() {
|
||||||
|
@Override
|
||||||
|
public void process(@Nonnull Button key) {
|
||||||
|
final String letter = key.getText().toString();
|
||||||
|
if (!GREEK_ALPHABET.contains(letter.toLowerCase(Locale.US))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (upperCase) {
|
||||||
|
key.setText(letter.toUpperCase(Locale.US));
|
||||||
|
} else {
|
||||||
|
key.setText(letter.toLowerCase(Locale.US));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (upperCase) {
|
||||||
|
button.setText("↓");
|
||||||
|
} else {
|
||||||
|
button.setText("↑");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -49,6 +49,7 @@ public class VariablesActivity extends BaseActivity implements CalculatorEventLi
|
|||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
final Bundle extras = getIntent().getExtras();
|
final Bundle extras = getIntent().getExtras();
|
||||||
final CppVariable variable = extras != null ? (CppVariable) extras.getParcelable(EXTRA_VARIABLE) : null;
|
final CppVariable variable = extras != null ? (CppVariable) extras.getParcelable(EXTRA_VARIABLE) : null;
|
||||||
|
EditVariableFragment.showDialog(variable, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class VariablesFragment extends BaseEntitiesFragment<IConstant> implements CalculatorEventListener {
|
public class VariablesFragment extends BaseEntitiesFragment<IConstant> implements CalculatorEventListener {
|
||||||
|
|
||||||
public static final String ARG_VARIABLE = "variable";
|
|
||||||
public static final String CREATE_VAR_EXTRA_STRING = "create_var";
|
|
||||||
@Inject
|
@Inject
|
||||||
VariablesRegistry registry;
|
VariablesRegistry registry;
|
||||||
@Inject
|
@Inject
|
||||||
@ -72,25 +70,6 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
// FIXME: 2016-01-29 continue
|
|
||||||
final Bundle bundle = getArguments();
|
|
||||||
if (bundle != null) {
|
|
||||||
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
|
|
||||||
if (!Strings.isEmpty(varValue)) {
|
|
||||||
EditVariableFragment.showDialog(EditVariableFragment.Input.newFromValue(varValue), getFragmentManager());
|
|
||||||
|
|
||||||
// in order to stop intent for other tabs
|
|
||||||
bundle.remove(CREATE_VAR_EXTRA_STRING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(@Nonnull AppComponent component) {
|
protected void inject(@Nonnull AppComponent component) {
|
||||||
super.inject(component);
|
super.inject(component);
|
||||||
@ -106,7 +85,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
|
|||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
EditVariableFragment.showDialog(EditVariableFragment.Input.newInstance(), getFragmentManager());
|
EditVariableFragment.showDialog(null, getFragmentManager());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -116,11 +95,6 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
|
|||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant);
|
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
|
||||||
public void addVarButtonClickHandler(@Nonnull View v) {
|
|
||||||
EditVariableFragment.showDialog(EditVariableFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected List<IConstant> getEntities() {
|
protected List<IConstant> getEntities() {
|
||||||
@ -179,7 +153,7 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> implement
|
|||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant);
|
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, constant);
|
||||||
return true;
|
return true;
|
||||||
case R.string.c_edit:
|
case R.string.c_edit:
|
||||||
EditVariableFragment.showDialog(EditVariableFragment.Input.newFromConstant(constant), activity.getSupportFragmentManager());
|
EditVariableFragment.showDialog(CppVariable.builder(constant).build(), activity);
|
||||||
return true;
|
return true;
|
||||||
case R.string.c_remove:
|
case R.string.c_remove:
|
||||||
MathEntityRemover.newConstantRemover(constant, null, activity, activity).showConfirmationDialog();
|
MathEntityRemover.newConstantRemover(constant, null, activity, activity).showConfirmationDialog();
|
||||||
|
95
app/src/main/res/layout/fragment_variable_edit.xml
Normal file
95
app/src/main/res/layout/fragment_variable_edit.xml
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ 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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
a:layout_width="wrap_content"
|
||||||
|
a:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:orientation="vertical">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
a:id="@+id/variable_name_label"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_gravity="start|center_vertical">
|
||||||
|
|
||||||
|
<org.solovyev.android.calculator.view.EditTextCompat
|
||||||
|
a:id="@+id/variable_name"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:hint="@string/c_var_name"
|
||||||
|
a:inputType="text" />
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
a:id="@+id/variable_keyboard_button"
|
||||||
|
a:layout_width="wrap_content"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_gravity="end|center_vertical"
|
||||||
|
a:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
a:text="@string/cpp_show_greek_keyboard"
|
||||||
|
a:textAllCaps="false"
|
||||||
|
a:padding="@dimen/cpp_image_button_padding"
|
||||||
|
a:minWidth="0dp"
|
||||||
|
a:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
a:id="@+id/variable_value_label"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<org.solovyev.android.calculator.view.EditTextCompat
|
||||||
|
a:id="@+id/variable_value"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:hint="@string/c_var_value"
|
||||||
|
a:inputType="numberDecimal" />
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
a:id="@+id/variable_description"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:hint="@string/c_var_description"
|
||||||
|
a:inputType="text" />
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
@ -1,122 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ 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
|
|
||||||
-->
|
|
||||||
|
|
||||||
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:minWidth="300dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:padding="6dp"
|
|
||||||
a:text="@string/c_var_name" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
a:id="@+id/var_edit_name"
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:inputType="text" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
a:id="@+id/var_toggle_greek_keyboard"
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:padding="6dp"
|
|
||||||
a:text="@string/cpp_var_show_greek_keyboard" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
a:id="@+id/var_greek_keyboard"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:orientation="vertical"
|
|
||||||
a:visibility="gone" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:padding="6dp"
|
|
||||||
a:text="@string/c_var_value" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
a:id="@+id/var_edit_value"
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:padding="6dp"
|
|
||||||
a:text="@string/c_var_description" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
a:id="@+id/var_edit_description"
|
|
||||||
style="@style/cpp_default_text_size"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:inputType="text" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
a:id="@+id/cancel_button"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:text="@string/c_cancel" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
a:id="@+id/remove_button"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:text="@string/c_remove" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
a:id="@+id/save_button"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:text="@string/c_save" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
|
|
@ -73,5 +73,6 @@
|
|||||||
<item name="cpp_kb_button_functions_constants" type="id" />
|
<item name="cpp_kb_button_functions_constants" type="id" />
|
||||||
<item name="cpp_kb_button_constants" type="id" />
|
<item name="cpp_kb_button_constants" type="id" />
|
||||||
<item name="cpp_kb_button_close" type="id" />
|
<item name="cpp_kb_button_close" type="id" />
|
||||||
|
<item name="cpp_kb_button_change_case" type="id" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -227,6 +227,7 @@
|
|||||||
several devices.\n\n
|
several devices.\n\n
|
||||||
By clicking \'Continue\' button you will be redirected to the Google Play app to make the payment.</string>
|
By clicking \'Continue\' button you will be redirected to the Google Play app to make the payment.</string>
|
||||||
<string name="cpp_purchase_title">Purchase</string>
|
<string name="cpp_purchase_title">Purchase</string>
|
||||||
|
<string name="cpp_show_greek_keyboard" translatable="false">αβγ</string>
|
||||||
<string name="cpp_var_show_greek_keyboard">Show Greek letters</string>
|
<string name="cpp_var_show_greek_keyboard">Show Greek letters</string>
|
||||||
<string name="cpp_var_hide_greek_keyboard">Hide Greek letters</string>
|
<string name="cpp_var_hide_greek_keyboard">Hide Greek letters</string>
|
||||||
<string name="cpp_clear_history_title">Clear history?</string>
|
<string name="cpp_clear_history_title">Clear history?</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user