Search in sources :

Example 51 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class TextArea method initRowString.

private void initRowString() {
    if (!Display.getInstance().isEdt()) {
        if (rowStrings == null) {
            rowStrings = new ArrayList();
            rowStrings.add(getText());
            return;
        }
    }
    Style style = getUnselectedStyle();
    rowStrings = new ArrayList();
    widthForRowCalculations = getWidth() - style.getHorizontalPadding();
    // to allow subclasses to override it
    if (isSingleLineTextArea()) {
        rowStrings.add(getText());
        return;
    }
    if (widthForRowCalculations <= 0) {
        rowStrings.add(getText());
        setShouldCalcPreferredSize(true);
        return;
    }
    if (text == null || text.equals("")) {
        return;
    }
    Font font = style.getFont();
    if (actAsLabel && text.length() <= columns && text.indexOf('\n') < 0) {
        int w = font.stringWidth(text);
        if (w <= getWidth()) {
            if (rowStrings == null) {
                rowStrings = new ArrayList();
                rowStrings.add(getText());
                return;
            } else {
                rowStrings.clear();
                rowStrings.add(getText());
                return;
            }
        }
    }
    char[] text = preprocess(getText());
    int rows = this.rows;
    if (growByContent) {
        rows = Math.max(rows, getLines());
    }
    int charWidth = font.charWidth(widestChar);
    Style selectedStyle = getSelectedStyle();
    if (selectedStyle.getFont() != style.getFont()) {
        int cw = selectedStyle.getFont().charWidth(widestChar);
        if (cw > charWidth) {
            charWidth = cw;
            font = selectedStyle.getFont();
        }
    }
    style = getStyle();
    int tPadding = style.getHorizontalPadding();
    int textAreaWidth = getWidth() - tPadding;
    /*if(textAreaWidth <= 0) {
            if(columns < 1) {
                textAreaWidth = Math.min(Display.getInstance().getDisplayWidth() - tPadding, getText().length()) * charWidth;
            } else {
                textAreaWidth = Math.min(Display.getInstance().getDisplayWidth() - tPadding, columns) * charWidth;
            }
        }*/
    if (textAreaWidth <= charWidth) {
        if (!isInitialized()) {
            rowStrings.add(getText());
        } else {
            // special case for the edge case of "no room".
            // Its important since sometimes this case occurs in the GUI builder by accident
            int tlen = text.length;
            for (int iter = 0; iter < tlen; iter++) {
                rowStrings.add("" + text[iter]);
            }
        }
        return;
    }
    int minCharactersInRow = Math.max(1, textAreaWidth / charWidth);
    int from = 0;
    int to = from + minCharactersInRow;
    int textLength = text.length;
    String rowText = null;
    int i, spaceIndex;
    // width to accommodate it
    if (textLength / minCharactersInRow > Math.max(2, rows)) {
        textAreaWidth -= getUIManager().getLookAndFeel().getVerticalScrollWidth();
        textAreaWidth -= charWidth / 2;
    }
    String unsupported = getUnsupportedChars();
    /*
        iteration over the string using indexes, from - the beginning of the row , to - end of a row
        for each row we will try to search for a "space" character at the end of the row ( row is text area available width)
        indorder to improve the efficiency we do not search an entire row but we start from minCharactersInRow which indicates
        what is the minimum amount of characters that can feet in the text area width.
        if we dont find we will go backwards and search for the first space available,
        if there is no space in the entire row we will cut the line inorder to fit in.
         */
    // Don't rely on the fact that short text has no newline character. we always have to parse the text.
    to = Math.max(Math.min(textLength - 1, to), 0);
    while (to < textLength) {
        if (to > textLength) {
            to = textLength;
        }
        spaceIndex = -1;
        rowText = "";
        int maxLength = to;
        if (useStringWidth || actAsLabel) {
            // fix for an infinite loop issue: http://forums.java.net/jive/thread.jspa?messageID=482802
            // currentRowWidth = 0;
            String currentRow = "";
            // search for "space" character at close as possible to the end of the row
            for (i = to; i < textLength && fastCharWidthCheck(text, from, i - from + 1, textAreaWidth, charWidth, font); i++) {
                char c = text[i];
                /*if(updateRowWidth(c, font) >= textAreaWidth) {
                        break;
                    }*/
                currentRow += c;
                if (font.stringWidth(currentRow) >= textAreaWidth) {
                    break;
                }
                if (unsupported.indexOf(c) > -1) {
                    text[i] = ' ';
                    c = ' ';
                }
                if (c == ' ' || c == '\n') {
                    spaceIndex = i;
                    // newline has been found. We can end the loop here as the line cannot grow more
                    if (c == '\n')
                        break;
                }
                maxLength++;
            }
        } else {
            currentRowWidth = 0;
            if (to != from) {
                currentRowWidth = font.charsWidth(text, from, to - from);
            }
            // search for "space" character at close as possible to the end of the row
            for (i = to; i < textLength; i++) {
                char c = text[i];
                if (updateRowWidth(c, font) >= textAreaWidth) {
                    break;
                }
                if (unsupported.indexOf(c) > -1) {
                    text[i] = ' ';
                    c = ' ';
                }
                if (c == ' ' || c == '\n') {
                    spaceIndex = i;
                    // newline has been found. We can end the loop here as the line cannot grow more
                    if (c == '\n')
                        break;
                }
                maxLength++;
            }
        }
        // also if space is next character (in the next row) we can cut the line
        if (i == textLength || text[i] == ' ' || text[i] == '\n') {
            spaceIndex = i;
        }
        // if we found space in the limit width of the row (searched only from minCharactersInRow)
        if (spaceIndex != -1) {
            // make sure that if we have a newline character before the end of the line we should
            // break there instead
            int newLine = indexOf(text, '\n', from, spaceIndex - from);
            if (newLine > -1 && newLine < spaceIndex) {
                spaceIndex = newLine;
            }
            rowText = new String(text, from, spaceIndex - from);
            from = spaceIndex + 1;
        } else // if there is no space from minCharactersInRow to limit need to search backwards
        {
            for (i = to; spaceIndex == -1 && i >= from; i--) {
                char chr = text[i];
                if (chr == ' ' || chr == '\n' || chr == '\t') {
                    spaceIndex = i;
                    // don't forget to search for line breaks in the
                    // remaining part. otherwise we overlook possible
                    // line breaks!
                    int newLine = indexOf(text, '\n', from, i - from);
                    if (newLine > -1 && newLine < spaceIndex) {
                        spaceIndex = newLine;
                    }
                    rowText = new String(text, from, spaceIndex - from);
                    from = spaceIndex + 1;
                }
            }
            if (spaceIndex == -1) {
                // from = to + 1;
                if (maxLength <= 0) {
                    maxLength = 1;
                }
                spaceIndex = maxLength;
                rowText = new String(text, from, spaceIndex - from);
                from = spaceIndex;
            }
        }
        if (rowText.length() == 0) {
            // This happens due to a race condition or something, no idea why???
            if (textAreaWidth <= charWidth) {
                if (!isInitialized()) {
                    rowStrings.add(getText());
                } else {
                    // special case for the edge case of "no room".
                    // Its important since sometimes this case occurs in the GUI builder by accident
                    int tlen = text.length;
                    for (int iter = 0; iter < tlen; iter++) {
                        rowStrings.add("" + text[iter]);
                    }
                }
                return;
            }
        }
        rowStrings.add(rowText);
        // adding minCharactersInRow doesn't work if what is left is less
        // then minCharactersInRow
        // +minCharactersInRow;
        to = from;
    }
    if (text[text.length - 1] == '\n') {
        rowStrings.add("");
    }
}
Also used : ArrayList(java.util.ArrayList) Style(com.codename1.ui.plaf.Style)

