當前位置: 首頁>>代碼示例>>Java>>正文


Java ActivityTestRule.getActivity方法代碼示例

本文整理匯總了Java中android.support.test.rule.ActivityTestRule.getActivity方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityTestRule.getActivity方法的具體用法?Java ActivityTestRule.getActivity怎麽用?Java ActivityTestRule.getActivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.test.rule.ActivityTestRule的用法示例。


在下文中一共展示了ActivityTestRule.getActivity方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rotateScreen

import android.support.test.rule.ActivityTestRule; //導入方法依賴的package包/類
private void rotateScreen(ActivityTestRule<?> activityRule) {
    Context context = InstrumentationRegistry.getTargetContext();
    int orientation = context.getResources().getConfiguration().orientation;

    Activity activity = activityRule.getActivity();
    activity.setRequestedOrientation(
            (orientation == Configuration.ORIENTATION_PORTRAIT) ?
                    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
 
開發者ID:ravidsrk,項目名稱:espresso-utils,代碼行數:10,代碼來源:EspressoUtils.java

示例2: rotateScreen

import android.support.test.rule.ActivityTestRule; //導入方法依賴的package包/類
public static void rotateScreen(ActivityTestRule<? extends Activity> activityRule) {
    Context context = InstrumentationRegistry.getTargetContext();
    int orientation
            = context.getResources().getConfiguration().orientation;

    Activity activity = activityRule.getActivity();
    activity.setRequestedOrientation(
            (orientation == Configuration.ORIENTATION_PORTRAIT) ?
                    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :
                    ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
 
開發者ID:rafaeltoledo,項目名稱:android-keep-testing,代碼行數:12,代碼來源:TestUtils.java

示例3: bringToFront

import android.support.test.rule.ActivityTestRule; //導入方法依賴的package包/類
/**
 * Brings activity to foreground, if it is already launched, or launches it.
 *
 * @param rule activity rule for the activity to operate on.
 * @param <T>  activity class.
 */
public static <T extends Activity> void bringToFront(final ActivityTestRule<T> rule) {
    final T runningActivity = rule.getActivity();
    if (runningActivity == null) {
        rule.launchActivity(null);
    } else {
        // TODO(dotdoom): launch using runningActivity.getIntent()? E.g. to preserve username
        //                and save roundtrip to login window.
        final Intent intent = new Intent(runningActivity, runningActivity.getClass());
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        runningActivity.startActivity(intent);
    }
}
 
開發者ID:dasfoo,項目名稱:delern,代碼行數:19,代碼來源:WaitView.java

示例4: waitForActivityStart

import android.support.test.rule.ActivityTestRule; //導入方法依賴的package包/類
protected Activity waitForActivityStart (final ActivityTestRule rule) {
	final ConditionVariable cv = new ConditionVariable();
	WebViewApp.setCurrentApp(new WebViewApp() {
		private boolean allowEvents = false;

		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			if ("CREATED".equals(eventId.name())) {
				allowEvents = true;
			}

			if (allowEvents && params[0].equals("com.unity3d.ads.test.unit.LifecycleListenerTestActivity")) {
				DeviceLog.debug(eventId.name() + " " + params[0]);

				EVENTS.add(eventId);
				EVENT_PARAMS.add(params);
				EVENT_COUNT++;
			}

			return true;
		}
	});

	new Thread(new Runnable() {
		@Override
		public void run() {
			rule.launchActivity(new Intent());
			cv.open();
		}
	}).start();

	boolean success = cv.block(30000);
	return rule.getActivity();
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:35,代碼來源:LifecycleListenerTest.java

示例5: setUp

import android.support.test.rule.ActivityTestRule; //導入方法依賴的package包/類
/**
 * Sets up the necessary members for this test class from a BackLayerLayoutActivity. Call this
 * method from a {@code @Before} method on the subclass.
 */
public void setUp(
    ActivityTestRule<? extends Activity> activityTestRule,
    @IdRes int coordinatorLayoutId,
    @IdRes int backLayerId,
    @IdRes int contentLayerId,
    @IdRes int primaryButtonId,
    @IdRes int secondaryButtonId,
    @IdRes int primaryExtraContentId,
    @IdRes int secondaryExtraContentId)
    throws Exception {
  this.backLayerId = backLayerId;
  this.contentLayerId = contentLayerId;
  activity = activityTestRule.getActivity();
  resources = activity.getResources();

  coordinatorLayout = activity.findViewById(coordinatorLayoutId);
  backLayer = activity.findViewById(backLayerId);
  contentLayer = activity.findViewById(contentLayerId);
  primaryExtraContent = activity.findViewById(primaryExtraContentId);
  secondaryExtraContent = activity.findViewById(secondaryExtraContentId);

  this.primaryButtonId = primaryButtonId;
  this.secondaryButtonId = secondaryButtonId;
  this.primaryExtraContentId = primaryExtraContentId;
  this.secondaryExtraContentId = secondaryExtraContentId;

  CoordinatorLayout.LayoutParams layoutParams =
      (CoordinatorLayout.LayoutParams) backLayer.getLayoutParams();
  int absoluteGravity =
      Gravity.getAbsoluteGravity(layoutParams.gravity, ViewCompat.getLayoutDirection(backLayer));
  isBackLayerAtEndSide = absoluteGravity == Gravity.RIGHT || absoluteGravity == Gravity.BOTTOM;
  isHorizontal = absoluteGravity == Gravity.RIGHT || absoluteGravity == Gravity.LEFT;

  if (backLayer.isExpanded()) {
    onView(withId(backLayerId)).perform(collapse());
  }
}
 
開發者ID:material-components,項目名稱:material-components-android,代碼行數:42,代碼來源:BackLayerLayoutTestBase.java


注:本文中的android.support.test.rule.ActivityTestRule.getActivity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。