Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - android drag and drop issue

android drag and drop issue

Put your problem here if it does not fit any of the other categories.

android drag and drop issue

Postby saychiz13 » Fri Jun 07, 2013 4:30 pm

I am trying to perfect the drag and drop app which for a week that I've been doing. This is the screenshot:

Image

as you can see, I have 2 droppable objects to drop onto the target.

FYI, this is the code I'm working on:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  @SuppressWarnings({ "deprecation", "unused" })
  2.        public class MainActivity extends Activity{
  3.         /** Called when the activity is first created. */
  4.         ImageView img, img2, img3=null;
  5.         AbsoluteLayout aLayout;
  6.         int status = 0;
  7.         private boolean dragging = false;
  8.     private Rect hitRect = new Rect();
  9.  
  10.    
  11.         @Override
  12.         public void onCreate(Bundle savedInstanceState) {
  13.                 super.onCreate(savedInstanceState);
  14.                 setContentView(R.layout.activity_main);
  15.                 aLayout= (AbsoluteLayout)findViewById(R.id.absLayout);
  16.                
  17.                 img = (ImageView)findViewById(R.id.imageView1);
  18.                 img2 = (ImageView)findViewById(R.id.imageView2);
  19.                 img3 = (ImageView)findViewById(R.id.imageView3);
  20.  
  21.                 img.setOnTouchListener(new OnTouchListener() {
  22.                         @Override
  23.                         public boolean onTouch(View v, MotionEvent event) {
  24.                                 status = 1;
  25.                                 Log.i("ImageStatus","1st image moved" + status);
  26.                                
  27.                                 return false;
  28.                         }
  29.                 });
  30.                
  31.                 img2.setOnTouchListener(new OnTouchListener() {
  32.                         @Override
  33.                         public boolean onTouch(View v, MotionEvent event) {
  34.                                 status = 2;
  35.                                 Log.i("ImageStatus","2nd image moved" + status);
  36.                                
  37.                                 return false;
  38.                         }
  39.                 });
  40.                
  41.                 aLayout.setOnTouchListener(new OnTouchListener() {
  42.                         @Override
  43.                         public boolean onTouch(View v, MotionEvent event) {
  44.                                 // TODO Auto-generated method stub
  45.                                 Log.i("touch", "touched here" + event);
  46.                                 boolean eventConsumed = true;
  47.                                 int x = (int)event.getX();
  48.                     int y = (int)event.getY();
  49.  
  50.                                 if(status == 1) // any event from down and move
  51.                                 {
  52.                                         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
  53.                                                         (int)event.getX()-img.getWidth()/2,
  54.                                                         (int)event.getY()-img.getHeight()/2);
  55.                                         img.setLayoutParams(lp);
  56.  
  57.                                 } else if(status == 2){
  58.                                                 LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
  59.                                                                 (int)event.getX()-img2.getWidth()/2,
  60.                                                                 (int)event.getY()-img2.getHeight()/2);
  61.                                                 img2.setLayoutParams(lp);
  62.                                 } else {
  63.                                         Log.i("Nothing", "Nothing");
  64.                                 }
  65.                                 if(event.getAction()==MotionEvent.ACTION_UP){
  66.                                        
  67.                                         //status = 0;
  68.                                         drop(v, event);
  69.                                        
  70.                                         /*
  71.                                         img.setBackgroundColor(Color.TRANSPARENT);
  72.                                         img2.setBackgroundColor(Color.TRANSPARENT);
  73.                                        
  74.                                         if(status == 1){
  75.                                                 if (dragging) {
  76.                                                         img3.getHitRect(hitRect);
  77.                                                         if (hitRect.contains(x, y)){
  78.                                 setSameAbsoluteLocation(img, img3);
  79.                                 }
  80.                             }
  81.                                         } else if (status == 2){
  82.                                                 if (dragging) {
  83.                                                         img3.getHitRect(hitRect);
  84.                                                         if (hitRect.contains(x, y)){
  85.                                 setSameAbsoluteLocation(img2, img3);
  86.                                 }
  87.                                                 }
  88.                                         }
  89.                 } */
  90.                 //dragging = false;
  91.      
  92.                         }
  93.                                
  94.                                 return true;
  95.                         }
  96.                 });
  97.  
  98.         }
  99.        
  100.         private void setSameAbsoluteLocation(View v1, View v2) {
  101.         AbsoluteLayout.LayoutParams alp2 = (AbsoluteLayout.LayoutParams) v2.getLayoutParams();
  102.         setAbsoluteLocation(v1, alp2.x, alp2.y);
  103.         }
  104.  
  105.         private void setAbsoluteLocationCentered(View v, int x, int y) {
  106.         setAbsoluteLocation(v, x - v.getWidth() / 2, y - v.getHeight() / 2);
  107.         }
  108.  
  109.         private void setAbsoluteLocation(View v, int x, int y) {
  110.         AbsoluteLayout.LayoutParams alp = (AbsoluteLayout.LayoutParams) v.getLayoutParams();
  111.         alp.x = x;
  112.         alp.y = y;
  113.         v.setLayoutParams(alp);
  114.         }
  115.  
  116.         private boolean checkHit(MotionEvent event, View hit){      
  117.                 Rect rhit = new Rect(hit.getLeft(), hit.getTop(), hit.getRight(), hit.getBottom());
  118.                 return rhit.contains((int)event.getRawX(), (int)event.getRawY());
  119.         }
  120.  
  121.         private boolean checkHit(View v, View hit){
  122.                 Rect rv = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
  123.                 Rect rhit = new Rect(hit.getLeft(), hit.getTop(), hit.getRight(), hit.getBottom());
  124.                 return rv.intersect(rhit);
  125.         }
  126.  
  127.         private void drop(View v, MotionEvent event){
  128.                 checkHit(v, img3);
  129.                 checkHit(event, img3);
  130.                 // Do some for looping, do some other magic, do what you want
  131.                 if(status == 1){
  132.                         setSameAbsoluteLocation(img, img3);
  133.                 }
  134.                 else if (status == 2){
  135.                         setSameAbsoluteLocation(img2, img3);
  136.                 } else {
  137.                         status = 0;
  138.                 }
  139.         }
  140.  
Parsed in 0.017 seconds, using GeSHi 1.0.8.4


But when I drag away the object onto the drop target, it's just staying there :( How can I let the dropped object return to its default position? I'd truly appreciate your help. Thanks.
saychiz13
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jun 07, 2013 4:21 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests