Example usage for android.widget LinearLayout VERTICAL

List of usage examples for android.widget LinearLayout VERTICAL

Introduction

In this page you can find the example usage for android.widget LinearLayout VERTICAL.

Prototype

int VERTICAL

To view the source code for android.widget LinearLayout VERTICAL.

Click Source Link

Usage

From source file:com.phonegap.bossbolo.plugin.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//w  w w . j a v a2s .  c  om
 * @param header
 */
public String showWebPage(final String url, HashMap<String, Boolean> features, final String header) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            int backgroundColor = Color.parseColor("#46bff7");
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout  header
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(50)));
            toolbar.setPadding(this.dpToPixels(8), this.dpToPixels(10), this.dpToPixels(8),
                    this.dpToPixels(10));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            toolbar.setBackgroundColor(backgroundColor);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setWidth(this.dpToPixels(34));
            back.setHeight(this.dpToPixels(31));
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("back", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                    //                        goBack();
                }
            });

            // Edit Text Box
            titletext = new TextView(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, this.dpToPixels(65));
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, this.dpToPixels(10));
            titletext.setLayoutParams(textLayoutParams);
            titletext.setId(3);
            titletext.setSingleLine(true);
            titletext.setText(header);
            titletext.setTextColor(Color.WHITE);
            titletext.setGravity(Gravity.CENTER);
            titletext.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.dpToPixels(20));
            titletext.setSingleLine();
            titletext.setEllipsize(TruncateAt.END);

            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            editLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            editLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setVisibility(View.GONE);

            // Forward button
            /*Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            forward.setBackgroundDrawable(fwdIcon);
            }
            else
            {
            forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
                    
            // Edit Text Box
            edittext = new TextView(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  navigate(edittext.getText().toString());
                  return true;
                }
                return false;
            }
            });
                    
                    
            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            close.setBackgroundDrawable(closeIcon);
            }
            else
            {
            close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                closeDialog();
            }
            });*/

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(getShowZoomControls());
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            //                actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(titletext);
            //                toolbar.addView(edittext);
            //                toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.ssn.currency.convertor.WheelView.java

/**
 * Creates item layouts if necessary//from   w  w w.  jav  a 2 s . c om
 */
