List of usage examples for android.webkit CookieManager getInstance
public static CookieManager getInstance()
From source file:com.android.browser.DownloadHandler.java
private static void onDownloadNoStreamImpl(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); // Check to see if we have an SDCard String status = Environment.getExternalStorageState(); if (!status.equals(Environment.MEDIA_MOUNTED)) { int title; String msg;/*w ww .ja v a2 s . c om*/ // Check to see if the SDCard is busy, same as the music app if (status.equals(Environment.MEDIA_SHARED)) { msg = activity.getString(R.string.download_sdcard_busy_dlg_msg); title = R.string.download_sdcard_busy_dlg_title; } else { msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename); title = R.string.download_no_sdcard_dlg_title; } new AlertDialog.Builder(activity).setTitle(title).setIconAttribute(android.R.attr.alertDialogIcon) .setMessage(msg).setPositiveButton(R.string.ok, null).show(); return; } // java.net.URI is a lot stricter than KURL so we have to encode some // extra characters. Fix for b 2538060 and b 1634719 WebAddress webAddress; try { webAddress = new WebAddress(url); webAddress.setPath(encodePath(webAddress.getPath())); } catch (Exception e) { // This only happens for very bad urls, we want to chatch the // exception here Log.e(LOGTAG, "Exception trying to parse url:" + url); return; } String addressString = webAddress.toString(); Uri uri = Uri.parse(addressString); final DownloadManager.Request request; try { request = new DownloadManager.Request(uri); } catch (IllegalArgumentException e) { Toast.makeText(activity, R.string.cannot_download, Toast.LENGTH_SHORT).show(); return; } request.setMimeType(mimetype); // set downloaded file destination to /sdcard/Download. // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype? try { request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); } catch (IllegalStateException ex) { // This only happens when directory Downloads can't be created or it isn't a directory // this is most commonly due to temporary problems with sdcard so show appropriate string Log.w(LOGTAG, "Exception trying to create Download dir:", ex); Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, Toast.LENGTH_SHORT).show(); return; } // let this downloaded file be scanned by MediaScanner - so that it can // show up in Gallery app, for example. request.allowScanningByMediaScanner(); request.setDescription(webAddress.getHost()); // XXX: Have to use the old url since the cookies were stored using the // old percent-encoded url. String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); if (!TextUtils.isEmpty(referer)) { request.addRequestHeader("Referer", referer); } request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); if (mimetype == null) { if (TextUtils.isEmpty(addressString)) { return; } // We must have long pressed on a link or image to download it. We // are not sure of the mimetype in this case, so do a head request new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start(); } else { final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE); new Thread("Browser download") { public void run() { manager.enqueue(request); } }.start(); } Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT).show(); }
From source file:com.sabaibrowser.DownloadHandler.java
private static void onDownloadNoStreamImpl(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); // Check to see if we have an SDCard String status = Environment.getExternalStorageState(); if (!status.equals(Environment.MEDIA_MOUNTED)) { int title; String msg;//from ww w.ja v a 2 s . co m // Check to see if the SDCard is busy, same as the music app if (status.equals(Environment.MEDIA_SHARED)) { msg = activity.getString(R.string.download_sdcard_busy_dlg_msg); title = R.string.download_sdcard_busy_dlg_title; } else { msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename); title = R.string.download_no_sdcard_dlg_title; } new AlertDialog.Builder(activity).setTitle(title).setIconAttribute(android.R.attr.alertDialogIcon) .setMessage(msg).setPositiveButton(R.string.ok, null).show(); return; } // java.net.URI is a lot stricter than KURL so we have to encode some // extra characters. Fix for b 2538060 and b 1634719 WebAddress webAddress; try { webAddress = new WebAddress(url); webAddress.setPath(encodePath(webAddress.getPath())); } catch (Exception e) { // This only happens for very bad urls, we want to chatch the // exception here Log.e(LOGTAG, "Exception trying to parse url:" + url); return; } String addressString = webAddress.toString(); Uri uri = Uri.parse(addressString); final DownloadManager.Request request; try { request = new DownloadManager.Request(uri); } catch (IllegalArgumentException e) { Toast.makeText(activity, R.string.cannot_download, Toast.LENGTH_SHORT).show(); return; } request.setMimeType(mimetype); // set downloaded file destination to /sdcard/Download. // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype? try { request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); } catch (IllegalStateException ex) { // This only happens when directory Downloads can't be created or it isn't a directory // this is most commonly due to temporary problems with sdcard so show appropriate string Log.w(LOGTAG, "Exception trying to create Download dir:", ex); Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, Toast.LENGTH_SHORT).show(); return; } // let this downloaded file be scanned by MediaScanner - so that it can // show up in Gallery app, for example. request.allowScanningByMediaScanner(); request.setDescription(webAddress.getHost()); // XXX: Have to use the old url since the cookies were stored using the // old percent-encoded url. String cookies = privateBrowsing ? "" : CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); if (!TextUtils.isEmpty(referer)) { request.addRequestHeader("Referer", referer); } request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); if (mimetype == null) { if (TextUtils.isEmpty(addressString)) { return; } // We must have long pressed on a link or image to download it. We // are not sure of the mimetype in this case, so do a head request new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start(); } else { final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE); new Thread("Browser download") { public void run() { manager.enqueue(request); } }.start(); } Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT).show(); }
From source file:com.msted.lensrocket.LensRocketService.java
public void logout(boolean shouldRedirectToLogin) { //Clear values mFriendNames.clear();//from www . j a va2 s . com mFriends.clear(); mRockets.clear(); //Clear the cookies so they won't auto login to a provider again CookieSyncManager.createInstance(mContext); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); //Clear the user id and token from the shared preferences SharedPreferences settings = mContext.getSharedPreferences("UserData", 0); SharedPreferences.Editor preferencesEditor = settings.edit(); preferencesEditor.clear(); preferencesEditor.commit(); //Clear settings shared preferences SharedPreferences settingsPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); if (settingsPrefs != null) { preferencesEditor = settingsPrefs.edit(); preferencesEditor.clear(); preferencesEditor.commit(); } mClient.logout(); //Take the user back to the splash screen activity to relogin if requested if (shouldRedirectToLogin) { Intent logoutIntent = new Intent(mContext, SplashScreenActivity.class); logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(logoutIntent); } }
From source file:com.near.chimerarevo.fragments.CommentsFragment.java
@SuppressLint("SetJavaScriptEnabled") private void loadDisqusOAuth() { if (getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "").length() > 1) { RequestBody formBody = new FormEncodingBuilder().add("grant_type", "refresh_token") .add("client_id", Constants.DISQUS_API_KEY).add("client_secret", Constants.DISQUS_API_SECRET) .add("refresh_token", getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "")) .build();/*from w ww. jav a 2 s . c o m*/ Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody).tag(FRAGMENT_TAG) .build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); return; } final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.webview_layout); dialog.setCancelable(true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) CookieManager.getInstance().removeAllCookies(null); else { CookieSyncManager.createInstance(getActivity()); CookieManager.getInstance().removeAllCookie(); } WebView wv = (WebView) dialog.findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setSaveFormData(false); wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dialog.findViewById(R.id.progressContainer).setVisibility(View.GONE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.VISIBLE); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); dialog.findViewById(R.id.progressContainer).setVisibility(View.VISIBLE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.GONE); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { boolean state = super.shouldOverrideUrlLoading(view, url); if (url.contains(Constants.SITE_URL)) { String code = url.split("code=")[1]; RequestBody formBody = new FormEncodingBuilder().add("grant_type", "authorization_code") .add("client_id", Constants.DISQUS_API_KEY) .add("client_secret", Constants.DISQUS_API_SECRET) .add("redirect_uri", Constants.SITE_URL).add("code", code).build(); Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody) .tag(FRAGMENT_TAG).build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); dialog.dismiss(); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); } return state; } @Override public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) { handler.proceed(); } }); wv.loadUrl(URLUtils.getDisqusAuthUrl()); isDialogOpen = true; mFab.hide(); dialog.show(); }
From source file:de.baumann.browser.Browser_right.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(ContextCompat.getColor(Browser_right.this, R.color.colorTwoDark)); WebView.enableSlowWholeDocumentDraw(); setContentView(R.layout.activity_browser); helper_main.onStart(Browser_right.this); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); sharedPref.edit()/*from w w w. j a va2 s. com*/ .putString("openURL", sharedPref.getString("startURL", "https://github.com/scoute-dich/browser/")) .apply(); sharedPref.edit().putInt("keyboard", 0).apply(); sharedPref.getInt("keyboard", 0); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setBackgroundColor(ContextCompat.getColor(Browser_right.this, R.color.colorTwo)); setSupportActionBar(toolbar); actionBar = getSupportActionBar(); customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer); progressBar = (ProgressBar) findViewById(R.id.progressBar); editText = (EditText) findViewById(R.id.editText); editText.setVisibility(View.GONE); editText.setHint(R.string.app_search_hint); editText.clearFocus(); urlBar = (TextView) findViewById(R.id.urlBar); imageButton = (ImageButton) findViewById(R.id.imageButton); imageButton.setVisibility(View.INVISIBLE); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mWebView.scrollTo(0, 0); imageButton.setVisibility(View.INVISIBLE); if (!actionBar.isShowing()) { urlBar.setText(mWebView.getTitle()); actionBar.show(); } helper_browser.setNavArrows(mWebView, imageButton_left, imageButton_right); } }); SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); assert swipeView != null; swipeView.setColorSchemeResources(R.color.colorTwo, R.color.colorAccent); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); mWebView = (ObservableWebView) findViewById(R.id.webView); if (sharedPref.getString("fullscreen", "2").equals("2") || sharedPref.getString("fullscreen", "2").equals("3")) { mWebView.setScrollViewCallbacks(this); } mWebChromeClient = new myWebChromeClient(); mWebView.setWebChromeClient(mWebChromeClient); imageButton_left = (ImageButton) findViewById(R.id.imageButton_left); imageButton_right = (ImageButton) findViewById(R.id.imageButton_right); if (sharedPref.getBoolean("arrow", false)) { imageButton_left.setVisibility(View.VISIBLE); imageButton_right.setVisibility(View.VISIBLE); } else { imageButton_left.setVisibility(View.INVISIBLE); imageButton_right.setVisibility(View.INVISIBLE); } helper_webView.webView_Settings(Browser_right.this, mWebView); helper_webView.webView_WebViewClient(Browser_right.this, swipeView, mWebView, urlBar); mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); if (isNetworkUnAvailable()) { if (sharedPref.getBoolean("offline", false)) { if (isNetworkUnAvailable()) { // loading offline mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); Snackbar.make(mWebView, R.string.toast_cache, Snackbar.LENGTH_SHORT).show(); } } else { Snackbar.make(mWebView, R.string.toast_noInternet, Snackbar.LENGTH_SHORT).show(); } } mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(final String url, String userAgent, final String contentDisposition, final String mimetype, long contentLength) { registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); Snackbar snackbar = Snackbar .make(mWebView, getString(R.string.toast_download_1) + " " + filename, Snackbar.LENGTH_LONG) .setAction(getString(R.string.toast_yes), new View.OnClickListener() { @Override public void onClick(View view) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.toast_download) + " " + filename, Snackbar.LENGTH_SHORT).show(); } }); snackbar.show(); } }); helper_browser.toolbar(Browser_right.this, Browser_left.class, mWebView, toolbar); helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar); helper_editText.editText_FocusChange(editText, Browser_right.this); helper_main.grantPermissionsStorage(Browser_right.this); onNewIntent(getIntent()); }
From source file:im.ene.lab.attiq.ui.activities.HomeActivity.java
private void logout() { // Show a dialog new AlertDialog.Builder(this).setMessage(R.string.logout_confirm) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override//from w w w . j a va2 s . co m public void onClick(DialogInterface dialog, int which) { if (dialog != null) { dialog.dismiss(); } } }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (dialog != null) { dialog.dismiss(); } mRealm.beginTransaction(); mRealm.clear(Profile.class); mRealm.clear(FeedItem.class); mRealm.clear(StockArticle.class); mRealm.clear(ReadArticle.class); mRealm.commitTransaction(); mMyProfile = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().removeAllCookies(null); } else { CookieManager.getInstance().removeAllCookie(); } PrefUtil.setCurrentToken(null); PrefUtil.setFirstStart(true); EventBus.getDefault() .post(new ProfileEvent(HomeActivity.class.getSimpleName(), true, null, null)); } }).create().show(); }
From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java
private void enableCookies(WebView webView) { CookieManager.getInstance().setAcceptCookie(true); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true); }/*from www . j a va 2 s .co m*/ }
From source file:de.baumann.browser.helper.helper_webView.java
public static void closeWebView(Activity from, WebView webView) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from); if (sharedPref.getBoolean("clearCookies", false)) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookies(null); cookieManager.flush();/*from ww w . j ava 2s . co m*/ } if (sharedPref.getBoolean("clearCache", false)) { webView.clearCache(true); } if (sharedPref.getBoolean("clearForm", false)) { webView.clearFormData(); } if (sharedPref.getBoolean("history", false)) { from.deleteDatabase("history.db"); webView.clearHistory(); } helper_main.isClosed(from); sharedPref.edit().putString("started", "").apply(); from.finishAffinity(); }
From source file:mgks.os.webview.MainActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "WrongViewCast" }) @Override/*from w w w . j a v a2s .c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.w("READ_PERM = ", Manifest.permission.READ_EXTERNAL_STORAGE); Log.w("WRITE_PERM = ", Manifest.permission.WRITE_EXTERNAL_STORAGE); //Prevent the app from being started again when it is still alive in the background if (!isTaskRoot()) { finish(); return; } setContentView(R.layout.activity_main); asw_view = findViewById(R.id.msw_view); final SwipeRefreshLayout pullfresh = findViewById(R.id.pullfresh); if (ASWP_PULLFRESH) { pullfresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { pull_fresh(); pullfresh.setRefreshing(false); } }); asw_view.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (asw_view.getScrollY() == 0) { pullfresh.setEnabled(true); } else { pullfresh.setEnabled(false); } } }); } else { pullfresh.setRefreshing(false); pullfresh.setEnabled(false); } if (ASWP_PBAR) { asw_progress = findViewById(R.id.msw_progress); } else { findViewById(R.id.msw_progress).setVisibility(View.GONE); } asw_loading_text = findViewById(R.id.msw_loading_text); Handler handler = new Handler(); //Launching app rating request if (ASWP_RATINGS) { handler.postDelayed(new Runnable() { public void run() { get_rating(); } }, 1000 * 60); //running request after few moments } //Getting basic device information get_info(); //Getting GPS location of device if given permission if (ASWP_LOCATION && !check_permission(1)) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm); } get_location(); //Webview settings; defaults are customized for best performance WebSettings webSettings = asw_view.getSettings(); if (!ASWP_OFFLINE) { webSettings.setJavaScriptEnabled(ASWP_JSCRIPT); } webSettings.setSaveFormData(ASWP_SFORM); webSettings.setSupportZoom(ASWP_ZOOM); webSettings.setGeolocationEnabled(ASWP_LOCATION); webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); asw_view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); asw_view.setHapticFeedbackEnabled(false); asw_view.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { if (!check_permission(2)) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, file_perm); } else { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setMimeType(mimeType); String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); request.setDescription(getString(R.string.dl_downloading)); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); assert dm != null; dm.enqueue(request); Toast.makeText(getApplicationContext(), getString(R.string.dl_downloading2), Toast.LENGTH_LONG) .show(); } } }); if (Build.VERSION.SDK_INT >= 21) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null); webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } else if (Build.VERSION.SDK_INT >= 19) { asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null); } asw_view.setVerticalScrollBarEnabled(false); asw_view.setWebViewClient(new Callback()); //Rendering the default URL aswm_view(ASWV_URL, false); asw_view.setWebChromeClient(new WebChromeClient() { //Handling input[type="file"] requests for android API 16+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { if (ASWP_FUPLOAD) { asw_file_message = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType(ASWV_F_TYPE); if (ASWP_MULFILE) { i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } startActivityForResult(Intent.createChooser(i, getString(R.string.fl_chooser)), asw_file_req); } } //Handling input[type="file"] requests for android API 21+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (check_permission(2) && check_permission(3)) { if (ASWP_FUPLOAD) { if (asw_file_path != null) { asw_file_path.onReceiveValue(null); } asw_file_path = filePathCallback; Intent takePictureIntent = null; if (ASWP_CAMUPLOAD) { takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = create_image(); takePictureIntent.putExtra("PhotoPath", asw_cam_message); } catch (IOException ex) { Log.e(TAG, "Image file creation failed", ex); } if (photoFile != null) { asw_cam_message = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); if (!ASWP_ONLYCAM) { contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType(ASWV_F_TYPE); if (ASWP_MULFILE) { contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } } Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.fl_chooser)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, asw_file_req); } return true; } else { get_file(); return false; } } //Getting webview rendering progress @Override public void onProgressChanged(WebView view, int p) { if (ASWP_PBAR) { asw_progress.setProgress(p); if (p == 100) { asw_progress.setProgress(0); } } } // overload the geoLocations permissions prompt to always allow instantly as app permission was granted previously public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { if (Build.VERSION.SDK_INT < 23 || check_permission(1)) { // location permissions were granted previously so auto-approve callback.invoke(origin, true, false); } else { // location permissions not granted so request them ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm); } } }); if (getIntent().getData() != null) { String path = getIntent().getDataString(); /* If you want to check or use specific directories or schemes or hosts Uri data = getIntent().getData(); String scheme = data.getScheme(); String host = data.getHost(); List<String> pr = data.getPathSegments(); String param1 = pr.get(0); */ aswm_view(path, false); } }
From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java
@Override public void onAccountLogoutSuccess() { LOG.debug("onAccountLogoutSuccess"); this.onAccountIsNotLoggedIn(); this.annotationsManager = null; //if current account ?? final SimplifiedCatalogAppServicesType app = Simplified.getCatalogAppServices(); app.getBooks().destroyBookStatusCache(); Simplified.getCatalogAppServices().reloadCatalog(true, this.account); final Resources rr = NullCheck.notNull(this.getResources()); final Context context = this.getApplicationContext(); final CharSequence text = NullCheck.notNull(rr.getString(R.string.settings_logout_succeeded)); final int duration = Toast.LENGTH_SHORT; final TextView bt = NullCheck.notNull(this.barcode_text); final TextView pt = NullCheck.notNull(this.pin_text); UIThread.runOnUIThread(() -> {//w w w. j ava2 s .c o m bt.setVisibility(View.GONE); pt.setVisibility(View.GONE); final Toast toast = Toast.makeText(context, text, duration); toast.show(); finish(); overridePendingTransition(0, 0); startActivity(getIntent()); overridePendingTransition(0, 0); }); // logout clever if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { final CookieSyncManager cookie_sync_manager = CookieSyncManager.createInstance(this); cookie_sync_manager.startSync(); final CookieManager cookie_manager = CookieManager.getInstance(); cookie_manager.removeAllCookie(); cookie_manager.removeSessionCookie(); cookie_sync_manager.stopSync(); cookie_sync_manager.sync(); } }