|
|
@@ -0,0 +1,376 @@
|
|
|
+package com.zy.bvvm.pdf;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.hjq.bar.OnTitleBarListener;
|
|
|
+import com.hjq.bar.TitleBar;
|
|
|
+import com.zy.bvvm.R;
|
|
|
+import com.zy.bvvm.helper.DownloadPDF;
|
|
|
+import com.zy.bvvm.helper.HttpUtils;
|
|
|
+import com.zy.bvvm.helper.SPUtils;
|
|
|
+import com.zy.bvvm.mvp.MvpActivity;
|
|
|
+import com.zy.bvvm.ui.bean.ModelListBean;
|
|
|
+import com.zy.bvvm.ui.bean.VerificationCodeBean;
|
|
|
+import com.zy.bvvm.ui.bean.VnDetailBean;
|
|
|
+import com.zy.bvvm.ui.report.vndetail.VnDetailContract;
|
|
|
+import com.zy.bvvm.ui.report.vndetail.VnDetailPresenter;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Callback;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
+public class RportPDFActivity extends MvpActivity<VnDetailPresenter> implements VnDetailContract.View, View.OnClickListener {
|
|
|
+
|
|
|
+ //产品信息
|
|
|
+ //左边
|
|
|
+ @BindView(R.id.tv_left_info_01)
|
|
|
+ TextView left_info_01;
|
|
|
+ @BindView(R.id.tv_left_info_02)
|
|
|
+ TextView left_info_02;
|
|
|
+ @BindView(R.id.tv_left_info_03)
|
|
|
+ TextView left_info_03;
|
|
|
+ @BindView(R.id.tv_left_info_04)
|
|
|
+ TextView left_info_04;
|
|
|
+ //右边
|
|
|
+ @BindView(R.id.tv_right_info_01)
|
|
|
+ TextView right_info_01;
|
|
|
+ @BindView(R.id.tv_right_info_02)
|
|
|
+ TextView right_info_02;
|
|
|
+ @BindView(R.id.tv_right_info_03)
|
|
|
+ TextView right_info_03;
|
|
|
+ @BindView(R.id.tv_right_info_04)
|
|
|
+ TextView right_info_04;
|
|
|
+ //报告编号
|
|
|
+ @BindView(R.id.tv_pdf_number)
|
|
|
+ TextView pdf_number;
|
|
|
+ //报告时间
|
|
|
+ @BindView(R.id.tv_pdf_time)
|
|
|
+ TextView pdf_time;
|
|
|
+ //报告状态
|
|
|
+ @BindView(R.id.iv_pdf_state)
|
|
|
+ ImageView pdf_state;
|
|
|
+ //二维码
|
|
|
+ @BindView(R.id.iv_pdf_QR_code)
|
|
|
+ ImageView pdf_QR_code;
|
|
|
+
|
|
|
+ //map图片
|
|
|
+ @BindView(R.id.iv_map_image)
|
|
|
+ ImageView map_image;
|
|
|
+ @BindView(R.id.iv_locaion)
|
|
|
+ ImageView map_location;
|
|
|
+ @BindView(R.id.tv_address)
|
|
|
+ TextView map_address;
|
|
|
+
|
|
|
+ //标题
|
|
|
+ @BindView(R.id.tv_pdf_title)
|
|
|
+ TitleBar pdf_title;
|
|
|
+
|
|
|
+ //布局
|
|
|
+ @BindView(R.id.ll_all_layoout)
|
|
|
+ LinearLayout all_layout;
|
|
|
+
|
|
|
+ //报警状态
|
|
|
+ private boolean isWarning = true;
|
|
|
+ //数据详情
|
|
|
+ private VnDetailBean.DataBean chipModel = null;
|
|
|
+ //状态
|
|
|
+ private int status;
|
|
|
+ private double lng = 0.0;
|
|
|
+ private double lat = 0.0;
|
|
|
+ private static final int ERROR = 1;
|
|
|
+ private static final int SUCCESS = 2;
|
|
|
+ private String address;
|
|
|
+ //下载权限
|
|
|
+ static final String[] PERMISSION = new String[]{
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
+ };
|
|
|
+ private String nextbtn;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+// setContentView(R.layout.activity_rport_p_d_f);
|
|
|
+ ButterKnife.bind(this); //必须要这一句,不然会出现奔溃
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.activity_rport_p_d_f;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTitleId() {
|
|
|
+ return R.id.tv_pdf_title;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ Intent intent = getIntent();
|
|
|
+ if (intent != null) {
|
|
|
+ chipModel = (VnDetailBean.DataBean) intent.getSerializableExtra("dataBean");
|
|
|
+ isWarning = intent.getBooleanExtra("isWarning", true);
|
|
|
+ status = intent.getIntExtra("status", 0);
|
|
|
+ nextbtn = intent.getStringExtra("nextbtn");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+ pdf_title.setOnTitleBarListener(new OnTitleBarListener() {
|
|
|
+ @Override
|
|
|
+ public void onLeftClick(View v) {
|
|
|
+ //判断数据来源
|
|
|
+ if (nextbtn.equals("read")) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTitleClick(View v) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRightClick(View v) {
|
|
|
+ //下载pdf报告
|
|
|
+// requestCemera();
|
|
|
+ DownloadPDF.requestCemera(getActivity(), all_layout);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //页面赋值
|
|
|
+ setViewData();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示详细信息
|
|
|
+ */
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
+ private void setViewData() {
|
|
|
+ pdf_number.setText("报告编号:" + chipModel.getCodeX()); //报告编号
|
|
|
+ pdf_time.setText("报告日期:" + chipModel.getDatetime()); //时间
|
|
|
+ //左边
|
|
|
+ left_info_01.setText(TextUtils.isEmpty(chipModel.getVaccineName()) ? "N/A" : chipModel.getVaccineName()); //商品名称
|
|
|
+ left_info_02.setText(TextUtils.isEmpty(chipModel.getVaccineCommonName()) ? "N/A" : chipModel.getVaccineCommonName()); //通用名称
|
|
|
+ left_info_03.setText(TextUtils.isEmpty(chipModel.getFactoryName()) ? "N/A" : chipModel.getFactoryName()); //生产企业名称
|
|
|
+ left_info_04.setText(TextUtils.isEmpty(chipModel.getVaccineExpiryDate()) ? "N/A" : chipModel.getVaccineExpiryDate() + "个月"); //有效期
|
|
|
+ //右边
|
|
|
+ right_info_01.setText(TextUtils.isEmpty(chipModel.getVaccineCategory()) ? "N/A" : chipModel.getVaccineCategory()); //规格
|
|
|
+ right_info_02.setText(TextUtils.isEmpty(chipModel.getStandardCode()) ? "N/A" : chipModel.getStandardCode()); //药品本位码
|
|
|
+ right_info_03.setText(TextUtils.isEmpty(chipModel.getApprovalNumber()) ? "N/A" : chipModel.getApprovalNumber()); //药品批准文号
|
|
|
+ right_info_04.setText(TextUtils.isEmpty(chipModel.getIdentificationCode()) ? "N/A" : chipModel.getIdentificationCode()); //国家药品标识码
|
|
|
+ //报警状态
|
|
|
+ if (isWarning == true) {
|
|
|
+ pdf_state.setImageResource(R.mipmap.pdf_image_warning);
|
|
|
+ } else {
|
|
|
+ pdf_state.setImageResource(R.mipmap.pdf_image_adopt);
|
|
|
+ }
|
|
|
+ //获取地图信息图片
|
|
|
+ setMapInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 展示地图
|
|
|
+ */
|
|
|
+ private void setMapInfo() {
|
|
|
+ //获取经纬度
|
|
|
+ gpsToLocation();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void gpsToLocation() {
|
|
|
+ String location[] = SPUtils.get("LOCATION", "").toString().split(",");
|
|
|
+ Double latitude = null;
|
|
|
+ Double longitude = null;
|
|
|
+ if (location.length > 1) {
|
|
|
+ latitude = Double.parseDouble(location[0]);
|
|
|
+ longitude = Double.parseDouble(location[1]);
|
|
|
+ }
|
|
|
+ //经纬度GPS转高得地图
|
|
|
+ String url = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=" + longitude + "," + latitude + "&coordsys=gps&key=166b0ac8c36df284fc779fd662237017";
|
|
|
+ Log.e("url", url);
|
|
|
+ HttpUtils.doGet(url, new Callback() {
|
|
|
+ @Override
|
|
|
+ public void onFailure(Call call, IOException e) {
|
|
|
+// toast(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Call call, Response response) throws IOException {
|
|
|
+ String asd = response.body().string();
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject(asd);
|
|
|
+ if (jsonObject.getString("info").equals("ok")) {
|
|
|
+ String locations = jsonObject.getString("locations");
|
|
|
+// SPUtils.put("LOCATIONS", locations);
|
|
|
+// return locations;
|
|
|
+ //
|
|
|
+ getAddressInfo(locations);
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据经纬度逆地理查询地址
|
|
|
+ *
|
|
|
+ * @param locations
|
|
|
+ */
|
|
|
+ private void getAddressInfo(String locations) {
|
|
|
+ String url = "https://restapi.amap.com/v3/geocode/regeo?&location=" + locations + "&key=166b0ac8c36df284fc779fd662237017";
|
|
|
+ Log.e("url", url);
|
|
|
+ HttpUtils.doGet(url, new Callback() {
|
|
|
+ @Override
|
|
|
+ public void onFailure(Call call, IOException e) {
|
|
|
+// toast(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Call call, Response response) throws IOException {
|
|
|
+ String asd = response.body().string();
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject(asd);
|
|
|
+ if (jsonObject.getString("status").equals("1")) {
|
|
|
+// address = jsonObject.getString("formatted_address");
|
|
|
+ address = jsonObject.getJSONObject("regeocode").getString("formatted_address");
|
|
|
+ getMapInfo(locations);
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getMapInfo(String locations) {
|
|
|
+ String url = "https://restapi.amap.com/v3/staticmap?location=" + locations + "&scale=2&zoom=14&size=512*307&key=166b0ac8c36df284fc779fd662237017";
|
|
|
+// String url = "https://restapi.amap.com/v3/staticmap?markers=mid,0xFF0000,A:116.37359,39.92437&labels=%E6%9C%9D%E9%98%B3%E5%85%AC%E5%9B%AD,2,0,16,0xFFFFFF,0x008000:116.37359,39.92437&key=166b0ac8c36df284fc779fd662237017";
|
|
|
+ Log.e("url", url);
|
|
|
+ HttpUtils.doGet(url, new Callback() {
|
|
|
+ @Override
|
|
|
+ public void onFailure(Call call, IOException e) {
|
|
|
+// toast(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Call call, Response response) throws IOException {
|
|
|
+ Log.e("map", response.body().toString());
|
|
|
+ //获取流
|
|
|
+ InputStream in = response.body().byteStream();
|
|
|
+ //转为bitmap
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeStream(in);
|
|
|
+ //使用Hanlder发送消息
|
|
|
+ Message msg = Message.obtain();
|
|
|
+
|
|
|
+ msg.what = SUCCESS;
|
|
|
+ msg.obj = bitmap;
|
|
|
+
|
|
|
+ handler.sendMessage(msg);
|
|
|
+// map_image.setImageBitmap(bitmap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ @SuppressLint("HandlerLeak")
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case SUCCESS:
|
|
|
+ map_location.setVisibility(View.VISIBLE);
|
|
|
+ if (address != null) {
|
|
|
+ map_address.setVisibility(View.VISIBLE);
|
|
|
+ map_address.setText(address);
|
|
|
+ } else {
|
|
|
+ map_address.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ map_image.setImageBitmap((Bitmap) msg.obj);
|
|
|
+ break;
|
|
|
+ case ERROR:
|
|
|
+ Toast.makeText(RportPDFActivity.this, "请求超时", Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected VnDetailPresenter createPresenter() {
|
|
|
+ return new VnDetailPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getDetailError(String msg) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getDetailSuccess(VnDetailBean data) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getSendMailError(String msg) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getSendMailSuccess(VnDetailBean data) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getmlistError(String msg) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getmlistSuccess(ModelListBean data) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getToReviewError(String msg) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getToReviewSuccess(VerificationCodeBean data) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|