Search in sources :

Example 1 with VirtualKeyboardInterface

use of com.codename1.impl.VirtualKeyboardInterface in project CodenameOne by codenameone.

the class AndroidImplementation method init.

@Override
public void init(Object m) {
    if (m instanceof CodenameOneActivity) {
        setContext(null);
        setActivity((CodenameOneActivity) m);
    } else {
        setActivity(null);
        setContext((Context) m);
    }
    instance = this;
    if (getActivity() != null && getActivity().hasUI()) {
        if (!hasActionBar()) {
            try {
                getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
            } catch (Exception e) {
            // Log.d("Codename One", "No idea why this throws a Runtime Error", e);
            }
        } else {
            getActivity().invalidateOptionsMenu();
            try {
                getActivity().requestWindowFeature(Window.FEATURE_ACTION_BAR);
                getActivity().requestWindowFeature(Window.FEATURE_PROGRESS);
                if (android.os.Build.VERSION.SDK_INT >= 21) {
                    // WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
                    getActivity().getWindow().addFlags(-2147483648);
                }
            } catch (Exception e) {
            // Log.d("Codename One", "No idea why this throws a Runtime Error", e);
            }
            NotifyActionBar notify = new NotifyActionBar(getActivity(), false);
            notify.run();
        }
        if (statusBarHidden) {
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            getActivity().getWindow().setStatusBarColor(android.graphics.Color.TRANSPARENT);
        }
        if (Display.getInstance().getProperty("StatusbarHidden", "").equals("true")) {
            getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        if (Display.getInstance().getProperty("KeepScreenOn", "").equals("true")) {
            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
        if (Display.getInstance().getProperty("DisableScreenshots", "").equals("true")) {
            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
        }
        if (m instanceof CodenameOneActivity) {
            ((CodenameOneActivity) m).setDefaultIntentResultListener(this);
            ((CodenameOneActivity) m).setIntentResultListener(this);
        }
        /**
         * translate our default font height depending on the screen density.
         * this is required for new high resolution devices. otherwise
         * everything looks awfully small.
         *
         * we use our default font height value of 16 and go from there. i
         * thought about using new Paint().getTextSize() for this value but if
         * some new version of android suddenly returns values already tranlated
         * to the screen then we might end up with too large fonts. the
         * documentation is not very precise on that.
         */
        final int defaultFontPixelHeight = 16;
        this.defaultFontHeight = this.translatePixelForDPI(defaultFontPixelHeight);
        this.defaultFont = (CodenameOneTextPaint) ((NativeFont) this.createFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM)).font;
        Display.getInstance().setTransitionYield(-1);
        initSurface();
        /**
         * devices are extremely sensitive so dragging should start a little
         * later than suggested by default implementation.
         */
        this.setDragStartPercentage(1);
        VirtualKeyboardInterface vkb = new AndroidKeyboard(this);
        Display.getInstance().registerVirtualKeyboard(vkb);
        Display.getInstance().setDefaultVirtualKeyboard(vkb);
        InPlaceEditView.endEdit();
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        if (nativePeers.size() > 0) {
            for (int i = 0; i < nativePeers.size(); i++) {
                ((AndroidImplementation.AndroidPeer) nativePeers.elementAt(i)).init();
            }
        }
    } else {
        /**
         * translate our default font height depending on the screen density.
         * this is required for new high resolution devices. otherwise
         * everything looks awfully small.
         *
         * we use our default font height value of 16 and go from there. i
         * thought about using new Paint().getTextSize() for this value but if
         * some new version of android suddenly returns values already tranlated
         * to the screen then we might end up with too large fonts. the
         * documentation is not very precise on that.
         */
        final int defaultFontPixelHeight = 16;
        this.defaultFontHeight = this.translatePixelForDPI(defaultFontPixelHeight);
        this.defaultFont = (CodenameOneTextPaint) ((NativeFont) this.createFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM)).font;
    }
    HttpURLConnection.setFollowRedirects(false);
    CookieHandler.setDefault(null);
}
Also used : VirtualKeyboardInterface(com.codename1.impl.VirtualKeyboardInterface) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Paint(android.graphics.Paint)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Paint (android.graphics.Paint)1 VirtualKeyboardInterface (com.codename1.impl.VirtualKeyboardInterface)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1