Search in sources :

Example 1 with IdleHandler

use of android.os.MessageQueue.IdleHandler in project android_frameworks_base by DirtyUnicorns.

the class BaseActivity method addListenerForLaunchCompletion.

/**
     * Closes the activity when it's idle.
     */
private void addListenerForLaunchCompletion() {
    addEventListener(new EventListener() {

        @Override
        public void onDirectoryNavigated(Uri uri) {
        }

        @Override
        public void onDirectoryLoaded(Uri uri) {
            removeEventListener(this);
            getMainLooper().getQueue().addIdleHandler(new IdleHandler() {

                @Override
                public boolean queueIdle() {
                    // close the activity once idle, and notify the testing activity.
                    if (getIntent().getBooleanExtra(EXTRA_BENCHMARK, false) && BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
                        setResult(RESULT_OK);
                        finish();
                    }
                    Metrics.logStartupMs(BaseActivity.this, (int) (new Date().getTime() - mStartTime));
                    // Remove the idle handler.
                    return false;
                }
            });
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                }
            });
        }
    });
}
Also used : IdleHandler(android.os.MessageQueue.IdleHandler) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Uri(android.net.Uri) Date(java.util.Date)

Example 2 with IdleHandler

use of android.os.MessageQueue.IdleHandler in project android_frameworks_base by AOSPA.

the class BaseActivity method addListenerForLaunchCompletion.

/**
     * Closes the activity when it's idle.
     */
private void addListenerForLaunchCompletion() {
    addEventListener(new EventListener() {

        @Override
        public void onDirectoryNavigated(Uri uri) {
        }

        @Override
        public void onDirectoryLoaded(Uri uri) {
            removeEventListener(this);
            getMainLooper().getQueue().addIdleHandler(new IdleHandler() {

                @Override
                public boolean queueIdle() {
                    // close the activity once idle, and notify the testing activity.
                    if (getIntent().getBooleanExtra(EXTRA_BENCHMARK, false) && BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
                        setResult(RESULT_OK);
                        finish();
                    }
                    Metrics.logStartupMs(BaseActivity.this, (int) (new Date().getTime() - mStartTime));
                    // Remove the idle handler.
                    return false;
                }
            });
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                }
            });
        }
    });
}
Also used : IdleHandler(android.os.MessageQueue.IdleHandler) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Uri(android.net.Uri) Date(java.util.Date)

Example 3 with IdleHandler

use of android.os.MessageQueue.IdleHandler in project double-espresso by JakeWharton.

the class GoogleInstrumentation method onCreate.

/**
   * Sets up intent spying, lifecycle monitoring, and argument registry.
   *
   * Subclasses must call up to onCreate(). This oncreate method does not call start()
   * it is the subclasses responsibility to call start if it desires.
   */
@Override
public void onCreate(Bundle arguments) {
    Log.i(LOG_TAG, "Instrumentation Started!");
    tryLoadingIntentSpy();
    InstrumentationRegistry.registerInstance(this);
    ActivityLifecycleMonitorRegistry.registerInstance(lifecycleMonitor);
    handlerForMainLooper = new Handler(Looper.getMainLooper());
    mainThread = Thread.currentThread();
    executorService = Executors.newCachedThreadPool();
    Looper.myQueue().addIdleHandler(idleHandler);
    super.onCreate(arguments);
}
Also used : Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler)

Example 4 with IdleHandler

use of android.os.MessageQueue.IdleHandler in project platform_frameworks_base by android.

the class BaseActivity method addListenerForLaunchCompletion.

/**
     * Closes the activity when it's idle.
     */
private void addListenerForLaunchCompletion() {
    addEventListener(new EventListener() {

        @Override
        public void onDirectoryNavigated(Uri uri) {
        }

        @Override
        public void onDirectoryLoaded(Uri uri) {
            removeEventListener(this);
            getMainLooper().getQueue().addIdleHandler(new IdleHandler() {

                @Override
                public boolean queueIdle() {
                    // close the activity once idle, and notify the testing activity.
                    if (getIntent().getBooleanExtra(EXTRA_BENCHMARK, false) && BENCHMARK_TESTING_PACKAGE.equals(getCallingPackage())) {
                        setResult(RESULT_OK);
                        finish();
                    }
                    Metrics.logStartupMs(BaseActivity.this, (int) (new Date().getTime() - mStartTime));
                    // Remove the idle handler.
                    return false;
                }
            });
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                }
            });
        }
    });
}
Also used : IdleHandler(android.os.MessageQueue.IdleHandler) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Uri(android.net.Uri) Date(java.util.Date)

Example 5 with IdleHandler

use of android.os.MessageQueue.IdleHandler in project double-espresso by JakeWharton.

the class LooperIdlingResource method registerIdleTransitionCallback.

@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
    this.resourceCallback = resourceCallback;
    // on main thread here.
    queueInterrogator = new QueueInterrogator(monitoredLooper);
    // must load idle handlers from monitored looper thread.
    IdleHandler idleHandler = new ResourceCallbackIdleHandler(resourceCallback, queueInterrogator, monitoredHandler);
    checkState(monitoredHandler.postAtFrontOfQueue(new Initializer(idleHandler)), "Monitored looper exiting.");
}
Also used : IdleHandler(android.os.MessageQueue.IdleHandler)

Aggregations

IdleHandler (android.os.MessageQueue.IdleHandler)7 Handler (android.os.Handler)6 Uri (android.net.Uri)5 Date (java.util.Date)5