3 import java.util.ArrayList;
6 import android.content.Context;
7 import android.graphics.Color;
8 import android.graphics.PorterDuff.Mode;
9 import android.graphics.Rect;
10 import android.util.AttributeSet;
11 import android.view.MotionEvent;
12 import android.view.View;
13 import android.view.View.OnLongClickListener;
14 import android.view.animation.Animation;
15 import android.view.animation.AnimationUtils;
16 import android.view.animation.Animation.AnimationListener;
17 import android.widget.FrameLayout;
19 public class IconFrameLayout extends FrameLayout implements OnLongClickListener {
20 private IconImageView target = null;
21 private IconImageView dest = null;
23 private Animation anime;
30 private boolean longClickFlg = false;
31 private IconScrollView scrollView;
32 private Context context = this.getContext();
34 public IconFrameLayout(Context context) {
38 public IconFrameLayout(Context context, AttributeSet attrs) {
39 super(context, attrs);
42 public IconFrameLayout(Context context, AttributeSet attrs, int defStyle) {
43 super(context, attrs, defStyle);
47 protected void onLayout(boolean changed, int left, int top, int right,
49 super.onLayout(changed, left, top, right, bottom);
51 int size = this.getChildCount();
52 for (int i = 0; i < size; i++) {
53 IconImageView vv = (IconImageView) this.getChildAt(i);
54 int x2 = vv.getInitX();
55 int y2 = vv.getInitY();
57 vv.layout(x2, y2, x2 + vv.getWidth(), y2 + vv.getHeight());
61 private View getView(int x, int y, View v, List<View> list) {
62 Rect rect = new Rect();
65 rect.left = v.getLeft();
66 rect.top = v.getTop();
67 rect.right = rect.left + v.getWidth();
68 rect.bottom = rect.top + v.getHeight();
70 if (rect.contains(x, y)) {
74 for (View view : list) {
76 rect.left = view.getLeft();
77 rect.top = view.getTop();
78 rect.right = rect.left + view.getWidth();
79 rect.bottom = rect.top + view.getHeight();
80 if (rect.contains(x, y)) {
89 public boolean onTouchEvent(MotionEvent event) {
91 if (event.getAction() == MotionEvent.ACTION_CANCEL) {
92 System.out.println("dummy");
94 int x = (int) event.getRawX();
95 int y = (int) event.getRawY();
97 x -= scrollView.getLeft();
98 y -= scrollView.getTop();
101 List<View> list = new ArrayList<View>();
102 int size = this.getChildCount();
103 for (int i = 0; i < size; i++) {
104 IconImageView v = (IconImageView) this.getChildAt(i);
107 View v = getView(x, y, target, list);
111 IconImageView obj = (IconImageView) v;
113 if (target == null) {
116 // scrollView.setOnTouchListener(new OnTouchListener() {
118 // public boolean onTouch(View v, MotionEvent event) {
122 // } else if (target != obj) {
126 return super.onTouchEvent(event);
129 this.getParent().requestDisallowInterceptTouchEvent(true);
131 if (event.getAction() == MotionEvent.ACTION_MOVE) {
137 int diffX = offsetX - x;
138 int diffY = offsetY - y;
144 obj.layout(currentX, currentY, currentX + obj.getWidth(),
145 currentY + obj.getHeight());
151 Rect rect = new Rect();
152 for (int i = 0; i < size; i++) {
153 IconImageView vv = (IconImageView) list.get(i);
155 if (rect.contains(x, y)) {
162 Rect rect = new Rect();
164 dest.getHitRect(rect);
165 if (!rect.contains(x, y)) {
170 } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
176 currentX = obj.getLeft();
177 currentY = obj.getTop();
179 target.setColorFilter(Color.RED, Mode.LIGHTEN);
181 scrollView.setScrollable(false);
183 } else if (event.getAction() == MotionEvent.ACTION_UP) {
189 obj.setAnimation(anime);
190 obj.startAnimation(anime);
191 // obj.setVisibility(View.GONE);
193 //
\8fÁ
\82·
\8fê
\8d\87
194 // layout.removeView(obj);
196 //
\83L
\83\83\83\93\83Z
\83\8b
197 int srcX = target.getInitX();
198 int srcY = target.getInitY();
199 target.layout(srcX, srcY, srcX + target.getWidth(), srcY
200 + target.getHeight());
201 target.setAlpha(255);
203 int srcX = target.getInitX();
204 int srcY = target.getInitY();
205 int dstX = dest.getInitX();
206 int dstY = dest.getInitY();
208 target.layout(dstX, dstY, dstX + target.getWidth(), dstY
209 + target.getHeight());
210 target.init(dstX, dstY);
211 target.setAlpha(255);
212 dest.layout(srcX, srcY, srcX + dest.getWidth(),
213 srcY + dest.getHeight());
214 dest.init(srcX, srcY);
218 //this.getParent().requestDisallowInterceptTouchEvent(false);
220 // bt2.getHitRect(rect);
221 // if (rect.contains(x, y)) {
222 // isBt2Click = true;
224 longClickFlg = false;
227 return super.onTouchEvent(event);
228 } catch (Exception e) {
235 public boolean onLongClick(View view) {
236 // if (!(view instanceof IconImageView)) {
239 // IconImageView v = (IconImageView) view;
240 if (target == null) {
243 IconImageView v = (IconImageView) target;
245 v.clearColorFilter();
251 public void setScrollView(final IconScrollView scrollView) {
252 this.scrollView = scrollView;
253 this.setOnLongClickListener(this);
254 this.setLongClickable(true);
256 anime = AnimationUtils.loadAnimation(context, R.anim.sample);
257 anime.setAnimationListener(new AnimationListener() {
258 public void onAnimationStart(Animation animation) {
261 public void onAnimationRepeat(Animation animation) {
264 public void onAnimationEnd(Animation animation) {
266 // bt2.performClick();
267 // isBt2Click = false;
272 scrollView.setScrollable(true);
273 scrollView.requestDisallowInterceptTouchEvent(false);
274 scrollView.invalidate();
280 // public boolean onTouchEvent(MotionEvent event) {
281 // // return super.onTouchEvent(event);
286 // public boolean onKeyDown(int keyCode, KeyEvent event) {
291 // public boolean onKeyLongPress(int keyCode, KeyEvent event) {
296 // public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent
302 // public boolean onKeyPreIme(int keyCode, KeyEvent event) {
307 // public boolean onKeyShortcut(int keyCode, KeyEvent event) {
312 // public boolean onKeyUp(int keyCode, KeyEvent event) {