android.app.Instrumentation.runOnMainSync()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中android.app.Instrumentation.runOnMainSync()方法的一些代码示例,展示了Instrumentation.runOnMainSync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.runOnMainSync()方法的具体详情如下:
包路径:android.app.Instrumentation
类名称:Instrumentation
方法名:runOnMainSync

Instrumentation.runOnMainSync介绍

暂无

代码示例

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public void runOnMainSync(Runnable runner) {
  base.runOnMainSync(runner);
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Clicks an ActionBar Home/Up button.
 */
public void clickOnActionBarHomeButton() {
  if(config.commandLogging){
    Log.d(config.commandLoggingTag, "clickOnActionBarHomeButton()");
  }
  
  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      clicker.clickOnActionBarHomeButton();
    }
  });
}

代码示例来源:origin: RobotiumTech/robotium

/**
 * Unlocks the lock screen.
 */
public void unlockScreen(){
  if(config.commandLogging){
    Log.d(config.commandLoggingTag, "unlockScreen()");
  }
  
  final Activity activity = activityUtils.getCurrentActivity(false);
  instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
      if(activity != null){
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
      }
    }
  });
}

代码示例来源:origin: RobotiumTech/robotium

public void doScreenshot() {
  View v = getScreenshotView();
  if(v == null) keepRunning = false;
  String final_name = name+"_"+seqno;
  ScreenshotRunnable r = new ScreenshotRunnable(v, final_name, quality);
  Log.d(LOG_TAG, "taking screenshot "+final_name);
  Activity activity = activityUtils.getCurrentActivity(false);
  if(activity != null){
    activity.runOnUiThread(r);
  }
  else {
    instrumentation.runOnMainSync(r);
  }
}

代码示例来源:origin: facebook/litho

/** Set the Component for the Activity to display. */
public void setComponent(final Component component) {
 final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
 instrumentation.runOnMainSync(
   new Runnable() {
    @Override
    public void run() {
     getActivity().setComponent(component);
    }
   });
 instrumentation.waitForIdleSync();
}

代码示例来源:origin: facebook/litho

/** Set ComponentTree for the Activity to display. */
public void setComponentTree(final ComponentTree componentTree) {
 final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
 instrumentation.runOnMainSync(
   new Runnable() {
    @Override
    public void run() {
     getActivity().setComponentTree(componentTree);
    }
   });
 instrumentation.waitForIdleSync();
}

代码示例来源:origin: square/leakcanary

public static void addToBackstack(final TestActivity activity) {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override public void run() {
   activity.getSupportFragmentManager()
     .beginTransaction()
     .addToBackStack(null)
     .replace(R.id.fragments, new ViewLeakingFragment())
     .commit();
  }
 });
}

代码示例来源:origin: square/leakcanary

public static void add(final TestActivity activity) {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override public void run() {
   leakingFragment = new LeakingFragment();
   activity.getSupportFragmentManager()
     .beginTransaction()
     .add(0, leakingFragment)
     .commitNow();
  }
 });
}

代码示例来源:origin: facebook/litho

/** Skip the given amount of frames */
 public void stepAnimationFrames(final int numFrames) {
  InstrumentationRegistry.getInstrumentation()
    .runOnMainSync(
      new Runnable() {
       @Override
       public void run() {
        mFakeTimingSource.step(numFrames);
       }
      });

  InstrumentationRegistry.getInstrumentation().waitForIdleSync();
 }
}

代码示例来源:origin: h6ah4i/android-advancedrecyclerview

public final void runOnMainSync(Runnable action) {
  InstrumentationRegistry.getInstrumentation().runOnMainSync(action);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Before
public void init() {
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   LayoutInflater inflater=LayoutInflater
     .from(InstrumentationRegistry.getTargetContext());
   root=inflater.inflate(R.layout.add, null);
  }
 });
 root.measure(800, 480);
 root.layout(0, 0, 800, 480);
 field=root.findViewById(R.id.title);
}

代码示例来源:origin: roughike/BottomBar

@Test
@UiThreadTest
public void whenTabWithBadgeClicked_BadgeIsHidden() {
  InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
    @Override
    public void run() {
      bottomBar.selectTabWithId(com.roughike.bottombar.test.R.id.tab_nearby);
      assertFalse(nearby.badge.isVisible());
    }
  });
}

代码示例来源:origin: roughike/BottomBar

@Test
@UiThreadTest
public void setOverrideTabSelectionListener_allowingSelection() {
  bottomBar.setTabSelectionInterceptor(tabSelectionInterceptor);
  when(tabSelectionInterceptor.shouldInterceptTabSelection(anyInt(), anyInt())).thenReturn(false);
  BottomBarTab oldTab = bottomBar.getCurrentTab();
  final BottomBarTab newTab = bottomBar.getTabAtPosition(2);
  getInstrumentation().runOnMainSync(new Runnable() {
    @Override
    public void run() {
      newTab.performClick();
    }
  });
  verify(tabSelectionInterceptor, times(1)).shouldInterceptTabSelection(oldTab.getId(), newTab.getId());
  assertSame(bottomBar.getCurrentTab(), newTab);
}

代码示例来源:origin: roughike/BottomBar

@Test
@UiThreadTest
public void setOverrideTabSelectionListener_whenNoListenerSet() {
  bottomBar.removeOverrideTabSelectionListener();
  BottomBarTab oldTab = bottomBar.getCurrentTab();
  final BottomBarTab newTab = bottomBar.getTabAtPosition(2);
  getInstrumentation().runOnMainSync(new Runnable() {
    @Override
    public void run() {
      newTab.performClick();
    }
  });
  verify(tabSelectionInterceptor, times(0)).shouldInterceptTabSelection(oldTab.getId(), newTab.getId());
  assertSame(bottomBar.getCurrentTab(), newTab);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Test
public void recreate() {
 stubPick();
 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
  @Override
  public void run() {
   main.getActivity().recreate();
  }
 });
 onView(withId(R.id.view)).check(matches(isEnabled()));
}

相关文章

Instrumentation类方法