List of usage examples for android.webkit WebView setWebChromeClient
public void setWebChromeClient(WebChromeClient client)
From source file:Main.java
public static void releaseWebView(WebView webview) { webview.stopLoading();/*from ww w .jav a 2 s . c o m*/ webview.setWebChromeClient(null); webview.setWebViewClient(null); webview.destroy(); webview = null; }
From source file:Main.java
/** * <p>Configures basic settings of the webView (Javascript enabled, DOM storage enabled, * database enabled).</p>//w ww . j ava 2 s . c o m * * @param webView The shared webView. */ @SuppressLint("SetJavaScriptEnabled") private static void configureWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); webView.setWebChromeClient(new WebChromeClient()); }
From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java
public static void loadText(final WebView webView, final String text) { webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadDataWithBaseURL(BASE_URL, CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX, HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null); }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static void showAboutDialog(final Context mContext) { LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = li.inflate(R.layout.about, null); String sVersionInfo = ""; try {// ww w. j av a 2 s .c o m PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); sVersionInfo += pi.versionName; if (!pi.versionName.contains("" + pi.versionCode)) sVersionInfo += " (" + pi.versionCode + ")"; if (OpenExplorer.IS_DEBUG_BUILD) sVersionInfo += " *debug*"; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String sBuildTime = ""; try { sBuildTime = SimpleDateFormat.getInstance() .format(new Date(new ZipFile( mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0).sourceDir) .getEntry("classes.dex").getTime())); } catch (Exception e) { Logger.LogError("Couldn't get Build Time.", e); } WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); Display d = wm.getDefaultDisplay(); String sHardwareInfo = "Display:\n"; sHardwareInfo += "Size: " + d.getWidth() + "x" + d.getHeight() + "\n"; if (dm != null) sHardwareInfo += "Density: " + dm.density + "\n"; sHardwareInfo += "Rotation: " + d.getRotation() + "\n\n"; sHardwareInfo += getNetworkInfo(mContext); sHardwareInfo += getDeviceInfo(); ((TextView) view.findViewById(R.id.about_hardware)).setText(sHardwareInfo); final String sSubject = "Feedback for OpenExplorer " + sVersionInfo; OnClickListener email = new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //intent.addCategory(Intent.CATEGORY_APP_EMAIL); intent.putExtra(android.content.Intent.EXTRA_TEXT, "\n" + getDeviceInfo()); intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "brandroid64@gmail.com" }); intent.putExtra(android.content.Intent.EXTRA_SUBJECT, sSubject); mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.s_chooser_email))); } }; OnClickListener viewsite = new OnClickListener() { public void onClick(View v) { mContext.startActivity( new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://brandroid.org/open/"))); } }; view.findViewById(R.id.about_email).setOnClickListener(email); view.findViewById(R.id.about_email_btn).setOnClickListener(email); view.findViewById(R.id.about_site).setOnClickListener(viewsite); view.findViewById(R.id.about_site_btn).setOnClickListener(viewsite); final View mRecentLabel = view.findViewById(R.id.about_recent_status_label); final WebView mRecent = (WebView) view.findViewById(R.id.about_recent); final OpenChromeClient occ = new OpenChromeClient(); occ.mStatus = (TextView) view.findViewById(R.id.about_recent_status); mRecent.setWebChromeClient(occ); mRecent.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { occ.mStatus.setVisibility(View.GONE); mRecent.setVisibility(View.GONE); mRecentLabel.setVisibility(View.GONE); } }); mRecent.setBackgroundColor(Color.TRANSPARENT); mRecent.loadUrl("http://brandroid.org/open/?show=recent"); ((TextView) view.findViewById(R.id.about_version)).setText(sVersionInfo); if (sBuildTime != "") ((TextView) view.findViewById(R.id.about_buildtime)).setText(sBuildTime); else ((TableRow) view.findViewById(R.id.row_buildtime)).setVisibility(View.GONE); fillShortcutsTable((TableLayout) view.findViewById(R.id.shortcuts_table)); final View tab1 = view.findViewById(R.id.tab1); final View tab2 = view.findViewById(R.id.tab2); final View tab3 = view.findViewById(R.id.tab3); ((Button) view.findViewById(R.id.btn_recent)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.VISIBLE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_hardware)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.VISIBLE); tab3.setVisibility(View.GONE); } }); ((Button) view.findViewById(R.id.btn_shortcuts)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tab1.setVisibility(View.GONE); tab2.setVisibility(View.GONE); tab3.setVisibility(View.VISIBLE); } }); AlertDialog mDlgAbout = new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setView(view) .create(); mDlgAbout.getWindow().getAttributes().windowAnimations = R.style.SlideDialogAnimation; mDlgAbout.getWindow().getAttributes().alpha = 0.9f; mDlgAbout.show(); }
From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java
@SuppressLint("ObsoleteSdkInt") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void unBindView(View view) { if (view == null) return;/*from ww w .ja v a 2 s .co m*/ Drawable drawable; int i; //1. try { view.setOnClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //2. try { view.setOnCreateContextMenuListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //3. try { view.setOnFocusChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //4. try { view.setOnKeyListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //5. try { view.setOnLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //6. try { view.setOnTouchListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //7. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { view.setOnApplyWindowInsetsListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //8. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnContextClickListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //9. try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setOnScrollChangeListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //10. try { view.setOnDragListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //11. try { view.setOnGenericMotionListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } //12. try { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13 view.setOnHoverListener(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } //13. try { view.setOnSystemUiVisibilityChangeListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } /** * @see SwipeRefreshLayout#onDetachedFromWindow() */ if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) { try { view.getBackground().setCallback(null); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16 view.setBackgroundDrawable(null); } else { view.setBackground(null); } } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageView if (view instanceof ImageView) { try { ImageView imageView = (ImageView) view; drawable = imageView.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageView.setImageDrawable(null); imageView.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //TextView if (view instanceof TextView) { try { TextView textView = (TextView) view; textView.setCompoundDrawables(null, null, null, null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(null, null, null, null); } textView.setCursorVisible(false); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ImageButton if (view instanceof ImageButton) { try { ImageButton imageButton = (ImageButton) view; drawable = imageButton.getDrawable(); if (drawable != null) { drawable.setCallback(null); } imageButton.setImageDrawable(null); imageButton.setImageBitmap(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //ListView if (view instanceof ListView) { ListView listView = (ListView) view; try { listView.setAdapter(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnScrollListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemLongClickListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } try { listView.setOnItemSelectedListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //RecyclerView if (view instanceof RecyclerView) { try { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setAdapter(null); recyclerView.setChildDrawingOrderCallback(null); recyclerView.setOnScrollListener(null); recyclerView.addOnScrollListener(null); recyclerView.removeOnScrollListener(null); recyclerView.setRecyclerListener(null); } catch (Throwable e) { CrashReport.postCatchedException(e); } } //WebView if (view instanceof WebView) { WebView webView = (WebView) view; try { webView.stopLoading(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.removeAllViews(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebChromeClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.setWebViewClient(null); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { webView.destroy(); } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } try { if (null != view.getParent() && view.getParent() instanceof ViewGroup) { ((ViewGroup) view.getParent()).removeView(view); } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } //SurfaceView if (view instanceof SurfaceView) { try { SurfaceView surfaceView = (SurfaceView) view; SurfaceHolder holder = surfaceView.getHolder(); if (holder != null) { Surface surface = holder.getSurface(); if (surface != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { surface.release(); } } } } catch (Throwable ignored) { CrashReport.postCatchedException(ignored); } } view.destroyDrawingCache(); view.clearAnimation(); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; int childCount = (viewGroup).getChildCount(); for (i = 0; i < childCount; i++) { unBindView((viewGroup).getChildAt(i)); } } }
From source file:com.prasanna.android.stacknetwork.FullscreenTextActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from ww w. j a v a2 s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.code_full_screen); getActionBar().hide(); CharSequence text = getIntent().getCharSequenceExtra(StringConstants.TEXT); WebView webView = (WebView) findViewById(R.id.fullScreenText); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadDataWithBaseURL(BASE_URL, CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX, HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null); }
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);//from w ww . j a v a 2 s . c om return true; } }); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://m.xincheping.com"); return v; }
From source file:com.androidquery.simplefeed.PQuery.java
private void debug(WebView wv) { wv.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { AQUtility.debug(cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId()); return true; }/*www .jav a 2 s .co m*/ }); }
From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_PROGRESS); SQLiteCookieDatabase.init(this); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); final Intent intent = getIntent(); final Uri data = intent.getData(); if (data == null || data.getHost() == null) { finish();/*from w w w . j a va2s .c o m*/ return; } final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY); OrientationUtil.setOrientation(this, intent); final WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); } }); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setTitle(url); if (url != null && url.startsWith(completeUrl)) { final HashMap<String, String> cookies = new HashMap<String, String>(); final String cookieString = CookieManager.getInstance().getCookie(url); if (cookieString != null) { // cookieString is a string like NAME=VALUE [; NAME=VALUE] for (String pair : cookieString.split(";")) { final String[] parts = pair.split("=", 2); if (parts.length != 2) { continue; } cookies.put(parts[0].trim(), parts[1].trim()); } } storeCookies(data.getHost(), cookies); WebAuthorisationScreen.this.setResult(RESULT_OK); finish(); } } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) { // hack for auth problem in android 2.1 handler.proceed(); } else { super.onReceivedSslError(view, handler, error); } } }); setContentView(view); view.loadUrl(intent.getDataString()); }
From source file:cn.sharesdk.analysis.MobclickAgentJSInterface.java
public MobclickAgentJSInterface(Context paramContext, WebView paramWebView) { this.context = paramContext; paramWebView.getSettings().setJavaScriptEnabled(true); paramWebView.setWebChromeClient(new StatisticsWebClient(null)); }