3 import java.util.ArrayList;
6 import android.content.Context;
7 import android.graphics.Color;
8 import android.graphics.Point;
9 import android.graphics.PorterDuff.Mode;
10 import android.graphics.Rect;
11 import android.util.AttributeSet;
12 import android.view.MotionEvent;
13 import android.view.View;
14 import android.view.View.OnLongClickListener;
15 import android.view.animation.Animation;
16 import android.view.animation.AnimationUtils;
17 import android.view.animation.Animation.AnimationListener;
18 import android.widget.FrameLayout;
20 public class IconFrameLayout extends FrameLayout implements OnLongClickListener {
21 private IconImageView target = null;
22 private IconImageView dest = null;
24 private Animation anime;
31 private boolean longClickFlg = false;
32 private IconScrollView scrollView;
33 private Context context = this.getContext();
35 public IconFrameLayout(Context context) {
39 public IconFrameLayout(Context context, AttributeSet attrs) {
40 super(context, attrs);
43 public IconFrameLayout(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
48 protected void onLayout(boolean changed, int left, int top, int right,
50 super.onLayout(changed, left, top, right, bottom);
52 int size = this.getChildCount();
53 for (int i = 0; i < size; i++) {
54 IconImageView vv = (IconImageView) this.getChildAt(i);
55 int x2 = vv.getInitX();
56 int y2 = vv.getInitY();
58 vv.layout(x2, y2, x2 + vv.getWidth(), y2 + vv.getHeight());
62 private View getView(int x, int y, View v, List<View> list) {
63 Rect rect = new Rect();
66 // rect.left = v.getLeft();
67 // rect.top = v.getTop();
68 // rect.right = rect.left + v.getWidth();
69 // rect.bottom = rect.top + v.getHeight();
72 if (rect.contains(x, y)) {
76 for (View view : list) {
78 // rect.left = view.getLeft();
79 // rect.top = view.getTop();
80 // rect.right = rect.left + view.getWidth();
81 // rect.bottom = rect.top + view.getHeight();
82 view.getHitRect(rect);
83 if (rect.contains(x, y)) {
93 public boolean onTouchEvent(MotionEvent event) {
95 if (event.getAction() == MotionEvent.ACTION_CANCEL) {
96 System.out.println("dummy");
98 int x = (int) event.getRawX();
99 int y = (int) event.getRawY();
101 int dx = scrollView.getLeft();
102 int dy = scrollView.getTop();
108 List<View> list = new ArrayList<View>();
109 int size = this.getChildCount();
110 for (int i = 0; i < size; i++) {
111 IconImageView v = (IconImageView) this.getChildAt(i);
114 int sx = x + scrollView.getScrollX();
115 int sy = y + scrollView.getScrollY();
116 // View v = getView(x, y, target, list);
117 View v = getView(sx, sy, target, list);
121 IconImageView obj = (IconImageView) v;
123 if (target == null) {
126 // scrollView.setOnTouchListener(new OnTouchListener() {
128 // public boolean onTouch(View v, MotionEvent event) {
132 // } else if (target != obj) {
136 return super.onTouchEvent(event);
139 this.getParent().requestDisallowInterceptTouchEvent(true);
141 if (event.getAction() == MotionEvent.ACTION_MOVE) {
147 int sh = scrollView.getHeight();
148 int lh = this.getHeight();
150 int py = scrollView.getScrollY();
158 scrollView.smoothScrollTo(0, py - sdy);
162 else if (sh - y < N){
164 if (maxY - py < sdy){
167 scrollView.smoothScrollTo(0, py + sdy);
172 int diffX = offsetX - x;
173 int diffY = offsetY - y;
179 obj.layout(currentX, currentY, currentX + obj.getWidth(),
180 currentY + obj.getHeight());
186 Rect rect = new Rect();
187 for (int i = 0; i < size; i++) {
188 IconImageView vv = (IconImageView) list.get(i);
190 if (rect.contains(x, y)) {
197 Rect rect = new Rect();
199 dest.getHitRect(rect);
200 if (!rect.contains(x, y)) {
205 } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
211 currentX = obj.getLeft();
212 currentY = obj.getTop();
214 target.setColorFilter(Color.RED, Mode.LIGHTEN);
216 scrollView.setScrollable(false);
218 } else if (event.getAction() == MotionEvent.ACTION_UP) {
224 obj.setAnimation(anime);
225 obj.startAnimation(anime);
226 // obj.setVisibility(View.GONE);
228 //
\8fÁ
\82·
\8fê
\8d\87
229 // layout.removeView(obj);
231 //
\83L
\83\83\83\93\83Z
\83\8b
232 int srcX = target.getInitX();
233 int srcY = target.getInitY();
234 target.layout(srcX, srcY, srcX + target.getWidth(), srcY
235 + target.getHeight());
236 target.setAlpha(255);
238 int srcX = target.getInitX();
239 int srcY = target.getInitY();
240 int dstX = dest.getInitX();
241 int dstY = dest.getInitY();
243 target.layout(dstX, dstY, dstX + target.getWidth(), dstY
244 + target.getHeight());
245 target.init(dstX, dstY);
246 target.setAlpha(255);
247 dest.layout(srcX, srcY, srcX + dest.getWidth(),
248 srcY + dest.getHeight());
249 dest.init(srcX, srcY);
253 //this.getParent().requestDisallowInterceptTouchEvent(false);
255 // bt2.getHitRect(rect);
256 // if (rect.contains(x, y)) {
257 // isBt2Click = true;
259 longClickFlg = false;
262 return super.onTouchEvent(event);
263 } catch (Exception e) {
270 public boolean onLongClick(View view) {
271 // if (!(view instanceof IconImageView)) {
274 // IconImageView v = (IconImageView) view;
275 if (target == null) {
278 IconImageView v = (IconImageView) target;
280 v.clearColorFilter();
282 this.removeView(target);
283 this.addView(target);
289 public void setScrollView(final IconScrollView scrollView) {
290 this.scrollView = scrollView;
291 this.setOnLongClickListener(this);
292 this.setLongClickable(true);
294 anime = AnimationUtils.loadAnimation(context, R.anim.sample);
295 anime.setAnimationListener(new AnimationListener() {
296 public void onAnimationStart(Animation animation) {
299 public void onAnimationRepeat(Animation animation) {
302 public void onAnimationEnd(Animation animation) {
304 // bt2.performClick();
305 // isBt2Click = false;
310 scrollView.setScrollable(true);
311 scrollView.requestDisallowInterceptTouchEvent(false);
312 scrollView.invalidate();
318 // public boolean onTouchEvent(MotionEvent event) {
319 // // return super.onTouchEvent(event);
324 // public boolean onKeyDown(int keyCode, KeyEvent event) {
329 // public boolean onKeyLongPress(int keyCode, KeyEvent event) {
334 // public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent
340 // public boolean onKeyPreIme(int keyCode, KeyEvent event) {
345 // public boolean onKeyShortcut(int keyCode, KeyEvent event) {
350 // public boolean onKeyUp(int keyCode, KeyEvent event) {