Search in sources :

Example 31 with Display

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

the class BubbleTransition method initTransition.

@Override
public void initTransition() {
    Component source = getSource();
    Component destination = getDestination();
    int w = source.getWidth();
    int h = source.getHeight();
    // improper replace() calls, this may still be valid and shouldn't fail
    if (w <= 0 || h <= 0) {
        return;
    }
    Form sourceForm = source.getComponentForm();
    originSrc = findByName(sourceForm, componentName);
    Form destForm = destination.getComponentForm();
    originDest = findByName(destForm, componentName);
    Display d = Display.getInstance();
    if (getDestination() instanceof Dialog) {
        Dialog dlg = (Dialog) destination;
        // transparent image!
        destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
        Graphics g = destBuffer.getGraphics();
        Style stl = dlg.getDialogComponent().getStyle();
        byte bgt = stl.getBgTransparency();
        stl.setBgTransparency(0xff);
        drawDialogCmp(destBuffer.getGraphics(), dlg);
        stl.setBgTransparency(bgt & 0xff, true);
    } else if (getSource() instanceof Dialog) {
        Dialog dlg = (Dialog) source;
        // transparent image!
        destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
        Graphics g = destBuffer.getGraphics();
        Style stl = dlg.getDialogComponent().getStyle();
        byte bgt = stl.getBgTransparency();
        stl.setBgTransparency(0xff);
        drawDialogCmp(destBuffer.getGraphics(), dlg);
        stl.setBgTransparency(bgt & 0xff, true);
    } else {
        if (originDest != null) {
            destBuffer = createMutableImage(source.getWidth(), source.getHeight());
            paint(destBuffer.getGraphics(), source, -source.getAbsoluteX(), -source.getAbsoluteY());
        } else {
            destBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
            paint(destBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
        }
    }
    Component dest = getDestination();
    if (dest instanceof Dialog) {
        dest = getDialogParent(dest);
    }
    Component src = getSource();
    if (src instanceof Dialog) {
        src = getDialogParent(src);
    }
    if (originSrc != null) {
        locMotionX = Motion.createLinearMotion(originSrc.getAbsoluteX() + originSrc.getWidth() / 2 - dest.getWidth() / 2, dest.getAbsoluteX(), duration);
        locMotionX.start();
        locMotionY = Motion.createLinearMotion(originSrc.getAbsoluteY() + originSrc.getHeight() / 2 - dest.getHeight() / 2, dest.getAbsoluteY(), duration);
        locMotionY.start();
        clipMotion = Motion.createLinearMotion(Math.min(originSrc.getWidth(), originSrc.getHeight()), Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
    } else {
        if (originDest != null) {
            locMotionX = Motion.createLinearMotion(src.getAbsoluteX(), originDest.getAbsoluteX() + originDest.getWidth() / 2 - src.getWidth() / 2, duration);
            locMotionX.start();
            locMotionY = Motion.createLinearMotion(src.getAbsoluteY(), originDest.getAbsoluteY() + originDest.getHeight() / 2 - src.getHeight() / 2, duration);
            locMotionY.start();
            clipMotion = Motion.createLinearMotion(Math.max(src.getWidth(), src.getHeight()) * 3 / 2, Math.min(originDest.getWidth(), originDest.getHeight()), duration);
        } else {
            x = dest.getAbsoluteX();
            y = dest.getAbsoluteY();
            clipMotion = Motion.createLinearMotion(0, Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
        }
    }
    clipMotion.start();
}
Also used : Graphics(com.codename1.ui.Graphics) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component) Display(com.codename1.ui.Display)

Example 32 with Display

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

the class Form method initAdPadding.

void initAdPadding(Display d) {
    // this is injected automatically by the implementation in case of ads
    String adPaddingBottom = d.getProperty("adPaddingBottom", null);
    if (adPaddingBottom != null && adPaddingBottom.length() > 0) {
        Container pad = new Container();
        int dim = Integer.parseInt(adPaddingBottom);
        dim = d.convertToPixels(dim, true);
        if (Display.getInstance().isTablet()) {
            dim *= 2;
        }
        pad.setPreferredSize(new Dimension(dim, dim));
        addComponentToForm(BorderLayout.SOUTH, pad);
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 33 with Display

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

the class AndroidLocationPlayServiceManager method setupBackgroundLocationRequest.

private void setupBackgroundLocationRequest(LocationRequest req) {
    Display d = Display.getInstance();
    String priorityStr = d.getProperty("android.backgroundLocation.priority", "PRIORITY_BALANCED_POWER_ACCURACY");
    String fastestIntervalStr = d.getProperty("android.backgroundLocation.fastestInterval", "5000");
    String intervalStr = d.getProperty("android.backgroundLocation.interval", "10000");
    String smallestDisplacementStr = d.getProperty("android.backgroundLocation.smallestDisplacement", "50");
    int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
    if ("PRIORITY_HIGH_ACCURACY".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
    } else if ("PRIORITY_LOW_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_LOW_POWER;
    } else if ("PRIORITY_NO_POWER".equals(priorityStr)) {
        priority = LocationRequest.PRIORITY_NO_POWER;
    }
    long interval = Long.parseLong(intervalStr);
    long fastestInterval = Long.parseLong(fastestIntervalStr);
    int smallestDisplacement = Integer.parseInt(smallestDisplacementStr);
    req.setPriority(priority).setFastestInterval(fastestInterval).setInterval(interval).setSmallestDisplacement(smallestDisplacement);
}
Also used : Display(com.codename1.ui.Display)

Example 34 with Display

use of com.codename1.ui.Display 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 35 with Display

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

the class ResetableTextWatcher method setEditedTextField.

public static void setEditedTextField(final TextArea textarea) {
    Display display = Display.getInstance();
    Runnable task = new Runnable() {

        public void run() {
            AndroidImplementation.getInstance().setFocusedEditingText(textarea);
        }
    };
    if (display.isEdt()) {
        task.run();
    } else {
        display.callSeriallyAndWait(task);
    }
}
Also used : Display(com.codename1.ui.Display)

Aggregations

Display (com.codename1.ui.Display)10 Component (com.codename1.ui.Component)7 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Container (com.codename1.ui.Container)4 Dialog (com.codename1.ui.Dialog)4 Form (com.codename1.ui.Form)4 IOException (java.io.IOException)4 RGBImage (com.codename1.ui.RGBImage)3 InputStream (java.io.InputStream)3 ParseException (java.text.ParseException)3 Hashtable (java.util.Hashtable)3 Cursor (android.database.Cursor)2 Paint (android.graphics.Paint)2 Paint (com.codename1.charts.compat.Paint)2 Point (com.codename1.charts.models.Point)2 SpanButton (com.codename1.components.SpanButton)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 Button (com.codename1.ui.Button)2 Font (com.codename1.ui.Font)2