slow or fast drag up (scroll) using robotium
Asked Answered
B

2

7

this my code for drag up current screen.

int screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getActivity().getWindowManager().getDefaultDisplay().getHeight();
int fromX, toX, fromY, toY = 0;
fromX = screenWidth/2;
toX = screenWidth/2;
fromY = (screenHeight/2) + (screenHeight/3);
toY = (screenHeight/2) - (screenHeight/3);
int scroll_time = 10000;             
solo.sleep(5000);
    // Drag UP  
solo.drag(fromX, toX, fromY, toY, 40);
Log.d(TAG, "Drag 1");
    // here default origin (x,y = 0,0) is left upper corner

here scroll is working but very slow.

So for fast scroll what changes in this code required ?

Boardinghouse answered 27/9, 2012 at 5:49 Comment(0)
H
9

I faced the same problem, what you need to do is adjust the following line of code,

solo.drag(fromX, toX, fromY, toY, 40); //Change 40 to 10

This will increase your scrolling speed, the lower the step count, the faster is the scrolling!

Hildie answered 27/9, 2012 at 6:51 Comment(1)
Thanks very much Royston Pinto, working on my phone Galaxy Ace well.Boardinghouse
M
0
 public class MainActivity extends Activity  {
 int windowwidth;
 int windowheight;    
 ImageView ima1,ima2;

  private android.widget.RelativeLayout.LayoutParams layoutParams ;
 // private android.widget.RelativeLayout.LayoutParams layoutParams ;
 //private android.widget.RelativeLayout.LayoutParams layoutParams ;           

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     windowwidth = getWindowManager().getDefaultDisplay().getWidth();
     windowheight = getWindowManager().getDefaultDisplay().getHeight();

     System.out.println("width" +windowwidth);
     System.out.println("height" +windowheight);             

     ima1 = (ImageView)findViewById(R.id.imageview1);
     ima1.setOnTouchListener(new View.OnTouchListener() {  

   public boolean onTouch(View v, MotionEvent event) {
   layoutParams = (RelativeLayout.LayoutParams) ima1.getLayoutParams();

     switch(event.getAction())                   
        {
          case MotionEvent.ACTION_DOWN:                          
                break;     

          case MotionEvent.ACTION_MOVE:
                int x_cord = (int) event.getRawX();
                int y_cord = (int) event.getRawY();

          System.out.println("value of x" +x_cord);
          System.out.println("value of y" +y_cord);           

                if (x_cord > windowwidth) {
                    x_cord = windowwidth;
                   }
                if (y_cord > windowheight) {
                    y_cord = windowheight;
                   }
         layoutParams.leftMargin = x_cord-25;
         layoutParams.topMargin = y_cord-25;
         //   layoutParams.rightMargin = x_cord-25;
         //   layoutParams.bottomMargin = y_cord-25;
         ima1.setLayoutParams(layoutParams);
                 break;
           default: break;
          }  
           return true;
        }
     });

     ima2 = (ImageView)findViewById(R.id.imageview2);
     ima2.setOnTouchListener(new View.OnTouchListener() {         

 public boolean onTouch(View v, MotionEvent event) {
     layoutParams = (RelativeLayout.LayoutParams) ima2.getLayoutParams();
          switch(event.getActionMasked())
             {
               case MotionEvent.ACTION_DOWN:
                   break;
               case MotionEvent.ACTION_MOVE:
                   int x_cord = (int) event.getRawX();
                   int y_cord = (int) event.getRawY();

                   System.out.println("value of x1" +x_cord);
               System.out.println("value of y1" +y_cord);                            

                    if (x_cord > windowwidth) {
                        x_cord = windowwidth;
                    }
                    if (y_cord > windowheight) {
                        y_cord = windowheight;
                    }
                    layoutParams.leftMargin = x_cord - 25;
                    layoutParams.topMargin = y_cord - 75;
                    ima2.setLayoutParams(layoutParams);
                    break;
                default: break;
            }
            return true;
        }
    });
   }
 }

see this one it is use full Android Drag and drop images on the Screen?

Mantellone answered 27/9, 2012 at 5:55 Comment(1)
i use robotium for automation, here no user interaction required, no setOnTouchListener required. My above code is working but i want to fast scroll current screen. anyway thanks NagarjunaReddy for your reply and try.Boardinghouse

© 2022 - 2024 — McMap. All rights reserved.