This commit is contained in:
Sergey Solovyev 2012-12-01 18:46:36 +04:00
parent c2662e7537
commit 2747b26506
69 changed files with 219 additions and 68 deletions

View File

@ -26,4 +26,6 @@
<!--only for not multipane-->
<dimen name="cpp_editor_padding">5dp</dimen>
<dimen name="cpp_display_padding">3dp</dimen>
<dimen name="cpp_widget_keyboard_button_text_size">20dp</dimen>
</resources>

View File

@ -87,4 +87,22 @@
<item name="android:textColor">@color/cpp_default_text_color</item>
</style>
<style name="widget_metro_digit_button_style" parent="metro_digit_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_control_button_style" parent="metro_control_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_blue_operation_button_style" parent="metro_blue_operation_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_control_image_button_style" parent="metro_control_image_button_style">
<item name="android:scaleType">center</item>
</style>
</resources>

View File

@ -15,6 +15,7 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.core.R;
import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.view.TextHighlighter;
import org.solovyev.android.view.AutoResizeTextView;

View File

@ -1,10 +1,9 @@
package org.solovyev.android.calculator.widget;
package org.solovyev.android.calculator;
import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorSpecialButton;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.core.R;
import java.util.HashMap;
import java.util.Map;
@ -14,7 +13,7 @@ import java.util.Map;
* Date: 10/20/12
* Time: 12:05 AM
*/
public enum WidgetButton {
public enum CalculatorButton {
/*digits*/
one(R.id.oneDigitButton, "1"),
@ -69,24 +68,24 @@ public enum WidgetButton {
private final String onLongClickText;
@NotNull
private static Map<Integer, WidgetButton> buttonsByIds = new HashMap<Integer, WidgetButton>();
private static Map<Integer, CalculatorButton> buttonsByIds = new HashMap<Integer, CalculatorButton>();
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
CalculatorButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
this(buttonId, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode());
}
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton) {
CalculatorButton(int buttonId, @NotNull CalculatorSpecialButton onClickButton) {
this(buttonId, onClickButton, null);
}
WidgetButton(int buttonId, @NotNull String onClickText, @Nullable String onLongClickText) {
CalculatorButton(int buttonId, @NotNull String onClickText, @Nullable String onLongClickText) {
this.buttonId = buttonId;
this.onClickText = onClickText;
this.onLongClickText = onLongClickText;
}
WidgetButton(int buttonId, @NotNull String onClickText) {
CalculatorButton(int buttonId, @NotNull String onClickText) {
this(buttonId, onClickText, null);
}
@ -103,7 +102,7 @@ public enum WidgetButton {
}
@Nullable
public static WidgetButton getById(int buttonId) {
public static CalculatorButton getById(int buttonId) {
initButtonsByIdsMap();
return buttonsByIds.get(buttonId);
@ -113,11 +112,11 @@ public enum WidgetButton {
if ( buttonsByIds.isEmpty() ) {
// if not initialized
final WidgetButton[] widgetButtons = values();
final CalculatorButton[] calculatorButtons = values();
final Map<Integer, WidgetButton> localButtonsByIds = new HashMap<Integer, WidgetButton>(widgetButtons.length);
for (WidgetButton widgetButton : widgetButtons) {
localButtonsByIds.put(widgetButton.getButtonId(), widgetButton);
final Map<Integer, CalculatorButton> localButtonsByIds = new HashMap<Integer, CalculatorButton>(calculatorButtons.length);
for (CalculatorButton calculatorButton : calculatorButtons) {
localButtonsByIds.put(calculatorButton.getButtonId(), calculatorButton);
}
buttonsByIds = localButtonsByIds;

View File

@ -4,7 +4,9 @@ import android.content.Context;
import jscl.math.Generic;
import jscl.math.function.Constant;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.core.R;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.plot.PlotInput;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.collections.CollectionsUtils;
@ -82,7 +84,8 @@ public enum CalculatorDisplayMenuItem implements LabeledMenuItem<CalculatorDispl
final Constant constant = CollectionsUtils.getFirstCollectionElement(CalculatorUtils.getNotSystemConstants(generic));
assert constant != null;
CalculatorActivityLauncher.plotGraph(context, generic, constant);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.plot_graph, PlotInput.newInstance(generic, constant));
}
@Override

View File

@ -45,7 +45,7 @@ public class CalculatorDisplayOnClickListener implements View.OnClickListener {
} else {
final String errorMessage = displayViewState.getErrorMessage();
if (errorMessage != null) {
AndroidCalculator.showEvaluationError(context, errorMessage);
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_evaluation_error, errorMessage);
}
}
}

View File

@ -0,0 +1,42 @@
package org.solovyev.android.calculator.plot;
import jscl.math.Generic;
import jscl.math.function.Constant;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 12/1/12
* Time: 5:09 PM
*/
public class PlotInput {
@NotNull
private Generic function;
@NotNull
private Constant constant;
public PlotInput() {
}
private PlotInput(@NotNull Generic function, @NotNull Constant constant) {
this.function = function;
this.constant = constant;
}
@NotNull
public static PlotInput newInstance(@NotNull Generic function, @NotNull Constant constant) {
return new PlotInput(function, constant);
}
@NotNull
public Generic getFunction() {
return function;
}
@NotNull
public Constant getConstant() {
return constant;
}
}

View File

@ -6,10 +6,10 @@ import android.view.View;
import android.view.WindowManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.ToJsclTextProcessor;
import org.solovyev.android.calculator.core.R;
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.common.MutableObject;
import org.solovyev.common.text.StringUtils;

View File

@ -10,11 +10,10 @@ import android.view.ViewGroup;
import android.widget.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorImpl;
import org.solovyev.math.units.*;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.core.R;
import org.solovyev.android.view.ViewBuilder;
import org.solovyev.android.view.ViewFromLayoutBuilder;
import org.solovyev.math.units.*;
import java.util.Collections;
import java.util.List;

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.solovyev.android.calculator.onscreen"
android:versionCode="1"
android:versionName="1.0"/>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId>
<version>1.5.3-SNAPSHOT</version>
</parent>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-onscreen</artifactId>
<version>1.5.3-SNAPSHOT</version>
<name>Calculator++ Application Onscreen</name>
<packaging>apklib</packaging>
<dependencies>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-core</artifactId>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-core</artifactId>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
</extension>
</extensions>
</build>
</project>

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
style="@style/cpp_widget_main_layout_style">
style="@style/cpp_onscreen_main_layout_style">
<include a:id="@+id/onscreen_header" layout="@layout/onscreen_header"/>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="cpp_onscreen_cursor_color">#ff707070</color>
</resources>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="cpp_onscreen_main_layout_style" parent="cpp_default_main_layout_style">
<item name="android:padding">1dp</item>
</style>
</resources>

View File

@ -15,7 +15,6 @@ import org.solovyev.android.AndroidUtils;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.external.*;
/**
@ -112,7 +111,7 @@ public class CalculatorOnscreenService extends Service implements ExternalCalcul
@NotNull
private static String getCursorColor(@NotNull Context context) {
if (cursorColor == null) {
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_widget_cursor_color)).substring(2);
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.cpp_onscreen_cursor_color)).substring(2);
}
return cursorColor;
}

View File

@ -10,7 +10,7 @@ import android.widget.ImageView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.widget.WidgetButton;
import org.solovyev.android.calculator.CalculatorButton;
/**
* User: serso
@ -153,14 +153,14 @@ public class CalculatorOnscreenView {
private void init() {
if (!initialized) {
for (final WidgetButton widgetButton : WidgetButton.values()) {
for (final CalculatorButton widgetButton : CalculatorButton.values()) {
final View button = root.findViewById(widgetButton.getButtonId());
if (button != null) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
widgetButton.onClick(context);
if ( widgetButton == WidgetButton.app ) {
if ( widgetButton == CalculatorButton.app ) {
minimize();
}
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cpp_widget_editor_text_size">25sp</dimen>
<dimen name="cpp_widget_keyboard_button_text_size">20dp</dimen>
<dimen name="cpp_widget_display_text_size">25sp</dimen>
<dimen name="cpp_widget_margin">6dp</dimen>
</resources>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="cpp_widget_main_layout_style" parent="cpp_default_main_layout_style">
<item name="android:padding">1dp</item>
<item name="android:layout_margin">@dimen/cpp_widget_margin</item>
@ -13,20 +14,4 @@
<item name="android:textSize">@dimen/cpp_widget_display_text_size</item>
</style>
<style name="widget_metro_digit_button_style" parent="metro_digit_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_control_button_style" parent="metro_control_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_blue_operation_button_style" parent="metro_blue_operation_button_style">
<item name="android:textSize">@dimen/cpp_widget_keyboard_button_text_size</item>
</style>
<style name="widget_metro_control_image_button_style" parent="metro_control_image_button_style">
<item name="android:scaleType">center</item>
</style>
</resources>

View File

@ -10,10 +10,7 @@ import android.text.Html;
import android.widget.RemoteViews;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorButtons;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.external.ExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
@ -113,7 +110,7 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
for (int appWidgetId : appWidgetIds) {
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
for (WidgetButton button : WidgetButton.values()) {
for (CalculatorButton button : CalculatorButton.values()) {
final Intent onButtonClickIntent = new Intent(context, getComponentClass());
onButtonClickIntent.setAction(BUTTON_PRESSED_ACTION);
onButtonClickIntent.putExtra(BUTTON_ID_EXTRA, button.getButtonId());

View File

@ -3,6 +3,7 @@ package org.solovyev.android.calculator.widget;
import android.content.Context;
import android.content.Intent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorButton;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.external.DefaultExternalCalculatorIntentHandler;
import org.solovyev.android.calculator.external.ExternalCalculatorStateUpdater;
@ -25,7 +26,7 @@ public class CalculatorWidgetIntentHandler extends DefaultExternalCalculatorInte
if (AbstractCalculatorWidgetProvider.BUTTON_PRESSED_ACTION.equals(intent.getAction())) {
final int buttonId = intent.getIntExtra(AbstractCalculatorWidgetProvider.BUTTON_ID_EXTRA, 0);
final WidgetButton button = WidgetButton.getById(buttonId);
final CalculatorButton button = CalculatorButton.getById(buttonId);
if (button != null) {
button.onClick(context);
}

View File

@ -35,6 +35,12 @@
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-onscreen</artifactId>
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId>

View File

@ -1,14 +1,10 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import jscl.NumeralBase;
import jscl.math.Generic;
import org.jetbrains.annotations.NotNull;
@ -40,19 +36,6 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
PreferenceManager.getDefaultSharedPreferences(application).registerOnSharedPreferenceChangeListener(this);
}
public static void showEvaluationError(@NotNull Context context, @NotNull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setPositiveButton(R.string.c_cancel, null)
.setView(errorMessageView);
builder.create().show();
}
public void init(@NotNull final Activity activity) {
setEditor(activity);
setDisplay(activity);

View File

@ -1,10 +1,15 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import jscl.math.Generic;
import jscl.math.function.Constant;
@ -18,6 +23,7 @@ import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.math.edit.*;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
import org.solovyev.android.calculator.plot.PlotInput;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils;
@ -190,6 +196,40 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
}
});
break;
case plot_graph:
final PlotInput plotInput = (PlotInput) data;
assert plotInput != null;
App.getInstance().getUiThreadExecutor().execute(new Runnable() {
@Override
public void run() {
plotGraph(App.getInstance().getApplication(), plotInput.getFunction(), plotInput.getConstant());
}
});
break;
case show_evaluation_error:
final String errorMessage = (String) data;
if (errorMessage != null) {
App.getInstance().getUiThreadExecutor().execute(new Runnable() {
@Override
public void run() {
showEvaluationError(App.getInstance().getApplication(), errorMessage);
}
});
}
break;
}
}
public static void showEvaluationError(@NotNull Context context, @NotNull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setPositiveButton(R.string.c_cancel, null)
.setView(errorMessageView);
builder.create().show();
}
}

View File

@ -156,7 +156,13 @@ public enum CalculatorEventType {
show_like_dialog,
show_create_var_dialog,
show_create_function_dialog;
show_create_function_dialog,
//org.solovyev.android.calculator.plot.PlotInput
plot_graph,
//String
show_evaluation_error;
public boolean isOfType(@NotNull CalculatorEventType... types) {
for (CalculatorEventType type : types) {

View File

@ -26,6 +26,7 @@
<module>android-app</module>
<module>android-app-core</module>
<module>android-app-widget</module>
<module>android-app-onscreen</module>
<module>android-app-test</module>
<module>core</module>
</modules>
@ -60,6 +61,13 @@
</dependency>
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-android-app-onscreen</artifactId>
<version>1.5.3-SNAPSHOT</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId>
<version>${common.version}</version>