Search in sources :

Example 1 with VirtualKeyboard

use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.

the class MicroActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    MenuInflater inflater = getMenuInflater();
    if (current == null) {
        inflater.inflate(R.menu.midlet_displayable, menu);
        return true;
    }
    boolean hasCommands = current.countCommands() > 0;
    Menu group;
    if (hasCommands) {
        inflater.inflate(R.menu.midlet_common, menu);
        group = menu.getItem(0).getSubMenu();
    } else {
        group = menu;
    }
    inflater.inflate(R.menu.midlet_displayable, group);
    if (current instanceof Canvas) {
        if (actionBarEnabled) {
            inflater.inflate(R.menu.midlet_canvas, menu);
        } else {
            inflater.inflate(R.menu.midlet_canvas_no_bar, group);
        }
        if (inputMethodManager == null) {
            menu.findItem(R.id.action_ime_keyboard).setVisible(false);
        }
        VirtualKeyboard vk = ContextHolder.getVk();
        if (vk != null) {
            inflater.inflate(R.menu.midlet_vk, group);
            if (vk.getLayoutEditMode() == VirtualKeyboard.LAYOUT_EOF) {
                menu.findItem(R.id.action_layout_edit_finish).setVisible(false);
            }
        }
    }
    if (!hasCommands) {
        return true;
    }
    for (Command cmd : current.getCommands()) {
        menu.add(Menu.NONE, cmd.hashCode(), Menu.NONE, cmd.getAndroidLabel());
    }
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) Command(javax.microedition.lcdui.Command) Canvas(javax.microedition.lcdui.Canvas) Menu(android.view.Menu) VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard)

Example 2 with VirtualKeyboard

use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.

the class MicroLoader method applyConfiguration.

