mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-02-05 19:51:34 -05:00
fix non proper scale of space key on low dpi
This commit is contained in:
@@ -1061,17 +1061,17 @@ public class LeanbackKeyboardContainer {
|
||||
}
|
||||
|
||||
public void setSelectorToFocus(Rect rect, boolean overestimateWidth, boolean overestimateHeight, boolean animate) {
|
||||
if (this.mSelector.getWidth() != 0 && this.mSelector.getHeight() != 0 && rect.width() != 0 && rect.height() != 0) {
|
||||
if (mSelector.getWidth() != 0 && mSelector.getHeight() != 0 && rect.width() != 0 && rect.height() != 0) {
|
||||
final float width = (float) rect.width();
|
||||
final float height = (float) rect.height();
|
||||
float heightOver = height;
|
||||
if (overestimateHeight) {
|
||||
heightOver = height * this.mOverestimate;
|
||||
heightOver = height * mOverestimate;
|
||||
}
|
||||
|
||||
float widthOver = width;
|
||||
if (overestimateWidth) {
|
||||
widthOver = width * this.mOverestimate;
|
||||
widthOver = width * mOverestimate;
|
||||
}
|
||||
|
||||
float deltaY = heightOver;
|
||||
@@ -1083,13 +1083,13 @@ public class LeanbackKeyboardContainer {
|
||||
|
||||
final float x = rect.exactCenterX() - deltaX / 2.0F;
|
||||
final float y = rect.exactCenterY() - deltaY / 2.0F;
|
||||
this.mSelectorAnimation.cancel();
|
||||
mSelectorAnimation.cancel();
|
||||
if (animate) {
|
||||
this.mSelectorAnimation.reset();
|
||||
this.mSelectorAnimation.setAnimationBounds(x, y, deltaX, deltaY);
|
||||
this.mSelector.startAnimation(this.mSelectorAnimation);
|
||||
mSelectorAnimation.reset();
|
||||
mSelectorAnimation.setAnimationBounds(x, y, deltaX, deltaY);
|
||||
mSelector.startAnimation(mSelectorAnimation);
|
||||
} else {
|
||||
this.mSelectorAnimation.setValues(x, y, deltaX, deltaY);
|
||||
mSelectorAnimation.setValues(x, y, deltaX, deltaY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
private int mBaseMiniKbIndex = -1;
|
||||
private final int mClickAnimDur;
|
||||
private final float mClickedScale;
|
||||
private final float mSquareIconScaleFactor;
|
||||
private int mColCount;
|
||||
private View mCurrentFocusView;
|
||||
private boolean mFocusClicked;
|
||||
@@ -141,6 +142,7 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
mShiftState = 0;
|
||||
mFocusedScale = res.getFraction(R.fraction.focused_scale, 1, 1);
|
||||
mClickedScale = res.getFraction(R.fraction.clicked_scale, 1, 1);
|
||||
mSquareIconScaleFactor = res.getFraction(R.fraction.square_icon_scale_factor, 1, 1);
|
||||
mClickAnimDur = res.getInteger(R.integer.clicked_anim_duration);
|
||||
mUnfocusStartDelay = res.getInteger(R.integer.unfocused_anim_delay);
|
||||
mInactiveMiniKbAlpha = res.getInteger(R.integer.inactive_mini_kb_alpha);
|
||||
@@ -179,8 +181,8 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
label = key.label.toString();
|
||||
}
|
||||
|
||||
if (Log.isLoggable("LbKbView", Log.DEBUG)) {
|
||||
Log.d("LbKbView", "LABEL: " + key.label + "->" + label);
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "LABEL: " + key.label + "->" + label);
|
||||
}
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(key.width, key.height, Config.ARGB_8888);
|
||||
@@ -202,15 +204,20 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
int iconWidth = key.icon.getIntrinsicWidth();
|
||||
int iconHeight = key.icon.getIntrinsicHeight();
|
||||
// NOTE: fix non proper scale of space key on low dpi
|
||||
|
||||
if (key.width > key.height) { // wide key fix (space key)
|
||||
iconWidth = key.width;
|
||||
int iconWidth = key.width; // originally used key.icon.getIntrinsicWidth();
|
||||
int iconHeight = key.height; // originally used key.icon.getIntrinsicHeight();
|
||||
|
||||
if (key.width == key.height) {
|
||||
int newSize = Math.round(key.width * mSquareIconScaleFactor);
|
||||
iconWidth = newSize;
|
||||
iconHeight = newSize;
|
||||
}
|
||||
|
||||
int dx = (key.width - padding.left - padding.right - iconWidth) / 2 + padding.left;
|
||||
int dy = (key.height - padding.top - padding.bottom - iconHeight) / 2 + padding.top;
|
||||
|
||||
canvas.translate((float) dx, (float) dy);
|
||||
key.icon.setBounds(0, 0, iconWidth, iconHeight);
|
||||
key.icon.draw(canvas);
|
||||
@@ -224,8 +231,12 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
paint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
|
||||
}
|
||||
|
||||
canvas.drawText(label, (float) ((key.width - padding.left - padding.right) / 2 + padding.left), (float) ((key.height - padding.top - padding.bottom) /
|
||||
2) + (paint.getTextSize() - paint.descent()) / 2.0F + (float) padding.top, paint);
|
||||
canvas.drawText(
|
||||
label,
|
||||
(float) ((key.width - padding.left - padding.right) / 2 + padding.left),
|
||||
(float) ((key.height - padding.top - padding.bottom) / 2) + (paint.getTextSize() - paint.descent()) / 2.0F + (float) padding.top,
|
||||
paint
|
||||
);
|
||||
paint.setShadowLayer(0.0F, 0.0F, 0.0F, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.voice;
|
||||
|
||||
import android.animation.TimeAnimator;
|
||||
import android.animation.TimeAnimator.TimeListener;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -10,8 +9,8 @@ import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import androidx.core.content.ContextCompat;
|
||||
@@ -49,10 +48,10 @@ public class BitmapSoundLevelView extends View {
|
||||
@TargetApi(16)
|
||||
public BitmapSoundLevelView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
this.mEmptyPaint = new Paint();
|
||||
mEmptyPaint = new Paint();
|
||||
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.BitmapSoundLevelView, defStyleAttr, 0);
|
||||
this.mEnableBackgroundColor = styledAttrs.getColor(R.styleable.BitmapSoundLevelView_enabledBackgroundColor, Color.parseColor("#66FFFFFF"));
|
||||
this.mDisableBackgroundColor = styledAttrs.getColor(R.styleable.BitmapSoundLevelView_disabledBackgroundColor, -1);
|
||||
mEnableBackgroundColor = styledAttrs.getColor(R.styleable.BitmapSoundLevelView_enabledBackgroundColor, Color.parseColor("#66FFFFFF"));
|
||||
mDisableBackgroundColor = styledAttrs.getColor(R.styleable.BitmapSoundLevelView_disabledBackgroundColor, -1);
|
||||
boolean primaryLevelEnabled = false;
|
||||
boolean peakLevelEnabled = false;
|
||||
int primaryLevelId = 0;
|
||||
@@ -67,130 +66,126 @@ public class BitmapSoundLevelView extends View {
|
||||
peakLevelEnabled = true;
|
||||
}
|
||||
|
||||
this.mCenterTranslationX = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_levelsCenterX, 0);
|
||||
this.mCenterTranslationY = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_levelsCenterY, 0);
|
||||
this.mMinimumLevelSize = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_minLevelRadius, 0);
|
||||
mCenterTranslationX = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_levelsCenterX, 0);
|
||||
mCenterTranslationY = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_levelsCenterY, 0);
|
||||
mMinimumLevelSize = styledAttrs.getDimensionPixelOffset(R.styleable.BitmapSoundLevelView_minLevelRadius, 0);
|
||||
styledAttrs.recycle();
|
||||
if (primaryLevelEnabled) {
|
||||
this.mPrimaryLevel = BitmapFactory.decodeResource(this.getResources(), primaryLevelId);
|
||||
mPrimaryLevel = BitmapFactory.decodeResource(getResources(), primaryLevelId);
|
||||
} else {
|
||||
this.mPrimaryLevel = null;
|
||||
mPrimaryLevel = null;
|
||||
}
|
||||
|
||||
if (peakLevelEnabled) {
|
||||
this.mTrailLevel = BitmapFactory.decodeResource(this.getResources(), trailLevelId);
|
||||
mTrailLevel = BitmapFactory.decodeResource(getResources(), trailLevelId);
|
||||
} else {
|
||||
this.mTrailLevel = null;
|
||||
mTrailLevel = null;
|
||||
}
|
||||
|
||||
this.mPaint = new Paint();
|
||||
this.mDestRect = new Rect();
|
||||
this.mEmptyPaint.setFilterBitmap(true);
|
||||
this.mLevelSource = new SpeechLevelSource();
|
||||
this.mLevelSource.setSpeechLevel(0);
|
||||
this.mAnimator = new TimeAnimator();
|
||||
this.mAnimator.setRepeatCount(-1);
|
||||
this.mAnimator.setTimeListener(new TimeListener() {
|
||||
public void onTimeUpdate(TimeAnimator animator, long l, long l1) {
|
||||
BitmapSoundLevelView.this.invalidate();
|
||||
}
|
||||
});
|
||||
mPaint = new Paint();
|
||||
mDestRect = new Rect();
|
||||
mEmptyPaint.setFilterBitmap(true);
|
||||
mLevelSource = new SpeechLevelSource();
|
||||
mLevelSource.setSpeechLevel(0);
|
||||
mAnimator = new TimeAnimator();
|
||||
mAnimator.setRepeatCount(-1);
|
||||
mAnimator.setTimeListener((animation, totalTime, deltaTime) -> invalidate());
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
private void startAnimator() {
|
||||
if (!this.mAnimator.isStarted()) {
|
||||
this.mAnimator.start();
|
||||
if (!mAnimator.isStarted()) {
|
||||
mAnimator.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
private void stopAnimator() {
|
||||
this.mAnimator.cancel();
|
||||
mAnimator.cancel();
|
||||
}
|
||||
|
||||
private void updateAnimatorState() {
|
||||
if (this.isEnabled()) {
|
||||
this.startAnimator();
|
||||
if (isEnabled()) {
|
||||
startAnimator();
|
||||
} else {
|
||||
this.stopAnimator();
|
||||
stopAnimator();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
this.updateAnimatorState();
|
||||
updateAnimatorState();
|
||||
}
|
||||
|
||||
protected void onDetachedFromWindow() {
|
||||
this.stopAnimator();
|
||||
stopAnimator();
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
public void onDraw(Canvas canvas) {
|
||||
if (this.isEnabled()) {
|
||||
canvas.drawColor(this.mEnableBackgroundColor);
|
||||
final int level = this.mLevelSource.getSpeechLevel();
|
||||
if (level > this.mPeakLevel) {
|
||||
this.mPeakLevel = level;
|
||||
this.mPeakLevelCountDown = 25;
|
||||
} else if (this.mPeakLevelCountDown == 0) {
|
||||
this.mPeakLevel = Math.max(0, this.mPeakLevel - 2);
|
||||
if (isEnabled()) {
|
||||
canvas.drawColor(mEnableBackgroundColor);
|
||||
final int level = mLevelSource.getSpeechLevel();
|
||||
if (level > mPeakLevel) {
|
||||
mPeakLevel = level;
|
||||
mPeakLevelCountDown = 25;
|
||||
} else if (mPeakLevelCountDown == 0) {
|
||||
mPeakLevel = Math.max(0, mPeakLevel - 2);
|
||||
} else {
|
||||
--this.mPeakLevelCountDown;
|
||||
--mPeakLevelCountDown;
|
||||
}
|
||||
|
||||
if (level > this.mCurrentVolume) {
|
||||
this.mCurrentVolume += (level - this.mCurrentVolume) / 4;
|
||||
if (level > mCurrentVolume) {
|
||||
mCurrentVolume += (level - mCurrentVolume) / 4;
|
||||
} else {
|
||||
this.mCurrentVolume = (int) ((float) this.mCurrentVolume * 0.95F);
|
||||
mCurrentVolume = (int) ((float) mCurrentVolume * 0.95F);
|
||||
}
|
||||
|
||||
final int centerX = this.mCenterTranslationX + this.getWidth() / 2;
|
||||
final int centerY = this.mCenterTranslationY + this.getWidth() / 2;
|
||||
final int centerX = mCenterTranslationX + getWidth() / 2;
|
||||
final int centerY = mCenterTranslationY + getWidth() / 2;
|
||||
int size;
|
||||
if (this.mTrailLevel != null) {
|
||||
size = (centerX - this.mMinimumLevelSize) * this.mPeakLevel / 100 + this.mMinimumLevelSize;
|
||||
this.mDestRect.set(centerX - size, centerY - size, centerX + size, centerY + size);
|
||||
canvas.drawBitmap(this.mTrailLevel, (Rect) null, this.mDestRect, this.mEmptyPaint);
|
||||
if (mTrailLevel != null) {
|
||||
size = (centerX - mMinimumLevelSize) * mPeakLevel / 100 + mMinimumLevelSize;
|
||||
mDestRect.set(centerX - size, centerY - size, centerX + size, centerY + size);
|
||||
canvas.drawBitmap(mTrailLevel, null, mDestRect, mEmptyPaint);
|
||||
}
|
||||
|
||||
if (this.mPrimaryLevel != null) {
|
||||
size = (centerX - this.mMinimumLevelSize) * this.mCurrentVolume / 100 + this.mMinimumLevelSize;
|
||||
this.mDestRect.set(centerX - size, centerY - size, centerX + size, centerY + size);
|
||||
canvas.drawBitmap(this.mPrimaryLevel, (Rect) null, this.mDestRect, this.mEmptyPaint);
|
||||
this.mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_background));
|
||||
this.mPaint.setStyle(Style.FILL);
|
||||
canvas.drawCircle((float) centerX, (float) centerY, (float) (this.mMinimumLevelSize - 3), this.mPaint);
|
||||
if (mPrimaryLevel != null) {
|
||||
size = (centerX - mMinimumLevelSize) * mCurrentVolume / 100 + mMinimumLevelSize;
|
||||
mDestRect.set(centerX - size, centerY - size, centerX + size, centerY + size);
|
||||
canvas.drawBitmap(mPrimaryLevel, null, mDestRect, mEmptyPaint);
|
||||
mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_background));
|
||||
mPaint.setStyle(Style.FILL);
|
||||
canvas.drawCircle((float) centerX, (float) centerY, (float) (mMinimumLevelSize - 3), mPaint);
|
||||
}
|
||||
|
||||
if (this.mTrailLevel != null && this.mPrimaryLevel != null) {
|
||||
this.mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_levels_guideline));
|
||||
this.mPaint.setStyle(Style.STROKE);
|
||||
canvas.drawCircle((float) centerX, (float) centerY, (float) (centerX - 13), this.mPaint);
|
||||
if (mTrailLevel != null && mPrimaryLevel != null) {
|
||||
mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_levels_guideline));
|
||||
mPaint.setStyle(Style.STROKE);
|
||||
canvas.drawCircle((float) centerX, (float) centerY, (float) (centerX - 13), mPaint);
|
||||
}
|
||||
|
||||
} else {
|
||||
canvas.drawColor(this.mDisableBackgroundColor);
|
||||
canvas.drawColor(mDisableBackgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void onWindowFocusChanged(boolean var1) {
|
||||
super.onWindowFocusChanged(var1);
|
||||
if (var1) {
|
||||
this.updateAnimatorState();
|
||||
updateAnimatorState();
|
||||
} else {
|
||||
this.stopAnimator();
|
||||
stopAnimator();
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(boolean var1) {
|
||||
super.setEnabled(var1);
|
||||
this.updateAnimatorState();
|
||||
updateAnimatorState();
|
||||
}
|
||||
|
||||
public void setLevelSource(SpeechLevelSource var1) {
|
||||
this.mLevelSource = var1;
|
||||
mLevelSource = var1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<fraction name="square_icon_scale_factor">85.0%</fraction>
|
||||
<fraction name="clicked_scale">88.0%</fraction>
|
||||
<fraction name="focused_scale">119.99817%</fraction>
|
||||
<fraction name="alpha_in">100.0%</fraction>
|
||||
|
||||
Reference in New Issue
Block a user