List of usage examples for android.webkit WebSettings setJavaScriptEnabled
public abstract void setJavaScriptEnabled(boolean flag);
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
/** * Initialize the WebView. Loads the .js script from the given path and sets the appropriate * base URL./*ww w. ja v a2 s . c o m*/ * * @return the initialized WebView */ private synchronized WebView getWebView() { if (mWebView == null) { mWebView = new WebView(TomahawkApp.getContext()); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath()); settings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new TomahawkWebChromeClient()); mWebView.setWebViewClient(new ScriptWebViewClient(ScriptResolver.this)); final ScriptInterface scriptInterface = new ScriptInterface(ScriptResolver.this); mWebView.addJavascriptInterface(scriptInterface, SCRIPT_INTERFACE_NAME); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); } final String baseurl = "file:///android_asset/test.html"; String data = "<!DOCTYPE html>" + "<html><body>" + "<script src=\"file:///android_asset/js/cryptojs-core.js" + "\" type=\"text/javascript\"></script>"; for (String scriptPath : mMetaData.manifest.scripts) { data += "<script src=\"file:///android_asset/" + mPath + "/" + scriptPath + "\" type=\"text/javascript\"></script>"; } try { String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs"); for (String scriptPath : cryptoJsScripts) { data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } catch (IOException e) { Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage()); } data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk_android_post.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/" + mPath + "/" + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>"; final String finalData = data; mWebView.loadDataWithBaseURL(baseurl, finalData, "text/html", null, null); } return mWebView; }
From source file:net.wequick.small.webkit.WebView.java
private void initSettings() { WebSettings webSettings = this.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setUserAgentString(webSettings.getUserAgentString() + " Native"); this.addJavascriptInterface(new SmallJsBridge(), "_Small"); this.setWebChromeClient(new WebChromeClient() { @Override/*from ww w . j a v a2s .c om*/ public void onReceivedTitle(android.webkit.WebView view, String title) { // Call if html title is set super.onReceivedTitle(view, title); mTitle = title; WebActivity activity = (WebActivity) WebViewPool.getContext(view); if (activity != null) { activity.setTitle(title); } // May receive head meta at the same time initMetas(); } @Override public boolean onJsAlert(android.webkit.WebView view, String url, String message, final android.webkit.JsResult result) { Context context = WebViewPool.getContext(view); if (context == null) return false; AlertDialog.Builder dlg = new AlertDialog.Builder(context); dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mConfirmed = true; result.confirm(); } }); dlg.setMessage(message); AlertDialog alert = dlg.create(); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (!mConfirmed) { result.cancel(); } } }); mConfirmed = false; alert.show(); return true; } @Override public boolean onJsConfirm(android.webkit.WebView view, String url, String message, final android.webkit.JsResult result) { Context context = WebViewPool.getContext(view); AlertDialog.Builder dlg = new AlertDialog.Builder(context); dlg.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mConfirmed = true; result.confirm(); } }); dlg.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mConfirmed = true; result.cancel(); } }); dlg.setMessage(message); AlertDialog alert = dlg.create(); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (!mConfirmed) { result.cancel(); } } }); mConfirmed = false; alert.show(); return true; } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String msg = consoleMessage.message(); if (msg == null) return false; Uri uri = Uri.parse(msg); if (uri != null && null != uri.getScheme() && uri.getScheme().equals(SMALL_SCHEME)) { String host = uri.getHost(); String ret = uri.getQueryParameter(SMALL_QUERY_KEY_RET); if (host.equals(SMALL_HOST_POP)) { WebActivity activity = (WebActivity) WebViewPool.getContext(WebView.this); activity.finish(ret); } else if (host.equals(SMALL_HOST_EXEC)) { if (mOnResultListener != null) { mOnResultListener.onResult(ret); } } return true; } Log.d(consoleMessage.sourceId(), "line" + consoleMessage.lineNumber() + ": " + consoleMessage.message()); return true; } @Override public void onCloseWindow(android.webkit.WebView window) { super.onCloseWindow(window); close(new OnResultListener() { @Override public void onResult(String ret) { if (ret.equals("false")) return; WebActivity activity = (WebActivity) WebViewPool.getContext(WebView.this); activity.finish(ret); } }); } }); this.setWebViewClient(new android.webkit.WebViewClient() { private final String ANCHOR_SCHEME = "anchor"; @Override public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) { if (mLoadingUrl != null && mLoadingUrl.equals(url)) { // reload by window.location.reload or something return super.shouldOverrideUrlLoading(view, url); } Boolean hasStarted = mHasStartedUrl.get(url); if (hasStarted != null && hasStarted) { // location redirected before page finished return super.shouldOverrideUrlLoading(view, url); } HitTestResult hit = view.getHitTestResult(); if (hit != null) { Uri uri = Uri.parse(url); if (uri.getScheme().equals(ANCHOR_SCHEME)) { // Scroll to anchor int anchorY = Integer.parseInt(uri.getHost()); view.scrollTo(0, anchorY); } else { Small.openUri(uri, WebViewPool.getContext(view)); } return true; } return super.shouldOverrideUrlLoading(view, url); } @Override public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); mHasStartedUrl.put(url, true); if (mLoadingUrl != null && mLoadingUrl.equals(url)) { // reload by window.location.reload or something mInjected = false; } if (sWebViewClient != null && url.equals(mLoadingUrl)) { sWebViewClient.onPageStarted(WebViewPool.getContext(view), (WebView) view, url, favicon); } } @Override public void onPageFinished(android.webkit.WebView view, String url) { super.onPageFinished(view, url); mHasStartedUrl.remove(url); HitTestResult hit = view.getHitTestResult(); if (hit != null && hit.getType() == HitTestResult.SRC_ANCHOR_TYPE) { // Triggered by user clicked Uri uri = Uri.parse(url); String anchor = uri.getFragment(); if (anchor != null) { // If is an anchor, calculate the content offset by DOM // and call native to adjust WebView's offset view.loadUrl(JS_PREFIX + "var y=document.body.scrollTop;" + "var e=document.getElementsByName('" + anchor + "')[0];" + "while(e){" + "y+=e.offsetTop-e.scrollTop+e.clientTop;e=e.offsetParent;}" + "location='" + ANCHOR_SCHEME + "://'+y;"); } } if (!mInjected) { // Re-inject Small Js loadJs(SMALL_INJECT_JS); initMetas(); mInjected = true; } if (sWebViewClient != null && url.equals(mLoadingUrl)) { sWebViewClient.onPageFinished(WebViewPool.getContext(view), (WebView) view, url); } } @Override public void onReceivedError(android.webkit.WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); Log.e("Web", "error: " + description); if (sWebViewClient != null && failingUrl.equals(mLoadingUrl)) { sWebViewClient.onReceivedError(WebViewPool.getContext(view), (WebView) view, errorCode, description, failingUrl); } } }); }
From source file:net.evecom.android.web.Web5Activity.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 ww w .j a v a 2 s. c om * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ webView.setWebViewClient(new HelloWebViewClient()); dialog = ProgressDialog.show(Web5Activity.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 // + "/buildingController/login"; http://harlan-pc/gssms/mobile/ // String url =HttpUtil.BASE_PC_URL+"/loginController/countLogin"; String url = HttpUtil.BASE_PC_URL + "mobile/loginController/countLogin"; // post // String postDate = "loginname=sysadmin&pwd=888888"; String postDate = "loginname=" + ShareUtil.getString(getApplicationContext(), "SESSION", "USERNAME", "") + "&pwd=" + ShareUtil.getString(getApplicationContext(), "SESSION", "PASSWORD", "") + "&pageSize=" + temp; // 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.setPluginsEnabled(true); //(flash) /** */ // // 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; // 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(); }
From source file:net.evecom.android.web.Web4Activity.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 w w w .j a v a2 s . c o m * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ webView.setWebViewClient(new HelloWebViewClient()); dialog = ProgressDialog.show(Web4Activity.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 // + "/buildingController/login"; http://harlan-pc/gssms/mobile/ // String url // =HttpUtil.BASE_PC_URL+"loginController/professionalJobLogin"; String url = HttpUtil.BASE_PC_URL + "mobile/loginController/professionalJobLogin"; // post // String postDate = "loginname=sysadmin&pwd=888888"; 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.setPluginsEnabled(true); //(flash) /** */ // // 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; // 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(); }
From source file:net.evecom.android.web.Web3Activity.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(); /**/* w w w. j av a 2 s . c om*/ * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ webView.setWebViewClient(new HelloWebViewClient()); dialog = ProgressDialog.show(Web3Activity.this, null, ".."); dialog.setCancelable(true); // http://harlan-pc/fzaj/emergency/mobileWebApp/publicInfo/login.do?userName=zf1&userPwd=1 // http://localhost/gssms/mobile/base/loginController/login?loginname=sysadmin&pwd=888888 // String url = HttpUtil.BASE_PC_URL // + "/base/loginController/login"; // http://localhost/gssms/mobile/loginController/baseLogin?loginname=sysadmin&pwd=888888 String url = HttpUtil.BASE_PC_URL + "mobile/loginController/baseLogin"; // post // String postDate = "loginname=sysadmin&pwd=888888"; 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.setPluginsEnabled(true); //(flash) /** */ // // 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; // 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(); }
From source file:org.apache.cordova.CordovaWebView.java
/** * Initialize webview./*from ww w. java 2s. c om*/ */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setup() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(false); this.requestFocusFromTouch(); // Enable JavaScript WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); //Set the nav dump for HTC 2.x devices (disabling for ICS/Jellybean) if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) settings.setNavDump(true); //Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist //while we do this if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) settings.setAllowUniversalAccessFromFileURLs(true); // Enable database settings.setDatabaseEnabled(true); String databasePath = this.cordova.getActivity().getApplicationContext() .getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); //Start up the plugin manager try { this.pluginManager = new PluginManager(this, this.cordova); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } exposeJsInterface(); }
From source file:com.timemachine.controller.ControllerActivity.java
private void setupUI() { // Set layout listener View controllerView = findViewById(R.id.controllerView); ViewTreeObserver vto = controllerView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override//w w w .ja va 2 s . c o m public void onGlobalLayout() { runOnUiThread(new Runnable() { public void run() { locationSliderHeight = locationSlider.getHeight(); originLocationSliderContainerY = locationSliderContainer.getY(); originPlayPauseButtonY = playPause.getY(); minLocationSliderContainerY = originLocationSliderContainerY; maxLocationSliderContainerY = originLocationSliderContainerY + locationSliderHeight; midLocationSliderContainerY = (minLocationSliderContainerY + maxLocationSliderContainerY) / 2; } }); System.out.println("locationSliderHeight: " + locationSliderHeight); System.out.println("locationSliderContainerY: " + originLocationSliderContainerY); locationSlider.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); // Connect to controller.html controllerURL = "http://" + ipText + ":8080/controller.html"; locationSlider = (WebView) findViewById(R.id.webview); locationSliderContainer = (FrameLayout) findViewById(R.id.sliderContainer); locationSlider.setBackgroundColor(Color.TRANSPARENT); locationSlider.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); locationSlider.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { System.out.println("onReceivedError"); showConnectDialog("Error while connecting to controller. Connect again."); } @Override public void onLoadResource(WebView view, String url) { if (url.contains("thumbnail")) isMasterConnected = true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { isMasterConnectedTimerTask = null; isMasterConnectedTimerTask = new TimerTask() { @Override public void run() { if (isMasterConnected == false) showConnectDialog("Master is not loaded in the browser. Connect again."); } }; isMasterConnectedTimer.schedule(isMasterConnectedTimerTask, 6000); } @Override public void onPageFinished(WebView view, String url) { if (url.contains(controllerURL)) { drag.setVisibility(View.VISIBLE); playPause.setVisibility(View.VISIBLE); loadPreferences(); } super.onPageFinished(view, url); } }); try { locationSlider.loadUrl(controllerURL); } catch (Exception e) { e.printStackTrace(); } // Set JavaScript Interface locationSlider.addJavascriptInterface(this, "androidObject"); WebSettings webSettings = locationSlider.getSettings(); webSettings.setJavaScriptEnabled(true); // Set the play-pause button playPause = (ImageButton) findViewById(R.id.playPauseButton); playPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { socket.emit("handlePlayPauseServer"); } }); socket.emit("setControllerPlayButton"); // Set the drag button drag = (ImageButton) findViewById(R.id.drag); drag.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { dragYDiffBetweenFingerAndSliderTop = locationSliderContainer.getY() - event.getRawY(); dragYDiffBetweenFingerAndPlayPauseTop = playPause.getY() - event.getRawY(); } if (event.getAction() == MotionEvent.ACTION_MOVE) { // Move the slider based on current finger location float newSliderY = event.getRawY() + dragYDiffBetweenFingerAndSliderTop; float newPlayPauseY = event.getRawY() + dragYDiffBetweenFingerAndPlayPauseTop; if (newSliderY > minLocationSliderContainerY && newSliderY < maxLocationSliderContainerY) { locationSliderContainer.setY(newSliderY); playPause.setY(newPlayPauseY); } } if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getEventTime() - event.getDownTime() <= tapTimeout) { // Tap is detected, toggle the slider System.out.println("onTap"); runOnUiThread(new Runnable() { public void run() { toggleSlider(); } }); } else { // Not a tap gesture, slide up or down based on the slider's current position if (locationSliderContainer.getY() > midLocationSliderContainerY) slideDown(); else slideUp(); } } return true; } }); // Set the Google map setUpMapIfNeeded(); }
From source file:net.evecom.android.web.Web2Activity.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(); /**// w w w .ja v a 2 s . c o m * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ webView.setWebViewClient(new HelloWebViewClient()); dialog = ProgressDialog.show(Web2Activity.this, null, ".."); dialog.setCancelable(true); // http://localhost/gssms/mobile/loginController/dailyOfficeLogin?loginname=sysadmin&pwd=888888 String url = HttpUtil.BASE_PC_URL + "mobile/loginController/dailyOfficeLogin"; // post // String postDate = "loginname=sysadmin&pwd=888888"; 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.setPluginsEnabled(true); //(flash) /** */ // // 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; // 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(); }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** * Configure a webview to use the activity as * its client, and update its settings with * the desired parameters for the activity. * @param webView the webview to configure. *///from ww w . j a va 2 s .co m private void configureWebView(WebView webView) { webView.clearCache(true); webView.setWebViewClient(new SecureWebClient(this)); WebSettings settings = mWebView.getSettings(); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); // settings.setPluginState(PluginState.ON_DEMAND); settings.setPluginState(PluginState.ON); settings.setAllowFileAccess(true); settings.setAllowContentAccess(true); settings.setSaveFormData(false); settings.setSavePassword(false); webView.clearFormData(); settings.setDomStorageEnabled(true); String defaultUserAgent = settings.getUserAgentString(); StringBuilder sb = new StringBuilder(); sb.append(defaultUserAgent); sb.append(" SmarterSecureBrowser/1.0"); sb.append(" OS/"); sb.append(mDeviceStatus.operatingSystem); sb.append(" Version/"); sb.append(mDeviceStatus.operatingSystemVersion); sb.append(" Model/"); sb.append(mDeviceStatus.model); settings.setUserAgentString(sb.toString()); }
From source file:net.evecom.android.web.WebdbActivity.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 w w w . j a v a 2 s .com*/ * WebViewJavaScript */ webView.getSettings().setJavaScriptEnabled(true); /** * loadUrl() */ HelloWebViewClient client = new HelloWebViewClient(); webView.setWebViewClient(client); dialog = ProgressDialog.show(WebdbActivity.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/eventlistLogin"; // post // http://wangzy:8081/gssms/mobile/loginController/eventlistLogin?loginname=sysadmin&pwd=888888 // String postDate = "loginname=sysadmin&pwd=888888"; 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.setPluginsEnabled(true); //(flash) /** */ // // 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; // 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(); }