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 LabelIconView target = null;
22 private LabelIconView dest = null;
23 private List<LabelIconView> list = new ArrayList<LabelIconView>();
25 private Animation anime;
32 private boolean longClickFlg = false;
33 private IconScrollView scrollView;
34 private Context context = this.getContext();
36 public IconFrameLayout(Context context) {
40 public IconFrameLayout(Context context, AttributeSet attrs) {
41 super(context, attrs);
44 public IconFrameLayout(Context context, AttributeSet attrs, int defStyle) {
45 super(context, attrs, defStyle);
49 protected void onLayout(boolean changed, int left, int top, int right,
51 super.onLayout(changed, left, top, right, bottom);
53 int size = this.getChildCount();
54 for (int i = 0; i < size; i++) {
55 LabelIconView vv = (LabelIconView) this.getChildAt(i);
56 int x2 = vv.getInitX();
57 int y2 = vv.getInitY();
59 vv.layout(x2, y2, x2 + vv.getWidth(), y2 + vv.getHeight());
63 public void addView(LabelIconView child) {
68 public void removeView(LabelIconView child) {
69 super.removeView(child);
73 public void moveTop(LabelIconView child){
74 this.removeView(child);
78 private LabelIconView getView(int x, int y, LabelIconView v, List<LabelIconView> list, boolean flag) {
79 Rect rect = new Rect();
84 if (rect.contains(x, y)) {
89 for (LabelIconView view : list) {
91 view.getHitRect(rect);
92 if (rect.contains(x, y)) {
102 public boolean onTouchEvent(MotionEvent event) {
104 int x = (int) event.getRawX();
105 int y = (int) event.getRawY();
107 int dx = scrollView.getLeft();
108 int dy = scrollView.getTop();
113 int sx = x + scrollView.getScrollX();
114 int sy = y + scrollView.getScrollY();
115 LabelIconView v = getView(sx, sy, target, list, true);
116 LabelIconView obj = (LabelIconView) v;
118 int size = list.size();
120 if (target == null) {
124 return super.onTouchEvent(event);
127 this.getParent().requestDisallowInterceptTouchEvent(true);
129 if (event.getAction() == MotionEvent.ACTION_MOVE) {
131 return super.onTouchEvent(event);
135 int sh = scrollView.getHeight();
136 int lh = this.getHeight();
138 int py = scrollView.getScrollY();
146 scrollView.smoothScrollTo(0, py - sdy);
150 else if (sh - y < N){
152 if (maxY - py < sdy){
155 scrollView.smoothScrollTo(0, py + sdy);
160 int diffX = offsetX - x;
161 int diffY = offsetY - y;
167 obj.layout(currentX, currentY, currentX + obj.getWidth(),
168 currentY + obj.getHeight());
173 v = getView(sx, sy, target, list, false);
188 } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
193 currentX = obj.getLeft();
194 currentY = obj.getTop();
196 target.setColorFilter(Color.RED, Mode.LIGHTEN);
198 scrollView.setScrollable(false);
201 target.clearColorFilter();
205 } else if (event.getAction() == MotionEvent.ACTION_UP) {
207 return super.onTouchEvent(event);
211 obj.setAnimation(anime);
212 obj.startAnimation(anime);
213 // obj.setVisibility(View.GONE);
215 //
\8fÁ
\82·
\8fê
\8d\87
216 // layout.removeView(obj);
218 //
\83L
\83\83\83\93\83Z
\83\8b
219 int srcX = target.getInitX();
220 int srcY = target.getInitY();
221 target.layout(srcX, srcY, srcX + target.getWidth(), srcY
222 + target.getHeight());
223 target.setAlpha(255);
225 int srcX = target.getInitX();
226 int srcY = target.getInitY();
227 int dstX = dest.getInitX();
228 int dstY = dest.getInitY();
230 target.layout(dstX, dstY, dstX + target.getWidth(), dstY
231 + target.getHeight());
232 target.init(dstX, dstY);
233 target.setAlpha(255);
234 dest.layout(srcX, srcY, srcX + dest.getWidth(),
235 srcY + dest.getHeight());
236 dest.init(srcX, srcY);
240 //this.getParent().requestDisallowInterceptTouchEvent(false);
242 // bt2.getHitRect(rect);
243 // if (rect.contains(x, y)) {
244 // isBt2Click = true;
246 longClickFlg = false;
249 return super.onTouchEvent(event);
250 } catch (Exception e) {
257 public boolean onLongClick(View view) {
258 if (target == null) {
261 LabelIconView v = (LabelIconView) target;
263 v.clearColorFilter();
271 public void setScrollView(final IconScrollView scrollView) {
272 this.scrollView = scrollView;
273 this.setOnLongClickListener(this);
274 //this.setLongClickable(true);
276 anime = AnimationUtils.loadAnimation(context, R.anim.sample);
277 anime.setAnimationListener(new AnimationListener() {
278 public void onAnimationStart(Animation animation) {
281 public void onAnimationRepeat(Animation animation) {
284 public void onAnimationEnd(Animation animation) {
286 // bt2.performClick();
287 // isBt2Click = false;
292 scrollView.setScrollable(true);
293 scrollView.requestDisallowInterceptTouchEvent(false);
294 scrollView.invalidate();
300 // public boolean onTouchEvent(MotionEvent event) {
301 // // return super.onTouchEvent(event);
306 // public boolean onKeyDown(int keyCode, KeyEvent event) {
311 // public boolean onKeyLongPress(int keyCode, KeyEvent event) {
316 // public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent
322 // public boolean onKeyPreIme(int keyCode, KeyEvent event) {
327 // public boolean onKeyShortcut(int keyCode, KeyEvent event) {
332 // public boolean onKeyUp(int keyCode, KeyEvent event) {