Example 52 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class AndroidImplementation method captureAudio.

public void captureAudio(final ActionListener response) {
    if (!checkForPermission(Manifest.permission.RECORD_AUDIO, "This is required to record the audio")) {
        return;
    }
    try {
        final Form current = Display.getInstance().getCurrent();
        final File temp = File.createTempFile("mtmp", ".3gpp");
        temp.deleteOnExit();
        if (recorder != null) {
            recorder.release();
        }
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
        recorder.setOutputFile(temp.getAbsolutePath());
        final Form recording = new Form("Recording");
        recording.setTransitionInAnimator(CommonTransitions.createEmpty());
        recording.setTransitionOutAnimator(CommonTransitions.createEmpty());
        recording.setLayout(new BorderLayout());
        recorder.prepare();
        recorder.start();
        final Label time = new Label("00:00");
        time.getAllStyles().setAlignment(Component.CENTER);
        Font f = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
        f = f.derive(getDisplayHeight() / 10, Font.STYLE_PLAIN);
        time.getAllStyles().setFont(f);
        recording.addComponent(BorderLayout.CENTER, time);
        recording.registerAnimated(new Animation() {

            long current = System.currentTimeMillis();

            long zero = current;

            int sec = 0;

            public boolean animate() {
                long now = System.currentTimeMillis();
                if (now - current > 1000) {
                    current = now;
                    sec++;
                    return true;
                }
                return false;
            }

            public void paint(Graphics g) {
                int seconds = sec % 60;
                int minutes = sec / 60;
                String secStr = seconds < 10 ? "0" + seconds : "" + seconds;
                String minStr = minutes < 10 ? "0" + minutes : "" + minutes;
                String txt = minStr + ":" + secStr;
                time.setText(txt);
            }
        });
        Container south = new Container(new com.codename1.ui.layouts.GridLayout(1, 2));
        Command cancel = new Command("Cancel") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(null);
            }
        };
        recording.setBackCommand(cancel);
        south.add(new com.codename1.ui.Button(cancel));
        south.add(new com.codename1.ui.Button(new Command("Save") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(new ActionEvent(temp.getAbsolutePath()));
            }
        }));
        recording.addComponent(BorderLayout.SOUTH, south);
        recording.show();
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start audio recording");
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) IOException(java.io.IOException) Font(com.codename1.ui.Font) Paint(android.graphics.Paint) BorderLayout(com.codename1.ui.layouts.BorderLayout) com.codename1.ui(com.codename1.ui) Animation(com.codename1.ui.animations.Animation) MediaRecorder(android.media.MediaRecorder) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 53 with Font