private void createItemsLayout() {
    if (itemsLayout == null) {
        itemsLayout = new LinearLayout(getContext());
        itemsLayout.setOrientation(LinearLayout.VERTICAL);
    }
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url//from  w w w . j a  v a  2  s. c o  m
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

            // Don't add the toolbar if its been disabled
            if (features.location) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:it.crs4.most.ehrlib.WidgetProvider.java

/**
 * build a view containing all widgets according to the json archetype structure, layout and ontology, All widgets are rendered in a vertical layout, 
 * optionally ordered by section and/or item priority (if specified in the layout json schema) 
 *
 * @param index the index of this Form Container
 * @return the FormContainer containing all widgets, ordered by section and item priority in a vertical layout
 *//*from ww  w  .ja  v a  2s .c o m*/
public FormContainer buildFormView(int index) {

    /*
            
     {
    "title" : "at0000",
            
    "datatypes" : {
         "at0004" : {
          "path": "/data[at0001]/events[at002]",
          "priority" : "0",
          "type" : "DV_QUANTITY",
          "attributes" : {
                   "unit_of_measure": "mm[Hg]",
                  "precision" : 2,
                    "range" : {"min" : 10 , "max" :180 }
                   }
        },
                
         "at0005" : {
          "path": "/data[at0001]/events[at002]",
          "priority" : "1",
          "type" : "DV_QUANTITY",
          "attributes" : {
                   "unit_of_measure": "mm[Hg]",
                  "precision" : 2,
                    "range" : {"min" : 10 , "max" :180 }
                   }
        }
    }
     */

    // Build cluster widgets, needed for sections including them
    try {
        buildClusterWidgetsMap(null);
    } catch (InvalidDatatypeException e2) {
        Log.e(TAG, String.format("Error building cluster Widget Map:%s", e2.getMessage()));
        e2.printStackTrace();

    }

    String[] sections = null;

    if (this.jsonLayoutSchema != null) {
        JSONArray jsonSections;
        try {
            jsonSections = this.jsonLayoutSchema.getJSONArray("sections");
            sections = new String[jsonSections.length()];

            for (int i = 0; i < sections.length; i++)
                sections[i] = jsonSections.getString(i);

            buildSectionWidgetsMap(sections);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (InvalidDatatypeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else
        try {
            buildSectionWidgetsMap(null);
        } catch (InvalidDatatypeException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    if (sections == null)
        sections = getSections();

    Log.d(TAG, "Generating form....");
    String formTitle = "Unknown Form";
    ArrayList<DatatypeWidget<EhrDatatype>> _allWidgets = new ArrayList<DatatypeWidget<EhrDatatype>>();

    try {

        //formTitle = String.format("%s [%s]", ontology.getJSONObject(datatypesSchema.getString("title")).getString("text"), index);   
        formTitle = ontology.getJSONObject(datatypesSchema.getString("title")).getString("text");
        Log.d(TAG, "FORM TITLE: " + formTitle);

        for (String section : sections) {
            List<DatatypeWidget<EhrDatatype>> sectionWidgets = this.sectionWidgetsMap.get(section);
            Log.d(TAG, String.format("SectionWidgets for section %s: %s", section, sectionWidgets));

            if (this.jsonLayoutSchema != null) {
                Collections.sort(sectionWidgets, new PriorityComparison(this.jsonLayoutSchema));
            }

            _allWidgets.addAll(sectionWidgets);

        }

    } catch (JSONException e) {
        Log.e(TAG, "Error parsing input json string:" + e);
        e.printStackTrace();
    }

    _container = new LinearLayout(context);
    _container.setOrientation(LinearLayout.VERTICAL);
    _container.setLayoutParams(defaultLayoutParams);

    _viewport = new ScrollView(context);
    _viewport.setLayoutParams(defaultLayoutParams);

    _layout = new LinearLayout(context);
    _layout.setOrientation(LinearLayout.VERTICAL);
    _layout.setLayoutParams(defaultLayoutParams);

    View titleView = buildTitleView(context, formTitle);
    _layout.addView(titleView);
    for (int i = 0; i < _allWidgets.size(); i++) {
        _layout.addView((View) _allWidgets.get(i).getView());
    }

    _viewport.addView(_layout);
    _container.addView(_viewport);

    FormContainer fc = new FormContainer((ViewGroup) _container, _allWidgets, index);
    Log.d(TAG, "Resetting all widgets...");
    //fc.resetAllWidgets();
    return fc;
}

From source file:com.woxthebox.draglistview.KanbanBoardView.java

public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header,
        boolean hasFixedItemSize) {
    final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext());
    recyclerView.setMotionEventSplittingEnabled(false);
    recyclerView.setDragItem(mDragItem);
    recyclerView.setLayoutParams(// w  w w.j  a  v a  2  s . com
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setHasFixedSize(hasFixedItemSize);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() {
        @Override
        public void onDragStarted(int itemPosition, float x, float y) {
            mDragStartColumn = getColumnOfList(recyclerView);
            mDragStartRow = itemPosition;
            mCurrentRecyclerView = recyclerView;
            mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY());
            if (mBoardListener != null) {
                mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow);
            }
            invalidate();
        }

        @Override
        public void onDragging(int itemPosition, float x, float y) {
        }

        @Override
        public void onDragEnded(int newItemPosition) {
            if (mBoardListener != null) {
                mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView),
                        newItemPosition);
            }
        }
    });

    recyclerView.setAdapter(adapter);
    recyclerView.setDragEnabled(mDragEnabled);
    adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() {
        @Override
        public boolean startDrag(View itemView, long itemId) {
            return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView),
                    getListTouchY(recyclerView));
        }

        @Override
        public boolean isDragging() {
            return recyclerView.isDragging();
        }
    });

    LinearLayout layout = new LinearLayout(getContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT));
    if (header != null) {
        header.setOnTouchListener(new HeaderTouchListener());
        layout.addView(header);
        mHeaders.put(mLists.size(), header);
    }
    layout.addView(recyclerView);

    mLists.add(recyclerView);
    mColumnLayout.addView(layout);
    return recyclerView;
}

From source file:com.wit.and.dialog.internal.BaseDialog.java

/**
 * <h5><i>protected View onCreateDialogView(LayoutInflater inflater,
 * ViewGroup container, Bundle savedInstanceState)</i></h5>
 * <p>/*w  ww .j  a  v  a 2 s  . c  o m*/
 * Create the dialog main view into which will be placed title, body and
 * buttons view.
 * </p>
 *
 * @param inflater           Layout inflater.
 * @param container          Inflated dialog main view.
 * @param savedInstanceState Saved state.
 * @return Inflated dialog view.
 */
protected View onCreateDialogView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout layout = new LinearLayout(inflater.getContext());
    layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);
    return layout;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void showOfflinePNRStatus(String trainDetails, ArrayList<String> passnDetails) {
    LinearLayout ll = new LinearLayout(mActivity);

    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);
    TextView tvTrainDetails = new TextView(mActivity);
    TextView[] tvPassnDetails = new TextView[passnDetails.size()];

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);/*from   w  w w  . j a  v a 2 s.co  m*/
    textViewPsnDtls.setText("Passenger Details");
    tvTrainDetails.setText(trainDetails);
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    tvTrainDetails.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Small);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    tvTrainDetails.setPadding(10, 10, 10, 10);

    tvTrainDetails.setBackgroundResource(R.drawable.card_background);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);

    ll.addView(tvTrainDetails);
    ll.addView(textViewPsnDtls);
    for (int i = 0; i < passnDetails.size(); ++i) {
        tvPassnDetails[i] = new TextView(mActivity);
        tvPassnDetails[i].setText(passnDetails.get(i));
        tvPassnDetails[i].setPadding(10, 10, 10, 10);
        tvPassnDetails[i].setBackgroundResource(R.drawable.card_background);
        tvPassnDetails[i].setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        ll.addView(tvPassnDetails[i]);
    }
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

