java uiautomation_Java UiAutomation類代碼示例

本文整理匯總了Java中android.app.UiAutomation類的典型用法代碼示例。如果您正苦於以下問題:Java UiAutomation類的具體用法?Java UiAutomation怎麽用?Java UiAutomation使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

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

示例1: injectTap

​點讚 3

import android.app.UiAutomation; //導入依賴的package包/類

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)

public static void injectTap(int x, int y, UiAutomation uiAutomation, boolean sync) {

long downTime = System.currentTimeMillis();

MotionEvent eventDown = MotionEvent.obtain(downTime,

downTime, MotionEvent.ACTION_DOWN,

x, y, 0);

eventDown.setSource(InputDevice.SOURCE_TOUCHSCREEN);

Log.d(TAG, "Injecting " + eventDown);

if (!uiAutomation.injectInputEvent(eventDown, sync)) {

Log.d(TAG, "Injection failed");

}

MotionEvent eventUp = MotionEvent.obtain(eventDown);

eventUp.setAction(MotionEvent.ACTION_UP);

Log.d(TAG, "Injecting " + eventUp);

if (!uiAutomation.injectInputEvent(eventUp, sync)) {

Log.d(TAG, "Injection failed");

}

eventDown.recycle();

eventUp.recycle();

}

開發者ID:evernote,項目名稱:kgb,代碼行數:25,

示例2: connect

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public void connect() {

if (mHandlerThread.isAlive()) {

throw new IllegalStateException("Already connected!");

}

mHandlerThread.start();

mUiAutomation = new UiAutomation(mHandlerThread.getLooper(), new UiAutomationConnection());

try {

mUiAutomation.disconnect();

} catch (RuntimeException e) {

// do nothing

}

mUiAutomation.connect();

}

開發者ID:brevent,項目名稱:Brevent,代碼行數:14,

示例3: run

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public void run() {

while (true) {

AccessibilityEvent accessibilityEvent = null;

toastMessages = init();

//return true if the AccessibilityEvent type is NOTIFICATION type

UiAutomation.AccessibilityEventFilter eventFilter = new UiAutomation.AccessibilityEventFilter() {

@Override

public boolean accept(AccessibilityEvent event) {

return event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;

}

};

Runnable runnable = new Runnable() {

@Override

public void run() {

// Not performing any event.

}

};

try {

//wait for AccessibilityEvent filter

accessibilityEvent = UiAutomatorBridge.getInstance().getUiAutomation()

.executeAndWaitForEvent(runnable /*executable event*/, eventFilter /* event to filter*/, 500 /*time out in ms*/);

} catch (Exception ignore) {}

if (accessibilityEvent != null) {

toastMessages = accessibilityEvent.getText();

previousTime = currentTimeMillis();

}

if(stopLooping){

break;

}

}

}

開發者ID:appium,項目名稱:appium-uiautomator2-server,代碼行數:35,

示例4: grantAllPermissions

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

private void grantAllPermissions() {

Context context = InstrumentationRegistry.getTargetContext();

try {

PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);

UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();

for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) {

if ((packageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {

grantReal(uiAutomation, packageInfo.requestedPermissions[i]);

}

}

} catch (PackageManager.NameNotFoundException e) {

Log.w(TAG, "packageInfo not found for: " + context.getPackageName());

}

}

開發者ID:jksiezni,項目名稱:permissive,代碼行數:15,

示例5: grantReal

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

private static void grantReal(UiAutomation automation, String permission) {

try {

String targetPackageName = InstrumentationRegistry.getTargetContext().getPackageName();

ParcelFileDescriptor pfn = automation.executeShellCommand("pm grant " + targetPackageName + " " + permission);

pfn.close();

} catch (IOException e) {

Log.w(TAG, e);

}

}

開發者ID:jksiezni,項目名稱:permissive,代碼行數:10,

示例6: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)

@Override

public UiAutomation getUiAutomation() {

return mBase.getUiAutomation();

}

開發者ID:alibaba,項目名稱:atlas,代碼行數:6,

示例7: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)

@Override

public UiAutomation getUiAutomation() {

return base.getUiAutomation();

}

開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:6,

示例8: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public UiAutomation getUiAutomation() {

return mUiAutomation;

}

開發者ID:brevent,項目名稱:Brevent,代碼行數:4,

示例9: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)

public UiAutomation getUiAutomation() {

return mInstrumentation.getUiAutomation();

}

開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:5,

示例10: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@Override

