CaptureResultActivity.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package com.xzjmyk.pm.activity;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.KeyEvent;
  9. import android.webkit.DownloadListener;
  10. import android.webkit.WebSettings;
  11. import android.webkit.WebView;
  12. import android.webkit.WebViewClient;
  13. import com.alibaba.fastjson.JSON;
  14. import com.common.data.JSONUtil;
  15. import com.common.data.StringUtil;
  16. import com.common.file.DownloadUtil;
  17. import com.core.app.MyApplication;
  18. import com.core.utils.CommonUtil;
  19. import com.uuzuche.lib_zxing.activity.CodeUtils;
  20. import com.xzjmyk.pm.activity.ui.me.ScanInfoResultsActivity;
  21. import com.xzjmyk.pm.activity.view.crouton.Crouton;
  22. import com.xzjmyk.pm.activity.view.crouton.LifecycleCallback;
  23. /**
  24. * @author RaoMeng
  25. * update fanglh 2017-6-7 新增扫描名片二维码需求
  26. * update fanglh 2017-9-14 新增扫描UAS二维码登录功能
  27. */
  28. public class CaptureResultActivity extends Activity {
  29. private WebView mWebView;
  30. @Override
  31. protected void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. setContentView(R.layout.activity_capture_result);
  34. initActivity();
  35. initData();
  36. }
  37. private void initActivity() {
  38. mWebView = (WebView) findViewById(R.id.result_webview);
  39. WebSettings webSettings = mWebView.getSettings();
  40. //允许加载JavaScript
  41. webSettings.setJavaScriptEnabled(true);
  42. //网页自适应屏幕
  43. webSettings.setUseWideViewPort(true);
  44. webSettings.setLoadWithOverviewMode(true);
  45. webSettings.setDomStorageEnabled(true);
  46. mWebView.setWebViewClient(new WebViewClient() {
  47. @Override
  48. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  49. // view.loadUrl(url);
  50. // return true;
  51. return false;
  52. }
  53. });
  54. mWebView.setDownloadListener(new DownloadListener() {
  55. @Override
  56. public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
  57. // Uri uri = Uri.parse(url);
  58. // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  59. // startActivity(intent);
  60. Log.d("fileurl", url);
  61. String fileName = url.substring(url.lastIndexOf("/") + 1);
  62. new AlertDialog.Builder(CaptureResultActivity.this).setTitle("提示").setMessage("确定下载文件<"+fileName+">吗?").setNegativeButton(R.string.cancel, null)
  63. .setPositiveButton(R.string.sure, new DialogInterface.OnClickListener() {
  64. @Override
  65. public void onClick(DialogInterface dialog, int which) {
  66. DownloadUtil.DownloadFile(CaptureResultActivity.this,url,"/sdcard/uu");
  67. }
  68. }).create().show();
  69. }
  70. });
  71. }
  72. private void initData() {
  73. Intent intent = getIntent();
  74. if (null != intent) {
  75. Bundle bundle = intent.getExtras();
  76. if (bundle == null){
  77. return;
  78. }
  79. if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS){
  80. String result = bundle.getString(CodeUtils.RESULT_STRING);
  81. //TODO update fanglh 2017-6-7 新增扫描名片二维码需求
  82. if (StringUtil.isEmpty(result)) {
  83. Crouton crouton = Crouton.makeText(CaptureResultActivity.this, "您扫描的二维码信息为空", 0xffff4444, 1500);
  84. crouton.show();
  85. crouton.setLifecycleCallback(new LifecycleCallback() {
  86. @Override
  87. public void onDisplayed() {
  88. }
  89. @Override
  90. public void onRemoved() {
  91. finish();
  92. }
  93. });
  94. }else {
  95. if (CommonUtil.isWebsite(result)){
  96. mWebView.loadUrl(result);
  97. }else {
  98. doJudgeInfoCard(result);//进行是否为名片二维码判断
  99. }
  100. }
  101. Log.d("scanurl",result);
  102. }
  103. }
  104. }
  105. private void doJudgeInfoCard(String result) {
  106. Boolean isJSONData = JSONUtil.validate(result);//是否是JSON格式字符
  107. if (isJSONData && result.contains("uu_name") && result.contains("uu_phone")){
  108. startActivity(new Intent(this, ScanInfoResultsActivity.class)
  109. .putExtra("ScanResults",result)
  110. .putExtra("isQRData",true));// true :扫描到的是名片信息标志
  111. }else if (isJSONData && result.contains("clientId")){
  112. doUasLoginRequest(result);
  113. }else {
  114. startActivity(new Intent(this, ScanInfoResultsActivity.class)
  115. .putExtra("ScanResults",result)
  116. .putExtra("isQRData",false));
  117. }
  118. // finish();
  119. }
  120. /**
  121. * 新增扫描UAS二维码登录功能
  122. * @param result
  123. */
  124. private void doUasLoginRequest(String result) {
  125. String clientId = JSON.parseObject(result).getString("clientId");
  126. if (StringUtil.isEmail(clientId)) return;
  127. /*HttpClient httpClient = new HttpClient.Builder("http://192.168.253.63:8080/ERP/").build();
  128. httpClient.Api().send(new HttpClient.Builder()
  129. .url("common/checkQrcodeScan.action")
  130. .add("clientId",clientId)
  131. .add("em_code ", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"))
  132. .add("sob",CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master"))
  133. .method(Method.GET)
  134. .build(),new ResultSubscriber<>(new ResultListener<Object>() {
  135. @Override
  136. public void onResponse(Object o) {
  137. Log.i("FLH",JSON.toJSONString(o)+"");
  138. Toast.makeText(MyApplication.getInstance(),JSON.toJSONString(o)+"",Toast.LENGTH_LONG).show();
  139. }
  140. }));*/
  141. String url = null;
  142. // url = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_baseurl")+"common/checkQrcodeScan.action";
  143. url = "http://192.168.253.63:8080/ERP/"+"common/checkQrcodeScan.action";
  144. String em_code = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username");
  145. String sob = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master");
  146. Intent intent_web = new Intent("com.modular.main.WebViewCommActivity");
  147. intent_web.putExtra("url", url + "?clientId=" + clientId + "?em_code=" + em_code + "?sob=" + sob);
  148. intent_web.putExtra("title", "UAS网页登录");
  149. intent_web.putExtra("cookie", true);
  150. startActivity(intent_web);
  151. finish();
  152. }
  153. @Override
  154. public boolean onKeyDown(int keyCode, KeyEvent event) {
  155. if (keyCode == KeyEvent.KEYCODE_BACK){
  156. if (mWebView.canGoBack()){
  157. mWebView.goBack();
  158. return true;
  159. }
  160. }
  161. return super.onKeyDown(keyCode, event);
  162. }
  163. }