List of usage examples for android.os Message obtain
public static Message obtain(Handler h)
From source file:com.Beat.RingdroidEditActivity.java
private void afterSavingRingtone(CharSequence title, String outPath, File outFile, int duration) { long length = outFile.length(); if (length <= 512) { outFile.delete();//from w w w . ja v a 2 s . com new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(R.string.too_small_error).setPositiveButton(R.string.alert_ok_button, null) .setCancelable(false).show(); return; } // Create the database record, pointing to the existing file path long fileSize = outFile.length(); String mimeType = "audio/mpeg"; String artist = "" + getResources().getText(R.string.artist_name); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, outPath); values.put(MediaStore.MediaColumns.TITLE, title.toString()); values.put(MediaStore.MediaColumns.SIZE, fileSize); values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType); values.put(MediaStore.Audio.Media.ARTIST, artist); values.put(MediaStore.Audio.Media.DURATION, duration); values.put(MediaStore.Audio.Media.IS_RINGTONE, mNewFileKind == FileSaveDialog.FILE_KIND_RINGTONE); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION); values.put(MediaStore.Audio.Media.IS_ALARM, mNewFileKind == FileSaveDialog.FILE_KIND_ALARM); values.put(MediaStore.Audio.Media.IS_MUSIC, mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC); // Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(outPath); final Uri newUri = getContentResolver().insert(uri, values); setResult(RESULT_OK, new Intent().setData(newUri)); // Update a preference that counts how many times we've // successfully saved a ringtone or other audio SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_SUCCESS_COUNT, successCount + 1); prefsEditor.commit(); // If Ringdroid was launched to get content, just return if (mWasGetContentIntent) { sendStatsToServerIfAllowedAndFinish(); return; } // There's nothing more to do with music or an alarm. Show a // success message and then quit. if (mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC || mNewFileKind == FileSaveDialog.FILE_KIND_ALARM) { Toast.makeText(this, R.string.save_success_message, Toast.LENGTH_SHORT).show(); sendStatsToServerIfAllowedAndFinish(); return; } // If it's a notification, give the user the option of making // this their default notification. If they say no, we're finished. if (mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION) { new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_success) .setMessage(R.string.set_default_notification) .setPositiveButton(R.string.alert_yes_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this, RingtoneManager.TYPE_NOTIFICATION, newUri); sendStatsToServerIfAllowedAndFinish(); } }).setNegativeButton(R.string.alert_no_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendStatsToServerIfAllowedAndFinish(); } }).setCancelable(false).show(); return; } // If we get here, that means the type is a ringtone. There are // three choices: make this your default ringtone, assign it to a // contact, or do nothing. final Handler handler = new Handler() { public void handleMessage(Message response) { int actionId = response.arg1; switch (actionId) { case R.id.button_make_default: RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(RingdroidEditActivity.this, R.string.default_ringtone_success_message, Toast.LENGTH_SHORT).show(); sendStatsToServerIfAllowedAndFinish(); break; case R.id.button_choose_contact: chooseContactForRingtone(newUri); break; default: case R.id.button_do_nothing: sendStatsToServerIfAllowedAndFinish(); break; } } }; Message message = Message.obtain(handler); AfterSaveActionDialog dlog = new AfterSaveActionDialog(this, message); dlog.show(); }
From source file:com.Beat.RingdroidEditActivity.java
private void onSave() { if (mIsPlaying) { handlePause();/* w w w . jav a2 s . c o m*/ } final Handler handler = new Handler() { public void handleMessage(Message response) { CharSequence newTitle = (CharSequence) response.obj; mNewFileKind = response.arg1; saveRingtone(newTitle); } }; Message message = Message.obtain(handler); FileSaveDialog dlog = new FileSaveDialog(this, getResources(), mTitle, message); dlog.show(); }
From source file:com.dzt.musicplay.player.AudioService.java
private void readMedia(String filePath, boolean noVideo) { Message message = Message.obtain(mPlayFileHandler); Bundle data = new Bundle(); data.putString("filePath", filePath); data.putBoolean("noVideo", noVideo); message.what = 1;/* w w w. j a v a 2 s . co m*/ message.setData(data); message.sendToTarget(); }
From source file:com.dzt.musicplay.player.AudioService.java
private void playIndex(int position) { Message message = Message.obtain(mPlayFileHandler); Bundle data = new Bundle(); data.putInt("position", position); message.what = 2;// w w w .j a va2 s .c o m message.setData(data); message.sendToTarget(); }
From source file:com.dzt.musicplay.player.AudioService.java
private void playNext() { Message message = Message.obtain(mPlayFileHandler); message.what = 3; message.sendToTarget(); }
From source file:com.dzt.musicplay.player.AudioService.java
private void playPrevious() { Message message = Message.obtain(mPlayFileHandler); message.what = 4; message.sendToTarget(); }
From source file:de.tudresden.inf.rn.mobilis.mxa.XMPPRemoteService.java
/** * Get all packets that are in the LostIQQueue and sends them. Assumes that * for every packet there is a corresponding thread. *//*ww w .j a v a 2 s.com*/ public void resendIQ() { // to the same as sendIQ, but we take the values from the list Log.v(TAG, "start resending iqs"); LostIQQueueEntry e; int size = mIQQueue.getCount(); // try to send each packet only once for (int i = 0; i < size; i++) { e = mIQQueue.getOldestEntry(); if (e == null) return; if (e.mSending) continue; e.mSending = true; Message msg = Message.obtain(e.mMessage); msg.what = ConstMXA.MSG_IQ_RESEND; msg.getData().putLong(ConstMXA.IQ_RESEND_ID, e.mID); IQRunner iqRunJob = new IQRunner(msg); mWriteExecutor.execute(iqRunJob); } Log.v(TAG, "end resending iqs"); }
From source file:eu.davidea.flexibleadapter.FlexibleAdapter.java
private void autoScrollWithDelay(final int position, final int subItemsCount, final long delay) { //Must be delayed to give time at RecyclerView to recalculate positions after an automatic collapse new Handler(Looper.getMainLooper(), new Handler.Callback() { public boolean handleMessage(Message message) { int firstVisibleItem = Utils .findFirstCompletelyVisibleItemPosition(mRecyclerView.getLayoutManager()); int lastVisibleItem = Utils.findLastCompletelyVisibleItemPosition(mRecyclerView.getLayoutManager()); int itemsToShow = position + subItemsCount - lastVisibleItem; // if (DEBUG) // Log.v(TAG, "autoScroll itemsToShow=" + itemsToShow + " firstVisibleItem=" + firstVisibleItem + " lastVisibleItem=" + lastVisibleItem + " RvChildCount=" + mRecyclerView.getChildCount()); if (itemsToShow > 0) { int scrollMax = position - firstVisibleItem; int scrollMin = Math.max(0, position + subItemsCount - lastVisibleItem); int scrollBy = Math.min(scrollMax, scrollMin); int spanCount = getSpanCount(mRecyclerView.getLayoutManager()); if (spanCount > 1) { scrollBy = scrollBy % spanCount + spanCount; }//from ww w . ja va 2 s .co m int scrollTo = firstVisibleItem + scrollBy; // if (DEBUG) // Log.v(TAG, "autoScroll scrollMin=" + scrollMin + " scrollMax=" + scrollMax + " scrollBy=" + scrollBy + " scrollTo=" + scrollTo); mRecyclerView.smoothScrollToPosition(scrollTo); } else if (position < firstVisibleItem) { mRecyclerView.smoothScrollToPosition(position); } return true; } }).sendMessageDelayed(Message.obtain(mHandler), delay); }