use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.
the class MicroActivity method showHideButtonDialog.
private void showHideButtonDialog() {
final VirtualKeyboard vk = ContextHolder.getVk();
boolean[] states = vk.getKeysVisibility();
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.hide_buttons).setMultiChoiceItems(vk.getKeyNames(), states, null).setPositiveButton(android.R.string.ok, (dialog, which) -> {
ListView lv = ((AlertDialog) dialog).getListView();
SparseBooleanArray current = lv.getCheckedItemPositions();
for (int i = 0; i < current.size(); i++) {
if (states[current.keyAt(i)] != current.valueAt(i)) {
vk.setKeysVisibility(current);
showSaveVkAlert(true);
return;
}
}
});
builder.show();
}
use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.
the class MicroActivity method showSaveVkAlert.
private void showSaveVkAlert(boolean keepScreenPreferred) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.CONFIRMATION_REQUIRED);
builder.setMessage(R.string.pref_vk_save_alert);
builder.setNegativeButton(android.R.string.no, null);
AlertDialog dialog = builder.create();
final VirtualKeyboard vk = ContextHolder.getVk();
if (vk.isPhone()) {
AppCompatCheckBox cb = new AppCompatCheckBox(this);
cb.setText(R.string.opt_save_screen_params);
cb.setChecked(keepScreenPreferred);
TypedValue out = new TypedValue();
getTheme().resolveAttribute(R.attr.dialogPreferredPadding, out, true);
int paddingH = getResources().getDimensionPixelOffset(out.resourceId);
int paddingT = getResources().getDimensionPixelOffset(R.dimen.abc_dialog_padding_top_material);
dialog.setView(cb, paddingH, paddingT, paddingH, 0);
dialog.setButton(dialog.BUTTON_POSITIVE, getText(android.R.string.yes), (d, w) -> {
if (cb.isChecked()) {
vk.saveScreenParams();
}
vk.onLayoutChanged(VirtualKeyboard.TYPE_CUSTOM);
});
} else {
dialog.setButton(dialog.BUTTON_POSITIVE, getText(android.R.string.yes), (d, w) -> ContextHolder.getVk().onLayoutChanged(VirtualKeyboard.TYPE_CUSTOM));
}
dialog.show();
}
use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.
the class Canvas method updateSize.
/**
* Update the size and position of the virtual screen relative to the real one.
*/
public void updateSize() {
/*
* We turn the sizes of the virtual screen into the sizes of the visible canvas.
*
* At the same time, we take into account that one or both virtual sizes can be less
* than zero, which means auto-selection of this size so that the resulting canvas
* has the same aspect ratio as the actual screen of the device.
*/
int scaledDisplayHeight;
VirtualKeyboard vk = ContextHolder.getVk();
boolean isPhoneSkin = vk != null && vk.isPhone();
// if phone keyboard layout is active, then scale down the virtual screen
if (isPhoneSkin) {
scaledDisplayHeight = (int) (displayHeight - vk.getPhoneKeyboardHeight() - 1);
} else {
scaledDisplayHeight = displayHeight;
}
if (virtualWidth > 0) {
if (virtualHeight > 0) {
/*
* the width and height of the canvas are strictly set
*/
width = virtualWidth;
height = virtualHeight;
} else {
/*
* only the canvas width is set
* height is selected by the ratio of the real screen
*/
width = virtualWidth;
height = scaledDisplayHeight * virtualWidth / displayWidth;
}
} else {
if (virtualHeight > 0) {
/*
* only the canvas height is set
* width is selected by the ratio of the real screen
*/
width = displayWidth * virtualHeight / scaledDisplayHeight;
height = virtualHeight;
} else {
/*
* nothing is set - screen-sized canvas
*/
width = displayWidth;
height = scaledDisplayHeight;
}
}
/*
* calculate the maximum height
*/
maxHeight = height;
/*
* calculate the current height
*/
if (!fullscreen) {
height = (int) (height * FULLSCREEN_HEIGHT_RATIO);
}
/*
* We turn the size of the canvas into the size of the image
* that will be displayed on the screen of the device.
*/
switch(scaleType) {
case 0:
// without scaling
onWidth = width;
onHeight = height;
break;
case 1:
// try to fit in width
onWidth = displayWidth;
onHeight = height * displayWidth / width;
if (onHeight > scaledDisplayHeight) {
// if height is too big, then fit in height
onHeight = scaledDisplayHeight;
onWidth = width * scaledDisplayHeight / height;
}
break;
case 2:
// scaling without preserving the aspect ratio:
// just stretch the picture to full screen
onWidth = displayWidth;
onHeight = scaledDisplayHeight;
break;
}
onWidth = onWidth * scaleRatio / 100;
onHeight = onHeight * scaleRatio / 100;
int screenGravity = isPhoneSkin ? 1 : Canvas.screenGravity;
switch(screenGravity) {
case // left
0:
onX = 0;
onY = (displayHeight - onHeight) / 2;
break;
case // top
1:
onX = (displayWidth - onWidth) / 2;
onY = 0;
break;
case // center
2:
onX = (displayWidth - onWidth) / 2;
onY = (displayHeight - onHeight) / 2;
break;
case // right
3:
onX = displayWidth - onWidth;
onY = (displayHeight - onHeight) / 2;
break;
case // bottom
4:
onX = (displayWidth - onWidth) / 2;
onY = displayHeight - onHeight;
break;
}
RectF screen = new RectF(0, 0, displayWidth, displayHeight);
virtualScreen.set(onX, onY, onX + onWidth, onY + onHeight);
if (offscreen == null) {
offscreen = Image.createTransparentImage(width, maxHeight);
offscreenCopy = Image.createTransparentImage(width, maxHeight);
}
if (offscreen.getWidth() != width || offscreen.getHeight() != height) {
offscreen.setSize(width, height);
offscreenCopy.setSize(width, height);
}
offscreen.getSingleGraphics().reset();
offscreenCopy.getSingleGraphics().reset();
if (overlay != null) {
overlay.resize(screen, virtualScreen);
}
if (graphicsMode == 1) {
float gl = 2.0f * virtualScreen.left / displayWidth - 1.0f;
float gt = 1.0f - 2.0f * virtualScreen.top / displayHeight;
float gr = 2.0f * virtualScreen.right / displayWidth - 1.0f;
float gb = 1.0f - 2.0f * virtualScreen.bottom / displayHeight;
float th = (float) height / offscreen.getBitmap().getHeight();
float tw = (float) width / offscreen.getBitmap().getWidth();
renderer.updateSize(gl, gt, gr, gb, th, tw);
}
}
Aggregations