use of android.os.Handler in project platform_frameworks_base by android.
the class BrowserService method onLoadChildren.
@Override
public void onLoadChildren(final String parentId, final Result<List<MediaBrowser.MediaItem>> result) {
new Handler().postDelayed(new Runnable() {
public void run() {
final ArrayList<MediaBrowser.MediaItem> list = new ArrayList();
for (int i = 0; i < 10; i++) {
MediaDescription.Builder bob = new MediaDescription.Builder();
bob.setTitle("Title " + i);
bob.setSubtitle("Summary " + i);
bob.setMediaId(Uri.withAppendedPath(BASE_URI, Integer.toString(i)).toString());
list.add(new MediaBrowser.MediaItem(bob.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(list);
}
}, 2000);
result.detach();
}
use of android.os.Handler in project platform_frameworks_base by android.
the class SoundTriggerTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure that this activity can punch through the lockscreen if needed.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDebugView = (TextView) findViewById(R.id.console);
mScrollView = (ScrollView) findViewById(R.id.scroller_id);
mRadioGroup = (RadioGroup) findViewById(R.id.model_group_id);
mPlayTriggerButton = (Button) findViewById(R.id.play_trigger_id);
mDebugView.setText(mDebugView.getText(), TextView.BufferType.EDITABLE);
mDebugView.setMovementMethod(new ScrollingMovementMethod());
mCaptureAudioCheckBox = (CheckBox) findViewById(R.id.caputre_check_box);
mPlayCapturedAudioButton = (Button) findViewById(R.id.play_captured_id);
mHandler = new Handler();
mButtonModelUuidMap = new HashMap();
mModelButtons = new HashMap();
mModelNames = new HashMap();
mModelRadioButtons = new LinkedList();
setVolumeControlStream(AudioManager.STREAM_MUSIC);
// Make sure that the service is started, so even if our activity goes down, we'll still
// have a request for it to run.
startService(new Intent(getBaseContext(), SoundTriggerTestService.class));
// Bind to SoundTriggerTestService.
Intent intent = new Intent(this, SoundTriggerTestService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
use of android.os.Handler in project platform_frameworks_base by android.
the class PlayerController method setListener.
public void setListener(Listener listener) {
mListener = listener;
Log.d(TAG, "Listener set to " + listener + " session is " + mController);
if (mListener != null) {
mHandler = new Handler();
mListener.onConnectionStateChange(mController == null ? STATE_DISCONNECTED : STATE_CONNECTED);
}
}
use of android.os.Handler in project platform_frameworks_base by android.
the class ConnectivityServiceTest method waitForIdleHandler.
/**
* Block until the given handler becomes idle, or until timeoutMs has passed.
*/
private static void waitForIdleHandler(HandlerThread handlerThread, int timeoutMs) {
final ConditionVariable cv = new ConditionVariable();
final Handler handler = new Handler(handlerThread.getLooper());
handler.post(() -> cv.open());
if (!cv.block(timeoutMs)) {
fail("HandlerThread " + handlerThread.getName() + " did not become idle after " + timeoutMs + " ms");
}
}
use of android.os.Handler in project platform_frameworks_base by android.
the class BidirectionalAsyncChannel method connect.
public void connect(final Looper looper, final Messenger messenger, final Handler incomingMessageHandler) {
assertEquals("AsyncChannel must be disconnected to connect", ChannelState.DISCONNECTED, mState);
mChannel = new AsyncChannel();
Handler rawMessageHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
Log.d(TAG, "Successfully half connected " + this);
mChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
mState = ChannelState.HALF_CONNECTED;
} else {
Log.d(TAG, "Failed to connect channel " + this);
mState = ChannelState.FAILURE;
mChannel = null;
}
break;
case AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED:
mState = ChannelState.CONNECTED;
Log.d(TAG, "Channel fully connected" + this);
break;
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
mState = ChannelState.DISCONNECTED;
mChannel = null;
Log.d(TAG, "Channel disconnected" + this);
break;
default:
incomingMessageHandler.handleMessage(msg);
break;
}
}
};
mChannel.connect(null, rawMessageHandler, messenger);
}
Aggregations