degrees + fix for tests

This commit is contained in:
serso
2011-10-23 14:11:33 +04:00
parent 4c59822396
commit e54ae2808d
13 changed files with 88 additions and 35 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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