List of usage examples for android.webkit WebView setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:org.liberty.android.fantastischmemo.downloader.google.GoogleOAuth2AccessCodeRetrievalFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); final View v = inflater.inflate(R.layout.oauth_login_layout, container, false); final WebView webview = (WebView) v.findViewById(R.id.login_page); final View loadingText = v.findViewById(R.id.auth_page_load_text); final View progressDialog = v.findViewById(R.id.auth_page_load_progress); final LinearLayout ll = (LinearLayout) v.findViewById(R.id.ll); // We have to set up the dialog's webview size manually or the webview will be zero size. // This should be a bug of Android. Rect displayRectangle = new Rect(); Window window = mActivity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle); ll.setMinimumWidth((int) (displayRectangle.width() * 0.9f)); ll.setMinimumHeight((int) (displayRectangle.height() * 0.8f)); webview.getSettings().setJavaScriptEnabled(true); try {/*from w w w.ja v a 2s . c o m*/ String uri = String.format( "https://accounts.google.com/o/oauth2/auth?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s", URLEncoder.encode(AMEnv.GOOGLE_CLIENT_ID, "UTF-8"), URLEncoder.encode("code", "UTF-8"), URLEncoder.encode(AMEnv.GOOGLE_REDIRECT_URI, "UTF-8"), URLEncoder.encode(AMEnv.GDRIVE_SCOPE, "UTF-8")); webview.loadUrl(uri); } catch (Exception e) { throw new RuntimeException(e); } // This is workaround to show input on some android version. webview.requestFocus(View.FOCUS_DOWN); webview.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); webview.setWebViewClient(new WebViewClient() { private boolean authenticated = false; @Override public void onPageFinished(WebView view, String url) { loadingText.setVisibility(View.GONE); progressDialog.setVisibility(View.GONE); webview.setVisibility(View.VISIBLE); if (authenticated == true) { return; } String code = getAuthCodeFromUrl(url); String error = getErrorFromUrl(url); if (error != null) { authCodeReceiveListener.onAuthCodeError(error); authenticated = true; dismiss(); } if (code != null) { authenticated = true; authCodeReceiveListener.onAuthCodeReceived(code); dismiss(); } } }); return v; }
From source file:eu.vranckaert.worktime.utils.donations.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button//*ww w . j ava2 s .c o m*/ */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // get flattr values from xml config String projectUrl = DonationsUtils.getResourceString(getActivity(), "donations__flattr_project_url"); String flattrUrl = DonationsUtils.getResourceString(getActivity(), "donations__flattr_url"); // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link mFlattrUrl = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrl.setText(flattrScheme + flattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + projectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + flattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:at.maui.cheapcast.fragment.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button///ww w.jav a 2s .co m */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // get flattr values from xml config String projectUrl = mFlattrProjectUrl; String flattrUrl = this.mFlattrUrl; // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link mFlattrUrlTextView = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrlTextView.setText(flattrScheme + flattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + projectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + flattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // disable scroll on touch mFlattrWebview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // already handled (returns true) when moving return (motionEvent.getAction() == MotionEvent.ACTION_MOVE); } }); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button//*from w w w . j av a 2s . c o m*/ */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { WebView.HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link TextView mFlattrUrlTextView = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrlTextView.setText(flattrScheme + mFlattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + mFlattrProjectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + mFlattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // disable scroll on touch mFlattrWebview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // already handled (returns true) when moving return (motionEvent.getAction() == MotionEvent.ACTION_MOVE); } }); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:org.sufficientlysecure.donations.DonationsFragment.java
/** * Build view for Flattr. see Flattr API for more information: * http://developers.flattr.net/button//*from ww w . j a v a 2 s . c om*/ */ @SuppressLint("SetJavaScriptEnabled") @TargetApi(11) private void buildFlattrView() { final FrameLayout mLoadingFrame; final WebView mFlattrWebview; mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview); mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame); // disable hardware acceleration for this webview to get transparent background working if (Build.VERSION.SDK_INT >= 11) { mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // define own webview client to override loading behaviour mFlattrWebview.setWebViewClient(new WebViewClient() { /** * Open all links in browser, not in webview */ @Override public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } return false; } /** * Links in the flattr iframe should load in the browser not in the iframe itself, * http:/ * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the * -browser */ @Override public void onLoadResource(WebView view, String url) { if (url.contains("flattr")) { HitTestResult result = view.getHitTestResult(); if (result != null && result.getType() > 0) { try { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (ActivityNotFoundException e) { openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser)); } view.stopLoading(); } } } /** * After loading is done, remove frame with progress circle */ @Override public void onPageFinished(WebView view, String url) { // remove loading frame, show webview if (mLoadingFrame.getVisibility() == View.VISIBLE) { mLoadingFrame.setVisibility(View.GONE); mFlattrWebview.setVisibility(View.VISIBLE); } } }); // make text white and background transparent String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>"; // https is not working in android 2.1 and 2.2 String flattrScheme; if (Build.VERSION.SDK_INT >= 9) { flattrScheme = "https://"; } else { flattrScheme = "http://"; } // set url of flattr link mFlattrUrlTextView = (TextView) getActivity().findViewById(R.id.donations__flattr_url); mFlattrUrlTextView.setText(flattrScheme + mFlattrUrl); String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>"; String htmlMiddle = "</head> <body> <div align='center'>"; String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + mFlattrProjectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + mFlattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>"; String htmlEnd = "</div> </body> </html>"; String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd; mFlattrWebview.getSettings().setJavaScriptEnabled(true); mFlattrWebview.loadData(flattrCode, "text/html", "utf-8"); // disable scroll on touch mFlattrWebview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // already handled (returns true) when moving return (motionEvent.getAction() == MotionEvent.ACTION_MOVE); } }); // make background of webview transparent // has to be called AFTER loadData // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2 mFlattrWebview.setBackgroundColor(0x00000000); }
From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
@Override public void create() { try {//from w ww. ja va 2 s. co m setContentView(R.layout.romanblack_html_main); root = (FrameLayout) findViewById(R.id.romanblack_root_layout); webView = new ObservableWebView(this); webView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); root.addView(webView); webView.setHorizontalScrollBarEnabled(false); setTitle("HTML"); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } appName = widget.getAppName(); if (widget.getPluginXmlData().length() == 0) { if (currentIntent.getStringExtra("WidgetFile").length() == 0) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } } if (widget.getTitle() != null && widget.getTitle().length() > 0) { setTopBarTitle(widget.getTitle()); } else { setTopBarTitle(getResources().getString(R.string.romanblack_html_web)); } currentUrl = (String) getSession(); if (currentUrl == null) { currentUrl = ""; } ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) { isOnline = true; } // topbar initialization setTopBarLeftButtonText(getString(R.string.common_home_upper), true, new View.OnClickListener() { @Override public void onClick(View view) { onBackPressed(); } }); if (isOnline) { webView.getSettings().setJavaScriptEnabled(true); } webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.getSettings().setGeolocationEnabled(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setUseWideViewPort(false); webView.getSettings().setSavePassword(false); webView.clearHistory(); webView.invalidate(); if (Build.VERSION.SDK_INT >= 19) { } webView.getSettings().setUserAgentString( "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.invalidate(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { } break; case MotionEvent.ACTION_UP: { if (!v.hasFocus()) { v.requestFocus(); } } break; case MotionEvent.ACTION_MOVE: { } break; } return false; } }); webView.setBackgroundColor(Color.WHITE); try { if (widget.getBackgroundColor() != Color.TRANSPARENT) { webView.setBackgroundColor(widget.getBackgroundColor()); } } catch (IllegalArgumentException e) { } webView.setDownloadListener(new DownloadListener() { @Override 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)); startActivity(intent); } }); webView.setWebChromeClient(new WebChromeClient() { FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); @Override public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) { AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setTitle(R.string.location_dialog_title); builder.setMessage(R.string.location_dialog_description); builder.setCancelable(true); builder.setPositiveButton(R.string.location_dialog_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, true, false); } }); builder.setNegativeButton(R.string.location_dialog_not_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, false, false); } }); AlertDialog alert = builder.create(); alert.show(); } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { if (customView != null) { customViewCallback.onCustomViewHidden(); return; } view.setBackgroundColor(Color.BLACK); view.setLayoutParams(LayoutParameters); root.addView(view); customView = view; customViewCallback = callback; webView.setVisibility(View.GONE); } @Override public void onHideCustomView() { if (customView == null) { return; } else { closeFullScreenVideo(); } } public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT);//Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); isMedia = true; startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } //For Android 4.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); isMedia = true; i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { isV21 = true; mUploadMessageV21 = filePathCallback; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); return true; } @Override public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) { super.onReceivedTouchIconUrl(view, url, precomposed); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (state == states.EMPTY) { currentUrl = url; setSession(currentUrl); state = states.LOAD_START; handler.sendEmptyMessage(SHOW_PROGRESS); } } @Override public void onLoadResource(WebView view, String url) { if (!alreadyLoaded && (url.startsWith("http://www.youtube.com/get_video_info?") || url.startsWith("https://www.youtube.com/get_video_info?")) && Build.VERSION.SDK_INT < 11) { try { String path = url.contains("https://www.youtube.com/get_video_info?") ? url.replace("https://www.youtube.com/get_video_info?", "") : url.replace("http://www.youtube.com/get_video_info?", ""); String[] parqamValuePairs = path.split("&"); String videoId = null; for (String pair : parqamValuePairs) { if (pair.startsWith("video_id")) { videoId = pair.split("=")[1]; break; } } if (videoId != null) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse("http://www.youtube.com/watch?v=" + videoId))); needRefresh = true; alreadyLoaded = !alreadyLoaded; return; } } catch (Exception ex) { } } else { super.onLoadResource(view, url); } } @Override public void onPageFinished(WebView view, String url) { if (hideProgress) { if (TextUtils.isEmpty(WebPlugin.this.url)) { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } else { view.loadUrl("javascript:(function(){" + "l=document.getElementById('link');" + "e=document.createEvent('HTMLEvents');" + "e.initEvent('click',true,true);" + "l.dispatchEvent(e);" + "})()"); hideProgress = false; } } else { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (errorCode == WebViewClient.ERROR_BAD_URL) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); } } @Override public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { final AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setMessage(R.string.notification_error_ssl_cert_invalid); builder.setPositiveButton(WebPlugin.this.getResources().getString(R.string.wp_continue), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.proceed(); } }); builder.setNegativeButton(WebPlugin.this.getResources().getString(R.string.wp_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); } @Override public void onFormResubmission(WebView view, Message dontResend, Message resend) { super.onFormResubmission(view, dontResend, resend); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { return super.shouldInterceptRequest(view, request); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { try { if (url.contains("youtube.com/watch")) { if (Build.VERSION.SDK_INT < 11) { try { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse(url))); return true; } catch (Exception ex) { return false; } } else { return false; } } else if (url.contains("paypal.com")) { if (url.contains("&bn=ibuildapp_SP")) { return false; } else { url = url + "&bn=ibuildapp_SP"; webView.loadUrl(url); return true; } } else if (url.contains("sms:")) { try { Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse(url)); startActivity(smsIntent); return true; } catch (Exception ex) { Log.e("", ex.getMessage()); return false; } } else if (url.contains("tel:")) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(url)); startActivity(callIntent); return true; } else if (url.contains("mailto:")) { MailTo mailTo = MailTo.parse(url); Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { mailTo.getTo() }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mailTo.getSubject()); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mailTo.getBody()); WebPlugin.this.startActivity(Intent.createChooser(emailIntent, getString(R.string.romanblack_html_send_email))); return true; } else if (url.contains("rtsp:")) { Uri address = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, address); final PackageManager pm = getPackageManager(); final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0); if (matches.size() > 0) { startActivity(intent); } else { Toast.makeText(WebPlugin.this, getString(R.string.romanblack_html_no_video_player), Toast.LENGTH_SHORT).show(); } return true; } else if (url.startsWith("intent:") || url.startsWith("market:") || url.startsWith("col-g2m-2:")) { Intent it = new Intent(); it.setData(Uri.parse(url)); startActivity(it); return true; } else if (url.contains("//play.google.com/")) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { if (url.contains("ibuildapp.com-1915109")) { String param = Uri.parse(url).getQueryParameter("widget"); finish(); if (param != null && param.equals("1001")) com.appbuilder.sdk.android.Statics.launchMain(); else if (param != null && !"".equals(param)) { View.OnClickListener widget = Statics.linkWidgets.get(Integer.valueOf(param)); if (widget != null) widget.onClick(view); } return false; } currentUrl = url; setSession(currentUrl); if (!isOnline) { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(STOP_LOADING); } else { String pageType = "application/html"; if (!url.contains("vk.com")) { getPageType(url); } if (pageType.contains("application") && !pageType.contains("html") && !pageType.contains("xml")) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); return super.shouldOverrideUrlLoading(view, url); } else { view.getSettings().setLoadWithOverviewMode(true); view.getSettings().setUseWideViewPort(true); view.setBackgroundColor(Color.WHITE); } } return false; } } catch (Exception ex) { // Error Logging return false; } } }); handler.sendEmptyMessage(SHOW_PROGRESS); new Thread() { @Override public void run() { EntityParser parser; if (widget.getPluginXmlData() != null) { if (widget.getPluginXmlData().length() > 0) { parser = new EntityParser(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } parser.parse(); url = parser.getUrl(); html = parser.getHtml(); if (url.length() > 0 && !isOnline) { handler.sendEmptyMessage(NEED_INTERNET_CONNECTION); } else { if (isOnline) { } else { if (html.length() == 0) { } } if (html.length() > 0 || url.length() > 0) { handler.sendEmptyMessageDelayed(SHOW_HTML, 700); } else { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(INITIALIZATION_FAILED); } } } }.start(); } catch (Exception ex) { } }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
protected void updateMessageDetail(final boolean isUpdate) { T.UI();//from w w w. j a v a 2 s .c o m // Set sender avatar ImageView avatarImage = (ImageView) findViewById(R.id.avatar); String sender = mCurrentMessage.sender; setAvatar(avatarImage, sender); // Set sender name TextView senderView = (TextView) findViewById(R.id.sender); final String senderName = mFriendsPlugin.getName(sender); senderView.setText(senderName == null ? sender : senderName); // Set timestamp TextView timestampView = (TextView) findViewById(R.id.timestamp); timestampView.setText(TimeUtils.getDayTimeStr(this, mCurrentMessage.timestamp * 1000)); // Set clickable region on top to go to friends detail final RelativeLayout messageHeader = (RelativeLayout) findViewById(R.id.message_header); messageHeader.setOnClickListener(getFriendDetailOnClickListener(mCurrentMessage.sender)); messageHeader.setVisibility(View.VISIBLE); // Set message TextView messageView = (TextView) findViewById(R.id.message); WebView web = (WebView) findViewById(R.id.webview); FrameLayout flay = (FrameLayout) findViewById(R.id.message_details); Resources resources = getResources(); flay.setBackgroundColor(resources.getColor(R.color.mc_background)); boolean showBranded = false; int darkSchemeTextColor = resources.getColor(android.R.color.primary_text_dark); int lightSchemeTextColor = resources.getColor(android.R.color.primary_text_light); senderView.setTextColor(lightSchemeTextColor); timestampView.setTextColor(lightSchemeTextColor); BrandingResult br = null; if (!TextUtils.isEmptyOrWhitespace(mCurrentMessage.branding)) { boolean brandingAvailable = false; try { brandingAvailable = mMessagingPlugin.getBrandingMgr().isBrandingAvailable(mCurrentMessage.branding); } catch (BrandingFailureException e1) { L.d(e1); } try { if (brandingAvailable) { br = mMessagingPlugin.getBrandingMgr().prepareBranding(mCurrentMessage); WebSettings settings = web.getSettings(); settings.setJavaScriptEnabled(false); settings.setBlockNetworkImage(false); web.loadUrl("file://" + br.file.getAbsolutePath()); web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); if (br.color != null) { flay.setBackgroundColor(br.color); } if (!br.showHeader) { messageHeader.setVisibility(View.GONE); MarginLayoutParams mlp = (MarginLayoutParams) web.getLayoutParams(); mlp.setMargins(0, 0, 0, mlp.bottomMargin); } else if (br.scheme == ColorScheme.dark) { senderView.setTextColor(darkSchemeTextColor); timestampView.setTextColor(darkSchemeTextColor); } showBranded = true; } else { mMessagingPlugin.getBrandingMgr().queueGenericBranding(mCurrentMessage.branding); } } catch (BrandingFailureException e) { L.bug("Could not display message with branding: branding is available, but prepareBranding failed", e); } } if (showBranded) { web.setVisibility(View.VISIBLE); messageView.setVisibility(View.GONE); } else { web.setVisibility(View.GONE); messageView.setVisibility(View.VISIBLE); messageView.setText(mCurrentMessage.message); } // Add list of members who did not ack yet FlowLayout memberSummary = (FlowLayout) findViewById(R.id.member_summary); memberSummary.removeAllViews(); SortedSet<MemberStatusTO> memberSummarySet = new TreeSet<MemberStatusTO>(getMemberstatusComparator()); for (MemberStatusTO ms : mCurrentMessage.members) { if ((ms.status & MessagingPlugin.STATUS_ACKED) != MessagingPlugin.STATUS_ACKED && !ms.member.equals(mCurrentMessage.sender)) { memberSummarySet.add(ms); } } FlowLayout.LayoutParams flowLP = new FlowLayout.LayoutParams(2, 0); for (MemberStatusTO ms : memberSummarySet) { FrameLayout fl = new FrameLayout(this); fl.setLayoutParams(flowLP); memberSummary.addView(fl); fl.addView(createParticipantView(ms)); } memberSummary.setVisibility(memberSummarySet.size() < 2 ? View.GONE : View.VISIBLE); // Add members statuses final LinearLayout members = (LinearLayout) findViewById(R.id.members); members.removeAllViews(); final String myEmail = mService.getIdentityStore().getIdentity().getEmail(); boolean isMember = false; mSomebodyAnswered = false; for (MemberStatusTO ms : mCurrentMessage.members) { boolean showMember = true; View view = getLayoutInflater().inflate(R.layout.message_member_detail, null); // Set receiver avatar RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.avatar); rl.addView(createParticipantView(ms)); // Set receiver name TextView receiverView = (TextView) view.findViewById(R.id.receiver); final String memberName = mFriendsPlugin.getName(ms.member); receiverView.setText(memberName == null ? sender : memberName); // Set received timestamp TextView receivedView = (TextView) view.findViewById(R.id.received_timestamp); if ((ms.status & MessagingPlugin.STATUS_RECEIVED) == MessagingPlugin.STATUS_RECEIVED) { final String humanTime = TimeUtils.getDayTimeStr(this, ms.received_timestamp * 1000); if (ms.member.equals(mCurrentMessage.sender)) receivedView.setText(getString(R.string.sent_at, humanTime)); else receivedView.setText(getString(R.string.received_at, humanTime)); } else { receivedView.setText(R.string.not_yet_received); } // Set replied timestamp TextView repliedView = (TextView) view.findViewById(R.id.acked_timestamp); if ((ms.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED) { mSomebodyAnswered = true; String acked_timestamp = TimeUtils.getDayTimeStr(this, ms.acked_timestamp * 1000); if (ms.button_id != null) { ButtonTO button = null; for (ButtonTO b : mCurrentMessage.buttons) { if (b.id.equals(ms.button_id)) { button = b; break; } } if (button == null) { repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); } else { repliedView.setText(getString(R.string.replied_at, button.caption, acked_timestamp)); } } else { if (ms.custom_reply == null) { // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); } else repliedView.setText(getString(R.string.replied_at, ms.custom_reply, acked_timestamp)); } } else { repliedView.setText(R.string.not_yet_replied); showMember = !ms.member.equals(mCurrentMessage.sender); } if (br != null && br.scheme == ColorScheme.dark) { receiverView.setTextColor(darkSchemeTextColor); receivedView.setTextColor(darkSchemeTextColor); repliedView.setTextColor(darkSchemeTextColor); } else { receiverView.setTextColor(lightSchemeTextColor); receivedView.setTextColor(lightSchemeTextColor); repliedView.setTextColor(lightSchemeTextColor); } if (showMember) members.addView(view); isMember |= ms.member.equals(myEmail); } boolean isLocked = (mCurrentMessage.flags & MessagingPlugin.FLAG_LOCKED) == MessagingPlugin.FLAG_LOCKED; boolean canEdit = isMember && !isLocked; // Add attachments LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachment_layout); attachmentLayout.removeAllViews(); if (mCurrentMessage.attachments.length > 0) { attachmentLayout.setVisibility(View.VISIBLE); for (final AttachmentTO attachment : mCurrentMessage.attachments) { View v = getLayoutInflater().inflate(R.layout.attachment_item, null); ImageView attachment_image = (ImageView) v.findViewById(R.id.attachment_image); if (AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(attachment.content_type) || AttachmentViewerActivity.CONTENT_TYPE_PNG.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_img); } else if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_pdf); } else if (AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4 .equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_video); } else { attachment_image.setImageResource(R.drawable.attachment_unknown); L.d("attachment.content_type not known: " + attachment.content_type); } TextView attachment_text = (TextView) v.findViewById(R.id.attachment_text); attachment_text.setText(attachment.name); v.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String downloadUrlHash = mMessagingPlugin .attachmentDownloadUrlHash(attachment.download_url); File attachmentsDir; try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), null); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } boolean attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); if (!attachmentAvailable) { try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), mCurrentMessage.key); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); } if (!mService.getNetworkConnectivityManager().isConnected() && !attachmentAvailable) { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(R.string.no_internet_connection_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } if (IOUtils.shouldCheckExternalStorageAvailable()) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // Its all oke } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (!attachmentAvailable) { L.d("Unable to write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } else { L.d("Unable to read or write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } L.d("attachment.content_type: " + attachment.content_type); L.d("attachment.download_url: " + attachment.download_url); L.d("attachment.name: " + attachment.name); L.d("attachment.size: " + attachment.size); if (AttachmentViewerActivity.supportsContentType(attachment.content_type)) { Intent i = new Intent(ServiceMessageDetailActivity.this, AttachmentViewerActivity.class); i.putExtra("thread_key", mCurrentMessage.getThreadKey()); i.putExtra("message", mCurrentMessage.key); i.putExtra("content_type", attachment.content_type); i.putExtra("download_url", attachment.download_url); i.putExtra("name", attachment.name); i.putExtra("download_url_hash", downloadUrlHash); startActivity(i); } else { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(getString(R.string.attachment_can_not_be_displayed_in_your_version, getString(R.string.app_name))); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); attachmentLayout.addView(v); } } else { attachmentLayout.setVisibility(View.GONE); } LinearLayout widgetLayout = (LinearLayout) findViewById(R.id.widget_layout); if (mCurrentMessage.form == null) { widgetLayout.setVisibility(View.GONE); } else { widgetLayout.setVisibility(View.VISIBLE); widgetLayout.setEnabled(canEdit); displayWidget(widgetLayout, br); } // Add buttons TableLayout tableLayout = (TableLayout) findViewById(R.id.buttons); tableLayout.removeAllViews(); for (final ButtonTO button : mCurrentMessage.buttons) { addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.form == null && (mCurrentMessage.flags & MessagingPlugin.FLAG_ALLOW_DISMISS) == MessagingPlugin.FLAG_ALLOW_DISMISS) { ButtonTO button = new ButtonTO(); button.caption = "Roger that!"; addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.broadcast_type != null) { L.d("Show broadcast spam control"); final RelativeLayout broadcastSpamControl = (RelativeLayout) findViewById(R.id.broadcast_spam_control); View broadcastSpamControlBorder = findViewById(R.id.broadcast_spam_control_border); final View broadcastSpamControlDivider = findViewById(R.id.broadcast_spam_control_divider); final LinearLayout broadcastSpamControlTextContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_text_container); TextView broadcastSpamControlText = (TextView) findViewById(R.id.broadcast_spam_control_text); final LinearLayout broadcastSpamControlSettingsContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_settings_container); TextView broadcastSpamControlSettingsText = (TextView) findViewById( R.id.broadcast_spam_control_settings_text); TextView broadcastSpamControlIcon = (TextView) findViewById(R.id.broadcast_spam_control_icon); broadcastSpamControlIcon.setTypeface(mFontAwesomeTypeFace); broadcastSpamControlIcon.setText(R.string.fa_bell); final FriendBroadcastInfo fbi = mFriendsPlugin.getFriendBroadcastFlowForMfr(mCurrentMessage.sender); if (fbi == null) { L.bug("BroadcastData was null for: " + mCurrentMessage.sender); collapseDetails(DETAIL_SECTIONS); return; } broadcastSpamControl.setVisibility(View.VISIBLE); broadcastSpamControlSettingsContainer.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { L.d("goto broadcast settings"); PressMenuIconRequestTO request = new PressMenuIconRequestTO(); request.coords = fbi.coords; request.static_flow_hash = fbi.staticFlowHash; request.hashed_tag = fbi.hashedTag; request.generation = fbi.generation; request.service = mCurrentMessage.sender; mContext = "MENU_" + UUID.randomUUID().toString(); request.context = mContext; request.timestamp = System.currentTimeMillis() / 1000; showTransmitting(null); Map<String, Object> userInput = new HashMap<String, Object>(); userInput.put("request", request.toJSONMap()); userInput.put("func", "com.mobicage.api.services.pressMenuItem"); MessageFlowRun mfr = new MessageFlowRun(); mfr.staticFlowHash = fbi.staticFlowHash; try { JsMfr.executeMfr(mfr, userInput, mService, true); } catch (EmptyStaticFlowException ex) { completeTransmit(null); AlertDialog.Builder builder = new AlertDialog.Builder(ServiceMessageDetailActivity.this); builder.setMessage(ex.getMessage()); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } } }); UIUtils.showHint(this, mService, HINT_BROADCAST, R.string.hint_broadcast, mCurrentMessage.broadcast_type, mFriendsPlugin.getName(mCurrentMessage.sender)); broadcastSpamControlText .setText(getString(R.string.broadcast_subscribed_to, mCurrentMessage.broadcast_type)); broadcastSpamControlSettingsText.setText(fbi.label); int ligthAlpha = 180; int darkAlpha = 70; int alpha = ligthAlpha; if (br != null && br.scheme == ColorScheme.dark) { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.black)); broadcastSpamControlBorder.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(darkSchemeTextColor); activity.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlText.setTextColor(lightSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(lightSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(lightSchemeTextColor), Color.green(lightSchemeTextColor), Color.blue(lightSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); alpha = darkAlpha; } else { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.white)); broadcastSpamControlBorder.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(lightSchemeTextColor); activity.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlText.setTextColor(darkSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(darkSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(darkSchemeTextColor), Color.green(darkSchemeTextColor), Color.blue(darkSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); } if (br != null && br.color != null) { int alphaColor = Color.argb(alpha, Color.red(br.color), Color.green(br.color), Color.blue(br.color)); broadcastSpamControl.setBackgroundColor(alphaColor); } mService.postOnUIHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { int maxHeight = broadcastSpamControl.getHeight(); broadcastSpamControlDivider.getLayoutParams().height = maxHeight; broadcastSpamControlDivider.requestLayout(); broadcastSpamControlSettingsContainer.getLayoutParams().height = maxHeight; broadcastSpamControlSettingsContainer.requestLayout(); broadcastSpamControlTextContainer.getLayoutParams().height = maxHeight; broadcastSpamControlTextContainer.requestLayout(); int broadcastSpamControlWidth = broadcastSpamControl.getWidth(); android.view.ViewGroup.LayoutParams lp = broadcastSpamControlSettingsContainer .getLayoutParams(); lp.width = broadcastSpamControlWidth / 4; broadcastSpamControlSettingsContainer.setLayoutParams(lp); } }); } if (!isUpdate) collapseDetails(DETAIL_SECTIONS); }
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void aboutSMBSync() { // common ??//from ww w. j ava 2 s .c o m final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); ((TextView) dialog.findViewById(R.id.about_dialog_title)) .setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")"); final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function); // func_view.loadDataWithBaseURL("file:///android_asset/", // getString(R.string.msgs_dlg_title_about_func_desc),"text/html","UTF-8",""); func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc)); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); func_view.getSettings().setBuiltInZoomControls(true); final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history); change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc)); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setBuiltInZoomControls(true); final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func); final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); func_view.setVisibility(TextView.VISIBLE); change_view.setVisibility(TextView.GONE); btnChange.setBackgroundResource(R.drawable.button_bg_color_selector); btnFunc.setBackgroundResource(R.drawable.button_bg_color_selector); btnChange.setTextColor(Color.DKGRAY); btnFunc.setTextColor(Color.GREEN); btnFunc.setEnabled(false); // btnOk.setTextColor(Color.DKGRAY); // btnOk.setTextColor(Color.GREEN); // btnOk.setBackgroundResource(R.drawable.button_back_ground_color_selector); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func? btnFunc.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.GONE); func_view.setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func_view.setEnabled(true); // change_view.setEnabled(false); btnFunc.setTextColor(Color.GREEN); btnChange.setTextColor(Color.DKGRAY); btnChange.setEnabled(true); btnFunc.setEnabled(false); } }); // change? btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.VISIBLE); func_view.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func_view.setEnabled(true); // change_view.setEnabled(false); btnChange.setTextColor(Color.GREEN); btnFunc.setTextColor(Color.DKGRAY); btnChange.setEnabled(false); btnFunc.setEnabled(true); } }); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(mContext)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
@SuppressLint("NewApi") final private void aboutTaskAutomation() { // common ??//from w w w . jav a 2 s . c om final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_dialog); ((TextView) dialog.findViewById(R.id.about_dialog_title)) .setText(getString(R.string.msgs_about_dlg_title) + " Ver " + getApplVersionName()); final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function); // func_view.setWebViewClient(new WebViewClient()); // func_view.getSettings().setJavaScriptEnabled(true); func_view.getSettings().setSupportZoom(true); // func_view.setVerticalScrollbarOverlay(true); func_view.setBackgroundColor(Color.LTGRAY); // func_view.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); func_view.setVerticalScrollBarEnabled(true); func_view.setScrollbarFadingEnabled(false); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_about_dlg_func_html)); final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history); if (Build.VERSION.SDK_INT > 10) { func_view.getSettings().setDisplayZoomControls(true); func_view.getSettings().setBuiltInZoomControls(true); } else { func_view.getSettings().setBuiltInZoomControls(true); } change_view.loadDataWithBaseURL("file:///android_asset/", getString(R.string.msgs_about_dlg_change_desc), "text/html", "UTF-8", ""); change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); change_view.getSettings().setSupportZoom(true); if (Build.VERSION.SDK_INT > 10) { change_view.getSettings().setDisplayZoomControls(true); change_view.getSettings().setBuiltInZoomControls(true); } else { change_view.getSettings().setBuiltInZoomControls(true); } final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func); final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change); final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok); func_view.setVisibility(TextView.VISIBLE); change_view.setVisibility(TextView.GONE); btnChange.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnFunc.setBackgroundResource(R.drawable.button_back_ground_color_selector); btnChange.setTextColor(Color.DKGRAY); btnFunc.setTextColor(Color.GREEN); btnFunc.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, true); // func? btnFunc.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.GONE); func_view.setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnFunc.setTextColor(Color.GREEN); btnChange.setTextColor(Color.DKGRAY); btnChange.setEnabled(true); btnFunc.setEnabled(false); } }); // change? btnChange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { change_view.setVisibility(TextView.VISIBLE); func_view.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeLimit(dialog, true); btnChange.setTextColor(Color.GREEN); btnFunc.setTextColor(Color.DKGRAY); btnChange.setEnabled(false); btnFunc.setEnabled(true); } }); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }