Clean up adjustHeights()

The methods in `kmwnative.ts` and `kmwembedded.ts` are nearly identical.

Also added a few pixels to the Android OSK dimensions.
This commit is contained in:
Darcy Wong 2019-03-18 15:45:23 +07:00
parent 6a6b455e48
commit 94a9ab4a00
4 changed files with 26 additions and 24 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Dimens for Default or Portrait (Tablet 7") -->
<resources>
<dimen name="keyboard_height">305dp</dimen>
<dimen name="keyboard_height">375dp</dimen>
<dimen name="key_width">58.5dp</dimen>
<dimen name="key_height">73.5dp</dimen>
<dimen name="popup_arrow_width">32dp</dimen>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Dimens for Default or Portrait (Phone) -->
<resources>
<dimen name="keyboard_height">205dp</dimen>
<dimen name="keyboard_height">275dp</dimen>
<dimen name="key_width">34.25dp</dimen>
<dimen name="key_height">49.25dp</dimen>
<dimen name="popup_arrow_width">21dp</dimen>

View file

@ -111,43 +111,42 @@ namespace com.keyman.osk {
* Adjust the absolute height of each keyboard element after a rotation - modified for KMEI, 13/11/14
*
**/
VisualKeyboard.prototype.adjustHeights=function(this: VisualKeyboard): boolean {
VisualKeyboard.prototype.adjustHeights = function(this: VisualKeyboard): boolean {
let keyman = com.keyman.singleton;
let osk = keyman.osk;
let _Box = osk._Box;
let oskManager = keyman.osk;
let _Box = oskManager._Box;
let util = keyman.util;
let device = util.device;
if(!_Box || !_Box.childNodes || !this.kbdDiv || !this.kbdDiv.firstChild || !this.kbdDiv.firstChild.firstChild.childNodes) {
if(!_Box || !this.kbdDiv || !this.kbdDiv.firstChild || !this.kbdDiv.firstChild.firstChild.childNodes) {
return false;
}
var layers=_Box.childNodes.item(1).firstChild.childNodes,
var layers=this.kbdDiv.firstChild.childNodes,
nRows=layers[0].childNodes.length,
oskHeight=osk.getHeight(),
rowHeight=Math.floor(oskHeight/nRows),
oskHeight=oskManager.getHeight(),
bannerHeight=oskManager.banner.height,
rowHeight=Math.floor((oskHeight-bannerHeight)/(nRows == 0 ? 1 : nRows)),
nLayer,nRow,rs,keys,nKeys,nKey,key,ks,j,pad=4,fs=1.0;
if(device.OS == 'Android' && 'devicePixelRatio' in window) {
rowHeight = rowHeight/window.devicePixelRatio;
}
oskHeight=nRows*rowHeight+bannerHeight;
oskHeight=nRows*rowHeight;
var b: HTMLElement = osk._Box, bs=b.style;
var b: HTMLElement = _Box, bs=b.style;
bs.height=bs.maxHeight=(oskHeight+3)+'px';
// sort out childNodes keymanweb_banner_bar and visualOSK
b = <HTMLElement> b.childNodes.item(1).firstChild;
bs=b.style;
bs.height=bs.maxHeight=(oskHeight+3)+'px';
pad = Math.round(0.15*rowHeight);
var resizeLabels=(device.OS == 'iOS' && device.formFactor == 'phone' && util.landscapeView());
for(nLayer=0;nLayer<layers.length; nLayer++) {
// Check the heights of each row, in case different layers have different row counts.
nRows=layers[nLayer].childNodes.length;
(<HTMLElement> layers[nLayer]).style.height=(oskHeight+3)+'px';
(<HTMLElement> layers[nLayer]).style.height=(oskHeight-bannerHeight+3)+'px';
for(nRow=0; nRow<nRows; nRow++) {
rs=(<HTMLElement> layers[nLayer].childNodes[nRow]).style;
@ -158,7 +157,7 @@ namespace com.keyman.osk {
for(nKey=0;nKey<nKeys;nKey++) {
key=keys[nKey];
// Must set the height of the text DIV, not the label (if any)
for(j=0;j<key.childNodes.length;j++) {
for(j=0; j<key.childNodes.length; j++) {
if(util.hasClass(key.childNodes[j],'kmw-key')) {
break;
}
@ -166,9 +165,11 @@ namespace com.keyman.osk {
ks=key.childNodes[j].style;
ks.bottom=rs.bottom;
ks.height=ks.minHeight=(rowHeight-pad)+'px';
// Rescale keycap labels on iPhone (iOS 7)
if(resizeLabels && (j > 0)) key.childNodes[0].style.fontSize='6px';
if(resizeLabels && (j > 0)) {
key.childNodes[0].style.fontSize='6px';
}
}
}
}

View file

@ -373,7 +373,7 @@ namespace com.keyman.osk {
let device = util.device;
if(!_Box || !this.kbdDiv || !this.kbdDiv.firstChild || !this.kbdDiv.firstChild.firstChild.childNodes) {
return;
return false;
}
var layers=this.kbdDiv.firstChild.childNodes,
@ -381,18 +381,19 @@ namespace com.keyman.osk {
oskHeight=oskManager.getHeight(),
bannerHeight=oskManager.banner.height,
rowHeight=Math.floor((oskHeight-bannerHeight)/(nRows == 0 ? 1 : nRows)),
nLayer,nRow,rs,keys,nKeys,nKey,key,ks,j,pad,fs=1.0;
nLayer,nRow,rs,keys,nKeys,nKey,key,ks,j,pad=4,fs=1.0;
if(device.OS == 'Android' && 'devicePixelRatio' in window) {
rowHeight = rowHeight/window.devicePixelRatio;
}
oskHeight=nRows*rowHeight+bannerHeight;
var b: HTMLElement = _Box,bs=b.style;
var b: HTMLElement = _Box, bs=b.style;
bs.height=bs.maxHeight=(oskHeight+3)+'px';
b = <HTMLElement> b.childNodes.item(1).firstChild;
bs=b.style;
bs.height=bs.maxHeight=(oskHeight+3)+'px';
pad = Math.round(0.15*rowHeight);
// TODO: Logically, this should be needed for Android, too - may need to be changed for the next version!
if(device.OS == 'iOS') {
@ -405,10 +406,8 @@ namespace com.keyman.osk {
for(nLayer=0;nLayer<layers.length; nLayer++) {
// Check the heights of each row, in case different layers have different row counts.
nRows=layers[nLayer].childNodes.length;
rowHeight=Math.floor((oskHeight-bannerHeight)/(nRows == 0 ? 1 : nRows));
(<HTMLElement> layers[nLayer]).style.height=(oskHeight-bannerHeight+3)+'px';
pad = Math.round(0.15*rowHeight);
(<HTMLElement> layers[nLayer]).style.height=(oskHeight+3)+'px';
for(nRow=0; nRow<nRows; nRow++) {
rs=(<HTMLElement> layers[nLayer].childNodes[nRow]).style;
rs.bottom=(nRows-nRow-1)*rowHeight+1+'px';
@ -437,6 +436,8 @@ namespace com.keyman.osk {
}
}
}
return true;
};
// /**