Search in sources :

Example 16 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class UIManager method buildTheme.

private void buildTheme(Hashtable themeProps) {
    String con = (String) themeProps.get("@includeNativeBool");
    if (con != null && con.equalsIgnoreCase("true") && Display.getInstance().hasNativeTheme()) {
        boolean a = accessible;
        accessible = true;
        Display.getInstance().installNativeTheme();
        accessible = a;
    }
    Enumeration e = themeProps.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        // this is a constant not a theme entry
        if (key.startsWith("@")) {
            themeConstants.put(key.substring(1, key.length()), themeProps.get(key));
            continue;
        }
        this.themeProps.put(key, themeProps.get(key));
    }
    if (!this.themeProps.containsKey("PickerButtonBar.derive")) {
        // For the button bar (with Cancel and Done) of the Picker interaction dialog in lightweight mode
        if (this.themeProps.containsKey("PickerButtonBarNative.derive")) {
            this.themeProps.put("PickerButtonBar.derive", "PickerButtonBarNative");
        } else {
            this.themeProps.put("PickerButtonBar.margin", "0,0,0,0");
            this.themeProps.put("PickerButtonBar.border", Border.createCompoundBorder(Border.createLineBorder(1, ColorUtil.rgb(148, 150, 151)), Border.createEmpty(), Border.createEmpty(), Border.createEmpty()));
            this.themeProps.put("PickerButtonBar.bgColor", "F0F1F3");
            this.themeProps.put("PickerButtonBar.transparency", "255");
        }
    }
    if (!this.themeProps.containsKey("PickerButtonTablet.derive")) {
        // For the buttons of the picker in lightweight mode (the Cancel and Done buttons)
        if (this.themeProps.containsKey("PickerButtonTabletNative.derive")) {
            this.themeProps.put("PickerButtonTablet.derive", "PickerButtonTabletNative");
            this.themeProps.put("PickerButtonTablet.sel#derive", "PickerButtonTabletNative.sel");
            this.themeProps.put("PickerButtonTablet.press#derive", "PickerButtonTabletNative.press");
        } else {
            this.themeProps.put("PickerButtonTablet.derive", "Button");
            this.themeProps.put("PickerButtonTablet.sel#derive", "Button");
            this.themeProps.put("PickerButtonTablet.press#derive", "Button");
        }
    }
    // necessary to clear up the style so we don't get resedue from the previous UI
    defaultStyle = new Style();
    // create's the default style
    defaultStyle = createStyle("", "", false);
    defaultSelectedStyle = new Style(defaultStyle);
    defaultSelectedStyle = createStyle("", "sel#", true);
    String overlayThemes = (String) themeProps.get("@OverlayThemes");
    if (overlayThemes != null) {
        java.util.List<String> overlayThemesArr = StringUtil.tokenize(overlayThemes, ',');
        for (String th : overlayThemesArr) {
            th = th.trim();
            if (th.length() == 0) {
                continue;
            }
            try {
                Resources res = Resources.openLayered("/" + th);
                boolean a = accessible;
                accessible = true;
                addThemeProps(res.getTheme(res.getThemeResourceNames()[0]));
                accessible = a;
            } catch (Exception ex) {
                System.err.println("Failed to load overlay theme file specified by @overlayThemes theme constant: " + th);
                Log.e(ex);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException)

Example 17 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class TestUtils method showSidemenu.

/**
 * Shows the sidemenu UI
 */
public static void showSidemenu() {
    Form f = Display.getInstance().getCurrent();
    Toolbar tb = f.getToolbar();
    if (tb != null) {
        tb.openSideMenu();
    } else {
        ((SideMenuBar) f.getMenuBar()).openMenu(null);
    }
}
Also used : Form(com.codename1.ui.Form) SideMenuBar(com.codename1.ui.SideMenuBar) Toolbar(com.codename1.ui.Toolbar)

Example 18 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class InstantUI method createEditUI.

/**
 * Creates editing UI for the given business object
 * @param bo the business object
 * @param autoCommit true if the bindings used should be auto-committed
 * @return a UI container that can be used to edit the business object
 */
public Container createEditUI(PropertyBusinessObject bo, boolean autoCommit) {
    Container cnt;
    if (Display.getInstance().isTablet()) {
        TableLayout tl = new TableLayout(1, 2);
        tl.setGrowHorizontally(true);
        cnt = new Container(tl);
    } else {
        cnt = new Container(BoxLayout.y());
    }
    UiBinding uib = new UiBinding();
    ArrayList<UiBinding.Binding> allBindings = new ArrayList<UiBinding.Binding>();
    if (order != null && order.length > 0) {
        for (PropertyBase b : order) {
            createEntryForProperty(b, cnt, allBindings, uib);
        }
    } else {
        for (PropertyBase b : bo.getPropertyIndex()) {
            createEntryForProperty(b, cnt, allBindings, uib);
        }
    }
    cnt.putClientProperty("cn1$iui-binding", uib.createGroupBinding(allBindings));
    return cnt;
}
Also used : Container(com.codename1.ui.Container) ArrayList(java.util.ArrayList) TableLayout(com.codename1.ui.table.TableLayout)

Example 19 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class GoogleImpl method nativeLoginImpl.

private void nativeLoginImpl(final GoogleApiClient client) {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(client);
    AndroidNativeUtil.startActivityForResult(signInIntent, RC_SIGN_IN, new IntentResultListener() {

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
            if (requestCode == RC_SIGN_IN) {
                final GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
                if (result.isSuccess()) {
                    // Signed in successfully, show authenticated UI.
                    GoogleSignInAccount acct = result.getSignInAccount();
                    String displayName = acct.getDisplayName();
                    String acctId = acct.getId();
                    String email = acct.getEmail();
                    String requestIdToken = acct.getIdToken();
                    Set<Scope> grantedScopes = acct.getGrantedScopes();
                    String code = acct.getServerAuthCode();
                    String scopeStr = scope;
                    System.out.println("Token is " + acct.getIdToken());
                    if (acct.getIdToken() == null && clientId != null && clientSecret != null) {
                        Log.p("Received null ID token even though clientId and clientSecret are set.");
                    }
                    // otherwise we'll set the token to null.
                    if (clientId != null && clientSecret != null && requestIdToken != null && code != null) {
                        ConnectionRequest req = new ConnectionRequest() {

                            @Override
                            protected void readResponse(InputStream input) throws IOException {
                                Map<String, Object> json = new JSONParser().parseJSON(new InputStreamReader(input, "UTF-8"));
                                if (json.containsKey("access_token")) {
                                    setAccessToken(new AccessToken((String) json.get("access_token"), (String) null));
                                    Display.getInstance().callSerially(new Runnable() {

                                        @Override
                                        public void run() {
                                            callback.loginSuccessful();
                                        }
                                    });
                                } else {
                                    setAccessToken(new AccessToken());
                                    Log.p("Failed to retrieve the access token from the google auth server.  Login succeeded, but access token is null, so you won't be able to use it to retrieve additional information.");
                                    Log.p("Response was " + json);
                                    Display.getInstance().callSerially(new Runnable() {

                                        @Override
                                        public void run() {
                                            callback.loginSuccessful();
                                        }
                                    });
                                }
                            }
                        };
                        req.setUrl("https://www.googleapis.com/oauth2/v4/token");
                        req.addArgument("grant_type", "authorization_code");
                        // req.addArgument("client_id", "555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com");
                        req.addArgument("client_id", clientId);
                        // req.addArgument("client_secret", "650YqplrnAI0KXb9LMUnVNnx");
                        req.addArgument("client_secret", clientSecret);
                        req.addArgument("redirect_uri", "");
                        req.addArgument("code", code);
                        req.addArgument("id_token", requestIdToken);
                        req.setPost(true);
                        req.setReadResponseForErrors(true);
                        NetworkManager.getInstance().addToQueue(req);
                    } else {
                        setAccessToken(new AccessToken());
                        Log.p("The access token was set to null because one of clientId, clientSecret, requestIdToken, or auth were null");
                        Log.p("The login succeeded, but you won't be able to make any requests to Google's REST apis using the login token.");
                        Log.p("In order to obtain a token that can be used with Google's REST APIs, you need to set the clientId, and clientSecret of" + "the GoogleConnect instance to valid OAuth2.0 Client IDs for Web Clients.");
                        Log.p("See https://console.developers.google.com/apis/credentials");
                        Log.p("You can get the OAuth2.0 client ID for this project in your google-services.json file in the oauth_client section");
                        Display.getInstance().callSerially(new Runnable() {

                            @Override
                            public void run() {
                                callback.loginSuccessful();
                            }
                        });
                    }
                } else {
                    if (callback != null) {
                        if (callback != null) {
                            Display.getInstance().callSerially(new Runnable() {

                                @Override
                                public void run() {
                                    callback.loginFailed(GooglePlayServicesUtil.getErrorString(result.getStatus().getStatusCode()));
                                }
                            });
                        }
                    }
                }
            }
        }
    });
}
Also used : Set(java.util.Set) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Intent(android.content.Intent) IOException(java.io.IOException) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult) ConnectionRequest(com.codename1.io.ConnectionRequest) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) IntentResultListener(com.codename1.impl.android.IntentResultListener) AccessToken(com.codename1.io.AccessToken) JSONParser(com.codename1.io.JSONParser) Map(java.util.Map)

