Example usage for android.webkit WebView getSettings

List of usage examples for android.webkit WebView getSettings

Introduction

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

Prototype

public WebSettings getSettings() 

Source Link

Document

Gets the WebSettings object used to control the settings for this WebView.

Usage

From source file:com.sahildave.snackbar.SnackBar.java

private View addLargeContainer(MessageType messageType, String inputUrl) {
    View v = activity.getLayoutInflater().inflate(R.layout.usb_large_container, null);
    WebView webView = (WebView) v.findViewById(R.id.snackWebview);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient() {

        @Override//from   ww w  .j  av a  2 s.c o  m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    webView.loadUrl(inputUrl);

    v.setTag(messageType);
    addToView(v);

    return v;

}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

@Override
public void onResume() {
    super.onResume();
    initRecorderFragment();//from   w w w . ja  v a  2s .  c  o  m
    final SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!defaultPrefs.getBoolean("LICENSES_ACCEPTED", false)) {
        final AlertDialog.Builder acceptLicenses = new AlertDialog.Builder(this);
        View v = getLayoutInflater().inflate(R.layout.alertdialog_license_prompt, null);
        acceptLicenses.setView(v);

        WebView cpol = (WebView) v.findViewById(R.id.CPOL_view),
                apache = (WebView) v.findViewById(R.id.APACHE_2_0_view);
        cpol.loadUrl("file:///android_res/raw/cpol.html");
        cpol.getSettings().setLoadWithOverviewMode(true);
        cpol.getSettings().setBuiltInZoomControls(true);
        cpol.getSettings().setUseWideViewPort(true);
        apache.loadUrl("file:///android_res/raw/apache.html");
        apache.getSettings().setLoadWithOverviewMode(true);
        apache.getSettings().setBuiltInZoomControls(true);
        apache.getSettings().setUseWideViewPort(true);

        acceptLicenses.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                defaultPrefs.edit().putBoolean("LICENSES_ACCEPTED", true).apply();
                dialog.dismiss();

                PreferenceManager.setDefaultValues(MainMenuActivity.this, R.xml.data_viewer_phone_options,
                        false);
            }
        });

        acceptLicenses.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        acceptLicenses.setCancelable(false);
        acceptLicenses.show();
    }
}

From source file:com.ezac.gliderlogs.FlightWeatherActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        appLND = extras.getString("Ref");
    }/*  w  ww  . j a v  a2s .  c o m*/
    setContentView(R.layout.weather_list);
    // hide soft keyboard
    setMode();
    // disable these fields, these are output only
    nameText = (EditText) findViewById(R.id.editText61);
    nameText.setClickable(false);
    nameText.setFocusable(false);
    rainText = (EditText) findViewById(R.id.editText61a);
    rainText.setClickable(false);
    rainText.setFocusable(false);
    windText = (EditText) findViewById(R.id.editText62);
    windText.setClickable(false);
    windText.setFocusable(false);
    wdpkText = (EditText) findViewById(R.id.editText62a);
    wdpkText.setClickable(false);
    wdpkText.setFocusable(false);
    presText = (EditText) findViewById(R.id.editText63);
    presText.setClickable(false);
    presText.setFocusable(false);
    humiText = (EditText) findViewById(R.id.editText64);
    humiText.setClickable(false);
    humiText.setFocusable(false);
    wdgrText = (EditText) findViewById(R.id.editText65);
    wdgrText.setClickable(false);
    wdgrText.setFocusable(false);
    wdirText = (EditText) findViewById(R.id.editText66);
    wdirText.setClickable(false);
    wdirText.setFocusable(false);
    tempText = (EditText) findViewById(R.id.editText67);
    tempText.setClickable(false);
    tempText.setFocusable(false);
    wolkText = (EditText) findViewById(R.id.editText67a);
    wolkText.setClickable(false);
    wolkText.setFocusable(false);
    sunuText = (EditText) findViewById(R.id.editText68);
    sunuText.setClickable(false);
    sunuText.setFocusable(false);
    sundText = (EditText) findViewById(R.id.editText69);
    sundText.setClickable(false);
    sundText.setFocusable(false);
    mtr1Text = (EditText) findViewById(R.id.editText70);
    mtr1Text.setClickable(false);
    mtr1Text.setFocusable(false);
    mtr2Text = (EditText) findViewById(R.id.editText71);
    mtr2Text.setClickable(false);
    mtr2Text.setFocusable(false);
    knmiText = (EditText) findViewById(R.id.editText81);
    knmiText.setClickable(false);
    knmiText.setFocusable(false);

    Button close = (Button) findViewById(R.id.button_close);
    WebView browser = (WebView) findViewById(R.id.webview_1);

    browser.getSettings().setLoadsImagesAutomatically(true);
    // browser.getSettings().setJavaScriptEnabled(true);
    browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    //browser.loadUrl("http://www.buienradar.nl/images.aspx?jaar=-3&soort=sp-loop");
    browser.loadUrl("http://api.buienradar.nl/image/1.0/RadarMapBE?w=500&h=512");

    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setResult(RESULT_OK);
            finish();
        }
    });

    new NET1_Task().execute("http://xml.buienradar.nl", "1;" + FlightOverviewActivity.appMST);
    String s[] = FlightOverviewActivity.appMTR.split(";");
    new NET1_Task().execute("http://aviationweather.gov/adds/dataserver_current/httpparam?"
            + "dataSource=metars&requestType=retrieve&format=xml&stationString=EHFS&"
            + "hoursBeforeNow=3&mostRecent=true", "2;" + s[0]);
    new NET1_Task().execute("http://aviationweather.gov/adds/dataserver_current/httpparam?"
            + "dataSource=metars&requestType=retrieve&format=xml&stationString=EHWO&"
            + "hoursBeforeNow=3&mostRecent=true", "3;" + s[1]);
    new NET2_Task().execute("http://www.knmi.nl/waarschuwingen_en_verwachtingen/luchtvaart/"
            + "weerbulletin_kleine_luchtvaart.html", "4;0");
}

