Java Code Examples for android.webkit.WebView#setWebViewClient()

The following examples show how to use android.webkit.WebView#setWebViewClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestActivity.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
private void initWebView() {
    WebView webView = (WebView) findViewById(R.id.test_activity_webView);
    webView.loadUrl("https://www.analysys.cn");
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAllowContentAccess(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view,
                                                String url) { //
            // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
            view.loadUrl(url);
            return true;
        }
    });
}
 
Example 2
Source File: TestCaseListActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void setClient(WebView web) {

        web.setWebChromeClient(new WebChromeClient() {
        });

        // 如果要自动唤起自定义的scheme,不能设置WebViewClient,
        // 否则,需要在shouldOverrideUrlLoading中自行处理自定义scheme
        // webView.setWebViewClient();
        web.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

        });
    }
 
Example 3
Source File: IssuePreviewActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void resetView() {
       setContentView(R.layout.activity_issue_preview);

	((TextView) findViewById(R.id.title)).setText(Utils.stripTags(title));

       final WebView web = (WebView) findViewById(R.id.detailsLabel);
       web.loadDataWithBaseURL(null, details, "text/html", "utf-8", null);
       web.setWebViewClient(new WebViewClient() {
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
           	try {
           		view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
           	} catch (Exception failed) {
           		return false;
           	}
               return true;
           }
       });
}
 
Example 4
Source File: PresentationActivity.java    From Pimp_my_Z1 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //noinspection ConstantConditions
    getActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.presentation_activity);
    mWebView = (WebView) findViewById(R.id.webView);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.loadUrl("file:///android_asset/slides/index.html");
}
 
Example 5
Source File: MainActivity.java    From Android-File-Chooser with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    verifyStoragePermissions(this);

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

    webView.loadUrl("https://en.imgbb.com/");
}
 
Example 6
Source File: MapPathHtml.java    From pe-protector-moe with GNU General Public License v3.0 6 votes vote down vote up
public MapPathHtml(String name, String config, WebView webview, HttpFinishCallBack callBack) {
    this.callBack = callBack;
    webview.loadUrl("file:///android_asset/html/map.html");
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            String f = "";
            if (!name.equals("")) {
                List<MapConfigBean> list = LitePal
                        .limit(1)
                        .where("name=?", name)
                        .find(MapConfigBean.class);
                if (list.size() > 0) {
                    f = list.get(0).data;
                }
            }
            if (!config.equals("")) {
                f = config;
            }
            String code = String.format("javascript:onLoad(\'%s\', \'%s\')", name, f);
            Log.i(TAG, "[JavaScript] 执行脚本" + code);
            view.loadUrl(code);
        }
    });
}
 
Example 7
Source File: UIHelper.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
public static void initWebView(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setDefaultFontSize(15);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    int sysVersion = Build.VERSION.SDK_INT;
    if (sysVersion >= 11) {
        settings.setDisplayZoomControls(false);
    } else {
        ZoomButtonsController zbc = new ZoomButtonsController(webView);
        zbc.getZoomControls().setVisibility(View.GONE);
    }
    webView.setWebViewClient(UIHelper.getWebViewClient());
}
 
Example 8
Source File: WebViewTestActivity.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view_test);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }
    });
    mWebView.loadUrl("http://www.baidu.com");

}
 
Example 9
Source File: HelpActivity.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  String subtitle = getString(R.string.my_tracks_app_name) + " v"
      + SystemUtils.getMyTracksVersion(this);
  ApiAdapterFactory.getApiAdapter()
      .setTitleAndSubtitle(this, getString(R.string.menu_help), subtitle);

  webView = (WebView) findViewById(R.id.help_webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient());

  if (savedInstanceState == null) {
    String language = Locale.getDefault().getLanguage();
    if (language == null || language.equals("")) {
      language = "en";
    }
    webView.loadUrl(getString(R.string.my_tracks_help_url, language));
  } else {
    webView.restoreState(savedInstanceState);
  }

  Button feedback = (Button) findViewById(R.id.help_feedback);
  boolean showFeedback = ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable();
  feedback.setVisibility(showFeedback ? View.VISIBLE : View.GONE);
  if (showFeedback) {
    feedback.setOnClickListener(new View.OnClickListener() {
        @Override
      public void onClick(View v) {
        GoogleFeedbackUtils.bindFeedback(HelpActivity.this);
      }
    });
  }
}
 
