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);
}
}
});
}
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);
}
}
});
}
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();
}
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();
}
});
}
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;
}
};
}
Aggregations