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.saltedge.sdk.webview.SEWebViewTools.java

public void initializeWithUrl(Activity activity, final WebView webView, final String url,
        WebViewRedirectListener listener) {
    this.activity = activity;
    this.webViewRedirectListener = listener;
    progressDialog = UITools.createProgressDialog(this.activity);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.setWebViewClient(new CustomWebViewClient());
    webView.setWebChromeClient(new WebChromeClient() {

        @Override/*from  w w w .j  a v  a 2 s.com*/
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            SETools.uploadMessage = filePathCallback;
            pickFile();
            return true;
        }

    });
    webView.loadUrl(url);
}

From source file:com.emobc.android.activities.generators.PdfActivityGenerator.java

@Override
protected void loadAppLevelData(final Activity activity, final AppLevelData data) {
    final PdfLevelDataItem item = (PdfLevelDataItem) data.findByNextLevel(nextLevel);
    if (item == null)
        return;//from   w  w  w  . j  a va2 s . com

    //rotateScreen(activity);
    initializeHeader(activity, item);

    //Create Banner
    CreateMenus c = (CreateMenus) activity;
    c.createBanner();
    if (Utils.hasLength(item.getPdfUrl())) {
        WebView webview = (WebView) activity.findViewById(R.id.pdfviewer);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.setWebViewClient(new InsideWebViewClient(activity));

        webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + item.getPdfUrl());

        //activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getPdfUrl())));

        /*
        File outputDir = activity.getCacheDir(); 
        try {
           File outputFile = File.createTempFile("eMobc", ".tmp", outputDir);
           if(downloadPdfToFile(outputFile, item.getPdfUrl())){
              File file = new File(outputFile.getAbsolutePath());
                
              if (file.exists()) {                      
               Uri path = Uri.fromFile(outputFile);
               Intent intent = new Intent(Intent.ACTION_VIEW);
               intent.setDataAndType(path, "application/pdf");
               intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                
               try {
                  activity.startActivity(intent);
               }catch (ActivityNotFoundException e) {
                   Toast.makeText(activity, 
                       "No Application Available to View PDF", 
                       Toast.LENGTH_SHORT).show();
               }
              }
           }            
        } catch (IOException e1) {
           Log.e("PdfActivityGenerator", "Error: " + e1.getMessage());
        }*/
        /*
                
        String pdfFileUrl = String.format(PDF_WEBVIEW_TPL, item.getPdfUrl());
                
        try {
           URL url = new URL(pdfFileUrl);
           URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
           url = uri.toURL();
                
                   
           WebView webView = (WebView)activity.findViewById(R.id.pdfviewer);
           webView.getSettings().setJavaScriptEnabled(true); 
           webView.loadUrl(url.toString());
                   
           Uri uriPath = Uri.parse(item.getPdfUrl());
                   
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uriPath, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                
        try {
           activity.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(activity, 
                "No Application Available to View PDF", 
                Toast.LENGTH_SHORT).show();
        }
        } catch (MalformedURLException e) {
           Log.e("PdfActivityGenerator", "MalformedURLException: " + e.getMessage());
        } catch (URISyntaxException e) {
           Log.e("PdfActivityGenerator", "URISyntaxException: " + e.getMessage());
        }
        */
    }
}