Example 10
Source File: AdvertiseActivity.java    From AnimeTaste with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAdvertise = getIntent().getParcelableExtra("Advertise");
    setContentView(R.layout.activity_advertise);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(mAdvertise.Name);
    mAdvertiseClient = new AdvertiseClient();
    mAdvertiseWebView = (WebView)findViewById(R.id.recommend_webview);
    mAdvertiseWebView.getSettings().setJavaScriptEnabled(true);
    mAdvertiseWebView.setWebViewClient(mAdvertiseClient);
    mAdvertiseWebView.loadUrl(mAdvertise.Link);
}
 
Example 11
Source File: RMBTTermsFragment.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
{
    
    activity = getActivity();
    
    webview = new WebView(activity);
    
    /* JavaScript must be enabled if you want it to work, obviously */
    // webview.getSettings().setJavaScriptEnabled(true);
    
    webview.getSettings().setSupportZoom(true);
    webview.getSettings().setBuiltInZoomControls(true);
    
    webview.setWebViewClient(new WebViewClient()
    {
        @Override
        public void onReceivedError(final WebView view, final int errorCode, final String description,
                final String failingUrl)
        {
            super.onReceivedError(view, errorCode, description, failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
        }
    });
    
    webview.loadUrl(this.getString(R.string.url_terms));
    
    return webview;
}
 
Example 12
Source File: OAuthWebViewDialogFragment.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

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

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    progressGroup = (ViewGroup) view.findViewById(R.id.progress);
    errorGroup = (ViewGroup) view.findViewById(R.id.error);

    webView = (WebView) view.findViewById(R.id.webview);
    // Javascript is necessary to display OpenStreetMap's OAuth page correctly
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new OAuthCallbackWebViewClient(
            new RetrieveVerificationCodeListener(), webView, progressGroup));

    Button tryAgain = (Button) view.findViewById(R.id.retry_button);
    tryAgain.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            restartAuthentication();
        }
    });

    return view;
}
 
Example 13
Source File: UConfigActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
  CookieManager cookieManager = CookieManager.getInstance();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    cookieManager.flush();
    cookieManager.removeAllCookies(null);
    cookieManager.removeSessionCookies(null);
  } else {
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
    cookieSyncManager.startSync();
    cookieManager.removeAllCookie();
    cookieManager.removeSessionCookie();
    cookieSyncManager.stopSync();
  }

  // Copy cookies from okhttp cookie store to CookieManager
  url = EhUrl.getUConfigUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_u_config);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = (WebView) findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new UConfigWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = (ProgressView) findViewById(R.id.progress);

  Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
}
 
Example 14
Source File: SensorUpdates.java    From SensorsAndAi with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate ( savedInstanceState );
    requestWindowFeature ( Window.FEATURE_NO_TITLE );//for full screen
    getWindow ().setFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN );
    setContentView ( R.layout.activity_sensor_updates );
    mywebView =(WebView)findViewById ( R.id.webView );
    WebSettings webSettings = mywebView.getSettings ();
    webSettings.setJavaScriptEnabled ( true );
    mywebView.loadUrl ( "https://sensors7834.blogspot.in" );
    mywebView.setWebViewClient ( new WebViewClient () );//prevents our url to open in another browser

}
 
Example 15
Source File: PrefetchService.java    From GankMeizhi with Apache License 2.0 5 votes vote down vote up
@UiThread
private void load(String url) {
    WebView webView = new WebView(this);
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                Log.d(TAG, "onProgressChanged: " + view.getUrl());
            }
        }
    });
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    String cacheDirPath = getFilesDir().getAbsolutePath() + "/webviewcache";
    webView.getSettings().setDatabasePath(cacheDirPath);
    webView.getSettings().setAppCachePath(cacheDirPath);
    webView.getSettings().setAppCacheEnabled(true);

    webView.requestFocus();
    webView.getSettings().getAllowFileAccess();

    webView.loadUrl(url);
}
 
Example 16
Source File: PageAndListRowFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FrameLayout root = new FrameLayout(getActivity());
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    lp.setMarginStart(32);
    mWebview = new WebView(getActivity());
    mWebview.setWebViewClient(new WebViewClient());
    mWebview.getSettings().setJavaScriptEnabled(true);
    root.addView(mWebview, lp);
    return root;
}
 
