Skip to content

Commit

Permalink
Tweak light themes to be less blurry
Browse files Browse the repository at this point in the history
This adjusts the icon-inverting algorithm, and turns off shadows
which didn't look good on the light themes.
  • Loading branch information
Klaus Weidner committed Nov 25, 2018
1 parent a8cce74 commit 2f5cb7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Paint.Align;
Expand Down Expand Up @@ -277,6 +278,14 @@ public interface OnKeyboardActionListener {
/* package */ static Method sSetRenderMode;
private static int sPrevRenderMode = -1;

private static final float[] INVERTING_MATRIX = {
-1.f, 0, 0, 0, 255, // Red
0, -1.f, 0, 0, 255, // Green
0, 0, -1.f, 0, 255, // Blue
0, 0, 0, 1.f, 0, // Alpha
};
private final ColorMatrixColorFilter mInvertingColorFilter = new ColorMatrixColorFilter(INVERTING_MATRIX);

private final UIHandler mHandler = new UIHandler();

class UIHandler extends Handler {
Expand Down Expand Up @@ -915,15 +924,7 @@ private void onBufferDraw(Canvas canvas) {
final Key[] keys = mKeys;
final Key invalidKey = mInvalidatedKey;

ColorFilter iconColorFilter = null;
ColorFilter shadowColorFilter = null;
if (mRecolorSymbols) {
// TODO: cache these?
iconColorFilter = new PorterDuffColorFilter(
mKeyTextColor, PorterDuff.Mode.SRC_ATOP);
shadowColorFilter = new PorterDuffColorFilter(
mShadowColor, PorterDuff.Mode.SRC_ATOP);
}
ColorFilter iconColorFilter = mRecolorSymbols ? mInvertingColorFilter : null;

boolean drawSingleKey = false;
if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
Expand Down Expand Up @@ -1100,25 +1101,9 @@ private void onBufferDraw(Canvas canvas) {
canvas.translate(drawableX, drawableY);
icon.setBounds(0, 0, drawableWidth, drawableHeight);

if (shadowColorFilter != null && iconColorFilter != null) {
// Re-color the icon to match the theme, and draw a shadow for it manually.
//
// This doesn't seem to look quite right, possibly a problem with using
// premultiplied icon images?

// Try EmbossMaskFilter, and/or offset? Configurable?
BlurMaskFilter shadowBlur = new BlurMaskFilter(mShadowRadius, BlurMaskFilter.Blur.OUTER);
Paint blurPaint = new Paint();
blurPaint.setMaskFilter(shadowBlur);
Bitmap tmpIcon = Bitmap.createBitmap(key.width, key.height, Bitmap.Config.ARGB_8888);
Canvas tmpCanvas = new Canvas(tmpIcon);
icon.draw(tmpCanvas);
int[] offsets = new int[2];
Bitmap shadowBitmap = tmpIcon.extractAlpha(blurPaint, offsets);
Paint shadowPaint = new Paint();
shadowPaint.setColorFilter(shadowColorFilter);
canvas.drawBitmap(shadowBitmap, offsets[0], offsets[1], shadowPaint);

if (iconColorFilter != null) {
// Re-color the icon to match the theme. Skip the shadow since it tends to not
// look right.
icon.setColorFilter(iconColorFilter);
icon.draw(canvas);
icon.setColorFilter(null);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/input_material_light.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
android:background="@drawable/keyboard_background_lxx_light"
latin:symbolColorScheme="@color/key_text_color_lxx_light"
latin:recolorSymbols="true"
latin:shadowRadius="0"
latin:shadowColor="#ff777777"
latin:keyTextColor="@color/key_text_color_lxx_light"
latin:keyHintColor="@color/key_hint_letter_color_lxx_light"

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/input_stone_bold.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
latin:keyHintColor="#FF777777"
latin:keyCursorColor="@color/latinkeyboard_dim_color_black"
latin:shadowColor="@color/latinkeyboard_key_color_white"
latin:shadowRadius="0"
latin:keyTextStyle="bold"
latin:symbolColorScheme="black"
latin:recolorSymbols="true"
Expand Down

0 comments on commit 2f5cb7e

Please sign in to comment.