From source file:com.stoutner.privacybrowser.AboutTabFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View tabLayout;/*from w  w  w  .j  ava2 s  .  c  om*/

    // Load the about tab layout.  Tab numbers start at 0.
    if (tabNumber == 0) {
        // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.
        // The fragment will take care of attaching the root automatically.
        tabLayout = inflater.inflate(R.layout.about_tab_version, container, false);

        // Version.
        TextView versionNumberText = (TextView) tabLayout.findViewById(R.id.about_version_number_text);
        String version = getString(R.string.version) + " " + BuildConfig.VERSION_NAME + " ("
                + getString(R.string.version_code) + " " + Integer.toString(BuildConfig.VERSION_CODE) + ")";
        versionNumberText.setText(version);

        // Brand.
        TextView versionBrandText = (TextView) tabLayout.findViewById(R.id.about_version_brand_text);
        versionBrandText.setText(Build.BRAND);

        // Manufacturer.
        TextView versionManufacturerText = (TextView) tabLayout
                .findViewById(R.id.about_version_manufacturer_text);
        versionManufacturerText.setText(Build.MANUFACTURER);

        // Model.
        TextView versionModelText = (TextView) tabLayout.findViewById(R.id.about_version_model_text);
        versionModelText.setText(Build.MODEL);

        // Device.
        TextView versionDeviceText = (TextView) tabLayout.findViewById(R.id.about_version_device_text);
        versionDeviceText.setText(Build.DEVICE);

        // Bootloader.
        TextView versionBootloaderText = (TextView) tabLayout.findViewById(R.id.about_version_bootloader_text);
        versionBootloaderText.setText(Build.BOOTLOADER);

        // Radio.
        TextView versionRadioText = (TextView) tabLayout.findViewById(R.id.about_version_radio_text);
        // Hide versionRadioTextView if there is no radio.
        if (Build.getRadioVersion().equals("")) {
            TextView versionRadioTitle = (TextView) tabLayout.findViewById(R.id.about_version_radio_title);
            versionRadioTitle.setVisibility(View.GONE);
            versionRadioText.setVisibility(View.GONE);
        } else { // Else, set the text.
            versionRadioText.setText(Build.getRadioVersion());
        }

        // Android.
        TextView versionAndroidText = (TextView) tabLayout.findViewById(R.id.about_version_android_text);
        String android = Build.VERSION.RELEASE + " (" + getString(R.string.api) + " "
                + Integer.toString(Build.VERSION.SDK_INT) + ")";
        versionAndroidText.setText(android);

        // Build.
        TextView versionBuildText = (TextView) tabLayout.findViewById(R.id.about_version_build_text);
        versionBuildText.setText(Build.DISPLAY);

        // Security Patch.
        TextView versionSecurityPatchText = (TextView) tabLayout
                .findViewById(R.id.about_version_securitypatch_text);
        // Build.VERSION.SECURITY_PATCH is only available for SDK_INT >= 23.
        if (Build.VERSION.SDK_INT >= 23) {
            versionSecurityPatchText.setText(Build.VERSION.SECURITY_PATCH);
        } else { // Hide versionSecurityPatchTextView.
            TextView versionSecurityPatchTitle = (TextView) tabLayout
                    .findViewById(R.id.about_version_securitypatch_title);
            versionSecurityPatchTitle.setVisibility(View.GONE);
            versionSecurityPatchText.setVisibility(View.GONE);
        }

        // webViewLayout is only used to get the default user agent from about_tab_webview.  It is not used to render content on the screen.
        View webViewLayout = inflater.inflate(R.layout.about_tab_webview, container, false);
        WebView tabLayoutWebView = (WebView) webViewLayout.findViewById(R.id.about_tab_webview);
        String userAgentString = tabLayoutWebView.getSettings().getUserAgentString();

        // WebKit.
        TextView versionWebKitText = (TextView) tabLayout.findViewById(R.id.about_version_webkit_text);
        // Select the substring that begins after "Safari/" and goes to the end of the string.
        String webkitVersion = userAgentString.substring(userAgentString.indexOf("Safari/") + 7);
        versionWebKitText.setText(webkitVersion);

        // Chrome.
        TextView versionChromeText = (TextView) tabLayout.findViewById(R.id.about_version_chrome_text);
        // Select the substring that begins after "Chrome/" and goes until the next " ".
        String chromeVersion = userAgentString.substring(userAgentString.indexOf("Chrome/") + 7,
                userAgentString.indexOf(" ", userAgentString.indexOf("Chrome/")));
        versionChromeText.setText(chromeVersion);
    } else { // load a WebView for all the other tabs.  Tab numbers start at 0.
        // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.
        // The fragment will take care of attaching the root automatically.
        tabLayout = inflater.inflate(R.layout.about_tab_webview, container, false);
        WebView tabWebView = (WebView) tabLayout;

        switch (tabNumber) {
        case 1:
            tabWebView.loadUrl("file:///android_asset/about_permissions.html");
            break;

        case 2:
            tabWebView.loadUrl("file:///android_asset/about_privacy_policy.html");
            break;

        case 3:
            tabWebView.loadUrl("file:///android_asset/about_changelog.html");
            break;

        case 4:
            tabWebView.loadUrl("file:///android_asset/about_license.html");
            break;

        case 5:
            tabWebView.loadUrl("file:///android_asset/about_contributors.html");
            break;

        case 6:
            tabWebView.loadUrl("file:///android_asset/about_links.html");

        default:
            break;
        }
    }

    return tabLayout;
}

