List of usage examples for android.os Message obtain
public static Message obtain()
From source file:com.adjust.sdk.ActivityHandler.java
@Override public void sendReferrer(String referrer, long clickTime) { Message message = Message.obtain(); message.arg1 = SessionHandler.SEND_REFERRER; ReferrerClickTime referrerClickTime = new ReferrerClickTime(referrer, clickTime); message.obj = referrerClickTime;/* w w w . j a v a 2s .c o m*/ sessionHandler.sendMessage(message); }
From source file:net.carlh.toast.Client.java
private void handler(JSONObject json) { try {/*from w ww . j av a 2 s. c o m*/ if (json.has("type") && json.get("type").equals("pong")) { setConnected(true); pong.set(true); } else { for (Handler h : handlers) { Message m = Message.obtain(); Bundle b = new Bundle(); b.putString("json", json.toString()); m.setData(b); h.sendMessage(m); } } } catch (JSONException e) { } }
From source file:org.openmidaas.app.activities.AuthorizationActivity.java
/** * Creates UI elements based on the requestData. * @param requestData/*from w w w . j a v a2 s . c o m*/ */ private void displayAuthorizationList(final JSONObject requestData) { new Thread(new Runnable() { @Override public void run() { //Get a session and lock it. //State the manager as busy so that it cannot create a new one until specifically made free. Message message = Message.obtain(); try { mSession = SessionManager.createSession(); Logger.debug(getClass(), "Session created and locked."); SessionManager.setBusyness(true); } catch (SessionCreationException e2) { Logger.error(getClass(), e2.getMessage()); } // Try to fetch the attributes try { Logger.debug(getClass(), "message: " + message); Logger.debug(getClass(), "request: " + requestData); fetchAttributeSet(message, requestData); } catch (AttributeFetchException e) { Logger.error(getClass(), e.getMessage()); // re-try fetching the attribute set from the persistence store again. try { fetchAttributeSet(message, requestData); } catch (AttributeFetchException e1) { Logger.error(getClass(), e1.getMessage()); DialogUtils.showNeutralButtonDialog(AuthorizationActivity.this, "Error", e1.getMessage()); dismissDialog(); } } } }).start(); }
From source file:com.yangtsaosoftware.pebblemessenger.activities.ToolsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SEND_MESSAGE: { Message msg = Message.obtain(); Bundle b = new Bundle(); msg.what = MessageProcessingService.MSG_NEW_MESSAGE; b.putString(MessageDbHandler.COL_MESSAGE_APP, LOG_TAG); b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, data.getStringExtra(MESSAGE_BODY)); try {/*ww w .j a v a2 s. c o m*/ msg.setData(b); rMessageProcessHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); Constants.log(LOG_TAG, "Error when sending message to MessageProcessingService."); } Toast.makeText(_context, R.string.tools_toast_send_message, Toast.LENGTH_LONG).show(); } break; case REQUEST_SEND_CALL: Intent inner_intent = new Intent(MessageProcessingService.class.getName()); inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_CALL_INCOMING); inner_intent.putExtra(Constants.BROADCAST_PHONE_NUM, data.getStringExtra(CALL_NUM)); inner_intent.putExtra(Constants.BROADCAST_NAME, data.getStringExtra(CALL_NAME)); LocalBroadcastManager.getInstance(getActivity().getBaseContext()).sendBroadcast(inner_intent); Toast.makeText(_context, R.string.tools_toast_send_call, Toast.LENGTH_LONG).show(); break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_playlist, container, false); mPlaylists = mPlaylistManager.getAllPlaylists(); mList = (ListView) view.findViewById(R.id.songs); mEmptyPlaylist = view.findViewById(R.id.playlist_empty); // Add Spinner to toolbar mPlaylistsSpinner = (Spinner) getActivity().findViewById(R.id.toolbar_spinner); mPlaylistsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*w w w .j ava2s .co m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { updateSongList(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); updatePlaylistSpinner(); // Create the adapter mAdapter = new PlaylistSongAdapter(getActivity(), R.layout.item_playlist, getSelectedPlaylistSongs()); mList.setOnItemClickListener(oiclSong); mList.setAdapter(mAdapter); mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) { SparseBooleanArray checkedPositions = mList.getCheckedItemPositions(); LinkedList<MySong> selectedSongs = new LinkedList<>(); for (int i = 0; i < checkedPositions.size(); ++i) { int position = checkedPositions.keyAt(i); if (checkedPositions.valueAt(i)) { selectedSongs.add(getSelectedPlaylistSongs().get(position)); } } if (!selectedSongs.isEmpty()) { switch (item.getItemId()) { case R.id.playlist_context_play: playSong(selectedSongs.get(0)); mode.finish(); return true; case R.id.playlist_context_download: LinkedList<String> urls = new LinkedList<>(); for (MySong s : selectedSongs) { urls.add(s.getUrl()); } if (!urls.isEmpty()) { DownloadManager.getInstance().addJob( ClementineMessageFactory.buildDownloadSongsMessage(DownloadItem.Urls, urls)); } mode.finish(); return true; case R.id.playlist_context_remove: Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildRemoveMultipleSongsFromPlaylist(getPlaylistId(), selectedSongs); App.ClementineConnection.mHandler.sendMessage(msg); mode.finish(); return true; default: return false; } } return false; } @Override public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) { android.view.MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.playlist_context_menu, menu); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status)); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, android.view.Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark)); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { } }); // Filter the results mAdapter.getFilter().filter(mFilterText); mActionBar.setTitle(""); mActionBar.setSubtitle(""); return view; }
From source file:com.open.file.manager.CutCopyService.java
void sendDuplicateMessage() { Message dupmsg = Message.obtain(); dupmsg.what = Consts.MSG_DUPLICATES; Bundle dupdata = new Bundle(); dupdata.putParcelableArrayList("duplicates", tree.duplicates); dupmsg.setData(dupdata);//ww w . j a v a 2s . co m MainActivity.acthandler.sendMessage(dupmsg); }
From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear();//from w ww. j a v a2 s . c o m inflater.inflate(R.menu.global_search_menu, menu); // Create a listener for search change final MenuItem search = menu.findItem(R.id.global_search_menu_search); final SearchView searchView = (SearchView) search.getActionView(); searchView.setIconifiedByDefault(true); searchView.setIconified(false); final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { mSwipeRefreshLayout.setRefreshing(true); mEmptyView.setRefreshing(true); Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildGlobalSearch(query); App.ClementineConnection.mHandler.sendMessage(msg); hideSoftInput(); // Set the actionbar title mActionBar.setTitle(getResources().getString(R.string.global_search_query, query)); mActionBar.setSubtitle("/"); // Query must be empty in order to collapse the search view. searchView.setQuery("", false); searchView.setIconified(true); // Remove currently present adapters mAdapters.clear(); showList(); return true; } }; searchView.setOnQueryTextListener(queryTextListener); searchView.setQueryHint(getString(R.string.global_search_search)); EditText searchText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); searchText.setHintTextColor(ContextCompat.getColor(getActivity(), R.color.searchview_edittext_hint)); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.adjust.sdk.ActivityHandler.java
private void updateStatus() { Message message = Message.obtain(); message.arg1 = SessionHandler.UPDATE_STATUS; sessionHandler.sendMessage(message); }
From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Send a message to the ui thread//from ww w . j ava2 s . c om * * @param obj The Message containing data */ private void sendUiMessage(Object obj) { Message msg = Message.obtain(); msg.obj = obj; // Send the Messages if (mUiHandler != null) { mUiHandler.sendMessage(msg); } }
From source file:com.example.lijingjiang.mobile_sensor_display.SimplePedometerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { /**//from w w w. ja v a2s . c o m * Initialization */ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0); } /** * Attach UI objects */ hrResultView = (TextView) findViewById(R.id.hr); hrResultView.setText(TEXT_HR + hr); distanceResultView = (TextView) findViewById(R.id.result_field); distanceResultView.setText(String.valueOf(accumulatedLocationCalculatedFromGoogle) + " Meters"); stepsResultView = (TextView) findViewById(R.id.steps); stepsResultView.setText(TEXT_NUM_STEPS + numSteps); startButtonRunning = (Button) findViewById(R.id.start_running_button); stopButtonRunning = (Button) findViewById(R.id.stop_running_button); startButtonRunning.setEnabled(true); stopButtonRunning.setEnabled(false); startButtonExercising = (Button) findViewById(R.id.start_exercise_button); stopButtonExercising = (Button) findViewById(R.id.stop_exercise_button); startButtonExercising.setEnabled(true); stopButtonExercising.setEnabled(false); startButtonSleeping = (Button) findViewById(R.id.start_sleep_button); stopButtonSleeping = (Button) findViewById(R.id.stop_sleep_button); startButtonSleeping.setEnabled(true); stopButtonSleeping.setEnabled(false); ageField = (EditText) findViewById(R.id.age_field); exerciseTypeField = (EditText) findViewById(R.id.exercise_type); /** * Sensor initialization */ sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); simpleStepDetector = new SimpleStepDetector(); simpleStepDetector.registerListener(this); /** * Google Service Initialization */ mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); mLocationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(2000) // 2000 milliseconds .setFastestInterval(2000); // 2000 milliseconds /** * The following code will enable the GPS sensor to get location data */ // locationManager = (LocationManager) // this.getSystemService(Context.LOCATION_SERVICE); // locationListener = new GPSLocationListener(); // locationProvider = LocationManager.GPS_PROVIDER; // lastKnown = // locationManager.getLastKnownLocation(locationProvider); // locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, // minTimeMs, minDistanceMeters, locationListener); mHandler = new Handler() { public void handleMessage(Message msg) { //distanceResultView.setText(R.string.zero); hrResultView.setText(TEXT_HR + hr); stepsResultView.setText(TEXT_NUM_STEPS + numSteps); //Start runnable here, maybe? mHandler.sendMessageDelayed(Message.obtain(), mUpdatePeriodMillis); } }; mHandler.sendMessageDelayed(Message.obtain(), mUpdatePeriodMillis); Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); }