From source file:it.angrydroids.epub3reader.BookView.java

@Override
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);

    // enable JavaScript for cool things to happen!
    view.getSettings().setJavaScriptEnabled(true);

    // ----- SWIPE PAGE
    view.setOnTouchListener(new OnTouchListener() {
        @Override//w ww  . j a v a2s.c o  m
        public boolean onTouch(View v, MotionEvent event) {

            if (state == ViewStateEnum.books)
                swipePage(v, event, 0);

            WebView view = (WebView) v;
            return view.onTouchEvent(event);
        }
    });

    // ----- NOTE & LINK
    view.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));
                    if (url != null)
                        navigator.setNote(url, index);
                }
            });
            view.requestFocusNodeHref(msg);

            return false;
        }
    });

    view.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                navigator.setBookPage(url, index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });

    view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE");
    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            view.loadUrl(
                    "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);");
        }
    });

    PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk);
    TopButton = (Button) getView().findViewById(R.id.btn_display_from_top);
    FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk);

    PreButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnPrevChunkOnClickListner(v);
        }
    });

    TopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnDisplayTopOnClickListner(v);
        }
    });

    FwdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnFwdChunkOnClickListner(v);
        }
    });
    loadPage(viewedPage);
}

From source file:org.quizreader.android.PageReadActivity.java