From source file:net.oremland.rss.reader.fragments.BrowserFragment.java

private void initializeViews(Bundle savedInstanceState) {
    if (savedInstanceState == null && getContext() != null) {
        boolean isTablet = getContext().getResources().getBoolean(R.bool.isTablet);
        WebSettings.ZoomDensity zoomDensity = isTablet ? WebSettings.ZoomDensity.MEDIUM
                : WebSettings.ZoomDensity.FAR;

        WebView description = (WebView) getView().findViewById(R.id.description);
        description.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        description.getSettings().setJavaScriptEnabled(true);
        description.getSettings().setPluginState(WebSettings.PluginState.ON);
        description.getSettings().setDefaultTextEncodingName("utf-8");
        description.getSettings().setLoadWithOverviewMode(true);
        description.getSettings().setDefaultZoom(zoomDensity);
        description.getSettings().setSupportZoom(true);
        description.getSettings().setBuiltInZoomControls(true);
        description.requestFocus(View.FOCUS_DOWN);
        description.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        description.getSettings().setUseWideViewPort(isTablet);
        description.setWebChromeClient(this.getWebChromeClient());
        description.setWebViewClient(this.getWebViewClient());
    }/*from w  ww .j a va  2 s  .c om*/
}

From source file:com.sinelead.car.club.XinchepingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.activity_content_xincheping, null);
    WebView webView = (WebView) v.findViewById(R.id.webView_xincheping);
    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);/*ww w  .  j a v a2 s .c o  m*/
            return true;
        }
    });

    webView.getSettings().setJavaScriptEnabled(true);

    webView.loadUrl("http://m.xincheping.com");
    return v;
}

