Add function dialog added
This commit is contained in:
parent
1c3537460a
commit
791eac433b
97
calculatorpp/res/layout/function_edit.xml
Normal file
97
calculatorpp/res/layout/function_edit.xml
Normal file
@ -0,0 +1,97 @@
|
||||
<?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
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:minWidth="300dp">
|
||||
|
||||
<LinearLayout a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:padding="6dp"
|
||||
style="@style/default_text_size"
|
||||
a:text="@string/c_function_name"/>
|
||||
|
||||
<EditText a:id="@+id/function_edit_name"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="@style/default_text_size"
|
||||
a:inputType="text"/>
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:padding="6dp"
|
||||
style="@style/default_text_size"
|
||||
a:text="@string/c_function_parameters"/>
|
||||
|
||||
<LinearLayout
|
||||
a:id="@+id/function_params_layout"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<include layout="@layout/function_edit_param" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="@style/default_text_size"
|
||||
a:padding="6dp"
|
||||
a:text="@string/c_function_value"/>
|
||||
|
||||
<EditText a:id="@+id/function_edit_value"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="@style/default_text_size"
|
||||
a:inputType="text"/>
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:padding="6dp"
|
||||
style="@style/default_text_size"
|
||||
a:text="@string/c_function_description"/>
|
||||
|
||||
<EditText a:id="@+id/function_edit_description"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="@style/default_text_size"
|
||||
a:inputType="text"/>
|
||||
|
||||
<LinearLayout
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent">
|
||||
|
||||
<Button a:id="@+id/cancel_button"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:text="@string/c_cancel"/>
|
||||
|
||||
<Button a:id="@+id/remove_button"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:text="@string/c_remove"/>
|
||||
|
||||
<Button a:id="@+id/save_button"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:text="@string/c_save"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
27
calculatorpp/res/layout/function_edit_param.xml
Normal file
27
calculatorpp/res/layout/function_edit_param.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
a:id="@+id/function_add_param_button"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="+" />
|
||||
|
||||
<Button
|
||||
a:id="@+id/function_remove_param_button"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"
|
||||
a:visibility="gone"
|
||||
a:text="-" />
|
||||
|
||||
<EditText
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
style="@style/default_text_size"
|
||||
a:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
15
calculatorpp/res/menu/functions_menu.xml
Normal file
15
calculatorpp/res/menu/functions_menu.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
-->
|
||||
|
||||
<menu xmlns:a="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item a:id="@+id/functions_menu_add_function"
|
||||
a:title="@string/c_add"
|
||||
a:icon="@drawable/ab_add"
|
||||
a:showAsAction="always"/>
|
||||
</menu>
|
@ -234,4 +234,9 @@
|
||||
<string name="p_blue_line_color">Blue</string>
|
||||
<string name="p_green_line_color">Green</string>
|
||||
|
||||
<string name="c_function_name">Name</string>
|
||||
<string name="c_function_value">Value</string>
|
||||
<string name="c_function_description">Description</string>
|
||||
<string name="c_function_parameters">Parameters</string>
|
||||
|
||||
</resources>
|
@ -0,0 +1,160 @@
|
||||
package org.solovyev.android.calculator.function;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils2;
|
||||
import org.solovyev.android.calculator.*;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/13/12
|
||||
* Time: 11:34 PM
|
||||
*/
|
||||
public class FunctionEditDialogFragment extends DialogFragment implements CalculatorEventListener {
|
||||
|
||||
@NotNull
|
||||
private final Input input;
|
||||
|
||||
public FunctionEditDialogFragment() {
|
||||
this(Input.newInstance());
|
||||
}
|
||||
|
||||
public FunctionEditDialogFragment(@NotNull Input input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.function_edit, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NotNull View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final View addParamButton = root.findViewById(R.id.function_add_param_button);
|
||||
|
||||
final ViewGroup functionParamsLayout = (ViewGroup) root.findViewById(R.id.function_params_layout);
|
||||
addParamButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
final View functionEditParamLayout = inflater.inflate(R.layout.function_edit_param, null);
|
||||
|
||||
final View addParamButton = functionEditParamLayout.findViewById(R.id.function_add_param_button);
|
||||
addParamButton.setVisibility(View.GONE);
|
||||
|
||||
final View removeParamButton = functionEditParamLayout.findViewById(R.id.function_remove_param_button);
|
||||
removeParamButton.setVisibility(View.VISIBLE);
|
||||
|
||||
functionParamsLayout.addView(functionEditParamLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public static void showDialog(@NotNull Input input, @NotNull FragmentManager fm) {
|
||||
AndroidUtils2.showDialog(new FunctionEditDialogFragment(input), "function-editor", fm);
|
||||
}
|
||||
|
||||
public static class Input {
|
||||
|
||||
@Nullable
|
||||
private CustomFunction function;
|
||||
|
||||
@Nullable
|
||||
private String name;
|
||||
|
||||
@Nullable
|
||||
private String value;
|
||||
|
||||
@Nullable
|
||||
private String description;
|
||||
|
||||
private Input() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Input newInstance() {
|
||||
return new Input();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Input newFromFunction(@NotNull CustomFunction function) {
|
||||
final Input result = new Input();
|
||||
result.function = function;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Input newFromValue(@Nullable String value) {
|
||||
final Input result = new Input();
|
||||
result.value = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Input newInstance(@Nullable CustomFunction function, @Nullable String name, @Nullable String value, @Nullable String description) {
|
||||
final Input result = new Input();
|
||||
result.function = function;
|
||||
result.name = name;
|
||||
result.value = value;
|
||||
result.description = description;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CustomFunction getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return name == null ? (function == null ? null : function.getName()) : name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getValue() {
|
||||
return value == null ? (function == null ? null : function.getContent()) : value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDescription() {
|
||||
return description == null ? (function == null ? null : function.getContent()) : description;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,12 +10,19 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.ClipboardManager;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||
import org.solovyev.android.calculator.CalculatorMathRegistry;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
@ -31,7 +38,7 @@ import java.util.List;
|
||||
*/
|
||||
public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<Function> {
|
||||
|
||||
public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
|
||||
public static final String CREATE_FUNCTION_EXTRA_STRING = "create_function";
|
||||
|
||||
public CalculatorFunctionsFragment() {
|
||||
super(CalculatorFragmentType.functions);
|
||||
@ -67,6 +74,8 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
|
||||
intent.removeExtra(CREATE_FUN_EXTRA_STRING);
|
||||
}
|
||||
}*/
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,10 +88,16 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
|
||||
protected List<LabeledMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
|
||||
List<LabeledMenuItem<Function>> result = new ArrayList<LabeledMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
|
||||
|
||||
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(item.getName())) ) {
|
||||
final CalculatorMathRegistry<Function> functionsRegistry = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry();
|
||||
if ( StringUtils.isEmpty(functionsRegistry.getDescription(item.getName())) ) {
|
||||
result.remove(LongClickMenuItem.copy_description);
|
||||
}
|
||||
|
||||
final Function function = functionsRegistry.get(item.getName());
|
||||
if (!(function instanceof CustomFunction)) {
|
||||
result.remove(LongClickMenuItem.edit);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -189,6 +204,35 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
|
||||
return CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getCategory(function);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* MENU
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.functions_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean result;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.functions_menu_add_function:
|
||||
FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager());
|
||||
result = true;
|
||||
break;
|
||||
default:
|
||||
result = super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
@ -205,13 +249,14 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
|
||||
}
|
||||
},
|
||||
|
||||
/*edit(R.string.c_edit) {
|
||||
@Override
|
||||
public void doAction(@NotNull Function data, @NotNull Context context) {
|
||||
if (context instanceof AbstractMathEntityListActivity) {
|
||||
}
|
||||
}
|
||||
},*/
|
||||
edit(R.string.c_edit) {
|
||||
@Override
|
||||
public void onClick(@NotNull Function function, @NotNull Context context) {
|
||||
if (function instanceof CustomFunction) {
|
||||
FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newFromFunction((CustomFunction) function), ((SherlockFragmentActivity) context).getSupportFragmentManager());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
copy_description(R.string.c_copy_description) {
|
||||
@Override
|
||||
|
@ -132,7 +132,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.var_menu, menu);
|
||||
inflater.inflate(R.menu.vars_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user