List of usage examples for android.webkit WebSettings setGeolocationEnabled
public abstract void setGeolocationEnabled(boolean flag);
From source file:com.nbplus.hybrid.BasicWebViewClient.java
/** * ??.// ww w .j a v a2s . c om * @param activity : context * @param view : ?? */ public BasicWebViewClient(Activity activity, WebView view, String alertTitleString, String confirmTitleString) { mWebView = view; mContext = activity; // This will handle downloading. It requires Gingerbread, though mDownloadManager = (DownloadManager) mContext.getSystemService(mContext.DOWNLOAD_SERVICE); mWebChromeClient = new BroadcastWebChromeClient(); // Enable remote debugging via chrome://inspect if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebView.setWebContentsDebuggingEnabled(true); } mWebView.setWebChromeClient(mWebChromeClient); WebSettings webSettings = mWebView.getSettings(); webSettings.setGeolocationEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { webSettings.setMediaPlaybackRequiresUserGesture(false); } // Enable pinch to zoom without the zoom buttons webSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ webSettings.setDisplayZoomControls(false); } webSettings.setAppCacheEnabled(true); mWebView.clearCache(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Sets whether the WebView should allow third party cookies to be set. // Allowing third party cookies is a per WebView policy and can be set differently on different WebView instances. // Apps that target KITKAT or below default to allowing third party cookies. // Apps targeting LOLLIPOP or later default to disallowing third party cookies. CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setAcceptThirdPartyCookies(mWebView, true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mWebView.getSettings().setTextZoom(100); } if (StringUtils.isEmptyString(alertTitleString)) { mAlertTitleString = activity.getString(R.string.default_webview_alert_title); } else { mAlertTitleString = alertTitleString; } if (StringUtils.isEmptyString(confirmTitleString)) { mConfirmTitleString = activity.getString(R.string.default_webview_confirm_title); } else { mConfirmTitleString = confirmTitleString; } mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); mContext.startActivity(intent); } }); Log.d(TAG, ">> user agent = " + mWebView.getSettings().getUserAgentString()); }
From source file:com.rfo.basic.Web.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.v(LOGTAG, "onCreate"); super.onCreate(savedInstanceState); ContextManager cm = Basic.getContextManager(); cm.registerContext(ContextManager.ACTIVITY_WEB, this); cm.setCurrent(ContextManager.ACTIVITY_WEB); setContentView(R.layout.web);//ww w.ja v a 2 s .co m View v = findViewById(R.id.web_engine); Intent intent = getIntent(); int showStatusBar = intent.getIntExtra(EXTRA_SHOW_STATUSBAR, 0); int orientation = intent.getIntExtra(EXTRA_ORIENTATION, -1); showStatusBar = (showStatusBar == 0) ? WindowManager.LayoutParams.FLAG_FULLSCREEN // do not show status bar : WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; // show status bar getWindow().setFlags(showStatusBar, showStatusBar); setOrientation(orientation); engine = (WebView) v; WebSettings webSettings = engine.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setAppCacheEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setGeolocationEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); engine.addJavascriptInterface(new JavaScriptInterface(), "Android"); engine.setWebViewClient(new MyWebViewClient()); aWebView = new TheWebView(this); engine.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { //Required functionality here return super.onJsAlert(view, url, message, result); } }); }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
/** * @param view Instance of flashcard.xml */// w ww. j ava 2 s.c o m public Flashcard(View view, OnCardAnsweredListener listener) { mListener = listener; mView = view; mQuestion = (StyledMarkdownView) view.findViewById(R.id.question); mAnswer = (StyledMarkdownView) view.findViewById(R.id.answer); mCardView = (CardView) view.findViewById(R.id.card); mButtonBar = view.findViewById(R.id.button_bar); mCorrectButton = (Button) view.findViewById(R.id.correct_button); mWrongButton = (Button) view.findViewById(R.id.wrong_button); mContext = mView.getContext(); // Load colors int[] attrs = { android.R.attr.textColorSecondary, android.R.attr.textColorPrimary }; TypedArray ta = mView.getContext().obtainStyledAttributes(R.style.AppTheme, attrs); sDeactivatedTextColor = colorToCSSString(ta.getColor(0, 0)); sDefaultTextColor = colorToCSSString(ta.getColor(1, 0)); ta.recycle(); sGreenTextColor = colorToCSSString(ContextCompat.getColor(mContext, R.color.green)); mQuestionColor = sDefaultTextColor; mAnswerColor = sGreenTextColor; // Make question visible mQuestion.setAlpha(1.0f); mAnswer.setAlpha(0.0f); // Setup WebViews WebSettings settings = mQuestion.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mQuestion.setHorizontalScrollBarEnabled(false); mQuestion.setVerticalScrollBarEnabled(false); settings = mAnswer.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mAnswer.setHorizontalScrollBarEnabled(false); mAnswer.setVerticalScrollBarEnabled(false); // Hack to disable text selection in WebViews mQuestion.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); mAnswer.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); // Card should "turn" on click final FrameLayout questionLayout = (FrameLayout) view.findViewById(R.id.question_layout); questionLayout.setClickable(true); questionLayout.setOnTouchListener(mTurnCardListener); mQuestion.setOnTouchListener(mTurnCardListener); mAnswer.setOnTouchListener(mTurnCardListener); // Deactivate card when user answers it mCorrectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(true); mListener.onCardAnswered(mCard, true); } }); mWrongButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(false); mListener.onCardAnswered(mCard, false); } }); // Limit card width to 400dp ViewTreeObserver observer = mCardView.getViewTreeObserver(); final int width480dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, view.getContext().getResources().getDisplayMetrics()); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (mCardView.getWidth() > width480dp) { ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams(); layoutParams.width = width480dp; mCardView.setLayoutParams(layoutParams); mCardView.requestLayout(); return false; } return true; } }); }
From source file:net.bluecarrot.lite.MainActivity.java
private void setUpWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); //allow Geolocation settings.setGeolocationEnabled(savedPreferences.getBoolean("pref_allowGeolocation", true)); // 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);//w w w . ja v a2 s . com settings.setLoadWithOverviewMode(true); // better image sizing support settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); settings.setGeolocationDatabasePath(getBaseContext().getFilesDir().getPath()); settings.setLoadsImagesAutomatically(!savedPreferences.getBoolean("pref_doNotDownloadImages", false));//to save data //todo setLoadsImagesAutomatically without restart the app // 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:org.openqa.selendroid.server.model.SelendroidWebDriver.java
private void configureWebView(final WebView view) { ServerInstrumentation.getInstance().runOnUiThread(new Runnable() { @Override/*w w w . j a va2s . c om*/ public void run() { view.clearCache(true); view.clearFormData(); view.clearHistory(); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setNetworkAvailable(true); view.setWebChromeClient(new MyWebChromeClient()); WebSettings settings = view.getSettings(); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(10 * 1024 * 1024); settings.setAppCachePath(""); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // Flash settings settings.setPluginState(WebSettings.PluginState.ON); // Geo location settings settings.setGeolocationEnabled(true); settings.setGeolocationDatabasePath("/data/data/selendroid"); } }); }
From source file:com.acrutiapps.browser.ui.components.CustomWebView.java
@SuppressLint("SetJavaScriptEnabled") public void loadSettings() { WebSettings settings = getSettings(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true)); settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true)); settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true)); settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false)); settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true)); settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true)); settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true)); settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100)); int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1); settings.setMinimumFontSize(minimumFontSize); settings.setMinimumLogicalFontSize(minimumFontSize); boolean useInvertedDisplay = prefs.getBoolean(Constants.PREFERENCE_INVERTED_DISPLAY, false); setWebSettingsProperty(settings, "inverted", useInvertedDisplay ? "true" : "false"); if (useInvertedDisplay) { setWebSettingsProperty(settings, "inverted_contrast", Float.toString(prefs.getInt(Constants.PREFERENCE_INVERTED_DISPLAY_CONTRAST, 100) / 100f)); }/*from w ww .j a v a 2s . com*/ settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID)); settings.setPluginState(PluginState .valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString()))); CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true)); settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); settings.setSupportMultipleWindows(true); settings.setEnableSmoothTransition(true); if (mPrivateBrowsing) { settings.setGeolocationEnabled(false); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setAppCacheEnabled(false); settings.setDatabaseEnabled(false); settings.setDomStorageEnabled(false); } else { // HTML5 API flags settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); // HTML5 configuration settings. settings.setAppCacheMaxSize(3 * 1024 * 1024); settings.setAppCachePath(mContext.getDir("appcache", 0).getPath()); settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); } setLongClickable(true); setDownloadListener(this); }
From source file:mgks.os.webview.MainActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "WrongViewCast" }) @Override//w w w . j a v a2 s . 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:net.evecom.androidecssp.base.BaseWebActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; temp = HttpUtil.getPageSize(this); setContentView(R.layout.message_post_web); // dialog = ProgressDialog.show(BaseWebActivity.this, null, // "..");/*from www .ja va2 s. c om*/ // dialog.setCancelable(true); lineProgressBar = (ProgressBar) findViewById(R.id.webview_progress_id); imageView = (ImageView) findViewById(R.id.image_view_at_web); webView = (WebView) this.findViewById(R.id.wv_oauth_message); CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); CookieManager.getInstance().removeSessionCookie(); webView.setWebViewClient(new BaseWebViewClient((BaseWebActivity) instance)); webView.setWebChromeClient(new BaseChromeClient((BaseWebActivity) instance)); // webView.setDownloadListener(new MyWebViewDownLoadListener()); WebSettings webSettings = webView.getSettings(); webSettings.setSupportZoom(true); // WebViewJavaScript webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBuiltInZoomControls(true);// support zoom webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); /** */ // // webSettings.setDatabaseEnabled(true); String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); // webSettings.setGeolocationEnabled(true); // webSettings.setGeolocationDatabasePath(dir); // webSettings.setDomStorageEnabled(true); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; if (mDensity == 240) { webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(ZoomDensity.CLOSE); // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){ // webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_HIGH) { webSettings.setDefaultZoom(ZoomDensity.FAR); } dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0") .setPositiveButton("", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); webView.addJavascriptInterface(new JsInterface(getApplicationContext()), "androidbase"); String url = HttpUtil.getPCURL() + "jfs/mobile/androidIndex/jqmobileTest"; // post // webView.postUrl(url, postData) postDatabyte[] // EncodingUtils.getBytes("&pwd=888", charset) webView.postUrl(url, EncodingUtils.getBytes("", "BASE64")); }
From source file:io.selendroid.server.model.SelendroidWebDriver.java
private void configureWebView(final WebView view) { ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { @Override// w w w .j a v a2 s. com public void run() { try { view.clearCache(true); view.clearFormData(); view.clearHistory(); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setNetworkAvailable(true); // need to check the class name rather than checking instanceof // since when it is not an instanceof, it likely means the app under test // does not contain the Cordova project and this will cause a RuntimeException if (view.getClass().getSimpleName().equalsIgnoreCase("CordovaWebView")) { CordovaWebView webview = (CordovaWebView) view; CordovaInterface ci = null; chromeClient = new ExtendedCordovaChromeClient(null, webview); } else { chromeClient = new SelendroidWebChromeClient(); } view.setWebChromeClient(chromeClient); WebSettings settings = view.getSettings(); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(10 * 1024 * 1024); settings.setAppCachePath(""); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // Flash settings settings.setPluginState(WebSettings.PluginState.ON); // Geo location settings settings.setGeolocationEnabled(true); settings.setGeolocationDatabasePath("/data/data/selendroid"); } catch (Exception e) { SelendroidLogger.error("Error configuring web view", e); } } }); }
From source file:net.evecom.android.web.Web0Activity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; temp = HttpUtil.getPageSize(this); setContentView(R.layout.message_post_web); imageView = (ImageView) findViewById(R.id.image_view_at_web); webView = (WebView) this.findViewById(R.id.wv_oauth_message); CookieSyncManager.createInstance(this); CookieSyncManager.getInstance().startSync(); CookieManager.getInstance().removeSessionCookie(); /**//from www .j a v a2 s . c o m * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ webView.setWebViewClient(new HelloWebViewClient()); dialog = ProgressDialog.show(Web0Activity.this, null, ".."); dialog.setCancelable(true); // http://harlan-pc/fzaj/emergency/mobileWebApp/publicInfo/login.do?userName=zf1&userPwd=1 // webView.loadUrl("http://www.baidu.com"); // String url = HttpUtil.BASE_PC_URL // String url =HttpUtil.BASE_PC_URL+"loginController/messageLogin"; String url = HttpUtil.BASE_PC_URL + "mobile/loginController/messageLogin"; // post String postDate = "loginname=" + ShareUtil.getString(getApplicationContext(), "SESSION", "USERNAME", "") + "&pwd=" + ShareUtil.getString(getApplicationContext(), "SESSION", "PASSWORD", "") + "&pageSize=" + temp; // webView.postUrl(url, postData) postDatabyte[] // EncodingUtils.getBytes(data, charset) webView.postUrl(url, EncodingUtils.getBytes(postDate, "BASE64")); // webView.setDownloadListener(new MyWebViewDownLoadListener()); WebSettings webSettings = webView.getSettings(); webSettings.setSupportZoom(true); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setBuiltInZoomControls(true);// support zoom // webSettings.setPluginsEnabled(true);//support flash webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); /** */ // // webSettings.setDatabaseEnabled(true); String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); // webSettings.setGeolocationEnabled(true); // webSettings.setGeolocationDatabasePath(dir); // webSettings.setDomStorageEnabled(true); // webSettings.setPluginsEnabled(true); //(flash) DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; // DebugLog.d(TAG, "densityDpi = " + mDensity); if (mDensity == 240) { webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(ZoomDensity.CLOSE); // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){ // webSettings.setDefaultZoom(ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_HIGH) { webSettings.setDefaultZoom(ZoomDensity.FAR); } webView.setWebChromeClient(m_chromeClient);// (flash) dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0") .setPositiveButton("", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); }