2015-01-29 13 views

cevap

4

Butonu gerçekleştirerek karmaşık ViewActions yazarak yapılabilir.

public static ViewAction swipeToTop() { 
    return new MySwipeAction(Swipe.FAST, 
     GeneralLocation.CENTER, 
     new CoordinatesProvider() { 
      @Override 
      public float[] calculateCoordinates(View view) { 
       float[] coordinates = GeneralLocation.CENTER.calculateCoordinates(view); 
       coordinates[1] = 0; 
       return coordinates; 
      } 
    }, Press.FINGER); 
} 


public static ViewAction swipeToBottom() { 
    return new MySwipeAction(Swipe.FAST, 
     GeneralLocation.CENTER, 
     new CoordinatesProvider() { 
      @Override 
      public float[] calculateCoordinates(View view) { 
       float[] coordinates = GeneralLocation.CENTER.calculateCoordinates(view); 
       coordinates[1] = view.getContext().getResources().getDisplayMetrics().heightPixels; 
       return coordinates; 
      } 
    }, Press.FINGER); 
} 

MySwipeAction böyle bir şey olabilir

:

public class MySwipeAction implements ViewAction { 
    public MySwipeAction(Swiper swiper, CoordinatesProvider startCoordProvide, CoordinatesProvider endCoordProvide, PrecisionDescriber precDesc) { 
      // store here in class variables to use in perform 
      ... 
    } 

    @Override public Matcher<View> getConstraints() {...} 

    @Override public String getDescription() {...} 

    @Override 
    public void perform(UiController uiController, View view) { 
     ... 
     float[] startCoord = startCoordProvide.calculateCoordinates(view); 
     float[] finalCoord = endCoordProvide.calculateCoordinates(view); 
     float[] precision = precDesc.describePrecision(); 

     Swiper.Status status = Swiper.Status.FAILURE; 

     // you could try this for several times until Swiper.Status is achieved or try count is reached 
     try { 
      status = m_swiper.sendSwipe(uiController, startCoord, finalCoord, precision); 
     } catch (RuntimeException re) { 
      ... 
     } 

     // ensures that the swipe has been run. 
     uiController.loopMainThreadForAtLeast(ViewConfiguration.getPressedStateDuration()); 
    } 
} 

Bunu size yardımcı olabilecek umuyoruz.

+2

çok fazla yorum ve noktaya sahip ... Kodunuzun "tam" örneğine sahipseniz, lütfen göster.Pek çok insan sizinkileri neye gireceklerini bilemez '...' – Morozov

+0

Katılıyorum. Kodunuzda kullanılan değişken tanımları ve atamaları hariç tutmak kafa karıştırıcıdır. Kodun okunmasını zorlaştırırsa, birkaç satırı kaydetmeye değmez. – Project

9

Böyle bir GeneralSwipeAction denediniz mi? @testsingh

new CoordinatesProvider() { 
    @Override 
    public float[] calculateCoordinates(View view) { 
     float[] coordinates = GeneralLocation.CENTER.calculateCoordinates(view); 
     coordinates[1] = 0; 
     return coordinates; 
    } 
} 
0

i hiçbir dışı off-box yöntemi olduğunu düşünüyorum: Anna önce de belirtildiği gibi

private static ViewAction swipeFromTopToBottom() { 
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, 
      GeneralLocation.BOTTOM_CENTER, Press.FINGER); 
} 

Belki, ikinci ve/veya üçüncü parametre için özel bir uygulama sağlamak zorunda "swipeTop" ya da belki en kolay yolu döngü aşağıdaki "swipeBottom" do (en aptalca) benim için çalıştı 012 swipeDown

için

// swipeUp 100 kez, tam tersi xDDD Eğer senin uygulamasında recyclerView kullanın, örneğin

for(int i=0;i<=100;i++){ 
    onView(withText("label")).perform(swipeUp()); 
} 
0

, böyle bir şey kullanabilirsiniz:

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp()) 

veya

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeDown()) 
-1

Ben partiye geç kaldım ama biraz sonra biliyorum Nişanlının sonunda, aşağıdan yukarıya, soldan sağa, vb. - herhangi bir kaynak kimliğine ihtiyaç duymadan - kaydırabilecek bir şey buldum.

İhtiyacımın nedeni, her şeyin tamamen belirsiz olduğu dinamik olarak doldurulmuş bir görünümdü. Aşağıdaki yöntemle tabana kadar kaydırabiliyorum ve hatta sadece bir sayfa aşağı kaydırmak için gecikmeyi değiştirebiliyorum.

static void swiper(int start, int end, int delay) { 
    long downTime = SystemClock.uptimeMillis(); 
    long eventTime = SystemClock.uptimeMillis(); 
    Instrumentation inst = getInstrumentation(); 

    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 500, start, 0); 
    inst.sendPointerSync(event); 
    eventTime = SystemClock.uptimeMillis() + delay; 
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 500, end, 0); 
    inst.sendPointerSync(event); 
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 500, end, 0); 
    inst.sendPointerSync(event); 
    SystemClock.sleep(2000); //The wait is important to scroll 
} 

Ben vs. soldan sağa gerek kalmaz ben (x ekseni olmak 500) orada 500 kodlanmış.

// This swipes all the way to the bottom of the screen 
public static void swipeToBottom(){ 
    swiper(1000, 100, 0) 
} 

// This scrolls down one page at a time 
public static void scrollSlowlyDown(){ 
    swiper(775, 100, 100); 
} 

// This swipes to the top 
public static void swipeToTop(){ 
    swiper(100, 1000, 0); 
} 

// This scrolls up one page at a time 
public static void scrollSlowlyUp(){ 
    swiper(100, 775, 100); 
} 

Ben bunun bu kadar sendeler herkes yardımcı olur umarım - ve

bunu benim yaptığımı yaptım onları aramak için.

+0

neden olmasın emin değilim - bu gayet iyi çalışıyor – Nefariis

+0

ne yazık ki, Android 7 üzerinde çalışan bu hedefe yönelik 26: Bu java.lang.SecurityException: Başka bir uygulamaya enjekte, sadece sistem uygulamalarına verilen INJECT_EVENTS izni gerektirir. – cV2

İlgili konular