OSDN Git Service

T28352
[everfolder/source.git] / source / workspace / EverFolder / src / com / yuji / ef / EverFolderActivity.java
1 package com.yuji.ef;
2
3 import android.app.Activity;
4 import android.content.res.Resources;
5 import android.graphics.Bitmap;
6 import android.graphics.BitmapFactory;
7 import android.graphics.Color;
8 import android.graphics.PixelFormat;
9 import android.graphics.Point;
10 import android.graphics.PorterDuff.Mode;
11 import android.graphics.Rect;
12 import android.os.Bundle;
13 import android.view.Gravity;
14 import android.view.MotionEvent;
15 import android.view.View;
16 import android.view.View.OnLongClickListener;
17 import android.view.View.OnTouchListener;
18 import android.view.WindowManager;
19 import android.view.animation.Animation;
20 import android.view.animation.Animation.AnimationListener;
21 import android.view.animation.AnimationUtils;
22 import android.widget.ScrollView;
23
24 public class EverFolderActivity extends Activity /*implements OnTouchListener,
25                 OnLongClickListener*/ {
26         private IconFrameLayout layout;
27         private IconScrollView scrollView;
28         private IconImageView target = null;
29         private IconImageView dest = null;
30
31         private Animation anime;
32         private int startX;
33         private int startY;
34         private int currentX;
35         private int currentY;
36         private int offsetX;
37         private int offsetY;
38         private boolean longClickFlg = false;
39
40         @Override
41         public void onCreate(Bundle savedInstanceState) {
42                 super.onCreate(savedInstanceState);
43                 setContentView(R.layout.main);
44
45                 scrollView = (IconScrollView) findViewById(R.id.scrollView);
46                 layout = (IconFrameLayout) findViewById(R.id.frameLayout);
47                 layout.setScrollView(scrollView);
48                 //layout.setClickable(false);
49                 // layout = new FrameLayout(this);
50                 // setContentView(layout);
51
52                 try {
53                         Resources r = getResources();
54                         Bitmap bmp1 = BitmapFactory.decodeResource(r, R.drawable.android);
55                         Bitmap bmp2 = BitmapFactory.decodeResource(r, R.drawable.test2);
56
57                         anime = AnimationUtils.loadAnimation(this, R.anim.sample);
58                         anime.setAnimationListener(new AnimationListener() {
59                                 public void onAnimationStart(Animation animation) {
60                                 }
61
62                                 public void onAnimationRepeat(Animation animation) {
63                                 }
64
65                                 public void onAnimationEnd(Animation animation) {
66                                         // if (isBt2Click) {
67                                         // bt2.performClick();
68                                         // isBt2Click = false;
69                                         // }
70                                         target = null;
71                                         dest = null;
72                                 }
73                         });
74
75                         // target = (ImageView) findViewById(R.id.ImageView01);
76                         // target.setImageBitmap(bmp);
77                         // this.target.setOnTouchListener(this);
78
79                         int x;
80                         int y;
81                         int N = 160;
82
83                         x = 100;
84                         y = 10;
85                         for (int i = 0; i < 4; i++) {
86                                 Bitmap bmp = (i % 2 == 0) ? bmp1 : bmp2;
87                                 createIconImageView(bmp, x, y);
88                                 y += N;
89                         }
90
91                         layout.setMinimumHeight(y * 2 + N);
92                 } catch (Exception e) {
93                         e.printStackTrace();
94                 }
95         }
96
97         private void createIconImageView(Bitmap bmp, int x, int y) {
98                 IconImageView v = new IconImageView(this);
99                 v.init(x, y);
100                 v.setImageBitmap(bmp);
101
102                 android.view.WindowManager.LayoutParams params = new WindowManager.LayoutParams();
103                 params.gravity = Gravity.TOP | Gravity.LEFT;
104                 params.height = WindowManager.LayoutParams.WRAP_CONTENT;
105                 params.width = WindowManager.LayoutParams.WRAP_CONTENT;
106                 params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
107                                 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
108                                 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
109                                 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
110                 params.format = PixelFormat.TRANSLUCENT;
111                 params.windowAnimations = 0;
112                 params.x = x;
113                 params.y = y;
114                 v.setLayoutParams(params);
115                 // v.setLayoutParams(new ViewGroup.LayoutParams(WC, WC));
116
117                 layout.addView(v, params);
118                 // v.setPadding(x, y, 0, 0);
119                 v.layout(x, y, x + v.getWidth(), y + v.getHeight());
120                 // v.setVisibility(View.INVISIBLE);
121
122                 // layout.addView(v, new ViewGroup.LayoutParams(WC, WC));
123                 // v.layout(x, y, x + v.getWidth(), y + v.getHeight());
124
125                 //v.setOnTouchListener(this);
126                 //v.setOnLongClickListener(this);
127         }
128
129         @Override
130         protected void onStart() {
131                 super.onStart();
132         }
133
134         public void onClickShowButton(View v) {
135                 // int size = layout.getChildCount();
136                 // for (int i = 0; i < size; i++){
137                 // View vv = layout.getChildAt(i);
138                 // vv.setVisibility(View.VISIBLE);
139                 // }
140                 if (target == null) {
141                         return;
142                 }
143
144                 Rect rect = new Rect();
145                 Point globalOffset = new Point();
146                 target.getGlobalVisibleRect(rect, globalOffset);
147                 // currentX = startX;
148                 // currentY = startY;
149                 currentX = 50;
150                 currentY = 50;
151                 target.layout(currentX, currentY, currentX + target.getWidth(),
152                                 currentY + target.getHeight());
153
154                 // TODO
155                 target.setAlpha(64);
156                 // layout.removeView(target);
157                 // layout.addView(target);
158                 target.setSelected(true);
159                 IconImageView iv = (IconImageView) target;
160                 iv.init(currentX, currentY);
161
162                 target = null;
163         }
164
165         public void onClickButton02(View v) {
166                 // TODO
167                 // Toast.makeText(this, "click", Toast.LENGTH_SHORT).show();
168                 // Intent intent = new Intent(DDSampleActivity.this, Next.class);
169                 // startActivity(intent);
170         }
171
172 //      @Override
173 //      public boolean onTouch(View v, MotionEvent event) {
174 //              int x = (int) event.getRawX();
175 //              int y = (int) event.getRawY();
176 //
177 //              // FOO
178 //              if (!(v instanceof IconImageView)) {
179 //                      return true;
180 //              }
181 //              IconImageView obj = (IconImageView) v;
182 //
183 //              if (target == null) {
184 //                      target = obj;
185 //
186 ////                    scrollView.setOnTouchListener(new OnTouchListener() {
187 ////                            @Override
188 ////                            public boolean onTouch(View v, MotionEvent event) {
189 ////                                    return true;
190 ////                            }
191 ////                    });
192 //              } else if (target != obj) {
193 //                      return true;
194 //              }
195 //              if (event.getAction() == MotionEvent.ACTION_MOVE) {
196 //                      if (!longClickFlg) {
197 //                              return false;
198 //                      }
199 //                      int diffX = offsetX - x;
200 //                      int diffY = offsetY - y;
201 //
202 //                      currentX -= diffX;
203 //                      currentY -= diffY;
204 //                      // currentX = x;;
205 //                      // currentY = y;
206 //                      obj.layout(currentX, currentY, currentX + obj.getWidth(), currentY
207 //                                      + obj.getHeight());
208 //
209 //                      offsetX = x;
210 //                      offsetY = y;
211 //
212 //                      if (dest == null) {
213 //                              Rect rect = new Rect();
214 //                              int size = layout.getChildCount();
215 //                              for (int i = 0; i < size; i++) {
216 //                                      IconImageView vv = (IconImageView) layout.getChildAt(i);
217 //                                      vv.getHitRect(rect);
218 //                                      if (rect.contains(x - layout.getLeft(),
219 //                                                      y - layout.getLeft())) {
220 //                                              dest = vv;
221 //                                              dest.setAlpha(32);
222 //                                              break;
223 //                                      }
224 //                              }
225 //                      } else {
226 //                              Rect rect = new Rect();
227 //
228 //                              dest.getHitRect(rect);
229 //                              if (!rect.contains(x - layout.getLeft(), y - layout.getLeft())) {
230 //                                      dest.setAlpha(255);
231 //                                      dest = null;
232 //                              }
233 //                      }
234 //              } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
235 //                      offsetX = x;
236 //                      offsetY = y;
237 //                      // TODO
238 //                      currentX = obj.getLeft();
239 //                      currentY = obj.getTop();
240 //
241 //                      target.setColorFilter(Color.RED, Mode.LIGHTEN);
242 //                      
243 //                      scrollView.setScrollable(false);
244 //                      return false;
245 //              } else if (event.getAction() == MotionEvent.ACTION_UP) {
246 //                      if (!longClickFlg) {
247 //                              return false;
248 //                      }
249 //                      obj.setAnimation(anime);
250 //                      obj.startAnimation(anime);
251 //                      // obj.setVisibility(View.GONE);
252 //                      if (dest == null) {
253 //                              // \8fÁ\82·\8fê\8d\87
254 //                              // layout.removeView(obj);
255 //
256 //                              // \83L\83\83\83\93\83Z\83\8b
257 //                              int srcX = target.getInitX();
258 //                              int srcY = target.getInitY();
259 //                              target.layout(srcX, srcY, srcX + target.getWidth(), srcY
260 //                                              + target.getHeight());
261 //                              target.setAlpha(255);
262 //                      } else {
263 //                              int srcX = target.getInitX();
264 //                              int srcY = target.getInitY();
265 //                              int dstX = dest.getInitX();
266 //                              int dstY = dest.getInitY();
267 //
268 //                              target.layout(dstX, dstY, dstX + target.getWidth(), dstY
269 //                                              + target.getHeight());
270 //                              target.init(dstX, dstY);
271 //                              target.setAlpha(255);
272 //                              dest.layout(srcX, srcY, srcX + dest.getWidth(),
273 //                                              srcY + dest.getHeight());
274 //                              dest.init(srcX, srcY);
275 //                              dest.setAlpha(255);
276 //                      }
277 //
278 //                      // bt2.getHitRect(rect);
279 //                      // if (rect.contains(x, y)) {
280 //                      // isBt2Click = true;
281 //                      // }
282 //                      longClickFlg = false;
283 //              }
284 //
285 //              return true;
286 //      }
287 //
288 //      @Override
289 //      public boolean onLongClick(View view) {
290 //              if (!(view instanceof IconImageView)) {
291 //                      return true;
292 //              }
293 //              IconImageView v = (IconImageView) view;
294 //              v.setAlpha(128);
295 //              v.clearColorFilter();
296 //
297 //              longClickFlg = true;
298 //              return true;
299 //      }
300 }