Example usage for android.webkit WebSettings LOAD_DEFAULT

List of usage examples for android.webkit WebSettings LOAD_DEFAULT

Introduction

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

Prototype

int LOAD_DEFAULT

To view the source code for android.webkit WebSettings LOAD_DEFAULT.

Click Source Link

Document

Default cache usage mode.

Usage

From source file:Main.java

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setGeolocationEnabled(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
}

From source file:com.barcamppenang2014.tabfragment.AgendaFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.agenda, container, false);
    WebView agenda_wv = (WebView) v.findViewById(R.id.webview);
    NetworkAvailability network = new NetworkAvailability();
    if (network.isNetworkAvalaible(getActivity().getApplicationContext())) {
        agenda_wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        agenda_wv.loadUrl("http://barcamppenang.org/agenda.html");
    } else {//from  w w w .  ja  va2 s.c o  m
        agenda_wv.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        agenda_wv.loadUrl("http://barcamppenang.org/agenda.html");
    }

    return v;
}

From source file:edu.umich.eecs.lab11.summon.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.init();
    wv = ((WebView) appView.getEngine().getView());
    wv.addJavascriptInterface(new JavaScriptInterface(getPackageManager()), "gateway");
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setSupportMultipleWindows(false);
    wv.getSettings().setNeedInitialFocus(false);
    wv.getSettings().setSupportZoom(false);
    wv.getSettings().setAllowFileAccess(true);
    wv.getSettings().setAppCacheEnabled(true);
    wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    wv.getSettings().setAppCachePath(wv.getContext().getCacheDir().getAbsolutePath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setTaskDescription(new TaskDescription(null, null, Color.parseColor("#FFC107")));
    loadUrl(launchUrl);//  w w w .  j  av  a  2s. c o  m
    try {
        InputStream is = getAssets().open("www/summon.android.js");
        byte[] buffer = new byte[is.available()];
        is.read(buffer);
        is.close();
        js = "javascript:(function(){ " + "s=document.createElement('script');" + "s.innerHTML = atob('"
                + Base64.encodeToString(buffer, Base64.NO_WRAP) + "'); "
                + "document.querySelector('head').appendChild(s); " + "})()";
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.usabusi.newsreader.ArticleFragment.java

/**
 * Sets up the UI. It consists if a single WebView.
 */// w  ww . j  a  va  2s  .c  o  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mWebView = new WebView(getActivity());
    //http://stackoverflow.com/questions/17259537/load-webview-from-cache
    WebSettings webSettings = mWebView.getSettings();
    // Enable JavaScript
    webSettings.setJavaScriptEnabled(true); // enable javascript
    mWebView.setHorizontalScrollBarEnabled(false);
    webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB
    webSettings.setAppCachePath(getActivity().getApplicationContext().getCacheDir().getAbsolutePath());
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
    //http://stackoverflow.com/questions/25161720/url-opened-in-browser-instead-of-web-view
    mWebView.setVisibility(View.VISIBLE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setBuiltInZoomControls(true);

    //final Activity activity = this;
    // Make WebClient
    mWebView.setWebViewClient(new WebViewClient() {
        // Trace Errors
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(getActivity().getApplicationContext(), description, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //http://developer.android.com/guide/webapps/webview.html#HandlingNavigation
            //                view.loadUrl(url);
            //                return true;
            return false;
        }
    });

    loadWebView();
    return mWebView;
}

From source file:net.olejon.mdapp.MedicationNlhFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w ww .j  av a2s . c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_medication_nlh, container, false);

    // Activity
    final Activity activity = getActivity();

    // Context
    final Context context = activity.getApplicationContext();

    // Tools
    final MyTools mTools = new MyTools(context);

    // Arguments
    Bundle bundle = getArguments();

    final String pageUri = bundle.getString("uri");

    // Progress bar
    final ProgressBar progressBar = (ProgressBar) activity
            .findViewById(R.id.medication_toolbar_progressbar_horizontal);

    // Toolbar
    final LinearLayout toolbarSearchLayout = (LinearLayout) activity
            .findViewById(R.id.medication_toolbar_search_layout);
    final EditText toolbarSearchEditText = (EditText) activity.findViewById(R.id.medication_toolbar_search);

    // Web view
    WEBVIEW = (WebView) viewGroup.findViewById(R.id.medication_nlh_content);

    WebSettings webSettings = WEBVIEW.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().getAbsolutePath());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    WEBVIEW.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!mTools.isDeviceConnected()) {
                mTools.showToast(getString(R.string.device_not_connected), 0);
                return true;
            } else if (url.matches(".*/[^#]+#[^/]+$")) {
                WEBVIEW.loadUrl(url.replaceAll("#[^/]+$", ""));
                return true;
            } else if (url.matches("^https?://.*?\\.pdf$")) {
                mTools.downloadFile(view.getTitle(), url);
                return true;
            }

            return false;
        }
    });

    WEBVIEW.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                progressBar.setVisibility(View.INVISIBLE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);

                toolbarSearchLayout.setVisibility(View.GONE);
                toolbarSearchEditText.setText("");
            }
        }
    });

    if (savedInstanceState == null) {
        WEBVIEW.loadUrl(pageUri);
    } else {
        WEBVIEW.restoreState(savedInstanceState);
    }

    return viewGroup;
}

