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;
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;
31 private Animation anime;
38 private boolean longClickFlg = false;
41 public void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
43 setContentView(R.layout.main);
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);
53 Resources r = getResources();
54 Bitmap bmp1 = BitmapFactory.decodeResource(r, R.drawable.android);
55 Bitmap bmp2 = BitmapFactory.decodeResource(r, R.drawable.test2);
57 anime = AnimationUtils.loadAnimation(this, R.anim.sample);
58 anime.setAnimationListener(new AnimationListener() {
59 public void onAnimationStart(Animation animation) {
62 public void onAnimationRepeat(Animation animation) {
65 public void onAnimationEnd(Animation animation) {
67 // bt2.performClick();
68 // isBt2Click = false;
75 // target = (ImageView) findViewById(R.id.ImageView01);
76 // target.setImageBitmap(bmp);
77 // this.target.setOnTouchListener(this);
85 for (int i = 0; i < 4; i++) {
86 Bitmap bmp = (i % 2 == 0) ? bmp1 : bmp2;
87 createIconImageView(bmp, x, y);
91 layout.setMinimumHeight(y * 2 + N);
92 } catch (Exception e) {
97 private void createIconImageView(Bitmap bmp, int x, int y) {
98 IconImageView v = new IconImageView(this);
100 v.setImageBitmap(bmp);
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;
114 v.setLayoutParams(params);
115 // v.setLayoutParams(new ViewGroup.LayoutParams(WC, WC));
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);
122 // layout.addView(v, new ViewGroup.LayoutParams(WC, WC));
123 // v.layout(x, y, x + v.getWidth(), y + v.getHeight());
125 //v.setOnTouchListener(this);
126 //v.setOnLongClickListener(this);
130 protected void onStart() {
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);
140 if (target == null) {
144 Rect rect = new Rect();
145 Point globalOffset = new Point();
146 target.getGlobalVisibleRect(rect, globalOffset);
147 // currentX = startX;
148 // currentY = startY;
151 target.layout(currentX, currentY, currentX + target.getWidth(),
152 currentY + target.getHeight());
156 // layout.removeView(target);
157 // layout.addView(target);
158 target.setSelected(true);
159 IconImageView iv = (IconImageView) target;
160 iv.init(currentX, currentY);
165 public void onClickButton02(View v) {
167 // Toast.makeText(this, "click", Toast.LENGTH_SHORT).show();
168 // Intent intent = new Intent(DDSampleActivity.this, Next.class);
169 // startActivity(intent);
173 // public boolean onTouch(View v, MotionEvent event) {
174 // int x = (int) event.getRawX();
175 // int y = (int) event.getRawY();
178 // if (!(v instanceof IconImageView)) {
181 // IconImageView obj = (IconImageView) v;
183 // if (target == null) {
186 //// scrollView.setOnTouchListener(new OnTouchListener() {
188 //// public boolean onTouch(View v, MotionEvent event) {
192 // } else if (target != obj) {
195 // if (event.getAction() == MotionEvent.ACTION_MOVE) {
196 // if (!longClickFlg) {
199 // int diffX = offsetX - x;
200 // int diffY = offsetY - y;
202 // currentX -= diffX;
203 // currentY -= diffY;
206 // obj.layout(currentX, currentY, currentX + obj.getWidth(), currentY
207 // + obj.getHeight());
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())) {
221 // dest.setAlpha(32);
226 // Rect rect = new Rect();
228 // dest.getHitRect(rect);
229 // if (!rect.contains(x - layout.getLeft(), y - layout.getLeft())) {
230 // dest.setAlpha(255);
234 // } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
238 // currentX = obj.getLeft();
239 // currentY = obj.getTop();
241 // target.setColorFilter(Color.RED, Mode.LIGHTEN);
243 // scrollView.setScrollable(false);
245 // } else if (event.getAction() == MotionEvent.ACTION_UP) {
246 // if (!longClickFlg) {
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);
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);
263 // int srcX = target.getInitX();
264 // int srcY = target.getInitY();
265 // int dstX = dest.getInitX();
266 // int dstY = dest.getInitY();
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);
278 // // bt2.getHitRect(rect);
279 // // if (rect.contains(x, y)) {
280 // // isBt2Click = true;
282 // longClickFlg = false;
289 // public boolean onLongClick(View view) {
290 // if (!(view instanceof IconImageView)) {
293 // IconImageView v = (IconImageView) view;
295 // v.clearColorFilter();
297 // longClickFlg = true;