List of usage examples for android.os Message obtain
public static Message obtain(Handler h, int what)
From source file:org.runbuddy.tomahawk.mediaplayers.PluginMediaPlayer.java
protected synchronized void callService(int what, Bundle bundle) { Message message = Message.obtain(null, what); message.setData(bundle);/*from w ww . j ava 2 s. c o m*/ callService(message); }
From source file:com.android.ex.chips.RecipientEditTextView.java
public RecipientEditTextView(final Context context, final AttributeSet attrs) { super(context, attrs); mAddTextWatcher = new Runnable() { @Override//from w w w . ja v a2 s .c o m public void run() { if (mTextWatcher == null) { mTextWatcher = new RecipientTextWatcher(); addTextChangedListener(mTextWatcher); } } }; mDelayedShrink = new Runnable() { @Override public void run() { shrink(); } }; mHandlePendingChips = new Runnable() { @Override public void run() { handlePendingChips(); } }; setChipDimensions(context, attrs); if (sSelectedTextColor == -1) sSelectedTextColor = ContextCompat.getColor(context, android.R.color.white); /*mAlternatesPopup=new ListPopupWindow(context); mAddressPopup=new ListPopupWindow(context);*/ mCopyDialog = new Dialog(context); mAlternatesListener = new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapterView, final View view, final int position, final long rowId) { //mAlternatesPopup.setOnItemClickListener(null); replaceChip(mSelectedChip, ((RecipientAlternatesAdapter) adapterView.getAdapter()).getRecipientEntry(position)); final Message delayed = Message.obtain(mHandler, DISMISS); //delayed.obj=mAlternatesPopup; mHandler.sendMessageDelayed(delayed, DISMISS_DELAY); clearComposingText(); } }; setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); setOnItemClickListener(null); setCustomSelectionActionModeCallback(this); mHandler = new Handler() { @Override public void handleMessage(final Message msg) { if (msg.what == DISMISS) { //((ListPopupWindow)msg.obj).dismiss(); return; } super.handleMessage(msg); } }; mTextWatcher = new RecipientTextWatcher(); addTextChangedListener(mTextWatcher); mGestureDetector = new GestureDetector(context, this); setOnEditorActionListener(this); }
From source file:com.marianhello.bgloc.LocationService.java
/** * Handle location from location location provider * * All locations updates are recorded in local db at all times. * Also location is also send to all messenger clients. * * If option.url is defined, each location is also immediately posted. * If post is successful, the location is deleted from local db. * All failed to post locations are coalesced and send in some time later in one single batch. * Batch sync takes place only when number of failed to post locations reaches syncTreshold. * * If only option.syncUrl is defined, locations are send only in single batch, * when number of locations reaches syncTreshold. * * @param location/*from w w w.j a v a 2s .co m*/ */ public void handleLocation(BackgroundLocation location) { log.debug("New location {}", location.toString()); location.setBatchStartMillis(System.currentTimeMillis() + ONE_MINUTE); // prevent sync of not yet posted location persistLocation(location); if (config.hasUrl() || config.hasSyncUrl()) { Long locationsCount = dao.locationsForSyncCount(System.currentTimeMillis()); log.debug("Location to sync: {} threshold: {}", locationsCount, config.getSyncThreshold()); if (locationsCount >= config.getSyncThreshold()) { log.debug("Attempt to sync locations: {} threshold: {}", locationsCount, config.getSyncThreshold()); SyncService.sync(syncAccount, getStringResource(Config.CONTENT_AUTHORITY_RESOURCE)); } } if (hasConnectivity && config.hasUrl()) { postLocationAsync(location); } Bundle bundle = new Bundle(); bundle.putParcelable("location", location); Message msg = Message.obtain(null, MSG_LOCATION_UPDATE); msg.setData(bundle); sendClientMessage(msg); }
From source file:pl.poznan.put.cs.ify.app.MainActivity.java
public void activateRecipe(String recipe, YParamList requiredParams) { Message msg = Message.obtain(null, ServiceHandler.REGISTER_Recipe); Bundle bundle = new Bundle(); bundle.putString(YRecipesService.Recipe, recipe); bundle.putParcelable(YRecipesService.PARAMS, requiredParams); msg.setData(bundle);/* w w w .j a v a2 s . c om*/ try { mService.send(msg); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.ruesga.rview.SearchActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(mMessenger); mAccount = Preferences.getAccount(this); mCurrentOption = Preferences.getAccountSearchMode(this, mAccount); fillSuggestions();/*from ww w.ja v a 2 s . co m*/ mBinding = DataBindingUtil.setContentView(this, R.layout.search_activity); mBinding.setHandlers(new EventHandlers(this)); mIcons = loadSearchIcons(); if (getSupportActionBar() != null) { getSupportActionBar().setTitle(R.string.menu_search); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false); } // Configure the suggestions loaders RxLoaderManager loaderManager = RxLoaderManagerCompat.get(this); mAccountSuggestionsLoader = loaderManager.create("accounts", this::fetchAccountSuggestions, mAccountSuggestionsObserver); mProjectSuggestionsLoader = loaderManager.create("projects", this::fetchProjectSuggestions, mProjectSuggestionsObserver); mDocSuggestionsLoader = loaderManager.create("docs", this::fetchDocSuggestions, mDocSuggestionsObserver); // Configure the search view mBinding.searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public boolean onSuggestionClicked(SearchSuggestion suggestion) { final Suggestion s = (Suggestion) suggestion; // Let type more if (!s.mHistory && mCurrentOption == Constants.SEARCH_MODE_CUSTOM) { return true; } // Directly complete the search performSearch(s.mSuggestionText, s.mSuggestionData); return false; } @Override public void onSearchAction(String currentQuery) { performSearch(currentQuery, null); } }); mBinding.searchView.setOnQueryChangeListener((oldFilter, newFilter) -> { mHandler.removeMessages(SHOW_HISTORY_MESSAGE); mHandler.removeMessages(FETCH_SUGGESTIONS_MESSAGE); final Message msg; if (TextUtils.isEmpty(newFilter)) { clearSuggestions(); msg = Message.obtain(mHandler, SHOW_HISTORY_MESSAGE); } else { msg = Message.obtain(mHandler, FETCH_SUGGESTIONS_MESSAGE, newFilter); msg.arg1 = mCurrentOption; } mHandler.sendMessageDelayed(msg, 500L); }); mBinding.searchView.setOnBindSuggestionCallback((v, imageView, textView, suggestion, position) -> { final Suggestion s = (Suggestion) suggestion; textView.setText(performFilterHighlight(s)); if (s.mSuggestionIcon != 0) { Drawable dw = ContextCompat.getDrawable(this, s.mSuggestionIcon); DrawableCompat.setTint(dw, ContextCompat.getColor(this, R.color.gray_active_icon)); imageView.setImageDrawable(dw); } else { imageView.setImageDrawable(null); } }); mBinding.searchView.setOnMenuItemClickListener(item -> performShowOptions()); mBinding.searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override public void onFocus() { mHandler.removeMessages(FETCH_SUGGESTIONS_MESSAGE); mHandler.removeMessages(SHOW_HISTORY_MESSAGE); final Message msg = Message.obtain(mHandler, SHOW_HISTORY_MESSAGE); mHandler.sendMessageDelayed(msg, 500L); } @Override public void onFocusCleared() { // Ignore } }); mBinding.searchView.setOnClearSearchActionListener(this::performShowHistory); clearSuggestions(); mBinding.searchView.setCustomIcon(ContextCompat.getDrawable(this, mIcons[mCurrentOption])); configureSearchHint(); boolean revealed = false; if (savedInstanceState != null) { revealed = savedInstanceState.getBoolean(EXTRA_REVEALED, false); } if (!revealed) { enterReveal(); } }
From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java
private void playPause() { Log.d(TAG, "Play/Pause clicked..."); Message msg = Message.obtain(null, MusicPlaybackService.MSG_PLAYPAUSE); try {//from ww w . jav a 2 s . co m Log.i(TAG, "Sending a request to start playing!"); mService.send(msg); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java
public boolean execute(String action, final JSONArray data, final CallbackContext callbackContext) { Activity activity = getActivity();/*from w w w . j av a2s. c om*/ Context context = getContext(); if (ACTION_START.equals(action)) { if (config == null) { log.warn("Attempt to start unconfigured service"); callbackContext.error("Plugin not configured. Please call configure method first."); return true; } if (!hasPermissions()) { log.info("Requesting permissions from user"); actionStartCallbackContext = callbackContext; PermissionHelper.requestPermissions(this, START_REQ_CODE, permissions); return true; } executorService.execute(new Runnable() { public void run() { startAndBindBackgroundService(); callbackContext.success(); } }); return true; } else if (ACTION_STOP.equals(action)) { executorService.execute(new Runnable() { public void run() { doUnbindService(); stopBackgroundService(); callbackContext.success(); } }); return true; } else if (ACTION_SWITCH_MODE.equals(action)) { Message msg = Message.obtain(null, LocationService.MSG_SWITCH_MODE); try { msg.arg1 = data.getInt(0); mService.send(msg); } catch (Exception e) { log.error("Switch mode failed: {}", e.getMessage()); } return true; } else if (ACTION_CONFIGURE.equals(action)) { this.callbackContext = callbackContext; executorService.execute(new Runnable() { public void run() { try { config = Config.fromJSONObject(data.getJSONObject(0)); persistConfiguration(config); // callbackContext.success(); //we cannot do this } catch (JSONException e) { log.error("Configuration error: {}", e.getMessage()); callbackContext.error("Configuration error: " + e.getMessage()); } catch (NullPointerException e) { log.error("Configuration error: {}", e.getMessage()); callbackContext.error("Configuration error: " + e.getMessage()); } } }); return true; } else if (ACTION_LOCATION_ENABLED_CHECK.equals(action)) { log.debug("Location services enabled check"); try { int isLocationEnabled = BackgroundGeolocationPlugin.isLocationEnabled(context) ? 1 : 0; callbackContext.success(isLocationEnabled); } catch (SettingNotFoundException e) { log.error("Location service checked failed: {}", e.getMessage()); callbackContext.error("Location setting error occured"); } return true; } else if (ACTION_SHOW_LOCATION_SETTINGS.equals(action)) { showLocationSettings(); // TODO: call success/fail callback return true; } else if (ACTION_SHOW_APP_SETTINGS.equals(action)) { showAppSettings(); // TODO: call success/fail callback return true; } else if (ACTION_ADD_MODE_CHANGED_LISTENER.equals(action)) { registerLocationModeChangeReceiver(callbackContext); // TODO: call success/fail callback return true; } else if (ACTION_REMOVE_MODE_CHANGED_LISTENER.equals(action)) { unregisterLocationModeChangeReceiver(); // TODO: call success/fail callback return true; } else if (ACTION_ADD_STATIONARY_LISTENER.equals(action)) { stationaryContexts.add(callbackContext); return true; } else if (ACTION_GET_STATIONARY.equals(action)) { try { if (stationaryLocation != null) { callbackContext.success(stationaryLocation.toJSONObject()); } else { callbackContext.success(); } } catch (JSONException e) { log.error("Getting stationary location failed: {}", e.getMessage()); callbackContext.error("Getting stationary location failed"); } return true; } else if (ACTION_GET_ALL_LOCATIONS.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { callbackContext.success(getAllLocations()); } catch (JSONException e) { log.error("Getting all locations failed: {}", e.getMessage()); callbackContext.error("Converting locations to JSON failed."); } } }); return true; } else if (ACTION_GET_VALID_LOCATIONS.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { callbackContext.success(getValidLocations()); } catch (JSONException e) { log.error("Getting valid locations failed: {}", e.getMessage()); callbackContext.error("Converting locations to JSON failed."); } } }); return true; } else if (ACTION_DELETE_LOCATION.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { Long locationId = data.getLong(0); deleteLocation(locationId); callbackContext.success(); } catch (JSONException e) { log.error("Delete location failed: {}", e.getMessage()); callbackContext.error("Deleting location failed: " + e.getMessage()); } } }); return true; } else if (ACTION_DELETE_ALL_LOCATIONS.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { deleteAllLocations(); callbackContext.success(); } }); return true; } else if (ACTION_GET_CONFIG.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { callbackContext.success(retrieveConfiguration()); } catch (JSONException e) { log.error("Error getting config: {}", e.getMessage()); callbackContext.error("Error getting config: " + e.getMessage()); } } }); return true; } else if (ACTION_GET_LOG_ENTRIES.equals(action)) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { callbackContext.success(getLogs(data.getInt(0))); } catch (Exception e) { callbackContext.error("Getting logs failed: " + e.getMessage()); } } }); return true; } return false; }
From source file:com.marianhello.bgloc.LocationService.java
public void handleStationary(BackgroundLocation location) { log.debug("New stationary {}", location.toString()); Bundle bundle = new Bundle(); bundle.putParcelable("location", location); Message msg = Message.obtain(null, MSG_ON_STATIONARY); msg.setData(bundle);//from w w w .ja va 2 s . co m sendClientMessage(msg); }
From source file:com.nps.micro.UsbService.java
private void sendStatusMessage() { for (int i = mClients.size() - 1; i >= 0; i--) { try {//from ww w . j av a2 s .c o m Bundle b = new Bundle(); b.putString(MSG_STATUS_CONTENT, status.getText()); b.putBoolean(MSG_STATUS_BUSY, status.isBusy()); Message message = Message.obtain(null, MSG_STATUS); message.setData(b); mClients.get(i).send(message); } catch (RemoteException e) { // The client is dead. Remove it from the list; we are going // through the list from back to front so this is safe to do // inside the loop. mClients.remove(i); } } }
From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java
private void next() { Log.d(TAG, "next..."); Message msg = Message.obtain(null, MusicPlaybackService.MSG_NEXT); try {/* w w w. ja v a 2s. c o m*/ Log.i(TAG, "SEnding a request to go to next!"); mService.send(msg); } catch (RemoteException e) { e.printStackTrace(); } }