From source file:org.safegees.safegees.gui.fragment.InfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_info, container, false);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);

    webView = (WebView) view.findViewById(R.id.webview_info);
    //webView.getSettings().setAppCachePath( this.getActivity().getApplicationContext().getCacheDir().getAbsolutePath() );
    //webView.getSettings().setAppCacheEnabled( true );
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default

    if (!Connectivity.isNetworkAvaiable(getContext())) { // loading offline
        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }//from   ww w .j  ava 2 s .c o  m
    webView.getSettings().setAllowFileAccess(true);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains(WebViewInfoWebDownloadController.CRISIS_HUB_DEFAULT_URL)) {
                view.loadUrl(url);

            } else {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
            }
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            progressBar.setVisibility(View.GONE);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            webView.loadUrl("about:blank");
            webView.loadUrl("file:///android_asset/default_error.html");
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            //super.onReceivedError(view, request, error);
        }
    });

    //Load language
    String language = Locale.getDefault().getDisplayLanguage();
    if (language.equals("ar")) {
        webView.loadUrl(WebViewInfoWebDownloadController.CRISIS_HUB_DEFAULT_URL_AR);
    } else if (language.equals("fa")) {
        webView.loadUrl(WebViewInfoWebDownloadController.CRISIS_HUB_DEFAULT_URL_FA);
    } else {
        webView.loadUrl(WebViewInfoWebDownloadController.CRISIS_HUB_DEFAULT_URL);
    }

    return view;
}

From source file:cn.zy.ef.fragment.WebViewFragment.java

protected void configureWebView(WebSettings settings) {
    settings.setJavaScriptCanOpenWindowsAutomatically(true);//js??window.open()false
    settings.setJavaScriptEnabled(true);//??jsfalsetrue????XSS?
    settings.setSupportZoom(true);//??true
    settings.setBuiltInZoomControls(false);//?false
    settings.setUseWideViewPort(true);//???
    settings.setLoadWithOverviewMode(true);//setUseWideViewPort(true)
    settings.setAppCacheEnabled(true);//?
    settings.setDomStorageEnabled(true);//DOM Storage
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
}

From source file:it.redturtle.mobile.apparpav.ForecastFragment.java

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

    View view = inflater.inflate(R.layout.showbulletin, container, false);

    // Set button in order to start the bulletin fragmnet
    final Button mv = (Button) view.findViewById(R.id.mv);
    mv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "MV");
            startActivity(newintent);//from   www.ja va 2  s.c  om
        }
    });

    // Set button in order to start the bulletin fragmnet
    final Button dm = (Button) view.findViewById(R.id.dm);
    dm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "DM");
            startActivity(newintent);
        }
    });

    // Set button in order to start the bulletin fragmnet
    final Button pm = (Button) view.findViewById(R.id.pm);
    pm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent newintent = new Intent();
            newintent.setClass(activity, BulletinActivity.class);
            newintent.putExtra("bulletinid", "MP");
            startActivity(newintent);
        }
    });

    WebView webview = (WebView) view.findViewById(R.id.datail_content);
    webview.setWebChromeClient(new WebChromeClient() {
    });
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

    String html = "<!doctype html>";
    html += "<html>";
    html += "<head>";
    html += "<meta name=\"author\" content=\"RedTurtle.it\" />";
    html += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />";
    html += "</head>";
    html += "<body style=\"font-family:Helvetica;font-size:small;\">";
    html += "<div style=\"text-align:center;\"><b>" + forecast.getName() + "</b></div>";

    if (forecast.getType() == 1) {
        html += "<div style=\"text-align:center;\">";
        html += "<p>" + forecast.getCaptionAt(0) + "</p>";
        html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
    }
    if (forecast.getType() == 2) {

        html += "<div style=\"text-align:center;\">";
        html += "<div style=\"display:inline-block;\">";
        html += "<div style=\"float:left;\">";
        html += "<p>" + forecast.getCaptionAt(0) + "</p>";
        html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
        html += "<div style=\"float:left;\">";
        html += "<p>" + forecast.getCaptionAt(1) + "</p>";
        html += "<img  src=\"" + forecast.getPathAt(1) + "\" width=\"140\" style=\"padding:2px;\"/>";
        html += "</div>";
        html += "</div>";
        html += "</div>";
    }

    html += forecast.getBody();
    html += "</body>";
    html += "</html>";

    webview.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
    return view;
}

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

/**
 * Initialize webview.//  w ww . j  a  v  a2  s  .c  om
 */
@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:net.granoeste.scaffold.app.ScaffoldWebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//  ww w .j a va  2s .  com
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    FrameLayout root = new FrameLayout(getActivity());

    // ------------------
    // Progress content
    // ------------------
    mPFrame = new LinearLayout(getActivity());
    mPFrame.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    mPFrame.setOrientation(LinearLayout.VERTICAL);
    mPFrame.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mPFrame.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    // ----------------
    // WebView content
    // ----------------
    mCFrame = new FrameLayout(getActivity());
    mCFrame.setId(INTERNAL_CONTENT_CONTAINER_ID);

    mWebView = new InternalWebView(getActivity());
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

    mWebView.getSettings().setJavaScriptEnabled(true);

    // Flash Support
    if (UIUtils.hasKitkat()) {
        // Flash(4.4?????)
    } else if (UIUtils.hasJellyBeanMr2()) {
        mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    } else if (UIUtils.hasFroyo()) {
        // Deprecated Since API level 9, and removed in API level 18 (JellyBeanMr2)
        // mWebView.getSettings().setPluginEnabled(true);
    }

    // mWebView.getSettings().setVerticalScrollbarOverlay(true);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

    // ?
    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setType(mimetype);
            intent.setData(Uri.parse(url));
            startActivity(intent);
        }
    });

    mWebView.setWebViewClient(new InternalWebViewClient(root, mCallbacks));

    mCFrame.addView(mWebView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.addView(mCFrame, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    root.addView(mPFrame, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}