Example usage for android.webkit WebSettings setLayoutAlgorithm

List of usage examples for android.webkit WebSettings setLayoutAlgorithm

Introduction

In this page you can find the example usage for android.webkit WebSettings setLayoutAlgorithm.

Prototype

public abstract void setLayoutAlgorithm(LayoutAlgorithm l);

Source Link

Document

Sets the underlying layout algorithm.

Usage

From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override// w  w w .  j a v a 2s  . c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false);

    if (mItem != null) {
        // set the views
        ViewSample viewSample = mItem.getViewSample();
        final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder);
        viewSample.createViews(getActivity(), viewsHolder);

        // load the CSS styling for the sample
        String css = ViewsData.getCSS(getActivity(), mItem);

        // Set up syntax highlighting
        WebView cssView = (WebView) rootView.findViewById(R.id.css_style);
        WebSettings s = cssView.getSettings();
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        s.setUseWideViewPort(false);
        s.setAllowFileAccess(true);
        s.setBuiltInZoomControls(true);
        s.setSupportZoom(true);
        s.setSupportMultipleWindows(false);
        s.setJavaScriptEnabled(true);

        StringBuilder contentString = new StringBuilder();
        contentString.append("<html><head>");
        contentString.append(
                "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> ");
        contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>");
        contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", "&nbsp;")
                .replaceAll("\t", "&nbsp;&nbsp;"));
        contentString.append("</code> </html> ");
        cssView.getSettings().setUseWideViewPort(true);
        cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html",
                StringUtil.EMPTY, StringUtil.EMPTY);

        // to aid in styling the css text shows in the textview, set its
        // ID. Eventually will not be needed.
        if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) {
            PixateFreestyle.setStyleId(cssView, "css-style", true);
        }

        // Style
        viewSample.style(css);
    }

    return rootView;
}

From source file:com.gh4a.FileViewerActivity.java

private void fillData(boolean highlight) {
    String data = new String(EncodingUtils.fromBase64(mContent.getContent()));
    WebView webView = (WebView) findViewById(R.id.web_view);

    WebSettings s = webView.getSettings();
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    s.setAllowFileAccess(true);/*from  w  w  w  .  ja  va 2s  .  c om*/
    s.setBuiltInZoomControls(true);
    s.setLightTouchEnabled(true);
    s.setLoadsImagesAutomatically(true);
    s.setPluginsEnabled(false);
    s.setSupportZoom(true);
    s.setSupportMultipleWindows(true);
    s.setJavaScriptEnabled(true);
    s.setUseWideViewPort(true);

    webView.setWebViewClient(webViewClient);
    if (FileUtils.isImage(mName)) {
        String htmlImage = StringUtils.highlightImage(
                "https://github.com/" + mRepoOwner + "/" + mRepoName + "/raw/" + mRef + "/" + mPath);
        webView.loadDataWithBaseURL("file:///android_asset/", htmlImage, "text/html", "utf-8", "");
    } else {
        String highlighted = StringUtils.highlightSyntax(data, highlight, mName);
        webView.loadDataWithBaseURL("file:///android_asset/", highlighted, "text/html", "utf-8", "");
    }
}

From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER);
    setContentView(R.layout.activity_externallink_webview);
    Bundle bundle = getIntent().getExtras();
    fileUrl = bundle.getString("url", "https://www.digipost.no");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w  ww .  j  a v a  2  s.  c om
    actionBar = getSupportActionBar();
    if (actionBar != null) {
        setActionBarTitle(fileUrl);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setBackgroundDrawable(new ColorDrawable(0xff2E2E2E));

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(
                    ContextCompat.getColor(this, R.color.metadata_externalbrowser_top_background));
        }
    }

    progressSpinner = (ProgressBar) findViewById(R.id.externallink_spinner);
    webView = (WebView) findViewById(R.id.externallink_webview);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDomStorageEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(true);
    enableCookies(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (firstLoad) {
                progressSpinner.setVisibility(View.GONE);
                webView.setVisibility(View.VISIBLE);
                firstLoad = false;
            }
            setActionBarTitle(view.getUrl());
        }
    });

    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, final String userAgent, final String content,
                final String mimeType, final long contentLength) {
            fileName = URLUtil.guessFileName(url, content, mimeType);
            fileUrl = url;
            onComplete = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                        showDownloadSuccessDialog(context);
                    }
                }
            };

            registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
            if (!mimeType.equals("text/html")) {
                if (FileUtilities.isStorageWriteAllowed(getApplicationContext())) {
                    showDownloadDialog(userAgent, content, mimeType, contentLength);
                } else {
                    showMissingPermissionsDialog();
                }
            }
        }
    });

    if (FileUtilities.isStorageWriteAllowed(this)) {
        webView.loadUrl(fileUrl);
    } else {
        showPermissionsDialog();
    }
}