public void imgShow(Bitmap bitmap, String strImgMsg) {
    MainActivity.adlib.put(strImgMsg, bitmap);
    Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size());
    Log.i("Portal", "Image added for key " + strImgMsg);

    if (MainActivity.myGallery == null)
        return;/*from  ww  w .  j  a  v a 2 s.  c  o  m*/

    if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized
        LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent();

        if (MainActivity.gal_size < 1) {
            ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash);
            imgSplash.setVisibility(View.INVISIBLE);
        }

        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setGravity(Gravity.CENTER);

        ImageView imageview = new ImageView(getApplicationContext());
        imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000));
        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageview.setImageBitmap(bitmap);

        //Add a button to go with it
        Button btnBuy = new Button(getApplicationContext());
        LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        btnParams.setMargins(-10, -10, -10, -10);
        btnBuy.setLayoutParams(btnParams);
        btnBuy.setText("Buy Now (" + strImgMsg + ")");
        btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap));
        btnBuy.setTextColor(Color.WHITE);

        btnBuy.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent newActivity = new Intent(getApplicationContext(), WebActivity.class);
                newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/");
                startActivity(newActivity);
            }
        });

        layout.addView(imageview);
        layout.addView(btnBuy);
        MainActivity.myGallery.addView(layout);
        MainActivity.gal_size++;
    }

}

From source file:com.example.drugsformarinemammals.Dose_Information.java

public LinearLayout createBorderLayout() {
    LinearLayout border_layout = new LinearLayout(this);
    border_layout.setOrientation(LinearLayout.VERTICAL);
    border_layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    border_layout.setBackgroundResource(R.drawable.layout_border);
    return border_layout;
}

From source file:com.dat.towerofhanoi.draggablerecyclerview.BoardView.java

public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header,
        boolean hasFixedItemSize, int color, Drawable drawable) {
    final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext());
    recyclerView.setMotionEventSplittingEnabled(false);
    recyclerView.setDragItem(mDragItem);

    if (drawable != null) {
        if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            recyclerView.setBackgroundDrawable(drawable);
            GradientDrawable gd = (GradientDrawable) recyclerView.getBackground().getCurrent();
            gd.setColor(getResources().getColor(R.color.white));
            gd.setStroke(2, getResources().getColor(R.color.grey), 0, 0);
        } else {//from  ww  w.  j a  v  a  2 s  . c o m
            recyclerView.setBackground(drawable);
        }
    }
    if (color > 0) {
        mColumnLayout.setBackgroundColor(color);
    }
    //settings for ToH rules
    recyclerView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
    linearLayoutManager.setReverseLayout(true);
    recyclerView.setCanNotDragBelowTopItem(mCanNotDragBelowTopItem);
    recyclerView.setCanNotDropBelowTopItem(mCanNotDropBelowTopItem);
    recyclerView.setDragItemCallback(new DragItemRecyclerView.DragItemCallback() {
        @Override
        public boolean canDragItemAtPosition(int dragPosition) {
            return true;
        }

        @Override
        public boolean canDropItemAtPosition(int dropPosition) {
            if (dropPosition == adapter.getItemCount() - 1) {
                // Log.d("TAG", "TRUE");
                return true;
            }
            return false;
        }
    });
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setHasFixedSize(hasFixedItemSize);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() {
        @Override
        public void onDragStarted(int itemPosition, float x, float y) {
            mDragStartColumn = getColumnOfList(recyclerView);
            mDragStartRow = itemPosition;
            mCurrentRecyclerView = recyclerView;
            mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY());
            if (mBoardListener != null) {
                mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow);
            }
            invalidate();
        }

        @Override
        public void onDragging(int itemPosition, float x, float y) {
        }

        @Override
        public void onDragEnded(int newItemPosition) {
            if (mBoardListener != null) {
                mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView),
                        newItemPosition);
            }
        }
    });

    recyclerView.setAdapter(adapter);
    recyclerView.setDragEnabled(mDragEnabled);
    adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() {
        @Override
        public boolean startDrag(View itemView, long itemId) {
            return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView),
                    getListTouchY(recyclerView));
        }

        @Override
        public boolean isDragging() {
            return recyclerView.isDragging();
        }
    });

    LinearLayout layout = new LinearLayout(getContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT));
    if (header != null) {
        layout.addView(header);
        mHeaders.put(mLists.size(), header);
    }
    layout.addView(recyclerView);

    mLists.add(recyclerView);
    mColumnLayout.addView(layout);
    return recyclerView;
}