RportPDFActivity.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. package com.zy.bvvm.pdf;
  2. import android.Manifest;
  3. import android.annotation.SuppressLint;
  4. import android.content.Intent;
  5. import android.graphics.Bitmap;
  6. import android.graphics.BitmapFactory;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.os.Message;
  10. import android.text.TextUtils;
  11. import android.util.Log;
  12. import android.view.View;
  13. import android.widget.ImageView;
  14. import android.widget.LinearLayout;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17. import com.hjq.bar.OnTitleBarListener;
  18. import com.hjq.bar.TitleBar;
  19. import com.zy.bvvm.R;
  20. import com.zy.bvvm.helper.DownloadPDF;
  21. import com.zy.bvvm.helper.HttpUtils;
  22. import com.zy.bvvm.helper.SPUtils;
  23. import com.zy.bvvm.mvp.MvpActivity;
  24. import com.zy.bvvm.ui.bean.ModelListBean;
  25. import com.zy.bvvm.ui.bean.VerificationCodeBean;
  26. import com.zy.bvvm.ui.bean.VnDetailBean;
  27. import com.zy.bvvm.ui.report.vndetail.VnDetailContract;
  28. import com.zy.bvvm.ui.report.vndetail.VnDetailPresenter;
  29. import org.json.JSONException;
  30. import org.json.JSONObject;
  31. import java.io.IOException;
  32. import java.io.InputStream;
  33. import butterknife.BindView;
  34. import butterknife.ButterKnife;
  35. import me.leefeng.promptlibrary.PromptDialog;
  36. import okhttp3.Call;
  37. import okhttp3.Callback;
  38. import okhttp3.Response;
  39. public class RportPDFActivity extends MvpActivity<VnDetailPresenter> implements VnDetailContract.View, View.OnClickListener {
  40. //产品信息
  41. //左边
  42. @BindView(R.id.tv_left_info_01)
  43. TextView left_info_01;
  44. @BindView(R.id.tv_left_info_02)
  45. TextView left_info_02;
  46. @BindView(R.id.tv_left_info_03)
  47. TextView left_info_03;
  48. @BindView(R.id.tv_left_info_04)
  49. TextView left_info_04;
  50. //右边
  51. @BindView(R.id.tv_right_info_01)
  52. TextView right_info_01;
  53. @BindView(R.id.tv_right_info_02)
  54. TextView right_info_02;
  55. @BindView(R.id.tv_right_info_03)
  56. TextView right_info_03;
  57. @BindView(R.id.tv_right_info_04)
  58. TextView right_info_04;
  59. //报告编号
  60. @BindView(R.id.tv_pdf_number)
  61. TextView pdf_number;
  62. //报告时间
  63. @BindView(R.id.tv_pdf_time)
  64. TextView pdf_time;
  65. //报告状态
  66. @BindView(R.id.iv_pdf_state)
  67. ImageView pdf_state;
  68. //二维码
  69. @BindView(R.id.iv_pdf_QR_code)
  70. ImageView pdf_QR_code;
  71. //map图片
  72. @BindView(R.id.iv_map_image)
  73. ImageView map_image;
  74. @BindView(R.id.iv_locaion)
  75. ImageView map_location;
  76. @BindView(R.id.tv_address)
  77. TextView map_address;
  78. //标题
  79. @BindView(R.id.tv_pdf_title)
  80. TitleBar pdf_title;
  81. //布局
  82. @BindView(R.id.ll_all_layoout)
  83. LinearLayout all_layout;
  84. //报警状态
  85. private boolean isWarning = true;
  86. //数据详情
  87. private VnDetailBean.DataBean chipModel = null;
  88. //状态
  89. private int status;
  90. private double lng = 0.0;
  91. private double lat = 0.0;
  92. private static final int ERROR = 1;
  93. private static final int SUCCESS = 2;
  94. private String address;
  95. //下载权限
  96. static final String[] PERMISSION = new String[]{
  97. Manifest.permission.WRITE_EXTERNAL_STORAGE,
  98. Manifest.permission.READ_EXTERNAL_STORAGE,
  99. };
  100. private String nextbtn;
  101. private PromptDialog promptDialog;
  102. @Override
  103. protected void onCreate(Bundle savedInstanceState) {
  104. super.onCreate(savedInstanceState);
  105. // setContentView(R.layout.activity_rport_p_d_f);
  106. ButterKnife.bind(this); //必须要这一句,不然会出现奔溃
  107. promptDialog = new PromptDialog(this);
  108. promptDialog.showLoading("数据加载中");
  109. }
  110. @Override
  111. protected int getLayoutId() {
  112. return R.layout.activity_rport_p_d_f;
  113. }
  114. @Override
  115. protected int getTitleId() {
  116. return R.id.tv_pdf_title;
  117. }
  118. @Override
  119. protected void initView() {
  120. Intent intent = getIntent();
  121. if (intent != null) {
  122. chipModel = (VnDetailBean.DataBean) intent.getSerializableExtra("dataBean");
  123. isWarning = intent.getBooleanExtra("isWarning", true);
  124. status = intent.getIntExtra("status", 0);
  125. nextbtn = intent.getStringExtra("nextbtn");
  126. }
  127. }
  128. @Override
  129. protected void initData() {
  130. pdf_title.setOnTitleBarListener(new OnTitleBarListener() {
  131. @Override
  132. public void onLeftClick(View v) {
  133. //判断数据来源
  134. finish();
  135. }
  136. @Override
  137. public void onTitleClick(View v) {
  138. }
  139. @Override
  140. public void onRightClick(View v) {
  141. //下载pdf报告
  142. // requestCemera();
  143. DownloadPDF.requestCemera(getActivity(), all_layout);
  144. }
  145. });
  146. //页面赋值
  147. setViewData();
  148. }
  149. @Override
  150. public void onClick(View v) {
  151. }
  152. /**
  153. * 显示详细信息
  154. */
  155. @SuppressLint("SetTextI18n")
  156. private void setViewData() {
  157. pdf_number.setText("报告编号:" + chipModel.getCodeX()); //报告编号
  158. pdf_time.setText("报告日期:" + chipModel.getDatetime()); //时间
  159. //左边
  160. left_info_01.setText(TextUtils.isEmpty(chipModel.getVaccineName()) ? "N/A" : chipModel.getVaccineName()); //商品名称
  161. left_info_02.setText(TextUtils.isEmpty(chipModel.getVaccineCommonName()) ? "N/A" : chipModel.getVaccineCommonName()); //通用名称
  162. left_info_03.setText(TextUtils.isEmpty(chipModel.getFactoryName()) ? "N/A" : chipModel.getFactoryName()); //生产企业名称
  163. left_info_04.setText(TextUtils.isEmpty(chipModel.getVaccineExpiryDate()) ? "N/A" : chipModel.getVaccineExpiryDate() + "个月"); //有效期
  164. //右边
  165. right_info_01.setText(TextUtils.isEmpty(chipModel.getVaccineCategory()) ? "N/A" : chipModel.getVaccineCategory()); //规格
  166. right_info_02.setText(TextUtils.isEmpty(chipModel.getStandardCode()) ? "N/A" : chipModel.getStandardCode()); //药品本位码
  167. right_info_03.setText(TextUtils.isEmpty(chipModel.getApprovalNumber()) ? "N/A" : chipModel.getApprovalNumber()); //药品批准文号
  168. right_info_04.setText(TextUtils.isEmpty(chipModel.getIdentificationCode()) ? "N/A" : chipModel.getIdentificationCode()); //国家药品标识码
  169. //报警状态
  170. if (isWarning == true) {
  171. pdf_state.setImageResource(R.mipmap.pdf_image_warning);
  172. } else {
  173. pdf_state.setImageResource(R.mipmap.pdf_image_adopt);
  174. }
  175. //获取地图信息图片
  176. setMapInfo();
  177. }
  178. /**
  179. * 展示地图
  180. */
  181. private void setMapInfo() {
  182. //获取经纬度
  183. gpsToLocation();
  184. }
  185. private void gpsToLocation() {
  186. String location[] = SPUtils.get("LOCATION", "").toString().split(",");
  187. Double latitude = null;
  188. Double longitude = null;
  189. if (location.length > 1) {
  190. latitude = Double.parseDouble(location[0]);
  191. longitude = Double.parseDouble(location[1]);
  192. }
  193. //经纬度GPS转高得地图
  194. String url = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=" + longitude + "," + latitude + "&coordsys=gps&key=166b0ac8c36df284fc779fd662237017";
  195. Log.e("url", url);
  196. HttpUtils.doGet(url, new Callback() {
  197. @Override
  198. public void onFailure(Call call, IOException e) {
  199. // toast(errorMsg);
  200. }
  201. @Override
  202. public void onResponse(Call call, Response response) throws IOException {
  203. String asd = response.body().string();
  204. try {
  205. JSONObject jsonObject = new JSONObject(asd);
  206. if (jsonObject.getString("info").equals("ok")) {
  207. String locations = jsonObject.getString("locations");
  208. // SPUtils.put("LOCATIONS", locations);
  209. // return locations;
  210. //
  211. getAddressInfo(locations);
  212. }
  213. } catch (JSONException e) {
  214. e.printStackTrace();
  215. }
  216. }
  217. });
  218. }
  219. /**
  220. * 根据经纬度逆地理查询地址
  221. *
  222. * @param locations
  223. */
  224. private void getAddressInfo(String locations) {
  225. String url = "https://restapi.amap.com/v3/geocode/regeo?&location=" + locations + "&key=166b0ac8c36df284fc779fd662237017";
  226. Log.e("url", url);
  227. HttpUtils.doGet(url, new Callback() {
  228. @Override
  229. public void onFailure(Call call, IOException e) {
  230. // toast(errorMsg);
  231. }
  232. @Override
  233. public void onResponse(Call call, Response response) throws IOException {
  234. String asd = response.body().string();
  235. try {
  236. JSONObject jsonObject = new JSONObject(asd);
  237. if (jsonObject.getString("status").equals("1")) {
  238. // address = jsonObject.getString("formatted_address");
  239. address = jsonObject.getJSONObject("regeocode").getString("formatted_address");
  240. getMapInfo(locations);
  241. }
  242. } catch (JSONException e) {
  243. e.printStackTrace();
  244. }
  245. }
  246. });
  247. }
  248. private void getMapInfo(String locations) {
  249. String url = "https://restapi.amap.com/v3/staticmap?location=" + locations + "&scale=2&zoom=14&size=512*307&key=166b0ac8c36df284fc779fd662237017";
  250. // 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";
  251. Log.e("url", url);
  252. HttpUtils.doGet(url, new Callback() {
  253. @Override
  254. public void onFailure(Call call, IOException e) {
  255. // toast(errorMsg);
  256. }
  257. @Override
  258. public void onResponse(Call call, Response response) throws IOException {
  259. Log.e("map", response.body().toString());
  260. //获取流
  261. InputStream in = response.body().byteStream();
  262. //转为bitmap
  263. Bitmap bitmap = BitmapFactory.decodeStream(in);
  264. //使用Hanlder发送消息
  265. Message msg = Message.obtain();
  266. msg.what = SUCCESS;
  267. msg.obj = bitmap;
  268. handler.sendMessage(msg);
  269. // map_image.setImageBitmap(bitmap);
  270. }
  271. });
  272. }
  273. private Handler handler = new Handler() {
  274. @SuppressLint("HandlerLeak")
  275. @Override
  276. public void handleMessage(Message msg) {
  277. switch (msg.what) {
  278. case SUCCESS:
  279. map_location.setVisibility(View.VISIBLE);
  280. if (address != null) {
  281. map_address.setVisibility(View.VISIBLE);
  282. map_address.setText(address);
  283. } else {
  284. map_address.setVisibility(View.GONE);
  285. }
  286. map_image.setImageBitmap((Bitmap) msg.obj);
  287. promptDialog.dismissImmediately();
  288. break;
  289. case ERROR:
  290. promptDialog.showError("请求超时");
  291. promptDialog.dismissImmediately();
  292. Toast.makeText(RportPDFActivity.this, "请求超时", Toast.LENGTH_SHORT).show();
  293. break;
  294. }
  295. }
  296. };
  297. @Override
  298. protected VnDetailPresenter createPresenter() {
  299. return new VnDetailPresenter();
  300. }
  301. @Override
  302. public void getDetailError(String msg) {
  303. }
  304. @Override
  305. public void getDetailSuccess(VnDetailBean data) {
  306. }
  307. @Override
  308. public void getSendMailError(String msg) {
  309. }
  310. @Override
  311. public void getSendMailSuccess(VnDetailBean data) {
  312. }
  313. @Override
  314. public void getmlistError(String msg) {
  315. }
  316. @Override
  317. public void getmlistSuccess(ModelListBean data) {
  318. }
  319. @Override
  320. public void getToReviewError(String msg) {
  321. }
  322. @Override
  323. public void getToReviewSuccess(VerificationCodeBean data) {
  324. }
  325. }