@@ -394,30 +394,52 @@ protected void onDrawKeyBackground(@NonNull final Key key, @NonNull final Canvas
394394
395395 final boolean isSelected = (key .getCode () == KeyCode .SHIFT && key .isLocked ())
396396 || (key .getCode () == KeyCode .TOGGLE_SELECTION_MODE && KeyboardActionListenerImpl .sPersistentSelectionModeActive );
397- boolean hasFilter = false ;
398- if (isSelected ) {
399- background .setColorFilter (Color .argb (0x80 , 0 , 0 , 0 ), PorterDuff .Mode .SRC_ATOP );
400- hasFilter = true ;
401- } else if (key .getCode () == KeyCode .ALPHA ) {
402- background .setColorFilter (Color .argb (0x1C , 0 , 0 , 0 ), PorterDuff .Mode .SRC_ATOP );
403- hasFilter = true ;
397+
398+ boolean hasCustomTint = false ;
399+ if (key .getCode () == KeyCode .ALPHA ) {
400+ final int accent = mColors .get (ColorType .ACTION_KEY_BACKGROUND );
401+ final int funcBg = mColors .get (ColorType .FUNCTIONAL_KEY_BACKGROUND );
402+ final int blended = blend (accent , funcBg , 0.15f );
403+ androidx .core .graphics .drawable .DrawableCompat .setTint (background , blended );
404+ hasCustomTint = true ;
404405 } else if (key .getCode () == KeyCode .TOGGLE_SELECTION_MODE ) {
405- background .setColorFilter (Color .argb (0x28 , 0 , 0 , 0 ), PorterDuff .Mode .SRC_ATOP );
406- hasFilter = true ;
406+ final int accent = mColors .get (ColorType .ACTION_KEY_BACKGROUND );
407+ final int funcBg = mColors .get (ColorType .FUNCTIONAL_KEY_BACKGROUND );
408+ final int blended = blend (accent , funcBg , 0.25f );
409+ androidx .core .graphics .drawable .DrawableCompat .setTint (background , blended );
410+ hasCustomTint = true ;
407411 } else if (key .getCode () == KeyCode .DELETE ) {
408- background .setColorFilter (Color .argb (0x38 , 0 , 0 , 0 ), PorterDuff .Mode .SRC_ATOP );
409- hasFilter = true ;
412+ final int accent = mColors .get (ColorType .ACTION_KEY_BACKGROUND );
413+ final int funcBg = mColors .get (ColorType .FUNCTIONAL_KEY_BACKGROUND );
414+ final int blended = blend (accent , funcBg , 0.35f );
415+ androidx .core .graphics .drawable .DrawableCompat .setTint (background , blended );
416+ hasCustomTint = true ;
417+ }
418+
419+ if (isSelected ) {
420+ background .setColorFilter (Color .argb (0x80 , 0 , 0 , 0 ), PorterDuff .Mode .SRC_ATOP );
410421 }
411422
412423 background .draw (canvas );
413424
414- if (hasFilter ) {
425+ if (isSelected ) {
415426 background .clearColorFilter ();
416427 }
428+ if (hasCustomTint ) {
429+ mColors .setColor (background , ColorType .FUNCTIONAL_KEY_BACKGROUND );
430+ }
417431
418432 canvas .translate (-bgX , -bgY );
419433 }
420434
435+ private static int blend (int c1 , int c2 , float ratio ) {
436+ float inverseRatio = 1f - ratio ;
437+ float r = Color .red (c1 ) * ratio + Color .red (c2 ) * inverseRatio ;
438+ float g = Color .green (c1 ) * ratio + Color .green (c2 ) * inverseRatio ;
439+ float b = Color .blue (c1 ) * ratio + Color .blue (c2 ) * inverseRatio ;
440+ return Color .rgb ((int ) r , (int ) g , (int ) b );
441+ }
442+
421443 // Draw key top visuals.
422444 protected void onDrawKeyTopVisuals (@ NonNull final Key key , @ NonNull final Canvas canvas ,
423445 @ NonNull final Paint paint , @ NonNull final KeyDrawParams params ) {
0 commit comments