Commit MetaInfo

Revision85744ba5d1ea8ffa04b696a47a9fab888eb1ab38 (tree)
Time2021-10-30 09:42:14
AuthorAng Iongchun <ang@iong...>
CommiterAng Iongchun

Log Message

fix keyboard view for portrait to landscape switch

Change Summary

Incremental Difference

diff -r 52276d0da410 -r 85744ba5d1ea app/src/main/java/tw/iongchun/taigikbd/TKKeyboardView.java
--- a/app/src/main/java/tw/iongchun/taigikbd/TKKeyboardView.java Sat Oct 16 16:08:10 2021 +0800
+++ b/app/src/main/java/tw/iongchun/taigikbd/TKKeyboardView.java Sat Oct 30 08:42:14 2021 +0800
@@ -153,7 +153,7 @@
153153 gapX = (float)key.width / 20;
154154 gapY = (float)key.height / 20;
155155 radiusX = (float)key.width / 16;
156- radiusY = (float)key.width / 16;
156+ radiusY = (float)key.height / 16;
157157 }
158158 rectf.set(left + gapX, top + gapY, right - gapX, bottom - gapY);
159159 paint.setColor(theme.keyColor);
@@ -252,4 +252,37 @@
252252 this.iconColor = charColor;
253253 }
254254 }
255+
256+ // Fix portrait to landscape switch
257+ // TODO: also fix landscape to portrait switch
258+ // TODO: will fix KeyboardView one day...
259+
260+ private int originWidth = -1;
261+
262+ @Override
263+ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
264+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
265+ if (originWidth < 0)
266+ originWidth = getMeasuredWidth();
267+ int width = MeasureSpec.getSize(widthMeasureSpec);
268+ int height = getMeasuredHeight();
269+ setMeasuredDimension(width, height);
270+ }
271+
272+ @Override
273+ public void onSizeChanged(int newWidth, int newHeight, int oldWidth, int oldHeight) {
274+ super.onSizeChanged(newWidth, newHeight, oldWidth, oldHeight);
275+ if (newWidth == oldWidth || originWidth <= 0)
276+ return;
277+ int width = getWidth();
278+ if (width == originWidth)
279+ return;
280+ float ratioX = (float)newWidth / originWidth;
281+ for (Keyboard.Key key : getKeyboard().getKeys()) {
282+ if (key.width <= 0)
283+ continue;
284+ key.x = (int)((float)key.x * ratioX);
285+ key.width = (int)((float)key.width * ratioX);
286+ }
287+ }
255288 }
Show on old repository browser