List of usage examples for android.os Message obtain
public static Message obtain(Handler h, int what)
From source file:com.smithdtyler.prettygoodmusicplayer.MusicPlaybackService.java
private void sendUpdateToClients() { List<Messenger> toRemove = new ArrayList<Messenger>(); synchronized (mClients) { for (Messenger client : mClients) { Message msg = Message.obtain(null, MSG_SERVICE_STATUS); Bundle b = new Bundle(); if (songFile != null) { b.putString(PRETTY_SONG_NAME, Utils.getPrettySongName(songFile)); b.putString(PRETTY_ALBUM_NAME, songFile.getParentFile().getName()); b.putString(PRETTY_ARTIST_NAME, songFile.getParentFile().getParentFile().getName()); } else { // songFile can be null while we're shutting down. b.putString(PRETTY_SONG_NAME, " "); b.putString(PRETTY_ALBUM_NAME, " "); b.putString(PRETTY_ARTIST_NAME, " "); }//from w w w . j av a 2s . c o m b.putBoolean(IS_SHUFFLING, this._shuffle); if (mp.isPlaying()) { b.putInt(PLAYBACK_STATE, PlaybackState.PLAYING.ordinal()); } else { b.putInt(PLAYBACK_STATE, PlaybackState.PAUSED.ordinal()); } // We might not be able to send the position right away if mp is // still being created // so instead let's send the last position we knew about. if (mp.isPlaying()) { lastDuration = mp.getDuration(); lastPosition = mp.getCurrentPosition(); } b.putInt(TRACK_DURATION, lastDuration); b.putInt(TRACK_POSITION, lastPosition); msg.setData(b); try { client.send(msg); } catch (RemoteException e) { e.printStackTrace(); toRemove.add(client); } } for (Messenger remove : toRemove) { mClients.remove(remove); } } }
From source file:de.dcja.prettygreatmusicplayer.MusicPlaybackService.java
private void sendUpdateToClients() { List<Messenger> toRemove = new ArrayList<Messenger>(); synchronized (mClients) { for (Messenger client : mClients) { Message msg = Message.obtain(null, MSG_SERVICE_STATUS); try { client.send(msg);//from ww w . j av a 2s. c o m } catch (RemoteException e) { e.printStackTrace(); toRemove.add(client); } } for (Messenger remove : toRemove) { mClients.remove(remove); } } }
From source file:com.cellobject.oikos.FormActivity.java
private void initializeRequestButton() { sendRequestButton = (Button) findViewById(R.id.btn_send_request); sendRequestButton.setOnClickListener(new View.OnClickListener() { public void onClick(final View view) { try { saveSelectedValues();// w ww . ja va 2 s . c o m // final Store selectedStore = (Store) storesSpinner.getSelectedItem(); requestWrapper = new RequestWrapper(messageEditText.getText().toString(), selectedStore.getId(), selectedStore.getName()); if (selectedStore.getId().equalsIgnoreCase(UNDEFINED_ID)) { requestWrapper.setStore(storeEditText.getText().toString()); } final County selectedCounty = (County) countiesSpinner.getSelectedItem(); requestWrapper.setCountyId(selectedCounty.getId()); if (!selectedCounty.getId().equalsIgnoreCase(UNDEFINED_ID)) { requestWrapper.setCounty(selectedCounty.getName()); } final Place selectedPlace = (Place) placesSpinner.getSelectedItem(); requestWrapper.setPlaceId(selectedPlace.getId()); requestWrapper.setPlace(placeEditText.getText().toString()); requestWrapper.setStoreFacebookPageId(selectedStore.getFacebookPageId()); // if (validateRequiredInputs(requestWrapper)) { formHandler.sendMessage(Message.obtain(formHandler, SUBMIT_PRODUCT)); } } catch (final Exception e) { Log.i(TAG, "Server connection failed"); } } }); }
From source file:com.ruesga.rview.SearchActivity.java
private void performShowOptions() { final ListPopupWindow popupWindow = new ListPopupWindow(this); ArrayList<String> values = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.search_options_labels))); String value = values.get(mCurrentOption); SimpleDropDownAdapter adapter = new SimpleDropDownAdapter(this, values, mIcons, value); popupWindow.setAnchorView(mBinding.anchor); popupWindow.setDropDownGravity(Gravity.END); popupWindow.setAdapter(adapter);//from w w w . ja va 2 s .co m popupWindow.setContentWidth(adapter.measureContentWidth()); popupWindow.setOnItemClickListener((parent, view, position, id) -> { popupWindow.dismiss(); mCurrentOption = position; Preferences.setAccountSearchMode(this, mAccount, mCurrentOption); configureSearchHint(); mBinding.searchView.setCustomIcon(ContextCompat.getDrawable(this, mIcons[position])); clearSuggestions(); mHandler.removeMessages(FETCH_SUGGESTIONS_MESSAGE); mHandler.removeMessages(SHOW_HISTORY_MESSAGE); final Message msg = Message.obtain(mHandler, SHOW_HISTORY_MESSAGE); mHandler.sendMessageDelayed(msg, 500L); }); popupWindow.setModal(true); popupWindow.show(); }
From source file:by.zatta.pilight.connection.ConnectionService.java
/** * Send the data to all clients./*from w w w. j a va 2 s . c o m*/ * * @param message * The message to send. */ private static void sendMessageToUI(int what, String message) { // Log.v(TAG, "sent message called, clients attached: " + Integer.toString(mClients.size())); Iterator<Messenger> messengerIterator = mClients.iterator(); while (messengerIterator.hasNext()) { Messenger messenger = messengerIterator.next(); try { Bundle bundle = new Bundle(); bundle.setClassLoader(aCtx.getClassLoader()); switch (what) { case MSG_SET_STATUS: // Log.v(TAG, "setting status: " + message); bundle.putString("status", message); Message msg_string = Message.obtain(null, MSG_SET_STATUS); msg_string.setData(bundle); messenger.send(msg_string); break; case MSG_SET_BUNDLE: if (!mDevices.isEmpty()) { // Log.v(TAG, "putting mDevices"); bundle.putParcelableArrayList("config", (ArrayList<? extends Parcelable>) mDevices); Message msg = Message.obtain(null, MSG_SET_BUNDLE); msg.setData(bundle); messenger.send(msg); } break; } } catch (RemoteException e) { Log.w(TAG, "mClients.remove called"); mClients.remove(messenger); } } }
From source file:com.suning.mobile.ebuy.lottery.network.util.Caller.java
/** * //w w w .j a v a2s.c o m * @Description: * @Author:12072565 * @Date 2013-5-6 * @return void */ private void updateRunning() { isFirst = false; timeFirst = SystemClock.elapsedRealtime(); mHandler.sendMessageDelayed(Message.obtain(mHandler, 2), 1000); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}//w ww .j a va 2 s. co m */ @Override public void computeScroll() { super.computeScroll(); // Determine whether we still scrolling and needs a viewport refresh final boolean scrolling = mScroller.computeScrollOffset(); if (scrolling) { float x = mScroller.getCurrX(); if (x > mMaxOffset || x < 0) { return; } mCurrentOffset = x; ViewCompat.postInvalidateOnAnimation(this); } else if (mState > STATE_MOVING) { boolean needsInvalidate = false; final boolean needOverScroll; synchronized (mLock) { needOverScroll = mData.size() >= Math.floor(mMaxBarItemsInScreen / 2); } final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (needOverScroll && overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS)) { float x = mScroller.getCurrX(); if (x >= mMaxOffset) { needsInvalidate = true; } if (x < 0) { needsInvalidate = true; } } if (!needsInvalidate) { // Reset state mState = STATE_IDLE; mLastPosition = -1; } else { ViewCompat.postInvalidateOnAnimation(this); } } int position = computeNearestPositionFromOffset(mCurrentOffset); // If we are not centered in a item, perform an scroll if (mState == STATE_IDLE) { smoothScrollTo(position); } if (mCurrentPosition != position) { // Don't perform selection operations while we are just scrolling if (mState != STATE_SCROLLING) { mCurrentPosition = position; // Notify any valid item, but only notify invalid items if // we are not panning/scrolling if (mCurrentPosition >= 0 || !scrolling) { Message.obtain(mUiHandler, MSG_ON_SELECTION_ITEM_CHANGED).sendToTarget(); } } } }
From source file:com.suning.mobile.ebuy.lottery.network.util.Caller.java
/** * /*from w w w . j av a 2s. c o m*/ * @Description: handleMessage * @param m * @Author:12072565 * @Date 2013-5-6 * @return void */ private void handleMessage(Message m) { if (m.what == 2) { timeSecond = SystemClock.elapsedRealtime(); updateDate(Math.abs(timeSecond - timeFirst)); mHandler.sendMessageDelayed(Message.obtain(mHandler, 2), 1000); } }
From source file:com.sabaibrowser.UI.java
private void hideCustomViewAfterDuration() { Message msg = Message.obtain(mHandler, MSG_HIDE_CUSTOM_VIEW); mHandler.sendMessageDelayed(msg, HIDE_CUSTOM_VIEW_DELAY); }
From source file:com.ruesga.rview.MainActivity.java
private void requestNavigateTo(int itemId, boolean force, boolean async) { // Select the item final boolean navigate = performSelectItem(itemId, force); // Close the drawer if (mBinding.drawerLayout != null) { if (mBinding.drawerLayout.isDrawerOpen(GravityCompat.START)) { mBinding.drawerLayout.closeDrawer(GravityCompat.START, true); }//from w ww. ja va 2s.com } if (navigate) { if (async) { Message.obtain(mUiHandler, MESSAGE_NAVIGATE_TO).sendToTarget(); } else { performNavigateTo(); } } }