Advertisement
aberesnev

Untitled

Apr 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. private View fillTheView(final View view, final Match match, final boolean found) {
  2. TextView tv2;
  3.  
  4. new Thread(new Runnable() {
  5. @Override
  6. public void run() {
  7. final String filename = "" + match.getSubjectid() + "." + match.getPhotoIDs();
  8. if (mainActivity.restService != null && found && !new File(Utils.getPathMediaFile(mainActivity, filename)).exists()) {
  9. final Call<ResponseBody> call = mainActivity.restService.image(match.getSubjectid(), match.getPhotoIDs());
  10. call.enqueue(new Callback<ResponseBody>() {
  11. @Override
  12. public void onResponse(Call<ResponseBody> call, final Response<ResponseBody> response) {
  13. final InputStream is = response.body().byteStream();
  14.  
  15. new Thread(new Runnable() {
  16. @Override
  17. public void run() {
  18. final Bitmap bitmap = BitmapFactory.decodeStream(is);
  19. mainActivity.runOnUiThread(new Runnable() {
  20. @Override
  21. public void run() {
  22. ((ImageView) view.findViewById(R.id.profilepicture)).setImageDrawable(new BitmapDrawable(mainActivity.getResources(), bitmap));
  23. if (bitmap != null) {
  24. new Thread(new Runnable() {
  25. @Override
  26. public void run() {
  27. try {
  28. Bitmap bpm = bitmap;
  29. if (bitmap.getWidth() > 320) {
  30. final Matrix matrix = new Matrix();
  31. final Bitmap pbm = Bitmap.createBitmap(bitmap, 0, 0, 256, bitmap.getHeight() / bitmap.getWidth() * 256, matrix, true);
  32. if (pbm != bitmap) {
  33. bitmap.recycle();
  34. }
  35. bpm = pbm;
  36. }
  37. if (!bpm.isRecycled()) {
  38. bpm.compress(Bitmap.CompressFormat.JPEG, 94, new FileOutputStream(Utils.getPathMediaFile(mainActivity, filename)));
  39. }
  40. } catch (FileNotFoundException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. }).start();
  45. }
  46. }
  47. });
  48. }
  49. }).start();
  50.  
  51. }
  52.  
  53. @Override
  54. public void onFailure(Call<ResponseBody> call, Throwable t) {
  55. }
  56. });
  57. } else {
  58. try {
  59. final BitmapDrawable drawable = new BitmapDrawable(mainActivity.getResources(), Utils.getOutputMediaFileAP(mainActivity, filename));
  60. mainActivity.runOnUiThread(new Runnable() {
  61. @Override
  62. public void run() {
  63. ((ImageView) view.findViewById(R.id.profilepicture)).setImageDrawable(drawable);
  64. }
  65. });
  66. } catch (FileNotFoundException ignored) {
  67. }
  68. }
  69. }
  70. }).start();
  71.  
  72. if (match.getScannedPath() != null) {
  73. new Thread(new Runnable() {
  74. @Override
  75. public void run() {
  76. try {
  77. final BitmapDrawable drawable = new BitmapDrawable(mainActivity.getResources(), Utils.getOutputMediaFileAP(mainActivity, match.getScannedPath()));
  78. mainActivity.runOnUiThread(new Runnable() {
  79. @Override
  80. public void run() {
  81. ((ImageView) view.findViewById(R.id.subjectpicture)).setImageDrawable(drawable);
  82. if (((int)view.getTag(R.id.age)) == 2) {
  83. view.setOnClickListener(new View.OnClickListener() {
  84. @Override
  85. public void onClick(View v) {
  86. ContinuousVisionActivity.showEnrollment(mainActivity, match.getScannedPath());
  87. }
  88. });
  89. }
  90. }
  91. });
  92. } catch (FileNotFoundException e) {
  93. //e.printStackTrace();
  94. mainActivity.runOnUiThread(new Runnable() {
  95. @Override
  96. public void run() {
  97. ((ImageView) view.findViewById(R.id.subjectpicture)).setImageDrawable(null);
  98. }
  99. });
  100. }
  101. }
  102. }).start();
  103. } else {
  104. ((ImageView) view.findViewById(R.id.subjectpicture)).setImageDrawable(null);
  105. }
  106.  
  107.  
  108.  
  109. if (found) {
  110. tv2 = (TextView) view.findViewById(R.id.name);
  111. tv2.setText(match.getFirstname() + " " + match.getLastname());
  112. } else {
  113. final TextView age = (TextView)view.findViewById(R.id.age);
  114. final String ages = match.getEstage() != 0 ? ""+match.getEstage() : "unknown";
  115. age.setText(ages);
  116.  
  117. final TextView gender = (TextView)view.findViewById(R.id.gender);
  118. final String genders = match.getEstgender() != null ? match.getEstgender() : "unknown";
  119. gender.setText(genders);
  120. }
  121.  
  122. //tv2 = (TextView)view.findViewById(R.id.advanced);
  123. tv2 = (TextView)view.findViewById(R.id.created);
  124. tv2.setText("" + match.getCreated());
  125. setGpsOnClickListener(tv2, match);
  126.  
  127. return view;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement