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 public class IconFrameLayout extends FrameLayout implements OnLongClickListener {
20 private EverFolderActivity activity = null;
22 private LabelIconView target = null;
23 private LabelIconView destTarget = null;
24 private LabelIconView selectedTarget = null;
25 private LabelIconView cutTarget = null;
26 private List<LabelIconView> labelIconViewList = new ArrayList<LabelIconView>();
28 private Animation anime;
33 private boolean longClickFlg = false;
34 private IconScrollView scrollView;
35 private Context context = this.getContext();
37 public IconFrameLayout(Context context) {
41 public IconFrameLayout(Context context, AttributeSet attrs) {
42 super(context, attrs);
45 public IconFrameLayout(Context context, AttributeSet attrs, int defStyle) {
46 super(context, attrs, defStyle);
49 public void setActivity(EverFolderActivity activity) {
50 this.activity = activity;
54 protected void onLayout(boolean changed, int left, int top, int right,
56 super.onLayout(changed, left, top, right, bottom);
58 int size = this.getChildCount();
59 for (int i = 0; i < size; i++) {
60 LabelIconView vv = (LabelIconView) this.getChildAt(i);
61 int x2 = vv.getInitX();
62 int y2 = vv.getInitY();
64 vv.layout(x2, y2, x2 + vv.getWidth(), y2 + vv.getHeight());
68 public LabelIconView getSelectedTarget() {
69 return selectedTarget;
72 public void addView(LabelIconView child) {
74 labelIconViewList.add(child);
77 public void removeAllViews(){
78 super.removeAllViews();
79 labelIconViewList.clear();
82 public void moveTop(LabelIconView child){
83 this.removeView(child);
87 private LabelIconView getView(int x, int y, LabelIconView v, List<LabelIconView> list, boolean flag) {
88 Rect rect = new Rect();
93 if (rect.contains(x, y)) {
98 for (LabelIconView view : list) {
100 view.getHitRect(rect);
101 if (rect.contains(x, y)) {
110 public void setScrollView(final IconScrollView scrollView) {
111 this.scrollView = scrollView;
112 this.setOnLongClickListener(this);
113 //this.setLongClickable(true);
115 anime = AnimationUtils.loadAnimation(context, R.anim.sample);
116 anime.setAnimationListener(new AnimationListener() {
117 public void onAnimationStart(Animation animation) {
120 public void onAnimationRepeat(Animation animation) {
123 public void onAnimationEnd(Animation animation) {
125 // bt2.performClick();
126 // isBt2Click = false;
131 scrollView.setScrollable(true);
132 scrollView.requestDisallowInterceptTouchEvent(false);
133 scrollView.invalidate();
138 public void refresh(){
139 if (selectedTarget != null){
140 long id = selectedTarget.getNodeId();
141 for (LabelIconView view : labelIconViewList){
142 if (view.getNodeId() == id){
143 selectedTarget = view;
145 selectedTarget.setAlpha(255);
146 selectedTarget.setColorFilter(Color.RED, Mode.LIGHTEN);
150 if (cutTarget != null){
151 long id = cutTarget.getNodeId();
152 for (LabelIconView view : labelIconViewList){
153 if (view.getNodeId() == id){
155 cutTarget.clearColorFilter();
156 cutTarget.setAlpha(64);
162 public LabelIconView getCutTarget(){
166 public void setCutTarget(LabelIconView cutTarget){
167 this.cutTarget = cutTarget;
168 selectedTarget = null;
173 public boolean onTouchEvent(MotionEvent event) {
175 int x = (int) event.getRawX();
176 int y = (int) event.getRawY();
178 int dx = scrollView.getLeft();
179 int dy = scrollView.getTop();
184 int sx = x + scrollView.getScrollX();
185 int sy = y + scrollView.getScrollY();
186 LabelIconView v = getView(sx, sy, target, labelIconViewList, true);
187 LabelIconView obj = (LabelIconView) v;
189 //int size = labelIconViewList.size();
190 if (target == null) {
194 return super.onTouchEvent(event);
197 this.getParent().requestDisallowInterceptTouchEvent(true);
199 if (event.getAction() == MotionEvent.ACTION_MOVE) {
201 return super.onTouchEvent(event);
203 if (target instanceof StatusIconView){
204 return super.onTouchEvent(event);
208 int sh = scrollView.getHeight();
209 int lh = this.getHeight();
211 int py = scrollView.getScrollY();
219 scrollView.smoothScrollTo(0, py - sdy);
223 else if (sh - y < N){
225 if (maxY - py < sdy){
228 scrollView.smoothScrollTo(0, py + sdy);
233 int diffX = offsetX - x;
234 int diffY = offsetY - y;
240 obj.layout(currentX, currentY, currentX + obj.getWidth(),
241 currentY + obj.getHeight());
246 v = getView(sx, sy, target, labelIconViewList, false);
247 if (destTarget == null) {
250 destTarget.setAlpha(128);
253 if (v != destTarget){
254 destTarget.setAlpha(255);
256 if (destTarget != null){
257 destTarget.setAlpha(128);
261 } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
262 //if (obj == target){
265 target.clearColorFilter();
268 if (target instanceof StatusIconView){
269 StatusIconView siv = (StatusIconView)target;
270 LabelIconView rv = siv.getRoot();
271 long id = rv.getNodeId();
273 activity.execute(id);
274 return super.onTouchEvent(event);
277 if (selectedTarget != null){
278 long id = selectedTarget.getNodeId();
280 target.clearColorFilter();
282 selectedTarget = target;
283 activity.targetSelectedChanged(true);
285 activity.executeView(id);
287 return super.onTouchEvent(event);
292 currentX = obj.getLeft();
293 currentY = obj.getTop();
295 target.setAlpha(255);
296 target.setColorFilter(Color.RED, Mode.LIGHTEN);
297 selectedTarget = target;
298 activity.targetSelectedChanged(true);
300 scrollView.setScrollable(false);
303 target.clearColorFilter();
305 selectedTarget = target;
306 activity.targetSelectedChanged(false);
309 } else if (event.getAction() == MotionEvent.ACTION_UP) {
311 return super.onTouchEvent(event);
313 if (target instanceof StatusIconView){
314 return super.onTouchEvent(event);
318 // obj.setVisibility(View.GONE);
319 if (destTarget == null || destTarget instanceof StatusIconView) {
320 obj.setAnimation(anime);
321 obj.startAnimation(anime);
322 // layout.removeView(obj);
324 int srcX = target.getInitX();
325 int srcY = target.getInitY();
326 target.layout(srcX, srcY, srcX + target.getWidth(), srcY
327 + target.getHeight());
328 target.setAlpha(255);
330 long src = target.getNodeId();
331 long dst = destTarget.getNodeId();
332 activity.execute(src, dst);
339 selectedTarget = null;
341 scrollView.setScrollable(true);
342 scrollView.requestDisallowInterceptTouchEvent(false);
343 scrollView.invalidate();
346 longClickFlg = false;
349 return super.onTouchEvent(event);
350 } catch (Exception e) {
357 public boolean onLongClick(View view) {
358 if (target == null) {
361 if (target instanceof StatusIconView){
365 LabelIconView v = (LabelIconView) target;
367 v.clearColorFilter();