functions activity added

This commit is contained in:
serso 2011-10-29 17:41:51 +04:00
parent 519bf9cad9
commit 614fef5805
13 changed files with 155 additions and 9 deletions

View File

@ -7,8 +7,8 @@
<uses-permission a:name="android.permission.VIBRATE"/>
<uses-sdk a:minSdkVersion="4"
a:targetSdkVersion="8"/>
<uses-sdk a:minSdkVersion="4"
a:targetSdkVersion="8"/>
<application a:icon="@drawable/icon"
a:label="@string/c_app_name">
@ -36,6 +36,11 @@
a:label="@string/c_about"
a:configChanges="orientation|keyboardHidden"/>
<activity a:name=".CalculatorFunctionsActivity"
a:label="@string/c_functions"
a:configChanges="orientation|keyboardHidden">
</activity>
<activity a:name=".CalculatorVarsActivity"
a:label="@string/c_vars_and_constants"
a:configChanges="orientation|keyboardHidden">

View File

@ -105,8 +105,8 @@
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/>

View File

@ -99,8 +99,8 @@
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/>

View File

@ -80,8 +80,8 @@
<include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_right_button"/>
<include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_history_button"/>
<include layout="@layout/calc_donate_button"/>
</LinearLayout>
</LinearLayout>

View File

@ -74,8 +74,8 @@
<include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_right_button"/>
<include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_history_button"/>
<include layout="@layout/calc_donate_button"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/functionsButton"
a:text="ƒ(x)"
a:textStyle="italic"
a:onClick="functionsButtonClickHandler"
style="?controlButtonStyle"/>

View File

@ -8,8 +8,7 @@
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/subtractionButton" a:text="-"
calc:textUp="{"
calc:textDown="}"
calc:textUp=","
calc:directionTextScale="0.5"
style="?digitButtonStyle"

20
res/layout/functions.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<ListView
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:layout_weight="1"
a:id="@android:id/list"/>
</LinearLayout>

View File

@ -116,5 +116,6 @@
<string name="p_calc_haptic_feedback_duration_title">Длительность отклика</string>
<string name="p_calc_haptic_feedback_duration_summary">Длительность вибрации по нажатию клавиши</string>
<string name="c_functions">Функции</string>
</resources>

View File

@ -117,5 +117,6 @@
<string name="p_calc_haptic_feedback_duration_title">Haptic feedback duration</string>
<string name="p_calc_haptic_feedback_duration_summary">Duration vibration on button click</string>
<string name="c_functions">Functions</string>
</resources>

View File

@ -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));

View File

@ -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<Function>(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<Function> {
private FunctionsArrayAdapter(Context context, int resource, int textViewResourceId, List<Function> 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;
}
}
}

View File

@ -239,6 +239,10 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
}
public void processDigitButtonAction(@Nullable final String text) {
processDigitButtonAction(text, true);
}
public void processDigitButtonAction(@Nullable final String text, boolean delayEvaluate) {
//Toast.makeText(CalculatorActivity.this, text, Toast.LENGTH_SHORT).show();
if (!StringUtils.isEmpty(text)) {
@ -268,7 +272,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
editor.getText().insert(editor.getSelectionStart(), textToBeInserted.toString());
editor.setSelection(editor.getSelectionStart() + cursorPositionOffset, editor.getSelectionEnd() + cursorPositionOffset);
}
});
}, delayEvaluate);
}
}