Example 20 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class ResetableTextWatcher method hideTextEditor.

/**
 * Hides the native text editor while keeping the active async edit session going.
 * This will effectively hide the native text editor, and show the light-weight text area
 * with cursor still in the correct position.
 */
private void hideTextEditor() {
    if (!mIsEditing || textEditorHidden || mEditText == null) {
        return;
    }
    textEditorHidden = true;
    final TextArea ta = mEditText.mTextArea;
    // Since this may be called off the UI thread, we need to issue async request on UI thread
    // to hide the text area.
    impl.getActivity().runOnUiThread(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea == ta) {
                // Note:  Setting visibility to GONE doesn't work here because the TextWatcher
                // will stop receiving input from the keyboard, so we don't have a way to
                // reactivate the text editor when the user starts typing again.  Using the margin
                // to move it off screen keeps the text editor active.
                mEditLayoutParams.setMargins(-Display.getInstance().getDisplayWidth(), 0, 0, 0);
                InPlaceEditView.this.requestLayout();
                final int cursorPos = mEditText.getSelectionStart();
                // Since we are going to be displaying the CN1 text area now, we need to update
                // the cursor.  That needs to happen on the EDT.
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        if (mEditText != null && mEditText.mTextArea == ta && mIsEditing && textEditorHidden) {
                            if (ta instanceof TextField) {
                                ((TextField) ta).setCursorPosition(cursorPos);
                            }
                        }
                    }
                });
            }
        }
    });
    // Repaint the CN1 text area on the EDT.  This is necessary because while the native editor
    // was shown, the cn1 text area paints only its background.  Now that the editor is hidden
    // it should paint its foreground also.
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea != null) {
                mEditText.mTextArea.repaint();
            }
        }
    });
// repaintTextEditor(true);
}
Also used : TextArea(com.codename1.ui.TextArea) TextField(com.codename1.ui.TextField)

Aggregations

Component (com.codename1.ui.Component)10 Label (com.codename1.ui.Label)9 ArrayList (java.util.ArrayList)9 Container (com.codename1.ui.Container)8 Form (com.codename1.ui.Form)8 IOException (java.io.IOException)8 TextArea (com.codename1.ui.TextArea)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 HashMap (java.util.HashMap)6 Vector (java.util.Vector)6 Entity (com.codename1.rad.models.Entity)5 Hashtable (java.util.Hashtable)5 EntityList (com.codename1.rad.models.EntityList)4 ActionNode (com.codename1.rad.nodes.ActionNode)4 EncodedImage (com.codename1.ui.EncodedImage)4 FontImage (com.codename1.ui.FontImage)4 Border (com.codename1.ui.plaf.Border)4 Log (com.codename1.io.Log)3 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)3 Thing (com.codename1.rad.schemas.Thing)3