use of com.codename1.ui.Font 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)

Example 54 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class ResetableTextWatcher method startEditing.

/**
 * Start editing the given text-area
 * This method is executed on the UI thread, so UI manipulation is safe here.
 * @param activity Current running activity
 * @param textArea The TextAreaData instance that wraps the CN1 TextArea that our internal EditText needs to overlap.  We use
 *                 a TextAreaData so that the text area properties can be accessed off the EDT safely.
 * @param codenameOneInputType One of the input type constants in com.codename1.ui.TextArea
 * @param initialText The text that appears in the Codename One text are before the call to startEditing
 * @param isEditedFieldSwitch if true, then special case for async edit mode - the native editing is already active, no need to show
 *                            native field, just change the connected field
 */
private synchronized void startEditing(Activity activity, TextAreaData textArea, String initialText, int codenameOneInputType, final boolean isEditedFieldSwitch) {
    int txty = lastTextAreaY = textArea.getAbsoluteY() + textArea.getScrollY();
    int txtx = lastTextAreaX = textArea.getAbsoluteX() + textArea.getScrollX();
    lastTextAreaWidth = textArea.getWidth();
    lastTextAreaHeight = textArea.getHeight();
    int paddingTop = 0;
    int paddingLeft = textArea.paddingLeft;
    int paddingRight = textArea.paddingRight;
    int paddingBottom = textArea.paddingBottom;
    if (textArea.isTextField) {
        switch(textArea.getVerticalAlignment()) {
            case Component.BOTTOM:
                paddingTop = textArea.getHeight() - textArea.paddingBottom - textArea.fontHeight;
                break;
            case Component.CENTER:
                paddingTop = textArea.getHeight() / 2 - textArea.fontHeight / 2;
                break;
            default:
                paddingTop = textArea.paddingTop;
                break;
        }
    } else {
        paddingTop = textArea.paddingTop;
    }
    int id = activity.getResources().getIdentifier("cn1Style", "attr", activity.getApplicationInfo().packageName);
    if (!isEditedFieldSwitch) {
        mEditText = new EditView(activity, textArea.textArea, this, id);
    } else {
        mEditText.switchToTextArea(textArea.textArea);
    }
    if (textArea.getClientProperty("blockCopyPaste") != null || Display.getInstance().getProperty("blockCopyPaste", "false").equals("true")) {
        // The code below is taken from this stackoverflow answer: http://stackoverflow.com/a/22756538/756809
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

                @Override
                public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                    menu.clear();
                }
            });
        } else {
            mEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
        }
    } else if (isEditedFieldSwitch) {
        // reset copy-paste protection
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(null);
        } else {
            mEditText.setCustomSelectionActionModeCallback(null);
        }
    }
    if (!isEditedFieldSwitch) {
        mEditText.addTextChangedListener(mEditText.mTextWatcher);
    }
    mEditText.setBackgroundDrawable(null);
    mEditText.setFocusableInTouchMode(true);
    mEditLayoutParams = new FrameLayout.LayoutParams(0, 0);
    // Set the appropriate gravity so that the left and top margins will be
    // taken into account
    mEditLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    mEditLayoutParams.setMargins(txtx, txty, 0, 0);
    mEditLayoutParams.width = textArea.getWidth();
    mEditLayoutParams.height = textArea.getHeight();
    mEditText.setLayoutParams(mEditLayoutParams);
    if (textArea.isRTL()) {
        mEditText.setGravity(Gravity.RIGHT | Gravity.TOP);
    } else {
        mEditText.setGravity(Gravity.LEFT | Gravity.TOP);
    }
    mEditText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    Component nextDown = textArea.nextDown;
    boolean imeOptionTaken = true;
    int ime = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    if (textArea.isSingleLineTextArea()) {
        if (textArea.getClientProperty("searchField") != null) {
            mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEARCH);
        } else {
            if (textArea.getClientProperty("sendButton") != null) {
                mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEND);
            } else {
                if (textArea.getClientProperty("goButton") != null) {
                    mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_GO);
                } else {
                    if (textArea.isTextField && textArea.getDoneListener() != null) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                    } else if (nextDown != null && nextDown instanceof TextArea && ((TextArea) nextDown).isEditable() && ((TextArea) nextDown).isEnabled()) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_NEXT);
                    } else {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                        imeOptionTaken = false;
                    }
                }
            }
        }
    }
    mEditText.setSingleLine(textArea.isSingleLineTextArea());
    mEditText.setAdapter((ArrayAdapter<String>) null);
    mEditText.setText(initialText);
    if (!textArea.isSingleLineTextArea() && textArea.textArea.isGrowByContent() && textArea.textArea.getGrowLimit() > -1) {
        defaultMaxLines = mEditText.getMaxLines();
        mEditText.setMaxLines(textArea.textArea.getGrowLimit());
    }
    if (textArea.nativeHintBool && textArea.getHint() != null) {
        mEditText.setHint(textArea.getHint());
    }
    if (!isEditedFieldSwitch) {
        addView(mEditText, mEditLayoutParams);
    }
    invalidate();
    setVisibility(VISIBLE);
    bringToFront();
    mEditText.requestFocus();
    Object nativeFont = textArea.nativeFont;
    if (nativeFont == null) {
        nativeFont = impl.getDefaultFont();
    }
    Paint p = (Paint) ((AndroidImplementation.NativeFont) nativeFont).font;
    mEditText.setTypeface(p.getTypeface());
    mEditText.setTextScaleX(p.getTextScaleX());
    mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, p.getTextSize());
    int fgColor = textArea.fgColor;
    mEditText.setTextColor(Color.rgb(fgColor >> 16, (fgColor & 0x00ff00) >> 8, (fgColor & 0x0000ff)));
    boolean password = false;
    if ((codenameOneInputType & TextArea.PASSWORD) == TextArea.PASSWORD) {
        codenameOneInputType = codenameOneInputType ^ TextArea.PASSWORD;
        password = true;
    }
    if (textArea.isSingleLineTextArea()) {
        mEditText.setInputType(getAndroidInputType(codenameOneInputType));
        // if not ime was explicity requested and this is a single line textfield of type ANY add the emoji keyboard.
        if (!imeOptionTaken && codenameOneInputType == TextArea.ANY) {
            mEditText.setInputType(getAndroidInputType(codenameOneInputType) | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
        }
        if (Display.getInstance().getProperty("andAddComma", "false").equals("true") && (codenameOneInputType & TextArea.DECIMAL) == TextArea.DECIMAL) {
            defaultKeyListener = mEditText.getKeyListener();
            mEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));
        }
    }
    if (password) {
        int type = mInputTypeMap.get(codenameOneInputType, InputType.TYPE_CLASS_TEXT);
        if ((type & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) == InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) {
            type = type ^ InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        }
        // turn off suggestions for passwords
        mEditText.setInputType(type | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        mEditText.setTransformationMethod(new MyPasswordTransformationMethod());
    }
    int maxLength = textArea.maxSize;
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
    mEditText.setFilters(FilterArray);
    mEditText.setSelection(mEditText.getText().length());
    showVirtualKeyboard(true);
    if (Boolean.FALSE.equals(textArea.getClientProperty("android.cursorVisible"))) {
        // This provides an imperfect workaround for this issue:
        // https://github.com/codenameone/CodenameOne/issues/2317
        // Blinking cursor causes text to disappear on some versions of android
        // Can't seem to find how to detect whether device is affected, so
        // just providing a client property to disable the blinking cursor
        // on a particular text field.
        mEditText.setCursorVisible(false);
    }
/*
        // Leaving this hack here for posterity.  It seems that this manually
        // blinking cursor causes the paste menu to disappear
        // https://github.com/codenameone/CodenameOne/issues/2147
        // Removing the hack below, fixes this issue.  And in the test device
        // I'm using the blinking of text doesn't seem to occur, so perhaps
        // it was fixed via other means.  Test device:
        // Name: Samsung Galaxy S3 (T-Mobile)
        //    OS: 4.3
        //    Manufacturer: Samsung
        //    Model: 4.3
        //    Chipset: armeabi-v7a 1512MHz
        //    Memory: 16000000000
        //    Heap: 256000000
        //    Display: 720 x 1280
        //
        // UPDATE Feb. 13, 2018:
        // This issue seems to be still present in some devices, but it isn't clear even
        // how to detect it.
        // Issue reported and reproduced here https://github.com/codenameone/CodenameOne/issues/2317
        // Issue has been observed in a Virtual Box installation with 5.1.1, but
        // cannot be reproduced in a Nexus 5 running 5.1.1.
        // 
        if (Build.VERSION.SDK_INT < 21) {
            // HACK!!!  On Android 4.4, it seems that the natural blinking cursor
            // causes text to disappear when it blinks.  Manually blinking the
            // cursor seems to work around this issue, so that's what we do here.
            // This issue is described here: http://stackoverflow.com/questions/41305052/textfields-content-disappears-during-typing?noredirect=1#comment69977316_41305052
            mEditText.setCursorVisible(false);
            final boolean[] cursorVisible = new boolean[]{false};
            if (cursorTimer != null) {
                cursorTimer.cancel();
            }
            cursorTimer = new Timer();
            cursorTimerTask = new TimerTask() {
                public void run() {
                    AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            EditView v = mEditText;
                            if (v != null) {
                                cursorVisible[0] = !cursorVisible[0];
                                v.setCursorVisible(cursorVisible[0]);
                            }
                        }
                    });

                }
            };
            cursorTimer.schedule(cursorTimerTask, 100, 500);
        }
        */
}
Also used : InputFilter(android.text.InputFilter) TextArea(com.codename1.ui.TextArea) ContextMenu(android.view.ContextMenu) MenuItem(android.view.MenuItem) Paint(android.graphics.Paint) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Paint(android.graphics.Paint) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu) Component(com.codename1.ui.Component)

