degrees + fix for tests
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.ParseException;
|
||||
@@ -26,9 +25,12 @@ public class TextHighlighter implements TextProcessor<String> {
|
||||
|
||||
public TextHighlighter(int baseColor) {
|
||||
this.color = baseColor;
|
||||
this.colorRed = Color.red(baseColor);
|
||||
this.colorGreen = Color.green(baseColor);
|
||||
this.colorBlue = Color.blue(baseColor);
|
||||
//this.colorRed = Color.red(baseColor);
|
||||
this.colorRed = (baseColor >> 16) & 0xFF;
|
||||
//this.colorGreen = Color.green(baseColor);
|
||||
this.colorGreen = (color >> 8) & 0xFF;
|
||||
//this.colorBlue = Color.blue(baseColor);
|
||||
this.colorBlue = color & 0xFF;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -49,8 +49,7 @@ public class Functions {
|
||||
allPrefix = functions;
|
||||
}
|
||||
|
||||
public final static String FACT = "!";
|
||||
public final static String DEGREE = "°";
|
||||
|
||||
public static final List<String> allPostfix = Arrays.asList(FACT, DEGREE);
|
||||
public static final List<String> allPostfix = Arrays.asList(DEGREE);
|
||||
}
|
||||
|
@@ -43,7 +43,20 @@ public enum MathType {
|
||||
}
|
||||
},
|
||||
|
||||
postfix_function(400, true, false, Functions.allPostfix),
|
||||
postfix_function(400, true, false, Functions.allPostfix) {
|
||||
@Override
|
||||
protected String getSubstitute(@NotNull String match) {
|
||||
final String result;
|
||||
|
||||
if ( match.equals(Functions.DEGREE)) {
|
||||
result = PI + "/180";
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
},
|
||||
unary_operation(500, false, false, "-", "=", "!"),
|
||||
binary_operation(600, false, false, "-", "+", "*", "×", "∙", "/", "^") {
|
||||
@Override
|
||||
|
@@ -14,7 +14,7 @@ import android.widget.LinearLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.view.widgets.NumberPicker;
|
||||
import org.solovyev.common.GenericIntervalMapper;
|
||||
import org.solovyev.common.NumberIntervalMapper;
|
||||
import org.solovyev.common.utils.Interval;
|
||||
import org.solovyev.common.utils.Mapper;
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.solovyev.common.utils.Mapper;
|
||||
*/
|
||||
public class NumberPickerDialogPreference extends AbstractDialogPreference<Integer> implements NumberPicker.OnChangedListener {
|
||||
|
||||
private static final NumberIntervalMapper<Integer> INTEGER_NUMBER_INTERVAL_MAPPER = new NumberIntervalMapper<Integer>(Integer.class);
|
||||
|
||||
@NotNull
|
||||
private NumberPicker numberPicker;
|
||||
|
||||
@@ -35,7 +37,7 @@ public class NumberPickerDialogPreference extends AbstractDialogPreference<Integ
|
||||
super(context, attrs, null, false);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
boundaries = new GenericIntervalMapper<Integer>(getMapper()).parseValue(attrs.getAttributeValue(localNameSpace, "boundaries"));
|
||||
boundaries = INTEGER_NUMBER_INTERVAL_MAPPER.parseValue(attrs.getAttributeValue(localNameSpace, "boundaries"));
|
||||
|
||||
createPreferenceView();
|
||||
}
|
||||
@@ -75,17 +77,7 @@ public class NumberPickerDialogPreference extends AbstractDialogPreference<Integ
|
||||
@NotNull
|
||||
@Override
|
||||
protected Mapper<Integer> getMapper() {
|
||||
return new Mapper<Integer>() {
|
||||
@Override
|
||||
public String formatValue(@Nullable Integer value) throws IllegalArgumentException {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parseValue(@Nullable String value) throws IllegalArgumentException {
|
||||
return Integer.valueOf(value);
|
||||
}
|
||||
};
|
||||
return INTEGER_NUMBER_INTERVAL_MAPPER.getMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,7 +6,6 @@
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import android.util.Log;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.utils.*;
|
||||
@@ -35,13 +34,16 @@ public abstract class AbstractIntervalMapper<T> implements Mapper<Interval<T>> {
|
||||
|
||||
@Override
|
||||
public Interval<T> parseValue(@Nullable String s) throws IllegalArgumentException {
|
||||
Log.d(AbstractIntervalMapper.class.getName(), "Parsing: " + s);
|
||||
//Log.d(AbstractIntervalMapper.class.getName(), "Parsing: " + s);
|
||||
final List<T> list = CollectionsUtils.split(s, ";", getParser());
|
||||
|
||||
assert list.size() == 2;
|
||||
return new IntervalImpl<T>(list.get(0), list.get(1));
|
||||
return newInstance(list.get(0), list.get(1));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Interval<T> newInstance(@Nullable T left, @Nullable T right);
|
||||
|
||||
@NotNull
|
||||
protected abstract Parser<T> getParser();
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import org.solovyev.common.utils.Parser;
|
||||
* Date: 9/26/11
|
||||
* Time: 10:45 PM
|
||||
*/
|
||||
public class GenericIntervalMapper<T> extends AbstractIntervalMapper<T> {
|
||||
public abstract class GenericIntervalMapper<T> extends AbstractIntervalMapper<T> {
|
||||
|
||||
@NotNull
|
||||
private final Mapper<T> mapper;
|
||||
@@ -36,4 +36,9 @@ public class GenericIntervalMapper<T> extends AbstractIntervalMapper<T> {
|
||||
protected Parser<T> getParser() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Mapper<T> getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@
|
||||
package org.solovyev.common;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.common.utils.Interval;
|
||||
import org.solovyev.common.utils.NumberInterval;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -18,4 +21,10 @@ public class NumberIntervalMapper<T extends Number> extends GenericIntervalMappe
|
||||
public NumberIntervalMapper(@NotNull Class<T> clazz) {
|
||||
super(new NumberMapper<T>(clazz));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Interval<T> newInstance(@Nullable T left, @Nullable T right) {
|
||||
return new NumberInterval<T>(left, right);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user