// Path: app/src/androidTest/java/com/tale/prettybundle/sample/espresso/ExtViewActions.java
// public class ExtViewActions {
// 
//     /**
//      * Perform action of waiting for a specific view id.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
//      *
//      * @param viewId
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitId(final int viewId, final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return isRoot();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 final long startTime = System.currentTimeMillis();
//                 final long endTime = startTime + millis;
//                 final Matcher<View> viewMatcher = withId(viewId);
// 
//                 do {
//                     for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
//                         // found view with required ID
//                         if (viewMatcher.matches(child)) {
//                             return;
//                         }
//                     }
// 
//                     uiController.loopMainThreadForAtLeast(50);
//                 }
//                 while (System.currentTimeMillis() < endTime);
// 
//                 // timeout happens
//                 throw new PerformException.Builder()
//                         .withActionDescription(this.getDescription())
//                         .withViewDescription(HumanReadables.describe(view))
//                         .withCause(new TimeoutException())
//                         .build();
//             }
//         };
//     }
// 
//     /**
//      * Perform action of waiting for a specific time. Useful when you need
//      * to wait for animations to end and Espresso fails at waiting.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15));
//      *
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitAtLeast(final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for at least " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 uiController.loopMainThreadForAtLeast(millis);
//             }
//         };
//     }
// 
//     public static ViewAction waitForSoftKeyboard() {
//         return waitAtLeast(500);
//     }
// 
//     public static ViewAction swipeTop() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
//     }
// 
//     public static ViewAction swipeBottom() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
//     }
// 
//     /**
//      * Perform action of waiting until UI thread is free.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitUntilIdle());
//      *
//      * @return
//      */
//     public static ViewAction waitUntilIdle() {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait until UI thread is free";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//             }
//         };
//     }
// 
// }


import android.support.test.espresso.Espresso;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.CheckBox;
import com.tale.prettybundle.sample.espresso.ExtViewActions;
package com.tale.prettybundle.sample;



/**
 * Created by tale on 2/18/15.
 */
public class InjectPrimaryTypeExtrasTest extends ActivityInstrumentationTestCase2<TestPrimaryTypeSetterActivity> {

    private TestPrimaryTypeSetterActivity activity;

    public InjectPrimaryTypeExtrasTest() {
        super(TestPrimaryTypeSetterActivity.class);
    }

    @Override public void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
    }

    public void testStartPrimaryTypeDisplayWithExtras() throws Exception {
        getInstrumentation().runOnMainSync(new Runnable() {
            @Override public void run() {
                ((CheckBox) activity.findViewById(R.id.cbBoolean)).setChecked(true);
            }
        });
        final String integerExtra = "1";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_int)).perform(ViewActions.typeText(integerExtra), ViewActions.pressImeActionButton());
        final String longExtra = "2";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_long)).perform(ViewActions.typeText(longExtra), ViewActions.pressImeActionButton());
        final String floatExtra = "3.4";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_float)).perform(ViewActions.typeText(floatExtra), ViewActions.pressImeActionButton());
        final String doubleExtra = "5.6";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_double)).perform(ViewActions.typeText(doubleExtra), ViewActions.pressImeActionButton());
        final String stringExtra = "String value";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_string)).perform(ViewActions.typeText(stringExtra), ViewActions.pressImeActionButton());
        final String charSequenceExtra = "CharSequence value";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_char_sequence)).perform(ViewActions.typeText(charSequenceExtra), ViewActions.pressImeActionButton());

        Espresso.closeSoftKeyboard();

