core moved to android-app
This commit is contained in:
1 parent
c2146dc0f6
commit
d834ccc305
161 files changed
+2711
-3015
No files matched your search
@@ -62,7 +62,6 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
compile project(':core')
|
|
||||||
compile 'org.solovyev:common-core:1.0.7'
|
compile 'org.solovyev:common-core:1.0.7'
|
||||||
compile 'org.solovyev:common-text:1.0.7'
|
compile 'org.solovyev:common-text:1.0.7'
|
||||||
compile 'org.solovyev:common-security:1.0.7'
|
compile 'org.solovyev:common-security:1.0.7'
|
||||||
@@ -91,6 +90,22 @@ dependencies {
|
|||||||
|
|
||||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
||||||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
||||||
|
compile group: 'org.solovyev', name: 'common-text', version: '1.0.7'
|
||||||
|
compile group: 'org.solovyev', name: 'common-listeners', version: '1.0.7'
|
||||||
|
compile(group: 'com.google.guava', name: 'guava', version: '11.0.2') {
|
||||||
|
exclude(module: 'jsr305')
|
||||||
|
}
|
||||||
|
compile(group: 'org.solovyev', name: 'jscl', version: '1.0.11') {
|
||||||
|
exclude(module: 'xercesImpl')
|
||||||
|
}
|
||||||
|
compile(group: 'org.simpleframework', name: 'simple-xml', version: '2.6.1') {
|
||||||
|
exclude(module: 'stax-api')
|
||||||
|
exclude(module: 'xpp3')
|
||||||
|
}
|
||||||
|
compile group: 'commons-cli', name: 'commons-cli', version: '1.2'
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||||
|
testCompile group: 'net.sf.opencsv', name: 'opencsv', version: '2.0'
|
||||||
|
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
task androidJavadocs(type: Javadoc) {
|
task androidJavadocs(type: Javadoc) {
|
||||||
|
|||||||
File renamed without changes.
+44
-44
@@ -1,44 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class AbstractFixableError implements FixableError {
|
public abstract class AbstractFixableError implements FixableError {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String fixCaption;
|
private String fixCaption;
|
||||||
|
|
||||||
protected AbstractFixableError() {
|
protected AbstractFixableError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractFixableError(@Nullable String fixCaption) {
|
protected AbstractFixableError(@Nullable String fixCaption) {
|
||||||
this.fixCaption = fixCaption;
|
this.fixCaption = fixCaption;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getFixCaption() {
|
public CharSequence getFixCaption() {
|
||||||
return fixCaption;
|
return fixCaption;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+49
-49
@@ -1,49 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import jscl.NumeralBase;
|
import jscl.NumeralBase;
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 24.09.12
|
* Date: 24.09.12
|
||||||
* Time: 16:45
|
* Time: 16:45
|
||||||
*/
|
*/
|
||||||
public interface CalculatorConversionEventData extends CalculatorEventData {
|
public interface CalculatorConversionEventData extends CalculatorEventData {
|
||||||
|
|
||||||
// display state on the moment of conversion
|
// display state on the moment of conversion
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CalculatorDisplayViewState getDisplayState();
|
CalculatorDisplayViewState getDisplayState();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
NumeralBase getFromNumeralBase();
|
NumeralBase getFromNumeralBase();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
NumeralBase getToNumeralBase();
|
NumeralBase getToNumeralBase();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Generic getValue();
|
Generic getValue();
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+35
-35
@@ -1,35 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 21.09.12
|
* Date: 21.09.12
|
||||||
* Time: 11:48
|
* Time: 11:48
|
||||||
*/
|
*/
|
||||||
public interface CalculatorEditorView {
|
public interface CalculatorEditorView {
|
||||||
|
|
||||||
void setState(@Nonnull CalculatorEditorViewState viewState);
|
void setState(@Nonnull CalculatorEditorViewState viewState);
|
||||||
}
|
}
|
||||||
File renamed without changes.
+85
-85
@@ -1,85 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 21.09.12
|
* Date: 21.09.12
|
||||||
* Time: 12:02
|
* Time: 12:02
|
||||||
*/
|
*/
|
||||||
public class CalculatorEditorViewStateImpl implements CalculatorEditorViewState {
|
public class CalculatorEditorViewStateImpl implements CalculatorEditorViewState {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private CharSequence text = "";
|
private CharSequence text = "";
|
||||||
|
|
||||||
private int selection = 0;
|
private int selection = 0;
|
||||||
|
|
||||||
private CalculatorEditorViewStateImpl() {
|
private CalculatorEditorViewStateImpl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorEditorViewStateImpl(@Nonnull CalculatorEditorViewState viewState) {
|
public CalculatorEditorViewStateImpl(@Nonnull CalculatorEditorViewState viewState) {
|
||||||
this.text = viewState.getText();
|
this.text = viewState.getText();
|
||||||
this.selection = viewState.getSelection();
|
this.selection = viewState.getSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorEditorViewState newDefaultInstance() {
|
public static CalculatorEditorViewState newDefaultInstance() {
|
||||||
return new CalculatorEditorViewStateImpl();
|
return new CalculatorEditorViewStateImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorEditorViewState newSelection(@Nonnull CalculatorEditorViewState viewState, int newSelection) {
|
public static CalculatorEditorViewState newSelection(@Nonnull CalculatorEditorViewState viewState, int newSelection) {
|
||||||
final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(viewState);
|
final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl(viewState);
|
||||||
|
|
||||||
result.selection = newSelection;
|
result.selection = newSelection;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorEditorViewState newInstance(@Nonnull CharSequence text, int selection) {
|
public static CalculatorEditorViewState newInstance(@Nonnull CharSequence text, int selection) {
|
||||||
final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl();
|
final CalculatorEditorViewStateImpl result = new CalculatorEditorViewStateImpl();
|
||||||
result.text = text;
|
result.text = text;
|
||||||
result.selection = selection;
|
result.selection = selection;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return this.text.toString();
|
return this.text.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getTextAsCharSequence() {
|
public CharSequence getTextAsCharSequence() {
|
||||||
return this.text;
|
return this.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSelection() {
|
public int getSelection() {
|
||||||
return this.selection;
|
return this.selection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
+35
-35
@@ -1,35 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/24/11
|
* Date: 10/24/11
|
||||||
* Time: 9:55 PM
|
* Time: 9:55 PM
|
||||||
*/
|
*/
|
||||||
public interface CalculatorEngineControl {
|
public interface CalculatorEngineControl {
|
||||||
|
|
||||||
void evaluate();
|
void evaluate();
|
||||||
|
|
||||||
void simplify();
|
void simplify();
|
||||||
}
|
}
|
||||||
File renamed without changes.
+88
-88
@@ -1,88 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.common.msg.Message;
|
||||||
import org.solovyev.common.msg.MessageLevel;
|
import org.solovyev.common.msg.MessageLevel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/8/11
|
* Date: 12/8/11
|
||||||
* Time: 1:27 AM
|
* Time: 1:27 AM
|
||||||
*/
|
*/
|
||||||
public class CalculatorEvalException extends Exception implements Message {
|
public class CalculatorEvalException extends Exception implements Message {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final Message message;
|
private final Message message;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final String expression;
|
private final String expression;
|
||||||
|
|
||||||
public CalculatorEvalException(@Nonnull Message message, @Nonnull Throwable cause, String expression) {
|
public CalculatorEvalException(@Nonnull Message message, @Nonnull Throwable cause, String expression) {
|
||||||
super(cause);
|
super(cause);
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getExpression() {
|
public String getExpression() {
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getMessageCode() {
|
public String getMessageCode() {
|
||||||
return this.message.getMessageCode();
|
return this.message.getMessageCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<Object> getParameters() {
|
public List<Object> getParameters() {
|
||||||
return this.message.getParameters();
|
return this.message.getParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MessageLevel getMessageLevel() {
|
public MessageLevel getMessageLevel() {
|
||||||
return this.message.getMessageLevel();
|
return this.message.getMessageLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getLocalizedMessage() {
|
public String getLocalizedMessage() {
|
||||||
return this.message.getLocalizedMessage(Locale.getDefault());
|
return this.message.getLocalizedMessage(Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getLocalizedMessage(@Nonnull Locale locale) {
|
public String getLocalizedMessage(@Nonnull Locale locale) {
|
||||||
return this.message.getLocalizedMessage(locale);
|
return this.message.getLocalizedMessage(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+41
-41
@@ -1,41 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/20/12
|
* Date: 9/20/12
|
||||||
* Time: 10:00 PM
|
* Time: 10:00 PM
|
||||||
*/
|
*/
|
||||||
public interface CalculatorEvaluationEventData extends CalculatorEventData {
|
public interface CalculatorEvaluationEventData extends CalculatorEventData {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
JsclOperation getOperation();
|
JsclOperation getOperation();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
String getExpression();
|
String getExpression();
|
||||||
}
|
}
|
||||||
File renamed without changes.
+79
-79
@@ -1,79 +1,79 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 20.09.12
|
* Date: 20.09.12
|
||||||
* Time: 16:39
|
* Time: 16:39
|
||||||
*/
|
*/
|
||||||
public interface CalculatorEventContainer {
|
public interface CalculatorEventContainer {
|
||||||
|
|
||||||
void addCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener);
|
void addCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener);
|
||||||
|
|
||||||
void removeCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener);
|
void removeCalculatorEventListener(@Nonnull CalculatorEventListener calculatorEventListener);
|
||||||
|
|
||||||
void fireCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data);
|
void fireCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data);
|
||||||
|
|
||||||
void fireCalculatorEvents(@Nonnull List<CalculatorEvent> calculatorEvents);
|
void fireCalculatorEvents(@Nonnull List<CalculatorEvent> calculatorEvents);
|
||||||
|
|
||||||
public static class CalculatorEvent {
|
public static class CalculatorEvent {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private CalculatorEventData calculatorEventData;
|
private CalculatorEventData calculatorEventData;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private CalculatorEventType calculatorEventType;
|
private CalculatorEventType calculatorEventType;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Object data;
|
private Object data;
|
||||||
|
|
||||||
public CalculatorEvent(@Nonnull CalculatorEventData calculatorEventData,
|
public CalculatorEvent(@Nonnull CalculatorEventData calculatorEventData,
|
||||||
@Nonnull CalculatorEventType calculatorEventType,
|
@Nonnull CalculatorEventType calculatorEventType,
|
||||||
@Nullable Object data) {
|
@Nullable Object data) {
|
||||||
this.calculatorEventData = calculatorEventData;
|
this.calculatorEventData = calculatorEventData;
|
||||||
this.calculatorEventType = calculatorEventType;
|
this.calculatorEventType = calculatorEventType;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CalculatorEventData getCalculatorEventData() {
|
public CalculatorEventData getCalculatorEventData() {
|
||||||
return calculatorEventData;
|
return calculatorEventData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CalculatorEventType getCalculatorEventType() {
|
public CalculatorEventType getCalculatorEventType() {
|
||||||
return calculatorEventType;
|
return calculatorEventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getData() {
|
public Object getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
+100
-100
@@ -1,100 +1,100 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/9/12
|
* Date: 10/9/12
|
||||||
* Time: 9:59 PM
|
* Time: 9:59 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorEventHolder {
|
public class CalculatorEventHolder {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private volatile CalculatorEventData lastEventData;
|
private volatile CalculatorEventData lastEventData;
|
||||||
|
|
||||||
public CalculatorEventHolder(@Nonnull CalculatorEventData lastEventData) {
|
public CalculatorEventHolder(@Nonnull CalculatorEventData lastEventData) {
|
||||||
this.lastEventData = lastEventData;
|
this.lastEventData = lastEventData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public synchronized CalculatorEventData getLastEventData() {
|
public synchronized CalculatorEventData getLastEventData() {
|
||||||
return lastEventData;
|
return lastEventData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public synchronized Result apply(@Nonnull CalculatorEventData newEventData) {
|
public synchronized Result apply(@Nonnull CalculatorEventData newEventData) {
|
||||||
final Result result = new Result(lastEventData, newEventData);
|
final Result result = new Result(lastEventData, newEventData);
|
||||||
|
|
||||||
if (result.isNewAfter()) {
|
if (result.isNewAfter()) {
|
||||||
this.lastEventData = newEventData;
|
this.lastEventData = newEventData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Result {
|
public static class Result {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final CalculatorEventData lastEventData;
|
private final CalculatorEventData lastEventData;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final CalculatorEventData newEventData;
|
private final CalculatorEventData newEventData;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Boolean after = null;
|
private Boolean after = null;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Boolean sameSequence = null;
|
private Boolean sameSequence = null;
|
||||||
|
|
||||||
public Result(@Nonnull CalculatorEventData lastEventData,
|
public Result(@Nonnull CalculatorEventData lastEventData,
|
||||||
@Nonnull CalculatorEventData newEventData) {
|
@Nonnull CalculatorEventData newEventData) {
|
||||||
this.lastEventData = lastEventData;
|
this.lastEventData = lastEventData;
|
||||||
this.newEventData = newEventData;
|
this.newEventData = newEventData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewAfter() {
|
public boolean isNewAfter() {
|
||||||
if (after == null) {
|
if (after == null) {
|
||||||
after = newEventData.isAfter(lastEventData);
|
after = newEventData.isAfter(lastEventData);
|
||||||
}
|
}
|
||||||
return after;
|
return after;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSameSequence() {
|
public boolean isSameSequence() {
|
||||||
if (sameSequence == null) {
|
if (sameSequence == null) {
|
||||||
sameSequence = newEventData.isSameSequence(lastEventData);
|
sameSequence = newEventData.isSameSequence(lastEventData);
|
||||||
}
|
}
|
||||||
return sameSequence;
|
return sameSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewAfterSequence() {
|
public boolean isNewAfterSequence() {
|
||||||
return newEventData.isAfterSequence(lastEventData);
|
return newEventData.isAfterSequence(lastEventData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewSameOrAfterSequence() {
|
public boolean isNewSameOrAfterSequence() {
|
||||||
return isSameSequence() || isNewAfterSequence();
|
return isSameSequence() || isNewAfterSequence();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+39
-39
@@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 20.09.12
|
* Date: 20.09.12
|
||||||
* Time: 16:39
|
* Time: 16:39
|
||||||
*/
|
*/
|
||||||
public interface CalculatorEventListener extends EventListener {
|
public interface CalculatorEventListener extends EventListener {
|
||||||
|
|
||||||
void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data);
|
void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data);
|
||||||
|
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+47
-47
@@ -1,47 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/22/12
|
* Date: 9/22/12
|
||||||
* Time: 1:08 PM
|
* Time: 1:08 PM
|
||||||
*/
|
*/
|
||||||
public interface CalculatorKeyboard {
|
public interface CalculatorKeyboard {
|
||||||
|
|
||||||
boolean buttonPressed(@Nullable String text);
|
boolean buttonPressed(@Nullable String text);
|
||||||
|
|
||||||
void roundBracketsButtonPressed();
|
void roundBracketsButtonPressed();
|
||||||
|
|
||||||
void pasteButtonPressed();
|
void pasteButtonPressed();
|
||||||
|
|
||||||
void clearButtonPressed();
|
void clearButtonPressed();
|
||||||
|
|
||||||
void copyButtonPressed();
|
void copyButtonPressed();
|
||||||
|
|
||||||
void moveCursorLeft();
|
void moveCursorLeft();
|
||||||
|
|
||||||
void moveCursorRight();
|
void moveCursorRight();
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+108
-108
@@ -1,108 +1,108 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.common.msg.Message;
|
||||||
import org.solovyev.common.msg.MessageLevel;
|
import org.solovyev.common.msg.MessageLevel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/6/11
|
* Date: 10/6/11
|
||||||
* Time: 9:25 PM
|
* Time: 9:25 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorParseException extends Exception implements Message {
|
public class CalculatorParseException extends Exception implements Message {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final Message message;
|
private final Message message;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final String expression;
|
private final String expression;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Integer position;
|
private final Integer position;
|
||||||
|
|
||||||
public CalculatorParseException(@Nonnull jscl.text.ParseException jsclParseException) {
|
public CalculatorParseException(@Nonnull jscl.text.ParseException jsclParseException) {
|
||||||
this.message = jsclParseException;
|
this.message = jsclParseException;
|
||||||
this.expression = jsclParseException.getExpression();
|
this.expression = jsclParseException.getExpression();
|
||||||
this.position = jsclParseException.getPosition();
|
this.position = jsclParseException.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorParseException(@Nullable Integer position,
|
public CalculatorParseException(@Nullable Integer position,
|
||||||
@Nonnull String expression,
|
@Nonnull String expression,
|
||||||
@Nonnull Message message) {
|
@Nonnull Message message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorParseException(@Nonnull String expression,
|
public CalculatorParseException(@Nonnull String expression,
|
||||||
@Nonnull Message message) {
|
@Nonnull Message message) {
|
||||||
this(null, expression, message);
|
this(null, expression, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getExpression() {
|
public String getExpression() {
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Integer getPosition() {
|
public Integer getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getMessageCode() {
|
public String getMessageCode() {
|
||||||
return this.message.getMessageCode();
|
return this.message.getMessageCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<Object> getParameters() {
|
public List<Object> getParameters() {
|
||||||
return this.message.getParameters();
|
return this.message.getParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public MessageLevel getMessageLevel() {
|
public MessageLevel getMessageLevel() {
|
||||||
return this.message.getMessageLevel();
|
return this.message.getMessageLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getLocalizedMessage() {
|
public String getLocalizedMessage() {
|
||||||
return this.message.getLocalizedMessage(Locale.getDefault());
|
return this.message.getLocalizedMessage(Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getLocalizedMessage(@Nonnull Locale locale) {
|
public String getLocalizedMessage(@Nonnull Locale locale) {
|
||||||
return this.message.getLocalizedMessage(locale);
|
return this.message.getLocalizedMessage(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+153
-153
@@ -1,153 +1,153 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||||
import org.solovyev.android.calculator.model.Var;
|
import org.solovyev.android.calculator.model.Var;
|
||||||
import org.solovyev.android.calculator.model.Vars;
|
import org.solovyev.android.calculator.model.Vars;
|
||||||
import org.solovyev.common.JBuilder;
|
import org.solovyev.common.JBuilder;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/29/11
|
* Date: 9/29/11
|
||||||
* Time: 4:57 PM
|
* Time: 4:57 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
public class CalculatorVarsRegistry extends AbstractCalculatorMathRegistry<IConstant, Var> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static final String ANS = "ans";
|
public static final String ANS = "ans";
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
substitutes.put("π", "pi");
|
substitutes.put("π", "pi");
|
||||||
substitutes.put("Π", "PI");
|
substitutes.put("Π", "PI");
|
||||||
substitutes.put("∞", "inf");
|
substitutes.put("∞", "inf");
|
||||||
substitutes.put("h", "h_reduced");
|
substitutes.put("h", "h_reduced");
|
||||||
substitutes.put("NaN", "nan");
|
substitutes.put("NaN", "nan");
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorVarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
|
public CalculatorVarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
|
||||||
@Nonnull MathEntityDao<Var> mathEntityDao) {
|
@Nonnull MathEntityDao<Var> mathEntityDao) {
|
||||||
super(mathRegistry, "c_var_description_", mathEntityDao);
|
super(mathRegistry, "c_var_description_", mathEntityDao);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends MathEntity> void saveVariable(@Nonnull CalculatorMathRegistry<T> registry,
|
public static <T extends MathEntity> void saveVariable(@Nonnull CalculatorMathRegistry<T> registry,
|
||||||
@Nonnull MathEntityBuilder<? extends T> builder,
|
@Nonnull MathEntityBuilder<? extends T> builder,
|
||||||
@Nullable T editedInstance,
|
@Nullable T editedInstance,
|
||||||
@Nonnull Object source, boolean save) {
|
@Nonnull Object source, boolean save) {
|
||||||
final T addedVar = registry.add(builder);
|
final T addedVar = registry.add(builder);
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
registry.save();
|
registry.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editedInstance == null) {
|
if (editedInstance == null) {
|
||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
|
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_added, addedVar, source);
|
||||||
} else {
|
} else {
|
||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
|
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.constant_changed, ChangeImpl.newInstance(editedInstance, addedVar), source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getSubstitutes() {
|
protected Map<String, String> getSubstitutes() {
|
||||||
return substitutes;
|
return substitutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void load() {
|
public synchronized void load() {
|
||||||
super.load();
|
super.load();
|
||||||
|
|
||||||
tryToAddAuxVar("x");
|
tryToAddAuxVar("x");
|
||||||
tryToAddAuxVar("y");
|
tryToAddAuxVar("y");
|
||||||
tryToAddAuxVar("t");
|
tryToAddAuxVar("t");
|
||||||
tryToAddAuxVar("j");
|
tryToAddAuxVar("j");
|
||||||
|
|
||||||
|
|
||||||
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
|
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
|
||||||
for (Var var : vars) {
|
for (Var var : vars) {
|
||||||
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
|
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected JBuilder<? extends IConstant> createBuilder(@Nonnull Var entity) {
|
protected JBuilder<? extends IConstant> createBuilder(@Nonnull Var entity) {
|
||||||
return new Var.Builder(entity);
|
return new Var.Builder(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected MathEntityPersistenceContainer<Var> createPersistenceContainer() {
|
protected MathEntityPersistenceContainer<Var> createPersistenceContainer() {
|
||||||
return new Vars();
|
return new Vars();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToAddAuxVar(@Nonnull String name) {
|
private void tryToAddAuxVar(@Nonnull String name) {
|
||||||
if (!contains(name)) {
|
if (!contains(name)) {
|
||||||
add(new Var.Builder(name, (String) null));
|
add(new Var.Builder(name, (String) null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
protected Var transform(@Nonnull IConstant entity) {
|
protected Var transform(@Nonnull IConstant entity) {
|
||||||
if (entity instanceof Var) {
|
if (entity instanceof Var) {
|
||||||
return (Var) entity;
|
return (Var) entity;
|
||||||
} else {
|
} else {
|
||||||
return new Var.Builder(entity).create();
|
return new Var.Builder(entity).create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription(@Nonnull String mathEntityName) {
|
public String getDescription(@Nonnull String mathEntityName) {
|
||||||
final IConstant var = get(mathEntityName);
|
final IConstant var = get(mathEntityName);
|
||||||
if (var != null && !var.isSystem()) {
|
if (var != null && !var.isSystem()) {
|
||||||
return var.getDescription();
|
return var.getDescription();
|
||||||
} else {
|
} else {
|
||||||
return super.getDescription(mathEntityName);
|
return super.getDescription(mathEntityName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCategory(@Nonnull IConstant var) {
|
public String getCategory(@Nonnull IConstant var) {
|
||||||
for (VarCategory category : VarCategory.values()) {
|
for (VarCategory category : VarCategory.values()) {
|
||||||
if (category.isInCategory(var)) {
|
if (category.isInCategory(var)) {
|
||||||
return category.name();
|
return category.name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
+36
-36
@@ -1,36 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 24.09.12
|
* Date: 24.09.12
|
||||||
* Time: 16:12
|
* Time: 16:12
|
||||||
*/
|
*/
|
||||||
public interface ConversionFailure {
|
public interface ConversionFailure {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Exception getException();
|
Exception getException();
|
||||||
}
|
}
|
||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 24.09.12
|
* Date: 24.09.12
|
||||||
* Time: 16:12
|
* Time: 16:12
|
||||||
*/
|
*/
|
||||||
public class ConversionFailureImpl implements ConversionFailure {
|
public class ConversionFailureImpl implements ConversionFailure {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private Exception exception;
|
private Exception exception;
|
||||||
|
|
||||||
public ConversionFailureImpl(@Nonnull Exception exception) {
|
public ConversionFailureImpl(@Nonnull Exception exception) {
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Exception getException() {
|
public Exception getException() {
|
||||||
return this.exception;
|
return this.exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+43
-43
@@ -1,43 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/17/11
|
* Date: 12/17/11
|
||||||
* Time: 9:37 PM
|
* Time: 9:37 PM
|
||||||
*/
|
*/
|
||||||
public interface Editor {
|
public interface Editor {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
CharSequence getText();
|
CharSequence getText();
|
||||||
|
|
||||||
void setText(@Nullable CharSequence text);
|
void setText(@Nullable CharSequence text);
|
||||||
|
|
||||||
int getSelection();
|
int getSelection();
|
||||||
|
|
||||||
void setSelection(int selection);
|
void setSelection(int selection);
|
||||||
|
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+82
-82
@@ -1,82 +1,82 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/18/11
|
* Date: 10/18/11
|
||||||
* Time: 10:07 PM
|
* Time: 10:07 PM
|
||||||
*/
|
*/
|
||||||
public class PreparedExpression implements CharSequence {
|
public class PreparedExpression implements CharSequence {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private String expression;
|
private String expression;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<IConstant> undefinedVars;
|
private List<IConstant> undefinedVars;
|
||||||
|
|
||||||
public PreparedExpression(@Nonnull String expression, @Nonnull List<IConstant> undefinedVars) {
|
public PreparedExpression(@Nonnull String expression, @Nonnull List<IConstant> undefinedVars) {
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.undefinedVars = undefinedVars;
|
this.undefinedVars = undefinedVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getExpression() {
|
public String getExpression() {
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExistsUndefinedVar() {
|
public boolean isExistsUndefinedVar() {
|
||||||
return !this.undefinedVars.isEmpty();
|
return !this.undefinedVars.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<IConstant> getUndefinedVars() {
|
public List<IConstant> getUndefinedVars() {
|
||||||
return undefinedVars;
|
return undefinedVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int length() {
|
public int length() {
|
||||||
return expression.length();
|
return expression.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char charAt(int i) {
|
public char charAt(int i) {
|
||||||
return expression.charAt(i);
|
return expression.charAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence subSequence(int i, int i1) {
|
public CharSequence subSequence(int i, int i1) {
|
||||||
return expression.subSequence(i, i1);
|
return expression.subSequence(i, i1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.expression;
|
return this.expression;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+97
-97
@@ -1,97 +1,97 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.Transient;
|
import org.simpleframework.xml.Transient;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/15/11
|
* Date: 10/15/11
|
||||||
* Time: 1:45 PM
|
* Time: 1:45 PM
|
||||||
*/
|
*/
|
||||||
public class AbstractHistoryState implements Cloneable {
|
public class AbstractHistoryState implements Cloneable {
|
||||||
|
|
||||||
@Element
|
@Element
|
||||||
private long time = new Date().getTime();
|
private long time = new Date().getTime();
|
||||||
|
|
||||||
@Element(required = false)
|
@Element(required = false)
|
||||||
@Nullable
|
@Nullable
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private boolean saved;
|
private boolean saved;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private int id = 0;
|
private int id = 0;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTime() {
|
public long getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(long time) {
|
public void setTime(long time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComment(@Nullable String comment) {
|
public void setComment(@Nullable String comment) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaved() {
|
public boolean isSaved() {
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSaved(boolean saved) {
|
public void setSaved(boolean saved) {
|
||||||
this.saved = saved;
|
this.saved = saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractHistoryState clone() {
|
protected AbstractHistoryState clone() {
|
||||||
AbstractHistoryState clone;
|
AbstractHistoryState clone;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clone = (AbstractHistoryState) super.clone();
|
clone = (AbstractHistoryState) super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new UnsupportedOperationException(e);
|
throw new UnsupportedOperationException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+161
-161
@@ -1,161 +1,161 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.Root;
|
import org.simpleframework.xml.Root;
|
||||||
import org.simpleframework.xml.Transient;
|
import org.simpleframework.xml.Transient;
|
||||||
import org.solovyev.android.calculator.CalculatorDisplay;
|
import org.solovyev.android.calculator.CalculatorDisplay;
|
||||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||||
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
|
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/17/11
|
* Date: 9/17/11
|
||||||
* Time: 11:05 PM
|
* Time: 11:05 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Root
|
@Root
|
||||||
public class CalculatorDisplayHistoryState implements Cloneable {
|
public class CalculatorDisplayHistoryState implements Cloneable {
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private boolean valid = true;
|
private boolean valid = true;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
@Nullable
|
@Nullable
|
||||||
private String errorMessage = null;
|
private String errorMessage = null;
|
||||||
|
|
||||||
@Element
|
@Element
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private EditorHistoryState editorState;
|
private EditorHistoryState editorState;
|
||||||
|
|
||||||
@Element
|
@Element
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private JsclOperation jsclOperation;
|
private JsclOperation jsclOperation;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
@Nullable
|
@Nullable
|
||||||
private Generic genericResult;
|
private Generic genericResult;
|
||||||
|
|
||||||
private CalculatorDisplayHistoryState() {
|
private CalculatorDisplayHistoryState() {
|
||||||
// for xml
|
// for xml
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static CalculatorDisplayHistoryState newInstance(@Nonnull CalculatorDisplayViewState viewState) {
|
public static CalculatorDisplayHistoryState newInstance(@Nonnull CalculatorDisplayViewState viewState) {
|
||||||
final CalculatorDisplayHistoryState result = new CalculatorDisplayHistoryState();
|
final CalculatorDisplayHistoryState result = new CalculatorDisplayHistoryState();
|
||||||
|
|
||||||
result.editorState = EditorHistoryState.newInstance(viewState);
|
result.editorState = EditorHistoryState.newInstance(viewState);
|
||||||
|
|
||||||
result.valid = viewState.isValid();
|
result.valid = viewState.isValid();
|
||||||
result.jsclOperation = viewState.getOperation();
|
result.jsclOperation = viewState.getOperation();
|
||||||
result.genericResult = viewState.getResult();
|
result.genericResult = viewState.getResult();
|
||||||
result.errorMessage = viewState.getErrorMessage();
|
result.errorMessage = viewState.getErrorMessage();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValuesFromHistory(@Nonnull CalculatorDisplay display) {
|
public void setValuesFromHistory(@Nonnull CalculatorDisplay display) {
|
||||||
if (this.isValid()) {
|
if (this.isValid()) {
|
||||||
display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition()));
|
display.setViewState(CalculatorDisplayViewStateImpl.newValidState(this.getJsclOperation(), this.getGenericResult(), Strings.getNotEmpty(this.getEditorState().getText(), ""), this.getEditorState().getCursorPosition()));
|
||||||
} else {
|
} else {
|
||||||
display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), "")));
|
display.setViewState(CalculatorDisplayViewStateImpl.newErrorState(this.getJsclOperation(), Strings.getNotEmpty(this.getErrorMessage(), "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public EditorHistoryState getEditorState() {
|
public EditorHistoryState getEditorState() {
|
||||||
return editorState;
|
return editorState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public JsclOperation getJsclOperation() {
|
public JsclOperation getJsclOperation() {
|
||||||
return jsclOperation;
|
return jsclOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getErrorMessage() {
|
public String getErrorMessage() {
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Generic getGenericResult() {
|
public Generic getGenericResult() {
|
||||||
return genericResult;
|
return genericResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
CalculatorDisplayHistoryState that = (CalculatorDisplayHistoryState) o;
|
CalculatorDisplayHistoryState that = (CalculatorDisplayHistoryState) o;
|
||||||
|
|
||||||
if (!editorState.equals(that.editorState)) return false;
|
if (!editorState.equals(that.editorState)) return false;
|
||||||
if (jsclOperation != that.jsclOperation) return false;
|
if (jsclOperation != that.jsclOperation) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = editorState.hashCode();
|
int result = editorState.hashCode();
|
||||||
result = 31 * result + jsclOperation.hashCode();
|
result = 31 * result + jsclOperation.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CalculatorDisplayHistoryState{" +
|
return "CalculatorDisplayHistoryState{" +
|
||||||
"valid=" + valid +
|
"valid=" + valid +
|
||||||
", errorMessage='" + errorMessage + '\'' +
|
", errorMessage='" + errorMessage + '\'' +
|
||||||
", editorHistoryState=" + editorState +
|
", editorHistoryState=" + editorState +
|
||||||
", jsclOperation=" + jsclOperation +
|
", jsclOperation=" + jsclOperation +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CalculatorDisplayHistoryState clone() {
|
protected CalculatorDisplayHistoryState clone() {
|
||||||
try {
|
try {
|
||||||
final CalculatorDisplayHistoryState clone = (CalculatorDisplayHistoryState) super.clone();
|
final CalculatorDisplayHistoryState clone = (CalculatorDisplayHistoryState) super.clone();
|
||||||
|
|
||||||
clone.editorState = this.editorState.clone();
|
clone.editorState = this.editorState.clone();
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+63
-63
@@ -1,63 +1,63 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||||
import org.solovyev.common.history.HistoryHelper;
|
import org.solovyev.common.history.HistoryHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 20.09.12
|
* Date: 20.09.12
|
||||||
* Time: 16:11
|
* Time: 16:11
|
||||||
*/
|
*/
|
||||||
public interface CalculatorHistory extends HistoryHelper<CalculatorHistoryState>, CalculatorEventListener {
|
public interface CalculatorHistory extends HistoryHelper<CalculatorHistoryState>, CalculatorEventListener {
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
void fromXml(@Nonnull String xml);
|
void fromXml(@Nonnull String xml);
|
||||||
|
|
||||||
String toXml();
|
String toXml();
|
||||||
|
|
||||||
void clearSavedHistory();
|
void clearSavedHistory();
|
||||||
|
|
||||||
void removeSavedHistory(@Nonnull CalculatorHistoryState historyState);
|
void removeSavedHistory(@Nonnull CalculatorHistoryState historyState);
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
List<CalculatorHistoryState> getSavedHistory();
|
List<CalculatorHistoryState> getSavedHistory();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState);
|
CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState);
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
List<CalculatorHistoryState> getStates();
|
List<CalculatorHistoryState> getStates();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
List<CalculatorHistoryState> getStates(boolean includeIntermediateStates);
|
List<CalculatorHistoryState> getStates(boolean includeIntermediateStates);
|
||||||
|
|
||||||
}
|
}
|
||||||
+292
-292
@@ -1,292 +1,292 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.Calculator;
|
import org.solovyev.android.calculator.Calculator;
|
||||||
import org.solovyev.android.calculator.CalculatorDisplayChangeEventData;
|
import org.solovyev.android.calculator.CalculatorDisplayChangeEventData;
|
||||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||||
import org.solovyev.android.calculator.CalculatorEditorChangeEventData;
|
import org.solovyev.android.calculator.CalculatorEditorChangeEventData;
|
||||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||||
import org.solovyev.android.calculator.CalculatorEventData;
|
import org.solovyev.android.calculator.CalculatorEventData;
|
||||||
import org.solovyev.android.calculator.CalculatorEventHolder;
|
import org.solovyev.android.calculator.CalculatorEventHolder;
|
||||||
import org.solovyev.android.calculator.CalculatorEventType;
|
import org.solovyev.android.calculator.CalculatorEventType;
|
||||||
import org.solovyev.android.calculator.CalculatorUtils;
|
import org.solovyev.android.calculator.CalculatorUtils;
|
||||||
import org.solovyev.android.calculator.Locator;
|
import org.solovyev.android.calculator.Locator;
|
||||||
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.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final HistoryHelper<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
|
private final HistoryHelper<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
|
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile CalculatorEditorViewState lastEditorViewState;
|
private volatile CalculatorEditorViewState lastEditorViewState;
|
||||||
|
|
||||||
public CalculatorHistoryImpl(@Nonnull Calculator calculator) {
|
public CalculatorHistoryImpl(@Nonnull 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(@Nonnull HistoryAction historyAction) {
|
public boolean isActionAvailable(@Nonnull HistoryAction historyAction) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.isActionAvailable(historyAction);
|
return history.isActionAvailable(historyAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHistoryState doAction(@Nonnull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) {
|
public CalculatorHistoryState doAction(@Nonnull 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);
|
||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
|
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<CalculatorHistoryState> getStates() {
|
public List<CalculatorHistoryState> getStates() {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
return history.getStates();
|
return history.getStates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
|
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
if (includeIntermediateStates) {
|
if (includeIntermediateStates) {
|
||||||
return getStates();
|
return getStates();
|
||||||
} else {
|
} else {
|
||||||
final List<CalculatorHistoryState> states = getStates();
|
final List<CalculatorHistoryState> states = getStates();
|
||||||
|
|
||||||
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
|
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
|
||||||
|
|
||||||
CalculatorHistoryState laterState = null;
|
CalculatorHistoryState laterState = null;
|
||||||
for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) {
|
for (CalculatorHistoryState state : org.solovyev.common.collections.Collections.reversed(states)) {
|
||||||
if (laterState != null) {
|
if (laterState != null) {
|
||||||
final String laterEditorText = laterState.getEditorState().getText();
|
final String laterEditorText = laterState.getEditorState().getText();
|
||||||
final String editorText = state.getEditorState().getText();
|
final String editorText = state.getEditorState().getText();
|
||||||
if (laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) {
|
if (laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) {
|
||||||
// intermediate result => skip from add
|
// intermediate result => skip from add
|
||||||
} else {
|
} else {
|
||||||
result.add(0, state);
|
result.add(0, state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.add(0, state);
|
result.add(0, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
laterState = state;
|
laterState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isIntermediate(@Nonnull String laterEditorText,
|
private boolean isIntermediate(@Nonnull String laterEditorText,
|
||||||
@Nonnull String editorText) {
|
@Nonnull String editorText) {
|
||||||
if (Math.abs(laterEditorText.length() - editorText.length()) <= 1) {
|
if (Math.abs(laterEditorText.length() - editorText.length()) <= 1) {
|
||||||
if (laterEditorText.length() > editorText.length()) {
|
if (laterEditorText.length() > editorText.length()) {
|
||||||
return laterEditorText.startsWith(editorText);
|
return laterEditorText.startsWith(editorText);
|
||||||
} else {
|
} else {
|
||||||
return editorText.startsWith(laterEditorText);
|
return editorText.startsWith(laterEditorText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
synchronized (history) {
|
synchronized (history) {
|
||||||
this.history.clear();
|
this.history.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<CalculatorHistoryState> getSavedHistory() {
|
public List<CalculatorHistoryState> getSavedHistory() {
|
||||||
return Collections.unmodifiableList(savedHistory);
|
return Collections.unmodifiableList(savedHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState) {
|
public CalculatorHistoryState addSavedState(@Nonnull CalculatorHistoryState historyState) {
|
||||||
if (historyState.isSaved()) {
|
if (historyState.isSaved()) {
|
||||||
return historyState;
|
return historyState;
|
||||||
} else {
|
} else {
|
||||||
final CalculatorHistoryState savedState = historyState.clone();
|
final CalculatorHistoryState savedState = historyState.clone();
|
||||||
|
|
||||||
savedState.setId(counter.incrementAndGet());
|
savedState.setId(counter.incrementAndGet());
|
||||||
savedState.setSaved(true);
|
savedState.setSaved(true);
|
||||||
|
|
||||||
savedHistory.add(savedState);
|
savedHistory.add(savedState);
|
||||||
|
|
||||||
return savedState;
|
return savedState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
// todo serso: create saved/loader class
|
// todo serso: create saved/loader class
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
// todo serso: create saved/loader class
|
// todo serso: create saved/loader class
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromXml(@Nonnull String xml) {
|
public void fromXml(@Nonnull String xml) {
|
||||||
clearSavedHistory();
|
clearSavedHistory();
|
||||||
|
|
||||||
HistoryUtils.fromXml(xml, this.savedHistory);
|
HistoryUtils.fromXml(xml, this.savedHistory);
|
||||||
for (CalculatorHistoryState historyState : savedHistory) {
|
for (CalculatorHistoryState historyState : savedHistory) {
|
||||||
historyState.setSaved(true);
|
historyState.setSaved(true);
|
||||||
historyState.setId(counter.incrementAndGet());
|
historyState.setId(counter.incrementAndGet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXml() {
|
public String toXml() {
|
||||||
return HistoryUtils.toXml(this.savedHistory);
|
return HistoryUtils.toXml(this.savedHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearSavedHistory() {
|
public void clearSavedHistory() {
|
||||||
this.savedHistory.clear();
|
this.savedHistory.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeSavedHistory(@Nonnull CalculatorHistoryState historyState) {
|
public void removeSavedHistory(@Nonnull CalculatorHistoryState historyState) {
|
||||||
this.savedHistory.remove(historyState);
|
this.savedHistory.remove(historyState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData,
|
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData,
|
||||||
@Nonnull CalculatorEventType calculatorEventType,
|
@Nonnull CalculatorEventType calculatorEventType,
|
||||||
@Nullable Object data) {
|
@Nullable Object data) {
|
||||||
if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) {
|
if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) {
|
||||||
|
|
||||||
final CalculatorEventHolder.Result result = lastEventData.apply(calculatorEventData);
|
final CalculatorEventHolder.Result result = lastEventData.apply(calculatorEventData);
|
||||||
|
|
||||||
if (result.isNewAfter() && result.isNewSameOrAfterSequence()) {
|
if (result.isNewAfter() && result.isNewSameOrAfterSequence()) {
|
||||||
switch (calculatorEventType) {
|
switch (calculatorEventType) {
|
||||||
case manual_calculation_requested:
|
case manual_calculation_requested:
|
||||||
lastEditorViewState = (CalculatorEditorViewState) data;
|
lastEditorViewState = (CalculatorEditorViewState) data;
|
||||||
break;
|
break;
|
||||||
case editor_state_changed:
|
case editor_state_changed:
|
||||||
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
|
final CalculatorEditorChangeEventData editorChangeData = (CalculatorEditorChangeEventData) data;
|
||||||
lastEditorViewState = editorChangeData.getNewValue();
|
lastEditorViewState = editorChangeData.getNewValue();
|
||||||
break;
|
break;
|
||||||
case display_state_changed:
|
case display_state_changed:
|
||||||
if (result.isSameSequence()) {
|
if (result.isSameSequence()) {
|
||||||
if (lastEditorViewState != null) {
|
if (lastEditorViewState != null) {
|
||||||
final CalculatorEditorViewState editorViewState = lastEditorViewState;
|
final CalculatorEditorViewState editorViewState = lastEditorViewState;
|
||||||
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
|
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;
|
||||||
final CalculatorDisplayViewState displayViewState = displayChangeData.getNewValue();
|
final CalculatorDisplayViewState displayViewState = displayChangeData.getNewValue();
|
||||||
addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState));
|
addState(CalculatorHistoryState.newInstance(editorViewState, displayViewState));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lastEditorViewState = null;
|
lastEditorViewState = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
+49
-49
@@ -1,49 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.simpleframework.xml.ElementList;
|
import org.simpleframework.xml.ElementList;
|
||||||
import org.simpleframework.xml.Root;
|
import org.simpleframework.xml.Root;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/17/11
|
* Date: 12/17/11
|
||||||
* Time: 9:30 PM
|
* Time: 9:30 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Root
|
@Root
|
||||||
public class History {
|
public class History {
|
||||||
|
|
||||||
@ElementList(type = CalculatorHistoryState.class)
|
@ElementList(type = CalculatorHistoryState.class)
|
||||||
private List<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>();
|
private List<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>();
|
||||||
|
|
||||||
public History() {
|
public History() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CalculatorHistoryState> getHistoryItems() {
|
public List<CalculatorHistoryState> getHistoryItems() {
|
||||||
return historyItems;
|
return historyItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+78
-78
@@ -1,78 +1,78 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.simpleframework.xml.Serializer;
|
import org.simpleframework.xml.Serializer;
|
||||||
import org.simpleframework.xml.core.Persister;
|
import org.simpleframework.xml.core.Persister;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/17/11
|
* Date: 12/17/11
|
||||||
* Time: 9:59 PM
|
* Time: 9:59 PM
|
||||||
*/
|
*/
|
||||||
class HistoryUtils {
|
class HistoryUtils {
|
||||||
|
|
||||||
// not intended for instantiation
|
// not intended for instantiation
|
||||||
private HistoryUtils() {
|
private HistoryUtils() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fromXml(@Nullable String xml, @Nonnull List<CalculatorHistoryState> historyItems) {
|
public static void fromXml(@Nullable String xml, @Nonnull List<CalculatorHistoryState> historyItems) {
|
||||||
if (xml != null) {
|
if (xml != null) {
|
||||||
final Serializer serializer = new Persister();
|
final Serializer serializer = new Persister();
|
||||||
try {
|
try {
|
||||||
final History history = serializer.read(History.class, xml);
|
final History history = serializer.read(History.class, xml);
|
||||||
for (CalculatorHistoryState historyItem : history.getHistoryItems()) {
|
for (CalculatorHistoryState historyItem : history.getHistoryItems()) {
|
||||||
historyItems.add(historyItem);
|
historyItems.add(historyItem);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String toXml(@Nonnull List<CalculatorHistoryState> historyItems) {
|
public static String toXml(@Nonnull List<CalculatorHistoryState> historyItems) {
|
||||||
final History history = new History();
|
final History history = new History();
|
||||||
for (CalculatorHistoryState historyState : historyItems) {
|
for (CalculatorHistoryState historyState : historyItems) {
|
||||||
if (historyState.isSaved()) {
|
if (historyState.isSaved()) {
|
||||||
history.getHistoryItems().add(historyState);
|
history.getHistoryItems().add(historyState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringWriter xml = new StringWriter();
|
final StringWriter xml = new StringWriter();
|
||||||
final Serializer serializer = new Persister();
|
final Serializer serializer = new Persister();
|
||||||
try {
|
try {
|
||||||
serializer.write(history, xml);
|
serializer.write(history, xml);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return xml.toString();
|
return xml.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 serso aka se.solovyev
|
* Copyright 2013 serso aka se.solovyev
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* Contact details
|
* Contact details
|
||||||
*
|
*
|
||||||
* Email: se.solovyev@gmail.com
|
* Email: se.solovyev@gmail.com
|
||||||
* Site: http://se.solovyev.org
|
* Site: http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.jscl;
|
package org.solovyev.android.calculator.jscl;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.CalculatorParseException;
|
import org.solovyev.android.calculator.CalculatorParseException;
|
||||||
import org.solovyev.android.calculator.text.TextProcessor;
|
import org.solovyev.android.calculator.text.TextProcessor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/6/11
|
* Date: 10/6/11
|
||||||
* Time: 9:48 PM
|
* Time: 9:48 PM
|
||||||
*/
|
*/
|
||||||
class FromJsclNumericTextProcessor implements TextProcessor<String, Generic> {
|
class FromJsclNumericTextProcessor implements TextProcessor<String, Generic> {
|
||||||
|
|
||||||
public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor();
|
public static final FromJsclNumericTextProcessor instance = new FromJsclNumericTextProcessor();
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String process(@Nonnull Generic numeric) throws CalculatorParseException {
|
public String process(@Nonnull Generic numeric) throws CalculatorParseException {
|
||||||
return numeric.toString().replace("*", "");
|
return numeric.toString().replace("*", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 161 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user