2727import android .view .Window ;
2828import android .view .animation .Animation ;
2929import android .view .animation .TranslateAnimation ;
30- import android .view .inputmethod .InputMethodManager ;
3130import android .widget .EditText ;
3231import android .widget .FrameLayout ;
3332import android .widget .ImageView ;
@@ -56,21 +55,12 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
5655 private ImageView dieluokaiguan ;
5756 private ImageView bisuokaiguan ;
5857 private ImageView huanwanggui ;
59- private ImageView fenzhixiang ;
60- private ImageView duanluqi ;
61- private ImageView fuhekaiguan ;
62- private ImageView gelikaiguan ;
63- private ImageView bianyaqi ;
64- private ImageView xiangbian ;
65- private ImageView dianlan ;
66- private ImageView dianlantou ;
58+
6759 private ImageView jiakongxian ;
6860 private ImageView rect ;
6961 private ImageView xuxian ;
70- private int mFoucsImageId = 0 ;
7162 private Set <View > mViewList = new HashSet <View >();
7263 private Set <View > mFocusViewList = new HashSet <View >();
73- //private DrawCanvasView mDrawCanvasView;
7464 private long downTime = 0 ;
7565 private float downX = 0f ;
7666 private float downY = 0f ;
@@ -89,16 +79,13 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
8979 private int mStatusBarHeight = 0 ;
9080 private FrameLayout mRootView ;
9181 private ImageView mCurrentImageView ;
92- private float rotateDegree = 0f ;
9382
9483 private Bitmap mLineBitmap ;
9584 private Bitmap mLineBitmapBlack ;
9685 private Bitmap mLineBitmapGreen ;
9786 private Bitmap mLineBitmapRed ;
9887 private Bitmap mDashLineBitmap ;
99- private Bitmap mDashLineBitmapBlack ;
100- private Bitmap mDashLineBitmapGreen ;
101- private Bitmap mDashLineBitmapRed ;
88+
10289
10390 private List <ViewInfo > mInfoList = new ArrayList <ViewInfo >();
10491 private FrameLayout mContent ;
@@ -120,7 +107,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
120107 private static final int MARGER_TOP = 107 ;
121108 private static final int PADDING = 20 ;
122109 private int mDeviceId = -1 ;
123- private InputMethodManager mInputMethodManager ;
110+
124111 private int mCurrentColor ; // 0--黑色,1--绿色,2--红色
125112 private MementoCreataker mCreataker ;
126113 private MementoOriginator mOriginator ;
@@ -130,7 +117,6 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
130117 private int mRealInfoId = 5000 ;
131118 private float mStartX ;
132119 private float mStartY ;
133- private float mRotation ;
134120 private static final int STROKE_WIDTH = 5 ;
135121
136122
@@ -151,27 +137,10 @@ protected void onCreate(Bundle savedInstanceState) {
151137
152138 RadioGroup radioGroup = (RadioGroup ) findViewById (R .id .radiogroup );
153139 radioGroup .setOnCheckedChangeListener (this );
154-
155- // mMyScrollView = (MyScrollView)findViewById(R.id.scrollView);
156- // mMyHorizontalScrollView = (MyHorizontalScrollView)findViewById(R.id.hscrollView);
157140 mContentLayoutParams = (FrameLayout .LayoutParams ) mContent .getLayoutParams ();
158141 mContentLayoutParams .width = mDisplayMetrics .widthPixels - 312 ;
159142 mContentLayoutParams .height = mDisplayMetrics .heightPixels - mStatusBarHeight - 107 ;
160143
161- // FrameLayout.LayoutParams editeTextParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
162- // mContent.setOnLongClickListener(new View.OnLongClickListener() {
163- // @Override
164- // public boolean onLongClick(View v) {
165- // return false;
166- // }
167- // });
168- // mRootView.setOnTouchListener(new View.OnTouchListener(){
169- //
170- // @Override
171- // public boolean onTouch(View v, MotionEvent event) {
172- // return true;
173- // }
174- // });
175144 mContent .setOnTouchListener (new View .OnTouchListener () {
176145 @ Override
177146 public boolean onTouch (View v , MotionEvent event ) {
@@ -263,8 +232,7 @@ public boolean onTouch(View v, MotionEvent event) {
263232 FrameLayout .LayoutParams layoutParams = new FrameLayout .LayoutParams (FrameLayout .LayoutParams .WRAP_CONTENT , FrameLayout .LayoutParams .WRAP_CONTENT );
264233 mContent .addView (editText , layoutParams );
265234 createMemento (editText , false , true );
266- if (mDeviceId == -1 )
267- mInputMethodManager .showSoftInput (editText , InputMethodManager .SHOW_IMPLICIT );
235+
268236 }
269237
270238 }
@@ -275,7 +243,7 @@ public boolean onTouch(View v, MotionEvent event) {
275243 return false ;
276244 }
277245 });
278- //mDrawCanvasView = (DrawCanvasView)findViewById(R.id.canvas_view);
246+
279247 mScaleGestureDetector = new ScaleGestureDetector (this , mScaleGestureListener );
280248 muxianjiange = (ImageView ) findViewById (R .id .allIcon );
281249 muxianjiange .setOnTouchListener (mTouchListener );
@@ -337,7 +305,7 @@ private void layoutViews() {
337305 editText .setX (viewInfo .x );
338306 editText .setY (viewInfo .y );
339307 editText .setText (text );
340- // editText.setOnTouchListener(new EditTextTouchListener(editText));
308+
341309 mViewList .add (editText );
342310 mContent .addView (editText , mDefaultEditTextParams );
343311
@@ -356,11 +324,6 @@ private void layoutViews() {
356324 setImageResource (imageView , false );
357325 if (newViewInfo .degree != 0 ) {
358326 imageView .setRotation (viewInfo .degree );
359- // imageView.setRotation(viewInfo.degree);
360- // Bitmap bitmap = getRotateBitmap(imageView, false, false);
361- // if (bitmap != null) {
362- // imageView.setImageBitmap(bitmap);
363- // }
364327 }
365328 mViewList .add (imageView );
366329 mContent .addView (imageView , mContentLayoutParams );
@@ -381,7 +344,7 @@ public void onDestroy() {
381344 mRootView .removeAllViews ();
382345
383346 recycle (mLineBitmap , mLineBitmapBlack , mLineBitmapGreen , mLineBitmapRed
384- , mDashLineBitmap , mDashLineBitmapBlack , mDashLineBitmapGreen , mDashLineBitmapRed );
347+ , mDashLineBitmap );
385348 }
386349
387350 private void recycle (Bitmap ... bitmaps ) {
@@ -432,7 +395,7 @@ public void setImageResource(ImageView v, boolean focus) {
432395 canvas .drawLine (0 , 50 , 100 , 50 , paint );
433396
434397 mLineBitmap = mLineBitmapBlack ;
435- //TODO 线条颜色有点小bug
398+
436399 if (viewInfo .color == 2 ) {
437400 mLineBitmap = mLineBitmapRed ;
438401 } else if (mCurrentColor == 1 ) {
@@ -605,10 +568,7 @@ public void onClick(View v) {
605568 view .setRotation (degree );
606569 LogUtils .d ("end x: " + view .getX () + ", y :" + view .getY ());
607570 createMemento (view , false , false );
608- // Bitmap bitmap = getRotateBitmap((ImageView) view, false);
609- // if (bitmap != null) {
610- // ((ImageView) view).setImageBitmap(bitmap);
611- // }
571+
612572 }
613573 break ;
614574 case R .id .clear :
@@ -652,7 +612,7 @@ public void onClick(View v) {
652612 break ;
653613 case R .id .done :
654614
655- Intent intent = new Intent ();
615+
656616 Bitmap bitmap = captureScreen ();
657617 FileOutputStream outputStream = null ;
658618 if (bitmap != null ) {
@@ -1101,17 +1061,17 @@ public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
11011061 case R .id .rb_black :
11021062 mCurrentColor = 0 ;
11031063 mLineBitmap = mLineBitmapBlack ;
1104- mDashLineBitmap = mDashLineBitmapBlack ;
1064+
11051065 break ;
11061066 case R .id .rb_green :
11071067 mCurrentColor = 1 ;
11081068 mLineBitmap = mLineBitmapGreen ;
1109- mDashLineBitmap = mDashLineBitmapGreen ;
1069+
11101070 break ;
11111071 case R .id .rb_red :
11121072 mCurrentColor = 2 ;
11131073 mLineBitmap = mLineBitmapRed ;
1114- mDashLineBitmap = mDashLineBitmapRed ;
1074+
11151075 break ;
11161076 default :
11171077 LogUtils .e ("default checkedId: " + checkedId , new IllegalArgumentException ());
@@ -1128,10 +1088,10 @@ public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
11281088 }
11291089
11301090
1131- class MyTouchListener implements View .OnTouchListener {
1091+ private class MyTouchListener implements View .OnTouchListener {
11321092 private ImageView imageView ;
11331093
1134- public MyTouchListener (ImageView imageView ) {
1094+ MyTouchListener (ImageView imageView ) {
11351095 this .imageView = imageView ;
11361096 }
11371097
@@ -1464,86 +1424,6 @@ public boolean onTouch(View v, MotionEvent event) {
14641424 }
14651425
14661426
1467- class EditTextTouchListener implements View .OnTouchListener {
1468-
1469- private EditText mEditText ;
1470-
1471- public EditTextTouchListener (EditText editText ) {
1472- this .mEditText = editText ;
1473- }
1474-
1475- @ Override
1476- public boolean onTouch (View v , MotionEvent event ) {
1477- int action = event .getAction ();
1478- ViewInfo viewInfo = (ViewInfo ) v .getTag ();
1479-
1480- // float downX1 = 0;
1481- // float downY1 = 0;
1482- int imageW = 0 ;
1483- int imageH = 0 ;
1484-
1485- switch (action ) {
1486- case MotionEvent .ACTION_DOWN :
1487- downTime = System .currentTimeMillis ();
1488- downX = mEditText .getX ();
1489- downY = mEditText .getY ();
1490-
1491- LogUtils .d ("ACTION_DOWN " + (int ) downX + "," + (int ) downY );
1492- return true ;
1493- case MotionEvent .ACTION_MOVE :
1494- float disX = event .getX ();
1495- float disY = event .getY ();
1496- LogUtils .i ("disX : " + (int ) disX + ", disY : " + (int ) disY );
1497-
1498- if (mFocusViewList .contains (mEditText )) {
1499- FrameLayout .LayoutParams params = (FrameLayout .LayoutParams ) mEditText .getLayoutParams ();
1500- params .width = imageW + (int ) disX ;
1501- params .height = imageH + (int ) disY ;
1502- mEditText .requestLayout ();
1503- } else { //处理图标拖动
1504- mEditText .setX (mEditText .getX () + disX );
1505- mEditText .setY (mEditText .getY () + disY );
1506- LogUtils .d ("ACTION_MOVE " + (int ) downX + "," + (int ) downY );
1507- }
1508- return true ;
1509- case MotionEvent .ACTION_UP :
1510- float x = mEditText .getX ();
1511- float y = mEditText .getY ();
1512- long time = System .currentTimeMillis () - downTime ;
1513- LogUtils .d ("ACTION_UP " + (int ) x + "," + (int ) y + " ### disTime: " + time );
1514- if (time <= 200 && Math .abs (x - downX ) < 50 && Math .abs (y - downY ) < 50 ) {
1515- mEditText .requestFocus ();
1516- if (mDeviceId == -1 )
1517- mInputMethodManager .showSoftInput (mEditText , InputMethodManager .SHOW_IMPLICIT );
1518- LogUtils .d ("聚焦" );
1519- } else {
1520- mEditText .clearFocus ();
1521- LogUtils .d ("清除焦点" );
1522- }
1523- if (x < 0 ) {
1524- x = 0 ;
1525- mEditText .setX (x );
1526- } else if (x > (mDisplayMetrics .widthPixels - 312 - 100 )) {
1527- x = mDisplayMetrics .widthPixels - 100 - 312 ;
1528- mEditText .setX (x );
1529- }
1530-
1531- if (y <= 0 ) {
1532- y = 0 ;
1533- mEditText .setY (y );
1534- } else if (y > mDisplayMetrics .heightPixels - 100 - mStatusBarHeight - 107 ) {
1535- y = mDisplayMetrics .heightPixels - 100 - mStatusBarHeight - 107 ;
1536- mEditText .setY (y );
1537- }
1538- if (mRectList != null ) {
1539- mRectList .clear ();
1540- }
1541- return true ;
1542- }
1543-
1544- return false ;
1545- }
1546- }
15471427
15481428 private void getLineCoordinate () {
15491429 mLefts .clear ();
@@ -1637,20 +1517,6 @@ public Bitmap captureScreen() {
16371517 return resultBmp ;
16381518 }
16391519
1640- // class ViewInfo {
1641- // public ViewInfo(int id, float degree) {
1642- // this.id = id;
1643- // this.degree = degree;
1644- // }
1645- //
1646- // public int id;
1647- // public float degree;
1648- // public int width;
1649- // public int height;
1650- // public int x;
1651- // public int y;
1652- //
1653- // }
16541520
16551521 private boolean inRange (Rect srcRect , Rect checkRect ) {
16561522 return srcRect .contains (checkRect );
0 commit comments