Calculator++ widget
@ -1,25 +1,13 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 19.10.12
|
* Date: 19.10.12
|
||||||
* Time: 17:31
|
* Time: 17:31
|
||||||
*/
|
*/
|
||||||
public final class CalculatorButtonActions {
|
public final class CalculatorButtonActions {
|
||||||
|
|
||||||
public static final String ERASE = "erase";
|
private CalculatorButtonActions() {
|
||||||
public static final String PASTE = "paste";
|
throw new AssertionError();
|
||||||
public static final String COPY = "copy";
|
}
|
||||||
public static final String CLEAR = "clear";
|
}
|
||||||
public static final String SHOW_FUNCTIONS = "functions";
|
|
||||||
public static final String SHOW_VARS = "vars";
|
|
||||||
public static final String SHOW_OPERATORS = "operators";
|
|
||||||
|
|
||||||
private CalculatorButtonActions() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String SHOW_HISTORY = "history";
|
|
||||||
public static final String MOVE_CURSOR_RIGHT = "▶";
|
|
||||||
public static final String MOVE_CURSOR_LEFT = "◀";
|
|
||||||
}
|
|
||||||
|
@ -5,12 +5,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/20/12
|
* Date: 9/20/12
|
||||||
* Time: 9:50 PM
|
* Time: 9:50 PM
|
||||||
*/
|
*/
|
||||||
public interface CalculatorDisplayViewState {
|
public interface CalculatorDisplayViewState extends Serializable {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
String getText();
|
String getText();
|
||||||
|
@ -13,11 +13,19 @@ import org.solovyev.common.text.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewState {
|
public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewState {
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* FIELDS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsclOperation operation = JsclOperation.numeric;
|
private JsclOperation operation = JsclOperation.numeric;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Generic result;
|
private transient Generic result;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String stringResult = "";
|
private String stringResult = "";
|
||||||
@ -29,6 +37,14 @@ public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewStat
|
|||||||
|
|
||||||
private int selection = 0;
|
private int selection = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* CONSTRUCTORS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
private CalculatorDisplayViewStateImpl() {
|
private CalculatorDisplayViewStateImpl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +78,14 @@ public class CalculatorDisplayViewStateImpl implements CalculatorDisplayViewStat
|
|||||||
return calculatorDisplayState;
|
return calculatorDisplayState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* METHODS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
|
@ -1,309 +1,311 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
import org.solovyev.android.calculator.history.EditorHistoryState;
|
import org.solovyev.android.calculator.history.EditorHistoryState;
|
||||||
import org.solovyev.common.gui.CursorControl;
|
import org.solovyev.common.gui.CursorControl;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 21.09.12
|
* Date: 21.09.12
|
||||||
* Time: 11:53
|
* Time: 11:53
|
||||||
*/
|
*/
|
||||||
public class CalculatorEditorImpl implements CalculatorEditor {
|
public class CalculatorEditorImpl implements CalculatorEditor {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CalculatorEditorView view;
|
private CalculatorEditorView view;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Object viewLock = new Object();
|
private final Object viewLock = new Object();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorEditorViewState lastViewState = CalculatorEditorViewStateImpl.newDefaultInstance();
|
private CalculatorEditorViewState lastViewState = CalculatorEditorViewStateImpl.newDefaultInstance();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Calculator calculator;
|
private final Calculator calculator;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorEventHolder lastEventHolder;
|
private final CalculatorEventHolder lastEventHolder;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CursorControlAdapter cursorControlAdapter = new CursorControlAdapter(this);
|
private final CursorControlAdapter cursorControlAdapter = new CursorControlAdapter(this);
|
||||||
|
|
||||||
public CalculatorEditorImpl(@NotNull Calculator calculator) {
|
public CalculatorEditorImpl(@NotNull Calculator calculator) {
|
||||||
this.calculator = calculator;
|
this.calculator = calculator;
|
||||||
this.calculator.addCalculatorEventListener(this);
|
this.calculator.addCalculatorEventListener(this);
|
||||||
this.lastEventHolder = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
this.lastEventHolder = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setView(@Nullable CalculatorEditorView view) {
|
public void setView(@Nullable CalculatorEditorView view) {
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
if ( view != null ) {
|
if ( view != null ) {
|
||||||
view.setState(lastViewState);
|
view.setState(lastViewState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public CalculatorEditorViewState getViewState() {
|
public CalculatorEditorViewState getViewState() {
|
||||||
return lastViewState;
|
return lastViewState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateViewState() {
|
public void updateViewState() {
|
||||||
setViewState(this.lastViewState, false);
|
setViewState(this.lastViewState, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setViewState(@NotNull CalculatorEditorViewState newViewState) {
|
public void setViewState(@NotNull CalculatorEditorViewState newViewState) {
|
||||||
setViewState(newViewState, true);
|
setViewState(newViewState, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setViewState(@NotNull CalculatorEditorViewState newViewState, boolean fireEvent) {
|
private void setViewState(@NotNull CalculatorEditorViewState newViewState, boolean majorChanges) {
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
final CalculatorEditorViewState oldViewState = this.lastViewState;
|
final CalculatorEditorViewState oldViewState = this.lastViewState;
|
||||||
|
|
||||||
this.lastViewState = newViewState;
|
this.lastViewState = newViewState;
|
||||||
if (this.view != null) {
|
if (this.view != null) {
|
||||||
this.view.setState(newViewState);
|
this.view.setState(newViewState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fireEvent) {
|
if (majorChanges) {
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.editor_state_changed, new CalculatorEditorChangeEventDataImpl(oldViewState, newViewState));
|
calculator.fireCalculatorEvent(CalculatorEventType.editor_state_changed, new CalculatorEditorChangeEventDataImpl(oldViewState, newViewState));
|
||||||
}
|
} else {
|
||||||
}
|
calculator.fireCalculatorEvent(CalculatorEventType.editor_state_changed_light, new CalculatorEditorChangeEventDataImpl(oldViewState, newViewState));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
|
||||||
@NotNull CalculatorEventType calculatorEventType,
|
@Override
|
||||||
@Nullable Object data) {
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
||||||
final CalculatorEventHolder.Result result = lastEventHolder.apply(calculatorEventData);
|
@NotNull CalculatorEventType calculatorEventType,
|
||||||
|
@Nullable Object data) {
|
||||||
if (result.isNewAfter()) {
|
final CalculatorEventHolder.Result result = lastEventHolder.apply(calculatorEventData);
|
||||||
switch (calculatorEventType) {
|
|
||||||
case use_history_state:
|
if (result.isNewAfter()) {
|
||||||
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
|
switch (calculatorEventType) {
|
||||||
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
|
case use_history_state:
|
||||||
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
|
||||||
break;
|
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
|
||||||
}
|
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
}
|
||||||
**********************************************************************
|
|
||||||
*
|
/*
|
||||||
* SELECTION
|
**********************************************************************
|
||||||
*
|
*
|
||||||
**********************************************************************
|
* SELECTION
|
||||||
*/
|
*
|
||||||
|
**********************************************************************
|
||||||
@NotNull
|
*/
|
||||||
private CalculatorEditorViewState newSelectionViewState(int newSelection) {
|
|
||||||
if (this.lastViewState.getSelection() != newSelection) {
|
@NotNull
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection);
|
private CalculatorEditorViewState newSelectionViewState(int newSelection) {
|
||||||
setViewState(result, false);
|
if (this.lastViewState.getSelection() != newSelection) {
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection);
|
||||||
} else {
|
setViewState(result, false);
|
||||||
return this.lastViewState;
|
return result;
|
||||||
}
|
} else {
|
||||||
}
|
return this.lastViewState;
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
public CalculatorEditorViewState setCursorOnStart() {
|
|
||||||
synchronized (viewLock) {
|
@NotNull
|
||||||
return newSelectionViewState(0);
|
public CalculatorEditorViewState setCursorOnStart() {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
}
|
return newSelectionViewState(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
public CalculatorEditorViewState setCursorOnEnd() {
|
|
||||||
synchronized (viewLock) {
|
@NotNull
|
||||||
return newSelectionViewState(this.lastViewState.getText().length());
|
public CalculatorEditorViewState setCursorOnEnd() {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
}
|
return newSelectionViewState(this.lastViewState.getText().length());
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
public CalculatorEditorViewState moveCursorLeft() {
|
|
||||||
synchronized (viewLock) {
|
@NotNull
|
||||||
if (this.lastViewState.getSelection() > 0) {
|
public CalculatorEditorViewState moveCursorLeft() {
|
||||||
return newSelectionViewState(this.lastViewState.getSelection() - 1);
|
synchronized (viewLock) {
|
||||||
} else {
|
if (this.lastViewState.getSelection() > 0) {
|
||||||
return this.lastViewState;
|
return newSelectionViewState(this.lastViewState.getSelection() - 1);
|
||||||
}
|
} else {
|
||||||
}
|
return this.lastViewState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
public CalculatorEditorViewState moveCursorRight() {
|
|
||||||
synchronized (viewLock) {
|
@NotNull
|
||||||
if (this.lastViewState.getSelection() < this.lastViewState.getText().length()) {
|
public CalculatorEditorViewState moveCursorRight() {
|
||||||
return newSelectionViewState(this.lastViewState.getSelection() + 1);
|
synchronized (viewLock) {
|
||||||
} else {
|
if (this.lastViewState.getSelection() < this.lastViewState.getText().length()) {
|
||||||
return this.lastViewState;
|
return newSelectionViewState(this.lastViewState.getSelection() + 1);
|
||||||
}
|
} else {
|
||||||
}
|
return this.lastViewState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CursorControl asCursorControl() {
|
@NotNull
|
||||||
return cursorControlAdapter;
|
@Override
|
||||||
}
|
public CursorControl asCursorControl() {
|
||||||
|
return cursorControlAdapter;
|
||||||
/*
|
}
|
||||||
**********************************************************************
|
|
||||||
*
|
/*
|
||||||
* EDITOR ACTIONS
|
**********************************************************************
|
||||||
*
|
*
|
||||||
**********************************************************************
|
* EDITOR ACTIONS
|
||||||
*/
|
*
|
||||||
|
**********************************************************************
|
||||||
@NotNull
|
*/
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState erase() {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
int selection = this.lastViewState.getSelection();
|
public CalculatorEditorViewState erase() {
|
||||||
final String text = this.lastViewState.getText();
|
synchronized (viewLock) {
|
||||||
if (selection > 0 && text.length() > 0 && selection <= text.length()) {
|
int selection = this.lastViewState.getSelection();
|
||||||
final StringBuilder newText = new StringBuilder(text.length() - 1);
|
final String text = this.lastViewState.getText();
|
||||||
newText.append(text.substring(0, selection - 1)).append(text.substring(selection, text.length()));
|
if (selection > 0 && text.length() > 0 && selection <= text.length()) {
|
||||||
|
final StringBuilder newText = new StringBuilder(text.length() - 1);
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), selection - 1);
|
newText.append(text.substring(0, selection - 1)).append(text.substring(selection, text.length()));
|
||||||
setViewState(result);
|
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), selection - 1);
|
||||||
} else {
|
setViewState(result);
|
||||||
return this.lastViewState;
|
return result;
|
||||||
}
|
} else {
|
||||||
}
|
return this.lastViewState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState clear() {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
return setText("");
|
public CalculatorEditorViewState clear() {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
}
|
return setText("");
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState setText(@NotNull String text) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, text.length());
|
public CalculatorEditorViewState setText(@NotNull String text) {
|
||||||
setViewState(result);
|
synchronized (viewLock) {
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, text.length());
|
||||||
}
|
setViewState(result);
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState setText(@NotNull String text, int selection) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
selection = correctSelection(selection, text);
|
public CalculatorEditorViewState setText(@NotNull String text, int selection) {
|
||||||
|
synchronized (viewLock) {
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, selection);
|
selection = correctSelection(selection, text);
|
||||||
setViewState(result);
|
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, selection);
|
||||||
}
|
setViewState(result);
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState insert(@NotNull String text) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
return insert(text, 0);
|
public CalculatorEditorViewState insert(@NotNull String text) {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
}
|
return insert(text, 0);
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState insert(@NotNull String text, int selectionOffset) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
final int selection = this.lastViewState.getSelection();
|
public CalculatorEditorViewState insert(@NotNull String text, int selectionOffset) {
|
||||||
final String oldText = this.lastViewState.getText();
|
synchronized (viewLock) {
|
||||||
|
final int selection = this.lastViewState.getSelection();
|
||||||
int newTextLength = text.length() + oldText.length();
|
final String oldText = this.lastViewState.getText();
|
||||||
final StringBuilder newText = new StringBuilder(newTextLength);
|
|
||||||
|
int newTextLength = text.length() + oldText.length();
|
||||||
newText.append(oldText.substring(0, selection));
|
final StringBuilder newText = new StringBuilder(newTextLength);
|
||||||
newText.append(text);
|
|
||||||
newText.append(oldText.substring(selection));
|
newText.append(oldText.substring(0, selection));
|
||||||
|
newText.append(text);
|
||||||
int newSelection = correctSelection(text.length() + selection + selectionOffset, newTextLength);
|
newText.append(oldText.substring(selection));
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), newSelection);
|
|
||||||
setViewState(result);
|
int newSelection = correctSelection(text.length() + selection + selectionOffset, newTextLength);
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), newSelection);
|
||||||
}
|
setViewState(result);
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState moveSelection(int offset) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
int selection = this.lastViewState.getSelection() + offset;
|
public CalculatorEditorViewState moveSelection(int offset) {
|
||||||
|
synchronized (viewLock) {
|
||||||
return setSelection(selection);
|
int selection = this.lastViewState.getSelection() + offset;
|
||||||
}
|
|
||||||
}
|
return setSelection(selection);
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
public CalculatorEditorViewState setSelection(int selection) {
|
@NotNull
|
||||||
synchronized (viewLock) {
|
@Override
|
||||||
selection = correctSelection(selection, this.lastViewState.getText());
|
public CalculatorEditorViewState setSelection(int selection) {
|
||||||
|
synchronized (viewLock) {
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection);
|
selection = correctSelection(selection, this.lastViewState.getText());
|
||||||
setViewState(result, false);
|
|
||||||
return result;
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection);
|
||||||
}
|
setViewState(result, false);
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
private int correctSelection(int selection, @NotNull String text) {
|
}
|
||||||
return correctSelection(selection, text.length());
|
|
||||||
}
|
private int correctSelection(int selection, @NotNull String text) {
|
||||||
|
return correctSelection(selection, text.length());
|
||||||
private int correctSelection(int selection, int textLength) {
|
}
|
||||||
int result = Math.max(selection, 0);
|
|
||||||
result = Math.min(result, textLength);
|
private int correctSelection(int selection, int textLength) {
|
||||||
return result;
|
int result = Math.max(selection, 0);
|
||||||
}
|
result = Math.min(result, textLength);
|
||||||
|
return result;
|
||||||
private static final class CursorControlAdapter implements CursorControl {
|
}
|
||||||
|
|
||||||
@NotNull
|
private static final class CursorControlAdapter implements CursorControl {
|
||||||
private final CalculatorEditor calculatorEditor;
|
|
||||||
|
@NotNull
|
||||||
private CursorControlAdapter(@NotNull CalculatorEditor calculatorEditor) {
|
private final CalculatorEditor calculatorEditor;
|
||||||
this.calculatorEditor = calculatorEditor;
|
|
||||||
}
|
private CursorControlAdapter(@NotNull CalculatorEditor calculatorEditor) {
|
||||||
|
this.calculatorEditor = calculatorEditor;
|
||||||
@Override
|
}
|
||||||
public void setCursorOnStart() {
|
|
||||||
this.calculatorEditor.setCursorOnStart();
|
@Override
|
||||||
}
|
public void setCursorOnStart() {
|
||||||
|
this.calculatorEditor.setCursorOnStart();
|
||||||
@Override
|
}
|
||||||
public void setCursorOnEnd() {
|
|
||||||
this.calculatorEditor.setCursorOnEnd();
|
@Override
|
||||||
}
|
public void setCursorOnEnd() {
|
||||||
|
this.calculatorEditor.setCursorOnEnd();
|
||||||
@Override
|
}
|
||||||
public void moveCursorLeft() {
|
|
||||||
this.calculatorEditor.moveCursorLeft();
|
@Override
|
||||||
}
|
public void moveCursorLeft() {
|
||||||
|
this.calculatorEditor.moveCursorLeft();
|
||||||
@Override
|
}
|
||||||
public void moveCursorRight() {
|
|
||||||
this.calculatorEditor.moveCursorRight();
|
@Override
|
||||||
}
|
public void moveCursorRight() {
|
||||||
}
|
this.calculatorEditor.moveCursorRight();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
import java.io.Serializable;
|
||||||
* User: Solovyev_S
|
|
||||||
* Date: 21.09.12
|
/**
|
||||||
* Time: 11:48
|
* User: Solovyev_S
|
||||||
*/
|
* Date: 21.09.12
|
||||||
public interface CalculatorEditorViewState {
|
* Time: 11:48
|
||||||
|
*/
|
||||||
@NotNull
|
public interface CalculatorEditorViewState extends Serializable {
|
||||||
String getText();
|
|
||||||
|
@NotNull
|
||||||
int getSelection();
|
String getText();
|
||||||
}
|
|
||||||
|
int getSelection();
|
||||||
|
}
|
||||||
|
@ -1,141 +1,154 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 20.09.12
|
* Date: 20.09.12
|
||||||
* Time: 16:40
|
* Time: 16:40
|
||||||
*/
|
*/
|
||||||
public enum CalculatorEventType {
|
public enum CalculatorEventType {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* CALCULATION
|
* CALCULATION
|
||||||
* org.solovyev.android.calculator.CalculatorEvaluationEventData
|
* org.solovyev.android.calculator.CalculatorEvaluationEventData
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// @NotNull CalculatorEditorViewState
|
// @NotNull CalculatorEditorViewState
|
||||||
manual_calculation_requested,
|
manual_calculation_requested,
|
||||||
|
|
||||||
// @NotNull org.solovyev.android.calculator.CalculatorOutput
|
// @NotNull org.solovyev.android.calculator.CalculatorOutput
|
||||||
calculation_result,
|
calculation_result,
|
||||||
|
|
||||||
calculation_cancelled,
|
calculation_cancelled,
|
||||||
|
|
||||||
// @NotNull org.solovyev.android.calculator.CalculatorFailure
|
// @NotNull org.solovyev.android.calculator.CalculatorFailure
|
||||||
calculation_failed,
|
calculation_failed,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* CONVERSION
|
* CONVERSION
|
||||||
* CalculatorConversionEventData
|
* CalculatorConversionEventData
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
conversion_started,
|
conversion_started,
|
||||||
|
|
||||||
// @NotNull String conversion result
|
// @NotNull String conversion result
|
||||||
conversion_result,
|
conversion_result,
|
||||||
|
|
||||||
// @NotNull ConversionFailure
|
// @NotNull ConversionFailure
|
||||||
conversion_failed,
|
conversion_failed,
|
||||||
|
|
||||||
conversion_finished,
|
conversion_finished,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* EDITOR
|
* EDITOR
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @NotNull org.solovyev.android.calculator.CalculatorEditorChangeEventData
|
// @NotNull org.solovyev.android.calculator.CalculatorEditorChangeEventData
|
||||||
editor_state_changed,
|
editor_state_changed,
|
||||||
|
editor_state_changed_light,
|
||||||
// @NotNull CalculatorDisplayChangeEventData
|
|
||||||
display_state_changed,
|
// @NotNull CalculatorDisplayChangeEventData
|
||||||
|
display_state_changed,
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* ENGINE
|
*
|
||||||
*
|
* ENGINE
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
engine_preferences_changed,
|
|
||||||
|
engine_preferences_changed,
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* HISTORY
|
*
|
||||||
*
|
* HISTORY
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
// @NotNull CalculatorHistoryState
|
|
||||||
history_state_added,
|
// @NotNull CalculatorHistoryState
|
||||||
|
history_state_added,
|
||||||
// @NotNull CalculatorHistoryState
|
|
||||||
use_history_state,
|
// @NotNull CalculatorHistoryState
|
||||||
|
use_history_state,
|
||||||
clear_history_requested,
|
|
||||||
|
clear_history_requested,
|
||||||
show_history,
|
|
||||||
|
/*
|
||||||
/*
|
**********************************************************************
|
||||||
**********************************************************************
|
*
|
||||||
*
|
* MATH ENTITIES
|
||||||
* MATH ENTITIES
|
*
|
||||||
*
|
**********************************************************************
|
||||||
**********************************************************************
|
*/
|
||||||
*/
|
|
||||||
|
// @NotNull IConstant
|
||||||
// @NotNull IConstant
|
use_constant,
|
||||||
use_constant,
|
|
||||||
|
// @NotNull Function
|
||||||
// @NotNull Function
|
use_function,
|
||||||
use_function,
|
|
||||||
|
// @NotNull Operator
|
||||||
// @NotNull Operator
|
use_operator,
|
||||||
use_operator,
|
|
||||||
|
// @NotNull IConstant
|
||||||
// @NotNull IConstant
|
constant_added,
|
||||||
constant_added,
|
|
||||||
|
// @NotNull Change<IConstant>
|
||||||
// @NotNull Change<IConstant>
|
constant_changed,
|
||||||
constant_changed,
|
|
||||||
|
// @NotNull IConstant
|
||||||
// @NotNull IConstant
|
constant_removed,
|
||||||
constant_removed,
|
|
||||||
|
/*
|
||||||
/*
|
**********************************************************************
|
||||||
**********************************************************************
|
*
|
||||||
*
|
* OTHER
|
||||||
* OTHER
|
*
|
||||||
*
|
**********************************************************************
|
||||||
**********************************************************************
|
*/
|
||||||
*/
|
show_history,
|
||||||
|
show_history_detached,
|
||||||
show_functions,
|
|
||||||
show_vars,
|
show_functions,
|
||||||
show_operators;
|
show_functions_detached,
|
||||||
|
|
||||||
public boolean isOfType(@NotNull CalculatorEventType... types) {
|
show_vars,
|
||||||
for (CalculatorEventType type : types) {
|
show_vars_detached,
|
||||||
if ( this == type ) {
|
|
||||||
return true;
|
open_app,
|
||||||
}
|
|
||||||
}
|
show_operators,
|
||||||
|
show_operators_detached,
|
||||||
return false;
|
|
||||||
}
|
show_settings,
|
||||||
|
show_settings_detached,
|
||||||
}
|
|
||||||
|
show_like_dialog;
|
||||||
|
|
||||||
|
public boolean isOfType(@NotNull CalculatorEventType... types) {
|
||||||
|
for (CalculatorEventType type : types) {
|
||||||
|
if ( this == type ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,142 +1,124 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/22/12
|
* Date: 9/22/12
|
||||||
* Time: 1:08 PM
|
* Time: 1:08 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorKeyboardImpl implements CalculatorKeyboard {
|
public class CalculatorKeyboardImpl implements CalculatorKeyboard {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Calculator calculator;
|
private final Calculator calculator;
|
||||||
|
|
||||||
public CalculatorKeyboardImpl(@NotNull Calculator calculator) {
|
public CalculatorKeyboardImpl(@NotNull Calculator calculator) {
|
||||||
this.calculator = calculator;
|
this.calculator = calculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed(@Nullable final String text) {
|
public void buttonPressed(@Nullable final String text) {
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
assert text != null;
|
assert text != null;
|
||||||
|
|
||||||
// process special buttons
|
// process special buttons
|
||||||
boolean processed = processSpecialButtons(text);
|
boolean processed = processSpecialButtons(text);
|
||||||
|
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
int cursorPositionOffset = 0;
|
int cursorPositionOffset = 0;
|
||||||
final StringBuilder textToBeInserted = new StringBuilder(text);
|
final StringBuilder textToBeInserted = new StringBuilder(text);
|
||||||
|
|
||||||
final MathType.Result mathType = MathType.getType(text, 0, false);
|
final MathType.Result mathType = MathType.getType(text, 0, false);
|
||||||
switch (mathType.getMathType()) {
|
switch (mathType.getMathType()) {
|
||||||
case function:
|
case function:
|
||||||
textToBeInserted.append("()");
|
textToBeInserted.append("()");
|
||||||
cursorPositionOffset = -1;
|
cursorPositionOffset = -1;
|
||||||
break;
|
break;
|
||||||
case operator:
|
case operator:
|
||||||
textToBeInserted.append("()");
|
textToBeInserted.append("()");
|
||||||
cursorPositionOffset = -1;
|
cursorPositionOffset = -1;
|
||||||
break;
|
break;
|
||||||
case comma:
|
case comma:
|
||||||
textToBeInserted.append(" ");
|
textToBeInserted.append(" ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursorPositionOffset == 0) {
|
if (cursorPositionOffset == 0) {
|
||||||
if (MathType.openGroupSymbols.contains(text)) {
|
if (MathType.openGroupSymbols.contains(text)) {
|
||||||
cursorPositionOffset = -1;
|
cursorPositionOffset = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
|
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
|
||||||
editor.insert(textToBeInserted.toString(), cursorPositionOffset);
|
editor.insert(textToBeInserted.toString(), cursorPositionOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processSpecialButtons(@NotNull String text) {
|
private boolean processSpecialButtons(@NotNull String text) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
if (CalculatorButtonActions.MOVE_CURSOR_LEFT.equals(text)) {
|
final CalculatorSpecialButton button = CalculatorSpecialButton.getByActionCode(text);
|
||||||
this.moveCursorLeft();
|
if ( button != null ) {
|
||||||
result = true;
|
button.onClick(this);
|
||||||
} else if (CalculatorButtonActions.MOVE_CURSOR_RIGHT.equals(text)) {
|
result = true;
|
||||||
this.moveCursorRight();
|
}
|
||||||
result = true;
|
|
||||||
} else if (CalculatorButtonActions.SHOW_HISTORY.equals(text)) {
|
return result;
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history, null);
|
}
|
||||||
} else if (CalculatorButtonActions.ERASE.equals(text)) {
|
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().erase();
|
@Override
|
||||||
} else if (CalculatorButtonActions.COPY.equals(text)) {
|
public void roundBracketsButtonPressed() {
|
||||||
copyButtonPressed();
|
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
|
||||||
} else if (CalculatorButtonActions.PASTE.equals(text)) {
|
CalculatorEditorViewState viewState = editor.getViewState();
|
||||||
pasteButtonPressed();
|
|
||||||
} else if (CalculatorButtonActions.CLEAR.equals(text)) {
|
final int cursorPosition = viewState.getSelection();
|
||||||
clearButtonPressed();
|
final String oldText = viewState.getText();
|
||||||
} else if (CalculatorButtonActions.SHOW_FUNCTIONS.equals(text)) {
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions, null);
|
final StringBuilder newText = new StringBuilder(oldText.length() + 2);
|
||||||
} else if (CalculatorButtonActions.SHOW_OPERATORS.equals(text)) {
|
newText.append("(");
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
|
newText.append(oldText.substring(0, cursorPosition));
|
||||||
} else if (CalculatorButtonActions.SHOW_VARS.equals(text)) {
|
newText.append(")");
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars, null);
|
newText.append(oldText.substring(cursorPosition));
|
||||||
}
|
editor.setText(newText.toString(), cursorPosition + 2);
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
@Override
|
||||||
|
public void pasteButtonPressed() {
|
||||||
@Override
|
final String text = CalculatorLocatorImpl.getInstance().getClipboard().getText();
|
||||||
public void roundBracketsButtonPressed() {
|
if (text != null) {
|
||||||
final CalculatorEditor editor = CalculatorLocatorImpl.getInstance().getEditor();
|
CalculatorLocatorImpl.getInstance().getEditor().insert(text);
|
||||||
CalculatorEditorViewState viewState = editor.getViewState();
|
}
|
||||||
|
}
|
||||||
final int cursorPosition = viewState.getSelection();
|
|
||||||
final String oldText = viewState.getText();
|
@Override
|
||||||
|
public void clearButtonPressed() {
|
||||||
final StringBuilder newText = new StringBuilder(oldText.length() + 2);
|
CalculatorLocatorImpl.getInstance().getEditor().clear();
|
||||||
newText.append("(");
|
}
|
||||||
newText.append(oldText.substring(0, cursorPosition));
|
|
||||||
newText.append(")");
|
@Override
|
||||||
newText.append(oldText.substring(cursorPosition));
|
public void copyButtonPressed() {
|
||||||
editor.setText(newText.toString(), cursorPosition + 2);
|
final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState();
|
||||||
}
|
if (displayViewState.isValid()) {
|
||||||
|
final CharSequence text = displayViewState.getText();
|
||||||
@Override
|
if (!StringUtils.isEmpty(text)) {
|
||||||
public void pasteButtonPressed() {
|
CalculatorLocatorImpl.getInstance().getClipboard().setText(text);
|
||||||
final String text = CalculatorLocatorImpl.getInstance().getClipboard().getText();
|
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
|
||||||
if (text != null) {
|
}
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().insert(text);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void moveCursorLeft() {
|
||||||
public void clearButtonPressed() {
|
CalculatorLocatorImpl.getInstance().getEditor().moveCursorLeft();
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().clear();
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void moveCursorRight() {
|
||||||
public void copyButtonPressed() {
|
CalculatorLocatorImpl.getInstance().getEditor().moveCursorRight();
|
||||||
final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState();
|
}
|
||||||
if (displayViewState.isValid()) {
|
}
|
||||||
final CharSequence text = displayViewState.getText();
|
|
||||||
if (!StringUtils.isEmpty(text)) {
|
|
||||||
CalculatorLocatorImpl.getInstance().getClipboard().setText(text);
|
|
||||||
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void moveCursorLeft() {
|
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().moveCursorLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void moveCursorRight() {
|
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().moveCursorRight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -19,4 +19,6 @@ public interface CalculatorNotifier {
|
|||||||
void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @NotNull List<Object> parameters);
|
void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @NotNull List<Object> parameters);
|
||||||
|
|
||||||
void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters);
|
void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters);
|
||||||
|
|
||||||
|
void showDebugMessage(@Nullable String tag, @NotNull String message);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,155 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/20/12
|
||||||
|
* Time: 2:05 PM
|
||||||
|
*/
|
||||||
|
public enum CalculatorSpecialButton {
|
||||||
|
|
||||||
|
history("history") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
history_detached("history_detached") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_history_detached, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cursor_right("▶") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
keyboard.moveCursorRight();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cursor_left("◀") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
keyboard.moveCursorLeft();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
settings("settings") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
settings_detached("settings_detached") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings_detached, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
like("like") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_like_dialog, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
erase("erase") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getEditor().erase();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
paste("paste") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
keyboard.pasteButtonPressed();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
copy("copy") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
keyboard.copyButtonPressed();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
equals("=") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().evaluate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clear("clear") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
keyboard.clearButtonPressed();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
functions("functions") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
functions_detached("functions_detached") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_functions_detached, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
open_app("open_app") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.open_app, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vars("vars") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vars_detached("vars_detached") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_vars_detached, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
operators("operators") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
operators_detached("operators_detached") {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NotNull CalculatorKeyboard keyboard) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators_detached, null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final String actionCode;
|
||||||
|
|
||||||
|
CalculatorSpecialButton(@NotNull String actionCode) {
|
||||||
|
this.actionCode = actionCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getActionCode() {
|
||||||
|
return actionCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static CalculatorSpecialButton getByActionCode(@NotNull String actionCode) {
|
||||||
|
for (CalculatorSpecialButton button : values()) {
|
||||||
|
if (button.getActionCode().equals(actionCode)) {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onClick(@NotNull CalculatorKeyboard keyboard);
|
||||||
|
}
|
@ -25,4 +25,8 @@ public class DummyCalculatorNotifier implements CalculatorNotifier {
|
|||||||
@Override
|
@Override
|
||||||
public void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters) {
|
public void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showDebugMessage(@Nullable String tag, @NotNull String message) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
|
|||||||
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
|
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
|
||||||
|
|
||||||
for (CalculatorEvent e : calculatorEvents) {
|
for (CalculatorEvent e : calculatorEvents) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getLogger().debug(TAG, "Event fired: " + e.getCalculatorEventType());
|
||||||
for (CalculatorEventListener listener : listeners) {
|
for (CalculatorEventListener listener : listeners) {
|
||||||
/*long startTime = System.currentTimeMillis();*/
|
/*long startTime = System.currentTimeMillis();*/
|
||||||
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import jscl.math.Expression;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/20/12
|
||||||
|
* Time: 12:24 PM
|
||||||
|
*/
|
||||||
|
public class CalculatorDisplayViewStateImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializable() throws Exception {
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, null, "test", 3));
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, Expression.valueOf("3"), "test", 3));
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorDisplayViewStateImpl.newValidState(JsclOperation.simplify, Expression.valueOf("3+3"), "test", 3));
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorDisplayViewStateImpl.newDefaultInstance());
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.numeric, "ertert"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/20/12
|
||||||
|
* Time: 12:31 PM
|
||||||
|
*/
|
||||||
|
public class CalculatorEditorViewStateImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerialization() throws Exception {
|
||||||
|
CalculatorTestUtils.testSerialization(CalculatorEditorViewStateImpl.newDefaultInstance());
|
||||||
|
|
||||||
|
CalculatorEditorViewState out = CalculatorTestUtils.testSerialization(CalculatorEditorViewStateImpl.newInstance("treter", 2));
|
||||||
|
Assert.assertEquals(2, out.getSelection());
|
||||||
|
Assert.assertEquals("treter", out.getText());
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import org.mockito.Mockito;
|
|||||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ public class CalculatorTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void assertEval(@NotNull String expected, @NotNull String expression) {
|
public static void assertEval(@NotNull String expected, @NotNull String expression) {
|
||||||
assertEval(expected, expression, JsclOperation.numeric);
|
assertEval(expected, expression, JsclOperation.numeric);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertEval(@NotNull String expected, @NotNull String expression, @NotNull JsclOperation operation) {
|
public static void assertEval(@NotNull String expected, @NotNull String expression, @NotNull JsclOperation operation) {
|
||||||
@ -57,8 +58,8 @@ public class CalculatorTestUtils {
|
|||||||
calculatorEventListener.setCalculatorEventData(calculator.evaluate(operation, expression));
|
calculatorEventListener.setCalculatorEventData(calculator.evaluate(operation, expression));
|
||||||
|
|
||||||
if (latch.await(TIMEOUT, TimeUnit.SECONDS)) {
|
if (latch.await(TIMEOUT, TimeUnit.SECONDS)) {
|
||||||
Assert.assertNotNull(calculatorEventListener.getResult());
|
Assert.assertNotNull(calculatorEventListener.getResult());
|
||||||
Assert.assertEquals(expected, calculatorEventListener.getResult().getText());
|
Assert.assertEquals(expected, calculatorEventListener.getResult().getText());
|
||||||
} else {
|
} else {
|
||||||
Assert.fail("Too long wait for: " + expression);
|
Assert.fail("Too long wait for: " + expression);
|
||||||
}
|
}
|
||||||
@ -74,7 +75,33 @@ public class CalculatorTestUtils {
|
|||||||
assertError(expression, JsclOperation.numeric);
|
assertError(expression, JsclOperation.numeric);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestCalculatorEventListener implements CalculatorEventListener {
|
public static <S extends Serializable> S testSerialization(@NotNull S serializable) throws IOException, ClassNotFoundException {
|
||||||
|
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
try {
|
||||||
|
oos = new ObjectOutputStream(out);
|
||||||
|
oos.writeObject(serializable);
|
||||||
|
} finally {
|
||||||
|
if (oos != null) {
|
||||||
|
oos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] serialized = out.toByteArray();
|
||||||
|
|
||||||
|
Assert.assertTrue(serialized.length > 0);
|
||||||
|
|
||||||
|
|
||||||
|
final ObjectInputStream resultStream = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
|
||||||
|
final S result = (S) resultStream.readObject();
|
||||||
|
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class TestCalculatorEventListener implements CalculatorEventListener {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CalculatorEventData calculatorEventData;
|
private CalculatorEventData calculatorEventData;
|
||||||
@ -95,7 +122,7 @@ public class CalculatorTestUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
if ( this.calculatorEventData != null && calculatorEventData.isSameSequence(this.calculatorEventData) ) {
|
if (this.calculatorEventData != null && calculatorEventData.isSameSequence(this.calculatorEventData)) {
|
||||||
if (calculatorEventType == CalculatorEventType.display_state_changed) {
|
if (calculatorEventType == CalculatorEventType.display_state_changed) {
|
||||||
final CalculatorDisplayChangeEventData displayChange = (CalculatorDisplayChangeEventData) data;
|
final CalculatorDisplayChangeEventData displayChange = (CalculatorDisplayChangeEventData) data;
|
||||||
|
|
||||||
|
@ -1,77 +1,80 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="100" android:versionName="1.4.2" package="org.solovyev.android.calculator">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="100" android:versionName="1.4.2" package="org.solovyev.android.calculator">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="com.android.vending.BILLING"/>
|
<uses-permission android:name="com.android.vending.BILLING"/>
|
||||||
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
|
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
|
||||||
|
|
||||||
<application android:debuggable="false" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication" android:theme="@style/metro_blue_theme">
|
<application android:debuggable="false" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication" android:theme="@style/metro_blue_theme">
|
||||||
|
|
||||||
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">
|
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan" android:clearTaskOnLaunch="true">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- settings must use action bar icon-->
|
<!-- settings must use action bar icon-->
|
||||||
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
|
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_help" android:name=".help.CalculatorHelpActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.CalculatorHelpActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
|
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
|
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||||
|
|
||||||
<activity android:name=".widget.CalculatorWidgetConfigurationActivity" android:theme="@style/metro_blue_theme">
|
<activity android:name=".widget.CalculatorWidgetConfigurationActivity" android:theme="@style/metro_blue_theme">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- settings must use action bar icon-->
|
<!-- settings must use action bar icon-->
|
||||||
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_settings" android:name=".plot.CalculatorPlotPreferenceActivity"/>
|
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_settings" android:name=".plot.CalculatorPlotPreferenceActivity"/>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:icon="@drawable/icon"
|
android:icon="@drawable/icon"
|
||||||
android:label="Example Widget"
|
android:label="@string/c_app_name"
|
||||||
android:name=".widget.CalculatorWidgetProvider">
|
android:name=".widget.CalculatorWidgetProvider">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||||
</intent-filter>
|
<action android:name="org.solovyev.calculator.widget.EDITOR_STATE_CHANGED"/>
|
||||||
|
<action android:name="org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED"/>
|
||||||
<meta-data
|
<action android:name="org.solovyev.calculator.widget.BUTTON_PRESSED"/>
|
||||||
android:name="android.appwidget.provider"
|
</intent-filter>
|
||||||
android:resource="@xml/calculator_widget_info"/>
|
|
||||||
</receiver>
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/>
|
android:resource="@xml/calculator_widget_info"/>
|
||||||
|
</receiver>
|
||||||
<service android:name="net.robotmedia.billing.BillingService"/>
|
|
||||||
<receiver android:name="net.robotmedia.billing.BillingReceiver">
|
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/>
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.android.vending.billing.IN_APP_NOTIFY"/>
|
<service android:name="net.robotmedia.billing.BillingService"/>
|
||||||
<action android:name="com.android.vending.billing.RESPONSE_CODE"/>
|
<receiver android:name="net.robotmedia.billing.BillingReceiver">
|
||||||
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
|
<intent-filter>
|
||||||
</intent-filter>
|
<action android:name="com.android.vending.billing.IN_APP_NOTIFY"/>
|
||||||
</receiver>
|
<action android:name="com.android.vending.billing.RESPONSE_CODE"/>
|
||||||
|
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
|
||||||
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:name="org.acra.CrashReportDialog" android:theme="@style/Theme.Sherlock.Dialog"/>
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
</application>
|
|
||||||
|
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:name="org.acra.CrashReportDialog" android:theme="@style/Theme.Sherlock.Dialog"/>
|
||||||
|
|
||||||
|
</application>
|
||||||
</manifest>
|
</manifest>
|
BIN
calculatorpp/misc/res/widget.png
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
calculatorpp/res/drawable-hdpi/kb_logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
calculatorpp/res/drawable-hdpi/kb_settings.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
calculatorpp/res/drawable-hdpi/logo_square.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
calculatorpp/res/drawable-ldpi/kb_logo.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
calculatorpp/res/drawable-ldpi/kb_settings.png
Normal file
After Width: | Height: | Size: 590 B |
BIN
calculatorpp/res/drawable-mdpi/kb_logo.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
calculatorpp/res/drawable-mdpi/kb_settings.png
Normal file
After Width: | Height: | Size: 868 B |
BIN
calculatorpp/res/drawable-nodpi/widget_preview.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
calculatorpp/res/drawable-xhdpi/ic_menu_preferences.png
Executable file
After Width: | Height: | Size: 2.5 KiB |
BIN
calculatorpp/res/drawable-xhdpi/kb_logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
calculatorpp/res/drawable-xhdpi/kb_settings.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
calculatorpp/res/drawable-xlarge-hdpi/kb_logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
calculatorpp/res/drawable-xlarge-hdpi/kb_settings.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
a:id="@+id/pasteButton"
|
a:id="@+id/copyButton"
|
||||||
a:drawableTop="@drawable/kb_copy"
|
a:drawableTop="@drawable/kb_copy"
|
||||||
style="?controlImageButtonStyle"
|
style="?controlImageButtonStyle"
|
||||||
a:onClick="copyButtonClickHandler"/>
|
a:onClick="copyButtonClickHandler"/>
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||||
a:id="@+id/squareBracketsButton"
|
a:id="@+id/periodButton"
|
||||||
a:text="."
|
a:text="."
|
||||||
c:textUp=","
|
c:textUp=","
|
||||||
c:directionTextScale="0.5"
|
c:directionTextScale="0.5"
|
||||||
|
13
calculatorpp/res/layout/widget_app_button.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/appButton"
|
||||||
|
a:src="@drawable/kb_logo"
|
||||||
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="App"/>
|
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/clearButton"
|
a:id="@+id/clearButton"
|
||||||
a:text="@string/c_clear"
|
a:text="@string/c_clear"
|
||||||
a:textStyle="bold"
|
a:textStyle="bold"
|
||||||
style="@style/metro_control_image_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/pasteButton"
|
a:id="@+id/copyButton"
|
||||||
a:drawableTop="@drawable/kb_copy"
|
a:src="@drawable/kb_copy"
|
||||||
style="@style/metro_control_image_button_style"/>
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="Copy"/>
|
@ -1,17 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/calculatorDisplay"
|
a:id="@+id/calculatorDisplay"
|
||||||
style="@style/display_style"
|
style="@style/widget_display_style"
|
||||||
a:padding="@dimen/display_padding"
|
a:textIsSelectable="true"
|
||||||
a:inputType="textMultiLine"
|
a:padding="@dimen/display_padding"
|
||||||
a:maxLines="3"
|
a:singleLine="false"
|
||||||
a:scrollHorizontally="false"
|
a:scrollbars="vertical"/>
|
||||||
a:scrollbars="none"/>
|
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/divisionButton"
|
a:id="@+id/divisionButton"
|
||||||
a:text="/"
|
a:text="/"
|
||||||
style="@style/metro_blue_operation_button_style"/>
|
style="@style/widget_metro_blue_operation_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/squareBracketsButton"
|
a:id="@+id/periodButton"
|
||||||
a:text="."
|
a:text="."
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/metro_digit_button_style"/>
|
@ -1,24 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/main_fragment_layout"
|
a:id="@+id/main_fragment_layout"
|
||||||
style="@style/default_fragment_layout_style"
|
style="@style/default_fragment_layout_style"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:padding="@dimen/editor_padding">
|
a:padding="@dimen/editor_padding">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:id="@+id/calculatorEditor"
|
a:id="@+id/calculatorEditor"
|
||||||
style="@style/editor_style"
|
style="@style/widget_editor_style"
|
||||||
a:textIsSelectable="true"
|
a:textIsSelectable="true"
|
||||||
a:singleLine="false"
|
a:singleLine="false"
|
||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
a:hint="@string/c_calc_editor_hint"/>
|
a:hint="@string/c_calc_editor_hint"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/eightDigitButton"
|
a:id="@+id/eightDigitButton"
|
||||||
a:text="8"
|
a:text="8"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button
|
<Button
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/equalsButton"
|
a:id="@+id/equalsButton"
|
||||||
a:text="="
|
a:text="="
|
||||||
style="@style/metro_control_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/eraseButton"
|
a:id="@+id/eraseButton"
|
||||||
a:drawableTop="@drawable/kb_delete"
|
a:src="@drawable/kb_delete"
|
||||||
style="@style/metro_control_image_button_style"/>
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="Erase"/>
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/fiveDigitButton"
|
a:id="@+id/fiveDigitButton"
|
||||||
a:text="5"
|
a:text="5"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/fourDigitButton"
|
a:id="@+id/fourDigitButton"
|
||||||
a:text="4"
|
a:text="4"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/functionsButton"
|
a:id="@+id/functionsButton"
|
||||||
a:text="ƒ(x)"
|
a:text="ƒ(x)"
|
||||||
a:textStyle="italic"
|
a:textStyle="italic"
|
||||||
style="@style/metro_control_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/historyButton"
|
a:id="@+id/historyButton"
|
||||||
a:text="@string/c_history_button"
|
a:text="@string/c_history_button"
|
||||||
style="@style/metro_control_button_style"
|
style="@style/widget_metro_control_button_style"
|
||||||
a:textStyle="bold"/>
|
a:textStyle="bold"/>
|
@ -1,69 +1,74 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1"
|
<LinearLayout a:layout_weight="1"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp">
|
a:layout_height="0dp">
|
||||||
|
|
||||||
<include layout="@layout/widget_seven_digit_button"/>
|
<include layout="@layout/widget_seven_digit_button"/>
|
||||||
<include layout="@layout/widget_eight_digit_button"/>
|
<include layout="@layout/widget_eight_digit_button"/>
|
||||||
<include layout="@layout/widget_nine_digit_button"/>
|
<include layout="@layout/widget_nine_digit_button"/>
|
||||||
<include layout="@layout/widget_multiplication_button"/>
|
<include layout="@layout/widget_multiplication_button"/>
|
||||||
<include layout="@layout/widget_clear_button"/>
|
<include layout="@layout/widget_percent_button"/>
|
||||||
|
<include layout="@layout/widget_clear_button"/>
|
||||||
</LinearLayout>
|
|
||||||
|
</LinearLayout>
|
||||||
<LinearLayout a:layout_weight="1"
|
|
||||||
a:layout_width="match_parent"
|
<LinearLayout a:layout_weight="1"
|
||||||
a:layout_height="0dp">
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
<include layout="@layout/widget_four_digit_button"/>
|
|
||||||
<include layout="@layout/widget_five_digit_button"/>
|
<include layout="@layout/widget_four_digit_button"/>
|
||||||
<include layout="@layout/widget_six_digit_button"/>
|
<include layout="@layout/widget_five_digit_button"/>
|
||||||
<include layout="@layout/widget_division_button"/>
|
<include layout="@layout/widget_six_digit_button"/>
|
||||||
<include layout="@layout/widget_erase_button"/>
|
<include layout="@layout/widget_division_button"/>
|
||||||
|
<include layout="@layout/widget_power_button"/>
|
||||||
</LinearLayout>
|
<include layout="@layout/widget_erase_button"/>
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1"
|
</LinearLayout>
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="0dp">
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
<include layout="@layout/widget_one_digit_button"/>
|
a:layout_height="0dp">
|
||||||
<include layout="@layout/widget_two_digit_button"/>
|
|
||||||
<include layout="@layout/widget_three_digit_button"/>
|
<include layout="@layout/widget_one_digit_button"/>
|
||||||
<include layout="@layout/widget_plus_button"/>
|
<include layout="@layout/widget_two_digit_button"/>
|
||||||
<include layout="@layout/widget_copy_button"/>
|
<include layout="@layout/widget_three_digit_button"/>
|
||||||
|
<include layout="@layout/widget_plus_button"/>
|
||||||
</LinearLayout>
|
<include layout="@layout/widget_like_button"/>
|
||||||
|
<include layout="@layout/widget_copy_button"/>
|
||||||
<LinearLayout a:layout_weight="1"
|
|
||||||
a:layout_width="match_parent"
|
</LinearLayout>
|
||||||
a:layout_height="0dp">
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
<include layout="@layout/widget_round_brackets_button"/>
|
a:layout_width="match_parent"
|
||||||
<include layout="@layout/widget_zero_digit_button"/>
|
a:layout_height="0dp">
|
||||||
<include layout="@layout/widget_dot_button"/>
|
|
||||||
<include layout="@layout/widget_subtraction_button"/>
|
<include layout="@layout/widget_round_brackets_button"/>
|
||||||
<include layout="@layout/widget_paste_button"/>
|
<include layout="@layout/widget_zero_digit_button"/>
|
||||||
|
<include layout="@layout/widget_dot_button"/>
|
||||||
</LinearLayout>
|
<include layout="@layout/widget_subtraction_button"/>
|
||||||
|
<include layout="@layout/widget_settings_button"/>
|
||||||
|
<include layout="@layout/widget_paste_button"/>
|
||||||
<LinearLayout a:layout_weight="1"
|
|
||||||
a:layout_width="match_parent"
|
</LinearLayout>
|
||||||
a:layout_height="0dp">
|
|
||||||
|
|
||||||
<include layout="@layout/widget_left_button"/>
|
<LinearLayout a:layout_weight="1"
|
||||||
<include layout="@layout/widget_right_button"/>
|
a:layout_width="match_parent"
|
||||||
<include layout="@layout/widget_vars_button"/>
|
a:layout_height="0dp">
|
||||||
<include layout="@layout/widget_functions_button"/>
|
|
||||||
<include layout="@layout/widget_history_button"/>
|
<include layout="@layout/widget_left_button"/>
|
||||||
|
<include layout="@layout/widget_right_button"/>
|
||||||
</LinearLayout>
|
<include layout="@layout/widget_vars_button"/>
|
||||||
|
<include layout="@layout/widget_functions_button"/>
|
||||||
|
<include layout="@layout/widget_app_button"/>
|
||||||
|
<include layout="@layout/widget_history_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,36 +1,36 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
style="@style/default_main_layout_style">
|
style="@style/widget_main_layout_style">
|
||||||
|
|
||||||
<include layout="@layout/widget_editor"
|
<include layout="@layout/widget_editor"
|
||||||
a:layout_weight="2"
|
a:layout_weight="2"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1"
|
<LinearLayout a:layout_weight="1"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp">
|
a:layout_height="0dp">
|
||||||
|
|
||||||
<include layout="@layout/widget_equals_button"
|
<include layout="@layout/widget_equals_button"
|
||||||
a:layout_margin="@dimen/button_margin"
|
a:layout_margin="@dimen/button_margin"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
<include layout="@layout/widget_display"
|
<include layout="@layout/widget_display"
|
||||||
a:layout_weight="4"
|
a:layout_weight="5"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="match_parent"/>
|
a:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<include layout="@layout/widget_keyboard"
|
<include layout="@layout/widget_keyboard"
|
||||||
a:layout_weight="5"
|
a:layout_weight="5"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/leftButton"
|
a:id="@+id/leftButton"
|
||||||
a:text="◀"
|
a:text="◀"
|
||||||
style="@style/metro_control_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
13
calculatorpp/res/layout/widget_like_button.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/likeButton"
|
||||||
|
a:src="@drawable/kb_facebook"
|
||||||
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="Like"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/multiplicationButton"
|
a:id="@+id/multiplicationButton"
|
||||||
a:text="×"
|
a:text="×"
|
||||||
style="@style/metro_blue_operation_button_style"/>
|
style="@style/widget_metro_blue_operation_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/nineDigitButton"
|
a:id="@+id/nineDigitButton"
|
||||||
a:text="9"
|
a:text="9"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/oneDigitButton"
|
a:id="@+id/oneDigitButton"
|
||||||
a:text="1"
|
a:text="1"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/pasteButton"
|
a:id="@+id/pasteButton"
|
||||||
a:drawableTop="@drawable/kb_paste"
|
a:src="@drawable/kb_paste"
|
||||||
style="@style/metro_control_image_button_style"/>
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="Paste"/>
|
12
calculatorpp/res/layout/widget_percent_button.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/percentButton"
|
||||||
|
a:text="%"
|
||||||
|
style="@style/widget_metro_blue_operation_button_style"/>
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/plusButton"
|
a:id="@+id/plusButton"
|
||||||
a:text="+"
|
a:text="+"
|
||||||
style="@style/metro_blue_operation_button_style"/>
|
style="@style/widget_metro_blue_operation_button_style"/>
|
12
calculatorpp/res/layout/widget_power_button.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/powerButton"
|
||||||
|
a:text="^"
|
||||||
|
style="@style/widget_metro_blue_operation_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/rightButton"
|
a:id="@+id/rightButton"
|
||||||
a:text="▶"
|
a:text="▶"
|
||||||
style="@style/metro_control_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/roundBracketsButton"
|
a:id="@+id/roundBracketsButton"
|
||||||
a:text="()"
|
a:text="()"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
13
calculatorpp/res/layout/widget_settings_button.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ImageButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/settingsButton"
|
||||||
|
a:src="@drawable/kb_settings"
|
||||||
|
style="@style/widget_metro_control_image_button_style"
|
||||||
|
a:contentDescription="Settings"/>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/sevenDigitButton"
|
a:id="@+id/sevenDigitButton"
|
||||||
a:text="7"
|
a:text="7"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/sixDigitButton"
|
a:id="@+id/sixDigitButton"
|
||||||
a:text="6"
|
a:text="6"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/subtractionButton"
|
a:id="@+id/subtractionButton"
|
||||||
a:text="-"
|
a:text="-"
|
||||||
style="@style/metro_blue_operation_button_style"/>
|
style="@style/widget_metro_blue_operation_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/threeDigitButton"
|
a:id="@+id/threeDigitButton"
|
||||||
a:text="3"
|
a:text="3"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/twoDigitButton"
|
a:id="@+id/twoDigitButton"
|
||||||
a:text="2"
|
a:text="2"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/varsButton"
|
a:id="@+id/varsButton"
|
||||||
a:text="π,…"
|
a:text="π,…"
|
||||||
a:textStyle="italic"
|
a:textStyle="italic"
|
||||||
style="@style/metro_control_button_style"/>
|
style="@style/widget_metro_control_button_style"/>
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
<Button xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/zeroDigitButton"
|
a:id="@+id/zeroDigitButton"
|
||||||
a:text="0"
|
a:text="0"
|
||||||
style="@style/metro_digit_button_style"/>
|
style="@style/widget_metro_digit_button_style"/>
|
@ -11,6 +11,7 @@
|
|||||||
<color name="button_ce_text_color">#ffffffff</color>
|
<color name="button_ce_text_color">#ffffffff</color>
|
||||||
<color name="default_text_color">#ffffffff</color>
|
<color name="default_text_color">#ffffffff</color>
|
||||||
<color name="display_error_text_color">#ff393939</color>
|
<color name="display_error_text_color">#ff393939</color>
|
||||||
|
<color name="widget_cursor_color">#ff707070</color>
|
||||||
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
||||||
<color name="default_background">#ff000000</color>
|
<color name="default_background">#ff000000</color>
|
||||||
<color name="pane_background">#ff1f1f1f</color>
|
<color name="pane_background">#ff1f1f1f</color>
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="text_size">20sp</dimen>
|
<dimen name="text_size">20sp</dimen>
|
||||||
<dimen name="button_margin">0.5dp</dimen>
|
<dimen name="button_margin">0.5dp</dimen>
|
||||||
<dimen name="display_margin_land">2.5dp</dimen>
|
<dimen name="display_margin_land">2.5dp</dimen>
|
||||||
|
|
||||||
<dimen name="fragment_text_size">15sp</dimen>
|
<dimen name="fragment_text_size">15sp</dimen>
|
||||||
<dimen name="fragment_title_text_size">20sp</dimen>
|
<dimen name="fragment_title_text_size">20sp</dimen>
|
||||||
|
|
||||||
<dimen name="keyboard_button_text_size">30dp</dimen>
|
<dimen name="keyboard_button_text_size">30dp</dimen>
|
||||||
<dimen name="button_text_size">20dp</dimen>
|
<dimen name="button_text_size">20dp</dimen>
|
||||||
<dimen name="display_text_size">25sp</dimen>
|
<dimen name="display_text_size">25sp</dimen>
|
||||||
<dimen name="editor_text_size">25sp</dimen>
|
<dimen name="editor_text_size">25sp</dimen>
|
||||||
<dimen name="pane_margin">5dp</dimen>
|
<dimen name="pane_margin">5dp</dimen>
|
||||||
<dimen name="pane_padding">5dp</dimen>
|
<dimen name="pane_padding">5dp</dimen>
|
||||||
<dimen name="math_entity_text_size">20sp</dimen>
|
<dimen name="math_entity_text_size">20sp</dimen>
|
||||||
<dimen name="math_entity_description_text_size">15sp</dimen>
|
<dimen name="math_entity_description_text_size">15sp</dimen>
|
||||||
|
|
||||||
<!--only for not multipane-->
|
<dimen name="widget_editor_text_size">25sp</dimen>
|
||||||
<dimen name="editor_padding">5dp</dimen>
|
<dimen name="widget_keyboard_button_text_size">20dp</dimen>
|
||||||
<dimen name="display_padding">3dp</dimen>
|
<dimen name="widget_display_text_size">25sp</dimen>
|
||||||
|
|
||||||
|
<!--only for not multipane-->
|
||||||
|
<dimen name="editor_padding">5dp</dimen>
|
||||||
|
<dimen name="display_padding">3dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -58,6 +58,14 @@
|
|||||||
<item name="android:textSize">@dimen/display_text_size</item>
|
<item name="android:textSize">@dimen/display_text_size</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_editor_style" parent="editor_style">
|
||||||
|
<item name="android:textSize">@dimen/widget_editor_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_display_style" parent="display_style">
|
||||||
|
<item name="android:textSize">@dimen/widget_display_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="about_style" parent="default_text">
|
<style name="about_style" parent="default_text">
|
||||||
<item name="android:gravity">center</item>
|
<item name="android:gravity">center</item>
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
|
@ -80,6 +80,10 @@
|
|||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_main_layout_style" parent="default_main_layout_style">
|
||||||
|
<item name="android:padding">1dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="default_actionbar_style" parent="@style/Widget.Sherlock.ActionBar">
|
<style name="default_actionbar_style" parent="@style/Widget.Sherlock.ActionBar">
|
||||||
<item name="background">@drawable/default_abs__ab_transparent_dark_holo</item>
|
<item name="background">@drawable/default_abs__ab_transparent_dark_holo</item>
|
||||||
<item name="android:background">@drawable/default_abs__ab_transparent_dark_holo</item>
|
<item name="android:background">@drawable/default_abs__ab_transparent_dark_holo</item>
|
||||||
|
@ -4,18 +4,34 @@
|
|||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
<item name="android:background">@drawable/metro_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_metro_digit_button_style" parent="metro_digit_button_style">
|
||||||
|
<item name="android:textSize">@dimen/widget_keyboard_button_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
<item name="android:background">@drawable/metro_button_light</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_metro_control_button_style" parent="metro_control_button_style">
|
||||||
|
<item name="android:textSize">@dimen/widget_keyboard_button_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_blue_button</item>
|
<item name="android:background">@drawable/metro_blue_button</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_metro_blue_operation_button_style" parent="metro_blue_operation_button_style">
|
||||||
|
<item name="android:textSize">@dimen/widget_keyboard_button_text_size</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="widget_metro_control_image_button_style" parent="metro_control_image_button_style">
|
||||||
|
<item name="android:scaleType">center</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="metro_blue_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
<style name="metro_blue_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
||||||
<item name="background">@drawable/metro_blue_list_item</item>
|
<item name="background">@drawable/metro_blue_list_item</item>
|
||||||
<item name="android:background">@drawable/metro_blue_list_item</item>
|
<item name="android:background">@drawable/metro_blue_list_item</item>
|
||||||
|
@ -1,34 +1,17 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="metro_digit_button_style" parent="keyboard_button_style">
|
|
||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_green</item>
|
<item name="android:background">@drawable/metro_button_green</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
|
||||||
<item name="android:padding">6dp</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_green_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
<style name="metro_green_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
||||||
<item name="background">@drawable/metro_green_list_item</item>
|
<item name="background">@drawable/metro_green_list_item</item>
|
||||||
<item name="android:background">@drawable/metro_green_list_item</item>
|
<item name="android:background">@drawable/metro_green_list_item</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_green_theme" parent="default_theme">
|
<style name="metro_green_theme" parent="metro_blue_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
|
||||||
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
|
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
|
||||||
|
|
||||||
<item name="fragmentListViewItemStyle">@style/metro_green_fragment_list_view_item_style</item>
|
<item name="fragmentListViewItemStyle">@style/metro_green_fragment_list_view_item_style</item>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,34 +1,18 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="metro_digit_button_style" parent="keyboard_button_style">
|
|
||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_purple</item>
|
<item name="android:background">@drawable/metro_button_purple</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
|
||||||
<item name="android:padding">6dp</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="metro_purple_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
<style name="metro_purple_fragment_list_view_item_style" parent="default_fragment_list_view_item_style">
|
||||||
<item name="background">@drawable/metro_purple_list_item</item>
|
<item name="background">@drawable/metro_purple_list_item</item>
|
||||||
<item name="android:background">@drawable/metro_purple_list_item</item>
|
<item name="android:background">@drawable/metro_purple_list_item</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_purple_theme" parent="default_theme">
|
<style name="metro_purple_theme" parent="metro_blue_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
|
||||||
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
|
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
|
||||||
|
|
||||||
<item name="fragmentListViewItemStyle">@style/metro_purple_fragment_list_view_item_style</item>
|
<item name="fragmentListViewItemStyle">@style/metro_purple_fragment_list_view_item_style</item>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
<appwidget-provider xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:minWidth="150dp"
|
a:minWidth="180dp"
|
||||||
a:minHeight="200dp"
|
a:minHeight="220dp"
|
||||||
a:updatePeriodMillis="1000"
|
a:initialLayout="@layout/widget_layout"
|
||||||
a:initialLayout="@layout/widget_layout"
|
a:previewImage="@drawable/widget_preview"
|
||||||
a:resizeMode="horizontal|vertical">
|
a:resizeMode="horizontal|vertical">
|
||||||
|
|
||||||
</appwidget-provider>
|
</appwidget-provider>
|
@ -1,35 +1,40 @@
|
|||||||
package org.solovyev.android;
|
package org.solovyev.android;
|
||||||
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.os.Looper;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
/**
|
|
||||||
* User: Solovyev_S
|
/**
|
||||||
* Date: 03.10.12
|
* User: Solovyev_S
|
||||||
* Time: 10:48
|
* Date: 03.10.12
|
||||||
*/
|
* Time: 10:48
|
||||||
public final class AndroidUtils2 {
|
*/
|
||||||
|
public final class AndroidUtils2 {
|
||||||
private AndroidUtils2() {
|
|
||||||
throw new AssertionError();
|
private AndroidUtils2() {
|
||||||
}
|
throw new AssertionError();
|
||||||
|
}
|
||||||
public static void showDialog(@NotNull DialogFragment dialogFragment,
|
|
||||||
@NotNull String fragmentTag,
|
public static void showDialog(@NotNull DialogFragment dialogFragment,
|
||||||
@NotNull FragmentManager fm) {
|
@NotNull String fragmentTag,
|
||||||
final FragmentTransaction ft = fm.beginTransaction();
|
@NotNull FragmentManager fm) {
|
||||||
|
final FragmentTransaction ft = fm.beginTransaction();
|
||||||
Fragment prev = fm.findFragmentByTag(fragmentTag);
|
|
||||||
if (prev != null) {
|
Fragment prev = fm.findFragmentByTag(fragmentTag);
|
||||||
ft.remove(prev);
|
if (prev != null) {
|
||||||
}
|
ft.remove(prev);
|
||||||
ft.addToBackStack(null);
|
}
|
||||||
|
ft.addToBackStack(null);
|
||||||
// Create and show the dialog.
|
|
||||||
dialogFragment.show(ft, fragmentTag);
|
// Create and show the dialog.
|
||||||
|
dialogFragment.show(ft, fragmentTag);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUiThread() {
|
||||||
|
return Looper.myLooper() == Looper.getMainLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,191 +1,218 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import jscl.NumeralBase;
|
import jscl.NumeralBase;
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/22/12
|
* Date: 9/22/12
|
||||||
* Time: 5:42 PM
|
* Time: 5:42 PM
|
||||||
*/
|
*/
|
||||||
public class AndroidCalculator implements Calculator, CalculatorEventListener {
|
public class AndroidCalculator implements Calculator, CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Calculator calculator = new CalculatorImpl();
|
private final Calculator calculator = new CalculatorImpl();
|
||||||
|
|
||||||
public AndroidCalculator() {
|
public AndroidCalculator() {
|
||||||
this.calculator.addCalculatorEventListener(this);
|
this.calculator.addCalculatorEventListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showEvaluationError(@NotNull Context context, @NotNull final String errorMessage) {
|
public static void showEvaluationError(@NotNull Context context, @NotNull final String errorMessage) {
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
|
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
|
||||||
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
|
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setPositiveButton(R.string.c_cancel, null)
|
.setPositiveButton(R.string.c_cancel, null)
|
||||||
.setView(errorMessageView);
|
.setView(errorMessageView);
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(@NotNull final Activity activity) {
|
public void init(@NotNull final Activity activity) {
|
||||||
setEditor(activity);
|
setEditor(activity);
|
||||||
setDisplay(activity);
|
setDisplay(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplay(@NotNull Activity activity) {
|
public void setDisplay(@NotNull Activity activity) {
|
||||||
final AndroidCalculatorDisplayView displayView = (AndroidCalculatorDisplayView) activity.findViewById(R.id.calculatorDisplay);
|
final AndroidCalculatorDisplayView displayView = (AndroidCalculatorDisplayView) activity.findViewById(R.id.calculatorDisplay);
|
||||||
setDisplay(activity, displayView);
|
setDisplay(activity, displayView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplay(@NotNull Context context, @NotNull AndroidCalculatorDisplayView displayView) {
|
public void setDisplay(@NotNull Context context, @NotNull AndroidCalculatorDisplayView displayView) {
|
||||||
displayView.init(context);
|
displayView.init(context);
|
||||||
CalculatorLocatorImpl.getInstance().getDisplay().setView(displayView);
|
CalculatorLocatorImpl.getInstance().getDisplay().setView(displayView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEditor(@NotNull Activity activity) {
|
public void setEditor(@NotNull Activity activity) {
|
||||||
final AndroidCalculatorEditorView editorView = (AndroidCalculatorEditorView) activity.findViewById(R.id.calculatorEditor);
|
final AndroidCalculatorEditorView editorView = (AndroidCalculatorEditorView) activity.findViewById(R.id.calculatorEditor);
|
||||||
setEditor(activity, editorView);
|
setEditor(activity, editorView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEditor(@NotNull Context context, @NotNull AndroidCalculatorEditorView editorView) {
|
public void setEditor(@NotNull Context context, @NotNull AndroidCalculatorEditorView editorView) {
|
||||||
editorView.init(context);
|
editorView.init(context);
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().setView(editorView);
|
CalculatorLocatorImpl.getInstance().getEditor().setView(editorView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* DELEGATED TO CALCULATOR
|
* DELEGATED TO CALCULATOR
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEventData evaluate(@NotNull JsclOperation operation, @NotNull String expression) {
|
public CalculatorEventData evaluate(@NotNull JsclOperation operation, @NotNull String expression) {
|
||||||
return calculator.evaluate(operation, expression);
|
return calculator.evaluate(operation, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEventData evaluate(@NotNull JsclOperation operation, @NotNull String expression, @NotNull Long sequenceId) {
|
public CalculatorEventData evaluate(@NotNull JsclOperation operation, @NotNull String expression, @NotNull Long sequenceId) {
|
||||||
return calculator.evaluate(operation, expression, sequenceId);
|
return calculator.evaluate(operation, expression, sequenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConversionPossible(@NotNull Generic generic, @NotNull NumeralBase from, @NotNull NumeralBase to) {
|
public boolean isConversionPossible(@NotNull Generic generic, @NotNull NumeralBase from, @NotNull NumeralBase to) {
|
||||||
return calculator.isConversionPossible(generic, from, to);
|
return calculator.isConversionPossible(generic, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEventData convert(@NotNull Generic generic, @NotNull NumeralBase to) {
|
public CalculatorEventData convert(@NotNull Generic generic, @NotNull NumeralBase to) {
|
||||||
return calculator.convert(generic, to);
|
return calculator.convert(generic, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
return calculator.fireCalculatorEvent(calculatorEventType, data);
|
return calculator.fireCalculatorEvent(calculatorEventType, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data, @NotNull Object source) {
|
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data, @NotNull Object source) {
|
||||||
return calculator.fireCalculatorEvent(calculatorEventType, data, source);
|
return calculator.fireCalculatorEvent(calculatorEventType, data, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data, @NotNull Long sequenceId) {
|
public CalculatorEventData fireCalculatorEvent(@NotNull CalculatorEventType calculatorEventType, @Nullable Object data, @NotNull Long sequenceId) {
|
||||||
return calculator.fireCalculatorEvent(calculatorEventType, data, sequenceId);
|
return calculator.fireCalculatorEvent(calculatorEventType, data, sequenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
this.calculator.init();
|
this.calculator.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
|
public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
|
||||||
calculator.addCalculatorEventListener(calculatorEventListener);
|
calculator.addCalculatorEventListener(calculatorEventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
|
public void removeCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
|
||||||
calculator.removeCalculatorEventListener(calculatorEventListener);
|
calculator.removeCalculatorEventListener(calculatorEventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
public void fireCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
calculator.fireCalculatorEvent(calculatorEventData, calculatorEventType, data);
|
calculator.fireCalculatorEvent(calculatorEventData, calculatorEventType, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
|
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
|
||||||
calculator.fireCalculatorEvents(calculatorEvents);
|
calculator.fireCalculatorEvents(calculatorEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doHistoryAction(@NotNull HistoryAction historyAction) {
|
public void doHistoryAction(@NotNull HistoryAction historyAction) {
|
||||||
calculator.doHistoryAction(historyAction);
|
calculator.doHistoryAction(historyAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCurrentHistoryState(@NotNull CalculatorHistoryState editorHistoryState) {
|
public void setCurrentHistoryState(@NotNull CalculatorHistoryState editorHistoryState) {
|
||||||
calculator.setCurrentHistoryState(editorHistoryState);
|
calculator.setCurrentHistoryState(editorHistoryState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorHistoryState getCurrentHistoryState() {
|
public CalculatorHistoryState getCurrentHistoryState() {
|
||||||
return calculator.getCurrentHistoryState();
|
return calculator.getCurrentHistoryState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() {
|
public void evaluate() {
|
||||||
calculator.evaluate();
|
calculator.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate(@NotNull Long sequenceId) {
|
public void evaluate(@NotNull Long sequenceId) {
|
||||||
calculator.evaluate(sequenceId);
|
calculator.evaluate(sequenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simplify() {
|
public void simplify() {
|
||||||
calculator.simplify();
|
calculator.simplify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
switch (calculatorEventType) {
|
switch (calculatorEventType) {
|
||||||
case show_history:
|
case show_history:
|
||||||
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance());
|
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance());
|
||||||
break;
|
break;
|
||||||
case show_functions:
|
case show_history_detached:
|
||||||
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance());
|
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance(), true);
|
||||||
break;
|
break;
|
||||||
case show_vars:
|
case show_functions:
|
||||||
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance());
|
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance());
|
||||||
break;
|
break;
|
||||||
}
|
case show_functions_detached:
|
||||||
}
|
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance(), true);
|
||||||
}
|
break;
|
||||||
|
case show_operators:
|
||||||
|
CalculatorActivityLauncher.showOperators(CalculatorApplication.getInstance());
|
||||||
|
break;
|
||||||
|
case show_operators_detached:
|
||||||
|
CalculatorActivityLauncher.showOperators(CalculatorApplication.getInstance(), true);
|
||||||
|
break;
|
||||||
|
case show_vars:
|
||||||
|
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance());
|
||||||
|
break;
|
||||||
|
case show_vars_detached:
|
||||||
|
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance(), true);
|
||||||
|
break;
|
||||||
|
case show_settings:
|
||||||
|
CalculatorActivityLauncher.showSettings(CalculatorApplication.getInstance());
|
||||||
|
break;
|
||||||
|
case show_settings_detached:
|
||||||
|
CalculatorActivityLauncher.showSettings(CalculatorApplication.getInstance(), true);
|
||||||
|
break;
|
||||||
|
case show_like_dialog:
|
||||||
|
CalculatorActivityLauncher.likeButtonPressed(CalculatorApplication.getInstance());
|
||||||
|
break;
|
||||||
|
case open_app:
|
||||||
|
CalculatorActivityLauncher.openApp(CalculatorApplication.getInstance());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -47,9 +47,8 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
|
|
||||||
private volatile boolean viewStateChange = false;
|
private volatile boolean viewStateChange = false;
|
||||||
|
|
||||||
// NOTE: static because super constructor calls some overridden methods (like onSelectionChanged and current lock is not yet created)
|
@Nullable
|
||||||
@NotNull
|
private final Object viewLock = new Object();
|
||||||
private static final Object viewLock = new Object();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Handler uiHandler = new Handler();
|
private final Handler uiHandler = new Handler();
|
||||||
@ -154,45 +153,51 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setState(@NotNull final CalculatorEditorViewState viewState) {
|
public void setState(@NotNull final CalculatorEditorViewState viewState) {
|
||||||
synchronized (viewLock) {
|
if (viewLock != null) {
|
||||||
|
synchronized (viewLock) {
|
||||||
|
|
||||||
final CharSequence text = prepareText(viewState.getText(), highlightText);
|
final CharSequence text = prepareText(viewState.getText(), highlightText);
|
||||||
|
|
||||||
uiHandler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
|
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
try {
|
try {
|
||||||
editorView.viewStateChange = true;
|
editorView.viewStateChange = true;
|
||||||
editorView.viewState = viewState;
|
editorView.viewState = viewState;
|
||||||
editorView.setText(text, BufferType.EDITABLE);
|
editorView.setText(text, BufferType.EDITABLE);
|
||||||
editorView.setSelection(viewState.getSelection());
|
editorView.setSelection(viewState.getSelection());
|
||||||
} finally {
|
} finally {
|
||||||
editorView.viewStateChange = false;
|
editorView.viewStateChange = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSelectionChanged(int selStart, int selEnd) {
|
protected void onSelectionChanged(int selStart, int selEnd) {
|
||||||
synchronized (viewLock) {
|
if (viewLock != null) {
|
||||||
if (!viewStateChange) {
|
synchronized (viewLock) {
|
||||||
// external text change => need to notify editor
|
if (!viewStateChange) {
|
||||||
super.onSelectionChanged(selStart, selEnd);
|
// external text change => need to notify editor
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart);
|
super.onSelectionChanged(selStart, selEnd);
|
||||||
|
CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleTextChange(Editable s) {
|
public void handleTextChange(Editable s) {
|
||||||
synchronized (viewLock) {
|
if (viewLock != null) {
|
||||||
if (!viewStateChange) {
|
synchronized (viewLock) {
|
||||||
// external text change => need to notify editor
|
if (!viewStateChange) {
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s));
|
// external text change => need to notify editor
|
||||||
|
CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.os.Handler;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.AndroidUtils2;
|
||||||
import org.solovyev.android.msg.AndroidMessage;
|
import org.solovyev.android.msg.AndroidMessage;
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.common.msg.Message;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
@ -20,13 +22,18 @@ public class AndroidCalculatorNotifier implements CalculatorNotifier {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final Application application;
|
private final Application application;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final Handler uiHandler = new Handler();
|
||||||
|
|
||||||
public AndroidCalculatorNotifier(@NotNull Application application) {
|
public AndroidCalculatorNotifier(@NotNull Application application) {
|
||||||
|
assert AndroidUtils2.isUiThread();
|
||||||
|
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMessage(@NotNull Message message) {
|
public void showMessage(@NotNull Message message) {
|
||||||
Toast.makeText(application, message.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
|
showMessageInUiThread(message.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,4 +45,25 @@ public class AndroidCalculatorNotifier implements CalculatorNotifier {
|
|||||||
public void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters) {
|
public void showMessage(@NotNull Integer messageCode, @NotNull MessageType messageType, @Nullable Object... parameters) {
|
||||||
showMessage(new AndroidMessage(messageCode, messageType, application, parameters));
|
showMessage(new AndroidMessage(messageCode, messageType, application, parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showDebugMessage(@Nullable final String tag, @NotNull final String message) {
|
||||||
|
/*if (AndroidUtils.isDebuggable(application)) {
|
||||||
|
showMessageInUiThread(tag == null ? message : tag + ": " + message);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMessageInUiThread(@NotNull final String message) {
|
||||||
|
if (AndroidUtils2.isUiThread()) {
|
||||||
|
Toast.makeText(application, message, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
uiHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(application,message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,318 +1,322 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
|
||||||
import org.solovyev.android.fragments.FragmentUtils;
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
||||||
|
|
||||||
private boolean useBackAsPrev;
|
private boolean useBackAsPrev;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorActivityHelper activityHelper;
|
private CalculatorActivityHelper activityHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
|
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
|
||||||
activityHelper.logDebug("onCreate");
|
activityHelper.logDebug("onCreate");
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
activityHelper.logDebug("super.onCreate");
|
activityHelper.logDebug("super.onCreate");
|
||||||
|
|
||||||
if (findViewById(R.id.main_second_pane) != null) {
|
if (findViewById(R.id.main_second_pane) != null) {
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.variables, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.plotter, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.plotter, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.faq, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.faq, null, R.id.main_second_pane);
|
||||||
} else {
|
} else {
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
||||||
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
||||||
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
||||||
|
|
||||||
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
firstTimeInit(preferences, this);
|
firstTimeInit(preferences, this);
|
||||||
|
|
||||||
toggleOrientationChange(preferences);
|
toggleOrientationChange(preferences);
|
||||||
|
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private AndroidCalculator getCalculator() {
|
private AndroidCalculator getCalculator() {
|
||||||
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
||||||
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
||||||
if (appOpenedCounter != null) {
|
if (appOpenedCounter != null) {
|
||||||
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
||||||
|
|
||||||
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
||||||
|
|
||||||
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
||||||
|
|
||||||
boolean dialogShown = false;
|
boolean dialogShown = false;
|
||||||
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
||||||
// new start
|
// new start
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
builder.setTitle(R.string.c_first_start_text_title);
|
builder.setTitle(R.string.c_first_start_text_title);
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
dialogShown = true;
|
dialogShown = true;
|
||||||
} else {
|
} else {
|
||||||
if (savedVersion < appVersion) {
|
if (savedVersion < appVersion) {
|
||||||
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
||||||
if (showReleaseNotes) {
|
if (showReleaseNotes) {
|
||||||
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
|
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
|
||||||
if (!StringUtils.isEmpty(releaseNotes)) {
|
if (!StringUtils.isEmpty(releaseNotes)) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
builder.setTitle(R.string.c_release_notes);
|
builder.setTitle(R.string.c_release_notes);
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
dialogShown = true;
|
dialogShown = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
||||||
if (!dialogShown) {
|
if (!dialogShown) {
|
||||||
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
||||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
||||||
if ( specialWindowShown != null && !specialWindowShown ) {
|
if ( specialWindowShown != null && !specialWindowShown ) {
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
final View view = layoutInflater.inflate(layoutId, null);
|
final View view = layoutInflater.inflate(layoutId, null);
|
||||||
|
|
||||||
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
||||||
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
|
||||||
result = true;
|
result = true;
|
||||||
specialWindowShownPref.putPreference(preferences, true);
|
specialWindowShownPref.putPreference(preferences, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
if (useBackAsPrev) {
|
if (useBackAsPrev) {
|
||||||
getCalculator().doHistoryAction(HistoryAction.undo);
|
getCalculator().doHistoryAction(HistoryAction.undo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void equalsButtonClickHandler(@NotNull View v) {
|
public void equalsButtonClickHandler(@NotNull View v) {
|
||||||
getCalculator().evaluate();
|
buttonPressed(CalculatorSpecialButton.equals);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
this.activityHelper.onPause(this);
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||||
if ( newLayout != activityHelper.getLayout() ) {
|
if ( newLayout != activityHelper.getLayout() ) {
|
||||||
AndroidUtils.restartActivity(this);
|
AndroidUtils.restartActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activityHelper.onResume(this);
|
this.activityHelper.onResume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
activityHelper.onDestroy(this);
|
activityHelper.onDestroy(this);
|
||||||
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
||||||
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
||||||
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
||||||
toggleOrientationChange(preferences);
|
toggleOrientationChange(preferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
||||||
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
} else {
|
} else {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* BUTTON HANDLERS
|
* BUTTON HANDLERS
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void elementaryButtonClickHandler(@NotNull View v) {
|
public void elementaryButtonClickHandler(@NotNull View v) {
|
||||||
throw new UnsupportedOperationException("Not implemented yet!");
|
throw new UnsupportedOperationException("Not implemented yet!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void historyButtonClickHandler(@NotNull View v) {
|
public void historyButtonClickHandler(@NotNull View v) {
|
||||||
buttonPressed(CalculatorButtonActions.SHOW_HISTORY);
|
buttonPressed(CalculatorSpecialButton.history);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void eraseButtonClickHandler(@NotNull View v) {
|
public void eraseButtonClickHandler(@NotNull View v) {
|
||||||
buttonPressed(CalculatorButtonActions.ERASE);
|
buttonPressed(CalculatorSpecialButton.erase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void simplifyButtonClickHandler(@NotNull View v) {
|
public void simplifyButtonClickHandler(@NotNull View v) {
|
||||||
throw new UnsupportedOperationException("Not implemented yet!");
|
throw new UnsupportedOperationException("Not implemented yet!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void pasteButtonClickHandler(@NotNull View v) {
|
public void pasteButtonClickHandler(@NotNull View v) {
|
||||||
buttonPressed(CalculatorButtonActions.PASTE);
|
buttonPressed(CalculatorSpecialButton.paste);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void copyButtonClickHandler(@NotNull View v) {
|
public void copyButtonClickHandler(@NotNull View v) {
|
||||||
buttonPressed(CalculatorButtonActions.COPY);
|
buttonPressed(CalculatorSpecialButton.copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static CalculatorKeyboard getKeyboard() {
|
private static CalculatorKeyboard getKeyboard() {
|
||||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void clearButtonClickHandler(@NotNull View v) {
|
public void clearButtonClickHandler(@NotNull View v) {
|
||||||
buttonPressed(CalculatorButtonActions.CLEAR);
|
buttonPressed(CalculatorSpecialButton.clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void digitButtonClickHandler(@NotNull View v) {
|
public void digitButtonClickHandler(@NotNull View v) {
|
||||||
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
|
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
|
||||||
|
|
||||||
if (v instanceof Button) {
|
if (v instanceof Button) {
|
||||||
|
|
||||||
boolean processText = true;
|
boolean processText = true;
|
||||||
if ( v instanceof ColorButton) {
|
if ( v instanceof ColorButton) {
|
||||||
processText = ((ColorButton) v).isShowText();
|
processText = ((ColorButton) v).isShowText();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( processText ) {
|
if ( processText ) {
|
||||||
buttonPressed(((Button)v).getText().toString());
|
buttonPressed(((Button)v).getText().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonPressed(@NotNull String text) {
|
private void buttonPressed(@NotNull CalculatorSpecialButton button) {
|
||||||
getKeyboard().buttonPressed(text);
|
buttonPressed(button.getActionCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
private void buttonPressed(@NotNull String text) {
|
||||||
public void functionsButtonClickHandler(@NotNull View v) {
|
getKeyboard().buttonPressed(text);
|
||||||
buttonPressed(CalculatorButtonActions.SHOW_FUNCTIONS);
|
}
|
||||||
}
|
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
public void functionsButtonClickHandler(@NotNull View v) {
|
||||||
public void operatorsButtonClickHandler(@NotNull View v) {
|
buttonPressed(CalculatorSpecialButton.functions);
|
||||||
buttonPressed(CalculatorButtonActions.SHOW_OPERATORS);
|
}
|
||||||
}
|
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
public void operatorsButtonClickHandler(@NotNull View v) {
|
||||||
public void varsButtonClickHandler(@NotNull View v) {
|
buttonPressed(CalculatorSpecialButton.operators);
|
||||||
buttonPressed(CalculatorButtonActions.SHOW_VARS);
|
}
|
||||||
}
|
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
public void varsButtonClickHandler(@NotNull View v) {
|
||||||
public void likeButtonClickHandler(@NotNull View v) {
|
buttonPressed(CalculatorSpecialButton.vars);
|
||||||
CalculatorApplication.likeButtonPressed(this);
|
}
|
||||||
}
|
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void likeButtonClickHandler(@NotNull View v) {
|
||||||
|
buttonPressed(CalculatorSpecialButton.like);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,85 +1,138 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import android.net.Uri;
|
||||||
import jscl.math.Generic;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import jscl.math.function.Constant;
|
import jscl.math.Generic;
|
||||||
import org.achartengine.ChartFactory;
|
import jscl.math.function.Constant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.achartengine.ChartFactory;
|
||||||
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.help.CalculatorHelpActivity;
|
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
import org.solovyev.android.calculator.help.CalculatorHelpActivity;
|
||||||
import org.solovyev.android.calculator.math.edit.*;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
import org.solovyev.android.calculator.math.edit.*;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 11/2/11
|
* User: serso
|
||||||
* Time: 2:18 PM
|
* Date: 11/2/11
|
||||||
*/
|
* Time: 2:18 PM
|
||||||
public class CalculatorActivityLauncher {
|
*/
|
||||||
|
public class CalculatorActivityLauncher {
|
||||||
public static void showHistory(@NotNull final Context context) {
|
|
||||||
context.startActivity(new Intent(context, CalculatorHistoryActivity.class));
|
public static void showHistory(@NotNull final Context context) {
|
||||||
}
|
showHistory(context, false);
|
||||||
|
}
|
||||||
public static void showHelp(@NotNull final Context context) {
|
|
||||||
context.startActivity(new Intent(context, CalculatorHelpActivity.class));
|
public static void showHistory(@NotNull final Context context, boolean detached) {
|
||||||
}
|
final Intent intent = new Intent(context, CalculatorHistoryActivity.class);
|
||||||
|
addFlags(intent, detached);
|
||||||
public static void showSettings(@NotNull final Context context) {
|
context.startActivity(intent);
|
||||||
context.startActivity(new Intent(context, CalculatorPreferencesActivity.class));
|
}
|
||||||
}
|
|
||||||
|
public static void showHelp(@NotNull final Context context) {
|
||||||
public static void showAbout(@NotNull final Context context) {
|
context.startActivity(new Intent(context, CalculatorHelpActivity.class));
|
||||||
context.startActivity(new Intent(context, CalculatorAboutActivity.class));
|
}
|
||||||
}
|
|
||||||
|
public static void showSettings(@NotNull final Context context) {
|
||||||
public static void showFunctions(@NotNull final Context context) {
|
showSettings(context, false);
|
||||||
context.startActivity(new Intent(context, CalculatorFunctionsActivity.class));
|
}
|
||||||
}
|
public static void showSettings(@NotNull final Context context, boolean detached) {
|
||||||
|
final Intent intent = new Intent(context, CalculatorPreferencesActivity.class);
|
||||||
public static void showOperators(@NotNull final Context context) {
|
addFlags(intent, detached);
|
||||||
context.startActivity(new Intent(context, CalculatorOperatorsActivity.class));
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showVars(@NotNull final Context context) {
|
private static void addFlags(@NotNull Intent intent, boolean detached) {
|
||||||
context.startActivity(new Intent(context, CalculatorVarsActivity.class));
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
}
|
|
||||||
|
if (detached) {
|
||||||
public static void plotGraph(@NotNull final Context context, @NotNull Generic generic, @NotNull Constant constant){
|
flags = flags | Intent.FLAG_ACTIVITY_NO_HISTORY;
|
||||||
final Intent intent = new Intent();
|
}
|
||||||
intent.putExtra(ChartFactory.TITLE, context.getString(R.string.c_graph));
|
|
||||||
intent.putExtra(CalculatorPlotFragment.INPUT, new CalculatorPlotFragment.Input(generic.toString(), constant.getName()));
|
intent.setFlags(flags);
|
||||||
intent.setClass(context, CalculatorPlotActivity.class);
|
|
||||||
context.startActivity(intent);
|
}
|
||||||
}
|
|
||||||
|
public static void showAbout(@NotNull final Context context) {
|
||||||
public static void createVar(@NotNull final Context context, @NotNull CalculatorDisplay calculatorDisplay) {
|
context.startActivity(new Intent(context, CalculatorAboutActivity.class));
|
||||||
final CalculatorDisplayViewState viewState = calculatorDisplay.getViewState();
|
}
|
||||||
if (viewState.isValid() ) {
|
|
||||||
final String varValue = viewState.getText();
|
public static void showFunctions(@NotNull final Context context) {
|
||||||
if (!StringUtils.isEmpty(varValue)) {
|
showHistory(context, false);
|
||||||
if (CalculatorVarsFragment.isValidValue(varValue)) {
|
}
|
||||||
if (context instanceof SherlockFragmentActivity) {
|
|
||||||
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager());
|
public static void showFunctions(@NotNull final Context context, boolean detached) {
|
||||||
} else {
|
final Intent intent = new Intent(context, CalculatorFunctionsActivity.class);
|
||||||
final Intent intent = new Intent(context, CalculatorVarsActivity.class);
|
addFlags(intent, detached);
|
||||||
intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue);
|
context.startActivity(intent);
|
||||||
context.startActivity(intent);
|
}
|
||||||
}
|
|
||||||
} else {
|
public static void showOperators(@NotNull final Context context) {
|
||||||
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_not_valid_result, MessageType.error);
|
showOperators(context, false);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_empty_var_error, MessageType.error);
|
public static void showOperators(@NotNull final Context context, boolean detached) {
|
||||||
}
|
final Intent intent = new Intent(context, CalculatorOperatorsActivity.class);
|
||||||
} else {
|
addFlags(intent, detached);
|
||||||
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_not_valid_result, MessageType.error);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public static void showVars(@NotNull final Context context) {
|
||||||
|
showVars(context, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showVars(@NotNull final Context context, boolean detached) {
|
||||||
|
final Intent intent = new Intent(context, CalculatorVarsActivity.class);
|
||||||
|
addFlags(intent, detached);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void plotGraph(@NotNull final Context context, @NotNull Generic generic, @NotNull Constant constant){
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.putExtra(ChartFactory.TITLE, context.getString(R.string.c_graph));
|
||||||
|
intent.putExtra(CalculatorPlotFragment.INPUT, new CalculatorPlotFragment.Input(generic.toString(), constant.getName()));
|
||||||
|
intent.setClass(context, CalculatorPlotActivity.class);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createVar(@NotNull final Context context, @NotNull CalculatorDisplay calculatorDisplay) {
|
||||||
|
final CalculatorDisplayViewState viewState = calculatorDisplay.getViewState();
|
||||||
|
if (viewState.isValid() ) {
|
||||||
|
final String varValue = viewState.getText();
|
||||||
|
if (!StringUtils.isEmpty(varValue)) {
|
||||||
|
if (CalculatorVarsFragment.isValidValue(varValue)) {
|
||||||
|
if (context instanceof SherlockFragmentActivity) {
|
||||||
|
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager());
|
||||||
|
} else {
|
||||||
|
final Intent intent = new Intent(context, CalculatorVarsActivity.class);
|
||||||
|
intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_not_valid_result, MessageType.error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_empty_var_error, MessageType.error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showMessage(R.string.c_not_valid_result, MessageType.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openApp(@NotNull Context context) {
|
||||||
|
final Intent intent = new Intent(context, CalculatorActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void likeButtonPressed(@NotNull final Context context) {
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(CalculatorApplication.FACEBOOK_APP_URL));
|
||||||
|
addFlags(intent, false);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import net.robotmedia.billing.helper.DefaultBillingObserver;
|
import net.robotmedia.billing.helper.DefaultBillingObserver;
|
||||||
@ -15,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.solovyev.android.ads.AdsController;
|
import org.solovyev.android.ads.AdsController;
|
||||||
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
|
import org.solovyev.android.calculator.widget.CalculatorWidgetHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -39,6 +37,7 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private static final String TAG = "Calculator++ Application";
|
||||||
public static final String FACEBOOK_APP_URL = "http://www.facebook.com/calculatorpp";
|
public static final String FACEBOOK_APP_URL = "http://www.facebook.com/calculatorpp";
|
||||||
|
|
||||||
public static final String AD_FREE_PRODUCT_ID = "ad_free";
|
public static final String AD_FREE_PRODUCT_ID = "ad_free";
|
||||||
@ -49,6 +48,9 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static CalculatorApplication instance;
|
private static CalculatorApplication instance;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CalculatorWidgetHelper widgetHelper;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
@ -91,6 +93,10 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
||||||
|
|
||||||
|
// in order to not to be garbage collected
|
||||||
|
widgetHelper = new CalculatorWidgetHelper();
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(widgetHelper);
|
||||||
|
|
||||||
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -115,6 +121,9 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
AdsController.getInstance().isAdFree(CalculatorApplication.this);
|
AdsController.getInstance().isAdFree(CalculatorApplication.this);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getLogger().debug(TAG, "Application started!");
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Application started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||||
@ -154,7 +163,4 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void likeButtonPressed(@NotNull final Context context) {
|
|
||||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(FACEBOOK_APP_URL)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package org.solovyev.android.calculator.widget;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: Solovyev_S
|
|
||||||
* Date: 19.10.12
|
|
||||||
* Time: 18:09
|
|
||||||
*/
|
|
||||||
public class CalculatorWidgetController {
|
|
||||||
|
|
||||||
public static final String BUTTON_PRESSED_ACTION = "org.solovyev.calculator.widget.BUTTON_PRESSED";
|
|
||||||
}
|
|
@ -0,0 +1,65 @@
|
|||||||
|
package org.solovyev.android.calculator.widget;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/19/12
|
||||||
|
* Time: 11:11 PM
|
||||||
|
*/
|
||||||
|
public class CalculatorWidgetHelper extends BroadcastReceiver implements CalculatorEventListener {
|
||||||
|
|
||||||
|
private static final String TAG = "Calculator++ Widget Helper";
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final CalculatorEventHolder lastEvent = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
||||||
|
|
||||||
|
public CalculatorWidgetHelper() {
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
|
final CalculatorEventHolder.Result result = lastEvent.apply(calculatorEventData);
|
||||||
|
if (result.isNewAfter()) {
|
||||||
|
switch (calculatorEventType) {
|
||||||
|
case editor_state_changed_light:
|
||||||
|
case editor_state_changed:
|
||||||
|
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
|
||||||
|
final CalculatorEditorViewState newEditorState = editorChangeData.getNewValue();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed: " + newEditorState.getText());
|
||||||
|
|
||||||
|
CalculatorWidgetProvider.onEditorStateChanged(CalculatorApplication.getInstance(), newEditorState);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case display_state_changed:
|
||||||
|
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
|
||||||
|
final CalculatorDisplayViewState newDisplayState = displayChangeData.getNewValue();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed: " + newDisplayState.getText());
|
||||||
|
|
||||||
|
CalculatorWidgetProvider.onDisplayStateChanged(CalculatorApplication.getInstance(), newDisplayState);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (CalculatorWidgetProvider.BUTTON_PRESSED_ACTION.equals(intent.getAction())) {
|
||||||
|
final int buttonId = intent.getIntExtra(CalculatorWidgetProvider.BUTTON_ID_EXTRA, 0);
|
||||||
|
//Toast.makeText(context, "Button id: " + buttonId, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
final WidgetButton button = WidgetButton.getById(buttonId);
|
||||||
|
if ( button != null ) {
|
||||||
|
button.onClick(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +1,199 @@
|
|||||||
package org.solovyev.android.calculator.widget;
|
package org.solovyev.android.calculator.widget;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.appwidget.AppWidgetProvider;
|
import android.appwidget.AppWidgetProvider;
|
||||||
import android.content.Context;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Context;
|
||||||
import android.widget.RemoteViews;
|
import android.content.Intent;
|
||||||
import android.widget.Toast;
|
import android.text.Html;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import android.widget.RemoteViews;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||||
/**
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
* User: Solovyev_S
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
* Date: 19.10.12
|
import org.solovyev.android.calculator.R;
|
||||||
* Time: 16:18
|
|
||||||
*/
|
import java.io.Serializable;
|
||||||
public class CalculatorWidgetProvider extends AppWidgetProvider {
|
|
||||||
|
/**
|
||||||
public static final String BUTTON_PRESSED = "org.solovyev.calculator.widget.BUTTON_PRESSED";
|
* User: Solovyev_S
|
||||||
|
* Date: 19.10.12
|
||||||
|
* Time: 16:18
|
||||||
@Override
|
*/
|
||||||
public void onUpdate(@NotNull Context context,
|
public class CalculatorWidgetProvider extends AppWidgetProvider {
|
||||||
@NotNull AppWidgetManager appWidgetManager,
|
|
||||||
@NotNull int[] appWidgetIds) {
|
/*
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
**********************************************************************
|
||||||
|
*
|
||||||
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
* CONSTANTS
|
||||||
|
*
|
||||||
final Intent onButtonClickIntent = new Intent(context, CalculatorWidgetProvider.class);
|
**********************************************************************
|
||||||
onButtonClickIntent.setAction(CalculatorWidgetController.BUTTON_PRESSED_ACTION);
|
*/
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, onButtonClickIntent, 0);
|
public static final String BUTTON_ID_EXTRA = "buttonId";
|
||||||
views.setOnClickPendingIntent(R.id.oneDigitButton, pendingIntent);
|
public static final String BUTTON_PRESSED_ACTION = "org.solovyev.calculator.widget.BUTTON_PRESSED";
|
||||||
}
|
|
||||||
|
private static final String EDITOR_STATE_CHANGED_ACTION = "org.solovyev.calculator.widget.EDITOR_STATE_CHANGED";
|
||||||
@Override
|
private static final String EDITOR_STATE_EXTRA = "editorState";
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
super.onReceive(context, intent);
|
private static final String DISPLAY_STATE_CHANGED_ACTION = "org.solovyev.calculator.widget.DISPLAY_STATE_CHANGED";
|
||||||
|
private static final String DISPLAY_STATE_EXTRA = "displayState";
|
||||||
if ( BUTTON_PRESSED.equals(intent.getAction()) ) {
|
|
||||||
Toast.makeText(CalculatorApplication.getInstance(), "Button pressed!", Toast.LENGTH_SHORT).show();
|
private static final String TAG = "Calculator++ Widget";
|
||||||
}
|
|
||||||
}
|
/*
|
||||||
}
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* FIELDS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private String cursorColor;
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* METHODS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnabled(Context context) {
|
||||||
|
super.onEnabled(context);
|
||||||
|
|
||||||
|
getCursorColor(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getCursorColor(@NotNull Context context) {
|
||||||
|
if ( cursorColor == null ) {
|
||||||
|
cursorColor = Integer.toHexString(context.getResources().getColor(R.color.widget_cursor_color)).substring(2);
|
||||||
|
}
|
||||||
|
return cursorColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate(@NotNull Context context,
|
||||||
|
@NotNull AppWidgetManager appWidgetManager,
|
||||||
|
@NotNull int[] appWidgetIds) {
|
||||||
|
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||||
|
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||||
|
|
||||||
|
for (WidgetButton button : WidgetButton.values()) {
|
||||||
|
final Intent onButtonClickIntent = new Intent(context, CalculatorWidgetProvider.class);
|
||||||
|
onButtonClickIntent.setAction(BUTTON_PRESSED_ACTION);
|
||||||
|
onButtonClickIntent.putExtra(BUTTON_ID_EXTRA, button.getButtonId());
|
||||||
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, button.getButtonId(), onButtonClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
if (pendingIntent != null) {
|
||||||
|
views.setOnClickPendingIntent(button.getButtonId(), pendingIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
super.onReceive(context, intent);
|
||||||
|
|
||||||
|
if (CalculatorWidgetProvider.BUTTON_PRESSED_ACTION.equals(intent.getAction())) {
|
||||||
|
final int buttonId = intent.getIntExtra(CalculatorWidgetProvider.BUTTON_ID_EXTRA, 0);
|
||||||
|
|
||||||
|
final WidgetButton button = WidgetButton.getById(buttonId);
|
||||||
|
if (button != null) {
|
||||||
|
button.onClick(context);
|
||||||
|
}
|
||||||
|
} else if (EDITOR_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast received!");
|
||||||
|
|
||||||
|
final Serializable object = intent.getSerializableExtra(EDITOR_STATE_EXTRA);
|
||||||
|
if (object instanceof CalculatorEditorViewState) {
|
||||||
|
updateEditorState(context, (CalculatorEditorViewState) object);
|
||||||
|
}
|
||||||
|
} else if (DISPLAY_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast received!");
|
||||||
|
|
||||||
|
final Serializable object = intent.getSerializableExtra(DISPLAY_STATE_EXTRA);
|
||||||
|
if (object instanceof CalculatorDisplayViewState) {
|
||||||
|
updateDisplayState(context, (CalculatorDisplayViewState) object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDisplayState(@NotNull Context context, @NotNull CalculatorDisplayViewState displayState) {
|
||||||
|
if (displayState.isValid()) {
|
||||||
|
setText(context, R.id.calculatorDisplay, displayState.getText());
|
||||||
|
setTextColor(context, R.id.calculatorDisplay, context.getResources().getColor(R.color.default_text_color));
|
||||||
|
} else {
|
||||||
|
setTextColor(context, R.id.calculatorDisplay, context.getResources().getColor(R.color.display_error_text_color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setText(@NotNull Context context, int textViewId, @Nullable CharSequence text) {
|
||||||
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
|
||||||
|
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, CalculatorWidgetProvider.class));
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||||
|
views.setTextViewText(textViewId, text);
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTextColor(@NotNull Context context, int textViewId, int textColor) {
|
||||||
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
|
||||||
|
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, CalculatorWidgetProvider.class));
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
|
||||||
|
views.setTextColor(textViewId, textColor);
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEditorState(@NotNull Context context, @NotNull CalculatorEditorViewState editorState) {
|
||||||
|
String text = editorState.getText();
|
||||||
|
|
||||||
|
CharSequence newText = text;
|
||||||
|
int selection = editorState.getSelection();
|
||||||
|
if (selection >= 0 && selection <= text.length() ) {
|
||||||
|
// inject cursor
|
||||||
|
newText = Html.fromHtml(text.substring(0, selection) + "<font color=\"#" + getCursorColor(context) + "\">|</font>" + text.substring(selection));
|
||||||
|
}
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "New editor state: " + text);
|
||||||
|
setText(context, R.id.calculatorEditor, newText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* STATIC
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void onEditorStateChanged(@NotNull Context context, @NotNull CalculatorEditorViewState editorViewState) {
|
||||||
|
final Intent intent = new Intent(EDITOR_STATE_CHANGED_ACTION);
|
||||||
|
intent.setClass(context, CalculatorWidgetProvider.class);
|
||||||
|
intent.putExtra(EDITOR_STATE_EXTRA, editorViewState);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Editor state changed broadcast sent");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onDisplayStateChanged(@NotNull Context context, @NotNull CalculatorDisplayViewState displayViewState) {
|
||||||
|
final Intent intent = new Intent(DISPLAY_STATE_CHANGED_ACTION);
|
||||||
|
intent.setClass(context, CalculatorWidgetProvider.class);
|
||||||
|
intent.putExtra(DISPLAY_STATE_EXTRA, displayViewState);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage(TAG, "Display state changed broadcast sent");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
package org.solovyev.android.calculator.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
|
import org.solovyev.android.calculator.CalculatorSpecialButton;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/20/12
|
||||||
|
* Time: 12:05 AM
|
||||||
|
*/
|
||||||
|
enum WidgetButton {
|
||||||
|
|
||||||
|
/*digits*/
|
||||||
|
one(R.id.oneDigitButton, "1"),
|
||||||
|
two(R.id.twoDigitButton, "2"),
|
||||||
|
three(R.id.threeDigitButton, "3"),
|
||||||
|
four(R.id.fourDigitButton, "4"),
|
||||||
|
five(R.id.fiveDigitButton, "5"),
|
||||||
|
six(R.id.sixDigitButton, "6"),
|
||||||
|
seven(R.id.sevenDigitButton, "7"),
|
||||||
|
eight(R.id.eightDigitButton, "8"),
|
||||||
|
nine(R.id.nineDigitButton, "9"),
|
||||||
|
zero(R.id.zeroDigitButton, "0"),
|
||||||
|
|
||||||
|
period(R.id.periodButton, "."),
|
||||||
|
brackets(R.id.roundBracketsButton, "()"),
|
||||||
|
|
||||||
|
settings(R.id.settingsButton, CalculatorSpecialButton.settings_detached),
|
||||||
|
like(R.id.likeButton, CalculatorSpecialButton.like),
|
||||||
|
|
||||||
|
/*last row*/
|
||||||
|
left(R.id.leftButton, CalculatorSpecialButton.cursor_left),
|
||||||
|
right(R.id.rightButton, CalculatorSpecialButton.cursor_right),
|
||||||
|
vars(R.id.varsButton, CalculatorSpecialButton.vars_detached),
|
||||||
|
functions(R.id.functionsButton, CalculatorSpecialButton.functions_detached),
|
||||||
|
app(R.id.appButton, CalculatorSpecialButton.open_app),
|
||||||
|
history(R.id.historyButton, CalculatorSpecialButton.history_detached),
|
||||||
|
|
||||||
|
/*operations*/
|
||||||
|
multiplication(R.id.multiplicationButton, "*"),
|
||||||
|
division(R.id.divisionButton, "/"),
|
||||||
|
plus(R.id.plusButton, "+"),
|
||||||
|
subtraction(R.id.subtractionButton, "-"),
|
||||||
|
percent(R.id.percentButton, "%"),
|
||||||
|
power(R.id.powerButton, "^"),
|
||||||
|
|
||||||
|
/*last column*/
|
||||||
|
clear(R.id.clearButton, CalculatorSpecialButton.clear),
|
||||||
|
erase(R.id.eraseButton, CalculatorSpecialButton.erase),
|
||||||
|
copy(R.id.copyButton, CalculatorSpecialButton.copy),
|
||||||
|
paste(R.id.pasteButton, CalculatorSpecialButton.paste),
|
||||||
|
|
||||||
|
/*equals*/
|
||||||
|
equals(R.id.equalsButton, CalculatorSpecialButton.equals);
|
||||||
|
|
||||||
|
|
||||||
|
private final int buttonId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final String text;
|
||||||
|
|
||||||
|
WidgetButton(int buttonId, @NotNull CalculatorSpecialButton button) {
|
||||||
|
this(buttonId, button.getActionCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetButton(int buttonId, @NotNull String text) {
|
||||||
|
this.buttonId = buttonId;
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(@NotNull Context context) {
|
||||||
|
CalculatorLocatorImpl.getInstance().getNotifier().showDebugMessage("Calculator++ Widget", "Button pressed: " + text);
|
||||||
|
CalculatorLocatorImpl.getInstance().getKeyboard().buttonPressed(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static WidgetButton getById(int buttonId) {
|
||||||
|
for (WidgetButton widgetButton : values()) {
|
||||||
|
if (widgetButton.buttonId == buttonId) {
|
||||||
|
return widgetButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getButtonId() {
|
||||||
|
return buttonId;
|
||||||
|
}
|
||||||
|
}
|