// Path: app/src/androidTest/java/com/tale/prettybundle/sample/espresso/ExtViewActions.java
// public class ExtViewActions {
// 
//     /**
//      * Perform action of waiting for a specific view id.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
//      *
//      * @param viewId
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitId(final int viewId, final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return isRoot();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 final long startTime = System.currentTimeMillis();
//                 final long endTime = startTime + millis;
//                 final Matcher<View> viewMatcher = withId(viewId);
// 
//                 do {
//                     for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
//                         // found view with required ID
//                         if (viewMatcher.matches(child)) {
//                             return;
//                         }
//                     }
// 
//                     uiController.loopMainThreadForAtLeast(50);
//                 }
//                 while (System.currentTimeMillis() < endTime);
// 
//                 // timeout happens
//                 throw new PerformException.Builder()
//                         .withActionDescription(this.getDescription())
//                         .withViewDescription(HumanReadables.describe(view))
//                         .withCause(new TimeoutException())
//                         .build();
//             }
//         };
//     }
// 
//     /**
//      * Perform action of waiting for a specific time. Useful when you need
//      * to wait for animations to end and Espresso fails at waiting.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitAtLeast(Sampling.SECONDS_15));
//      *
//      * @param millis
//      * @return
//      */
//     public static ViewAction waitAtLeast(final long millis) {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait for at least " + millis + " millis.";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//                 uiController.loopMainThreadForAtLeast(millis);
//             }
//         };
//     }
// 
//     public static ViewAction waitForSoftKeyboard() {
//         return waitAtLeast(500);
//     }
// 
//     public static ViewAction swipeTop() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
//     }
// 
//     public static ViewAction swipeBottom() {
//         return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
//     }
// 
//     /**
//      * Perform action of waiting until UI thread is free.
//      * <p/>
//      * E.g.:
//      * onView(isRoot()).perform(waitUntilIdle());
//      *
//      * @return
//      */
//     public static ViewAction waitUntilIdle() {
//         return new ViewAction() {
//             @Override
//             public Matcher<View> getConstraints() {
//                 return anything();
//             }
// 
//             @Override
//             public String getDescription() {
//                 return "wait until UI thread is free";
//             }
// 
//             @Override
//             public void perform(final UiController uiController, final View view) {
//                 uiController.loopMainThreadUntilIdle();
//             }
//         };
//     }
// 
// }


// Path: app/src/androidTest/java/com/tale/prettybundle/sample/InjectPrimaryTypeExtrasTest.java
import android.support.test.espresso.Espresso;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.CheckBox;
import com.tale.prettybundle.sample.espresso.ExtViewActions;

package com.tale.prettybundle.sample;



/**
 * Created by tale on 2/18/15.
 */
public class InjectPrimaryTypeExtrasTest extends ActivityInstrumentationTestCase2<TestPrimaryTypeSetterActivity> {

    private TestPrimaryTypeSetterActivity activity;

    public InjectPrimaryTypeExtrasTest() {
        super(TestPrimaryTypeSetterActivity.class);
    }

    @Override public void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
    }

    public void testStartPrimaryTypeDisplayWithExtras() throws Exception {
        getInstrumentation().runOnMainSync(new Runnable() {
            @Override public void run() {
                ((CheckBox) activity.findViewById(R.id.cbBoolean)).setChecked(true);
            }
        });
        final String integerExtra = "1";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_int)).perform(ViewActions.typeText(integerExtra), ViewActions.pressImeActionButton());
        final String longExtra = "2";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_long)).perform(ViewActions.typeText(longExtra), ViewActions.pressImeActionButton());
        final String floatExtra = "3.4";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_float)).perform(ViewActions.typeText(floatExtra), ViewActions.pressImeActionButton());
        final String doubleExtra = "5.6";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_double)).perform(ViewActions.typeText(doubleExtra), ViewActions.pressImeActionButton());
        final String stringExtra = "String value";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_string)).perform(ViewActions.typeText(stringExtra), ViewActions.pressImeActionButton());
        final String charSequenceExtra = "CharSequence value";
        Espresso.onView(ViewMatchers.withHint(R.string.hint_char_sequence)).perform(ViewActions.typeText(charSequenceExtra), ViewActions.pressImeActionButton());

        Espresso.closeSoftKeyboard();

        Espresso.onView(ViewMatchers.withText(R.string.submit)).perform(ExtViewActions.waitForSoftKeyboard(), ViewActions.scrollTo(), ViewActions.click());