From source file:com.example.robert.bluetoothnew.BluetoothChatFragment.java

public void initWebView(View view) {
    myWebView = (WebView) view.findViewById(R.id.webview);
    myWebView.getSettings().setJavaScriptEnabled(true);
    WebSettings settings = myWebView.getSettings();
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setUseWideViewPort(true);/*from www .  j  av a 2  s  .c  om*/
    settings.setLoadWithOverviewMode(true);
    myWebView.requestFocus();
    myWebView.setWebViewClient(new MyWebViewClient());
    //        myWebView.loadUrl("http://10.21.22.34:3000/index.html");
    //        myWebView.loadUrl("http://00efacc5.ngrok.io/index.html");
    myWebView.loadUrl("http://172.20.10.8:3000/index.html");
    //        myWebView.loadUrl("http://140.134.26.31/Bluetooth/Bluetooth.html");
    myWebView.addJavascriptInterface(new JavaScriptInterface(getActivity()), "JSInterface");
}

From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java

/**
 * Initialize webview.// w w  w  .  ja  v a2  s .  co m
 */
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(true);
    this.setHorizontalScrollBarEnabled(true);
    this.requestFocusFromTouch();
    // Enable JavaScript
    WebSettings settings = this.getSettings();

    settings.setBuiltInZoomControls(false);// ??
    settings.setUseWideViewPort(false);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    settings.setAllowFileAccess(true);
    settings.setAppCacheMaxSize(1024 * 1024 * 32);
    settings.setAppCachePath(mContext.getFilesDir().getPath() + "/cache");
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    // Set Cache Mode: LOAD_NO_CACHE is noly for debug
    //settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //enablePageCache(settings,5);
    //enableWorkers(settings);

    // Enable database
    settings.setDatabaseEnabled(true);
    String databasePath = mContext.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Improve render performance
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    if (Build.VERSION.SDK_INT >= 21) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
}

From source file:org.apache.cordova.CordovaWebView.java

/**
 * Initialize webview.// w w  w.  j  a v a 2s .  co  m
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setup() {

    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    this.requestFocusFromTouch();

    // Enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    //Set the nav dump for HTC 2.x devices (disabling for ICS/Jellybean)
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
        settings.setNavDump(true);

    //Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    //while we do this
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        settings.setAllowUniversalAccessFromFileURLs(true);
    // Enable database
    settings.setDatabaseEnabled(true);
    String databasePath = this.cordova.getActivity().getApplicationContext()
            .getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    //Start up the plugin manager
    try {
        this.pluginManager = new PluginManager(this, this.cordova);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    exposeJsInterface();
}

From source file:org.apache.cordova.AndroidWebView.java

/**
 * Initialize webview.//from ww  w .j a  v  a2s.  com
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
        this.requestFocusFromTouch();
    }
    // Enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2)
    try {
        Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class });

        String manufacturer = android.os.Build.MANUFACTURER;
        Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB
                && android.os.Build.MANUFACTURER.contains("HTC")) {
            gingerbread_getMethod.invoke(settings, true);
        }
    } catch (NoSuchMethodException e) {
        Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
        Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
        Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        Level16Apis.enableUniversalAccess(settings);
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = this.cordova.getActivity().getApplicationContext()
            .getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);

    //Determine whether we're in debug or release mode, and turn on Debugging!
    try {
        final String packageName = this.cordova.getActivity().getPackageName();
        final PackageManager pm = this.cordova.getActivity().getPackageManager();
        ApplicationInfo appInfo;

        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
                && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            setWebContentsDebuggingEnabled(true);
        }
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    } catch (NameNotFoundException e) {
        Log.d(TAG, "This should never happen: Your application's package can't be found.");
        e.printStackTrace();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    String pathToCache = this.cordova.getActivity().getApplicationContext()
            .getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setAppCachePath(pathToCache);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    this.updateUserAgentString();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                updateUserAgentString();
            }
        };
        this.cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405

    pluginManager = new PluginManager(this, this.cordova);
    jsMessageQueue = new NativeToJsMessageQueue(this, cordova);
    exposedJsApi = new AndroidExposedJsApi(pluginManager, jsMessageQueue);
    resourceApi = new CordovaResourceApi(this.getContext(), pluginManager);
    exposeJsInterface();
}

From source file:com.phonegap.DroidGap.java

/**
 * Create and initialize web container./*from   w  w  w  .  ja  v a 2  s . com*/
 */
