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