greek letters added to the var names

This commit is contained in:
serso 2013-07-02 14:49:35 +04:00 committed by Solovyev_S
parent 9ae9aed9fc
commit c55001ffa2
3 changed files with 94 additions and 5 deletions

View File

@ -46,6 +46,69 @@
style="@style/cpp_default_text_size" style="@style/cpp_default_text_size"
a:inputType="text"/> a:inputType="text"/>
<LinearLayout
a:id="@+id/var_edit_greek_buttons_1"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:orientation="horizontal">
<Button a:text="α"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="β"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="γ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="δ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="ε"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
</LinearLayout>
<LinearLayout a:id="@+id/var_edit_greek_buttons_2"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:orientation="horizontal">
<Button a:text="θ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="λ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="μ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="τ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
<Button a:text="φ"
a:layout_height="wrap_content"
a:layout_width="0dp"
a:layout_weight="1"/>
</LinearLayout>
<TextView <TextView
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"

View File

@ -80,8 +80,6 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category"; public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
protected final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
/* /*
********************************************************************** **********************************************************************

View File

@ -22,6 +22,7 @@
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
@ -30,17 +31,24 @@ import android.text.TextWatcher;
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.view.WindowManager; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.model.Var; import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.sherlock.AndroidSherlockUtils; import org.solovyev.android.sherlock.AndroidSherlockUtils;
import org.solovyev.common.text.Strings;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
/** /**
* User: Solovyev_S * User: Solovyev_S
@ -49,6 +57,8 @@ import org.solovyev.android.sherlock.AndroidSherlockUtils;
*/ */
public class VarEditDialogFragment extends DialogFragment implements CalculatorEventListener { public class VarEditDialogFragment extends DialogFragment implements CalculatorEventListener {
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюёαβγδεζηθικλμνξοπρστυφχψω_".toCharArray()));
@Nonnull @Nonnull
private final Input input; private final Input input;
@ -101,7 +111,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
if (!AbstractMathEntityListFragment.acceptableChars.contains(c)) { if (!acceptableChars.contains(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(errorMsg, c), Toast.LENGTH_SHORT).show();
} }
@ -109,9 +119,12 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
}); });
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_1);
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_2);
// show soft keyboard automatically // show soft keyboard automatically
editName.requestFocus(); editName.requestFocus();
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); getDialog().getWindow().setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);
final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value); final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value);
editValue.setText(input.getValue()); editValue.setText(input.getValue());
@ -149,6 +162,21 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
} }
private void processGreekButtons(@Nonnull View root, @Nonnull final EditText editName, int greekButtonsViewId) {
final ViewGroup greekButtons = (ViewGroup) root.findViewById(greekButtonsViewId);
Views.processViewsOfType(greekButtons, Button.class, new Views.ViewProcessor<Button>() {
@Override
public void process(@Nonnull final Button greekButton) {
greekButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editName.append(greekButton.getText());
}
});
}
});
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) { switch (calculatorEventType) {