ScanBaseView.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. package epson.scan.activity;
  2. import android.content.Context;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.graphics.Canvas;
  6. import android.graphics.DashPathEffect;
  7. import android.graphics.Paint;
  8. import android.graphics.Path;
  9. import android.graphics.Point;
  10. import android.graphics.Rect;
  11. import android.graphics.RectF;
  12. import android.os.Build;
  13. import android.os.Handler;
  14. import android.view.MotionEvent;
  15. import android.view.View;
  16. import android.widget.EditText;
  17. import java.util.ArrayList;
  18. import java.util.Locale;
  19. import epson.common.Constants;
  20. import epson.common.Utils;
  21. import epson.print.ActivityIACommon;
  22. import epson.print.R;
  23. import epson.print.Util.EPLog;
  24. import epson.scan.lib.escanLib;
  25. public class ScanBaseView extends ActivityIACommon {
  26. public static int SCAN_AREA_HOTSPOT_SIZE = 40;
  27. private static final int SCAN_REDRAWBITMAP = -100;
  28. private static final String TAG = "ScanBaseView";
  29. public final int LINE_AREA_BORDER = 2;
  30. public final int LINE_CORNER_BIG = 18;
  31. public final int LINE_CORNER_BIG_WIDTH = 150;
  32. public final int LINE_CORNER_SMALL = 6;
  33. public final int LINE_CORNER_SMALL_WIDTH = 60;
  34. public final int MARGIN_LEFT_RIGHT = 10;
  35. public int MARGIN_TOP_BOT = 60;
  36. final int MAX_DASHEFFECT_PHASE;
  37. public final int SCREEN_STATUS_BOTLEFT_TOPRIGHT = 2;
  38. public final int SCREEN_STATUS_BOTRIGHT_TOPLEFT = 3;
  39. public final int SCREEN_STATUS_TOPLEFT_BOTRIGHT = 1;
  40. public final int SCREEN_STATUS_TOPRIGHT_BOTLEFT = 4;
  41. private BitmapFactory.Options _bmOption;
  42. public boolean bLongTouch = false;
  43. public Bitmap bmCenter;
  44. private RectF bmRectF;
  45. Context context;
  46. int curentViewingFile;
  47. escanLib escan;
  48. private PointInfo first;
  49. private int inSampleSize;
  50. private boolean isDisplayResult;
  51. public boolean isDoctable = false;
  52. private boolean isSetSize = false;
  53. private boolean isValidArea;
  54. private ArrayList<String> listSavedJPGFilePath;
  55. private Point mBaseBot;
  56. private Point mBaseTop;
  57. private Bitmap mBitmap;
  58. Point mBot;
  59. Point mCenter;
  60. Point mFirstTouch;
  61. private Paint mPaint;
  62. Point mTop;
  63. Point mTouch;
  64. int mWhere;
  65. private double maxScanHeightOnScreen = 0.0d;
  66. private double maxScanWidthOnScreen = 0.0d;
  67. private int maxheight = 0;
  68. private int maxwidth = 0;
  69. int phase;
  70. private PointInfo piBaseBot;
  71. private PointInfo piBaseTop;
  72. private RectF rectScanArea;
  73. private double scale;
  74. private int screenStatus = 1;
  75. private PointInfo second;
  76. int totalScanned;
  77. class PointInfo {
  78. /* access modifiers changed from: private */
  79. /* renamed from: x */
  80. public double f411x = 0.0d;
  81. /* access modifiers changed from: private */
  82. /* renamed from: y */
  83. public double f412y = 0.0d;
  84. public PointInfo(double d, double d2) {
  85. f411x = d;
  86. f412y = d2;
  87. }
  88. public double getX() {
  89. return f411x;
  90. }
  91. public void setX(double d) {
  92. f411x = d;
  93. }
  94. public double getY() {
  95. return f412y;
  96. }
  97. public void setY(double d) {
  98. f412y = d;
  99. }
  100. public String toString() {
  101. return String.format(Locale.US, "(%.2f,%.2f)", new Object[]{Double.valueOf(this.f411x), Double.valueOf(this.f412y)});
  102. }
  103. }
  104. public PointInfo getPiBaseTop() {
  105. return piBaseTop;
  106. }
  107. public void setPiBaseTop(PointInfo pointInfo) {
  108. piBaseTop = pointInfo;
  109. }
  110. public PointInfo getPiBaseBot() {
  111. return piBaseBot;
  112. }
  113. public void setPiBaseBot(PointInfo pointInfo) {
  114. piBaseBot = pointInfo;
  115. }
  116. public Context getContext() {
  117. return context;
  118. }
  119. public void setContext(Context context2) {
  120. context = context2;
  121. }
  122. public Point getmBaseTop() {
  123. return mBaseTop;
  124. }
  125. public void setmBaseTop(Point point) {
  126. mBaseTop = point;
  127. }
  128. public Point getmBaseBot() {
  129. return mBaseBot;
  130. }
  131. public void setmBaseBot(Point point) {
  132. mBaseBot = point;
  133. }
  134. public RectF getRectScanArea() {
  135. return rectScanArea;
  136. }
  137. public void setRectScanArea(RectF rectF) {
  138. rectScanArea = rectF;
  139. }
  140. public escanLib getEscan() {
  141. return escan;
  142. }
  143. public void setEscan(escanLib escanlib) {
  144. escan = escanlib;
  145. }
  146. public double getScale() {
  147. return scale;
  148. }
  149. public void setScale(double d) {
  150. scale = d;
  151. }
  152. public int getMaxwidth() {
  153. return maxwidth;
  154. }
  155. public void setMaxwidth(int i) {
  156. maxwidth = i;
  157. }
  158. public int getMaxheight() {
  159. return maxheight;
  160. }
  161. public void setMaxheight(int i) {
  162. maxheight = i;
  163. }
  164. public Point getmTop() {
  165. return mTop;
  166. }
  167. public void setmTop(Point point) {
  168. mTop = point;
  169. }
  170. public Point getmBot() {
  171. return mBot;
  172. }
  173. public void setmBot(Point point) {
  174. mBot = point;
  175. }
  176. public Point getmCenter() {
  177. return mCenter;
  178. }
  179. public void setmCenter(Point point) {
  180. mCenter = point;
  181. }
  182. public Point getmTouch() {
  183. return mTouch;
  184. }
  185. public void setmTouch(Point point) {
  186. mTouch = point;
  187. }
  188. public Point getmFirstTouch() {
  189. return mFirstTouch;
  190. }
  191. public void setmFirstTouch(Point point) {
  192. mFirstTouch = point;
  193. }
  194. public Bitmap getBmCenter() {
  195. return bmCenter;
  196. }
  197. public void setBmCenter(Bitmap bitmap) {
  198. bmCenter = bitmap;
  199. }
  200. public int getScreenStatus() {
  201. return screenStatus;
  202. }
  203. public void setScreenStatus(int i) {
  204. screenStatus = i;
  205. }
  206. public BitmapFactory.Options get_bmOption() {
  207. return _bmOption;
  208. }
  209. public void set_bmOption(BitmapFactory.Options options) {
  210. _bmOption = options;
  211. }
  212. public int getInSampleSize() {
  213. return inSampleSize;
  214. }
  215. public void setInSampleSize(int i) {
  216. inSampleSize = i;
  217. }
  218. public boolean isSetSize() {
  219. return isSetSize;
  220. }
  221. public void setSetSize(boolean z) {
  222. isSetSize = z;
  223. }
  224. public RectF getBmRectF() {
  225. return bmRectF;
  226. }
  227. public void setBmRectF(RectF rectF) {
  228. bmRectF = rectF;
  229. }
  230. public Bitmap getBm() {
  231. return mBitmap;
  232. }
  233. public void setBm(Bitmap bitmap) {
  234. mBitmap = bitmap;
  235. }
  236. public int getmWhere() {
  237. return mWhere;
  238. }
  239. public void setmWhere(int i) {
  240. mWhere = i;
  241. }
  242. public Paint getmPaint() {
  243. return mPaint;
  244. }
  245. public void setmPaint(Paint paint) {
  246. mPaint = paint;
  247. }
  248. public void setListSavedJPGFilePath(ArrayList<String> arrayList) {
  249. listSavedJPGFilePath = arrayList;
  250. }
  251. public ArrayList<String> getListSavedJPGFilePath() {
  252. return listSavedJPGFilePath;
  253. }
  254. public double getMaxScanHeightOnScreen() {
  255. return maxScanHeightOnScreen;
  256. }
  257. public void setMaxScanHeightOnScreen(double d) {
  258. maxScanHeightOnScreen = d;
  259. }
  260. public double getMaxScanWidthOnScreen() {
  261. return maxScanWidthOnScreen;
  262. }
  263. public void setMaxScanWidthOnScreen(double d) {
  264. maxScanWidthOnScreen = d;
  265. }
  266. public ScanBaseView() {
  267. piBaseTop = new PointInfo(0.0d, 0.0d);
  268. piBaseBot = new PointInfo(0.0d, 0.0d);
  269. mBaseTop = new Point();
  270. mBaseBot = new Point();
  271. mTop = new Point();
  272. mBot = new Point();
  273. mCenter = new Point();
  274. mTouch = new Point();
  275. mFirstTouch = new Point();
  276. curentViewingFile = 1;
  277. totalScanned = 0;
  278. mWhere = 2;
  279. first = new PointInfo(0.0d, 0.0d);
  280. second = new PointInfo(0.0d, 0.0d);
  281. isValidArea = false;
  282. isDisplayResult = false;
  283. phase = 0;
  284. mAX_DASHEFFECT_PHASE = 1000;
  285. escan = new escanLib();
  286. escan.setJobDone(false);
  287. _bmOption = new BitmapFactory.Options();
  288. if (mPaint == null) {
  289. mPaint = new Paint();
  290. mPaint.setStrokeWidth(2.0f);
  291. mPaint.setColor(ViewCompat.MEASURED_STATE_MASK);
  292. }
  293. listSavedJPGFilePath = new ArrayList<>();
  294. }
  295. public void setupScanArea() {
  296. double unused = first.f411x = Math.min(this.piBaseTop.f411x, piBaseBot.f411x);
  297. double unused2 = first.f412y = Math.min(this.piBaseTop.f412y, piBaseBot.f412y);
  298. double unused3 = second.f411x = Math.max(this.piBaseTop.f411x, piBaseBot.f411x);
  299. double unused4 = second.f412y = Math.max(this.piBaseTop.f412y, piBaseBot.f412y);
  300. if (this.first.f411x < (getmBaseTop().x)) {
  301. double unused5 = first.f411x = getmBaseTop().x;
  302. }
  303. if (this.first.f412y < (getmBaseTop().y)) {
  304. double unused6 = first.f412y = getmBaseTop().y;
  305. }
  306. if (this.second.f411x > (getmBaseBot().x)) {
  307. double unused7 = second.f411x = getmBaseBot().x;
  308. }
  309. if (this.second.f412y > (getmBaseBot().y)) {
  310. double unused8 = second.f412y = getmBaseBot().y;
  311. }
  312. if (this.second.f411x <= (getmBaseTop().x) || first.f411x >= (getmBaseBot().x) || second.f412y <= (getmBaseTop().y) || first.f412y >= (getmBaseBot().y)) {
  313. isValidArea = false;
  314. } else {
  315. isValidArea = true;
  316. }
  317. escan.setOffsetX(Math.max((Math.abs(this.first.f411x - (getmBaseTop().x)) * (getMaxwidth())) / getMaxScanWidthOnScreen(), 0.0d));
  318. escan.setOffsetY(Math.max((Math.abs(this.first.f412y - (getmBaseTop().y)) * (getMaxheight())) / getMaxScanHeightOnScreen(), 0.0d));
  319. int min = Math.min((Math.abs(this.first.f411x - second.f411x) * (getMaxwidth())) / getMaxScanWidthOnScreen(), (getMaxwidth() - escan.getOffsetX()));
  320. int min2 = Math.min((Math.abs(this.first.f412y - second.f412y) * (getMaxheight())) / getMaxScanHeightOnScreen(), (getMaxheight() - escan.getOffsetY()));
  321. if (min == 0) {
  322. escanLib escanlib = escan;
  323. escanlib.setOffsetX(escanlib.getOffsetX() - 1);
  324. min = 1;
  325. }
  326. if (min2 == 0) {
  327. escanLib escanlib2 = escan;
  328. escanlib2.setOffsetY(escanlib2.getOffsetY() - 1);
  329. min2 = 1;
  330. }
  331. escan.setScanAreaWidth(min);
  332. escan.setScanAreaHeight(min2);
  333. if (Utils.getPrefInt(this.context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_2SIDED) == 1 || !this.isDoctable) {
  334. escan.setOffsetX(Utils.getPrefInt(getContext(), Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_MAX_WIDTH) - min);
  335. }
  336. rectScanArea = new RectF((float) (Math.max(this.first.f411x, getmBaseTop().x)), (float) (Math.max(this.first.f412y, getmBaseTop().y)), (float) (Math.min(this.second.f411x, getmBaseBot().x)), (float) (Math.min(this.second.f412y, getmBaseBot().y)));
  337. }
  338. public Point calculateTheCenterPoint(Point point, Point point2) {
  339. Point point3 = new Point();
  340. point3.x = Math.min(point.x, point2.x) + Math.round((float) (Math.abs(point.x - point2.x) / 2));
  341. point3.y = Math.min(point.y, point2.y) + Math.round((float) (Math.abs(point.y - point2.y) / 2));
  342. return point3;
  343. }
  344. public boolean isValidArea() {
  345. return isValidArea;
  346. }
  347. public void setValidArea(boolean z) {
  348. isValidArea = z;
  349. }
  350. class ScanAreaSet extends View {
  351. private Point _pBaseBottomRight;
  352. private Point _pBaseCenter;
  353. private Point _pBaseTopLeft;
  354. int _touchtime = 0;
  355. public Handler redrawCBHandler = null;
  356. public ScanAreaSet(Context context) {
  357. super(context);
  358. ScanBaseView.SCAN_AREA_HOTSPOT_SIZE = ((((float) ScanBaseView.SCAN_AREA_HOTSPOT_SIZE) * getResources().getDisplayMetrics().density) + 0.5f);
  359. }
  360. protected void onSizeChanged(int i, int i2, int i3, int i4) {
  361. super.onSizeChanged(i, i2, i3, i4);
  362. }
  363. protected void onDraw(Canvas canvas) {
  364. super.onDraw(canvas);
  365. if (ScanBaseView.this.bLongTouch && ScanBaseView.mWhere != 2) {
  366. invalidate();
  367. ScanBaseView.this.phase += 2;
  368. if (ScanBaseView.this.phase > 1000) {
  369. ScanBaseView.this.phase = 0;
  370. }
  371. }
  372. drawScanArea(canvas);
  373. Handler handler = redrawCBHandler;
  374. if (handler != null) {
  375. handler.sendEmptyMessage(-100);
  376. }
  377. }
  378. private synchronized void drawScanArea(Canvas canvas) {
  379. _pBaseTopLeft = ScanBaseView.this.getmTop();
  380. _pBaseBottomRight = ScanBaseView.this.getmBot();
  381. if (!ScanBaseView.this.isDisplayResult && ScanBaseView.this.getBm() != null) {
  382. if (Build.VERSION.SDK_INT >= 14) {
  383. EPLog.i("drawScanArea", "14");
  384. Bitmap bm = ScanBaseView.this.getBm();
  385. RectF bmRectF = ScanBaseView.this.getBmRectF();
  386. Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bm, bmRectF.width(), bmRectF.height(), true);
  387. ScanBaseView.this.setBm(createScaledBitmap);
  388. canvas.drawBitmap(createScaledBitmap, ScanBaseView.this.getBmRectF().left, ScanBaseView.this.getBmRectF().top, (Paint) null);
  389. } else {
  390. canvas.drawBitmap(ScanBaseView.this.getBm(), (Rect) null, ScanBaseView.this.getBmRectF(), ScanBaseView.this.getmPaint());
  391. }
  392. }
  393. if (ScanBaseView.this.isDoctable) {
  394. if (ScanBaseView.this.isSetSize) {
  395. drawNormalCorner(canvas);
  396. _pBaseCenter = ScanBaseView.this.getmCenter();
  397. }
  398. Paint paint = new Paint();
  399. if (!ScanBaseView.this.bLongTouch || ScanBaseView.mWhere == 2) {
  400. Paint paint2 = ScanBaseView.this.getmPaint();
  401. canvas.drawLine((float) _pBaseTopLeft.x, (float) _pBaseTopLeft.y, (float) _pBaseBottomRight.x, (float) _pBaseTopLeft.y, paint2);
  402. canvas.drawLine((float) _pBaseBottomRight.x, (float) _pBaseTopLeft.y, (float) _pBaseBottomRight.x, (float) _pBaseBottomRight.y, paint2);
  403. canvas.drawLine((float) _pBaseBottomRight.x, (float) _pBaseBottomRight.y, (float) _pBaseTopLeft.x, (float) _pBaseBottomRight.y, paint2);
  404. canvas.drawLine((float) _pBaseTopLeft.x, (float) _pBaseBottomRight.y, (float) _pBaseTopLeft.x, (float) _pBaseTopLeft.y, paint2);
  405. } else {
  406. Path path = new Path();
  407. path.addRect((float) _pBaseTopLeft.x, (float) _pBaseTopLeft.y, (float) _pBaseBottomRight.x, (float) _pBaseBottomRight.y, Path.Direction.CW);
  408. paint.setPathEffect(new DashPathEffect(new float[]{10.0f, 2.0f}, (float) ScanBaseView.this.phase));
  409. paint.setStrokeWidth(1.5f);
  410. paint.setStyle(Paint.Style.STROKE);
  411. canvas.drawPath(path, paint);
  412. }
  413. if (ScanBaseView.this.bLongTouch) {
  414. drawTheCornerImage(canvas, ScanBaseView.this.getmPaint());
  415. } else {
  416. drawNormalCorner(canvas);
  417. }
  418. }
  419. if (ScanBaseView.this.isSetSize) {
  420. ScanBaseView.this.setupScanArea();
  421. ScanBaseView.this.setSetSize(false);
  422. }
  423. }
  424. private void drawTheCornerImage(Canvas canvas, Paint paint) {
  425. switch (ScanBaseView.this.screenStatus) {
  426. case 1:
  427. int i = ScanBaseView.mWhere;
  428. if (i != -1) {
  429. if (i == 1) {
  430. drawCornerTopLeft(canvas, _pBaseTopLeft);
  431. drawCornerBotRightMoving(canvas, _pBaseBottomRight);
  432. break;
  433. } else {
  434. drawCornerTopLeft(canvas, _pBaseTopLeft);
  435. drawCornerBotRight(canvas, _pBaseBottomRight);
  436. break;
  437. }
  438. } else {
  439. drawCornerTopLeftMoving(canvas, _pBaseTopLeft);
  440. drawCornerBotRight(canvas, _pBaseBottomRight);
  441. break;
  442. }
  443. case 2:
  444. int i2 = ScanBaseView.mWhere;
  445. if (i2 != -1) {
  446. if (i2 == 1) {
  447. drawCornerBotLeft(canvas, _pBaseTopLeft);
  448. drawCornerTopRightMoving(canvas, _pBaseBottomRight);
  449. break;
  450. } else {
  451. drawCornerBotLeft(canvas, _pBaseTopLeft);
  452. drawCornerTopRight(canvas, _pBaseBottomRight);
  453. break;
  454. }
  455. } else {
  456. drawCornerBotLeftMoving(canvas, _pBaseTopLeft);
  457. drawCornerTopRight(canvas, _pBaseBottomRight);
  458. break;
  459. }
  460. case 3:
  461. int i3 = ScanBaseView.mWhere;
  462. if (i3 != -1) {
  463. if (i3 == 1) {
  464. drawCornerBotRight(canvas, _pBaseTopLeft);
  465. drawCornerTopLeftMoving(canvas, _pBaseBottomRight);
  466. break;
  467. } else {
  468. drawCornerBotRight(canvas, _pBaseTopLeft);
  469. drawCornerTopLeft(canvas, _pBaseBottomRight);
  470. break;
  471. }
  472. } else {
  473. drawCornerBotRightMoving(canvas, _pBaseTopLeft);
  474. drawCornerTopLeft(canvas, _pBaseBottomRight);
  475. break;
  476. }
  477. case 4:
  478. int i4 = ScanBaseView.mWhere;
  479. if (i4 != -1) {
  480. if (i4 == 1) {
  481. drawCornerTopRight(canvas, _pBaseTopLeft);
  482. drawCornerBotLeftMoving(canvas, _pBaseBottomRight);
  483. break;
  484. } else {
  485. drawCornerTopRight(canvas, _pBaseTopLeft);
  486. drawCornerBotLeft(canvas, _pBaseBottomRight);
  487. break;
  488. }
  489. } else {
  490. drawCornerTopRightMoving(canvas, _pBaseTopLeft);
  491. drawCornerBotLeft(canvas, _pBaseBottomRight);
  492. break;
  493. }
  494. }
  495. if (ScanBaseView.this.bLongTouch) {
  496. String localClassName = ScanBaseView.this.getLocalClassName();
  497. EPLog.i(localClassName, "mWhere = " + ScanBaseView.mWhere);
  498. if (ScanBaseView.mWhere == 0 && ScanBaseView.this.bmCenter == null) {
  499. ScanBaseView.this.bmCenter = BitmapFactory.decodeResource(getResources(), R.drawable.area_center, ScanBaseView.this._bmOption);
  500. }
  501. if (ScanBaseView.this.bmCenter != null) {
  502. if (this._pBaseCenter == null) {
  503. _pBaseCenter = ScanBaseView.this.getmCenter();
  504. }
  505. if (ScanBaseView.this.inSampleSize != 0) {
  506. canvas.drawBitmap(ScanBaseView.this.bmCenter, (float) (this._pBaseCenter.x - ((ScanBaseView.this.bmCenter.getWidth() / 2) * ScanBaseView.this.getInSampleSize())), (float) (this._pBaseCenter.y - ((ScanBaseView.this.bmCenter.getHeight() / 2) * ScanBaseView.this.getInSampleSize())), (Paint) null);
  507. } else {
  508. canvas.drawBitmap(ScanBaseView.this.bmCenter, (float) (this._pBaseCenter.x - (ScanBaseView.this.bmCenter.getWidth() / 2)), (float) (this._pBaseCenter.y - (ScanBaseView.this.bmCenter.getHeight() / 2)), (Paint) null);
  509. }
  510. }
  511. }
  512. }
  513. public boolean onTouchEvent(MotionEvent motionEvent) {
  514. if (!ScanBaseView.this.isDoctable) {
  515. return true;
  516. }
  517. Point point = new Point(motionEvent.getX(), motionEvent.getY());
  518. ScanBaseView.this.setmTouch(point);
  519. ScanBaseView.this.detectTheScreenStatus();
  520. switch (motionEvent.getAction()) {
  521. case 0:
  522. ScanBaseView.this.setmWhere(2);
  523. ScanBaseView.this.detectTheTouchPoint();
  524. ScanBaseView.this.setmFirstTouch(point);
  525. break;
  526. case 1:
  527. ScanBaseView.this.setmWhere(2);
  528. ScanBaseView.this.setBmCenter((Bitmap) null);
  529. ScanBaseView scanBaseView = ScanBaseView.this;
  530. scanBaseView.phase = 0;
  531. _touchtime = 0;
  532. scanBaseView.setupScanArea();
  533. ScanBaseView.this.bLongTouch = false;
  534. break;
  535. case 2:
  536. if (ScanBaseView.this.bLongTouch) {
  537. moveTheTouchPoint();
  538. break;
  539. }
  540. break;
  541. default:
  542. return false;
  543. }
  544. postInvalidate();
  545. return true;
  546. }
  547. public void moveTheTouchPoint() {
  548. switch (ScanBaseView.this.getmWhere()) {
  549. case -1:
  550. _pBaseTopLeft = ScanBaseView.this.getmTouch();
  551. _pBaseCenter = ScanBaseView.this.calculateTheCenterPoint(this._pBaseTopLeft, _pBaseBottomRight);
  552. break;
  553. case 0:
  554. moveCenter();
  555. ScanBaseView.this.setmCenter(this._pBaseCenter);
  556. break;
  557. case 1:
  558. _pBaseBottomRight = ScanBaseView.this.getmTouch();
  559. _pBaseCenter = ScanBaseView.this.calculateTheCenterPoint(this._pBaseTopLeft, _pBaseBottomRight);
  560. break;
  561. }
  562. ScanBaseView.this.setmTop(this._pBaseTopLeft);
  563. ScanBaseView.this.setmBot(this._pBaseBottomRight);
  564. ScanBaseView scanBaseView = ScanBaseView.this;
  565. scanBaseView.setPiBaseTop(new PointInfo(_pBaseTopLeft.x, _pBaseTopLeft.y));
  566. ScanBaseView scanBaseView2 = ScanBaseView.this;
  567. scanBaseView2.setPiBaseBot(new PointInfo(_pBaseBottomRight.x, _pBaseBottomRight.y));
  568. ScanBaseView.this.setmCenter(this._pBaseCenter);
  569. }
  570. private void moveCenter() {
  571. Point point = ScanBaseView.this.getmFirstTouch();
  572. Point point2 = ScanBaseView.this.getmTouch();
  573. int i = point2.x - point.x;
  574. int i2 = point2.y - point.y;
  575. _pBaseTopLeft.x += i;
  576. _pBaseTopLeft.y += i2;
  577. _pBaseBottomRight.x += i;
  578. _pBaseBottomRight.y += i2;
  579. _pBaseCenter.x += i;
  580. _pBaseCenter.y += i2;
  581. ScanBaseView.this.setmFirstTouch(point2);
  582. }
  583. private void drawNormalCorner(Canvas canvas) {
  584. switch (ScanBaseView.this.screenStatus) {
  585. case 2:
  586. drawCornerBotLeft(canvas, ScanBaseView.mTop);
  587. drawCornerTopRight(canvas, ScanBaseView.mBot);
  588. return;
  589. case 3:
  590. drawCornerBotRight(canvas, ScanBaseView.mTop);
  591. drawCornerTopLeft(canvas, ScanBaseView.mBot);
  592. return;
  593. case 4:
  594. drawCornerTopRight(canvas, ScanBaseView.mTop);
  595. drawCornerBotLeft(canvas, ScanBaseView.mBot);
  596. return;
  597. default:
  598. drawCornerTopLeft(canvas, ScanBaseView.mTop);
  599. drawCornerBotRight(canvas, ScanBaseView.mBot);
  600. return;
  601. }
  602. }
  603. private void drawCornerTopLeft(Canvas canvas, Point point) {
  604. Canvas canvas2 = canvas;
  605. canvas2.drawRect((float) (point.x - 6), (float) (point.y - 6), (float) ((point.x - 6) + 60), (float) point.y, ScanBaseView.this.getmPaint());
  606. canvas2.drawRect((float) (point.x - 6), (float) (point.y - 6), (float) point.x, (float) ((point.y - 6) + 60), ScanBaseView.this.getmPaint());
  607. }
  608. private void drawCornerBotRight(Canvas canvas, Point point) {
  609. Canvas canvas2 = canvas;
  610. canvas2.drawRect((float) ((point.x + 6) - 60), (float) point.y, (float) (point.x + 6), (float) (point.y + 6), ScanBaseView.this.getmPaint());
  611. canvas2.drawRect((float) point.x, (float) ((point.y + 6) - 60), (float) (point.x + 6), (float) (point.y + 6), ScanBaseView.this.getmPaint());
  612. }
  613. private void drawCornerBotLeft(Canvas canvas, Point point) {
  614. Canvas canvas2 = canvas;
  615. canvas2.drawRect((float) (point.x - 6), (float) point.y, (float) ((point.x - 6) + 60), (float) (point.y + 6), ScanBaseView.this.getmPaint());
  616. canvas2.drawRect((float) (point.x - 6), (float) ((point.y + 6) - 60), (float) point.x, (float) (point.y + 6), ScanBaseView.this.getmPaint());
  617. }
  618. private void drawCornerTopRight(Canvas canvas, Point point) {
  619. Canvas canvas2 = canvas;
  620. canvas2.drawRect((float) ((point.x + 6) - 60), (float) (point.y - 6), (float) (point.x + 6), (float) point.y, ScanBaseView.this.getmPaint());
  621. canvas2.drawRect((float) point.x, (float) (point.y - 6), (float) (point.x + 6), (float) ((point.y - 6) + 60), ScanBaseView.this.getmPaint());
  622. }
  623. private void drawCornerTopLeftMoving(Canvas canvas, Point point) {
  624. Canvas canvas2 = canvas;
  625. canvas2.drawRect((float) (point.x - 18), (float) (point.y - 18), (float) ((point.x - 18) + 150), (float) point.y, ScanBaseView.this.getmPaint());
  626. canvas2.drawRect((float) (point.x - 18), (float) (point.y - 18), (float) point.x, (float) ((point.y - 18) + 150), ScanBaseView.this.getmPaint());
  627. }
  628. private void drawCornerBotRightMoving(Canvas canvas, Point point) {
  629. Canvas canvas2 = canvas;
  630. canvas2.drawRect((float) ((point.x + 18) - 150), (float) point.y, (float) (point.x + 18), (float) (point.y + 18), ScanBaseView.this.getmPaint());
  631. canvas2.drawRect((float) point.x, (float) ((point.y + 18) - 150), (float) (point.x + 18), (float) (point.y + 18), ScanBaseView.this.getmPaint());
  632. }
  633. private void drawCornerBotLeftMoving(Canvas canvas, Point point) {
  634. Canvas canvas2 = canvas;
  635. canvas2.drawRect((float) (point.x - 18), (float) point.y, (float) ((point.x - 18) + 150), (float) (point.y + 18), ScanBaseView.this.getmPaint());
  636. canvas2.drawRect((float) (point.x - 18), (float) ((point.y + 18) - 150), (float) point.x, (float) (point.y + 18), ScanBaseView.this.getmPaint());
  637. }
  638. private void drawCornerTopRightMoving(Canvas canvas, Point point) {
  639. Canvas canvas2 = canvas;
  640. canvas2.drawRect((float) ((point.x + 18) - 150), (float) (point.y - 18), (float) (point.x + 18), (float) point.y, ScanBaseView.this.getmPaint());
  641. canvas2.drawRect((float) point.x, (float) (point.y - 18), (float) (point.x + 18), (float) ((point.y - 18) + 150), ScanBaseView.this.getmPaint());
  642. }
  643. }
  644. public void detectTheTouchPoint() {
  645. if (mTouch.x > Math.max(mTop.x, mBot.x) || mTouch.x < Math.min(mTop.x, mBot.x) || mTouch.y > Math.max(mTop.y, mBot.y) || mTouch.y < Math.min(mTop.y, mBot.y)) {
  646. EPLog.i(getLocalClassName(), "touche out");
  647. if ((Math.abs(Math.min(mTop.x, mBot.x) - mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE && Math.abs(mTouch.x - Math.max(mTop.x, mBot.x)) >= SCAN_AREA_HOTSPOT_SIZE) || (Math.abs(Math.min(mTop.y, mBot.y) - mTouch.y) >= SCAN_AREA_HOTSPOT_SIZE && Math.abs(mTouch.y - Math.max(mTop.y, mBot.y)) >= SCAN_AREA_HOTSPOT_SIZE)) {
  648. mWhere = 2;
  649. } else if (mTop.x >= mBot.x || mTop.y >= mBot.y) {
  650. if (mTop.x >= mBot.x || mTop.y <= mBot.y) {
  651. if (mTop.x <= mBot.x || mTop.y <= mBot.y) {
  652. if ((mTouch.x > mTop.x && Math.abs(mTouch.y - mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(mTop.x - mTouch.x) < SCAN_AREA_HOTSPOT_SIZE) {
  653. mWhere = -1;
  654. } else if ((mTouch.x >= mBot.x || Math.abs(mTouch.y - mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(mTouch.x - mBot.x) >= SCAN_AREA_HOTSPOT_SIZE) {
  655. mWhere = 0;
  656. } else {
  657. mWhere = 1;
  658. }
  659. } else if ((mTouch.x > mTop.x && Math.abs(mTouch.y - mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(mTop.x - mTouch.x) < SCAN_AREA_HOTSPOT_SIZE) {
  660. mWhere = -1;
  661. } else if ((mTouch.x >= mBot.x || Math.abs(mTouch.y - mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(mTouch.x - mBot.x) >= SCAN_AREA_HOTSPOT_SIZE) {
  662. mWhere = 0;
  663. } else {
  664. mWhere = 1;
  665. }
  666. } else if ((mTouch.x < mTop.x && Math.abs(mTouch.y - mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(mTouch.x - mTop.x) < SCAN_AREA_HOTSPOT_SIZE) {
  667. mWhere = -1;
  668. } else if ((mTouch.x <= mBot.x || Math.abs(mTouch.y - mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(mBot.x - mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE) {
  669. mWhere = 0;
  670. } else {
  671. mWhere = 1;
  672. }
  673. } else if ((mTouch.x < mTop.x && Math.abs(mTouch.y - mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(mTouch.x - mTop.x) < SCAN_AREA_HOTSPOT_SIZE) {
  674. mWhere = -1;
  675. } else if ((mTouch.x <= mBot.x || Math.abs(mTouch.y - mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(mBot.x - mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE) {
  676. mWhere = 0;
  677. } else {
  678. mWhere = 1;
  679. }
  680. } else {
  681. EPLog.i(getLocalClassName(), "touche in");
  682. if (mTop.x >= mBot.x || mTop.y >= mBot.y) {
  683. if (mTop.x >= mBot.x || mTop.y <= mBot.y) {
  684. if (mTop.x <= mBot.x || mTop.y <= mBot.y) {
  685. if (Math.abs(mTop.x - mTouch.x) < SCAN_AREA_HOTSPOT_SIZE && mTouch.y - mTop.y < SCAN_AREA_HOTSPOT_SIZE) {
  686. mWhere = -1;
  687. } else if (Math.abs(mTouch.x - mBot.x) >= SCAN_AREA_HOTSPOT_SIZE || mBot.y - mTouch.y >= SCAN_AREA_HOTSPOT_SIZE) {
  688. mWhere = 0;
  689. } else {
  690. mWhere = 1;
  691. }
  692. } else if (Math.abs(mTop.x - mTouch.x) < SCAN_AREA_HOTSPOT_SIZE && mTop.y - mTouch.y < SCAN_AREA_HOTSPOT_SIZE) {
  693. mWhere = -1;
  694. } else if (Math.abs(mTouch.x - mBot.x) >= SCAN_AREA_HOTSPOT_SIZE || mTouch.y - mBot.y >= SCAN_AREA_HOTSPOT_SIZE) {
  695. mWhere = 0;
  696. } else {
  697. mWhere = 1;
  698. }
  699. } else if (Math.abs(mTouch.x - mTop.x) < SCAN_AREA_HOTSPOT_SIZE && mTop.y - mTouch.y < SCAN_AREA_HOTSPOT_SIZE) {
  700. mWhere = -1;
  701. } else if (Math.abs(mBot.x - mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE || mTouch.y - mBot.y >= SCAN_AREA_HOTSPOT_SIZE) {
  702. mWhere = 0;
  703. } else {
  704. mWhere = 1;
  705. }
  706. } else if (Math.abs(mTouch.x - mTop.x) < SCAN_AREA_HOTSPOT_SIZE && mTouch.y - mTop.y < SCAN_AREA_HOTSPOT_SIZE) {
  707. mWhere = -1;
  708. } else if (Math.abs(mBot.x - mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE || mBot.y - mTouch.y >= SCAN_AREA_HOTSPOT_SIZE) {
  709. mWhere = 0;
  710. } else {
  711. mWhere = 1;
  712. }
  713. }
  714. }
  715. public void detectTheScreenStatus() {
  716. if (mTop.x < mBot.x && mTop.y < mBot.y) {
  717. screenStatus = 1;
  718. } else if (mTop.x < mBot.x && mTop.y > mBot.y) {
  719. screenStatus = 2;
  720. } else if (mTop.x <= mBot.x || mTop.y <= mBot.y) {
  721. screenStatus = 4;
  722. } else {
  723. screenStatus = 3;
  724. }
  725. }
  726. class ScanAreaBackground extends View {
  727. Paint _paint = new Paint();
  728. Paint _textPaint;
  729. boolean hideText;
  730. ScanActivity mScanActivity;
  731. String text;
  732. protected void onSizeChanged(int i, int i2, int i3, int i4) {
  733. super.onSizeChanged(i, i2, i3, i4);
  734. mScanActivity.onScanAreaSizeChange();
  735. }
  736. private void drawTextInCanvas(Canvas canvas) {
  737. String str = new String();
  738. float f = ((float) (ScanBaseView.this.getmBaseBot().x - ScanBaseView.this.getmBaseTop().x)) * 0.9f;
  739. float f2 = (float) (ScanBaseView.this.getmBaseBot().y - ScanBaseView.this.getmBaseTop().y);
  740. Rect rect = new Rect();
  741. int length = text.length();
  742. String str2 = str;
  743. int i = 0;
  744. int i2 = 0;
  745. while (i < length) {
  746. int breakText = _textPaint.breakText(this.text.substring(i, length), true, f, (float[]) null) + i;
  747. String substring = text.substring(i, breakText);
  748. _textPaint.getTextBounds(substring, 0, substring.length(), rect);
  749. i2 += rect.height();
  750. str2 = (str2 + substring) + Constants.BREAK_LINE;
  751. i = breakText;
  752. }
  753. int i3 = (((float) ScanBaseView.this.getmBaseTop().x) + (((float) (ScanBaseView.this.getmBaseBot().x - ScanBaseView.this.getmBaseTop().x)) * 0.05f));
  754. int i4 = ((((float) ScanBaseView.this.getmBaseTop().y) + (f2 / 2.0f)) - ((float) (i2 / 2)));
  755. String[] split = str2.split(Constants.BREAK_LINE);
  756. int i5 = 0;
  757. for (int i6 = 0; i6 < split.length; i6++) {
  758. canvas.drawText(split[i6], (float) i3, (float) (i4 + i5), _textPaint);
  759. _textPaint.getTextBounds(split[i6], 0, split[i6].length(), rect);
  760. i5 += rect.height();
  761. }
  762. }
  763. public void hideText(boolean z) {
  764. hideText = z;
  765. }
  766. public ScanAreaBackground(Context context) {
  767. super(context);
  768. mScanActivity = (ScanActivity) context;
  769. _paint.setColor(-1);
  770. _paint.setShadowLayer(5.5f, 6.0f, 6.0f, R.color.light_gray);
  771. _textPaint = new Paint();
  772. _textPaint.setColor(getResources().getColor(R.color.light_gray));
  773. _textPaint.setAntiAlias(true);
  774. _textPaint.setTextAlign(Paint.Align.LEFT);
  775. _textPaint.setTextSize(new EditText(getContext()).getTextSize());
  776. text = ScanBaseView.this.getString(R.string.str_msg_scan_viewbase);
  777. }
  778. protected void onDraw(Canvas canvas) {
  779. super.onDraw(canvas);
  780. drawTheDefaultBackground(canvas);
  781. }
  782. private void drawTheDefaultBackground(Canvas canvas) {
  783. canvas.drawRect((float) ScanBaseView.this.getmBaseTop().x, (float) ScanBaseView.this.getmBaseTop().y, (float) ScanBaseView.this.getmBaseBot().x, (float) ScanBaseView.this.getmBaseBot().y, _paint);
  784. if (!this.hideText) {
  785. drawTextInCanvas(canvas);
  786. }
  787. }
  788. }
  789. }