├── .gitignore
├── AndroidManifest.xml
├── README.md
├── demo.gif
├── ic_launcher-web.png
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── defalut_img.png
│ ├── ic_sticker_10.png
│ ├── ic_sticker_11.png
│ ├── ic_sticker_12.png
│ ├── ic_sticker_13.png
│ ├── ic_sticker_14.png
│ ├── ic_sticker_2.png
│ ├── ic_sticker_3.png
│ ├── ic_sticker_4.png
│ ├── ic_sticker_5.png
│ ├── ic_sticker_6.png
│ ├── ic_sticker_7.png
│ ├── ic_sticker_8.png
│ ├── ic_sticker_9.png
│ ├── move_scale_content_border.xml
│ ├── move_scale_content_no_border.xml
│ ├── move_scale_image_bias_btn.png
│ └── move_scale_image_delete_btn.png
├── layout
│ └── activity_main.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ └── strings.xml
└── src
└── com
└── oo
├── movescaleviewdemo
└── MainActivity.java
└── view
├── CanvasLayout.java
└── MoveScaleRotateView.java
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | gen/
3 | .classpath
4 | .project
5 | .settings/
6 | .idea/
7 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IDE
2 | Build On Android Studio.
3 |
4 | # Sample
5 | 
6 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/demo.gif
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/ic_launcher-web.png
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/defalut_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/defalut_img.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_10.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_11.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_12.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_13.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_14.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_2.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_3.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_4.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_5.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_6.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_7.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_8.png
--------------------------------------------------------------------------------
/res/drawable/ic_sticker_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/ic_sticker_9.png
--------------------------------------------------------------------------------
/res/drawable/move_scale_content_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
--------------------------------------------------------------------------------
/res/drawable/move_scale_content_no_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
--------------------------------------------------------------------------------
/res/drawable/move_scale_image_bias_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/move_scale_image_bias_btn.png
--------------------------------------------------------------------------------
/res/drawable/move_scale_image_delete_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrawlerChaos/MoveScaleRotateView/4886a62d05bbeac1b88a0dd5c8c278845241a374/res/drawable/move_scale_image_delete_btn.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | MoveScaleViewDemo
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/oo/movescaleviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.oo.movescaleviewdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 | import android.widget.Button;
8 |
9 | import com.oo.view.CanvasLayout;
10 |
11 | public class MainActivity extends Activity {
12 | public CanvasLayout canvas_layout;
13 | private Button addImage;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | canvas_layout = (CanvasLayout)findViewById(R.id.canvas_layout);
20 | addImage = (Button)findViewById(R.id.addImage);
21 | addImage.setOnClickListener(new OnClickListener() {
22 |
23 | @Override
24 | public void onClick(View arg0) {
25 | canvas_layout.addMSRView(null);
26 | }
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/oo/view/CanvasLayout.java:
--------------------------------------------------------------------------------
1 | package com.oo.view;
2 |
3 | import com.oo.movescaleviewdemo.R;
4 |
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.widget.AbsoluteLayout;
11 |
12 | @SuppressWarnings("deprecation")
13 | public class CanvasLayout extends AbsoluteLayout{
14 |
15 | private MoveScaleRotateView moveScaleView;
16 | public MoveScaleRotateView onFocusView;
17 | private static final int MIN_MARGIN_DP = 30;
18 | private Context context;
19 |
20 | public CanvasLayout(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | this.context = context;
23 | }
24 |
25 | private Bitmap scaleBitmap(View parent,Bitmap bitmap,Context context){
26 | float density = context.getResources().getDisplayMetrics().density;
27 | int maxWidth = (int)(parent.getWidth() - density * (MIN_MARGIN_DP * 2 + MoveScaleRotateView.IMAGE_MARGIN * 2 + MoveScaleRotateView.BUTTON_SIZE));
28 | int maxHeigth = (int)(parent.getHeight() - density * (MIN_MARGIN_DP * 2 + MoveScaleRotateView.IMAGE_MARGIN * 2 + MoveScaleRotateView.BUTTON_SIZE));
29 | if(maxWidth < bitmap.getWidth() || maxHeigth < bitmap.getHeight()){
30 | float widthRatio = bitmap.getWidth() * 1.0f / maxWidth;
31 | float heightRatio = bitmap.getHeight() * 1.0f / maxHeigth ;
32 | float ratio = widthRatio > heightRatio ? widthRatio : heightRatio;
33 | bitmap = Bitmap.createScaledBitmap(bitmap,(int)(bitmap.getWidth() / ratio), (int)(bitmap.getHeight() / ratio), true);
34 | }
35 | return bitmap;
36 | }
37 |
38 | public void addMSRView(Bitmap bitmap) {
39 | if (bitmap == null) {
40 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.defalut_img);
41 | }
42 | bitmap = scaleBitmap(this, bitmap, context);
43 | moveScaleView = new MoveScaleRotateView(context,this);
44 | if (onFocusView != null) {
45 | onFocusView.unfocus();
46 | onFocusView = null;
47 | }
48 | onFocusView = moveScaleView;
49 | AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 0);
50 |
51 | moveScaleView.setLayoutParams(layoutParams);
52 | moveScaleView.setImage(bitmap);
53 | int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
54 | int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
55 | moveScaleView.measure(w, h);
56 | int viewHeight = moveScaleView.getMeasuredHeight();
57 | int viewWidth = moveScaleView.getMeasuredWidth();
58 |
59 | layoutParams.x = (getWidth() - viewWidth) / 2;
60 | layoutParams.y = (getHeight() - viewHeight) / 2;
61 | addView(moveScaleView);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/oo/view/MoveScaleRotateView.java:
--------------------------------------------------------------------------------
1 | package com.oo.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Point;
6 | import android.util.DisplayMetrics;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 | import android.widget.AbsoluteLayout;
10 | import android.widget.ImageView;
11 | import android.widget.ImageView.ScaleType;
12 | import android.widget.RelativeLayout;
13 |
14 | import com.oo.movescaleviewdemo.R;
15 |
16 |
17 |
18 | @SuppressWarnings("deprecation")
19 | public class MoveScaleRotateView extends AbsoluteLayout {
20 |
21 | public final static int IMAGE_MARGIN = 10;
22 | public final static int BUTTON_SIZE = 30;
23 | private ImageView delete_btn,bias_btn,image;
24 | private RelativeLayout content_layout;
25 | private Point center;
26 | private int location[] = new int[2];
27 | private LayoutParams move_scale_layout_params,delete_params,bias_params,content_params;
28 | private RelativeLayout.LayoutParams image_params;
29 | private DisplayMetrics displayMetrics;
30 | private int size_btn,image_width,imgae_height,content_margin,image_margin;
31 | private ButtonTouchLisener buttonTouchLisener;
32 | private int startX,startY,endX,endY,deltaX,deltaY;
33 | private float angle,startA,endA;
34 | private double startR,endR,ratioRY,ratioRX;
35 | private int moveScaleViewTop,moveScaleViewBottom,moveScaleViewRight,moveScaleViewLeft;
36 | private int moveScaleWidth,moveScaleHeight;
37 | private CanvasLayout parent;
38 | private float anglePauseDelta = 3.0f;
39 | private boolean isFocus;
40 |
41 | public MoveScaleRotateView(Context context,CanvasLayout parent) {
42 | super(context);
43 | init(context,parent);
44 | }
45 |
46 |
47 | void init(Context context,CanvasLayout parent){
48 | this.parent = parent;
49 | content_layout = new RelativeLayout(context);
50 | image = new ImageView(context);
51 | delete_btn = new ImageView(context);
52 | bias_btn = new ImageView(context);
53 | displayMetrics = context.getResources().getDisplayMetrics();
54 | angle = 0.0f;
55 | buttonTouchLisener = new ButtonTouchLisener();
56 | size_btn = Math.round(BUTTON_SIZE * displayMetrics.density);
57 | content_margin = Math.round(BUTTON_SIZE * displayMetrics.density / 2);
58 | image_margin = Math.round(IMAGE_MARGIN * displayMetrics.density);
59 | }
60 |
61 | public void setImage(Bitmap bitmap){
62 | image_width = bitmap.getWidth();
63 | imgae_height = bitmap.getHeight();
64 | move_scale_layout_params = (LayoutParams)this.getLayoutParams();
65 | move_scale_layout_params.height = size_btn + imgae_height + image_margin * 2;
66 | move_scale_layout_params.width = size_btn + image_width + image_margin * 2;
67 | ratioRY = move_scale_layout_params.height / Math.hypot(move_scale_layout_params.width,move_scale_layout_params.height);
68 | ratioRX =move_scale_layout_params.width / Math.hypot(move_scale_layout_params.width,move_scale_layout_params.height);
69 | addContent(bitmap);
70 | addButton();
71 | setLisener();
72 | reLocationChildView();
73 | }
74 |
75 |
76 | void addContent(Bitmap bitmap){
77 | content_params = new LayoutParams(image_margin * 2 + image_width, image_margin * 2 + imgae_height,content_margin,content_margin);
78 | image_params = new RelativeLayout.LayoutParams(image_width, imgae_height);
79 |
80 | image_params.leftMargin = image_margin;
81 | image_params.rightMargin = image_margin;
82 | image_params.topMargin = image_margin;
83 | image_params.bottomMargin = image_margin;
84 | image.setImageBitmap(bitmap);
85 | image.setScaleType(ScaleType.FIT_CENTER);
86 | content_layout.setBackgroundResource(R.drawable.move_scale_content_border);
87 | content_layout.addView(image, image_params);
88 | this.addView(content_layout, content_params);
89 | }
90 |
91 | private void addButton(){
92 | delete_params = new LayoutParams(size_btn, size_btn,0,imgae_height + image_margin * 2);
93 | bias_params = new LayoutParams(size_btn, size_btn,image_width + image_margin * 2,0);
94 | delete_btn.setImageResource(R.drawable.move_scale_image_delete_btn);
95 | bias_btn.setImageResource(R.drawable.move_scale_image_bias_btn);
96 | bias_btn.setLayoutParams(bias_params);
97 | delete_btn.setLayoutParams(delete_params);
98 | this.addView(bias_btn);
99 | this.addView(delete_btn);
100 | }
101 |
102 | private void setLisener(){
103 | bias_btn.setClickable(true);
104 | image.setClickable(true);
105 | bias_btn.setOnTouchListener(buttonTouchLisener);
106 | image.setOnTouchListener(buttonTouchLisener);
107 | image.setOnClickListener(new OnClickListener() {
108 |
109 | @Override
110 | public void onClick(View v) {
111 | if (parent.onFocusView != MoveScaleRotateView.this || !isFocus) {
112 | if (parent.onFocusView != null)
113 | parent.onFocusView.unfocus();
114 | focus();
115 | }
116 | }
117 | });
118 | delete_btn.setOnClickListener(new OnClickListener() {
119 |
120 | @Override
121 | public void onClick(View arg0) {
122 | parent.removeView(MoveScaleRotateView.this);
123 | }
124 | });
125 | }
126 |
127 | private void moveOrScale(View view,int scaleX,int scaleY,int translationX,int translationY,float rotation){
128 |
129 | if (view == bias_btn) {
130 | setRotation(getAngleByPauseDelta(rotation));
131 | if ( moveScaleViewBottom - moveScaleViewTop +scaleY * 2 < size_btn * 2) {
132 | return ;
133 | }else {
134 | layout(moveScaleViewLeft-scaleX, moveScaleViewTop-scaleY, moveScaleViewRight+scaleX, moveScaleViewBottom+scaleY);
135 | }
136 | } else if (view == image) {
137 | layout(moveScaleViewLeft+translationX, moveScaleViewTop+translationY, moveScaleViewRight+translationX, moveScaleViewBottom+translationY);
138 | }
139 | reLocationChildView();
140 | }
141 |
142 | private void reLocationChildView(){
143 | moveScaleWidth = getWidth();
144 | moveScaleHeight = getHeight();
145 | delete_btn.layout(0,moveScaleHeight-size_btn,size_btn,moveScaleHeight);
146 | bias_btn.layout(moveScaleWidth-size_btn,0,moveScaleWidth,size_btn);
147 | content_layout.layout(content_margin, content_margin, moveScaleWidth-content_margin, moveScaleHeight-content_margin);
148 | image.layout(image_margin, image_margin, content_layout.getWidth()-image_margin, content_layout.getHeight()-image_margin);
149 |
150 | }
151 |
152 | private void saveParmas(){
153 | move_scale_layout_params = (LayoutParams)this.getLayoutParams();
154 | delete_params = (LayoutParams)delete_btn.getLayoutParams();
155 | bias_params = (LayoutParams)bias_btn.getLayoutParams();
156 | content_params = (LayoutParams)content_layout.getLayoutParams();
157 | image_params = (RelativeLayout.LayoutParams)image.getLayoutParams();
158 |
159 | move_scale_layout_params.height = getBottom() - getTop();
160 | move_scale_layout_params.width = getRight() - getLeft();
161 | move_scale_layout_params.x = getLeft();
162 | move_scale_layout_params.y = getTop();
163 |
164 | delete_params.width = delete_btn.getRight() - delete_btn.getLeft();
165 | delete_params.height = delete_btn.getBottom() - delete_btn.getTop();
166 | delete_params.x = delete_btn.getLeft();
167 | delete_params.y = delete_btn.getTop();
168 |
169 |
170 | bias_params.width = bias_btn.getRight() - bias_btn.getLeft();
171 | bias_params.height = bias_btn.getBottom() - bias_btn.getTop();
172 | bias_params.x = bias_btn.getLeft();
173 | bias_params.y = bias_btn.getTop();
174 |
175 | content_params.width = content_layout.getRight() - content_layout.getLeft();
176 | content_params.height = content_layout.getBottom() - content_layout.getTop();
177 | content_params.x = content_layout.getLeft();
178 | content_params.y = content_layout.getTop();
179 |
180 | image_params.width = image.getRight() - image.getLeft();
181 | image_params.height = image.getBottom() - image.getTop();
182 |
183 |
184 | }
185 |
186 | private void setCenter(){
187 | if (center == null) {
188 | center = new Point();
189 | }
190 | ((View)getParent()).getLocationOnScreen(location);
191 | center.x = location[0] + (moveScaleViewRight + moveScaleViewLeft) / 2;
192 | center.y = location[1] + (moveScaleViewBottom + moveScaleViewTop) / 2;
193 | }
194 |
195 | public void focus(){
196 | delete_btn.setVisibility(View.VISIBLE);
197 | bias_btn.setVisibility(View.VISIBLE);
198 | content_layout.setBackgroundResource(R.drawable.move_scale_content_border);
199 | parent.removeView(this);
200 | parent.addView(this);
201 | parent.onFocusView = this;
202 | isFocus = true;
203 |
204 | }
205 |
206 | public void unfocus(){
207 | delete_btn.setVisibility(View.INVISIBLE);
208 | bias_btn.setVisibility(View.INVISIBLE);
209 | content_layout.setBackgroundResource(R.drawable.move_scale_content_no_border);
210 | isFocus = false;
211 | }
212 |
213 | private class ButtonTouchLisener implements OnTouchListener{
214 |
215 | @Override
216 | public boolean onTouch(View arg0, MotionEvent arg1) {
217 |
218 | if (parent.onFocusView != null && parent.onFocusView != MoveScaleRotateView.this) {
219 | return false;
220 | }
221 |
222 | switch (arg1.getAction()) {
223 | case MotionEvent.ACTION_DOWN:
224 | moveScaleViewTop = MoveScaleRotateView.this.getTop();
225 | moveScaleViewBottom = MoveScaleRotateView.this.getBottom();
226 | moveScaleViewRight = MoveScaleRotateView.this.getRight();
227 | moveScaleViewLeft = MoveScaleRotateView.this.getLeft();
228 | setCenter();
229 | startX = (int)arg1.getRawX();
230 | startY = (int)arg1.getRawY();
231 | deltaX = startX - center.x;
232 | deltaY = startY - center.y;
233 | startR = Math.hypot(deltaX,deltaY);
234 | startA = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
235 | angle = getRotation();
236 | break;
237 |
238 | case MotionEvent.ACTION_MOVE:
239 | endX = (int)arg1.getRawX();
240 | endY = (int)arg1.getRawY();
241 | deltaX = endX - center.x;
242 | deltaY = endY - center.y;
243 | endA = (float) Math.toDegrees(Math.atan2(deltaY, deltaX));
244 | endR = Math.hypot(deltaX,deltaY);
245 | deltaX = (int)(ratioRX * (endR - startR));
246 | deltaY = (int)(ratioRY * (endR - startR));
247 | moveOrScale(arg0,deltaX,deltaY,endX - startX,endY - startY,endA - startA + angle);
248 | invalidate();
249 | break;
250 | case MotionEvent.ACTION_UP:
251 | saveParmas();
252 | break;
253 |
254 | default:
255 | break;
256 | }
257 | return false;
258 | }
259 |
260 | }
261 |
262 | private float getAngleByPauseDelta(float delta){
263 | if (Math.abs(delta % 90) < anglePauseDelta) {
264 | return delta - delta % 90;
265 | } else if (Math.abs(delta % 90) > 90 - anglePauseDelta) {
266 | if (delta > 0) {
267 | return ((int)(delta / 90) + 1) * 90;
268 | } else
269 | return ((int)(delta / 90) - 1) * 90;
270 | } else
271 | return delta;
272 | }
273 |
274 | }
275 |
--------------------------------------------------------------------------------