MailActivity.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package epson.scan.activity;
  2. import android.content.Intent;
  3. import android.net.Uri;
  4. import android.os.Bundle;
  5. import android.support.p000v4.media.session.PlaybackStateCompat;
  6. import android.text.Editable;
  7. import android.text.InputFilter;
  8. import android.text.TextWatcher;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.RadioGroup;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15. import epson.common.Constants;
  16. import epson.common.ExternalFileUtils;
  17. import epson.print.ActivityIACommon;
  18. import epson.print.C2135R;
  19. import epson.print.CommonDefine;
  20. import epson.print.ScanFileNumber;
  21. import epson.print.Util.EPLog;
  22. import epson.print.Util.Utils;
  23. import epson.print.fileBrower;
  24. import epson.provider.ScannedFileProvider;
  25. import epson.scan.lib.libHaru;
  26. import epson.server.utils.Define;
  27. import epson.server.utils.MyUtility;
  28. import java.io.File;
  29. import java.util.ArrayList;
  30. public class MailActivity extends ActivityIACommon implements View.OnClickListener, CommonDefine {
  31. private RadioGroup chooseFileType;
  32. /* access modifiers changed from: private */
  33. public Button clearBtn;
  34. private int count;
  35. private Intent emailIntent;
  36. private File fileAttachment;
  37. private Long fileSizeInByte;
  38. private float fileSizeInKb;
  39. /* access modifiers changed from: private */
  40. public EditText mFileName;
  41. /* access modifiers changed from: private */
  42. public String mFileType = Constants.PDF_TYPE;
  43. /* access modifiers changed from: private */
  44. public Button saveBtn;
  45. private ArrayList<String> saveFilePathArray = new ArrayList<>();
  46. private float totalFileSize = 0.0f;
  47. private Utils utils = new Utils();
  48. /* access modifiers changed from: protected */
  49. public void onCreate(Bundle bundle) {
  50. super.onCreate(bundle);
  51. setContentView((int) C2135R.layout.save_as);
  52. setActionBar((int) C2135R.string.str_btn_mail, true);
  53. this.mFileName = (EditText) findViewById(C2135R.C2137id.save_as_dialog_file_name);
  54. this.mFileName.setFilters(new InputFilter[]{new InputFilter.LengthFilter(64)});
  55. this.mFileName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  56. public void onFocusChange(View view, boolean z) {
  57. if (!z) {
  58. MailActivity.this.mFileName.extendSelection(0);
  59. MailActivity.this.mFileName.setSelection(0);
  60. }
  61. }
  62. });
  63. this.chooseFileType = (RadioGroup) findViewById(C2135R.C2137id.file_type_for_save_as);
  64. this.saveBtn = (Button) findViewById(C2135R.C2137id.save_button);
  65. this.saveBtn.setText(C2135R.string.str_btn_mail);
  66. this.saveBtn.setOnClickListener(this);
  67. this.clearBtn = (Button) findViewById(C2135R.C2137id.clear_mail_title_btn);
  68. this.clearBtn.setOnClickListener(this);
  69. this.chooseFileType.check(C2135R.C2137id.save_as_pdf_type);
  70. this.chooseFileType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  71. public void onCheckedChanged(RadioGroup radioGroup, int i) {
  72. switch (i) {
  73. case C2135R.C2137id.save_as_jpeg_type /*2131231434*/:
  74. String unused = MailActivity.this.mFileType = Constants.JPEG_TYPE;
  75. return;
  76. case C2135R.C2137id.save_as_pdf_type /*2131231435*/:
  77. String unused2 = MailActivity.this.mFileType = Constants.PDF_TYPE;
  78. return;
  79. default:
  80. return;
  81. }
  82. }
  83. });
  84. this.saveFilePathArray = getIntent().getStringArrayListExtra(Define.SAVING_FILE_PATH);
  85. this.count = ScanFileNumber.getCount(this);
  86. EditText editText = this.mFileName;
  87. editText.setText(getString(C2135R.string.f448epson) + this.utils.editNumber(this.count));
  88. for (int i = 0; i < this.saveFilePathArray.size(); i++) {
  89. this.fileAttachment = new File(this.saveFilePathArray.get(i));
  90. this.fileSizeInByte = Long.valueOf(this.fileAttachment.length());
  91. this.fileSizeInKb = (float) (this.fileSizeInByte.longValue() / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID);
  92. EPLog.m313i("Data", " " + this.fileSizeInKb);
  93. this.totalFileSize = this.totalFileSize + this.fileSizeInKb;
  94. }
  95. if (this.totalFileSize > 500.0f) {
  96. ((TextView) findViewById(C2135R.C2137id.save_as_file_size)).setText("" + MyUtility.mathRound((double) (this.totalFileSize / 1024.0f), 2) + "MB");
  97. } else {
  98. ((TextView) findViewById(C2135R.C2137id.save_as_file_size)).setText("" + MyUtility.mathRound((double) this.totalFileSize, 2) + "KB");
  99. }
  100. if (this.mFileName.getText().toString().length() > 0) {
  101. this.clearBtn.setVisibility(0);
  102. }
  103. this.mFileName.addTextChangedListener(new TextWatcher() {
  104. public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  105. }
  106. public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  107. }
  108. public void afterTextChanged(Editable editable) {
  109. if (MailActivity.this.mFileName.getText().toString().equals("")) {
  110. MailActivity.this.clearBtn.setVisibility(8);
  111. MailActivity.this.saveBtn.setEnabled(false);
  112. return;
  113. }
  114. MailActivity.this.clearBtn.setVisibility(0);
  115. MailActivity.this.saveBtn.setEnabled(true);
  116. }
  117. });
  118. }
  119. public void onClick(View view) {
  120. String str;
  121. boolean z;
  122. int id = view.getId();
  123. if (id != C2135R.C2137id.clear_mail_title_btn) {
  124. if (id == C2135R.C2137id.save_button) {
  125. if (!fileBrower.isAvailableFileName(this.mFileName.getText().toString())) {
  126. Toast.makeText(getApplicationContext(), C2135R.string.str_error_Filename, 1).show();
  127. return;
  128. }
  129. this.saveBtn.setEnabled(false);
  130. if (this.mFileType.equals(Constants.PDF_TYPE)) {
  131. str = this.mFileName.getText().toString();
  132. z = false;
  133. } else {
  134. String obj = this.mFileName.getText().toString();
  135. if (!obj.equals("EPSON" + this.utils.editNumber(this.count))) {
  136. str = this.mFileName.getText().toString();
  137. z = true;
  138. } else if (this.saveFilePathArray.size() == 1) {
  139. str = this.mFileName.getText().toString();
  140. z = false;
  141. } else {
  142. str = "EPSON";
  143. z = false;
  144. }
  145. }
  146. try {
  147. if (this.mFileType.equals(Constants.PDF_TYPE)) {
  148. libHaru libharu = new libHaru();
  149. String scannedImageDir = ExternalFileUtils.getInstance(this).getScannedImageDir();
  150. String path = new File(scannedImageDir, str + CommonDefine.FileType_PDF).getPath();
  151. libharu.createPDF(this.saveFilePathArray, path);
  152. this.emailIntent = new Intent("android.intent.action.SEND");
  153. this.fileAttachment = new File(path);
  154. Uri uriForFile = ScannedFileProvider.getUriForFile(this, this.fileAttachment);
  155. this.emailIntent = new Intent("android.intent.action.SEND");
  156. this.emailIntent.putExtra("android.intent.extra.STREAM", uriForFile);
  157. } else if (this.mFileType.equals(Constants.JPEG_TYPE)) {
  158. ArrayList arrayList = new ArrayList();
  159. this.emailIntent = new Intent("android.intent.action.SEND_MULTIPLE");
  160. int i = this.count;
  161. ExternalFileUtils.getInstance(this).createTempFolder(ExternalFileUtils.getInstance(this).getScannedImageDir());
  162. if (this.saveFilePathArray.size() == 1) {
  163. this.fileAttachment = MyUtility.createTempFile(this, this.saveFilePathArray.get(0), str + ".jpg");
  164. arrayList.add(ScannedFileProvider.getUriForFile(this, this.fileAttachment));
  165. } else {
  166. if (z) {
  167. i = 1;
  168. }
  169. for (int i2 = 0; i2 < this.saveFilePathArray.size(); i2++) {
  170. this.fileAttachment = MyUtility.createTempFile(this, this.saveFilePathArray.get(i2), str + this.utils.editNumber(i) + ".jpg");
  171. i++;
  172. arrayList.add(ScannedFileProvider.getUriForFile(this, this.fileAttachment));
  173. }
  174. }
  175. this.emailIntent.putParcelableArrayListExtra("android.intent.extra.STREAM", arrayList);
  176. }
  177. this.emailIntent.setType("message/rfc822");
  178. this.emailIntent.putExtra("android.intent.extra.SUBJECT", getString(C2135R.string.app_name));
  179. this.emailIntent.putExtra("android.intent.extra.TEXT", getString(C2135R.string.using_Epson_iPrint));
  180. startActivityForResult(Intent.createChooser(this.emailIntent, "Send mail..."), 1);
  181. return;
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. }
  185. } else {
  186. return;
  187. }
  188. }
  189. this.mFileName.setText("");
  190. }
  191. /* access modifiers changed from: protected */
  192. public void onActivityResult(int i, int i2, Intent intent) {
  193. super.onActivityResult(i, i2, intent);
  194. if (i == 1 && i2 == 0) {
  195. setResult(-1);
  196. finish();
  197. }
  198. this.saveBtn.setEnabled(true);
  199. }
  200. }