DocumentSizeEditActivity.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. package com.epson.cameracopy.ui;
  2. import android.content.res.Configuration;
  3. import android.os.Bundle;
  4. import android.os.SystemClock;
  5. import android.view.Menu;
  6. import android.view.MenuItem;
  7. import android.view.MotionEvent;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.RadioGroup;
  12. import android.widget.TextView;
  13. import com.epson.cameracopy.printlayout.DocumentSizeInfo;
  14. import com.epson.cameracopy.printlayout.RegistedDocumentSizeList;
  15. import java.math.BigDecimal;
  16. import epson.print.ActivityIACommon;
  17. import epson.print.widgets.LongTapRepeatAdapter;
  18. /* renamed from: com.epson.cameracopy.ui.DocumentSizeEditActivity */
  19. public class DocumentSizeEditActivity extends ActivityIACommon implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
  20. private final double RATIO_INCHTOMM = 25.4d;
  21. private final double SIZE_INCH_MAX = 39.37d;
  22. private final double SIZE_INCH_MIN = 0.1d;
  23. private final int SIZE_MM_MAX = 1000;
  24. private final int SIZE_MM_MIN = 1;
  25. DocumentSizeInfo mDocumentSizeInfo;
  26. private double mHeight;
  27. private Button mHeightDec;
  28. private Button mHeightInc;
  29. private TextView mHeightText;
  30. private boolean mInch = false;
  31. int mPosition;
  32. private RadioGroup mScale;
  33. private double mWidth;
  34. private Button mWidthDec;
  35. private Button mWidthInc;
  36. private TextView mWidthText;
  37. protected void onCreate(Bundle bundle) {
  38. super.onCreate(bundle);
  39. setContentView(R.layout.activity_document_size_edit);
  40. setActionBar(R.string.document_size_edit_title, true);
  41. mScale = (RadioGroup) findViewById(R.id.document_size_scale);
  42. mScale.setOnCheckedChangeListener(this);
  43. mWidthText = (TextView) findViewById(R.id.width);
  44. mWidthDec = (Button) findViewById(R.id.width_dec_button);
  45. mWidthDec.setOnClickListener(this);
  46. mWidthInc = (Button) findViewById(R.id.width_inc_button);
  47. mWidthInc.setOnClickListener(this);
  48. mHeightText = (TextView) findViewById(R.id.height);
  49. mHeightDec = (Button) findViewById(R.id.height_dec_button);
  50. mHeightDec.setOnClickListener(this);
  51. mHeightInc = (Button) findViewById(R.id.height_inc_button);
  52. mHeightInc.setOnClickListener(this);
  53. LongTapRepeatAdapter.bless(mWidthDec);
  54. LongTapRepeatAdapter.bless(mWidthInc);
  55. LongTapRepeatAdapter.bless(mHeightDec);
  56. LongTapRepeatAdapter.bless(mHeightInc);
  57. setDocumentSize();
  58. }
  59. protected void onPause() {
  60. super.onPause();
  61. if (isFinishing()) {
  62. deleteLongTapMessage();
  63. }
  64. }
  65. public void onClick(View view) {
  66. switch (view.getId()) {
  67. case R.id.height_dec_button /*2131231100*/:
  68. decHeight();
  69. return;
  70. case R.id.height_inc_button /*2131231101*/:
  71. incHeight();
  72. return;
  73. case R.id.width_dec_button /*2131231633*/:
  74. decWidth();
  75. return;
  76. case R.id.width_inc_button /*2131231634*/:
  77. incWidth();
  78. return;
  79. default:
  80. return;
  81. }
  82. }
  83. public void onCheckedChanged(RadioGroup radioGroup, int i) {
  84. if (i != -1) {
  85. if (i == R.id.inch_button) {
  86. mInch = true;
  87. convertDocumentSize();
  88. } else if (i == R.id.mm_button) {
  89. mInch = false;
  90. convertDocumentSize();
  91. }
  92. }
  93. radioGroup.invalidate();
  94. }
  95. private void setDocumentSize() {
  96. mDocumentSizeInfo = (DocumentSizeInfo) getIntent().getParcelableExtra("DocumentSize");
  97. mPosition = getIntent().getIntExtra("DocumentSizePos", -1);
  98. ((EditText) findViewById(R.id.et_document_size)).setText(mDocumentSizeInfo.getDocSizeName(this));
  99. mInch = mDocumentSizeInfo.getScaleId() == 2;
  100. if (mInch) {
  101. mScale.check(R.id.inch_button);
  102. mWidth = mDocumentSizeInfo.getWidth();
  103. double roundDownValue = getRoundDownValue(mWidth, 1);
  104. TextView textView = mWidthText;
  105. textView.setText(String.valueOf(roundDownValue) + " in");
  106. mHeight = mDocumentSizeInfo.getHeight();
  107. double roundDownValue2 = getRoundDownValue(mHeight, 1);
  108. TextView textView2 = mHeightText;
  109. textView2.setText(String.valueOf(roundDownValue2) + " in");
  110. return;
  111. }
  112. mScale.check(R.id.mm_button);
  113. mWidth = mDocumentSizeInfo.getWidth();
  114. TextView textView3 = mWidthText;
  115. textView3.setText(String.valueOf(getRoundDownValue(mWidth, 0)) + " mm");
  116. mHeight = mDocumentSizeInfo.getHeight();
  117. TextView textView4 = mHeightText;
  118. textView4.setText(String.valueOf(getRoundDownValue(mHeight, 0)) + " mm");
  119. }
  120. private void decWidth() {
  121. if (mInch) {
  122. mWidth = decDouble(mWidth, 0.1d);
  123. if (mWidth < 0.1d) {
  124. mWidth = 0.1d;
  125. }
  126. double roundDownValue = getRoundDownValue(mWidth, 1);
  127. TextView textView = mWidthText;
  128. textView.setText(String.valueOf(roundDownValue) + " in");
  129. mWidth = roundDownValue;
  130. return;
  131. }
  132. mWidth = decDouble(mWidth, 1.0d);
  133. if (mWidth < 1.0d) {
  134. mWidth = 1.0d;
  135. }
  136. int roundDownValue2 = getRoundDownValue(mWidth, 0);
  137. TextView textView2 = mWidthText;
  138. textView2.setText(String.valueOf(roundDownValue2) + " mm");
  139. mWidth = roundDownValue2;
  140. }
  141. private void incWidth() {
  142. if (mInch) {
  143. mWidth = incDouble(mWidth, 0.1d);
  144. if (mWidth > 39.37d) {
  145. mWidth = 39.37d;
  146. }
  147. double roundDownValue = getRoundDownValue(mWidth, 1);
  148. TextView textView = mWidthText;
  149. textView.setText(String.valueOf(roundDownValue) + " in");
  150. mWidth = roundDownValue;
  151. return;
  152. }
  153. mWidth = incDouble(mWidth, 1.0d);
  154. if (mWidth > 1000.0d) {
  155. mWidth = 1000.0d;
  156. }
  157. int roundDownValue2 = getRoundDownValue(mWidth, 0);
  158. TextView textView2 = mWidthText;
  159. textView2.setText(String.valueOf(roundDownValue2) + " mm");
  160. mWidth = roundDownValue2;
  161. }
  162. private void decHeight() {
  163. if (mInch) {
  164. mHeight = decDouble(mHeight, 0.1d);
  165. if (mHeight < 0.1d) {
  166. mHeight = 0.1d;
  167. }
  168. double roundDownValue = getRoundDownValue(mHeight, 1);
  169. TextView textView = mHeightText;
  170. textView.setText(String.valueOf(roundDownValue) + " in");
  171. return;
  172. }
  173. mHeight = decDouble(mHeight, 1.0d);
  174. if (mHeight < 1.0d) {
  175. mHeight = 1.0d;
  176. }
  177. int roundDownValue2 = getRoundDownValue(mHeight, 0);
  178. TextView textView2 = mHeightText;
  179. textView2.setText(String.valueOf(roundDownValue2) + " mm");
  180. mHeight = roundDownValue2;
  181. }
  182. private void incHeight() {
  183. if (mInch) {
  184. mHeight = incDouble(mHeight, 0.1d);
  185. if (mHeight > 39.37d) {
  186. mHeight = 39.37d;
  187. }
  188. double roundDownValue = getRoundDownValue(mHeight, 1);
  189. TextView textView = mHeightText;
  190. textView.setText(String.valueOf(roundDownValue) + " in");
  191. mHeight = roundDownValue;
  192. return;
  193. }
  194. mHeight = incDouble(mHeight, 1.0d);
  195. if (mHeight > 1000.0d) {
  196. mHeight = 1000.0d;
  197. }
  198. int roundDownValue2 = getRoundDownValue(mHeight, 0);
  199. TextView textView2 = mHeightText;
  200. textView2.setText(String.valueOf(roundDownValue2) + " mm");
  201. mHeight = roundDownValue2;
  202. }
  203. private void convertDocumentSize() {
  204. if (mInch) {
  205. mWidth /= 25.4d;
  206. double d = mWidth;
  207. if (d < 0.1d) {
  208. d = 0.1d;
  209. }
  210. mWidth = d;
  211. double roundDownValue = getRoundDownValue(mWidth, 1);
  212. mWidthText.setText(String.valueOf(roundDownValue) + " in");
  213. mWidth = roundDownValue;
  214. mHeight = mHeight / 25.4d;
  215. double d2 = mHeight;
  216. if (d2 < 0.1d) {
  217. d2 = 0.1d;
  218. }
  219. mHeight = d2;
  220. double roundDownValue2 = getRoundDownValue(mHeight, 1);
  221. mHeightText.setText(String.valueOf(roundDownValue2) + " in");
  222. mHeight = roundDownValue2;
  223. return;
  224. }
  225. mWidth *= 25.4d;
  226. double d3 = mWidth;
  227. if (d3 > 1000.0d) {
  228. d3 = 1000.0d;
  229. }
  230. mWidth = d3;
  231. int roundDownValue3 = getRoundDownValue(mWidth, 0);
  232. mWidthText.setText(String.valueOf(roundDownValue3) + " mm");
  233. mWidth = roundDownValue3;
  234. mHeight = mHeight * 25.4d;
  235. double d4 = mHeight;
  236. if (d4 > 1000.0d) {
  237. d4 = 1000.0d;
  238. }
  239. mHeight = d4;
  240. int roundDownValue4 = getRoundDownValue(mHeight, 0);
  241. mHeightText.setText(String.valueOf(roundDownValue4) + " mm");
  242. mHeight = roundDownValue4;
  243. }
  244. private double getRoundDownValue(double d, int i) {
  245. return new BigDecimal(String.valueOf(d)).setScale(i, 1).doubleValue();
  246. }
  247. private void checkDocumentSize() {
  248. String obj = ((EditText) findViewById(R.id.et_document_size)).getText().toString();
  249. if (obj.isEmpty()) {
  250. SimpleMessageDialogFragment.newInstance(R.string.no_name_documentsize_message).show(getSupportFragmentManager(), "error-dialog");
  251. return;
  252. }
  253. mDocumentSizeInfo.setDocSizeName(obj);
  254. mDocumentSizeInfo.setScaleId(mInch ? 2 : 1);
  255. mDocumentSizeInfo.setWidth(getRoundDownValue(mWidth, 1));
  256. mDocumentSizeInfo.setHeight(getRoundDownValue(mHeight, 1));
  257. RegistedDocumentSizeList instance = RegistedDocumentSizeList.getInstance(this);
  258. if (instance.isExistDocumentSizeName(obj, mPosition)) {
  259. SimpleMessageDialogFragment.newInstance(R.string.exist_documentsize_message).show(getSupportFragmentManager(), "error-dialog");
  260. return;
  261. }
  262. int i = mPosition;
  263. if (i < 0) {
  264. instance.add(mDocumentSizeInfo);
  265. finish();
  266. return;
  267. }
  268. instance.update(mDocumentSizeInfo, i);
  269. finish();
  270. }
  271. private double incDouble(double d, double d2) {
  272. return new BigDecimal(String.valueOf(d)).add(new BigDecimal(String.valueOf(d2))).doubleValue();
  273. }
  274. private double decDouble(double d, double d2) {
  275. return new BigDecimal(String.valueOf(d)).subtract(new BigDecimal(String.valueOf(d2))).doubleValue();
  276. }
  277. public boolean onCreateOptionsMenu(Menu menu) {
  278. if (mDocumentSizeInfo.getPaperId() == -2) {
  279. getMenuInflater().inflate(R.menu.menu_done, menu);
  280. }
  281. return super.onCreateOptionsMenu(menu);
  282. }
  283. public boolean onOptionsItemSelected(MenuItem menuItem) {
  284. if (menuItem.getItemId() != R.id.menuSettingsDone) {
  285. return super.onOptionsItemSelected(menuItem);
  286. }
  287. checkDocumentSize();
  288. return true;
  289. }
  290. protected void deleteLongTapMessage() {
  291. MotionEvent obtain = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis() + 10, 1, 0.0f, 0.0f, 0);
  292. mWidthDec.dispatchTouchEvent(obtain);
  293. mWidthInc.dispatchTouchEvent(obtain);
  294. mHeightDec.dispatchTouchEvent(obtain);
  295. mHeightInc.dispatchTouchEvent(obtain);
  296. }
  297. public void onConfigurationChanged(Configuration configuration) {
  298. super.onConfigurationChanged(configuration);
  299. deleteLongTapMessage();
  300. }
  301. }