From 6e245d2dbae74bcf82f5ede66df5cb303e365c8a Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 29 Oct 2011 17:41:51 +0400 Subject: [PATCH] functions activity added --- AndroidManifest.xml | 9 +- res/layout-land/main_calculator.xml | 2 +- res/layout-land/main_cellphone.xml | 2 +- res/layout-port/main_calculator.xml | 2 +- res/layout-port/main_cellphone.xml | 2 +- res/layout/calc_functions_button.xml | 14 +++ res/layout/calc_subtraction_button.xml | 3 +- res/layout/functions.xml | 20 ++++ res/values-ru/strings.xml | 1 + res/values/strings.xml | 1 + .../calculator/CalculatorActivity.java | 5 + .../CalculatorFunctionsActivity.java | 97 +++++++++++++++++++ .../android/calculator/CalculatorModel.java | 6 +- 13 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 res/layout/calc_functions_button.xml create mode 100644 res/layout/functions.xml create mode 100644 src/main/java/org/solovyev/android/calculator/CalculatorFunctionsActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 379f4dc2..e9c12744 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -7,8 +7,8 @@ - + @@ -36,6 +36,11 @@ a:label="@string/c_about" a:configChanges="orientation|keyboardHidden"/> + + + diff --git a/res/layout-land/main_calculator.xml b/res/layout-land/main_calculator.xml index 83ddd626..260cfa7a 100644 --- a/res/layout-land/main_calculator.xml +++ b/res/layout-land/main_calculator.xml @@ -105,8 +105,8 @@ + - diff --git a/res/layout-land/main_cellphone.xml b/res/layout-land/main_cellphone.xml index 79677bdb..5e0837c1 100644 --- a/res/layout-land/main_cellphone.xml +++ b/res/layout-land/main_cellphone.xml @@ -99,8 +99,8 @@ + - diff --git a/res/layout-port/main_calculator.xml b/res/layout-port/main_calculator.xml index 58a74050..1f0f0215 100644 --- a/res/layout-port/main_calculator.xml +++ b/res/layout-port/main_calculator.xml @@ -80,8 +80,8 @@ + - diff --git a/res/layout-port/main_cellphone.xml b/res/layout-port/main_cellphone.xml index 1cb6f49a..3d17e17b 100644 --- a/res/layout-port/main_cellphone.xml +++ b/res/layout-port/main_cellphone.xml @@ -74,8 +74,8 @@ + - diff --git a/res/layout/calc_functions_button.xml b/res/layout/calc_functions_button.xml new file mode 100644 index 00000000..18ddaa8b --- /dev/null +++ b/res/layout/calc_functions_button.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/res/layout/calc_subtraction_button.xml b/res/layout/calc_subtraction_button.xml index a0d68986..1dc83010 100644 --- a/res/layout/calc_subtraction_button.xml +++ b/res/layout/calc_subtraction_button.xml @@ -8,8 +8,7 @@ + + + + + + + + \ No newline at end of file diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml index dc32f56c..ef4b03b6 100644 --- a/res/values-ru/strings.xml +++ b/res/values-ru/strings.xml @@ -116,5 +116,6 @@ Длительность отклика Длительность вибрации по нажатию клавиши + Функции diff --git a/res/values/strings.xml b/res/values/strings.xml index 30136621..c81c905b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -117,5 +117,6 @@ Haptic feedback duration Duration vibration on button click + Functions diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index a943f0d4..664289ea 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -332,6 +332,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh calculatorModel.processDigitButtonAction(((DirectionDragButton) v).getTextMiddle()); } + @SuppressWarnings({"UnusedDeclaration"}) + public void functionsButtonClickHandler(@NotNull View v) { + startActivity(new Intent(this, CalculatorFunctionsActivity.class)); + } + @SuppressWarnings({"UnusedDeclaration"}) public void varsButtonClickHandler(@NotNull View v) { startActivity(new Intent(this, CalculatorVarsActivity.class)); diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsActivity.java new file mode 100644 index 00000000..837d973a --- /dev/null +++ b/src/main/java/org/solovyev/android/calculator/CalculatorFunctionsActivity.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2009-2011. Created by serso aka se.solovyev. + * For more information, please, contact se.solovyev@gmail.com + * or visit http://se.solovyev.org + */ + +package org.solovyev.android.calculator; + +import android.app.ListActivity; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.*; +import jscl.math.function.Function; +import org.jetbrains.annotations.NotNull; +import org.solovyev.android.calculator.model.CalculatorEngine; +import org.solovyev.common.utils.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * User: serso + * Date: 10/29/11 + * Time: 4:55 PM + */ +public class CalculatorFunctionsActivity extends ListActivity{ + + @NotNull + private FunctionsArrayAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.functions); + + adapter = new FunctionsArrayAdapter(this, R.layout.var, R.id.var_text, new ArrayList(CalculatorEngine.instance.getFunctionsRegistry().getEntities())); + setListAdapter(adapter); + + final ListView lv = getListView(); + lv.setTextFilterEnabled(true); + + + + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(final AdapterView parent, + final View view, + final int position, + final long id) { + + CalculatorModel.instance.processDigitButtonAction(((Function) parent.getItemAtPosition(position)).getName(), false); + + CalculatorFunctionsActivity.this.finish(); + } + }); + + } + + private class FunctionsArrayAdapter extends ArrayAdapter { + + private FunctionsArrayAdapter(Context context, int resource, int textViewResourceId, List objects) { + super(context, resource, textViewResourceId, objects); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent); + + final Function function = getItem(position); + + if (!StringUtils.isEmpty(function.getDescription())) { + TextView description = (TextView) result.findViewById(R.id.var_description); + if (description == null) { + final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.var, null); + description = (TextView) itemView.findViewById(R.id.var_description); + itemView.removeView(description); + result.addView(description); + } + description.setText(function.getDescription()); + } else { + TextView description = (TextView) result.findViewById(R.id.var_description); + if (description != null) { + result.removeView(description); + } + } + + + return result; + } + } + + +} diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorModel.java b/src/main/java/org/solovyev/android/calculator/CalculatorModel.java index dfdaf9cd..4d60562c 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorModel.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorModel.java @@ -239,6 +239,10 @@ public enum CalculatorModel implements CursorControl, HistoryControl