Example 17
Source File: NewsDetailActivity.java    From LiuAGeAndroid with MIT License 4 votes vote down vote up
/**
     * 准备UI
     */
    private void prepareUI() {
        mTopBar = findViewById(R.id.v_cell_news_detail_top_bar);
        mContentView = (ViewGroup) findViewById(R.id.activity_news_detail);
        mProgressBar = (ProgressBar) findViewById(R.id.pb_news_detail_progressbar);
        mScrollView = (ScrollView) findViewById(R.id.bsv_news_detail_scrollview);
        mContentWebView = (WebView) findViewById(R.id.wv_news_detail_webview);
        mShareQQButton = findViewById(R.id.ll_article_content_share_qq);
        mShareWxButton = findViewById(R.id.ll_article_content_share_weixin);
        mSharePyqButton = findViewById(R.id.ll_article_content_share_pyq);
        mBackButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_back);
        mEditButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_edit);
        mFontButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_font);
        mCollectionButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_collection);
        mShareButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_share);
        mLinkLayout = (LinearLayout) findViewById(R.id.ll_news_detail_links);
        mLinkRecyclerView = (RecyclerView) findViewById(R.id.rv_news_detail_links_recyclerview);
        mCommentLayout = (LinearLayout) findViewById(R.id.ll_news_detail_comment);
        mCommentRecyclerView = (RecyclerView) findViewById(R.id.rv_news_detail_comment_recyclerview);
        mMoreCommentButton = (Button) findViewById(R.id.btn_news_detail_comment_more);
        mAdImageView = (SimpleDraweeView) findViewById(R.id.iv_news_detail_ad_image);
        mAdTextView = (TextView) findViewById(R.id.tv_news_detail_ad_text);

        // 如果未能修改掉状态栏的颜色,就修改状态栏的背景颜色
        if (!isStatusChanged) {
            mTopBar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            mTopBar.setAlpha(1);
        }

        // 新闻正文
        WebSettings webSettings = mContentWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // 开启硬件加速后,webView内容太大会crash 还在寻求最终解决办法
//        mContentWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        mContentWebView.addJavascriptInterface(new ArticleJavascriptInterface(), "ARTICLE");
        mContentWebView.setWebChromeClient(new WebChromeClient() {
        });
        mContentWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // 隐藏加载进度条
                mProgressBar.setVisibility(View.INVISIBLE);
                // 网页加载完成才去加载其他UI
                setupDetailData();
                // 加载网页缓存图片
                getImageFromDownloaderOrDiskByImageUrlArray();
                // 页面滑动到顶部
                mScrollView.fullScroll(ScrollView.FOCUS_UP);
            }

        });

        // 底部工具条按钮点击事件
        mBackButton.setOnClickListener(this);
        mEditButton.setOnClickListener(this);
        mFontButton.setOnClickListener(this);
        mCollectionButton.setOnClickListener(this);
        mShareButton.setOnClickListener(this);
        mShareQQButton.setOnClickListener(this);
        mShareWxButton.setOnClickListener(this);
        mSharePyqButton.setOnClickListener(this);
        mAdImageView.setOnClickListener(this);

        // 更多评论
        mMoreCommentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到评论列表
                CommentListActivity.start(mContext, classid, id, commentBeanList, "news");
            }
        });

    }
 
