Example usage for android.webkit WebView setLayoutParams

List of usage examples for android.webkit WebView setLayoutParams

Introduction

In this page you can find the example usage for android.webkit WebView setLayoutParams.

Prototype

@Override
    public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Usage

From source file:Main.java

/**
 * Sets the WebView's width/height layout params to MATCH_PARENT
 *
 * @param webView The shared webView.//from   w ww  .java2  s  . co m
 */
private static void setWebViewLayoutParams(WebView webView) {
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    webView.setLayoutParams(params);
}

From source file:org.microg.gms.auth.login.LoginActivity.java

private static WebView createWebView(Context context) {
    WebView webView = new WebView(context);
    if (SDK_INT < LOLLIPOP) {
        webView.setVisibility(VISIBLE);/*w ww.  j  a v  a2 s  .c  o m*/
    } else {
        webView.setVisibility(INVISIBLE);
    }
    webView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setBackgroundColor(Color.TRANSPARENT);
    prepareWebViewSettings(webView.getSettings());
    return webView;
}

From source file:com.github.ekulf.spotifystreamer.LicensesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    webView.loadUrl("file:///android_asset/licences.html");
    return webView;
}

From source file:fr.cph.stock.android.activity.ChartActivity.java

@Override
public void displayError(JSONObject json) {
    boolean sessionError = ((StockTrackerApp) getApplication()).isSessionError(json);
    if (sessionError) {
        ((StockTrackerApp) getApplication()).loadErrorActivity(this, json);
    } else {/*from   www  .j a  v  a2  s . c om*/
        errorView.setText(json.optString("error"));
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) LayoutParams.MATCH_PARENT,
                (int) LayoutParams.MATCH_PARENT);
        params.addRule(RelativeLayout.BELOW, errorView.getId());
        WebView webView = (WebView) findViewById(R.id.webView);
        webView.setLayoutParams(params);
        menuItem.collapseActionView();
        menuItem.setActionView(null);
    }
}

