|
|
|
@ -1,13 +1,28 @@ |
|
|
|
package com.qhclh.ytzh.work.CatchChicken; |
|
|
|
|
|
|
|
import android.Manifest; |
|
|
|
import android.content.Intent; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import com.google.zxing.integration.android.IntentIntegrator; |
|
|
|
import com.google.zxing.integration.android.IntentResult; |
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
import com.qhclh.ytzh.home.RpcUrl; |
|
|
|
import com.qhclh.ytzh.tasks.ViewOnClickTask; |
|
|
|
import com.qhclh.ytzh.utils.DateTimeUtil; |
|
|
|
import com.qhclh.ytzh.work.scan.ScanActivity; |
|
|
|
|
|
|
|
import org.forks.jsonrpc.JsonRpcResult; |
|
|
|
import org.forks.jsonrpc.RpcFacade; |
|
|
|
import org.forks.jsonrpc.RpcObject; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import pub.devrel.easypermissions.AfterPermissionGranted; |
|
|
|
import pub.devrel.easypermissions.EasyPermissions; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by 青花瓷 on 2018/5/8. |
|
|
|
@ -48,6 +63,94 @@ public class CCScanActivity extends BaseActivity { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void initOper() { |
|
|
|
dongtaiQuanxian(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onResume() { |
|
|
|
super.onResume(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final int REQUEST_PERMISSION_CAMERA_CODE = 102; |
|
|
|
|
|
|
|
@AfterPermissionGranted(REQUEST_PERMISSION_CAMERA_CODE) |
|
|
|
private void dongtaiQuanxian() { |
|
|
|
String[] perms = {Manifest.permission.CAMERA}; |
|
|
|
if (!EasyPermissions.hasPermissions(this, perms)) { |
|
|
|
// Do not have permissions, request them now |
|
|
|
EasyPermissions.requestPermissions(this, getString(R.string.permission_camera), |
|
|
|
REQUEST_PERMISSION_CAMERA_CODE, perms); |
|
|
|
} else { |
|
|
|
// Already have permission, do the thing |
|
|
|
scan(); |
|
|
|
} |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void scan() { |
|
|
|
IntentIntegrator integrator = new IntentIntegrator(this); |
|
|
|
// 设置要扫描的条码类型,ONE_D_CODE_TYPES:一维码,QR_CODE_TYPES-二维码 |
|
|
|
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES); |
|
|
|
integrator.setCaptureActivity(ScanActivity.class); |
|
|
|
|
|
|
|
integrator.setPrompt("扫描养殖场"); |
|
|
|
integrator.setCameraId(0); //前置或者后置摄像头 |
|
|
|
integrator.setBeepEnabled(false); //扫描成功的「哔哔」声,默认开启 |
|
|
|
integrator.setBarcodeImageEnabled(true); |
|
|
|
integrator.initiateScan(); |
|
|
|
} |
|
|
|
|
|
|
|
///< 回调获取扫描得到的条码值 |
|
|
|
@Override |
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
|
|
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); |
|
|
|
if (result != null) { |
|
|
|
if (result.getContents() == null) { |
|
|
|
showToast("取消扫描"); |
|
|
|
finish(); |
|
|
|
} else { |
|
|
|
scanStr = result.getContents(); |
|
|
|
CatchChickenInsert(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
super.onActivityResult(requestCode, resultCode, data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CatchChickenInsert() { |
|
|
|
ViewOnClickTask arrivefTask = new ViewOnClickTask(this,"加载中...") { |
|
|
|
RpcObject rpcObj; |
|
|
|
@Override |
|
|
|
protected void successUI() { |
|
|
|
if (rpcObj.getString("Employee_Name")!=null){ |
|
|
|
catchscan_name.setText(rpcObj.getString("Employee_Name")); |
|
|
|
} |
|
|
|
if (rpcObj.getString("BreedFactory_Name")!=null){ |
|
|
|
catchscan_factory.setText(rpcObj.getString("BreedFactory_Name")); |
|
|
|
} |
|
|
|
if (rpcObj.getString("Employee_HandPhone")!=null){ |
|
|
|
catchscan_phone.setText(rpcObj.getString("Employee_HandPhone")); |
|
|
|
} |
|
|
|
|
|
|
|
if (rpcObj.getDate("Time")!=null){ |
|
|
|
catchscan_time.setText(DateTimeUtil.getYMD4(rpcObj.getDate("Time"))); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
JsonRpcResult result = RpcFacade.rpcCall(RpcUrl.CatchChickenInsert,scanStr); |
|
|
|
rpcObj = result.getRpcObject(RpcUrl.CatchChickenInsert_fanhui); |
|
|
|
return null; |
|
|
|
} |
|
|
|
}; |
|
|
|
arrivefTask.execute(); |
|
|
|
} |
|
|
|
} |