Search in sources :

Example 31 with Activity

use of android.app.Activity in project PreLollipopTransition by takahirom.

the class MainActivityTest method testGoSubActivity2.

public void testGoSubActivity2() throws InterruptedException {
    Spoon.screenshot(getActivity(), "init");
    Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(SubActivity2.class.getName(), null, false);
    final ImageView imageView = (ImageView) getActivity().findViewById(R.id.imageView2);
    instrumentation.waitForIdleSync();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            assertTrue(imageView.performClick());
        }
    });
    Activity activity = instrumentation.waitForMonitor(monitor);
    // Verify new activity was shown.
    ANDROID.assertThat(monitor).hasHits(1);
    // Wait for animation
    Thread.sleep(2000l);
    Spoon.screenshot(activity, "sub_activity_shown");
    // subactivity -> mainactivity
    sendKeys(KeyEvent.KEYCODE_BACK);
    // Wait for animation
    Thread.sleep(2000l);
    instrumentation.waitForIdleSync();
    Spoon.screenshot(getActivity(), "main_activity_backed");
}
Also used : Instrumentation(android.app.Instrumentation) Activity(android.app.Activity) ImageView(android.widget.ImageView)

Example 32 with Activity

use of android.app.Activity in project jpHolo by teusink.

the class StatusBar method execute.

/**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback id used when calling back into JavaScript.
     * @return                  True if the action was valid, false otherwise.
     */
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
    Log.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();
    if ("_ready".equals(action)) {
        boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
    }
    if ("show".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        });
        return true;
    }
    if ("hide".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        });
        return true;
    }
    return false;
}
Also used : Window(android.view.Window) PluginResult(org.apache.cordova.PluginResult) Activity(android.app.Activity)

Example 33 with Activity

use of android.app.Activity in project Rutgers-Course-Tracker by tevjef.

the class OrientationChangeAction method perform.

@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);
    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
Also used : Activity(android.app.Activity)

Example 34 with Activity

use of android.app.Activity in project Shuttle by timusus.

the class ShuttleUtilsTest method testOpenShuttleLinkNullInput.

@Test
public void testOpenShuttleLinkNullInput() throws Exception {
    Activity mockActivity = mock(Activity.class);
    String fakePackage = "fake.package.name";
    ShuttleUtils.openShuttleLink(null, null);
    verify(mockActivity, never()).startActivity(any(Intent.class));
    ShuttleUtils.openShuttleLink(mockActivity, null);
    verify(mockActivity, never()).startActivity(any(Intent.class));
    ShuttleUtils.openShuttleLink(null, fakePackage);
    verify(mockActivity, never()).startActivity(any(Intent.class));
}
Also used : Activity(android.app.Activity) Intent(android.content.Intent) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 35 with Activity

use of android.app.Activity in project Shuttle by timusus.

the class ShuttleUtilsTest method testOpenShuttleLinkMarketLink.

@Test
public void testOpenShuttleLinkMarketLink() throws Exception {
    Activity mockActivity = mock(Activity.class);
    String fakePackage = "fake.package.name";
    // Call the method and capture the "fired" intent
    ShuttleUtils.openShuttleLink(mockActivity, fakePackage);
    ArgumentCaptor<Intent> intentCaptor = new ArgumentCaptor<>();
    verify(mockActivity).startActivity(intentCaptor.capture());
    Intent intent = intentCaptor.getValue();
    assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    // Also, I guess ShuttleUtils.isAmazonBuild() needs to be tested or we can't trust this test
    if (ShuttleUtils.isAmazonBuild()) {
        assertThat(intent.getData()).isEqualTo(Uri.parse("amzn://apps/android?p=" + fakePackage));
    } else {
        assertThat(intent.getData()).isEqualTo(Uri.parse("market://details?id=" + fakePackage));
    }
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) Activity(android.app.Activity) Intent(android.content.Intent) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Activity (android.app.Activity)1215 View (android.view.View)206 Test (org.junit.Test)187 Intent (android.content.Intent)184 TextView (android.widget.TextView)88 ArrayList (java.util.ArrayList)62 Bundle (android.os.Bundle)58 Context (android.content.Context)57 ViewGroup (android.view.ViewGroup)50 DialogInterface (android.content.DialogInterface)47 AlertDialog (android.app.AlertDialog)45 Robolectric.buildActivity (org.robolectric.Robolectric.buildActivity)40 LayoutInflater (android.view.LayoutInflater)38 ImageView (android.widget.ImageView)38 Twitter (twitter4j.Twitter)35 AppCompatActivity (android.support.v7.app.AppCompatActivity)34 DisplayMetrics (android.util.DisplayMetrics)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 Robolectric.setupActivity (org.robolectric.Robolectric.setupActivity)28 Uri (android.net.Uri)27