Example 18
Source File: EvernoteOAuthActivity.java    From EverMemo with MIT License 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Show web loading progress
	getWindow().requestFeature(Window.FEATURE_PROGRESS);

	setContentView(R.layout.esdk__webview);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setDisplayUseLogoEnabled(false);
	getSupportActionBar().setDisplayShowTitleEnabled(true);
	mActivity = this;

	mWebView = (WebView) findViewById(R.id.esdk__webview);
	mWebView.setWebViewClient(mWebViewClient);
	mWebView.setWebChromeClient(mWebChromeClient);
	mWebView.getSettings().setJavaScriptEnabled(true);

	if (savedInstanceState != null) {
		mEvernoteService = savedInstanceState
				.getParcelable(EXTRA_EVERNOTE_SERVICE);
		mConsumerKey = savedInstanceState.getString(EXTRA_CONSUMER_KEY);
		mConsumerSecret = savedInstanceState
				.getString(EXTRA_CONSUMER_SECRET);
		mRequestToken = savedInstanceState.getString(EXTRA_REQUEST_TOKEN);
		mRequestTokenSecret = savedInstanceState
				.getString(EXTRA_REQUEST_TOKEN_SECRET);
		mSelectedBootstrapProfile = (BootstrapProfile) savedInstanceState
				.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILE);
		mSelectedBootstrapProfilePos = savedInstanceState
				.getInt(EXTRA_BOOTSTRAP_SELECTED_PROFILE_POS);
		mBootstrapProfiles = (ArrayList<BootstrapProfile>) savedInstanceState
				.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILES);
		mWebView.restoreState(savedInstanceState);

	} else {
		Intent intent = getIntent();
		mEvernoteService = intent
				.getParcelableExtra(EXTRA_EVERNOTE_SERVICE);
		mConsumerKey = intent.getStringExtra(EXTRA_CONSUMER_KEY);
		mConsumerSecret = intent.getStringExtra(EXTRA_CONSUMER_SECRET);
	}
}
 
Example 19
Source File: LightningView.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
    BrowserApp.getAppComponent().inject(this);
    mActivity = activity;
    mUIController = (UIController) activity;
    mWebView = new WebView(activity);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.setId(View.generateViewId());
    }
    mIsIncognitoTab = isIncognito;
    mTitle = new LightningViewTitle(activity);

    sMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();

    mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
    mWebView.setFocusableInTouchMode(true);
    mWebView.setFocusable(true);
    mWebView.setDrawingCacheEnabled(false);
    mWebView.setWillNotCacheDrawing(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        mWebView.setAnimationCacheEnabled(false);
        //noinspection deprecation
        mWebView.setAlwaysDrawnWithCacheEnabled(false);
    }
    mWebView.setBackgroundColor(Color.WHITE);

    mWebView.setScrollbarFadingEnabled(true);
    mWebView.setSaveEnabled(true);
    mWebView.setNetworkAvailable(true);
    mWebView.setWebChromeClient(new LightningChromeClient(activity, this));
    mWebView.setWebViewClient(new LightningWebClient(activity, this));
    mWebView.setDownloadListener(new LightningDownloadListener(activity));
    mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
    mWebView.setOnTouchListener(new TouchListener());
    sDefaultUserAgent = mWebView.getSettings().getUserAgentString();
    initializeSettings();
    initializePreferences(activity);

    if (url != null) {
        if (!url.trim().isEmpty()) {
            mWebView.loadUrl(url, mRequestHeaders);
        } else {
            // don't load anything, the user is looking for a blank tab
        }
    } else {
        loadHomepage();
    }
}
 
Example 20
Source File: ZbigzFragment.java    From video-player with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View InputFragmentView = inflater.inflate(R.layout.fragment_zbigz, container, false);
    tWebView = (WebView) InputFragmentView.findViewById(R.id.zbigz_web_view);
    tProgressBar = (ProgressBar) InputFragmentView.findViewById(R.id.zbigz_progress_bar);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tWebView.getSettings().setAllowContentAccess(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        tWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        tWebView.getSettings().setAllowFileAccessFromFileURLs(true);
    }

    tWebView.getSettings().setAppCacheEnabled(true);
    tWebView.getSettings().setAllowFileAccess(true);
    tWebView.getSettings().setDatabaseEnabled(true);
    tWebView.getSettings().setDomStorageEnabled(true);
    tWebView.getSettings().setSaveFormData(true);
    tWebView.getSettings().setJavaScriptEnabled(true);
    tWebView.setWebViewClient(new WebViewClient());

    tWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            mListener.onZbigzFragmentInteraction(url);
        }
    });

    tWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && tProgressBar.getVisibility() == ProgressBar.GONE) {
                tProgressBar.setVisibility(ProgressBar.VISIBLE);
                tWebView.setVisibility(WebView.GONE);
            }
            tProgressBar.setProgress(progress);
            if (progress == 100) {
                tProgressBar.setVisibility(ProgressBar.GONE);
                tWebView.setVisibility(WebView.VISIBLE);
            }
        }
    });

    tWebView.loadUrl("http://m.zbigz.com/");
    return InputFragmentView;
}