From source file:org.jorge.cmp.ui.fragment.ArticleReaderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    setHasOptionsMenu(Boolean.TRUE);
    final View ret = inflater.inflate(R.layout.fragment_article_reader, container, Boolean.FALSE);
    View mHeaderView = ret.findViewById(R.id.image);
    PicassoUtils.loadInto(mContext, mArticle.getImageUrl(), mDefaultImageId,
            (android.widget.ImageView) mHeaderView, TAG);
    final String title = mArticle.getTitle();
    mHeaderView.setContentDescription(title);
    ((TextView) ret.findViewById(R.id.title)).setText(title);
    WebView contentView = (WebView) ret.findViewById(android.R.id.text1);
    WebSettings webViewSettings = contentView.getSettings();
    contentView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    webViewSettings.setJavaScriptCanOpenWindowsAutomatically(Boolean.TRUE);
    webViewSettings.setBuiltInZoomControls(Boolean.FALSE);
    contentView.setBackgroundColor(0x00000000); //I wonder why the default background is white
    contentView.loadData(mArticle.getPreviewText(), "text/html; charset=UTF-8", "UTF-8");

    mActionBar = mActivity.getSupportActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(Boolean.TRUE);
    mActionBarBackgroundDrawable = new ColorDrawable(
            mContext.getResources().getColor(R.color.toolbar_background));
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mActionBarBackgroundDrawable.setCallback(mDrawableCallback);
    }//w  w w. ja v  a 2 s. c  o m
    mActionBar.setBackgroundDrawable(mActionBarBackgroundDrawable);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mOriginalElevation = mActionBar.getElevation();
        mActionBar.setElevation(0); //So that the shadow of the ActionBar doesn't show over
        // the article title
    }
    mActionBar.setTitle(mActivity.getString(R.string.section_title_article_reader));

    StickyParallaxNotifyingScrollView scrollView = (StickyParallaxNotifyingScrollView) ret
            .findViewById(R.id.scroll_view);
    scrollView.setOnScrollChangedListener(mOnScrollChangedListener);
    scrollView.smoothScrollTo(0, 0);

    if (!mArticle.isRead()) {
        mMarkAsReadFab = (FloatingActionButton) ret.findViewById(R.id.fab_button_mark_as_read);
        mMarkAsReadFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                markArticleAsRead(mArticle);
                if (mMarkAsReadFab.isShown())
                    mMarkAsReadFab.hide();
            }

            private void markArticleAsRead(FeedArticle article) {
                final Realm r = Realm.getInstanceByRealmId(ArticleReaderFragment.this.mAccount.getRealmEnum());
                String l = PreferenceAssistant.readSharedString(mContext, PreferenceAssistant.PREF_LANG, null);
                if (l == null || !Arrays.asList(r.getLocales()).contains(l)) {
                    l = r.getLocales()[0];
                    PreferenceAssistant.writeSharedString(mContext, PreferenceAssistant.PREF_LANG, l);
                }
                final Class newsClass = NewsListFragment.class;
                final Class communityClass = CommunityListFragment.class;
                final Class schoolClass = SchoolListFragment.class;
                String tableName;
                if (mClass == newsClass) {
                    if (l == null || !Arrays.asList(r.getLocales()).contains(l)) {
                        l = r.getLocales()[0];
                        PreferenceAssistant.writeSharedString(mContext, PreferenceAssistant.PREF_LANG, l);
                    }
                    tableName = SQLiteDAO.getNewsTableName(r, l);
                } else if (mClass == communityClass) {
                    tableName = SQLiteDAO.getCommunityTableName();
                } else if (mClass == schoolClass) {
                    tableName = SQLiteDAO.getSchoolTableName();
                } else {
                    throw new IllegalArgumentException(
                            "Feed list fragment class " + mClass.getCanonicalName() + " not recognized.");
                }
                new AsyncTask<Object, Void, Void>() {
                    @Override
                    protected Void doInBackground(Object... params) {
                        SQLiteDAO.getInstance().markArticleAsRead((FeedArticle) params[0], (String) params[1]);
                        return null;
                    }
                }.executeOnExecutor(Executors.newSingleThreadExecutor(), article, tableName);
                article.markAsRead();
            }
        });

        mMarkAsReadFab.hide();
        mMarkAsReadFab.setVisibility(View.VISIBLE);

        showMarkAsReadFabIfItProceeds();
    }
    return ret;
}

From source file:com.android.xbrowser.DownloadTouchIcon.java

/**
 * Use this ctor to store the touch icon in the bookmarks database for
 * the originalUrl so we take account of redirects. Used when the user
 * bookmarks a page from outside the bookmarks activity.
 *///from  w w  w.jav  a2s  .co  m
public DownloadTouchIcon(Tab tab, Context ctx, ContentResolver cr, WebView view) {
    mTab = tab;
    mContext = ctx.getApplicationContext();
    mContentResolver = cr;
    // Store these in case they change.
    mOriginalUrl = view.getOriginalUrl();
    mUrl = view.getUrl();
    mUserAgent = view.getSettings().getUserAgentString();
}

From source file:it.rignanese.leo.slimfacebook.MainActivity.java

private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    //to make the webview faster
    //settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);/*from ww w  .  j a  v a2s.  c o  m*/
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}

From source file:com.example.android.navigationdrawer.AboutUs.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aboutus);//ww  w .j a  va2  s .c  om

    WebView wv = (WebView) findViewById(R.id.aboutwebview);
    wv.loadUrl("http://202.125.255.1/finaltruetonev1/index.php/user/guestAbout");
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    //        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // improve performance by indicating the list if fixed size.
    mDrawerList.setHasFixedSize(true);
    mDrawerList.setLayoutManager(new LinearLayoutManager(this));

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new PlanetAdapter(mPlanetTitles, this));
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(2);
    }
}

From source file:com.hhs.hfnavigator.slidingtabs.tools.EdmodoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();//from w w  w  .  ja  v  a  2s  .  c om
    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
            }
        });
        webView.loadUrl("http://www.edmodo.com/m");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);

    }
    return root;
}