android-calculatorpp-102 More greek letters

This commit is contained in:
serso 2014-05-20 23:53:11 +02:00
parent b3310255fd
commit 827451babe
4 changed files with 93 additions and 92 deletions

View File

@ -327,4 +327,6 @@
Если у вас есть вопросы или проблемы вы всегда можете обратиться ко мне напрямую (конакты доступны в Меню->О Если у вас есть вопросы или проблемы вы всегда можете обратиться ко мне напрямую (конакты доступны в Меню->О
приложении) приложении)
</string> </string>
<string name="cpp_var_show_greek_keyboard">Показать греческий алфавит</string>
<string name="cpp_var_hide_greek_keyboard">Скрыть греческий алфавит</string>
</resources> </resources>

View File

@ -322,4 +322,6 @@
</string> </string>
<string name="acl_yes">Yes</string> <string name="acl_yes">Yes</string>
<string name="acl_no">No</string> <string name="acl_no">No</string>
<string name="cpp_var_show_greek_keyboard">Show Greek letters</string>
<string name="cpp_var_hide_greek_keyboard">Hide Greek letters</string>
</resources> </resources>

View File

@ -46,68 +46,20 @@
style="@style/cpp_default_text_size" style="@style/cpp_default_text_size"
a:inputType="text"/> a:inputType="text"/>
<TextView
a:id="@+id/var_toggle_greek_keyboard"
a:text="@string/cpp_var_show_greek_keyboard"
a:layout_height="wrap_content"
a:layout_width="match_parent"
a:padding="6dp"
style="@style/cpp_default_text_size" />
<LinearLayout <LinearLayout
a:id="@+id/var_edit_greek_buttons_1" a:id="@+id/var_greek_keyboard"
a:layout_height="wrap_content" a:visibility="gone"
a:layout_width="match_parent" a:layout_width="match_parent"
a:orientation="horizontal"> a:layout_height="wrap_content"
a:orientation="vertical"/>
<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"

View File

@ -22,7 +22,6 @@
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;
@ -31,33 +30,33 @@ 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.widget.Button; import android.view.ViewPropertyAnimator;
import android.widget.EditText; import android.widget.*;
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.Nullable;
import org.solovyev.android.Views; 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 org.solovyev.common.text.Strings;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import static android.graphics.Paint.UNDERLINE_TEXT_FLAG;
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;
/**
* User: Solovyev_S
* Date: 01.10.12
* Time: 17:41
*/
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())); private final static String greekAlphabet = "αβγδεζηθικλμνξοπρστυφχψω";
private final static List<Character> acceptableChars = Arrays.asList(Strings.toObjects(("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_" + greekAlphabet).toCharArray()));
@Nonnull @Nonnull
private final Input input; private final Input input;
@ -111,7 +110,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 (!acceptableChars.contains(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(errorMsg, c), Toast.LENGTH_SHORT).show();
} }
@ -119,8 +118,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
}); });
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_1); fillGreekKeyboard(root, editName);
processGreekButtons(root, editName, R.id.var_edit_greek_buttons_2);
// show soft keyboard automatically // show soft keyboard automatically
editName.requestFocus(); editName.requestFocus();
@ -162,19 +160,66 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
} }
} }
private void processGreekButtons(@Nonnull View root, @Nonnull final EditText editName, int greekButtonsViewId) { private void fillGreekKeyboard(View root, final EditText editName) {
final ViewGroup greekButtons = (ViewGroup) root.findViewById(greekButtonsViewId); final TextView greekKeyboardToggle = (TextView) root.findViewById(R.id.var_toggle_greek_keyboard);
Views.processViewsOfType(greekButtons, Button.class, new Views.ViewProcessor<Button>() { 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 process(@Nonnull final Button greekButton) { public void onClick(View v) {
greekButton.setOnClickListener(new View.OnClickListener() { if (greekKeyboard.getVisibility() == VISIBLE) {
@Override greekKeyboard.setVisibility(GONE);
public void onClick(View v) { greekKeyboardToggle.setText(R.string.cpp_var_show_greek_keyboard);
editName.append(greekButton.getText()); } 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) {
assert view instanceof Button;
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)));
button.setOnClickListener(buttonOnClickListener);
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));
} }
@Override @Override