public void init() {

    // Create web container
    this.appView = new WebView(DroidGap.this);
    this.appView.setId(100);

    this.appView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT, 1.0F));

    WebViewReflect.checkCompatibility();

    if (android.os.Build.VERSION.RELEASE.startsWith("2.")) {
        this.appView.setWebChromeClient(new EclairClient(DroidGap.this));
    } else {
        this.appView.setWebChromeClient(new GapClient(DroidGap.this));
    }

    this.setWebViewClient(this.appView, new GapViewClient(this));

    this.appView.setInitialScale(100);

    this.appView.setHorizontalScrollbarOverlay(false);
    this.appView.setVerticalScrollbarOverlay(false);
    this.appView.setVerticalScrollBarEnabled(false);
    this.appView.setHorizontalScrollBarEnabled(false);
    this.appView.requestFocusFromTouch();

    /*
    this.appView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return(event.getAction() == MotionEvent.ACTION_MOVE);
            }
    });
    */

    // Enable JavaScript
    WebSettings settings = this.appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Enable database
    Package pack = this.getClass().getPackage();
    String appPackage = pack.getName();
    WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/");

    // Enable DOM storage
    WebViewReflect.setDomStorage(settings);

    // Enable built-in geolocation
    WebViewReflect.setGeolocationEnabled(settings, true);

    // Bind PhoneGap objects to JavaScript
    this.bindBrowser(this.appView);

    // Add web view
    root.addView(this.appView);
    setContentView(root);

    // Clear cancel flag
    this.cancelLoadUrl = false;

    // If url specified, then load it
    String url = this.getStringProperty("url", null);
    if (url != null) {
        System.out.println("Loading initial URL=" + url);
        this.loadUrl(url);
    }
}

From source file:com.intel.xdk.device.Device.java

public void showRemoteSite(final String strURL, final int closeX_pt, final int closeY_pt, final int closeX_ls,
        final int closeY_ls, final int closeW, final int closeH, final String closeImage) {
    if (strURL == null || strURL.length() == 0)
        return;//  ww  w  . j a  va 2 s  . co m

    remoteCloseXPort = closeX_pt;
    remoteCloseYPort = closeY_pt;
    remoteCloseXLand = closeX_ls;
    remoteCloseYLand = closeY_ls;

    //hack to adjust image size
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    remoteCloseW = (int) ((float) closeW * dm.density);
    remoteCloseH = (int) ((float) closeH * dm.density);

    //Set position, width, height of closeImage according to currentOrientation
    if (this.getOrientation() == 0 || this.getOrientation() == 180) {
        //Portrait
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXPort,
                remoteCloseYPort);
        remoteClose.setLayoutParams(params);
    } else {
        AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
                remoteCloseW == 0 ? 48 : remoteCloseW, remoteCloseH == 0 ? 48 : remoteCloseH, remoteCloseXLand,
                remoteCloseYLand);
        remoteClose.setLayoutParams(params);
    }

    activity.runOnUiThread(new Runnable() {

        public void run() {

            if (remoteView == null) {

                remoteView = new WebView(activity);
                remoteView.setInitialScale(0);
                remoteView.setVerticalScrollBarEnabled(false);
                remoteView.setWebViewClient(new WebViewClient());
                final WebSettings settings = remoteView.getSettings();
                settings.setJavaScriptEnabled(true);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);

                remoteLayout.addView(remoteView,
                        new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));

                remoteView.requestFocusFromTouch();

                remoteView.setOnKeyListener(new View.OnKeyListener() {
                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        if (event.getAction() != KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                            remoteClose.performClick();
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
            }
            // load the url
            remoteView.loadUrl(strURL);
            // show the view
            remoteLayout.setVisibility(View.VISIBLE);
            // set the flag
            isShowingRemoteSite = true;
            // isShowingRemoteSite = true;
            // get focus
            remoteView.requestFocus(View.FOCUS_DOWN);
            remoteClose.bringToFront();
        }
    });

}

From source file:cn.suishen.email.activity.MessageViewFragmentBase.java

protected void resetView() {
    showContent(false, false);//from ww  w  .  j  a  v  a2s.  c  om
    updateTabs(0);
    setCurrentTab(TAB_MESSAGE);
    if (mMessageContentView != null) {
        blockNetworkLoads(true);
        mMessageContentView.scrollTo(0, 0);

        // Dynamic configuration of WebView
        final WebSettings settings = mMessageContentView.getSettings();
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        mMessageContentView.setInitialScale(getWebViewZoom());
    }
    mAttachmentsScroll.scrollTo(0, 0);
    mInviteScroll.scrollTo(0, 0);
    mAttachments.removeAllViews();
    mAttachments.setVisibility(View.GONE);
    initContactStatusViews();
}