From source file:de.dreier.mytargets.features.scoreboard.ScoreboardActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void print() {
    // Get a print adapter instance
    final WebView webViewPrint = new WebView(this);
    webViewPrint.setVisibility(View.INVISIBLE);
    ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    webViewPrint.setLayoutParams(p);
    ((ViewGroup) binding.getRoot()).addView(webViewPrint);

    new AsyncTask<Void, Void, String>() {

        @Override/*from  w w w . j  a  v  a2  s.co m*/
        protected String doInBackground(Void... params) {
            return HtmlUtils.getScoreboard(mTraining, mRound, ScoreboardConfiguration.fromPrintSettings());
        }

        @SuppressWarnings("deprecation")
        @Override
        protected void onPostExecute(String s) {
            webViewPrint.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "UTF-8", "");
            PrintDocumentAdapter printAdapter = webViewPrint.createPrintDocumentAdapter();

            // Create a print job with name and adapter instance
            PrintManager printManager = (PrintManager) getSystemService(PRINT_SERVICE);
            String jobName = getString(R.string.scoreboard) + " Document";
            printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    }.execute();
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java

public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/* ww  w . j  ava 2 s  .  com*/
    // TODO: hack to show object history in app feeds
    JSONObject appState = getAppState(context, content);
    if (appState != null) {
        content = appState;
    } else {
        Log.e(TAG, "Missing inner content, probably because of format changes");
    }

    boolean rendered = false;
    AppState ref = new AppState(content);
    String thumbnail = ref.getThumbnailImage();
    if (thumbnail != null) {
        rendered = true;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView);
        frame.addView(imageView);
    }

    thumbnail = ref.getThumbnailText();
    if (thumbnail != null) {
        rendered = true;
        TextView valueTV = new TextView(context);
        valueTV.setText(thumbnail);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }

    thumbnail = ref.getThumbnailHtml();
    if (thumbnail != null) {
        rendered = true;
        WebView webview = new WebView(context);
        webview.loadData(thumbnail, "text/html", "UTF-8");
        webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        Object o = frame.getTag(R.id.object_entry);
        webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o));
        frame.addView(webview);
    }

    if (!rendered) {
        String appName = content.optString(PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Welcome to " + appName + "!";
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void addWebObject(String width, String height, String url) {
    WebView wv = new WebView(getActivity());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    wv.setLayoutParams(params);
    wv.getSettings().setUseWideViewPort(true);
    wv.getSettings().setLoadWithOverviewMode(true);
    wv.getSettings().setSupportZoom(false);
    wv.setVerticalScrollBarEnabled(true);
    wv.setHorizontalScrollBarEnabled(true);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    wv.setWebViewClient(new WebViewClient());

    String frame = "<iframe width=\"" + width + "\" height=\"" + height + "\" frameborder=\"0\" src=\"" + url
            + "\"/>";
    wv.loadDataWithBaseURL(url, frame, "html/plain", "UTF-8", null);
    lay.addView(wv);//from w ww . j av  a  2  s. c  o  m
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetSettingsAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    /* TODO: This definitely needs some huge refactoring
     *///  w  w w.  java 2  s  .co m
    final int pos = position;

    RelativeLayout widgetView;
    TextView labelTextView;
    ImageView roomEditView;
    int widgetLayout = 0;
    OpenHABWidget openHABWidget = getItem(position);
    switch (this.getItemViewType(position)) {
    case TYPE_FRAME:
        widgetLayout = R.layout.openhabwidgetlist_frameitem;
        break;
    case TYPE_GROUP:
        widgetLayout = R.layout.openhabwidget_settings_item;
        break;

    case TYPE_IMAGE:
        widgetLayout = R.layout.openhabwidgetlist_imageitem;
        break;

    case TYPE_CHART:
        widgetLayout = R.layout.openhabwidgetlist_chartitem;
        break;
    case TYPE_VIDEO:
        widgetLayout = R.layout.openhabwidgetlist_videoitem;
        break;
    case TYPE_WEB:
        widgetLayout = R.layout.openhabwidgetlist_webitem;
        break;
    default:
        widgetLayout = R.layout.openhabwidget_settings_item;
        break;
    }
    if (convertView == null) {
        widgetView = new RelativeLayout(getContext());
        String inflater = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater vi;
        vi = (LayoutInflater) getContext().getSystemService(inflater);
        vi.inflate(widgetLayout, widgetView, true);
    } else {
        widgetView = (RelativeLayout) convertView;
    }
    switch (getItemViewType(position)) {
    case TYPE_FRAME:
        labelTextView = (TextView) widgetView.findViewById(R.id.framelabel);
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        widgetView.setClickable(false);
        if (openHABWidget.getLabel().length() > 0) { // hide empty frames
            widgetView.setVisibility(View.VISIBLE);
            labelTextView.setVisibility(View.VISIBLE);
        } else {
            widgetView.setVisibility(View.GONE);
            labelTextView.setVisibility(View.GONE);
        }
        break;
    case TYPE_IMAGE:
        MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage);
        imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false);
        if (openHABWidget.getRefresh() > 0) {
            imageImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(imageImage);
        }
        break;
    case TYPE_CHART:
        MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage);
        OpenHABItem chartItem = openHABWidget.getItem();
        Random random = new Random();
        String chartUrl = "";
        if (chartItem.getType().equals("GroupItem")) {
            chartUrl = openHABBaseUrl + "rrdchart.png?groups=" + chartItem.getName() + "&period="
                    + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt());
        }
        Log.i("OpenHABWidgetAdapter", "Chart url = " + chartUrl);
        chartImage.setImageUrl(chartUrl, false);
        // TODO: This is quite dirty fix to make charts look full screen width on all displays
        ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams();
        int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay().getWidth();
        chartLayoutParams.height = (int) (screenWidth / 1.88);
        chartImage.setLayoutParams(chartLayoutParams);
        if (openHABWidget.getRefresh() > 0) {
            chartImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(chartImage);
        }
        Log.i("OpenHABWidgetAdapter",
                "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height);
        break;
    case TYPE_VIDEO:
        VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo);
        Log.i("OpenHABWidgetAdapter", "Opening video at " + openHABWidget.getUrl());
        // TODO: This is quite dirty fix to make video look maximum available size on all screens
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams();
        videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77);
        videoVideo.setLayoutParams(videoLayoutParams);
        // We don't have any event handler to know if the VideoView is on the screen
        // so we manage an array of all videos to stop them when user leaves the page
        if (!videoWidgetList.contains(videoVideo))
            videoWidgetList.add(videoVideo);
        // Start video
        if (!videoVideo.isPlaying()) {
            videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl()));
            videoVideo.start();
        }
        Log.i("OpenHABWidgetAdapter", "Video height is " + videoVideo.getHeight());
        break;
    case TYPE_WEB:
        WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb);
        if (openHABWidget.getHeight() > 0) {
            ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams();
            webLayoutParams.height = openHABWidget.getHeight() * 80;
            webWeb.setLayoutParams(webLayoutParams);
        }
        webWeb.setWebViewClient(new WebViewClient());
        webWeb.loadUrl(openHABWidget.getUrl());
        break;

    default:
        labelTextView = (TextView) widgetView.findViewById(R.id.itemlabel);
        roomEditView = (ImageView) widgetView.findViewById(R.id.editimg);
        if (null != roomEditView) {
            roomEditView.setVisibility(View.VISIBLE);
            roomEditView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    if (null != listItemListener)
                        listItemListener.onEditClickListener(pos);
                }
            });
        }
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        MySmartImageView sliderImage = (MySmartImageView) widgetView.findViewById(R.id.itemimage);
        sliderImage.setImageUrl(openHABBaseUrl + "images/" + openHABWidget.getIcon() + ".png");
        break;
    }
    LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider);
    if (dividerLayout != null) {
        if (position < this.getCount() - 1) {
            if (this.getItemViewType(position + 1) == TYPE_FRAME) {
                dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets
            } else {
                dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others
            }
        } else { // last widget in the list, hide divider
            dividerLayout.setVisibility(View.GONE);
        }
    }
    return widgetView;
}

From source file:org.gluu.super_gluu.app.fragments.LicenseFragment.LicenseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.license_fragment, container, false);
    WebView licenseWebView = (WebView) view.findViewById(R.id.license_webView);
    licenseWebView.loadDataWithBaseURL(null, readLicenseTxt(), "text/html", "UTF-8", null);
    //        licenseTextView.setMovementMethod(new ScrollingMovementMethod());

    Button aceptButton = (Button) view.findViewById(R.id.accept_button);
    LinearLayout action_left_button = (LinearLayout) view.findViewById(R.id.action_left_button);
    action_left_button.setOnClickListener(new View.OnClickListener() {
        @Override//w  w  w  . j a va 2 s . c om
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    aceptButton.setOnClickListener(this);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) licenseWebView.getLayoutParams();
    if (!isForFirstLoading) {
        aceptButton.setVisibility(View.GONE);
        action_left_button.setVisibility(View.VISIBLE);
        params.weight = 0.25f;
    } else {
        action_left_button.setVisibility(View.GONE);
        params.weight = 0.98f;
    }
    licenseWebView.setLayoutParams(params);
    //Setup fonts
    Typeface face = Typeface.createFromAsset(getActivity().getAssets(), "ProximaNova-Regular.otf");
    aceptButton.setTypeface(face);

    return view;
}

From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * /*from   w w  w  .  j a  v  a 2  s .  com*/
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
private void showLoginUI(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });
    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}