@TargetApi(18)

public UiAutomation getUiAutomation() {

return this.mBase.getUiAutomation();

}

開發者ID:bunnyblue,項目名稱:ACDD,代碼行數:6,

示例11: start

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Called after all test classes are in place, ready to test

*/

protected void start() {

TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());

try {

collector.addTestClasses(mTestClasses);

} catch (ClassNotFoundException e) {

// will be caught by uncaught handler

throw new RuntimeException(e.getMessage(), e);

}

if (mDebug) {

Debug.waitForDebugger();

}

mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);

mHandlerThread.setDaemon(true);

mHandlerThread.start();

UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();

automationWrapper.connect();

long startTime = SystemClock.uptimeMillis();

TestResult testRunResult = new TestResult();

ResultReporter resultPrinter;

String outputFormat = mParams.getString("outputFormat");

List testCases = collector.getTestCases();

Bundle testRunOutput = new Bundle();

if ("simple".equals(outputFormat)) {

resultPrinter = new SimpleResultPrinter(System.out, true);

} else {

resultPrinter = new WatcherResultPrinter(testCases.size());

}

try {

automationWrapper.setRunAsMonkey(mMonkey);

mUiDevice = MyUiDevice.getInstance();

UiAutomation uiAutomation = automationWrapper.getUiAutomation();

mUiDevice.initialize(new ShellUiAutomatorBridge(uiAutomation));

mUiDevice.setUiAutomation(uiAutomation);

String traceType = mParams.getString("traceOutputMode");

if (traceType != null) {

Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);

if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {

String filename = mParams.getString("traceLogFilename");

if (filename == null) {

throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter");

}

Tracer.getInstance().setOutputFilename(filename);

}

Tracer.getInstance().setOutputMode(mode);

}

// add test listeners

testRunResult.addListener(resultPrinter);

// add all custom listeners

for (TestListener listener : mTestListeners) {

testRunResult.addListener(listener);

}

// run tests for realz!

for (TestCase testCase : testCases) {

prepareTestCase(testCase);

testCase.run(testRunResult);

}

} catch (Throwable t) {

// catch all exceptions so a more verbose error message can be outputted

resultPrinter.printUnexpectedError(t);

} finally {

long runTime = SystemClock.uptimeMillis() - startTime;

resultPrinter.print(testRunResult, runTime, testRunOutput);

automationWrapper.disconnect();

automationWrapper.setRunAsMonkey(false);

mHandlerThread.quit();

}

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:75,

示例12: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public UiAutomation getUiAutomation() {

return this.mAutomation;

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:4,

示例13: setUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public void setUiAutomation(UiAutomation uiauto) {

this.mAutomation = uiauto;

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:4,

示例14: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public UiAutomation getUiAutomation() {

return (UiAutomation)getField(CLASS_UI_AUTOMATOR_BRIDGE, FIELD_UI_AUTOMATOR, uiAutomatorBridge);

}

開發者ID:appium,項目名稱:appium-uiautomator2-server,代碼行數:4,

示例15: KeyboardTypeAction

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public KeyboardTypeAction(UiAutomation uiAutomation) {

this.uiAutomation = uiAutomation;

}

開發者ID:evernote,項目名稱:kgb,代碼行數:4,

示例16: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@Override

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)

public UiAutomation getUiAutomation() {

return targetInstrumentation.getUiAutomation();

}

開發者ID:cantalou,項目名稱:AndroidSkinChange,代碼行數:6,

示例17: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@Override

public UiAutomation getUiAutomation() {

// TODO Auto-generated method stub

return mBase.getUiAutomation();

}

開發者ID:luoqii,項目名稱:ApkLauncher,代碼行數:6,

示例18: getUiAutomation

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

@TargetApi(18)

public UiAutomation getUiAutomation() {

return this.mBase.getUiAutomation();

}

開發者ID:achellies,項目名稱:AtlasForAndroid,代碼行數:5,

示例19: testAirplaneModeToOn

​點讚 2

import android.app.UiAutomation; //導入依賴的package包/類

public void testAirplaneModeToOn() {

UiAutomation uiAutomation = getInstrumentation().getUiAutomation();

// Activityの起動を監視するリスナーをセット

mMainLaunched = false;

uiAutomation

.setOnAccessibilityEventListener(new OnAccessibilityEventListener() {

@Override

public void onAccessibilityEvent(AccessibilityEvent event) {

if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {

// ウィンドウのコンテンツが変わった

if (TARGET_PKG.equals(event.getPackageName())) {

// MainActivityが起動した

mMainLaunched = true;

}

}

}

});

// MainActivity起動

Activity target = launchActivity(TARGET_PKG, MainActivity.class, null);

try {

// MainActivity起動待ち

do {

Thread.sleep(1000);

} while (!mMainLaunched);

// 機內モードをOnにする

// Settingsの起動

Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

getInstrumentation().getContext().startActivity(intent);

// Settingsの起動待ち

AccessibilityNodeInfo root;

while (true) {

root = uiAutomation.getRootInActiveWindow();

if (root != null && SETTINGS_PKG.equals(root.getPackageName())) {

break;

} else {

Thread.sleep(1000);

}

}

// ボタンを押す

List list = root

.findAccessibilityNodeInfosByViewId("android:id/list");

AccessibilityNodeInfo listViewInfo = list.get(0);

AccessibilityNodeInfo airplaneModeView = listViewInfo.getChild(0);

List checkList = airplaneModeView

.findAccessibilityNodeInfosByViewId("android:id/checkbox");

AccessibilityNodeInfo airplaneModeCheck = checkList.get(0);

if (!airplaneModeCheck.isChecked()) {

airplaneModeView.performAction(AccessibilityNodeInfo.ACTION_CLICK);

}

// Backキーを押してSettingsの終了

uiAutomation.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);

// 機內モード反映待ち

Thread.sleep(10000);

// TextViewの文字列検証

String expected = target

.getString(org.techbooster.uiautomationsample.R.string.airplane_mode_off);

TextView textView = (TextView) target

.findViewById(org.techbooster.uiautomationsample.R.id.text_view);

assertEquals(expected, textView.getText().toString());

} catch (Exception e) {

fail(e.getMessage());

e.printStackTrace();

} finally {

if (target != null) {

target.finish();

}

}

}