/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override/*from  w w w  .  j  a  va  2  s  . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page_read);
    // immediately pop up loading dialog
    dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setMessage("loading page");
    dialog.show();
    // set up webview
    WebView webview = (WebView) findViewById(R.id.webView);
    webview.setWebViewClient(new QRWebViewClient());
    webview.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId());
            return true;
        }
    });
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.addJavascriptInterface(new QuizReaderInterface(), "qr");
    try {
        random = new Random();
        wordDao = new WordDao(this);
        qzzFile = new QzzFile(title.getFilepath(), this);
        URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection());
        if (htmlURL == null) { // beyond the last section
            setResult(RESULT_END_TITLE);
            finish();
        }
        String externalForm = htmlURL.toExternalForm();
        webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph());
    } catch (Exception ex) {
        webview.loadData(ex.toString(), "text/plain", null);
    }
}

From source file:com.example.health_connect.MySampleFragment3.java

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

    mView = inflater.inflate(R.layout.sample_fragment3, container, false);
    Parse.initialize(mView.getContext(), "e0FVFRBMAWJi5shg4XF8zL3SIuRwDIufww3338so",
            "toTJmlHTEF43u7PoAFT4fedwqfhoWiSajj1Se7FT");

    ParseUser currentUser = ParseUser.getCurrentUser();
    Log.d("Check", currentUser.getObjectId());
    ImageView birthdaypic = (ImageView) mView.findViewById(R.id.imageView2);
    TextView wish = (TextView) mView.findViewById(R.id.textView23);
    TextView hbday = (TextView) mView.findViewById(R.id.textView24);

    WebView webview = (WebView) mView.findViewById(R.id.pic);
    webview.setWebViewClient(new WebViewClient() {
        @Override/*from www.j  a  v  a 2 s.c o  m*/
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.i("WEB_VIEW_TEST", "error code: " + errorCode + " " + description);
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setDomStorageEnabled(true);
    String u_r_l;
    if (currentUser.getString("image_flag").equalsIgnoreCase("1")) {
        u_r_l = "http://cdn.filter.to/100x100/http://s3-ap-southeast-1.amazonaws.com/hconnect/"
                + currentUser.getObjectId();
    } else {
        u_r_l = "http://cdn.filter.to/100x100/cdn1.iconfinder.com/data/icons/PRACTIKA/256/user.png";
    }

    webview.loadUrl(u_r_l);

    String date_of_birth = currentUser.getString("Dob");

    Calendar c = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String formattedDate = df.format(c.getTime());
    //Log.d("Check",formattedDate);
    String str[] = { "Every patient carries her or his own doctor inside.", "Laughter is the best medicine",
            "The art of medicine consists in amusing the patient while nature cures the disease.",
            "Health is wealth", "My health is good,it's my age that's bad.",
            "A healthy body is a guest-chamber for the soul; a sick body is a prison.",
            "Fitness:If it came in a bottle,everybody would have a good body.",
            "Ypu don't get ulcers form what you eat,but from what's eating you.",
            "Those who don't find time for exercise will have to find time for illness.",
            "Sickness comes on horseback and departs on foot.",
            "Health and appetite impart the sweetness to sugar,bread and meat.",
            "Health is not valued till sickness comes.", "Health is not simply the absence of sickness.",
            "To eat is a necessity,but to eat intelligently is an art.",
            "Let food be the medicine,thy medicine shall be thy food.", "Food is fuel,choose wisely.",
            "Health and intellect are the two blessings of life.", "The greatest wealth is health.",
            "Think positive and focus on gratitude.", "Get a good night's sleep.", "Use food over supplements.",
            "Eat 5 servings of fruits and veggies a day.", "Big idea: Be happy :)",
            "Drink water instead of surgery drinks.", "Swap big serves for smaller ones.",
            "Park the car and walk the rest of the way.",
            "No disease that can be treated by diet should be treated with any other means.",
            "Your body hears everything your mind says/",
            "Take care of your body. It's the only place you have to live.",
            "Every human being is the author of his own health or disease." };
    Random r = new Random();
    int High = 30; // 30 excluded
    int Low = 0;
    int random_number = r.nextInt(High - Low) + Low;

    if ((formattedDate.substring(0, 2).equalsIgnoreCase(date_of_birth.substring(0, 2)))
            && (formattedDate.substring(3, 5).equalsIgnoreCase(date_of_birth.substring(3, 5))))
    //   if(d1==d2 && m1==m2)
    {

    } else {
        //   Log.d("Check", d1);
        birthdaypic.setImageDrawable(null);
        wish.setText(null);
        hbday.setText(null);
        wish.setText(str[random_number]);
        //wish.setVisibility(View.GONE);
        hbday.setVisibility(View.GONE);
    }

    TextView a_name = (TextView) mView.findViewById(R.id.pdob);
    TextView a_eid = (TextView) mView.findViewById(R.id.textView8);
    TextView a_add = (TextView) mView.findViewById(R.id.textView10);
    TextView a_dob = (TextView) mView.findViewById(R.id.textView12);
    TextView a_lno = (TextView) mView.findViewById(R.id.textView14);
    TextView a_year = (TextView) mView.findViewById(R.id.textView16);
    TextView a_mschool = (TextView) mView.findViewById(R.id.textView18);
    TextView a_spec = (TextView) mView.findViewById(R.id.textView20);
    TextView a_deg = (TextView) mView.findViewById(R.id.textView22);
    a_name.setText(currentUser.getUsername());
    a_deg.setText(currentUser.getString("Degree"));
    a_dob.setText(currentUser.getString("Dob"));
    a_spec.setText(currentUser.getString("Primary_speciality"));
    a_mschool.setText(currentUser.getString("Medical_School"));
    a_add.setText(currentUser.getString("Address"));
    a_year.setText(currentUser.getString("Start_Practice"));
    a_eid.setText(currentUser.getEmail());
    a_lno.setText(currentUser.getString("LicenseNo"));

    return mView;
}

