Search in sources :

Example 6 with IdleHandler

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

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 7 with IdleHandler

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

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)

Aggregations

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