Search in sources :

Example 1 with Runnable

use of java.lang.Runnable in project android_frameworks_base by ParanoidAndroid.

the class DeviceMotionService method sendErrorEvent.

private void sendErrorEvent() {
    assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
    // The spec requires that each listener receives the error event only once.
    if (mHaveSentErrorEvent)
        return;
    mHaveSentErrorEvent = true;
    createHandler();
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
            if (mIsRunning) {
                // The special case of all nulls is used to signify a failure to get data.
                mManager.onMotionChange(null, null, null, 0.0);
            }
        }
    });
}
Also used : Runnable(java.lang.Runnable)

Example 2 with Runnable

use of java.lang.Runnable in project android_frameworks_base by ParanoidAndroid.

the class DeviceOrientationService method sendErrorEvent.

private void sendErrorEvent() {
    assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
    // The spec requires that each listener receives the error event only once.
    if (mHaveSentErrorEvent)
        return;
    mHaveSentErrorEvent = true;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            assert WebViewCore.THREAD_NAME.equals(Thread.currentThread().getName());
            if (mIsRunning) {
                // The special case of all nulls is used to signify a failure to get data.
                mManager.onOrientationChange(null, null, null);
            }
        }
    });
}
Also used : Runnable(java.lang.Runnable)

Example 3 with Runnable

use of java.lang.Runnable in project platform_frameworks_base by android.

the class SvcMonitor method startMonitor.

private void startMonitor(Intent intent) {
    if (tMonitor != null) {
        Log.d(TAG, "thread already active");
        return;
    }
    javaProc = intent.getStringExtra("java");
    halProc = intent.getStringExtra("hal");
    period = intent.getIntExtra("period", 1000);
    if (javaProc == null || halProc == null || period < 100) {
        Log.d(TAG, "Failed starting monitor, invalid arguments.");
        stopSelf();
        return;
    }
    Runnable monitor = new MonitorRunnable(this);
    tMonitor = new Thread(monitor);
    tMonitor.start();
}
Also used : Runnable(java.lang.Runnable) Thread(java.lang.Thread)

Example 4 with Runnable

use of java.lang.Runnable in project platform_frameworks_base by android.

the class MediaPlayer method addSubtitleSource.

/** @hide */
public void addSubtitleSource(InputStream is, MediaFormat format) throws IllegalStateException {
    final InputStream fIs = is;
    final MediaFormat fFormat = format;
    if (is != null) {
        // way to implement timeouts in the future.
        synchronized (mOpenSubtitleSources) {
            mOpenSubtitleSources.add(is);
        }
    } else {
        Log.w(TAG, "addSubtitleSource called with null InputStream");
    }
    getMediaTimeProvider();
    // process each subtitle in its own thread
    final HandlerThread thread = new HandlerThread("SubtitleReadThread", Process.THREAD_PRIORITY_BACKGROUND + Process.THREAD_PRIORITY_MORE_FAVORABLE);
    thread.start();
    Handler handler = new Handler(thread.getLooper());
    handler.post(new Runnable() {

        private int addTrack() {
            if (fIs == null || mSubtitleController == null) {
                return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
            }
            SubtitleTrack track = mSubtitleController.addTrack(fFormat);
            if (track == null) {
                return MEDIA_INFO_UNSUPPORTED_SUBTITLE;
            }
            // TODO: do the conversion in the subtitle track
            Scanner scanner = new Scanner(fIs, "UTF-8");
            String contents = scanner.useDelimiter("\\A").next();
            synchronized (mOpenSubtitleSources) {
                mOpenSubtitleSources.remove(fIs);
            }
            scanner.close();
            synchronized (mIndexTrackPairs) {
                mIndexTrackPairs.add(Pair.<Integer, SubtitleTrack>create(null, track));
            }
            Handler h = mTimeProvider.mEventHandler;
            int what = TimeProvider.NOTIFY;
            int arg1 = TimeProvider.NOTIFY_TRACK_DATA;
            Pair<SubtitleTrack, byte[]> trackData = Pair.create(track, contents.getBytes());
            Message m = h.obtainMessage(what, arg1, 0, trackData);
            h.sendMessage(m);
            return MEDIA_INFO_EXTERNAL_METADATA_UPDATE;
        }

        public void run() {
            int res = addTrack();
            if (mEventHandler != null) {
                Message m = mEventHandler.obtainMessage(MEDIA_INFO, res, 0, null);
                mEventHandler.sendMessage(m);
            }
            thread.getLooper().quitSafely();
        }
    });
}
Also used : MediaFormat(android.media.MediaFormat) Scanner(java.util.Scanner) HandlerThread(android.os.HandlerThread) Message(android.os.Message) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Runnable(java.lang.Runnable) Handler(android.os.Handler) Pair(android.util.Pair)

Example 5 with Runnable

use of java.lang.Runnable in project XobotOS by xamarin.

the class DeviceMotionService method createHandler.

private void createHandler() {
    if (mHandler != null) {
        return;
    }
    mHandler = new Handler();
    mUpdateRunnable = new Runnable() {

        @Override
        public void run() {
            assert mIsRunning;
            mManager.onMotionChange(new Double(mLastAcceleration[0]), new Double(mLastAcceleration[1]), new Double(mLastAcceleration[2]), INTERVAL_MILLIS);
            mHandler.postDelayed(mUpdateRunnable, INTERVAL_MILLIS);
            // Now that we have successfully sent some data, reset whether we've sent an error.
            mHaveSentErrorEvent = false;
        }
    };
}
Also used : Runnable(java.lang.Runnable) Handler(android.os.Handler)

Aggregations

Runnable (java.lang.Runnable)27 Handler (android.os.Handler)17 HandlerThread (android.os.HandlerThread)15 Context (android.content.Context)10 MediaFormat (android.media.MediaFormat)10 Message (android.os.Message)10 Pair (android.util.Pair)10 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 AssetFileDescriptor (android.content.res.AssetFileDescriptor)5 SubtitleController (android.media.SubtitleController)5 Anchor (android.media.SubtitleController.Anchor)5 RenderingWidget (android.media.SubtitleTrack.RenderingWidget)5 ErrnoException (android.system.ErrnoException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileDescriptor (java.io.FileDescriptor)5 IOException (java.io.IOException)5 Thread (java.lang.Thread)5 Scanner (java.util.Scanner)5 Override (java.lang.Override)1