void applyConfiguration() {
    try {
        // Apply configuration to the launching MIDlet
        if (params.showKeyboard) {
            ContextHolder.setVk(new VirtualKeyboard(params));
        } else {
            ContextHolder.setVk(null);
        }
        setProperties();
        final String[] propLines = params.systemProperties.split("\n");
        for (String line : propLines) {
            String[] prop = line.split(":[ ]*", 2);
            if (prop.length == 2) {
                System.setProperty(prop[0], prop[1]);
                MidletSystem.setProperty(prop[0], prop[1]);
            }
        }
        try {
            Charset.forName(System.getProperty("microedition.encoding"));
        } catch (Exception e) {
            System.setProperty("microedition.encoding", "ISO-8859-1");
            MidletSystem.setProperty("microedition.encoding", "ISO-8859-1");
        }
        int screenWidth = params.screenWidth;
        int screenHeight = params.screenHeight;
        Displayable.setVirtualSize(screenWidth, screenHeight);
        Canvas.setBackgroundColor(params.screenBackgroundColor);
        Canvas.setScale(params.screenGravity, params.screenScaleType, params.screenScaleRatio);
        Canvas.setFilterBitmap(params.screenFilter);
        EventQueue.setImmediate(params.immediateMode);
        Canvas.setGraphicsMode(params.graphicsMode, params.parallelRedrawScreen);
        ShaderInfo shader = params.shader;
        if (shader != null) {
            shader.dir = workDir + Config.SHADERS_DIR;
        }
        Canvas.setShaderFilter(shader);
        Canvas.setForceFullscreen(params.forceFullscreen);
        Canvas.setShowFps(params.showFps);
        Canvas.setLimitFps(params.fpsLimit);
        Font.applySettings(params);
        KeyMapper.setKeyMapping(params);
        Canvas.setHasTouchInput(params.touchInput);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ShaderInfo(ru.playsoftware.j2meloader.config.ShaderInfo) VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with VirtualKeyboard

use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.

the class MicroActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme();
    super.onCreate(savedInstanceState);
    ContextHolder.setCurrentActivity(this);
    setContentView(R.layout.activity_micro);
    OverlayView overlayView = findViewById(R.id.vOverlay);
    layout = findViewById(R.id.displayable_container);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    actionBarEnabled = sp.getBoolean(PREF_TOOLBAR, false);
    statusBarEnabled = sp.getBoolean(PREF_STATUSBAR, false);
    if (sp.getBoolean(PREF_KEEP_SCREEN, false)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    ContextHolder.setVibration(sp.getBoolean(PREF_VIBRATION, true));
    Intent intent = getIntent();
    appName = intent.getStringExtra(KEY_MIDLET_NAME);
    Uri data = intent.getData();
    if (data == null) {
        showErrorDialog("Invalid intent: app path is null");
        return;
    }
    String appPath = data.toString();
    microLoader = new MicroLoader(this, appPath);
    if (!microLoader.init()) {
        Config.startApp(this, appName, appPath, true);
        finish();
        return;
    }
    microLoader.applyConfiguration();
    VirtualKeyboard vk = ContextHolder.getVk();
    int orientation = microLoader.getOrientation();
    if (vk != null) {
        vk.setView(overlayView);
        overlayView.addLayer(vk);
        if (vk.isPhone()) {
            orientation = ORIENTATION_PORTRAIT;
        }
    }
    setOrientation(orientation);
    menuKey = microLoader.getMenuKeyCode();
    inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    try {
        loadMIDlet();
    } catch (Exception e) {
        e.printStackTrace();
        showErrorDialog(e.toString());
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard) Uri(android.net.Uri) OverlayView(javax.microedition.lcdui.overlay.OverlayView) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException)

Example 4 with VirtualKeyboard

use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.

the class MicroActivity method handleVkOptions.

private void handleVkOptions(int id) {
    VirtualKeyboard vk = ContextHolder.getVk();
    if (id == R.id.action_layout_edit_mode) {
        vk.setLayoutEditMode(VirtualKeyboard.LAYOUT_KEYS);
        Toast.makeText(this, R.string.layout_edit_mode, Toast.LENGTH_SHORT).show();
    } else if (id == R.id.action_layout_scale_mode) {
        vk.setLayoutEditMode(VirtualKeyboard.LAYOUT_SCALES);
        Toast.makeText(this, R.string.layout_scale_mode, Toast.LENGTH_SHORT).show();
    } else if (id == R.id.action_layout_edit_finish) {
        vk.setLayoutEditMode(VirtualKeyboard.LAYOUT_EOF);
        Toast.makeText(this, R.string.layout_edit_finished, Toast.LENGTH_SHORT).show();
        showSaveVkAlert(false);
    } else if (id == R.id.action_layout_switch) {
        showSetLayoutDialog();
    } else if (id == R.id.action_hide_buttons) {
        showHideButtonDialog();
    }
}
Also used : VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard)

Example 5 with VirtualKeyboard

use of javax.microedition.lcdui.keyboard.VirtualKeyboard in project J2ME-Loader by nikita36078.

the class MicroActivity method showSetLayoutDialog.

private void showSetLayoutDialog() {
    final VirtualKeyboard vk = ContextHolder.getVk();
    AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.layout_switch).setSingleChoiceItems(R.array.PREF_VK_TYPE_ENTRIES, vk.getLayout(), null).setPositiveButton(android.R.string.ok, (d, w) -> {
        vk.setLayout(((AlertDialog) d).getListView().getCheckedItemPosition());
        if (vk.isPhone()) {
            setOrientation(ORIENTATION_PORTRAIT);
        } else {
            setOrientation(microLoader.getOrientation());
        }
    });
    builder.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard)

Aggregations

VirtualKeyboard (javax.microedition.lcdui.keyboard.VirtualKeyboard)8 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (androidx.appcompat.app.AlertDialog)3 IOException (java.io.IOException)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 RectF (android.graphics.RectF)1 Uri (android.net.Uri)1 SparseBooleanArray (android.util.SparseBooleanArray)1 TypedValue (android.util.TypedValue)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 ListView (android.widget.ListView)1 AppCompatCheckBox (androidx.appcompat.widget.AppCompatCheckBox)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Canvas (javax.microedition.lcdui.Canvas)1 Command (javax.microedition.lcdui.Command)1 OverlayView (javax.microedition.lcdui.overlay.OverlayView)1 ShaderInfo (ru.playsoftware.j2meloader.config.ShaderInfo)1