Fix too light and too dark colors in editor/display

This commit is contained in:
serso 2016-01-07 20:22:28 +01:00
parent 40390b537d
commit 781f3d5648
2 changed files with 10 additions and 39 deletions

View File

@ -26,47 +26,31 @@ import android.graphics.Typeface;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.BaseNumberBuilder; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorEngine;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.LiteNumberBuilder;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.NumberBuilder;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.text.TextProcessorEditorResult; import org.solovyev.android.calculator.text.TextProcessorEditorResult;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
/**
* User: serso
* Date: 10/12/11
* Time: 9:47 PM
*/
public class TextHighlighter implements TextProcessor<TextProcessorEditorResult, String> { public class TextHighlighter implements TextProcessor<TextProcessorEditorResult, String> {
private final int red; private final int red;
private final int green; private final int green;
private final int blue; private final int blue;
private final boolean formatNumber; private final boolean formatNumber;
private final boolean dark; private final int dark;
public TextHighlighter(int color, boolean formatNumber) { public TextHighlighter(int color, boolean formatNumber) {
this.formatNumber = formatNumber; this.formatNumber = formatNumber;
//this.red = Color.red(baseColor);
red = red(color); red = red(color);
//this.green = Color.green(baseColor);
green = green(color); green = green(color);
//this.blue = Color.blue(baseColor);
blue = blue(color); blue = blue(color);
dark = isDark(red, green, blue); dark = isDark(red, green, blue) ? 1 : -1;
} }
private static int blue(int color) { private static int blue(int color) {
@ -195,13 +179,7 @@ public class TextHighlighter implements TextProcessor<TextProcessorEditorResult,
} }
private int getColor(int group, int groupsCount) { private int getColor(int group, int groupsCount) {
int offset = ((int) (255 * 0.8)) * group / (groupsCount + 1); final int offset = (int) (dark * 255 * 0.6) * group / (groupsCount + 1);
if (!dark) {
offset = -offset;
}
// for tests:
// int result = Color.rgb(BASE_COLOUR_RED_COMPONENT - offset, BASE_COLOUR_GREEN_COMPONENT - offset, BASE_COLOUR_BLUE_COMPONENT - offset);
return (0xFF << 24) | ((red + offset) << 16) | ((green + offset) << 8) | (blue + offset); return (0xFF << 24) | ((red + offset) << 16) | ((green + offset) << 8) | (blue + offset);
} }

View File

@ -38,15 +38,9 @@ import android.text.SpannableStringBuilder;
import android.text.SpannedString; import android.text.SpannedString;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorButton;
import org.solovyev.android.calculator.CalculatorDisplayViewState;
import org.solovyev.android.calculator.CalculatorEditorViewState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.Preferences.SimpleTheme; import org.solovyev.android.calculator.Preferences.SimpleTheme;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -54,9 +48,7 @@ import javax.annotation.Nullable;
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT; import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_DISPLAY_STATE_CHANGED; import static org.solovyev.android.calculator.CalculatorBroadcaster.*;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_STATE_CHANGED;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_THEME_CHANGED;
import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent; import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent;
public class CalculatorWidget extends AppWidgetProvider { public class CalculatorWidget extends AppWidgetProvider {
@ -218,11 +210,12 @@ public class CalculatorWidget extends AppWidgetProvider {
final SpannableStringBuilder result; final SpannableStringBuilder result;
// inject cursor // inject cursor
if (unspan) { if (unspan) {
result = new SpannableStringBuilder();
final CharSequence beforeCursor = text.subSequence(0, selection); final CharSequence beforeCursor = text.subSequence(0, selection);
final CharSequence afterCursor = text.subSequence(selection, text.length());
result = new SpannableStringBuilder();
result.append(unspan(beforeCursor)); result.append(unspan(beforeCursor));
result.append(getCursorString(context)); result.append(getCursorString(context));
final CharSequence afterCursor = text.subSequence(selection, text.length());
result.append(unspan(afterCursor)); result.append(unspan(afterCursor));
} else { } else {
result = new SpannableStringBuilder(text); result = new SpannableStringBuilder(text);