OSDN Git Service

T28353
authorYuji Konishi <yuji.k64613@gmail.com>
Sat, 12 May 2012 05:30:11 +0000 (14:30 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Sat, 12 May 2012 05:30:11 +0000 (14:30 +0900)
source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java
source/workspace/EverFolder/src/com/yuji/ef/IconFrameLayout.java
source/workspace/EverFolder/src/com/yuji/ef/LabelIconView.java [new file with mode: 0644]
source/workspace/EverFolder/src/com/yuji/ef/dao/DirNode.java [new file with mode: 0644]
source/workspace/EverFolder/src/com/yuji/ef/dao/FileNode.java [new file with mode: 0644]
source/workspace/EverFolder/src/com/yuji/ef/dao/Node.java [new file with mode: 0644]

index 549c8d2..b3aa1ed 100644 (file)
@@ -1,25 +1,25 @@
 package com.yuji.ef;
 
+import java.util.List;
+
 import android.app.Activity;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.Color;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
-import android.graphics.PorterDuff.Mode;
 import android.graphics.Rect;
 import android.os.Bundle;
 import android.view.Gravity;
-import android.view.MotionEvent;
 import android.view.View;
-import android.view.View.OnLongClickListener;
-import android.view.View.OnTouchListener;
 import android.view.WindowManager;
 import android.view.animation.Animation;
 import android.view.animation.Animation.AnimationListener;
 import android.view.animation.AnimationUtils;
-import android.widget.ScrollView;
+
+import com.yuji.ef.dao.DirNode;
+import com.yuji.ef.dao.FileNode;
+import com.yuji.ef.dao.Node;
 
 public class EverFolderActivity extends Activity /*implements OnTouchListener,
                OnLongClickListener*/ {
@@ -27,6 +27,7 @@ public class EverFolderActivity extends Activity /*implements OnTouchListener,
        private IconScrollView scrollView;
        private IconImageView target = null;
        private IconImageView dest = null;
+       private Node top = null;
 
        private Animation anime;
        private int startX;
@@ -76,24 +77,120 @@ public class EverFolderActivity extends Activity /*implements OnTouchListener,
                        // target.setImageBitmap(bmp);
                        // this.target.setOnTouchListener(this);
 
-                       int x;
-                       int y;
-                       int N = 200;
-
-                       x = 100;
-                       y = 0;
-                       for (int i = 0; i < 4; i++) {
-                               Bitmap bmp = (i % 2 == 0) ? bmp1 : bmp2;
-                               createIconImageView(bmp, x, y);
-                               y += N;
-                       }
+//                     int x;
+//                     int y;
+//                     int N = 200;
+//
+//                     x = 100;
+//                     y = 0;
+//                     for (int i = 0; i < 4; i++) {
+//                             Bitmap bmp = (i % 2 == 0) ? bmp1 : bmp2;
+//                             //createIconImageView(bmp, x, y);
+//                             createIconImageView(bmp, "TEXT" + i, x, y);
+//                             y += N;
+//                     }
+//
+//                     layout.setMinimumHeight(y * 2 + N);
+                       top = new DirNode(null, null);
+                       
+                       Node node;
+                       node = new DirNode("\83f\83B\83\8c\83N\83g\83\8a", new LabelIconView(this));
+                       top.add(node);
+                       node.add(new FileNode("\83t\83@\83C\83\8baaa", new LabelIconView(this)));
+                       node.add(new FileNode("\83t\83@\83C\83\8bbb", new LabelIconView(this)));
+                       node.add(new FileNode("\83t\83@\83C\83\8bc", new LabelIconView(this)));
+                       
+                       node = new DirNode("\83f\83B\83\8c\83N\83g\83\8aAAA", new LabelIconView(this));
+                       top.add(node);
+                       node.add(new DirNode("directory qqqq", new LabelIconView(this)));
+                       node.add(new FileNode("\83t\83@\83C\83\8bdddddddd", new LabelIconView(this)));
+                       node.add(new FileNode("\83t\83@\83C\83\8beee", new LabelIconView(this)));
 
-                       layout.setMinimumHeight(y * 2 + N);
+                       node = new FileNode("\83t\83@\83C\83\8bzzz", new LabelIconView(this));
+                       top.add(node);
+                       
+                       updateList(top);
+                       layout.setMinimumHeight(viewY);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
 
+       private int viewY;
+       
+       private void updateList(Node parent){
+               int x = 50;
+               viewY = 30;
+               
+               List<Node> list = parent.getChildren();
+               for (Node node : list){
+                       updateList(node, x);
+               }
+       }
+       
+       private void updateList(Node node, int x){
+               int N = 200;
+               int M = 120;
+               
+               LabelIconView view = node.getView();
+               Resources r = getResources();
+               Bitmap bmp = BitmapFactory.decodeResource(r, node.getIconId());
+               createIconImageView(view, bmp, node.getName(), x, viewY);
+
+               viewY += M;
+               
+               List<Node> list = node.getChildren();
+               if (list == null){
+                       return;
+               }
+               for (Node n : list){
+                       updateList(n, x + N);
+               }
+       }
+       
+       private void createIconImageView(LabelIconView v, Bitmap bmp, String text, int x, int y) {
+               v.init(x, y, bmp, text);
+
+               android.view.WindowManager.LayoutParams params = new WindowManager.LayoutParams();
+               params.gravity = Gravity.TOP | Gravity.LEFT;
+               params.height = WindowManager.LayoutParams.WRAP_CONTENT;
+               params.width = WindowManager.LayoutParams.WRAP_CONTENT;
+               params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+                               | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+                               | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+                               | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
+               params.format = PixelFormat.TRANSLUCENT;
+               params.windowAnimations = 0;
+               params.x = x;
+               params.y = y;
+               v.setLayoutParams(params);
+
+               layout.addView(v);
+               v.layout(x, y, x + v.getWidth(), y + v.getHeight());
+       }
+       
+       private void createIconImageView(Bitmap bmp, String text, int x, int y) {
+               LabelIconView v = new LabelIconView(this);
+               v.init(x, y, bmp, text);
+
+               android.view.WindowManager.LayoutParams params = new WindowManager.LayoutParams();
+               params.gravity = Gravity.TOP | Gravity.LEFT;
+               params.height = WindowManager.LayoutParams.WRAP_CONTENT;
+               params.width = WindowManager.LayoutParams.WRAP_CONTENT;
+               params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+                               | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
+                               | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+                               | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
+               params.format = PixelFormat.TRANSLUCENT;
+               params.windowAnimations = 0;
+               params.x = x;
+               params.y = y;
+               v.setLayoutParams(params);
+
+               layout.addView(v);
+               v.layout(x, y, x + v.getWidth(), y + v.getHeight());
+       }
+       
        private void createIconImageView(Bitmap bmp, int x, int y) {
                IconImageView v = new IconImageView(this);
                v.init(x, y);
index 0225c64..626c40e 100644 (file)
@@ -18,9 +18,10 @@ import android.view.animation.Animation.AnimationListener;
 import android.widget.FrameLayout;
 
 public class IconFrameLayout extends FrameLayout implements OnLongClickListener {
-       private IconImageView target = null;
-       private IconImageView dest = null;
-
+       private LabelIconView target = null;
+       private LabelIconView dest = null;
+       private List<LabelIconView> list = new ArrayList<LabelIconView>();
+       
        private Animation anime;
        private int startX;
        private int startY;
@@ -51,7 +52,7 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
 
                int size = this.getChildCount();
                for (int i = 0; i < size; i++) {
-                       IconImageView vv = (IconImageView) this.getChildAt(i);
+                       LabelIconView vv = (LabelIconView) this.getChildAt(i);
                        int x2 = vv.getInitX();
                        int y2 = vv.getInitY();
                        // vv.init(x2, y2);
@@ -59,7 +60,22 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
                }
        }
 
-       private View getView(int x, int y, View v, List<View> list) {
+       public void addView(LabelIconView child) {
+               super.addView(child);
+               list.add(child);
+       }
+
+       public void removeView(LabelIconView child) {
+               super.removeView(child);
+               list.remove(child);
+       }
+
+       public void moveTop(LabelIconView child){
+               this.removeView(child);
+               this.addView(child);
+       }
+       
+       private View getView(int x, int y, View v, List<LabelIconView> list) {
                Rect rect = new Rect();
 
                if (v != null) {
@@ -104,13 +120,6 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
                        x -= dx;
                        y -= dy;
                        
-                       // FOO
-                       List<View> list = new ArrayList<View>();
-                       int size = this.getChildCount();
-                       for (int i = 0; i < size; i++) {
-                               IconImageView v = (IconImageView) this.getChildAt(i);
-                               list.add(v);
-                       }
                        int sx = x + scrollView.getScrollX();
                        int sy = y + scrollView.getScrollY();
 //                     View v = getView(x, y, target, list);
@@ -118,8 +127,10 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
 //                     if (v == null) {
 //                             return false;
 //                     }
-                       IconImageView obj = (IconImageView) v;
+                       LabelIconView obj = (LabelIconView) v;
 
+                       int size = list.size();
+                       
                        if (target == null) {
                                target = obj;
 
@@ -185,7 +196,7 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
                                if (dest == null) {
                                        Rect rect = new Rect();
                                        for (int i = 0; i < size; i++) {
-                                               IconImageView vv = (IconImageView) list.get(i);
+                                               LabelIconView vv = (LabelIconView) list.get(i);
                                                vv.getHitRect(rect);
                                                if (rect.contains(x, y)) {
                                                        dest = vv;
@@ -275,12 +286,11 @@ public class IconFrameLayout extends FrameLayout implements OnLongClickListener
                if (target == null) {
                        return false;
                }
-               IconImageView v = (IconImageView) target;
+               LabelIconView v = (LabelIconView) target;
                v.setAlpha(128);
                v.clearColorFilter();
 
-               this.removeView(target);
-               this.addView(target);
+               moveTop(target);
                
                longClickFlg = true;
                return true;
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/LabelIconView.java b/source/workspace/EverFolder/src/com/yuji/ef/LabelIconView.java
new file mode 100644 (file)
index 0000000..be10429
--- /dev/null
@@ -0,0 +1,62 @@
+package com.yuji.ef;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.PorterDuff.Mode;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class LabelIconView extends LinearLayout {
+       private boolean isInit = false;
+       private int initX = 0;
+       private int initY = 0;
+       
+       private ImageView imageView = null;
+       private TextView textView = null;
+
+       public LabelIconView(Context context) {
+               super(context);
+       }
+
+       public void init(int x, int y, Bitmap bmp, String text) {
+               init(x, y);
+               Context context = this.getContext();
+               
+               imageView = new ImageView(context);
+               imageView.setImageBitmap(bmp);
+               
+               textView = new TextView(context);
+               textView.setText(text);
+               
+               this.addView(imageView);
+               this.addView(textView);
+       }
+
+       public int getInitX() {
+               return initX;
+       }
+
+       public int getInitY() {
+               return initY;
+       }
+
+       public void init(int x, int y) {
+               initX = x;
+               initY = y;
+       }
+
+       public void setAlpha(int alpha) {
+               imageView.setAlpha(alpha);              
+       }
+
+       public void setColorFilter(int color, Mode mode) {
+               imageView.setColorFilter(color, mode);
+       }
+
+       public void clearColorFilter() {
+               imageView.clearColorFilter();
+       }
+
+
+}
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/DirNode.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/DirNode.java
new file mode 100644 (file)
index 0000000..e6fb718
--- /dev/null
@@ -0,0 +1,19 @@
+package com.yuji.ef.dao;
+
+import java.util.ArrayList;
+
+import com.yuji.ef.LabelIconView;
+import com.yuji.ef.R;
+
+public class DirNode extends Node {
+       public DirNode(String name, LabelIconView view){
+               super(name, view);
+               
+               children = new ArrayList<Node>();
+       }
+
+       @Override
+       public int getIconId(){
+               return R.drawable.test2;
+       }
+}
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/FileNode.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/FileNode.java
new file mode 100644 (file)
index 0000000..6b4af3a
--- /dev/null
@@ -0,0 +1,15 @@
+package com.yuji.ef.dao;
+
+import com.yuji.ef.LabelIconView;
+import com.yuji.ef.R;
+
+public class FileNode extends Node {
+       public FileNode(String name, LabelIconView view){
+               super(name, view);
+       }
+
+       @Override
+       public int getIconId(){
+               return R.drawable.android;
+       }
+}
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/Node.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/Node.java
new file mode 100644 (file)
index 0000000..b7196df
--- /dev/null
@@ -0,0 +1,43 @@
+package com.yuji.ef.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.yuji.ef.LabelIconView;
+
+public class Node {
+       //private Node parent = null;
+       protected String guid = null;
+       protected String name = null;
+       protected LabelIconView view = null;
+       protected List<Node> children = null;
+
+       public Node(String name, LabelIconView view){
+               this.name = name;
+               this.view = view;
+       }
+       
+       public List<Node> getChildren() {
+               return children;
+       }
+       
+       public String getGuid() {
+               return guid;
+       }
+       
+       public String getName(){
+               return name;
+       }
+       
+       public void add(Node node){
+               children.add(node);
+       }
+       
+       public LabelIconView getView() {
+               return view;
+       }
+       
+       public int getIconId(){
+               return -1;
+       }
+}