Search in sources :

Example 1 with ScriptInterface

use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.

the class AppUtils method getPackageName.

@ScriptInterface
public String getPackageName(String appName) {
    PackageManager packageManager = mContext.getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo applicationInfo : installedApplications) {
        if (packageManager.getApplicationLabel(applicationInfo).toString().equals(appName)) {
            return applicationInfo.packageName;
        }
    }
    return null;
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface)

Example 2 with ScriptInterface

use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.

the class AppUtils method launchPackage.

@ScriptInterface
public boolean launchPackage(String packageName) {
    try {
        PackageManager packageManager = mContext.getPackageManager();
        mContext.startActivity(packageManager.getLaunchIntentForPackage(packageName).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface)

Example 3 with ScriptInterface

use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.

the class UiSelector method findOne.

@ScriptInterface
public UiObject findOne(long timeout) {
    if (timeout == -1) {
        return untilFindOne();
    }
    UiObjectCollection uiObjectCollection = find();
    long start = SystemClock.uptimeMillis();
    while (uiObjectCollection.empty()) {
        if (Thread.currentThread().isInterrupted()) {
            throw new ScriptInterruptedException();
        }
        if (SystemClock.uptimeMillis() - start > timeout) {
            return null;
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            throw new ScriptInterruptedException();
        }
        uiObjectCollection = find();
    }
    return uiObjectCollection.get(0);
}
Also used : UiObjectCollection(com.stardust.automator.UiObjectCollection) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface)

Example 4 with ScriptInterface

use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.

the class UiSelector method find.

@NonNull
@ScriptInterface
public UiObjectCollection find() {
    ensureAccessibilityServiceEnabled();
    AccessibilityNodeInfo root = mAccessibilityBridge.getRootInActiveWindow();
    if (root == null) {
        return UiObjectCollection.EMPTY;
    }
    if (root.getPackageName() != null && mAccessibilityBridge.getConfig().whiteListContains(root.getPackageName().toString())) {
        Log.d(TAG, "package in white list, return null");
        return UiObjectCollection.EMPTY;
    }
    return findOf(UiObject.createRoot(root, mAllocator));
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface) NonNull(android.support.annotation.NonNull)

Example 5 with ScriptInterface

use of com.stardust.autojs.annotation.ScriptInterface in project Auto.js by hyb1996.

the class AppUtils method getAppName.

@ScriptInterface
public String getAppName(String packageName) {
    PackageManager packageManager = mContext.getPackageManager();
    try {
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
        CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
        return appName == null ? null : appName.toString();
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface)

Aggregations

ScriptInterface (com.stardust.autojs.annotation.ScriptInterface)7 PackageManager (android.content.pm.PackageManager)3 Intent (android.content.Intent)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 NonNull (android.support.annotation.NonNull)1 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)1 ScriptInterruptedException (com.stardust.autojs.runtime.exception.ScriptInterruptedException)1 UiObjectCollection (com.stardust.automator.UiObjectCollection)1