| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package com.xzjmyk.pm.activity;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.webkit.DownloadListener;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import com.alibaba.fastjson.JSON;
- import com.common.data.JSONUtil;
- import com.common.data.StringUtil;
- import com.common.file.DownloadUtil;
- import com.core.app.MyApplication;
- import com.core.utils.CommonUtil;
- import com.uuzuche.lib_zxing.activity.CodeUtils;
- import com.xzjmyk.pm.activity.ui.me.ScanInfoResultsActivity;
- import com.xzjmyk.pm.activity.view.crouton.Crouton;
- import com.xzjmyk.pm.activity.view.crouton.LifecycleCallback;
- /**
- * @author RaoMeng
- * update fanglh 2017-6-7 新增扫描名片二维码需求
- * update fanglh 2017-9-14 新增扫描UAS二维码登录功能
- */
- public class CaptureResultActivity extends Activity {
- private WebView mWebView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_capture_result);
- initActivity();
- initData();
- }
- private void initActivity() {
- mWebView = (WebView) findViewById(R.id.result_webview);
- WebSettings webSettings = mWebView.getSettings();
- //允许加载JavaScript
- webSettings.setJavaScriptEnabled(true);
- //网页自适应屏幕
- webSettings.setUseWideViewPort(true);
- webSettings.setLoadWithOverviewMode(true);
- webSettings.setDomStorageEnabled(true);
- mWebView.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- // view.loadUrl(url);
- // return true;
- return false;
- }
- });
- mWebView.setDownloadListener(new DownloadListener() {
- @Override
- public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
- // Uri uri = Uri.parse(url);
- // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- // startActivity(intent);
- Log.d("fileurl", url);
- String fileName = url.substring(url.lastIndexOf("/") + 1);
- new AlertDialog.Builder(CaptureResultActivity.this).setTitle("提示").setMessage("确定下载文件<"+fileName+">吗?").setNegativeButton(R.string.cancel, null)
- .setPositiveButton(R.string.sure, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- DownloadUtil.DownloadFile(CaptureResultActivity.this,url,"/sdcard/uu");
- }
- }).create().show();
- }
- });
- }
- private void initData() {
- Intent intent = getIntent();
- if (null != intent) {
- Bundle bundle = intent.getExtras();
- if (bundle == null){
- return;
- }
- if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS){
- String result = bundle.getString(CodeUtils.RESULT_STRING);
- //TODO update fanglh 2017-6-7 新增扫描名片二维码需求
- if (StringUtil.isEmpty(result)) {
- Crouton crouton = Crouton.makeText(CaptureResultActivity.this, "您扫描的二维码信息为空", 0xffff4444, 1500);
- crouton.show();
- crouton.setLifecycleCallback(new LifecycleCallback() {
- @Override
- public void onDisplayed() {
- }
- @Override
- public void onRemoved() {
- finish();
- }
- });
- }else {
- if (CommonUtil.isWebsite(result)){
- mWebView.loadUrl(result);
- }else {
- doJudgeInfoCard(result);//进行是否为名片二维码判断
- }
- }
- Log.d("scanurl",result);
- }
- }
- }
- private void doJudgeInfoCard(String result) {
- Boolean isJSONData = JSONUtil.validate(result);//是否是JSON格式字符
- if (isJSONData && result.contains("uu_name") && result.contains("uu_phone")){
- startActivity(new Intent(this, ScanInfoResultsActivity.class)
- .putExtra("ScanResults",result)
- .putExtra("isQRData",true));// true :扫描到的是名片信息标志
- }else if (isJSONData && result.contains("clientId")){
- doUasLoginRequest(result);
- }else {
- startActivity(new Intent(this, ScanInfoResultsActivity.class)
- .putExtra("ScanResults",result)
- .putExtra("isQRData",false));
- }
- // finish();
- }
- /**
- * 新增扫描UAS二维码登录功能
- * @param result
- */
- private void doUasLoginRequest(String result) {
- String clientId = JSON.parseObject(result).getString("clientId");
- if (StringUtil.isEmail(clientId)) return;
- /*HttpClient httpClient = new HttpClient.Builder("http://192.168.253.63:8080/ERP/").build();
- httpClient.Api().send(new HttpClient.Builder()
- .url("common/checkQrcodeScan.action")
- .add("clientId",clientId)
- .add("em_code ", CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username"))
- .add("sob",CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master"))
- .method(Method.GET)
- .build(),new ResultSubscriber<>(new ResultListener<Object>() {
- @Override
- public void onResponse(Object o) {
- Log.i("FLH",JSON.toJSONString(o)+"");
- Toast.makeText(MyApplication.getInstance(),JSON.toJSONString(o)+"",Toast.LENGTH_LONG).show();
- }
- }));*/
- String url = null;
- // url = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_baseurl")+"common/checkQrcodeScan.action";
- url = "http://192.168.253.63:8080/ERP/"+"common/checkQrcodeScan.action";
- String em_code = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_username");
- String sob = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master");
- Intent intent_web = new Intent("com.modular.main.WebViewCommActivity");
- intent_web.putExtra("url", url + "?clientId=" + clientId + "?em_code=" + em_code + "?sob=" + sob);
- intent_web.putExtra("title", "UAS网页登录");
- intent_web.putExtra("cookie", true);
- startActivity(intent_web);
- finish();
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK){
- if (mWebView.canGoBack()){
- mWebView.goBack();
- return true;
- }
- }
- return super.onKeyDown(keyCode, event);
- }
- }
|