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.Animation.AnimationListener;
16 import android.view.animation.AnimationUtils;
17 import android.widget.FrameLayout;
19 import com.yuji.ef.dao.Node;
21 public class IconFrameLayout extends FrameLayout implements OnLongClickListener {
22 private EverFolderActivity activity = null;
24 private LabelIconView target = null;
25 private LabelIconView destTarget = null;
26 private LabelIconView selectedTarget = null;
27 private List<LabelIconView> labelIconViewList = new ArrayList<LabelIconView>();
29 private Animation anime;
36 private boolean longClickFlg = false;
37 private IconScrollView scrollView;
38 private Context context = this.getContext();
40 public IconFrameLayout(Context context) {
44 public IconFrameLayout(Context context, AttributeSet attrs) {
45 super(context, attrs);
48 public IconFrameLayout(Context context, AttributeSet attrs, int defStyle) {
49 super(context, attrs, defStyle);
52 public void setActivity(EverFolderActivity activity) {
53 this.activity = activity;
57 protected void onLayout(boolean changed, int left, int top, int right,
59 super.onLayout(changed, left, top, right, bottom);
61 int size = this.getChildCount();
62 for (int i = 0; i < size; i++) {
63 LabelIconView vv = (LabelIconView) this.getChildAt(i);
64 int x2 = vv.getInitX();
65 int y2 = vv.getInitY();
67 vv.layout(x2, y2, x2 + vv.getWidth(), y2 + vv.getHeight());
71 public LabelIconView getSelectedTarget() {
72 return selectedTarget;
75 public void addView(LabelIconView child) {
77 labelIconViewList.add(child);
80 public void removeView(LabelIconView child) {
81 super.removeView(child);
82 labelIconViewList.remove(child);
85 public void removeAllViews(){
86 super.removeAllViews();
87 labelIconViewList.clear();
90 public void moveTop(LabelIconView child){
91 this.removeView(child);
95 private LabelIconView getView(int x, int y, LabelIconView v, List<LabelIconView> list, boolean flag) {
96 Rect rect = new Rect();
101 if (rect.contains(x, y)) {
106 for (LabelIconView view : list) {
108 view.getHitRect(rect);
109 if (rect.contains(x, y)) {
119 public boolean onTouchEvent(MotionEvent event) {
121 int x = (int) event.getRawX();
122 int y = (int) event.getRawY();
124 int dx = scrollView.getLeft();
125 int dy = scrollView.getTop();
130 int sx = x + scrollView.getScrollX();
131 int sy = y + scrollView.getScrollY();
132 LabelIconView v = getView(sx, sy, target, labelIconViewList, true);
133 LabelIconView obj = (LabelIconView) v;
135 int size = labelIconViewList.size();
137 if (target == null) {
141 return super.onTouchEvent(event);
144 this.getParent().requestDisallowInterceptTouchEvent(true);
146 if (event.getAction() == MotionEvent.ACTION_MOVE) {
148 return super.onTouchEvent(event);
150 if (target instanceof StatusIconView){
151 return super.onTouchEvent(event);
155 int sh = scrollView.getHeight();
156 int lh = this.getHeight();
158 int py = scrollView.getScrollY();
166 scrollView.smoothScrollTo(0, py - sdy);
170 else if (sh - y < N){
172 if (maxY - py < sdy){
175 scrollView.smoothScrollTo(0, py + sdy);
180 int diffX = offsetX - x;
181 int diffY = offsetY - y;
187 obj.layout(currentX, currentY, currentX + obj.getWidth(),
188 currentY + obj.getHeight());
193 v = getView(sx, sy, target, labelIconViewList, false);
194 if (destTarget == null) {
197 destTarget.setAlpha(128);
200 if (v != destTarget){
201 destTarget.setAlpha(255);
203 if (destTarget != null){
204 destTarget.setAlpha(128);
208 } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
209 //if (obj == target){
212 target.clearColorFilter();
215 if (target instanceof StatusIconView){
216 StatusIconView siv = (StatusIconView)target;
217 LabelIconView rv = siv.getRoot();
218 long id = rv.getNodeId();
220 activity.execute(id);
221 return super.onTouchEvent(event);
224 if (selectedTarget != null){
225 long id = selectedTarget.getNodeId();
227 target.clearColorFilter();
229 selectedTarget = target;
230 activity.targetSelectedChanged(true);
232 activity.executeView(id);
234 return super.onTouchEvent(event);
239 currentX = obj.getLeft();
240 currentY = obj.getTop();
242 target.setColorFilter(Color.RED, Mode.LIGHTEN);
243 selectedTarget = target;
244 activity.targetSelectedChanged(true);
246 scrollView.setScrollable(false);
249 target.clearColorFilter();
251 selectedTarget = target;
252 activity.targetSelectedChanged(false);
255 } else if (event.getAction() == MotionEvent.ACTION_UP) {
257 return super.onTouchEvent(event);
259 if (target instanceof StatusIconView){
260 return super.onTouchEvent(event);
264 // obj.setVisibility(View.GONE);
265 if (destTarget == null || destTarget instanceof StatusIconView) {
266 obj.setAnimation(anime);
267 obj.startAnimation(anime);
268 // layout.removeView(obj);
270 int srcX = target.getInitX();
271 int srcY = target.getInitY();
272 target.layout(srcX, srcY, srcX + target.getWidth(), srcY
273 + target.getHeight());
274 target.setAlpha(255);
276 // int srcX = target.getInitX();
277 // int srcY = target.getInitY();
278 // int dstX = dest.getInitX();
279 // int dstY = dest.getInitY();
281 // target.layout(dstX, dstY, dstX + target.getWidth(), dstY
282 // + target.getHeight());
283 // target.init(dstX, dstY);
284 // target.setAlpha(255);
285 // dest.layout(srcX, srcY, srcX + dest.getWidth(),
286 // srcY + dest.getHeight());
287 // dest.init(srcX, srcY);
288 // dest.setAlpha(255);
289 long src = target.getNodeId();
290 long dst = destTarget.getNodeId();
291 activity.execute(src, dst);
297 scrollView.setScrollable(true);
298 scrollView.requestDisallowInterceptTouchEvent(false);
299 scrollView.invalidate();
302 //this.getParent().requestDisallowInterceptTouchEvent(false);
304 // bt2.getHitRect(rect);
305 // if (rect.contains(x, y)) {
306 // isBt2Click = true;
308 longClickFlg = false;
311 return super.onTouchEvent(event);
312 } catch (Exception e) {
319 public boolean onLongClick(View view) {
320 if (target == null) {
323 if (target instanceof StatusIconView){
327 LabelIconView v = (LabelIconView) target;
329 v.clearColorFilter();
337 public void setScrollView(final IconScrollView scrollView) {
338 this.scrollView = scrollView;
339 this.setOnLongClickListener(this);
340 //this.setLongClickable(true);
342 anime = AnimationUtils.loadAnimation(context, R.anim.sample);
343 anime.setAnimationListener(new AnimationListener() {
344 public void onAnimationStart(Animation animation) {
347 public void onAnimationRepeat(Animation animation) {
350 public void onAnimationEnd(Animation animation) {
352 // bt2.performClick();
353 // isBt2Click = false;
358 scrollView.setScrollable(true);
359 scrollView.requestDisallowInterceptTouchEvent(false);
360 scrollView.invalidate();
366 // public boolean onTouchEvent(MotionEvent event) {
367 // // return super.onTouchEvent(event);
372 // public boolean onKeyDown(int keyCode, KeyEvent event) {
377 // public boolean onKeyLongPress(int keyCode, KeyEvent event) {
382 // public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent
388 // public boolean onKeyPreIme(int keyCode, KeyEvent event) {
393 // public boolean onKeyShortcut(int keyCode, KeyEvent event) {
398 // public boolean onKeyUp(int keyCode, KeyEvent event) {