Example 55 with Font

use of com.codename1.ui.Font in project CodenameOne by codenameone.

the class Canvas method applyPaint.

private void applyPaint(Paint paint, boolean forText) {
    // Log.p("Applyingn paint : "+paint);
    g.setColor(paint.getColor());
    int alpha = ColorUtil.alpha(paint.getColor());
    g.setAlpha(alpha);
    if (forText) {
        Font typeFace = paint.getTypeface();
        if (typeFace != null) {
            if (typeFace.getSize() != (int) paint.getTextSize()) {
                typeFace = typeFace.derive(paint.getTextSize(), Font.STYLE_PLAIN);
            }
            g.setFont(typeFace);
        } else {
            g.setFont(null);
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Aggregations

Font (com.codename1.ui.Font)30 Image (com.codename1.ui.Image)12 Hashtable (java.util.Hashtable)10 EditorFont (com.codename1.ui.EditorFont)8 Border (com.codename1.ui.plaf.Border)8 Component (com.codename1.ui.Component)7 Style (com.codename1.ui.plaf.Style)7 EncodedImage (com.codename1.ui.EncodedImage)6 TextArea (com.codename1.ui.TextArea)6 AnimationObject (com.codename1.ui.animations.AnimationObject)6 BufferedImage (java.awt.image.BufferedImage)6 IOException (java.io.IOException)6 java.awt (java.awt)5 Container (com.codename1.ui.Container)4 Dimension (com.codename1.ui.geom.Dimension)4 RoundBorder (com.codename1.ui.plaf.RoundBorder)4 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)4 ParseException (java.text.ParseException)4 Paint (android.graphics.Paint)3 EditorTTFFont (com.codename1.ui.EditorTTFFont)3