332 lines
15 KiB
Java
332 lines
15 KiB
Java
package cn.shangyu.gdxzExpert.activity;
|
|
|
|
import static cn.bertsir.zbar.QrConfig.SCANVIEW_TYPE_QRCODE;
|
|
import static cn.bertsir.zbar.QrConfig.SCREEN_PORTRAIT;
|
|
import static cn.bertsir.zbar.QrConfig.TYPE_QRCODE;
|
|
import static cn.bertsir.zbar.view.ScanLineView.style_line;
|
|
import static cn.shangyu.gdxzExpert.utils.Url.scanurl;
|
|
|
|
import android.Manifest;
|
|
import android.content.Intent;
|
|
import android.graphics.Color;
|
|
import android.os.Build;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.util.Log;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import com.github.dfqin.grantor.PermissionListener;
|
|
import com.github.dfqin.grantor.PermissionsUtil;
|
|
import com.gyf.immersionbar.ImmersionBar;
|
|
import com.hjq.window.EasyWindow;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.io.DataOutputStream;
|
|
import java.io.InputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
|
|
import cn.bertsir.zbar.Qr.ScanResult;
|
|
import cn.bertsir.zbar.QrConfig;
|
|
import cn.bertsir.zbar.QrManager;
|
|
import cn.shangyu.gdxzExpert.R;
|
|
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
|
import cn.shangyu.gdxzExpert.fragment.MeetingFragment;
|
|
import cn.shangyu.gdxzExpert.utils.AESUtil;
|
|
import cn.shangyu.gdxzExpert.utils.Constant;
|
|
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
|
import cn.shangyu.gdxzExpert.utils.StreamTool;
|
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
|
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
|
import cn.shangyu.gdxzExpert.utils.UIUtils;
|
|
import cn.shangyu.gdxzExpert.widget.LoadingPage;
|
|
|
|
/**
|
|
* Created by WANGChengXin on 2020/3/10.
|
|
*/
|
|
|
|
public class GandanMeetingActivity extends BaseActivity{
|
|
private View view;
|
|
@Override
|
|
public void setTitle() {
|
|
top_title.setText("肝胆会议");
|
|
top_right_text.setVisibility(View.VISIBLE);
|
|
top_right_text.setText("扫一扫");
|
|
// top_right_text.setText("回放");
|
|
top_right_text.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO Auto-generated method stub
|
|
// Intent intent = new Intent(ct, HistoryActivity.class);
|
|
// intent.putExtra("title",getResources().getString(R.string.gandanhuifang));
|
|
// startActivity(intent);
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
//
|
|
if (PermissionsUtil.hasPermission(GandanMeetingActivity.this, Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
//有访问摄像头的权限,读写内存,网络定位,打电话,读取短信,录音,通讯录
|
|
startToCapture();
|
|
} else {
|
|
EasyWindow.with(GandanMeetingActivity.this).setGravity(Gravity.TOP).setYOffset(200).setWidth(1000)
|
|
|
|
.setContentView(R.layout.float_top_dialog).show();
|
|
PermissionsUtil.requestPermission(GandanMeetingActivity.this, new PermissionListener() {
|
|
@Override
|
|
public void permissionGranted(@NonNull String[] permissions) {
|
|
EasyWindow.cancelAll();
|
|
//用户授予了访问读取短信的权限
|
|
startToCapture();
|
|
}
|
|
@Override
|
|
public void permissionDenied(@NonNull String[] permissions) {
|
|
//用户拒绝了访问读取短信的申请
|
|
EasyWindow.cancelAll();
|
|
}
|
|
|
|
}, new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE});
|
|
}
|
|
|
|
}else {
|
|
startToCapture();
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
private void startToCapture() {
|
|
start();
|
|
// startActivity(new Intent(MainActivity.this, CaptureActivity.class));
|
|
}
|
|
String scanResult;
|
|
private void start() {
|
|
|
|
QrConfig qrConfig = new QrConfig.Builder()
|
|
.setDesText("将二维码放入框内,自动扫码")//扫描框下文字
|
|
.setShowDes(true)//是否显示扫描框下面文字
|
|
.setShowLight(false)//显示手电筒按钮
|
|
.setShowTitle(true)//显示Title
|
|
.setShowAlbum(false)//显示从相册选择按钮
|
|
.setNeedCrop(false)//是否从相册选择后裁剪图片
|
|
// .setCornerColor(Color.parseColor("#E42E30"))//设置扫描框颜色
|
|
.setLineColor(Color.parseColor("#8D2316"))//设置扫描线颜色
|
|
.setLineSpeed(QrConfig.LINE_MEDIUM)//设置扫描线速度
|
|
.setScanType(TYPE_QRCODE)//设置扫码类型(二维码,条形码,全部,自定义,默认为二维码)
|
|
.setScanViewType(SCANVIEW_TYPE_QRCODE)//设置扫描框类型(二维码还是条形码,默认为二维码)
|
|
.setCustombarcodeformat(QrConfig.BARCODE_PDF417)//此项只有在扫码类型为TYPE_CUSTOM时才有效
|
|
.setPlaySound(true)//是否扫描成功后bi~的声音
|
|
// .setDingPath(cb_show_custom_ding.isChecked() ? R.raw.test : R.raw.qrcode)//设置提示音(不设置为默认的Ding~)
|
|
.setIsOnlyCenter(false)//是否只识别框中内容(默认为全屏识别)
|
|
// .setTitleText(et_qr_title.getText().toString())//设置Tilte文字
|
|
.setTitleBackgroudColor(Color.parseColor("#FFEFEFEF"))//设置状态栏颜色
|
|
.setTitleTextColor(Color.parseColor("#8D2316"))//设置Title文字颜色
|
|
// .setShowZoom(cb_show_zoom.isChecked())//是否开始滑块的缩放
|
|
// .setAutoZoom(cb_auto_zoom.isChecked())//是否开启自动缩放(实验性功能,不建议使用)
|
|
// .setFingerZoom(cb_finger_zoom.isChecked())//是否开始双指缩放
|
|
// .setDoubleEngine(cb_double_engine.isChecked())//是否开启双引擎识别(仅对识别二维码有效,并且开启后只识别框内功能将失效)
|
|
.setScreenOrientation(SCREEN_PORTRAIT)//设置屏幕方式
|
|
.setOpenAlbumText("选择要识别的图片")//打开相册的文字
|
|
.setLooperScan(false)//是否连续扫描二维码
|
|
// .setLooperWaitTime(Integer.parseInt(et_loop_scan_time.getText().toString()) * 1000)//连续扫描间隔时间
|
|
.setScanLineStyle(style_line)//扫描线样式
|
|
// .setAutoLight(cb_auto_light.isChecked())//自动灯光
|
|
.setShowVibrator(true)//是否震动提醒
|
|
.create();
|
|
QrManager.getInstance().init(qrConfig).startScan(this, new QrManager.OnScanResultCallback() {
|
|
@Override
|
|
public void onScanSuccess(ScanResult result) {
|
|
// Log.e(TAG, "onScanSuccess: " + result);
|
|
|
|
scanResult = result.getContent();
|
|
try {
|
|
scanResult= AESUtil.Decrypt(scanResult, "deoep09_klodLdAo");
|
|
new Thread(networkTask2).start();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// Toast.makeText(MainActivity.this, "内容:" + result.getContent()
|
|
// + " 类型:" + result.getType(), Toast.LENGTH_SHORT).show();
|
|
}
|
|
});
|
|
}
|
|
String finres;
|
|
String canfinres;
|
|
Runnable networkTask2 = new Runnable() {
|
|
|
|
@Override
|
|
public void run() {
|
|
// TODO
|
|
//String url = null;
|
|
|
|
if(scanResult==null)
|
|
{
|
|
ToastUtil.showMessage("您扫描的不是有效的肝胆相照平台二维码");
|
|
// finish();
|
|
return;
|
|
}
|
|
|
|
if (scanResult.contains("watchliveFrom")) {
|
|
|
|
String uuid = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.uuid, "123");
|
|
String realname = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.realName, "肝胆相照专家");
|
|
String photo = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.photo, "https://doc.igandan.com/app/html/img/2016/20160714132557.png");
|
|
if (StringUtil.isEmpty(photo) || "null".equals(photo)) {
|
|
photo = "https://doc.igandan.com/app/html/img/2016/20160714132557.png";
|
|
}
|
|
scanResult = scanResult.replaceAll("watchliveFrom:", "");
|
|
try {
|
|
//url = urlpath +"?message=" + AESUtil.Encrypt("liveScanSuccess}" + result + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
finres=AESUtil.Encrypt("watchliveTo}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
canfinres=AESUtil.Encrypt("watchliveCancel}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
getTooken1(scanurl,AESUtil.Encrypt("liveScanSuccess}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo"));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
else if(scanResult.contains("watchvideoFrom")){
|
|
String uuid = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.uuid, "123");
|
|
String realname = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.realName, "肝胆相照专家");
|
|
String photo = SharePrefUtil.getString(GandanMeetingActivity.this, Constant.photo, "https://doc.igandan.com/app/html/img/2016/20160714132557.png");
|
|
if (StringUtil.isEmpty(photo) || "null".equals(photo)) {
|
|
photo = "https://doc.igandan.com/app/html/img/2016/20160714132557.png";
|
|
}
|
|
scanResult = scanResult.replaceAll("watchvideoFrom:", "");
|
|
try {
|
|
//url = urlpath + "?message=" +AESUtil.Encrypt("videoScanSuccess}" + result + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
finres=AESUtil.Encrypt("watchvideoTo}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
canfinres=AESUtil.Encrypt("watchvideoCancel}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo");
|
|
getTooken1(scanurl,AESUtil.Encrypt("videoScanSuccess}" + scanResult + "}" + uuid + "," + realname + "," + photo,"deoep09_klodLdAo"));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
else {
|
|
ToastUtil.showMessage("您扫描的不是有效的肝胆相照平台二维码");
|
|
// finish();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
private void getTooken1(String urlStringUtil,String param) {
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
try {
|
|
String data="message="+ URLEncoder.encode(param,"UTF-8");
|
|
URL url = new URL(urlStringUtil);
|
|
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
conn.setRequestMethod("POST");
|
|
conn.setDoOutput(true);
|
|
conn.setDoInput(true);
|
|
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
|
|
|
|
conn.setConnectTimeout(5 * 1000);
|
|
DataOutputStream dos=new DataOutputStream(conn.getOutputStream());
|
|
dos.writeBytes(data);
|
|
dos.flush();
|
|
dos.close();
|
|
if (conn.getResponseCode() == 200) {
|
|
InputStream inStream = conn.getInputStream();
|
|
String result = new String(
|
|
StreamTool.readInputStream(inStream), "UTF-8");
|
|
Log.d("saoresult" , result);
|
|
Message message = new Message();
|
|
message.what = 102;
|
|
message.obj = new String(result);
|
|
handler1.sendMessage(message);
|
|
}else {
|
|
Message message = new Message();
|
|
message.what = 105;
|
|
handler1.sendMessage(message);
|
|
ToastUtil.showMessage("请求失败了,请稍后重试");
|
|
}
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
ToastUtil.showMessage("请求失败,请稍后重试");
|
|
}
|
|
|
|
}
|
|
public Handler handler1 = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
// TODO Auto-generated method stub
|
|
switch (msg.what) {
|
|
case 102:
|
|
|
|
try {
|
|
|
|
String str = (String) msg.obj;
|
|
//Log.d("saoresult" , str);//{"code":1,"message":"授权成功"}
|
|
JSONObject objs = new JSONObject(str);
|
|
int retcode = objs.optInt("code");
|
|
|
|
// String expertuuid = objs.getString("expertUuid");
|
|
// String message = objs.getString("message");
|
|
//ToastUtil.showMessage(message,1);
|
|
if(retcode==1)
|
|
{
|
|
|
|
if(finres!=null&&canfinres!=null)
|
|
{
|
|
|
|
Intent intent=new Intent(GandanMeetingActivity.this, ConfirmActivity.class);
|
|
intent.putExtra("scancode",finres);
|
|
intent.putExtra("canfinres",canfinres);
|
|
startActivity(intent);
|
|
// finish();
|
|
}
|
|
}
|
|
else {
|
|
ToastUtil.showMessage("服务器异常!");
|
|
}
|
|
|
|
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
// ToastUtil.showMessage("服务器异常!");
|
|
finish();
|
|
}
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
@Override
|
|
public View onCreateSuccessedView() {
|
|
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
|
view = UIUtils.inflate(R.layout.activity_news);
|
|
MeetingFragment loveFragment = new MeetingFragment();
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, loveFragment, "love_fragment")
|
|
.commitAllowingStateLoss();
|
|
return view;
|
|
}
|
|
|
|
@Override
|
|
public LoadingPage.ResultState onLoad() {
|
|
return LoadingPage.ResultState.STATE_SUCCESSED;
|
|
}
|
|
|
|
@Override
|
|
protected void processClick(View v) {
|
|
|
|
}
|
|
}
|