From source file:com.purchasingpower.inappbrowser.WebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setContentView(R.layout.activity_main);
    setContentView(getResources().getIdentifier("nativebrowserplugin", "layout", getPackageName()));
    if (!checkPermission()) {
        requestPermission();//www  .  j a v a2s .c  o  m
    }
    Intent intent = getIntent();
    String url = intent.getExtras().getString("url");
    final WebView myWebView = (WebView) findViewById(
            getResources().getIdentifier("webview", "id", getPackageName()));
    myWebView.setWebViewClient(new MyWebViewClient());

    webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAllowFileAccess(true);
    myWebView.setWebChromeClient(new PQChromeClient());
    //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration
    if (Build.VERSION.SDK_INT >= 19) {
        myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) {
        myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    myWebView.loadUrl(url);

    back = (ImageView) findViewById(getResources().getIdentifier("back", "id", getPackageName()));
    back.setImageResource(getResources().getIdentifier("back_gray", "drawable", getPackageName()));
    forward = (ImageView) findViewById(getResources().getIdentifier("forward", "id", getPackageName()));
    forward.setImageResource(getResources().getIdentifier("forward_gray", "drawable", getPackageName()));
    done = (TextView) findViewById(getResources().getIdentifier("done", "id", getPackageName()));
    pbar = (ProgressBar) findViewById(getResources().getIdentifier("pbar", "id", getPackageName()));
    pbar.setVisibility(View.VISIBLE);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoBack()) {
                myWebView.goBack();
            }
        }
    });
    forward.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoForward()) {
                myWebView.goForward();
            }
        }
    });
    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v("Done", "Clicked");
            finish();
        }
    });
}

From source file:com.polyvi.xface.view.XWebViewClient.java

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    XIWebAppEventListener evtListener = mWebAppView.getAppEventListener();
    if (null == evtListener) {
        XLog.w(CLASS_NAME, "onPageStarted: XIWebAppEventListener is null!");
        return;//from w  ww  .  j a  v a2s .  c om
    }
    // ???WideViewPorttrue???
    view.getSettings().setUseWideViewPort(true);
    // ????
    view.getSettings().setSupportZoom(true);
    // ?about_blank????pageStart
    if (!ABOUT_BLANK.equals(url)) {
        evtListener.onPageStarted((XAppWebView) view);
    }
    XAppWebView appView = (XAppWebView) view;
    // TODO:4.0 ??? ???,?????? ??
    // 4.02.2 2.3[3.1] ????,???
    if (Build.VERSION.SDK_INT < XInputScaleHandler.APILEVEL_11) {
        appView.setAdapated(false);
    }
}

From source file:org.golang.app.WViewActivity.java

private void initWebView(WebView webView) {

    WebSettings settings = webView.getSettings();

    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);/*from  www.  j  a v a2s .  c om*/
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(true);
    // settings.setPluginsEnabled(true);
    methodInvoke(settings, "setPluginsEnabled", new Class[] { boolean.class }, new Object[] { true });
    // settings.setPluginState(PluginState.ON);
    methodInvoke(settings, "setPluginState", new Class[] { PluginState.class },
            new Object[] { PluginState.ON });
    // settings.setPluginsEnabled(true);
    methodInvoke(settings, "setPluginsEnabled", new Class[] { boolean.class }, new Object[] { true });
    // settings.setAllowUniversalAccessFromFileURLs(true);
    methodInvoke(settings, "setAllowUniversalAccessFromFileURLs", new Class[] { boolean.class },
            new Object[] { true });
    // settings.setAllowFileAccessFromFileURLs(true);
    methodInvoke(settings, "setAllowFileAccessFromFileURLs", new Class[] { boolean.class },
            new Object[] { true });

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.clearHistory();
    webView.clearFormData();
    webView.clearCache(true);

    webView.setWebChromeClient(new MyWebChromeClient());
    // webView.setDownloadListener(downloadListener);
}

From source file:com.example.ruby.mygetgps.ui.activities.MainActivity.java

private void setupWebView() {
    WebView webview = (WebView) findViewById(R.id.webview);
    webview.setWebChromeClient(new WebChromeClient() {
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }// w w w .  j a  v  a 2 s.  co  m
    });
    webview.setWebViewClient(new WebViewClient());
    webview.clearCache(true);
    webview.clearHistory();
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webview.loadUrl("https://getgpsserverrails-0.herokuapp.com/summaries");
}