Fragments
This commit is contained in:
parent
c6c2682362
commit
ff1dd19018
@ -1,292 +1,299 @@
|
|||||||
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.common.gui.CursorControl;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
|
import org.solovyev.android.calculator.history.EditorHistoryState;
|
||||||
/**
|
import org.solovyev.common.gui.CursorControl;
|
||||||
* User: Solovyev_S
|
import org.solovyev.common.text.StringUtils;
|
||||||
* Date: 21.09.12
|
|
||||||
* Time: 11:53
|
/**
|
||||||
*/
|
* User: Solovyev_S
|
||||||
public class CalculatorEditorImpl implements CalculatorEditor {
|
* Date: 21.09.12
|
||||||
|
* Time: 11:53
|
||||||
@Nullable
|
*/
|
||||||
private CalculatorEditorView view;
|
public class CalculatorEditorImpl implements CalculatorEditor {
|
||||||
|
|
||||||
@NotNull
|
@Nullable
|
||||||
private final Object viewLock = new Object();
|
private CalculatorEditorView view;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorEditorViewState lastViewState = CalculatorEditorViewStateImpl.newDefaultInstance();
|
private final Object viewLock = new Object();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Calculator calculator;
|
private CalculatorEditorViewState lastViewState = CalculatorEditorViewStateImpl.newDefaultInstance();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CursorControlAdapter cursorControlAdapter = new CursorControlAdapter(this);
|
private final Calculator calculator;
|
||||||
|
|
||||||
public CalculatorEditorImpl(@NotNull Calculator calculator) {
|
@NotNull
|
||||||
this.calculator = calculator;
|
private final CursorControlAdapter cursorControlAdapter = new CursorControlAdapter(this);
|
||||||
this.calculator.addCalculatorEventListener(this);
|
|
||||||
}
|
public CalculatorEditorImpl(@NotNull Calculator calculator) {
|
||||||
|
this.calculator = calculator;
|
||||||
@Override
|
this.calculator.addCalculatorEventListener(this);
|
||||||
public void setView(@Nullable CalculatorEditorView view) {
|
}
|
||||||
synchronized (viewLock) {
|
|
||||||
this.view = view;
|
@Override
|
||||||
|
public void setView(@Nullable CalculatorEditorView view) {
|
||||||
if ( view != null ) {
|
synchronized (viewLock) {
|
||||||
view.setState(lastViewState);
|
this.view = view;
|
||||||
}
|
|
||||||
}
|
if ( view != null ) {
|
||||||
}
|
view.setState(lastViewState);
|
||||||
|
}
|
||||||
@NotNull
|
}
|
||||||
@Override
|
}
|
||||||
public CalculatorEditorViewState getViewState() {
|
|
||||||
return lastViewState;
|
@NotNull
|
||||||
}
|
@Override
|
||||||
|
public CalculatorEditorViewState getViewState() {
|
||||||
@Override
|
return lastViewState;
|
||||||
public void updateViewState() {
|
}
|
||||||
setViewState(this.lastViewState, false);
|
|
||||||
}
|
@Override
|
||||||
|
public void updateViewState() {
|
||||||
@Override
|
setViewState(this.lastViewState, false);
|
||||||
public void setViewState(@NotNull CalculatorEditorViewState newViewState) {
|
}
|
||||||
setViewState(newViewState, true);
|
|
||||||
}
|
@Override
|
||||||
|
public void setViewState(@NotNull CalculatorEditorViewState newViewState) {
|
||||||
private void setViewState(CalculatorEditorViewState newViewState, boolean fireEvent) {
|
setViewState(newViewState, true);
|
||||||
synchronized (viewLock) {
|
}
|
||||||
final CalculatorEditorViewState oldViewState = this.lastViewState;
|
|
||||||
|
private void setViewState(CalculatorEditorViewState newViewState, boolean fireEvent) {
|
||||||
this.lastViewState = newViewState;
|
synchronized (viewLock) {
|
||||||
if (this.view != null) {
|
final CalculatorEditorViewState oldViewState = this.lastViewState;
|
||||||
this.view.setState(newViewState);
|
|
||||||
}
|
this.lastViewState = newViewState;
|
||||||
|
if (this.view != null) {
|
||||||
if (fireEvent) {
|
this.view.setState(newViewState);
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.editor_state_changed, new CalculatorEditorChangeEventDataImpl(oldViewState, newViewState));
|
}
|
||||||
}
|
|
||||||
}
|
if (fireEvent) {
|
||||||
}
|
calculator.fireCalculatorEvent(CalculatorEventType.editor_state_changed, new CalculatorEditorChangeEventDataImpl(oldViewState, newViewState));
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
}
|
||||||
@NotNull CalculatorEventType calculatorEventType,
|
|
||||||
@Nullable Object data) {
|
@Override
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
||||||
}
|
@NotNull CalculatorEventType calculatorEventType,
|
||||||
|
@Nullable Object data) {
|
||||||
/*
|
if (calculatorEventType == CalculatorEventType.use_history_state) {
|
||||||
**********************************************************************
|
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
|
||||||
*
|
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
|
||||||
* SELECTION
|
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
||||||
*
|
}
|
||||||
**********************************************************************
|
}
|
||||||
*/
|
|
||||||
|
/*
|
||||||
@NotNull
|
**********************************************************************
|
||||||
private CalculatorEditorViewState newSelectionViewState(int newSelection) {
|
*
|
||||||
if (this.lastViewState.getSelection() != newSelection) {
|
* SELECTION
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection);
|
*
|
||||||
setViewState(result);
|
**********************************************************************
|
||||||
return result;
|
*/
|
||||||
} else {
|
|
||||||
return this.lastViewState;
|
@NotNull
|
||||||
}
|
private CalculatorEditorViewState newSelectionViewState(int newSelection) {
|
||||||
}
|
if (this.lastViewState.getSelection() != newSelection) {
|
||||||
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection);
|
||||||
@NotNull
|
setViewState(result);
|
||||||
public CalculatorEditorViewState setCursorOnStart() {
|
return result;
|
||||||
synchronized (viewLock) {
|
} else {
|
||||||
return newSelectionViewState(0);
|
return this.lastViewState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
public CalculatorEditorViewState setCursorOnStart() {
|
||||||
public CalculatorEditorViewState setCursorOnEnd() {
|
synchronized (viewLock) {
|
||||||
synchronized (viewLock) {
|
return newSelectionViewState(0);
|
||||||
return newSelectionViewState(this.lastViewState.getText().length());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorEditorViewState moveCursorLeft() {
|
public CalculatorEditorViewState setCursorOnEnd() {
|
||||||
synchronized (viewLock) {
|
synchronized (viewLock) {
|
||||||
if (this.lastViewState.getSelection() > 0) {
|
return newSelectionViewState(this.lastViewState.getText().length());
|
||||||
return newSelectionViewState(this.lastViewState.getSelection() - 1);
|
}
|
||||||
} else {
|
}
|
||||||
return this.lastViewState;
|
|
||||||
}
|
@NotNull
|
||||||
}
|
public CalculatorEditorViewState moveCursorLeft() {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
|
if (this.lastViewState.getSelection() > 0) {
|
||||||
@NotNull
|
return newSelectionViewState(this.lastViewState.getSelection() - 1);
|
||||||
public CalculatorEditorViewState moveCursorRight() {
|
} else {
|
||||||
synchronized (viewLock) {
|
return this.lastViewState;
|
||||||
if (this.lastViewState.getSelection() < this.lastViewState.getText().length()) {
|
}
|
||||||
return newSelectionViewState(this.lastViewState.getSelection() + 1);
|
}
|
||||||
} else {
|
}
|
||||||
return this.lastViewState;
|
|
||||||
}
|
@NotNull
|
||||||
}
|
public CalculatorEditorViewState moveCursorRight() {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
|
if (this.lastViewState.getSelection() < this.lastViewState.getText().length()) {
|
||||||
@NotNull
|
return newSelectionViewState(this.lastViewState.getSelection() + 1);
|
||||||
@Override
|
} else {
|
||||||
public CursorControl asCursorControl() {
|
return this.lastViewState;
|
||||||
return cursorControlAdapter;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
|
||||||
**********************************************************************
|
@NotNull
|
||||||
*
|
@Override
|
||||||
* EDITOR ACTIONS
|
public CursorControl asCursorControl() {
|
||||||
*
|
return cursorControlAdapter;
|
||||||
**********************************************************************
|
}
|
||||||
*/
|
|
||||||
|
/*
|
||||||
@NotNull
|
**********************************************************************
|
||||||
@Override
|
*
|
||||||
public CalculatorEditorViewState erase() {
|
* EDITOR ACTIONS
|
||||||
synchronized (viewLock) {
|
*
|
||||||
int selection = this.lastViewState.getSelection();
|
**********************************************************************
|
||||||
final String text = this.lastViewState.getText();
|
*/
|
||||||
if (selection > 0 && text.length() > 0 && selection <= text.length()) {
|
|
||||||
final StringBuilder newText = new StringBuilder(text.length() - 1);
|
@NotNull
|
||||||
newText.append(text.substring(0, selection - 1)).append(text.substring(selection, text.length()));
|
@Override
|
||||||
|
public CalculatorEditorViewState erase() {
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), selection - 1);
|
synchronized (viewLock) {
|
||||||
setViewState(result);
|
int selection = this.lastViewState.getSelection();
|
||||||
return result;
|
final String text = this.lastViewState.getText();
|
||||||
} else {
|
if (selection > 0 && text.length() > 0 && selection <= text.length()) {
|
||||||
return this.lastViewState;
|
final StringBuilder newText = new StringBuilder(text.length() - 1);
|
||||||
}
|
newText.append(text.substring(0, selection - 1)).append(text.substring(selection, text.length()));
|
||||||
}
|
|
||||||
}
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), selection - 1);
|
||||||
|
setViewState(result);
|
||||||
@NotNull
|
return result;
|
||||||
@Override
|
} else {
|
||||||
public CalculatorEditorViewState clear() {
|
return this.lastViewState;
|
||||||
synchronized (viewLock) {
|
}
|
||||||
return setText("");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
@Override
|
||||||
@Override
|
public CalculatorEditorViewState clear() {
|
||||||
public CalculatorEditorViewState setText(@NotNull String text) {
|
synchronized (viewLock) {
|
||||||
synchronized (viewLock) {
|
return setText("");
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, text.length());
|
}
|
||||||
setViewState(result);
|
}
|
||||||
return result;
|
|
||||||
}
|
@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, int selection) {
|
setViewState(result);
|
||||||
synchronized (viewLock) {
|
return result;
|
||||||
selection = correctSelection(selection, text);
|
}
|
||||||
|
}
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, selection);
|
|
||||||
setViewState(result);
|
@NotNull
|
||||||
return result;
|
@Override
|
||||||
}
|
public CalculatorEditorViewState setText(@NotNull String text, int selection) {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
|
selection = correctSelection(selection, text);
|
||||||
@NotNull
|
|
||||||
@Override
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(text, selection);
|
||||||
public CalculatorEditorViewState insert(@NotNull String text) {
|
setViewState(result);
|
||||||
synchronized (viewLock) {
|
return result;
|
||||||
return insert(text, 0);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
@Override
|
||||||
@Override
|
public CalculatorEditorViewState insert(@NotNull String text) {
|
||||||
public CalculatorEditorViewState insert(@NotNull String text, int selectionOffset) {
|
synchronized (viewLock) {
|
||||||
synchronized (viewLock) {
|
return insert(text, 0);
|
||||||
final int selection = this.lastViewState.getSelection();
|
}
|
||||||
final String oldText = this.lastViewState.getText();
|
}
|
||||||
|
|
||||||
int newTextLength = text.length() + oldText.length();
|
@NotNull
|
||||||
final StringBuilder newText = new StringBuilder(newTextLength);
|
@Override
|
||||||
|
public CalculatorEditorViewState insert(@NotNull String text, int selectionOffset) {
|
||||||
newText.append(oldText.substring(0, selection));
|
synchronized (viewLock) {
|
||||||
newText.append(text);
|
final int selection = this.lastViewState.getSelection();
|
||||||
newText.append(oldText.substring(selection));
|
final String oldText = this.lastViewState.getText();
|
||||||
|
|
||||||
int newSelection = correctSelection(text.length() + selection + selectionOffset, newTextLength);
|
int newTextLength = text.length() + oldText.length();
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), newSelection);
|
final StringBuilder newText = new StringBuilder(newTextLength);
|
||||||
setViewState(result);
|
|
||||||
return result;
|
newText.append(oldText.substring(0, selection));
|
||||||
}
|
newText.append(text);
|
||||||
}
|
newText.append(oldText.substring(selection));
|
||||||
|
|
||||||
@NotNull
|
int newSelection = correctSelection(text.length() + selection + selectionOffset, newTextLength);
|
||||||
@Override
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newInstance(newText.toString(), newSelection);
|
||||||
public CalculatorEditorViewState moveSelection(int offset) {
|
setViewState(result);
|
||||||
synchronized (viewLock) {
|
return result;
|
||||||
int selection = this.lastViewState.getSelection() + offset;
|
}
|
||||||
|
}
|
||||||
return setSelection(selection);
|
|
||||||
}
|
@NotNull
|
||||||
}
|
@Override
|
||||||
|
public CalculatorEditorViewState moveSelection(int offset) {
|
||||||
@NotNull
|
synchronized (viewLock) {
|
||||||
@Override
|
int selection = this.lastViewState.getSelection() + offset;
|
||||||
public CalculatorEditorViewState setSelection(int selection) {
|
|
||||||
synchronized (viewLock) {
|
return setSelection(selection);
|
||||||
selection = correctSelection(selection, this.lastViewState.getText());
|
}
|
||||||
|
}
|
||||||
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection);
|
|
||||||
setViewState(result);
|
@NotNull
|
||||||
return result;
|
@Override
|
||||||
}
|
public CalculatorEditorViewState setSelection(int selection) {
|
||||||
}
|
synchronized (viewLock) {
|
||||||
|
selection = correctSelection(selection, this.lastViewState.getText());
|
||||||
private int correctSelection(int selection, @NotNull String text) {
|
|
||||||
return correctSelection(selection, text.length());
|
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection);
|
||||||
}
|
setViewState(result);
|
||||||
|
return result;
|
||||||
private int correctSelection(int selection, int textLength) {
|
}
|
||||||
int result = Math.max(selection, 0);
|
}
|
||||||
result = Math.min(result, textLength);
|
|
||||||
return result;
|
private int correctSelection(int selection, @NotNull String text) {
|
||||||
}
|
return correctSelection(selection, text.length());
|
||||||
|
}
|
||||||
private static final class CursorControlAdapter implements CursorControl {
|
|
||||||
|
private int correctSelection(int selection, int textLength) {
|
||||||
@NotNull
|
int result = Math.max(selection, 0);
|
||||||
private final CalculatorEditor calculatorEditor;
|
result = Math.min(result, textLength);
|
||||||
|
return result;
|
||||||
private CursorControlAdapter(@NotNull CalculatorEditor calculatorEditor) {
|
}
|
||||||
this.calculatorEditor = calculatorEditor;
|
|
||||||
}
|
private static final class CursorControlAdapter implements CursorControl {
|
||||||
|
|
||||||
@Override
|
@NotNull
|
||||||
public void setCursorOnStart() {
|
private final CalculatorEditor calculatorEditor;
|
||||||
this.calculatorEditor.setCursorOnStart();
|
|
||||||
}
|
private CursorControlAdapter(@NotNull CalculatorEditor calculatorEditor) {
|
||||||
|
this.calculatorEditor = calculatorEditor;
|
||||||
@Override
|
}
|
||||||
public void setCursorOnEnd() {
|
|
||||||
this.calculatorEditor.setCursorOnEnd();
|
@Override
|
||||||
}
|
public void setCursorOnStart() {
|
||||||
|
this.calculatorEditor.setCursorOnStart();
|
||||||
@Override
|
}
|
||||||
public void moveCursorLeft() {
|
|
||||||
this.calculatorEditor.moveCursorLeft();
|
@Override
|
||||||
}
|
public void setCursorOnEnd() {
|
||||||
|
this.calculatorEditor.setCursorOnEnd();
|
||||||
@Override
|
}
|
||||||
public void moveCursorRight() {
|
|
||||||
this.calculatorEditor.moveCursorRight();
|
@Override
|
||||||
}
|
public void moveCursorLeft() {
|
||||||
}
|
this.calculatorEditor.moveCursorLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveCursorRight() {
|
||||||
|
this.calculatorEditor.moveCursorRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -75,7 +75,21 @@ public enum CalculatorEventType {
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
engine_preferences_changed;
|
engine_preferences_changed,
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* HISTORY
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @NotNull CalculatorHistoryState
|
||||||
|
history_state_added,
|
||||||
|
|
||||||
|
// @NotNull CalculatorHistoryState
|
||||||
|
use_history_state;
|
||||||
|
|
||||||
public boolean isOfType(@NotNull CalculatorEventType... types) {
|
public boolean isOfType(@NotNull CalculatorEventType... types) {
|
||||||
for (CalculatorEventType type : types) {
|
for (CalculatorEventType type : types) {
|
||||||
|
@ -1,233 +1,234 @@
|
|||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
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.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.history.HistoryHelper;
|
import org.solovyev.common.history.HistoryHelper;
|
||||||
import org.solovyev.common.history.SimpleHistoryHelper;
|
import org.solovyev.common.history.SimpleHistoryHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed;
|
import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed;
|
||||||
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
|
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
|
||||||
import static org.solovyev.android.calculator.CalculatorEventType.manual_calculation_requested;
|
import static org.solovyev.android.calculator.CalculatorEventType.manual_calculation_requested;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 20.09.12
|
* Date: 20.09.12
|
||||||
* Time: 16:12
|
* Time: 16:12
|
||||||
*/
|
*/
|
||||||
public class CalculatorHistoryImpl implements CalculatorHistory {
|
public class CalculatorHistoryImpl implements CalculatorHistory {
|
||||||
|
|
||||||
private final AtomicInteger counter = new AtomicInteger(0);
|
private final AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
private final HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
|
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private volatile CalculatorEventData lastEventData = CalculatorUtils.createFirstEventDataId();
|
private volatile CalculatorEventData lastEventData = CalculatorUtils.createFirstEventDataId();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Object lastEventDataLock = new Object();
|
private final Object lastEventDataLock = new Object();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile CalculatorEditorViewState lastEditorViewState;
|
private volatile CalculatorEditorViewState lastEditorViewState;
|
||||||
|
|
||||||
public CalculatorHistoryImpl(@NotNull Calculator calculator) {
|
public CalculatorHistoryImpl(@NotNull Calculator calculator) {
|
||||||
calculator.addCalculatorEventListener(this);
|
calculator.addCalculatorEventListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return this.history.isEmpty();
|
return this.history.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHistoryState getLastHistoryState() {
|
public CalculatorHistoryState getLastHistoryState() {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return this.history.getLastHistoryState();
|
return this.history.getLastHistoryState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUndoAvailable() {
|
public boolean isUndoAvailable() {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.isUndoAvailable();
|
return history.isUndoAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) {
|
public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.undo(currentState);
|
return history.undo(currentState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRedoAvailable() {
|
public boolean isRedoAvailable() {
|
||||||
return history.isRedoAvailable();
|
return history.isRedoAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) {
|
public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.redo(currentState);
|
return history.redo(currentState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActionAvailable(@NotNull HistoryAction historyAction) {
|
public boolean isActionAvailable(@NotNull HistoryAction historyAction) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.isActionAvailable(historyAction);
|
return history.isActionAvailable(historyAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHistoryState doAction(@NotNull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) {
|
public CalculatorHistoryState doAction(@NotNull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.doAction(historyAction, currentState);
|
return history.doAction(historyAction, currentState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addState(@Nullable CalculatorHistoryState currentState) {
|
public void addState(@Nullable CalculatorHistoryState currentState) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
history.addState(currentState);
|
history.addState(currentState);
|
||||||
}
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
@Override
|
@NotNull
|
||||||
public List<CalculatorHistoryState> getStates() {
|
@Override
|
||||||
synchronized (history) {
|
public List<CalculatorHistoryState> getStates() {
|
||||||
return history.getStates();
|
synchronized (history) {
|
||||||
}
|
return history.getStates();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void clear() {
|
@Override
|
||||||
synchronized (history) {
|
public void clear() {
|
||||||
this.history.clear();
|
synchronized (history) {
|
||||||
}
|
this.history.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
@NotNull
|
@Override
|
||||||
public List<CalculatorHistoryState> getSavedHistory() {
|
@NotNull
|
||||||
return Collections.unmodifiableList(savedHistory);
|
public List<CalculatorHistoryState> getSavedHistory() {
|
||||||
}
|
return Collections.unmodifiableList(savedHistory);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
@NotNull
|
@Override
|
||||||
public CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState) {
|
@NotNull
|
||||||
if (historyState.isSaved()) {
|
public CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState) {
|
||||||
return historyState;
|
if (historyState.isSaved()) {
|
||||||
} else {
|
return historyState;
|
||||||
final CalculatorHistoryState savedState = historyState.clone();
|
} else {
|
||||||
|
final CalculatorHistoryState savedState = historyState.clone();
|
||||||
savedState.setId(counter.incrementAndGet());
|
|
||||||
savedState.setSaved(true);
|
savedState.setId(counter.incrementAndGet());
|
||||||
|
savedState.setSaved(true);
|
||||||
savedHistory.add(savedState);
|
|
||||||
|
savedHistory.add(savedState);
|
||||||
return savedState;
|
|
||||||
}
|
return savedState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void load() {
|
@Override
|
||||||
// todo serso: create saved/loader class
|
public void load() {
|
||||||
}
|
// todo serso: create saved/loader class
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void save() {
|
@Override
|
||||||
// todo serso: create saved/loader class
|
public void save() {
|
||||||
}
|
// todo serso: create saved/loader class
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void fromXml(@NotNull String xml) {
|
@Override
|
||||||
clearSavedHistory();
|
public void fromXml(@NotNull String xml) {
|
||||||
|
clearSavedHistory();
|
||||||
HistoryUtils.fromXml(xml, this.savedHistory);
|
|
||||||
for (CalculatorHistoryState historyState : savedHistory) {
|
HistoryUtils.fromXml(xml, this.savedHistory);
|
||||||
historyState.setSaved(true);
|
for (CalculatorHistoryState historyState : savedHistory) {
|
||||||
historyState.setId(counter.incrementAndGet());
|
historyState.setSaved(true);
|
||||||
}
|
historyState.setId(counter.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String toXml() {
|
@Override
|
||||||
return HistoryUtils.toXml(this.savedHistory);
|
public String toXml() {
|
||||||
}
|
return HistoryUtils.toXml(this.savedHistory);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void clearSavedHistory() {
|
@Override
|
||||||
this.savedHistory.clear();
|
public void clearSavedHistory() {
|
||||||
}
|
this.savedHistory.clear();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState) {
|
@Override
|
||||||
this.savedHistory.remove(historyState);
|
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState) {
|
||||||
}
|
this.savedHistory.remove(historyState);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
@Override
|
||||||
@NotNull CalculatorEventType calculatorEventType,
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
||||||
@Nullable Object data) {
|
@NotNull CalculatorEventType calculatorEventType,
|
||||||
if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) {
|
@Nullable Object data) {
|
||||||
|
if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) {
|
||||||
boolean sameSequence = false;
|
|
||||||
boolean afterSequence = false;
|
boolean sameSequence = false;
|
||||||
|
boolean afterSequence = false;
|
||||||
boolean processEvent = false;
|
|
||||||
|
boolean processEvent = false;
|
||||||
synchronized (this.lastEventDataLock) {
|
|
||||||
if (calculatorEventData.isAfter(this.lastEventData)) {
|
synchronized (this.lastEventDataLock) {
|
||||||
|
if (calculatorEventData.isAfter(this.lastEventData)) {
|
||||||
sameSequence = calculatorEventData.isSameSequence(this.lastEventData);
|
|
||||||
if (!sameSequence) {
|
sameSequence = calculatorEventData.isSameSequence(this.lastEventData);
|
||||||
afterSequence = calculatorEventData.isAfterSequence(this.lastEventData);
|
if (!sameSequence) {
|
||||||
processEvent = afterSequence;
|
afterSequence = calculatorEventData.isAfterSequence(this.lastEventData);
|
||||||
} else {
|
processEvent = afterSequence;
|
||||||
processEvent = true;
|
} else {
|
||||||
}
|
processEvent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (processEvent) {
|
|
||||||
this.lastEventData = calculatorEventData;
|
if (processEvent) {
|
||||||
|
this.lastEventData = calculatorEventData;
|
||||||
switch (calculatorEventType) {
|
|
||||||
case manual_calculation_requested:
|
switch (calculatorEventType) {
|
||||||
lastEditorViewState = (CalculatorEditorViewState) data;
|
case manual_calculation_requested:
|
||||||
break;
|
lastEditorViewState = (CalculatorEditorViewState) data;
|
||||||
case editor_state_changed:
|
break;
|
||||||
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
|
case editor_state_changed:
|
||||||
lastEditorViewState = editorChangeData.getNewState();
|
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
|
||||||
break;
|
lastEditorViewState = editorChangeData.getNewState();
|
||||||
case display_state_changed:
|
break;
|
||||||
if (sameSequence) {
|
case display_state_changed:
|
||||||
if (lastEditorViewState != null) {
|
if (sameSequence) {
|
||||||
final CalculatorEditorViewState editorViewState = lastEditorViewState;
|
if (lastEditorViewState != null) {
|
||||||
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
|
final CalculatorEditorViewState editorViewState = lastEditorViewState;
|
||||||
final CalculatorDisplayViewState displayViewState = displayChangeData.getNewState();
|
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
|
||||||
addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState));
|
final CalculatorDisplayViewState displayViewState = displayChangeData.getNewState();
|
||||||
}
|
addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState));
|
||||||
} else {
|
}
|
||||||
lastEditorViewState = null;
|
} else {
|
||||||
}
|
lastEditorViewState = null;
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,70 +1,66 @@
|
|||||||
<?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="81" android:versionName="1.3.2"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="81" android:versionName="1.3.2"
|
||||||
package="org.solovyev.android.calculator">
|
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="true" 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="true" 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">
|
||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
|
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.CalculatorHistoryFragment"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_saved_history" android:name=".history.CalculatorSavedHistoryFragment"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsTabActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsTabActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
|
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsTabActivity"/>
|
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||||
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
<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"/>
|
</application>
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
|
|
||||||
</application>
|
|
||||||
</manifest>
|
</manifest>
|
@ -1,336 +1,335 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>calculatorpp-parent</artifactId>
|
<artifactId>calculatorpp-parent</artifactId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>calculatorpp</artifactId>
|
<artifactId>calculatorpp</artifactId>
|
||||||
<packaging>apk</packaging>
|
<packaging>apk</packaging>
|
||||||
<name>Calculator++ Application</name>
|
<name>Calculator++ Application</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- OWN -->
|
<!-- OWN -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>calculatorpp-core</artifactId>
|
<artifactId>calculatorpp-core</artifactId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>common-core</artifactId>
|
<artifactId>common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>common-text</artifactId>
|
<artifactId>common-text</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-core</artifactId>
|
<artifactId>android-common-core</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-ads</artifactId>
|
<artifactId>android-common-ads</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-view</artifactId>
|
<artifactId>android-common-view</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-preferences</artifactId>
|
<artifactId>android-common-preferences</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-other</artifactId>
|
<artifactId>android-common-other</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-menu</artifactId>
|
<artifactId>android-common-menu</artifactId>
|
||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<artifactId>android-common-sherlock</artifactId>
|
<artifactId>android-common-sherlock</artifactId>
|
||||||
<version>1.0.0</version>
|
<type>apklib</type>
|
||||||
<type>apklib</type>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.solovyev</groupId>
|
||||||
<groupId>org.solovyev</groupId>
|
<artifactId>jscl</artifactId>
|
||||||
<artifactId>jscl</artifactId>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<!--OTHER-->
|
||||||
<!--OTHER-->
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.google.android</groupId>
|
||||||
<groupId>com.google.android</groupId>
|
<artifactId>android</artifactId>
|
||||||
<artifactId>android</artifactId>
|
<scope>provided</scope>
|
||||||
<scope>provided</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.google.android</groupId>
|
||||||
<groupId>com.google.android</groupId>
|
<artifactId>support-v4</artifactId>
|
||||||
<artifactId>support-v4</artifactId>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.actionbarsherlock</groupId>
|
||||||
<groupId>com.actionbarsherlock</groupId>
|
<artifactId>library</artifactId>
|
||||||
<artifactId>library</artifactId>
|
<type>apklib</type>
|
||||||
<version>4.1.0</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>net.sf.opencsv</groupId>
|
||||||
<groupId>net.sf.opencsv</groupId>
|
<artifactId>opencsv</artifactId>
|
||||||
<artifactId>opencsv</artifactId>
|
<version>2.0</version>
|
||||||
<version>2.0</version>
|
<scope>test</scope>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.simpleframework</groupId>
|
||||||
<groupId>org.simpleframework</groupId>
|
<artifactId>simple-xml</artifactId>
|
||||||
<artifactId>simple-xml</artifactId>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>achartengine</groupId>
|
||||||
<groupId>achartengine</groupId>
|
<artifactId>achartengine</artifactId>
|
||||||
<artifactId>achartengine</artifactId>
|
<version>0.7.0</version>
|
||||||
<version>0.7.0</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>admob</groupId>
|
||||||
<groupId>admob</groupId>
|
<artifactId>admob</artifactId>
|
||||||
<artifactId>admob</artifactId>
|
<version>6.1.0</version>
|
||||||
<version>6.1.0</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.solovyev.android</groupId>
|
||||||
<groupId>org.solovyev.android</groupId>
|
<artifactId>billing</artifactId>
|
||||||
<artifactId>billing</artifactId>
|
<version>0.1</version>
|
||||||
<version>0.1</version>
|
<!--<type>apklib</type>-->
|
||||||
<!--<type>apklib</type>-->
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.google.guava</groupId>
|
||||||
<groupId>com.google.guava</groupId>
|
<artifactId>guava</artifactId>
|
||||||
<artifactId>guava</artifactId>
|
<version>11.0.2</version>
|
||||||
<version>11.0.2</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>junit</groupId>
|
||||||
<groupId>junit</groupId>
|
<artifactId>junit</artifactId>
|
||||||
<artifactId>junit</artifactId>
|
<scope>test</scope>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.intellij</groupId>
|
||||||
<groupId>com.intellij</groupId>
|
<artifactId>annotations</artifactId>
|
||||||
<artifactId>annotations</artifactId>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
</dependencies>
|
||||||
</dependencies>
|
|
||||||
|
<build>
|
||||||
<build>
|
|
||||||
|
|
||||||
|
<plugins>
|
||||||
<plugins>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
<artifactId>android-maven-plugin</artifactId>
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
<extensions>true</extensions>
|
||||||
<extensions>true</extensions>
|
<configuration>
|
||||||
<configuration>
|
<manifest>
|
||||||
<manifest>
|
<debuggable>true</debuggable>
|
||||||
<debuggable>true</debuggable>
|
</manifest>
|
||||||
</manifest>
|
</configuration>
|
||||||
</configuration>
|
<executions>
|
||||||
<executions>
|
<execution>
|
||||||
<execution>
|
<id>manifestUpdate</id>
|
||||||
<id>manifestUpdate</id>
|
<phase>process-resources</phase>
|
||||||
<phase>process-resources</phase>
|
<goals>
|
||||||
<goals>
|
<goal>manifest-update</goal>
|
||||||
<goal>manifest-update</goal>
|
</goals>
|
||||||
</goals>
|
</execution>
|
||||||
</execution>
|
<execution>
|
||||||
<execution>
|
<id>alignApk</id>
|
||||||
<id>alignApk</id>
|
<phase>package</phase>
|
||||||
<phase>package</phase>
|
<goals>
|
||||||
<goals>
|
<goal>zipalign</goal>
|
||||||
<goal>zipalign</goal>
|
</goals>
|
||||||
</goals>
|
</execution>
|
||||||
</execution>
|
</executions>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
</plugins>
|
||||||
</plugins>
|
|
||||||
|
</build>
|
||||||
</build>
|
|
||||||
|
<profiles>
|
||||||
<profiles>
|
|
||||||
|
<profile>
|
||||||
<profile>
|
<id>release</id>
|
||||||
<id>release</id>
|
<!-- via this activation the profile is automatically used when the release is done with the maven release
|
||||||
<!-- via this activation the profile is automatically used when the release is done with the maven release
|
plugin -->
|
||||||
plugin -->
|
<activation>
|
||||||
<activation>
|
<property>
|
||||||
<property>
|
<name>performRelease</name>
|
||||||
<name>performRelease</name>
|
<value>true</value>
|
||||||
<value>true</value>
|
</property>
|
||||||
</property>
|
</activation>
|
||||||
</activation>
|
|
||||||
|
<build>
|
||||||
<build>
|
<plugins>
|
||||||
<plugins>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<artifactId>properties-maven-plugin</artifactId>
|
||||||
<artifactId>properties-maven-plugin</artifactId>
|
<version>1.0-alpha-2</version>
|
||||||
<version>1.0-alpha-2</version>
|
<executions>
|
||||||
<executions>
|
<execution>
|
||||||
<execution>
|
<phase>initialize</phase>
|
||||||
<phase>initialize</phase>
|
<goals>
|
||||||
<goals>
|
<goal>read-project-properties</goal>
|
||||||
<goal>read-project-properties</goal>
|
</goals>
|
||||||
</goals>
|
<configuration>
|
||||||
<configuration>
|
<files>
|
||||||
<files>
|
<file>${project.basedir}/misc/env/jarsigner.properties</file>
|
||||||
<file>${project.basedir}/misc/env/jarsigner.properties</file>
|
</files>
|
||||||
</files>
|
</configuration>
|
||||||
</configuration>
|
</execution>
|
||||||
</execution>
|
</executions>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-jarsigner-plugin</artifactId>
|
||||||
<artifactId>maven-jarsigner-plugin</artifactId>
|
<executions>
|
||||||
<executions>
|
<execution>
|
||||||
<execution>
|
<id>signing</id>
|
||||||
<id>signing</id>
|
<goals>
|
||||||
<goals>
|
<goal>sign</goal>
|
||||||
<goal>sign</goal>
|
<goal>verify</goal>
|
||||||
<goal>verify</goal>
|
</goals>
|
||||||
</goals>
|
<phase>package</phase>
|
||||||
<phase>package</phase>
|
<inherited>true</inherited>
|
||||||
<inherited>true</inherited>
|
<configuration>
|
||||||
<configuration>
|
<removeExistingSignatures>true</removeExistingSignatures>
|
||||||
<removeExistingSignatures>true</removeExistingSignatures>
|
<archiveDirectory/>
|
||||||
<archiveDirectory/>
|
<includes>
|
||||||
<includes>
|
<include>${project.build.directory}/${project.artifactId}-${project.version}.apk</include>
|
||||||
<include>${project.build.directory}/${project.artifactId}-${project.version}.apk</include>
|
</includes>
|
||||||
</includes>
|
<keystore>${sign.keystore}</keystore>
|
||||||
<keystore>${sign.keystore}</keystore>
|
<alias>${sign.alias}</alias>
|
||||||
<alias>${sign.alias}</alias>
|
<storepass>${sign.storepass}</storepass>
|
||||||
<storepass>${sign.storepass}</storepass>
|
<keypass>${sign.keypass}</keypass>
|
||||||
<keypass>${sign.keypass}</keypass>
|
<verbose>false</verbose>
|
||||||
<verbose>false</verbose>
|
</configuration>
|
||||||
</configuration>
|
</execution>
|
||||||
</execution>
|
</executions>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
<!-- the signed apk then needs to be zipaligned and we activate proguard and we run the manifest
|
||||||
<!-- the signed apk then needs to be zipaligned and we activate proguard and we run the manifest
|
update -->
|
||||||
update -->
|
<plugin>
|
||||||
<plugin>
|
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
<artifactId>android-maven-plugin</artifactId>
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
<inherited>true</inherited>
|
||||||
<inherited>true</inherited>
|
<configuration>
|
||||||
<configuration>
|
|
||||||
|
<sign>
|
||||||
<sign>
|
<debug>false</debug>
|
||||||
<debug>false</debug>
|
</sign>
|
||||||
</sign>
|
|
||||||
|
<zipalign>
|
||||||
<zipalign>
|
<verbose>false</verbose>
|
||||||
<verbose>false</verbose>
|
<inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
|
||||||
<inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
|
<outputApk>${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk</outputApk>
|
||||||
<outputApk>${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk</outputApk>
|
</zipalign>
|
||||||
</zipalign>
|
|
||||||
|
<manifest>
|
||||||
<manifest>
|
<debuggable>false</debuggable>
|
||||||
<debuggable>false</debuggable>
|
<versionCodeAutoIncrement>true</versionCodeAutoIncrement>
|
||||||
<versionCodeAutoIncrement>true</versionCodeAutoIncrement>
|
</manifest>
|
||||||
</manifest>
|
|
||||||
|
<proguard>
|
||||||
<proguard>
|
<skip>true</skip>
|
||||||
<skip>true</skip>
|
</proguard>
|
||||||
</proguard>
|
</configuration>
|
||||||
</configuration>
|
|
||||||
|
<executions>
|
||||||
<executions>
|
<execution>
|
||||||
<execution>
|
<id>manifestUpdate</id>
|
||||||
<id>manifestUpdate</id>
|
<phase>process-resources</phase>
|
||||||
<phase>process-resources</phase>
|
<goals>
|
||||||
<goals>
|
<goal>manifest-update</goal>
|
||||||
<goal>manifest-update</goal>
|
</goals>
|
||||||
</goals>
|
</execution>
|
||||||
</execution>
|
<execution>
|
||||||
<execution>
|
<id>alignApk</id>
|
||||||
<id>alignApk</id>
|
<phase>package</phase>
|
||||||
<phase>package</phase>
|
<goals>
|
||||||
<goals>
|
<goal>zipalign</goal>
|
||||||
<goal>zipalign</goal>
|
</goals>
|
||||||
</goals>
|
</execution>
|
||||||
</execution>
|
</executions>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
<configuration>
|
||||||
<configuration>
|
<artifacts>
|
||||||
<artifacts>
|
<artifact>
|
||||||
<artifact>
|
<file>${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk</file>
|
||||||
<file>${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk</file>
|
<type>apk</type>
|
||||||
<type>apk</type>
|
<classifier>signed-aligned</classifier>
|
||||||
<classifier>signed-aligned</classifier>
|
</artifact>
|
||||||
</artifact>
|
<artifact>
|
||||||
<artifact>
|
<file>${project.build.directory}/proguard/mapping.txt</file>
|
||||||
<file>${project.build.directory}/proguard/mapping.txt</file>
|
<type>map</type>
|
||||||
<type>map</type>
|
<classifier>release</classifier>
|
||||||
<classifier>release</classifier>
|
</artifact>
|
||||||
</artifact>
|
</artifacts>
|
||||||
</artifacts>
|
</configuration>
|
||||||
</configuration>
|
<executions>
|
||||||
<executions>
|
<execution>
|
||||||
<execution>
|
<id>attach-signed-aligned</id>
|
||||||
<id>attach-signed-aligned</id>
|
<phase>package</phase>
|
||||||
<phase>package</phase>
|
<goals>
|
||||||
<goals>
|
<goal>attach-artifact</goal>
|
||||||
<goal>attach-artifact</goal>
|
</goals>
|
||||||
</goals>
|
</execution>
|
||||||
</execution>
|
</executions>
|
||||||
</executions>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
</plugins>
|
||||||
</plugins>
|
</build>
|
||||||
</build>
|
</profile>
|
||||||
</profile>
|
</profiles>
|
||||||
</profiles>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,64 +1,19 @@
|
|||||||
<?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
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
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:id="@+id/main_layout"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_gravity="center"
|
a:layout_gravity="center"
|
||||||
a:background="@color/default_background">
|
a:background="@color/default_background">
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/editorContainer"
|
<include layout="@layout/main_first_pane"/>
|
||||||
a:layout_weight="2"
|
|
||||||
a:layout_width="match_parent"
|
</LinearLayout>
|
||||||
a:layout_height="0dp"/>
|
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="0dp">
|
|
||||||
|
|
||||||
<include layout="@layout/calc_left_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_erase_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/displayContainer"
|
|
||||||
a:layout_margin="@dimen/display_margin"
|
|
||||||
a:layout_weight="4"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_clear_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_right_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/keyboardContainer"
|
|
||||||
a:layout_weight="3"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="0dp"/>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
62
calculatorpp/res/layout-land/main_first_pane.xml
Normal file
62
calculatorpp/res/layout-land/main_first_pane.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
|
~ or visit http://se.solovyev.org
|
||||||
|
-->
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:orientation="vertical"
|
||||||
|
a:layout_gravity="center">
|
||||||
|
|
||||||
|
<LinearLayout a:id="@+id/editorContainer"
|
||||||
|
a:layout_weight="2"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_left_button"
|
||||||
|
a:layout_margin="@dimen/button_margin"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
<include layout="@layout/calc_erase_button"
|
||||||
|
a:layout_margin="@dimen/button_margin"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
<LinearLayout a:id="@+id/displayContainer"
|
||||||
|
a:layout_margin="@dimen/display_margin"
|
||||||
|
a:layout_weight="4"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<include layout="@layout/calc_clear_button"
|
||||||
|
a:layout_margin="@dimen/button_margin"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
<include layout="@layout/calc_right_button"
|
||||||
|
a:layout_margin="@dimen/button_margin"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:id="@+id/keyboardContainer"
|
||||||
|
a:layout_weight="3"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -1,78 +1,31 @@
|
|||||||
<?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
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
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:id="@+id/main_layout"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="horizontal"
|
a:orientation="horizontal"
|
||||||
a:layout_gravity="center"
|
a:layout_gravity="center"
|
||||||
a:background="@color/default_background"
|
a:background="@color/default_background"
|
||||||
a:baselineAligned="false">
|
a:baselineAligned="false">
|
||||||
|
|
||||||
<LinearLayout a:orientation="vertical"
|
<include layout="@layout/main_first_pane"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_weight="1">
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/editorContainer"
|
|
||||||
a:layout_weight="2"
|
<LinearLayout a:id="@+id/main_second_pane"
|
||||||
a:layout_width="match_parent"
|
a:orientation="vertical"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="match_parent"
|
||||||
|
a:layout_width="0dp"
|
||||||
<LinearLayout a:layout_weight="1"
|
a:layout_weight="1"/>
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="0dp">
|
|
||||||
|
</LinearLayout>
|
||||||
<include layout="@layout/calc_left_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_erase_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/displayContainer"
|
|
||||||
a:layout_margin="@dimen/display_margin"
|
|
||||||
a:layout_weight="4"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_clear_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
<include layout="@layout/calc_right_button"
|
|
||||||
a:layout_margin="@dimen/button_margin"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/keyboardContainer"
|
|
||||||
a:layout_weight="3"
|
|
||||||
a:layout_width="match_parent"
|
|
||||||
a:layout_height="0dp"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/content_second_pane"
|
|
||||||
a:orientation="vertical"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_weight="1"/>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
6
calculatorpp/res/layout/ad.xml
Normal file
6
calculatorpp/res/layout/ad.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:id="@+id/ad_parent_view"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="75px"/>
|
15
calculatorpp/res/layout/history_fragment.xml
Normal file
15
calculatorpp/res/layout/history_fragment.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:orientation="vertical">
|
||||||
|
|
||||||
|
<include layout="@layout/ad"/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="match_parent"
|
||||||
|
a:id="@android:id/list"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -1,21 +1,15 @@
|
|||||||
<?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/ad_parent_view"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<ListView
|
|
||||||
a:layout_width="fill_parent"
|
|
||||||
a:layout_height="fill_parent"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:id="@android:id/list"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,4 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="button_margin">0.5dp</dimen>
|
<dimen name="button_margin">0.5dp</dimen>
|
||||||
<dimen name="display_margin">@dimen/button_margin</dimen>
|
<dimen name="display_margin">2.0dp</dimen>
|
||||||
|
<dimen name="display_margin_land">2.5dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -1,381 +1,381 @@
|
|||||||
/*
|
/*
|
||||||
* 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.Activity;
|
import android.app.Activity;
|
||||||
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.support.v4.app.FragmentActivity;
|
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.util.TypedValue;
|
||||||
import android.util.TypedValue;
|
import android.view.*;
|
||||||
import android.view.*;
|
import android.widget.TextView;
|
||||||
import android.widget.TextView;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import net.robotmedia.billing.IBillingObserver;
|
import net.robotmedia.billing.IBillingObserver;
|
||||||
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.FontSizeAdjuster;
|
import org.solovyev.android.FontSizeAdjuster;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.view.CalculatorAdditionalTitle;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
import org.solovyev.android.fragments.FragmentUtils;
|
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||||
import org.solovyev.android.menu.ActivityMenu;
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.menu.ListActivityMenu;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.text.StringUtils;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
|
||||||
import org.solovyev.common.text.StringUtils;
|
public class CalculatorActivity extends SherlockFragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public class CalculatorActivity extends FragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
@NotNull
|
||||||
|
public static final String TAG = "Calculator++";
|
||||||
@NotNull
|
|
||||||
public static final String TAG = "Calculator++";
|
private static final int HVGA_WIDTH_PIXELS = 320;
|
||||||
|
|
||||||
private static final int HVGA_WIDTH_PIXELS = 320;
|
@Nullable
|
||||||
|
private IBillingObserver billingObserver;
|
||||||
@Nullable
|
|
||||||
private IBillingObserver billingObserver;
|
private boolean useBackAsPrev;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorActivityHelper activityHelper;
|
||||||
|
|
||||||
@NotNull
|
/**
|
||||||
private CalculatorPreferences.Gui.Layout layout;
|
* Called when the activity is first created.
|
||||||
|
*/
|
||||||
private boolean useBackAsPrev;
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@NotNull
|
|
||||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
CalculatorApplication.registerOnRemoteStackTrace();
|
||||||
|
|
||||||
/**
|
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
|
||||||
* Called when the activity is first created.
|
|
||||||
*/
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
CalculatorApplication.registerOnRemoteStackTrace();
|
activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(layout.getLayoutId());
|
||||||
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
if (findViewById(R.id.main_second_pane) != null) {
|
||||||
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
||||||
setTheme(this.theme.getThemeId());
|
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
|
||||||
|
activityHelper.restoreSavedTab(this);
|
||||||
super.onCreate(savedInstanceState);
|
}
|
||||||
setLayout(preferences);
|
|
||||||
|
CalculatorKeyboardFragment.fixThemeParameters(true, activityHelper.getTheme(), this.getWindow().getDecorView());
|
||||||
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
|
||||||
|
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");
|
|
||||||
|
/*if (customTitleSupported) {
|
||||||
if (customTitleSupported) {
|
try {
|
||||||
try {
|
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
||||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
|
||||||
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
|
additionalAdditionalTitleText.init(preferences);
|
||||||
additionalAdditionalTitleText.init(preferences);
|
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
|
||||||
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
|
} catch (ClassCastException e) {
|
||||||
} catch (ClassCastException e) {
|
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
|
||||||
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
|
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
|
||||||
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
|
}
|
||||||
}
|
}*/
|
||||||
}
|
|
||||||
|
billingObserver = new CalculatorBillingObserver(this);
|
||||||
billingObserver = new CalculatorBillingObserver(this);
|
BillingController.registerObserver(billingObserver);
|
||||||
BillingController.registerObserver(billingObserver);
|
|
||||||
|
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
firstTimeInit(preferences, this);
|
||||||
firstTimeInit(preferences, this);
|
|
||||||
|
// init billing controller
|
||||||
// init billing controller
|
BillingController.checkBillingSupported(this);
|
||||||
BillingController.checkBillingSupported(this);
|
|
||||||
|
toggleOrientationChange(preferences);
|
||||||
toggleOrientationChange(preferences);
|
|
||||||
|
CalculatorKeyboardFragment.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout));
|
||||||
CalculatorKeyboardFragment.toggleEqualsButton(preferences, this, theme, findViewById(R.id.main_layout));
|
|
||||||
|
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 synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
||||||
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
if (appOpenedCounter != null) {
|
||||||
|
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
||||||
setContentView(layout.getLayoutId());
|
}
|
||||||
}
|
|
||||||
|
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
||||||
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
|
||||||
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
||||||
if (appOpenedCounter != null) {
|
|
||||||
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
||||||
}
|
|
||||||
|
boolean dialogShown = false;
|
||||||
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
||||||
|
// new start
|
||||||
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
||||||
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
builder.setTitle(R.string.c_first_start_text_title);
|
||||||
|
builder.create().show();
|
||||||
boolean dialogShown = false;
|
dialogShown = true;
|
||||||
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
} else {
|
||||||
// new start
|
if (savedVersion < appVersion) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
if (showReleaseNotes) {
|
||||||
builder.setTitle(R.string.c_first_start_text_title);
|
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
|
||||||
builder.create().show();
|
if (!StringUtils.isEmpty(releaseNotes)) {
|
||||||
dialogShown = true;
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
||||||
} else {
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
if (savedVersion < appVersion) {
|
builder.setTitle(R.string.c_release_notes);
|
||||||
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
builder.create().show();
|
||||||
if (showReleaseNotes) {
|
dialogShown = true;
|
||||||
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
|
}
|
||||||
if (!StringUtils.isEmpty(releaseNotes)) {
|
}
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
}
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
}
|
||||||
builder.setTitle(R.string.c_release_notes);
|
|
||||||
builder.create().show();
|
|
||||||
dialogShown = true;
|
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
||||||
}
|
if (!dialogShown) {
|
||||||
}
|
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
||||||
}
|
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
if (!dialogShown) {
|
||||||
if (!dialogShown) {
|
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
|
||||||
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
}
|
||||||
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) {
|
||||||
|
boolean result = false;
|
||||||
if (!dialogShown) {
|
|
||||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
|
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
||||||
}
|
if ( specialWindowShown != null && !specialWindowShown ) {
|
||||||
}
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
|
final View view = layoutInflater.inflate(layoutId, null);
|
||||||
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
|
||||||
boolean result = false;
|
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
||||||
|
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
|
||||||
if ( specialWindowShown != null && !specialWindowShown ) {
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
final View view = layoutInflater.inflate(layoutId, null);
|
builder.create().show();
|
||||||
|
|
||||||
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
result = true;
|
||||||
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
specialWindowShownPref.putPreference(preferences, true);
|
||||||
|
}
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
return result;
|
||||||
builder.create().show();
|
}
|
||||||
|
|
||||||
result = true;
|
@Override
|
||||||
specialWindowShownPref.putPreference(preferences, true);
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
}
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
if (useBackAsPrev) {
|
||||||
return result;
|
getCalculator().doHistoryAction(HistoryAction.undo);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
return super.onKeyDown(keyCode, event);
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
}
|
||||||
if (useBackAsPrev) {
|
|
||||||
getCalculator().doHistoryAction(HistoryAction.undo);
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
return true;
|
public void equalsButtonClickHandler(@NotNull View v) {
|
||||||
}
|
getCalculator().evaluate();
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
/*
|
||||||
|
**********************************************************************
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
*
|
||||||
public void equalsButtonClickHandler(@NotNull View v) {
|
* MENU
|
||||||
getCalculator().evaluate();
|
*
|
||||||
}
|
**********************************************************************
|
||||||
|
*/
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
/* @Override
|
||||||
* MENU
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
*
|
return this.menu.onPrepareOptionsMenu(this, menu);
|
||||||
**********************************************************************
|
}
|
||||||
*/
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
@Override
|
return this.menu.onCreateOptionsMenu(this, menu);
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
}
|
||||||
return this.menu.onPrepareOptionsMenu(this, menu);
|
|
||||||
}
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
@Override
|
return menu.onOptionsItemSelected(this, item);
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
}*/
|
||||||
return this.menu.onCreateOptionsMenu(this, menu);
|
|
||||||
}
|
/**
|
||||||
|
* The font sizes in the layout files are specified for a HVGA display.
|
||||||
@Override
|
* Adjust the font sizes accordingly if we are running on a different
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
* display.
|
||||||
return menu.onOptionsItemSelected(this, item);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public void adjustFontSize(@NotNull TextView view) {
|
||||||
/**
|
float fontPixelSize = view.getTextSize();
|
||||||
* The font sizes in the layout files are specified for a HVGA display.
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
* Adjust the font sizes accordingly if we are running on a different
|
int h = Math.min(display.getWidth(), display.getHeight());
|
||||||
* display.
|
float ratio = (float) h / HVGA_WIDTH_PIXELS;
|
||||||
*/
|
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
||||||
@Override
|
}
|
||||||
public void adjustFontSize(@NotNull TextView view) {
|
|
||||||
float fontPixelSize = view.getTextSize();
|
@Override
|
||||||
Display display = getWindowManager().getDefaultDisplay();
|
protected void onResume() {
|
||||||
int h = Math.min(display.getWidth(), display.getHeight());
|
super.onResume();
|
||||||
float ratio = (float) h / HVGA_WIDTH_PIXELS;
|
|
||||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
}
|
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||||
|
if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
|
||||||
@Override
|
AndroidUtils.restartActivity(this);
|
||||||
protected void onResume() {
|
}
|
||||||
super.onResume();
|
|
||||||
|
this.activityHelper.onResume(this);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
}
|
||||||
|
|
||||||
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
@Override
|
||||||
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
protected void onDestroy() {
|
||||||
if (!theme.equals(newTheme) || !layout.equals(newLayout)) {
|
if (billingObserver != null) {
|
||||||
AndroidUtils.restartActivity(this);
|
BillingController.unregisterObserver(billingObserver);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
super.onDestroy();
|
||||||
@Override
|
}
|
||||||
protected void onDestroy() {
|
|
||||||
if (billingObserver != null) {
|
@Override
|
||||||
BillingController.unregisterObserver(billingObserver);
|
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
||||||
}
|
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
||||||
|
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
super.onDestroy();
|
}
|
||||||
}
|
|
||||||
|
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
||||||
@Override
|
toggleOrientationChange(preferences);
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
}
|
||||||
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
}
|
||||||
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
|
||||||
}
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
super.onSaveInstanceState(outState);
|
||||||
toggleOrientationChange(preferences);
|
|
||||||
}
|
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) {
|
||||||
CalculatorActivityLauncher.showHistory(this);
|
CalculatorActivityLauncher.showHistory(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void eraseButtonClickHandler(@NotNull View v) {
|
public void eraseButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().erase();
|
CalculatorLocatorImpl.getInstance().getEditor().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 moveLeftButtonClickHandler(@NotNull View v) {
|
public void moveLeftButtonClickHandler(@NotNull View v) {
|
||||||
getKeyboard().moveCursorLeft();
|
getKeyboard().moveCursorLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void moveRightButtonClickHandler(@NotNull View v) {
|
public void moveRightButtonClickHandler(@NotNull View v) {
|
||||||
getKeyboard().moveCursorRight();
|
getKeyboard().moveCursorRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void pasteButtonClickHandler(@NotNull View v) {
|
public void pasteButtonClickHandler(@NotNull View v) {
|
||||||
getKeyboard().pasteButtonPressed();
|
getKeyboard().pasteButtonPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void copyButtonClickHandler(@NotNull View v) {
|
public void copyButtonClickHandler(@NotNull View v) {
|
||||||
getKeyboard().copyButtonPressed();
|
getKeyboard().copyButtonPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
getKeyboard().clearButtonPressed();
|
getKeyboard().clearButtonPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 (((ColorButton) v).isShowText()) {
|
if (((ColorButton) v).isShowText()) {
|
||||||
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
|
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void functionsButtonClickHandler(@NotNull View v) {
|
public void functionsButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorActivityLauncher.showFunctions(this);
|
CalculatorActivityLauncher.showFunctions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void operatorsButtonClickHandler(@NotNull View v) {
|
public void operatorsButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorActivityLauncher.showOperators(this);
|
CalculatorActivityLauncher.showOperators(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
|
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
|
||||||
CalculatorActivityLauncher.showOperators(activity);
|
CalculatorActivityLauncher.showOperators(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void varsButtonClickHandler(@NotNull View v) {
|
public void varsButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorActivityLauncher.showVars(this);
|
CalculatorActivityLauncher.showVars(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void donateButtonClickHandler(@NotNull View v) {
|
public void donateButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorApplication.showDonationDialog(this);
|
CalculatorApplication.showDonationDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,19 +1,39 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.app.Activity;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import android.os.Bundle;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import android.support.v4.app.Fragment;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
/**
|
import org.jetbrains.annotations.NotNull;
|
||||||
* User: serso
|
import org.jetbrains.annotations.Nullable;
|
||||||
* Date: 9/25/12
|
|
||||||
* Time: 10:31 PM
|
/**
|
||||||
*/
|
* User: serso
|
||||||
public interface CalculatorActivityHelper {
|
* Date: 9/25/12
|
||||||
|
* Time: 10:31 PM
|
||||||
void onCreate(@NotNull SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState);
|
*/
|
||||||
|
public interface CalculatorActivityHelper {
|
||||||
void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState);
|
|
||||||
|
void onCreate(@NotNull SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState);
|
||||||
}
|
void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState);
|
||||||
|
|
||||||
|
void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState);
|
||||||
|
void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState);
|
||||||
|
|
||||||
|
int getLayoutId();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
CalculatorPreferences.Gui.Theme getTheme();
|
||||||
|
|
||||||
|
void onResume(@NotNull SherlockFragmentActivity activity);
|
||||||
|
void onResume(@NotNull Activity activity);
|
||||||
|
|
||||||
|
void addTab(@NotNull SherlockFragmentActivity activity,
|
||||||
|
@NotNull String tag,
|
||||||
|
@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
|
@Nullable Bundle fragmentArgs,
|
||||||
|
int captionResId, int parentViewId);
|
||||||
|
|
||||||
|
void restoreSavedTab(@NotNull SherlockFragmentActivity activity);
|
||||||
|
}
|
||||||
|
@ -1,121 +1,152 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v4.app.Fragment;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.preference.PreferenceManager;
|
||||||
import com.actionbarsherlock.app.ActionBar;
|
import android.support.v4.app.Fragment;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.ActionBar;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
import org.solovyev.android.AndroidUtils;
|
||||||
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
/**
|
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||||
* User: serso
|
|
||||||
* Date: 9/25/12
|
import java.util.ArrayList;
|
||||||
* Time: 10:32 PM
|
import java.util.List;
|
||||||
*/
|
|
||||||
public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
/**
|
||||||
|
* User: serso
|
||||||
/*
|
* Date: 9/25/12
|
||||||
**********************************************************************
|
* Time: 10:32 PM
|
||||||
*
|
*/
|
||||||
* CONSTANTS
|
public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||||
*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*/
|
**********************************************************************
|
||||||
private static final String SELECTED_NAV = "selected_nav";
|
*
|
||||||
|
* CONSTANTS
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
* FIELDS
|
private static final String SELECTED_NAV = "selected_nav";
|
||||||
*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*
|
||||||
private int layoutId;
|
* FIELDS
|
||||||
|
*
|
||||||
private boolean showActionBarTabs = true;
|
**********************************************************************
|
||||||
|
*/
|
||||||
private boolean homeIcon = false;
|
|
||||||
|
private int layoutId;
|
||||||
public CalculatorActivityHelperImpl(int layoutId) {
|
|
||||||
this.layoutId = layoutId;
|
private boolean homeIcon = false;
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
public CalculatorActivityHelperImpl(int layoutId, boolean showActionBarTabs, boolean homeIcon) {
|
private final List<String> fragmentTags = new ArrayList<String>();
|
||||||
this.layoutId = layoutId;
|
|
||||||
this.showActionBarTabs = showActionBarTabs;
|
@NotNull
|
||||||
this.homeIcon = homeIcon;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
}
|
private int navPosition = 0;
|
||||||
|
|
||||||
@Override
|
public CalculatorActivityHelperImpl(int layoutId) {
|
||||||
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
|
this.layoutId = layoutId;
|
||||||
activity.setContentView(layoutId);
|
}
|
||||||
|
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
|
||||||
actionBar.setDisplayUseLogoEnabled(false);
|
this.layoutId = layoutId;
|
||||||
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
|
this.homeIcon = homeIcon;
|
||||||
actionBar.setDisplayShowHomeEnabled(true);
|
}
|
||||||
actionBar.setDisplayShowTitleEnabled(true);
|
|
||||||
|
@Override
|
||||||
if (showActionBarTabs) {
|
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
|
||||||
addTab(activity, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.drawable.icon);
|
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||||
//addTab(activity, "messages", MessengerChatsFragment.class, null, R.string.c_messages, R.drawable.msg_footer_messages_icon);
|
activity.setTheme(this.theme.getThemeId());
|
||||||
|
|
||||||
// settings tab
|
activity.setContentView(layoutId);
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
}
|
||||||
tab.setTag("settings");
|
|
||||||
tab.setText(R.string.c_settings);
|
@Override
|
||||||
//tab.setIcon(R.drawable.msg_footer_settings_icon);
|
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
|
||||||
tab.setTabListener(new ActionBar.TabListener() {
|
this.onCreate((Activity) activity, savedInstanceState);
|
||||||
@Override
|
|
||||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
activity.startActivity(new Intent(activity.getApplicationContext(), CalculatorPreferencesActivity.class));
|
actionBar.setDisplayUseLogoEnabled(false);
|
||||||
}
|
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
|
||||||
|
actionBar.setDisplayShowHomeEnabled(true);
|
||||||
@Override
|
actionBar.setDisplayShowTitleEnabled(true);
|
||||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
|
||||||
}
|
if (savedInstanceState != null) {
|
||||||
|
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
|
||||||
@Override
|
}
|
||||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
}
|
||||||
}
|
|
||||||
});
|
@Override
|
||||||
actionBar.addTab(tab);
|
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
||||||
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
int navPosition = -1;
|
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
|
||||||
if (savedInstanceState != null) {
|
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
|
||||||
navPosition = savedInstanceState.getInt(SELECTED_NAV, -1);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (navPosition >= 0) {
|
@Override
|
||||||
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
|
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
||||||
}
|
FragmentUtils.detachFragments(activity, fragmentTags);
|
||||||
}
|
|
||||||
}
|
onSaveInstanceState((Activity) activity, outState);
|
||||||
|
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
||||||
@Override
|
}
|
||||||
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
|
||||||
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
@Override
|
||||||
}
|
public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
|
||||||
|
}
|
||||||
private void addTab(@NotNull SherlockFragmentActivity activity,
|
|
||||||
@NotNull String tag,
|
@Override
|
||||||
@NotNull Class<? extends Fragment> fragmentClass,
|
public void onResume(@NotNull Activity activity) {
|
||||||
@Nullable Bundle fragmentArgs,
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
int captionResId,
|
|
||||||
int iconResId) {
|
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
if (!theme.equals(newTheme)) {
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
AndroidUtils.restartActivity(activity);
|
||||||
tab.setTag(tag);
|
}
|
||||||
tab.setText(captionResId);
|
}
|
||||||
//tab.setIcon(iconResId);
|
|
||||||
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, R.id.content_second_pane));
|
@Override
|
||||||
actionBar.addTab(tab);
|
public void addTab(@NotNull SherlockFragmentActivity activity,
|
||||||
}
|
@NotNull String tag,
|
||||||
}
|
@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
|
@Nullable Bundle fragmentArgs,
|
||||||
|
int captionResId,
|
||||||
|
int parentViewId) {
|
||||||
|
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
|
|
||||||
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
|
final ActionBar.Tab tab = actionBar.newTab();
|
||||||
|
tab.setTag(tag);
|
||||||
|
tab.setText(captionResId);
|
||||||
|
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
|
||||||
|
actionBar.addTab(tab);
|
||||||
|
|
||||||
|
fragmentTags.add(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutId() {
|
||||||
|
return layoutId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public CalculatorPreferences.Gui.Theme getTheme() {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
||||||
|
onResume((Activity) activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,34 +1,33 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
/**
|
|
||||||
* User: Solovyev_S
|
/**
|
||||||
* Date: 25.09.12
|
* User: Solovyev_S
|
||||||
* Time: 12:03
|
* Date: 25.09.12
|
||||||
*/
|
* Time: 12:03
|
||||||
public class CalculatorDisplayFragment extends Fragment {
|
*/
|
||||||
|
public class CalculatorDisplayFragment extends SherlockFragment {
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
@Override
|
||||||
final View view = inflater.inflate(R.layout.calc_display, null);
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
return inflater.inflate(R.layout.calc_display, container, false);
|
||||||
return view;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
super.onViewCreated(view, savedInstanceState);
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
|
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setDisplay(getActivity());
|
||||||
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setDisplay(getActivity());
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
super.onActivityCreated(savedInstanceState);
|
||||||
super.onActivityCreated(savedInstanceState);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,32 +1,64 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.view.LayoutInflater;
|
||||||
import android.view.LayoutInflater;
|
import android.view.View;
|
||||||
import android.view.View;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
/**
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
* User: Solovyev_S
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
* Date: 25.09.12
|
import org.jetbrains.annotations.NotNull;
|
||||||
* Time: 10:49
|
import org.solovyev.android.menu.ActivityMenu;
|
||||||
*/
|
import org.solovyev.android.menu.ListActivityMenu;
|
||||||
public class CalculatorEditorFragment extends Fragment {
|
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
* User: Solovyev_S
|
||||||
return inflater.inflate(R.layout.calc_editor, null);
|
* Date: 25.09.12
|
||||||
}
|
* Time: 10:49
|
||||||
|
*/
|
||||||
@Override
|
public class CalculatorEditorFragment extends SherlockFragment {
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
@NotNull
|
||||||
|
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, SherlockMenuHelper.getInstance());
|
||||||
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setEditor(getActivity());
|
|
||||||
}
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@Override
|
super.onCreate(savedInstanceState);
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
return inflater.inflate(R.layout.calc_editor, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setEditor(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
this.menu.onCreateOptionsMenu(this.getActivity(), menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrepareOptionsMenu(Menu menu) {
|
||||||
|
this.menu.onPrepareOptionsMenu(this.getActivity(), menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
return this.menu.onOptionsItemSelected(this.getActivity(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,493 +1,492 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import jscl.AngleUnit;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
import jscl.NumeralBase;
|
import jscl.AngleUnit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import jscl.NumeralBase;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||||
import org.solovyev.android.calculator.view.OnDragListenerVibrator;
|
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||||
import org.solovyev.android.history.HistoryDragProcessor;
|
import org.solovyev.android.calculator.view.OnDragListenerVibrator;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.history.HistoryDragProcessor;
|
||||||
import org.solovyev.android.view.drag.*;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.common.Announcer;
|
import org.solovyev.android.view.drag.*;
|
||||||
import org.solovyev.common.math.Point2d;
|
import org.solovyev.common.Announcer;
|
||||||
|
import org.solovyev.common.math.Point2d;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: Solovyev_S
|
/**
|
||||||
* Date: 25.09.12
|
* User: Solovyev_S
|
||||||
* Time: 12:25
|
* Date: 25.09.12
|
||||||
*/
|
* Time: 12:25
|
||||||
public class CalculatorKeyboardFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
*/
|
||||||
|
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
@Nullable
|
|
||||||
private Vibrator vibrator;
|
@Nullable
|
||||||
|
private Vibrator vibrator;
|
||||||
@NotNull
|
|
||||||
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
@NotNull
|
||||||
|
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
||||||
@NotNull
|
|
||||||
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
@NotNull
|
||||||
|
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
||||||
@NotNull
|
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
@NotNull
|
||||||
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
@NotNull
|
|
||||||
private CalculatorPreferences.Gui.Layout layout;
|
@NotNull
|
||||||
|
private CalculatorPreferences.Gui.Layout layout;
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
@Override
|
||||||
super.onCreate(savedInstanceState);
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
vibrator = (Vibrator) this.getActivity().getSystemService(Activity.VIBRATOR_SERVICE);
|
|
||||||
|
vibrator = (Vibrator) this.getActivity().getSystemService(Activity.VIBRATOR_SERVICE);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
|
||||||
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
|
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
|
||||||
}
|
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
@Override
|
||||||
final View view = inflater.inflate(R.layout.calc_keyboard, null);
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
return inflater.inflate(R.layout.calc_keyboard, container, false);
|
||||||
return view;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
super.onViewCreated(root, savedInstanceState);
|
||||||
super.onViewCreated(root, savedInstanceState);
|
|
||||||
|
dpclRegister.clear();
|
||||||
dpclRegister.clear();
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, this.getActivity());
|
||||||
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, this.getActivity());
|
|
||||||
|
setOnDragListeners(root, dragPreferences, preferences);
|
||||||
setOnDragListeners(root, dragPreferences, preferences);
|
|
||||||
|
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
|
||||||
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
|
final DragButton historyButton = getButton(root, R.id.historyButton);
|
||||||
final DragButton historyButton = getButton(root, R.id.historyButton);
|
if (historyButton != null) {
|
||||||
if (historyButton != null) {
|
historyButton.setOnDragListener(historyOnDragListener);
|
||||||
historyButton.setOnDragListener(historyOnDragListener);
|
}
|
||||||
}
|
|
||||||
|
final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
|
||||||
final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
|
if (subtractionButton != null) {
|
||||||
if (subtractionButton != null) {
|
subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
|
||||||
subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
|
@Override
|
||||||
@Override
|
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
if (dragDirection == DragDirection.down) {
|
||||||
if (dragDirection == DragDirection.down) {
|
CalculatorActivity.operatorsButtonClickHandler(getActivity());
|
||||||
CalculatorActivity.operatorsButtonClickHandler(getActivity());
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}, dragPreferences), vibrator, preferences));
|
||||||
}, dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
|
||||||
final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
|
|
||||||
|
final DragButton rightButton = getButton(root, R.id.rightButton);
|
||||||
final DragButton rightButton = getButton(root, R.id.rightButton);
|
if (rightButton != null) {
|
||||||
if (rightButton != null) {
|
rightButton.setOnDragListener(toPositionOnDragListener);
|
||||||
rightButton.setOnDragListener(toPositionOnDragListener);
|
}
|
||||||
}
|
|
||||||
|
final DragButton leftButton = getButton(root, R.id.leftButton);
|
||||||
final DragButton leftButton = getButton(root, R.id.leftButton);
|
if (leftButton != null) {
|
||||||
if (leftButton != null) {
|
leftButton.setOnDragListener(toPositionOnDragListener);
|
||||||
leftButton.setOnDragListener(toPositionOnDragListener);
|
}
|
||||||
}
|
|
||||||
|
final DragButton equalsButton = getButton(root, R.id.equalsButton);
|
||||||
final DragButton equalsButton = getButton(root, R.id.equalsButton);
|
if (equalsButton != null) {
|
||||||
if (equalsButton != null) {
|
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
|
||||||
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
|
||||||
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
|
if (angleUnitsButton != null) {
|
||||||
if (angleUnitsButton != null) {
|
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(this.getActivity()), dragPreferences), vibrator, preferences));
|
||||||
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(this.getActivity()), dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
|
||||||
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
|
if (clearButton != null) {
|
||||||
if (clearButton != null) {
|
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences));
|
||||||
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
final DragButton varsButton = getButton(root, R.id.varsButton);
|
||||||
final DragButton varsButton = getButton(root, R.id.varsButton);
|
if (varsButton != null) {
|
||||||
if (varsButton != null) {
|
varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(this.getActivity()), dragPreferences), vibrator, preferences));
|
||||||
varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(this.getActivity()), dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
|
||||||
final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
|
if (roundBracketsButton != null) {
|
||||||
if (roundBracketsButton != null) {
|
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
|
||||||
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
|
}
|
||||||
}
|
|
||||||
|
if (layout == CalculatorPreferences.Gui.Layout.simple) {
|
||||||
if (layout == CalculatorPreferences.Gui.Layout.simple) {
|
toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
|
toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
|
toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
|
|
||||||
|
toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
|
toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
|
||||||
|
toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
|
||||||
|
toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
|
toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
|
||||||
toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
|
|
||||||
|
toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
|
||||||
toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
|
|
||||||
|
toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
|
||||||
toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
|
toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
|
||||||
toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
|
}
|
||||||
}
|
|
||||||
|
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||||
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
|
||||||
|
fixThemeParameters(true, theme, this.getView());
|
||||||
fixThemeParameters(true, theme, this.getView());
|
|
||||||
|
toggleEqualsButton(preferences, this.getActivity(), theme, root);
|
||||||
toggleEqualsButton(preferences, this.getActivity(), theme, root);
|
|
||||||
|
initMultiplicationButton();
|
||||||
initMultiplicationButton();
|
}
|
||||||
}
|
|
||||||
|
@Nullable
|
||||||
@Nullable
|
private <T extends DragButton> T getButton(@NotNull View root, int buttonId) {
|
||||||
private <T extends DragButton> T getButton(@NotNull View root, int buttonId) {
|
return (T) root.findViewById(buttonId);
|
||||||
return (T) root.findViewById(buttonId);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onDestroy() {
|
||||||
public void onDestroy() {
|
super.onDestroy();
|
||||||
super.onDestroy();
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
|
||||||
|
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
}
|
||||||
}
|
|
||||||
|
public static void fixThemeParameters(boolean fixMagicFlames,
|
||||||
public static void fixThemeParameters(boolean fixMagicFlames,
|
@NotNull CalculatorPreferences.Gui.Theme theme,
|
||||||
@NotNull CalculatorPreferences.Gui.Theme theme,
|
@NotNull View root) {
|
||||||
@NotNull View root) {
|
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
||||||
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
|
||||||
|
if (fixMagicFlames) {
|
||||||
if (fixMagicFlames) {
|
// for metro themes we should turn off magic flames
|
||||||
// for metro themes we should turn off magic flames
|
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
||||||
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
@Override
|
||||||
@Override
|
public void process(@NotNull ColorButton colorButton) {
|
||||||
public void process(@NotNull ColorButton colorButton) {
|
colorButton.setDrawMagicFlame(false);
|
||||||
colorButton.setDrawMagicFlame(false);
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void initMultiplicationButton() {
|
||||||
private void initMultiplicationButton() {
|
final View multiplicationButton = getView().findViewById(R.id.multiplicationButton);
|
||||||
final View multiplicationButton = getView().findViewById(R.id.multiplicationButton);
|
if ( multiplicationButton instanceof Button) {
|
||||||
if ( multiplicationButton instanceof Button) {
|
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
||||||
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
|
||||||
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
|
// IMPORTANT: this is workaround for probably android bug
|
||||||
// IMPORTANT: this is workaround for probably android bug
|
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
||||||
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
|
||||||
|
if (view != null) {
|
||||||
if (view != null) {
|
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
||||||
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||||
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
||||||
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
||||||
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
view.setLayoutParams(newParams);
|
||||||
view.setLayoutParams(newParams);
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}*/
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
super.onActivityCreated(savedInstanceState);
|
||||||
super.onActivityCreated(savedInstanceState);
|
}
|
||||||
}
|
|
||||||
|
private synchronized void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
|
||||||
private synchronized void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
|
final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
|
||||||
final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
|
|
||||||
|
final List<Integer> dragButtonIds = new ArrayList<Integer>();
|
||||||
final List<Integer> dragButtonIds = new ArrayList<Integer>();
|
final List<Integer> buttonIds = new ArrayList<Integer>();
|
||||||
final List<Integer> buttonIds = new ArrayList<Integer>();
|
|
||||||
|
for (Field field : R.id.class.getDeclaredFields()) {
|
||||||
for (Field field : R.id.class.getDeclaredFields()) {
|
int modifiers = field.getModifiers();
|
||||||
int modifiers = field.getModifiers();
|
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
||||||
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
try {
|
||||||
try {
|
int viewId = field.getInt(R.id.class);
|
||||||
int viewId = field.getInt(R.id.class);
|
final View view = root.findViewById(viewId);
|
||||||
final View view = root.findViewById(viewId);
|
if (view instanceof DragButton) {
|
||||||
if (view instanceof DragButton) {
|
dragButtonIds.add(viewId);
|
||||||
dragButtonIds.add(viewId);
|
}
|
||||||
}
|
if (view instanceof Button) {
|
||||||
if (view instanceof Button) {
|
buttonIds.add(viewId);
|
||||||
buttonIds.add(viewId);
|
}
|
||||||
}
|
} catch (IllegalAccessException e) {
|
||||||
} catch (IllegalAccessException e) {
|
Log.e(R.id.class.getName(), e.getMessage());
|
||||||
Log.e(R.id.class.getName(), e.getMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
for (Integer dragButtonId : dragButtonIds) {
|
||||||
for (Integer dragButtonId : dragButtonIds) {
|
final DragButton button = getButton(root, dragButtonId);
|
||||||
final DragButton button = getButton(root, dragButtonId);
|
if (button != null) {
|
||||||
if (button != null) {
|
button.setOnDragListener(onDragListener);
|
||||||
button.setOnDragListener(onDragListener);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
|
||||||
private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
|
@NotNull SimpleOnDragListener.Preferences dragPreferences) {
|
||||||
@NotNull SimpleOnDragListener.Preferences dragPreferences) {
|
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
|
||||||
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
|
dpclRegister.addListener(onDragListener);
|
||||||
dpclRegister.addListener(onDragListener);
|
return onDragListener;
|
||||||
return onDragListener;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
||||||
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this.getActivity()));
|
||||||
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this.getActivity()));
|
}
|
||||||
}
|
|
||||||
|
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
||||||
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||||
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
}
|
||||||
}
|
|
||||||
|
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
||||||
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
toggleEqualsButton(preferences, this.getActivity(), theme, getView());
|
||||||
toggleEqualsButton(preferences, this.getActivity(), theme, getView());
|
}
|
||||||
}
|
|
||||||
|
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
||||||
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
initMultiplicationButton();
|
||||||
initMultiplicationButton();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
|
||||||
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
|
final View v = getButton(root, id);
|
||||||
final View v = getButton(root, id);
|
if (v instanceof DirectionDragButton ) {
|
||||||
if (v instanceof DirectionDragButton ) {
|
final DirectionDragButton button = (DirectionDragButton)v;
|
||||||
final DirectionDragButton button = (DirectionDragButton)v;
|
for (DragDirection dragDirection : dragDirections) {
|
||||||
for (DragDirection dragDirection : dragDirections) {
|
button.showDirectionText(showDirectionText, dragDirection);
|
||||||
button.showDirectionText(showDirectionText, dragDirection);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
|
||||||
public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
|
@NotNull Activity activity,
|
||||||
@NotNull Activity activity,
|
@NotNull CalculatorPreferences.Gui.Theme theme,
|
||||||
@NotNull CalculatorPreferences.Gui.Theme theme,
|
@NotNull View root) {
|
||||||
@NotNull View root) {
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
|
||||||
|
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||||
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
final Display display = activity.getWindowManager().getDefaultDisplay();
|
||||||
final Display display = activity.getWindowManager().getDefaultDisplay();
|
|
||||||
|
final DragButton button = (DragButton)activity.findViewById(R.id.equalsButton);
|
||||||
final DragButton button = (DragButton)activity.findViewById(R.id.equalsButton);
|
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||||
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
|
||||||
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
|
if (display.getWidth() <= 480) {
|
||||||
if (display.getWidth() <= 480) {
|
// mobile phones
|
||||||
// mobile phones
|
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
||||||
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
if (calculatorDisplayView != null) {
|
||||||
if (calculatorDisplayView != null) {
|
calculatorDisplayView.setBackgroundDrawable(null);
|
||||||
calculatorDisplayView.setBackgroundDrawable(null);
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
|
||||||
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
|
if (display.getWidth() <= 480) {
|
||||||
if (display.getWidth() <= 480) {
|
// mobile phones
|
||||||
// mobile phones
|
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
||||||
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
if (calculatorDisplayView != null) {
|
||||||
if (calculatorDisplayView != null) {
|
calculatorDisplayView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.equals9));
|
||||||
calculatorDisplayView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.equals9));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fixThemeParameters(false, theme, root);
|
||||||
fixThemeParameters(false, theme, root);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Nullable
|
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
||||||
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
||||||
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
}
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private Calculator getCalculator() {
|
||||||
private Calculator getCalculator() {
|
return CalculatorLocatorImpl.getInstance().getCalculator();
|
||||||
return CalculatorLocatorImpl.getInstance().getCalculator();
|
}
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private static CalculatorKeyboard getKeyboard() {
|
||||||
private static CalculatorKeyboard getKeyboard() {
|
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
}
|
||||||
}
|
|
||||||
|
/*
|
||||||
/*
|
**********************************************************************
|
||||||
**********************************************************************
|
*
|
||||||
*
|
* STATIC CLASSES
|
||||||
* STATIC CLASSES
|
*
|
||||||
*
|
**********************************************************************
|
||||||
**********************************************************************
|
*/
|
||||||
*/
|
|
||||||
|
private static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||||
private static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
@Override
|
||||||
@Override
|
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
final boolean result;
|
||||||
final boolean result;
|
|
||||||
|
if (dragDirection == DragDirection.left) {
|
||||||
if (dragDirection == DragDirection.left) {
|
getKeyboard().roundBracketsButtonPressed();
|
||||||
getKeyboard().roundBracketsButtonPressed();
|
result = true;
|
||||||
result = true;
|
} else {
|
||||||
} else {
|
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||||
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||||
private static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private Context context;
|
||||||
private Context context;
|
|
||||||
|
private VarsDragProcessor(Context context) {
|
||||||
private VarsDragProcessor(Context context) {
|
this.context = context;
|
||||||
this.context = context;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
@NotNull DragButton dragButton,
|
||||||
@NotNull DragButton dragButton,
|
@NotNull Point2d startPoint2d,
|
||||||
@NotNull Point2d startPoint2d,
|
@NotNull MotionEvent motionEvent) {
|
||||||
@NotNull MotionEvent motionEvent) {
|
boolean result = false;
|
||||||
boolean result = false;
|
|
||||||
|
if (dragDirection == DragDirection.up) {
|
||||||
if (dragDirection == DragDirection.up) {
|
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
|
||||||
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
|
result = true;
|
||||||
result = true;
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
||||||
private static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private final DigitButtonDragProcessor processor;
|
||||||
private final DigitButtonDragProcessor processor;
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private final Context context;
|
||||||
private final Context context;
|
|
||||||
|
private AngleUnitsChanger(@NotNull Context context) {
|
||||||
private AngleUnitsChanger(@NotNull Context context) {
|
this.context = context;
|
||||||
this.context = context;
|
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
|
||||||
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
@NotNull DragButton dragButton,
|
||||||
@NotNull DragButton dragButton,
|
@NotNull Point2d startPoint2d,
|
||||||
@NotNull Point2d startPoint2d,
|
@NotNull MotionEvent motionEvent) {
|
||||||
@NotNull MotionEvent motionEvent) {
|
boolean result = false;
|
||||||
boolean result = false;
|
|
||||||
|
if (dragButton instanceof AngleUnitsButton) {
|
||||||
if (dragButton instanceof AngleUnitsButton) {
|
if (dragDirection != DragDirection.left) {
|
||||||
if (dragDirection != DragDirection.left) {
|
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
|
||||||
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
|
if (directionText != null) {
|
||||||
if (directionText != null) {
|
try {
|
||||||
try {
|
|
||||||
|
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
|
||||||
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
|
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
|
||||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
|
|
||||||
|
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
|
|
||||||
|
result = true;
|
||||||
result = true;
|
} catch (IllegalArgumentException e) {
|
||||||
} catch (IllegalArgumentException e) {
|
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
|
||||||
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (dragDirection == DragDirection.left) {
|
||||||
} else if (dragDirection == DragDirection.left) {
|
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||||
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
|
||||||
private static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private final Context context;
|
||||||
private final Context context;
|
|
||||||
|
private NumeralBasesChanger(@NotNull Context context) {
|
||||||
private NumeralBasesChanger(@NotNull Context context) {
|
this.context = context;
|
||||||
this.context = context;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
@NotNull DragButton dragButton,
|
||||||
@NotNull DragButton dragButton,
|
@NotNull Point2d startPoint2d,
|
||||||
@NotNull Point2d startPoint2d,
|
@NotNull MotionEvent motionEvent) {
|
||||||
@NotNull MotionEvent motionEvent) {
|
boolean result = false;
|
||||||
boolean result = false;
|
|
||||||
|
if (dragButton instanceof NumeralBasesButton) {
|
||||||
if (dragButton instanceof NumeralBasesButton) {
|
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
|
||||||
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
|
if (directionText != null) {
|
||||||
if (directionText != null) {
|
try {
|
||||||
try {
|
|
||||||
|
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
|
||||||
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
|
||||||
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
|
|
||||||
|
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
|
|
||||||
|
result = true;
|
||||||
result = true;
|
} catch (IllegalArgumentException e) {
|
||||||
} catch (IllegalArgumentException e) {
|
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
|
||||||
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,75 +1,75 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 4/23/12
|
* Date: 4/23/12
|
||||||
* Time: 2:25 PM
|
* Time: 2:25 PM
|
||||||
*/
|
*/
|
||||||
enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
|
enum CalculatorMenu implements LabeledMenuItem<MenuItem> {
|
||||||
|
|
||||||
settings(R.string.c_settings) {
|
settings(R.string.c_settings) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showSettings(context);
|
CalculatorActivityLauncher.showSettings(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
history(R.string.c_history) {
|
history(R.string.c_history) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showHistory(context);
|
CalculatorActivityLauncher.showHistory(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
about(R.string.c_about) {
|
about(R.string.c_about) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showAbout(context);
|
CalculatorActivityLauncher.showAbout(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
help(R.string.c_help) {
|
help(R.string.c_help) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
CalculatorActivityLauncher.showHelp(context);
|
CalculatorActivityLauncher.showHelp(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
conversion_tool(R.string.c_conversion_tool) {
|
conversion_tool(R.string.c_conversion_tool) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
new NumeralBaseConverterDialog(null).show(context);
|
new NumeralBaseConverterDialog(null).show(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
exit(R.string.c_exit) {
|
exit(R.string.c_exit) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
((Activity) context).finish();
|
((Activity) context).finish();
|
||||||
} else {
|
} else {
|
||||||
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
Log.e(CalculatorActivity.TAG, "Activity menu used with context");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int captionResId;
|
private final int captionResId;
|
||||||
|
|
||||||
private CalculatorMenu(int captionResId) {
|
private CalculatorMenu(int captionResId) {
|
||||||
this.captionResId = captionResId;
|
this.captionResId = captionResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCaption(@NotNull Context context) {
|
public String getCaption(@NotNull Context context) {
|
||||||
return context.getString(captionResId);
|
return context.getString(captionResId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,262 +1,285 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.content.Context;
|
||||||
import android.content.Context;
|
import android.os.Bundle;
|
||||||
import android.os.Bundle;
|
import android.view.LayoutInflater;
|
||||||
import android.view.LayoutInflater;
|
import android.view.View;
|
||||||
import android.view.View;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ListView;
|
||||||
import android.widget.ListView;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.google.ads.AdView;
|
||||||
import com.google.ads.AdView;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.solovyev.android.ads.AdsController;
|
||||||
import org.solovyev.android.ads.AdsController;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.menu.MenuImpl;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.common.equals.Equalizer;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.filter.Filter;
|
||||||
import org.solovyev.common.equals.Equalizer;
|
import org.solovyev.common.filter.FilterRule;
|
||||||
import org.solovyev.common.filter.Filter;
|
import org.solovyev.common.filter.FilterRulesChain;
|
||||||
import org.solovyev.common.filter.FilterRule;
|
import org.solovyev.common.text.StringUtils;
|
||||||
import org.solovyev.common.filter.FilterRulesChain;
|
|
||||||
import org.solovyev.common.text.StringUtils;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.ArrayList;
|
import java.util.Comparator;
|
||||||
import java.util.Collections;
|
import java.util.List;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
/**
|
||||||
|
* User: serso
|
||||||
/**
|
* Date: 10/15/11
|
||||||
* User: serso
|
* Time: 1:13 PM
|
||||||
* Date: 10/15/11
|
*/
|
||||||
* Time: 1:13 PM
|
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||||
*/
|
|
||||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment {
|
|
||||||
|
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||||
|
@Override
|
||||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||||
@Override
|
if (state1.isSaved() == state2.isSaved()) {
|
||||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
long l = state2.getTime() - state1.getTime();
|
||||||
if (state1.isSaved() == state2.isSaved()) {
|
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
||||||
long l = state2.getTime() - state1.getTime();
|
} else if (state1.isSaved()) {
|
||||||
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
return -1;
|
||||||
} else if (state1.isSaved()) {
|
} else if (state2.isSaved()) {
|
||||||
return -1;
|
return 1;
|
||||||
} else if (state2.isSaved()) {
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@NotNull
|
||||||
|
private ArrayAdapter<CalculatorHistoryState> adapter;
|
||||||
@NotNull
|
|
||||||
private ArrayAdapter<CalculatorHistoryState> adapter;
|
@Nullable
|
||||||
|
private AdView adView;
|
||||||
@Nullable
|
|
||||||
private AdView adView;
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@Override
|
super.onCreate(savedInstanceState);
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
}
|
||||||
return inflater.inflate(R.layout.history_activity, null);
|
|
||||||
}
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@Override
|
return inflater.inflate(R.layout.history_fragment, container, false);
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
}
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
|
@Override
|
||||||
adView = AdsController.getInstance().inflateAd(this.getActivity());
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
adapter = new HistoryArrayAdapter(this.getActivity(), getLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
|
||||||
setListAdapter(adapter);
|
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||||
|
setListAdapter(adapter);
|
||||||
final ListView lv = getListView();
|
|
||||||
lv.setTextFilterEnabled(true);
|
final ListView lv = getListView();
|
||||||
|
lv.setTextFilterEnabled(true);
|
||||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
public void onItemClick(final AdapterView<?> parent,
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
final View view,
|
public void onItemClick(final AdapterView<?> parent,
|
||||||
final int position,
|
final View view,
|
||||||
final long id) {
|
final int position,
|
||||||
|
final long id) {
|
||||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), getActivity());
|
|
||||||
}
|
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
||||||
});
|
}
|
||||||
|
});
|
||||||
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
||||||
@Override
|
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
@Override
|
||||||
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
|
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
||||||
final Context context = getActivity();
|
|
||||||
|
final Context context = getActivity();
|
||||||
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
|
||||||
|
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
||||||
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
|
||||||
|
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
||||||
if (historyState.isSaved()) {
|
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
if (historyState.isSaved()) {
|
||||||
} else {
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
if (isAlreadySaved(historyState)) {
|
} else {
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
if (isAlreadySaved(historyState)) {
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
menuItems.remove(HistoryItemMenuItem.remove);
|
}
|
||||||
menuItems.remove(HistoryItemMenuItem.edit);
|
menuItems.remove(HistoryItemMenuItem.remove);
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.edit);
|
||||||
|
}
|
||||||
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
|
||||||
menuItems.remove(HistoryItemMenuItem.copy_result);
|
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.copy_result);
|
||||||
|
}
|
||||||
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
|
||||||
menuBuilder.create(data).show();
|
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
||||||
|
menuBuilder.create(data).show();
|
||||||
return true;
|
|
||||||
}
|
return true;
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
@Override
|
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
}
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
@Override
|
if ( this.adView != null ) {
|
||||||
public void onDestroy() {
|
this.adView.destroy();
|
||||||
if ( this.adView != null ) {
|
}
|
||||||
this.adView.destroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
|
||||||
}
|
protected abstract int getItemLayoutId();
|
||||||
|
|
||||||
protected abstract int getLayoutId();
|
@Override
|
||||||
|
public void onResume() {
|
||||||
@Override
|
super.onResume();
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
|
|
||||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
updateAdapter();
|
||||||
try {
|
}
|
||||||
this.adapter.setNotifyOnChange(false);
|
|
||||||
this.adapter.clear();
|
@Override
|
||||||
for (CalculatorHistoryState historyState : historyList) {
|
public void onPause() {
|
||||||
this.adapter.add(historyState);
|
super.onPause();
|
||||||
}
|
|
||||||
} finally {
|
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||||
this.adapter.setNotifyOnChange(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.adapter.notifyDataSetChanged();
|
private void updateAdapter() {
|
||||||
}
|
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||||
|
|
||||||
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
||||||
assert !historyState.isSaved();
|
try {
|
||||||
|
adapter.setNotifyOnChange(false);
|
||||||
boolean result = false;
|
adapter.clear();
|
||||||
try {
|
for (CalculatorHistoryState historyState : historyList) {
|
||||||
historyState.setSaved(true);
|
adapter.add(historyState);
|
||||||
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
}
|
||||||
@Override
|
} finally {
|
||||||
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
adapter.setNotifyOnChange(true);
|
||||||
return first != null && second != null &&
|
}
|
||||||
first.getTime() == second.getTime() &&
|
|
||||||
first.getDisplayState().equals(second.getDisplayState()) &&
|
adapter.notifyDataSetChanged();
|
||||||
first.getEditorState().equals(second.getEditorState());
|
}
|
||||||
}
|
|
||||||
}) ) {
|
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
||||||
result = true;
|
assert !historyState.isSaved();
|
||||||
}
|
|
||||||
} finally {
|
boolean result = false;
|
||||||
historyState.setSaved(false);
|
try {
|
||||||
}
|
historyState.setSaved(true);
|
||||||
return result;
|
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
||||||
}
|
@Override
|
||||||
|
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
||||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull Activity activity) {
|
return first != null && second != null &&
|
||||||
final EditorHistoryState editorState = historyState.getEditorState();
|
first.getTime() == second.getTime() &&
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
first.getDisplayState().equals(second.getDisplayState()) &&
|
||||||
|
first.getEditorState().equals(second.getEditorState());
|
||||||
activity.finish();
|
}
|
||||||
}
|
}) ) {
|
||||||
|
result = true;
|
||||||
@NotNull
|
}
|
||||||
private List<CalculatorHistoryState> getHistoryList() {
|
} finally {
|
||||||
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
historyState.setSaved(false);
|
||||||
|
}
|
||||||
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
return result;
|
||||||
|
}
|
||||||
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
|
||||||
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
||||||
@Override
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
||||||
public boolean isFiltered(CalculatorHistoryState object) {
|
}
|
||||||
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
|
||||||
}
|
@NotNull
|
||||||
});
|
private List<CalculatorHistoryState> getHistoryList() {
|
||||||
|
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
||||||
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
|
||||||
|
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
||||||
return calculatorHistoryStates;
|
|
||||||
}
|
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
||||||
|
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
||||||
@NotNull
|
@Override
|
||||||
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
public boolean isFiltered(CalculatorHistoryState object) {
|
||||||
|
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
||||||
@NotNull
|
}
|
||||||
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
});
|
||||||
final StringBuilder result = new StringBuilder();
|
|
||||||
result.append(state.getEditorState().getText());
|
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
||||||
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
|
||||||
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
return calculatorHistoryStates;
|
||||||
if (expressionResult != null) {
|
}
|
||||||
result.append(expressionResult);
|
|
||||||
}
|
@NotNull
|
||||||
return result.toString();
|
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
||||||
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
final StringBuilder result = new StringBuilder();
|
||||||
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
result.append(state.getEditorState().getText());
|
||||||
}
|
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
||||||
|
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
||||||
// todo serso: menu
|
if (expressionResult != null) {
|
||||||
/* @Override
|
result.append(expressionResult);
|
||||||
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
}
|
||||||
final MenuInflater menuInflater = getMenuInflater();
|
return result.toString();
|
||||||
menuInflater.inflate(R.menu.history_menu, menu);
|
}
|
||||||
return true;
|
|
||||||
}
|
@NotNull
|
||||||
|
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
||||||
@Override
|
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
}
|
||||||
boolean result;
|
|
||||||
|
// todo serso: menu
|
||||||
switch (item.getItemId()) {
|
/* @Override
|
||||||
case R.id.history_menu_clear_history:
|
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
||||||
clearHistory();
|
final MenuInflater menuInflater = getMenuInflater();
|
||||||
result = true;
|
menuInflater.inflate(R.menu.history_menu, menu);
|
||||||
break;
|
return true;
|
||||||
default:
|
}
|
||||||
result = super.onOptionsItemSelected(item);
|
|
||||||
}
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
return result;
|
boolean result;
|
||||||
}*/
|
|
||||||
|
switch (item.getItemId()) {
|
||||||
protected abstract void clearHistory();
|
case R.id.history_menu_clear_history:
|
||||||
|
clearHistory();
|
||||||
@NotNull
|
result = true;
|
||||||
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
break;
|
||||||
return adapter;
|
default:
|
||||||
}
|
result = super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
protected abstract void clearHistory();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
|
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateAdapter();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/18/11
|
* Date: 12/18/11
|
||||||
* Time: 7:39 PM
|
* Time: 7:39 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.history;
|
return R.layout.history;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates());
|
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clearHistory() {
|
protected void clearHistory() {
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().clear();
|
CalculatorLocatorImpl.getInstance().getHistory().clear();
|
||||||
getAdapter().clear();
|
getAdapter().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,64 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
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.calculator.CalculatorActivityHelper;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
|
||||||
import org.solovyev.android.calculator.R;
|
/**
|
||||||
|
* User: serso
|
||||||
/**
|
* Date: 12/18/11
|
||||||
* User: serso
|
* Time: 7:37 PM
|
||||||
* Date: 12/18/11
|
*/
|
||||||
* Time: 7:37 PM
|
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
*/
|
|
||||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity {
|
@NotNull
|
||||||
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.main_empty);
|
||||||
@NotNull
|
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.history_activity);
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@Override
|
super.onCreate(savedInstanceState);
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_layout);
|
||||||
}
|
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_layout);
|
||||||
|
|
||||||
@Override
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
}
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
|
@Override
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
}
|
super.onSaveInstanceState(outState);
|
||||||
}
|
|
||||||
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
activityHelper.onResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
|
if ( calculatorEventType == CalculatorEventType.use_history_state ) {
|
||||||
|
this.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/18/11
|
* Date: 12/18/11
|
||||||
* Time: 7:40 PM
|
* Time: 7:40 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.saved_history;
|
return R.layout.saved_history;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory());
|
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clearHistory() {
|
protected void clearHistory() {
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().clearSavedHistory();
|
CalculatorLocatorImpl.getInstance().getHistory().clearSavedHistory();
|
||||||
getAdapter().clear();
|
getAdapter().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,155 +1,151 @@
|
|||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
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.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/18/11
|
* Date: 12/18/11
|
||||||
* Time: 3:09 PM
|
* Time: 3:09 PM
|
||||||
*/
|
*/
|
||||||
public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData> {
|
public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData> {
|
||||||
|
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
if (context instanceof Activity) {
|
AbstractCalculatorHistoryFragment.useHistoryItem(data.getHistoryState());
|
||||||
AbstractCalculatorHistoryFragment.useHistoryItem(data.getHistoryState(), (Activity) context);
|
}
|
||||||
} else {
|
},
|
||||||
Log.e(HistoryItemMenuItem.class.getName(), AbstractCalculatorHistoryFragment.class + " must be passed as context!");
|
|
||||||
}
|
copy_expression(R.string.c_copy_expression) {
|
||||||
}
|
@Override
|
||||||
},
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
|
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
||||||
copy_expression(R.string.c_copy_expression) {
|
final String text = calculatorHistoryState.getEditorState().getText();
|
||||||
@Override
|
if (!StringUtils.isEmpty(text)) {
|
||||||
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
clipboard.setText(text);
|
||||||
final String text = calculatorHistoryState.getEditorState().getText();
|
Toast.makeText(context, context.getText(R.string.c_expression_copied), Toast.LENGTH_SHORT).show();
|
||||||
if (!StringUtils.isEmpty(text)) {
|
}
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
}
|
||||||
clipboard.setText(text);
|
},
|
||||||
Toast.makeText(context, context.getText(R.string.c_expression_copied), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
copy_result(R.string.c_copy_result) {
|
||||||
}
|
@Override
|
||||||
},
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
|
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
||||||
copy_result(R.string.c_copy_result) {
|
final String text = calculatorHistoryState.getDisplayState().getEditorState().getText();
|
||||||
@Override
|
if (!StringUtils.isEmpty(text)) {
|
||||||
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
final CalculatorHistoryState calculatorHistoryState = data.getHistoryState();
|
clipboard.setText(text);
|
||||||
final String text = calculatorHistoryState.getDisplayState().getEditorState().getText();
|
Toast.makeText(context, context.getText(R.string.c_result_copied), Toast.LENGTH_SHORT).show();
|
||||||
if (!StringUtils.isEmpty(text)) {
|
}
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
}
|
||||||
clipboard.setText(text);
|
},
|
||||||
Toast.makeText(context, context.getText(R.string.c_result_copied), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
save(R.string.c_save) {
|
||||||
}
|
@Override
|
||||||
},
|
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||||
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
save(R.string.c_save) {
|
if (!historyState.isSaved()) {
|
||||||
@Override
|
createEditHistoryDialog(data, context, true);
|
||||||
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
} else {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
Toast.makeText(context, context.getText(R.string.c_history_already_saved), Toast.LENGTH_LONG).show();
|
||||||
if (!historyState.isSaved()) {
|
}
|
||||||
createEditHistoryDialog(data, context, true);
|
}
|
||||||
} else {
|
},
|
||||||
Toast.makeText(context, context.getText(R.string.c_history_already_saved), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
edit(R.string.c_edit) {
|
||||||
}
|
@Override
|
||||||
},
|
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||||
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
edit(R.string.c_edit) {
|
if (historyState.isSaved()) {
|
||||||
@Override
|
createEditHistoryDialog(data, context, false);
|
||||||
public void onClick(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
} else {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
Toast.makeText(context, context.getText(R.string.c_history_must_be_saved), Toast.LENGTH_LONG).show();
|
||||||
if (historyState.isSaved()) {
|
}
|
||||||
createEditHistoryDialog(data, context, false);
|
}
|
||||||
} else {
|
},
|
||||||
Toast.makeText(context, context.getText(R.string.c_history_must_be_saved), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
remove(R.string.c_remove) {
|
||||||
}
|
@Override
|
||||||
},
|
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
remove(R.string.c_remove) {
|
if (historyState.isSaved()) {
|
||||||
@Override
|
data.getAdapter().remove(historyState);
|
||||||
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
CalculatorLocatorImpl.getInstance().getHistory().removeSavedHistory(historyState);
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
Toast.makeText(context, context.getText(R.string.c_history_was_removed), Toast.LENGTH_LONG).show();
|
||||||
if (historyState.isSaved()) {
|
data.getAdapter().notifyDataSetChanged();
|
||||||
data.getAdapter().remove(historyState);
|
}
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().removeSavedHistory(historyState);
|
}
|
||||||
Toast.makeText(context, context.getText(R.string.c_history_was_removed), Toast.LENGTH_LONG).show();
|
};
|
||||||
data.getAdapter().notifyDataSetChanged();
|
|
||||||
}
|
private static void createEditHistoryDialog(@NotNull final HistoryItemMenuData data, @NotNull final Context context, final boolean save) {
|
||||||
}
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
};
|
|
||||||
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
private static void createEditHistoryDialog(@NotNull final HistoryItemMenuData data, @NotNull final Context context, final boolean save) {
|
final View editView = layoutInflater.inflate(R.layout.history_edit, null);
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
final TextView historyExpression = (TextView)editView.findViewById(R.id.history_edit_expression);
|
||||||
|
historyExpression.setText(AbstractCalculatorHistoryFragment.getHistoryText(historyState));
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
final View editView = layoutInflater.inflate(R.layout.history_edit, null);
|
final EditText comment = (EditText)editView.findViewById(R.id.history_edit_comment);
|
||||||
final TextView historyExpression = (TextView)editView.findViewById(R.id.history_edit_expression);
|
comment.setText(historyState.getComment());
|
||||||
historyExpression.setText(AbstractCalculatorHistoryFragment.getHistoryText(historyState));
|
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
final EditText comment = (EditText)editView.findViewById(R.id.history_edit_comment);
|
.setTitle(save ? R.string.c_save_history : R.string.c_edit_history)
|
||||||
comment.setText(historyState.getComment());
|
.setCancelable(true)
|
||||||
|
.setNegativeButton(R.string.c_cancel, null)
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
|
||||||
.setTitle(save ? R.string.c_save_history : R.string.c_edit_history)
|
@Override
|
||||||
.setCancelable(true)
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
.setNegativeButton(R.string.c_cancel, null)
|
if (save) {
|
||||||
.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
|
final CalculatorHistoryState savedHistoryItem = CalculatorLocatorImpl.getInstance().getHistory().addSavedState(historyState);
|
||||||
@Override
|
savedHistoryItem.setComment(comment.getText().toString());
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
CalculatorLocatorImpl.getInstance().getHistory().save();
|
||||||
if (save) {
|
// we don't need to add element to the adapter as adapter of another activity must be updated and not this
|
||||||
final CalculatorHistoryState savedHistoryItem = CalculatorLocatorImpl.getInstance().getHistory().addSavedState(historyState);
|
//data.getAdapter().add(savedHistoryItem);
|
||||||
savedHistoryItem.setComment(comment.getText().toString());
|
} else {
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().save();
|
historyState.setComment(comment.getText().toString());
|
||||||
// we don't need to add element to the adapter as adapter of another activity must be updated and not this
|
CalculatorLocatorImpl.getInstance().getHistory().save();
|
||||||
//data.getAdapter().add(savedHistoryItem);
|
}
|
||||||
} else {
|
data.getAdapter().notifyDataSetChanged();
|
||||||
historyState.setComment(comment.getText().toString());
|
Toast.makeText(context, context.getText(R.string.c_history_saved), Toast.LENGTH_LONG).show();
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().save();
|
}
|
||||||
}
|
})
|
||||||
data.getAdapter().notifyDataSetChanged();
|
.setView(editView);
|
||||||
Toast.makeText(context, context.getText(R.string.c_history_saved), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
builder.create().show();
|
||||||
})
|
}
|
||||||
.setView(editView);
|
|
||||||
|
private final int captionId;
|
||||||
builder.create().show();
|
|
||||||
}
|
private HistoryItemMenuItem(int captionId) {
|
||||||
|
this.captionId = captionId;
|
||||||
private final int captionId;
|
}
|
||||||
|
|
||||||
private HistoryItemMenuItem(int captionId) {
|
@NotNull
|
||||||
this.captionId = captionId;
|
@Override
|
||||||
}
|
public String getCaption(@NotNull Context context) {
|
||||||
|
return context.getString(captionId);
|
||||||
@NotNull
|
}
|
||||||
@Override
|
}
|
||||||
public String getCaption(@NotNull Context context) {
|
|
||||||
return context.getString(captionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,38 +1,85 @@
|
|||||||
package org.solovyev.android.fragments;
|
package org.solovyev.android.fragments;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
/**
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
* User: serso
|
|
||||||
* Date: 9/25/12
|
import java.util.Collections;
|
||||||
* Time: 9:29 PM
|
import java.util.List;
|
||||||
*/
|
|
||||||
public class FragmentUtils {
|
/**
|
||||||
|
* User: serso
|
||||||
public static void createFragment(@NotNull FragmentActivity activity,
|
* Date: 9/25/12
|
||||||
@NotNull Class<? extends Fragment> fragmentClass,
|
* Time: 9:29 PM
|
||||||
int parentViewId,
|
*/
|
||||||
@NotNull String tag) {
|
public class FragmentUtils {
|
||||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
|
||||||
|
public static void createFragment(@NotNull FragmentActivity activity,
|
||||||
Fragment messagesFragment = fm.findFragmentByTag(tag);
|
@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
|
int parentViewId,
|
||||||
final FragmentTransaction ft = fm.beginTransaction();
|
@NotNull String tag) {
|
||||||
try {
|
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||||
if (messagesFragment == null) {
|
|
||||||
messagesFragment = Fragment.instantiate(activity, fragmentClass.getName(), null);
|
Fragment messagesFragment = fm.findFragmentByTag(tag);
|
||||||
ft.add(parentViewId, messagesFragment, tag);
|
|
||||||
} else {
|
final FragmentTransaction ft = fm.beginTransaction();
|
||||||
if (messagesFragment.isDetached()) {
|
try {
|
||||||
ft.attach(messagesFragment);
|
if (messagesFragment == null) {
|
||||||
}
|
messagesFragment = Fragment.instantiate(activity, fragmentClass.getName(), null);
|
||||||
}
|
ft.add(parentViewId, messagesFragment, tag);
|
||||||
} finally {
|
} else {
|
||||||
ft.commit();
|
if (messagesFragment.isDetached()) {
|
||||||
}
|
ft.attach(messagesFragment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) {
|
||||||
|
removeFragments(activity, CollectionsUtils.asList(fragmentTags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull List<String> fragmentTags) {
|
||||||
|
for (String fragmentTag : fragmentTags) {
|
||||||
|
removeFragment(activity, fragmentTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) {
|
||||||
|
detachFragments(activity, CollectionsUtils.asList(fragmentTags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull List<String> fragmentTags) {
|
||||||
|
for (String fragmentTag : fragmentTags) {
|
||||||
|
detachFragment(activity, fragmentTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void detachFragment(@NotNull SherlockFragmentActivity activity, @NotNull String fragmentTag) {
|
||||||
|
final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||||
|
if ( fragment != null ) {
|
||||||
|
if ( !fragment.isDetached() ) {
|
||||||
|
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
ft.detach(fragment);
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeFragment(@NotNull SherlockFragmentActivity activity, @NotNull String fragmentTag) {
|
||||||
|
final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||||
|
if ( fragment != null ) {
|
||||||
|
if ( fragment.isAdded()) {
|
||||||
|
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||||
|
ft.remove(fragment);
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
14
pom.xml
14
pom.xml
@ -71,6 +71,20 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.solovyev.android</groupId>
|
||||||
|
<artifactId>android-common-sherlock</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<type>apklib</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.actionbarsherlock</groupId>
|
||||||
|
<artifactId>library</artifactId>
|
||||||
|
<version>4.0.2</version>
|
||||||
|
<type>apklib</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>jscl</artifactId>
|
<artifactId>jscl</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user