本文整理匯總了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);
}
示例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);
}
示例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);
}
}
示例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();
}
示例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