開發者ID:TechBooster,項目名稱:effective_android_sample,代碼行數:78,

示例20: setRotationRight

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Rotates right and also freezes rotation in that position by

* disabling the sensors. If you want to un-freeze the rotation

* and re-enable the sensors see {@link #unfreezeRotation()}. Note

* that doing so may cause the screen contents to rotate

* depending on the current physical position of the test device.

* @throws RemoteException

*/

public void setRotationRight() {

mUiAutomatorBridge.setRotation(UiAutomation.ROTATION_FREEZE_270);

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:12,

示例21: setRotationLeft

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Rotates left and also freezes rotation in that position by

* disabling the sensors. If you want to un-freeze the rotation

* and re-enable the sensors see {@link #unfreezeRotation()}. Note

* that doing so may cause the screen contents to rotate

* depending on the current physical position of the test device.

* @throws RemoteException

*/

public void setRotationLeft() {

mUiAutomatorBridge.setRotation(UiAutomation.ROTATION_FREEZE_90);

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:12,

示例22: setRotationNatural

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Rotates up and also freezes rotation in that position by

* disabling the sensors. If you want to un-freeze the rotation

* and re-enable the sensors see {@link #unfreezeRotation()}. Note

* that doing so may cause the screen contents to rotate

* depending on the current physical position of the test device.

* @throws RemoteException

*/

public void setRotationNatural() {

mUiAutomatorBridge.setRotation(UiAutomation.ROTATION_FREEZE_0);

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:12,

示例23: freezeRotation

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Disables the sensors and freezes the device rotation at its

* current rotation state.

* @throws RemoteException

*/

public void freezeRotation() {

mUiAutomatorBridge.setRotation(UiAutomation.ROTATION_FREEZE_CURRENT);

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:9,

示例24: unfreezeRotation

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* Re-enables the sensors and un-freezes the device rotation

* allowing its contents to rotate with the device physical rotation.

* @throws RemoteException

*/

public void unfreezeRotation() {

mUiAutomatorBridge.setRotation(UiAutomation.ROTATION_UNFREEZE);

}

開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:9,

示例25: KeyboardSwitcher

​點讚 1

import android.app.UiAutomation; //導入依賴的package包/類

/**

* When created manually as an accessibility event delegate

*

* @param baseContext the context this class will use

* @param automation the automation instance use to inject taps

*/

public KeyboardSwitcher(Context baseContext, UiAutomation automation) {

mAutomation = automation;

attachBaseContext(baseContext);

}

開發者ID:evernote,項目名稱:kgb,代碼行數:11,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值