Search in sources :

Example 71 with Handler

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();
}
Also used : MediaBrowser(android.media.browse.MediaBrowser) MediaDescription(android.media.MediaDescription) ArrayList(java.util.ArrayList) Handler(android.os.Handler)

Example 72 with Handler

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);
}
Also used : HashMap(java.util.HashMap) Handler(android.os.Handler) Intent(android.content.Intent) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) LinkedList(java.util.LinkedList)

Example 73 with Handler

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);
    }
}
Also used : Handler(android.os.Handler)

Example 74 with Handler

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");
    }
}
Also used : ConditionVariable(android.os.ConditionVariable) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler)

Example 75 with Handler

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);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel)

Aggregations

Handler (android.os.Handler)1906 Message (android.os.Message)254 View (android.view.View)207 Intent (android.content.Intent)174 HandlerThread (android.os.HandlerThread)156 TextView (android.widget.TextView)118 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)85 Context (android.content.Context)71 IntentFilter (android.content.IntentFilter)69 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)63 ComponentName (android.content.ComponentName)57 ImageView (android.widget.ImageView)57 Bundle (android.os.Bundle)56 RecyclerView (android.support.v7.widget.RecyclerView)54 Looper (android.os.Looper)53 File (java.io.File)46 ContentObserver (android.database.ContentObserver)44