List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION
int TYPE_NOTIFICATION
To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.
Click Source Link
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;/* www. j av a 2s . c o m*/ Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//w w w .java 2s . c om NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = null; sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.microsoft.projectoxford.face.samples.ui.Camera2BasicFragment.java
private void detectAndFrame() { final Bitmap bm = BitmapFactory .decodeFile(getActivity().getExternalFilesDir(null).getAbsolutePath() + "/pic.jpg"); final Bitmap bitm = Bitmap.createScaledBitmap(bm, bm.getWidth() / 8, bm.getHeight() / 8, true); final Bitmap bn = BitmapFactory .decodeFile(getActivity().getExternalFilesDir(null).getAbsolutePath() + "/pic_l.jpg"); final Bitmap bitn = Bitmap.createScaledBitmap(bn, bn.getWidth() / 8, bn.getHeight() / 8, true); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitm.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final AsyncTask<UUID, String, IdentifyResult[]> identifyTask = new AsyncTask<UUID, String, IdentifyResult[]>() { private boolean mSucceed = true; private String mPersonGroupId = getString(R.string.group_id); @Override//w w w. j a v a 2 s .co m protected IdentifyResult[] doInBackground(UUID... params) { try { // Start identification. return faceServiceClient.identity(this.mPersonGroupId, /* personGroupId */ params, /* faceIds */ 1); /* maxNumOfCandidatesReturned */ } catch (Exception e) { mSucceed = false; return null; } } @Override protected void onPostExecute(IdentifyResult[] result) { // Show the result on screen when detection is done. if (result == null) { showToast("error"); return; } if (result[0].candidates.size() > 0) { showToast("pass"); plu.unlock(); } else { showToast("no such user"); } } }; AsyncTask<InputStream, String, Face[]> detectTask = new AsyncTask<InputStream, String, Face[]>() { @Override protected Face[] doInBackground(InputStream... params) { try { publishProgress("Detecting..."); result = faceServiceClient.detect(params[0], true, // returnFaceId true, // returnFaceLandmarks null // returnFaceAttributes: a string like "age, gender" ); if (result == null) { publishProgress("Detection Finished. Nothing detected"); return null; } publishProgress(String.format("Detection Finished. %d face(s) detected", result.length)); return result; } catch (Exception e) { publishProgress("Detection failed"); return null; } } @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(String... progress) { } @Override protected void onPostExecute(Face[] result) { if (result == null || result.length == 0) { showToast("No Face"); return; } if (result.length > 1) { showToast("More than one Face"); return; } if (checkb(bitm, bitn) && checkl(bitm, bitn, result[0].faceLandmarks.eyeLeftOuter.x, result[0].faceLandmarks.eyeLeftTop.y, result[0].faceLandmarks.eyeLeftInner.x, result[0].faceLandmarks.eyeLeftBottom.y) && checkl(bitm, bitn, result[0].faceLandmarks.eyeRightInner.x, result[0].faceLandmarks.eyeRightTop.y, result[0].faceLandmarks.eyeRightOuter.x, result[0].faceLandmarks.eyeRightBottom.y)) { List<UUID> faceIds = new ArrayList<>(); for (Face face : result) { faceIds.add(face.faceId); } identifyTask.execute(faceIds.toArray(new UUID[faceIds.size()])); //showToast("Human"); } else { showToast("Photo"); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity().getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } } } }; detectTask.execute(inputStream); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//from w ww. j a v a 2s.com Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); ; String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = new Intent(context, NotificationComposeSecondAcc.class); sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.ringdroid.RingdroidEditActivity.java
private void afterSavingRingtone(CharSequence title, String outPath, File outFile, int duration) { long length = outFile.length(); if (length <= 512) { outFile.delete();// ww w .ja va 2 s.c o m 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.jtxdriggers.android.ventriloid.VentriloidService.java
@SuppressWarnings("deprecation") public boolean disconnect() { disconnect = true;//from www .j a v a 2s . c o m connected = false; if (ttsActive && !muted && prefs.getBoolean("tts_disconnect", true)) { HashMap<String, String> params = new HashMap<String, String>(); if (am.isBluetoothScoOn()) params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Disconnected"); tts.speak("Disconnected.", TextToSpeech.QUEUE_ADD, params); tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() { @Override public void onUtteranceCompleted(String utteranceId) { if (utteranceId.equals("Disconnected")) { tts.shutdown(); stopForeground(true); stopSelf(); } } }); } else if (ringtoneActive && !muted) { ringtone = RingtoneManager.getRingtone(VentriloidService.this, Uri.parse(prefs.getString("disconnect_notification", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()))); ringtone.play(); stopForeground(true); stopSelf(); } else { stopForeground(true); stopSelf(); } return true; }
From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java
private void afterSavingRingtone(CharSequence title, String outPath, File outFile, int duration) { long length = outFile.length(); if (length <= 512) { outFile.delete();// w w w . j av a 2 s . c om 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(PTimerEditActivity.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(PTimerEditActivity.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(PTimerEditActivity.this, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(PTimerEditActivity.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:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates a system notification.//from ww w .j a va 2 s . c om * * @param context Context. * @param notSound Enable or disable the sound * @param notSoundRawId Custom raw sound id. If enabled and not set * default notification sound will be used. Set to -1 to * default system notification. * @param multipleNot Setting to True allows showing multiple notifications. * @param groupMultipleNotKey If is set, multiple notifications can be grupped by this key. * @param notAction Action for this notification * @param notTitle Title * @param notMessage Message * @param notClazz Class to be executed * @param extras Extra information * */ public static void notification_generate(Context context, boolean notSound, int notSoundRawId, boolean multipleNot, String groupMultipleNotKey, String notAction, String notTitle, String notMessage, Class<?> notClazz, Bundle extras, boolean wakeUp) { try { int iconResId = notification_getApplicationIcon(context); long when = System.currentTimeMillis(); Notification notification = new Notification(iconResId, notMessage, when); // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; if (notSound) { if (notSoundRawId > 0) { try { notification.sound = Uri.parse("android.resource://" + context.getApplicationContext().getPackageName() + "/" + notSoundRawId); } catch (Exception e) { if (LOG_ENABLE) { Log.w(TAG, "Custom sound " + notSoundRawId + "could not be found. Using default."); } notification.defaults |= Notification.DEFAULT_SOUND; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } else { notification.defaults |= Notification.DEFAULT_SOUND; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } Intent notificationIntent = new Intent(context, notClazz); notificationIntent.setAction(notClazz.getName() + "." + notAction); if (extras != null) { notificationIntent.putExtras(extras); } //Set intent so it does not start a new activity // //Notes: // - The flag FLAG_ACTIVITY_SINGLE_TOP makes that only one instance of the activity exists(each time the // activity is summoned no onCreate() method is called instead, onNewIntent() is called. // - If we use FLAG_ACTIVITY_CLEAR_TOP it will make that the last "snapshot"/TOP of the activity it will // be this called this intent. We do not want this because the HOME button will call this "snapshot". // To avoid this behaviour we use FLAG_ACTIVITY_BROUGHT_TO_FRONT that simply takes to foreground the // activity. // //See http://developer.android.com/reference/android/content/Intent.html notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); int REQUEST_UNIQUE_ID = 0; if (multipleNot) { if (groupMultipleNotKey != null && groupMultipleNotKey.length() > 0) { REQUEST_UNIQUE_ID = groupMultipleNotKey.hashCode(); } else { if (random == null) { random = new Random(); } REQUEST_UNIQUE_ID = random.nextInt(); } PendingIntent.getActivity(context, REQUEST_UNIQUE_ID, notificationIntent, PendingIntent.FLAG_ONE_SHOT); } notification.setLatestEventInfo(context, notTitle, notMessage, intent); //This makes the device to wake-up is is idle with the screen off. if (wakeUp) { powersaving_wakeUp(context); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //We check if the sound is disabled to enable just for a moment AudioManager amanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int previousAudioMode = amanager.getRingerMode(); ; if (notSound && previousAudioMode != AudioManager.RINGER_MODE_NORMAL) { amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } notificationManager.notify(REQUEST_UNIQUE_ID, notification); //We restore the sound setting if (previousAudioMode != AudioManager.RINGER_MODE_NORMAL) { //We wait a little so sound is played try { Thread.sleep(3000); } catch (Exception e) { } } amanager.setRingerMode(previousAudioMode); Log.d(TAG, "Android Notification created."); } catch (Exception e) { if (LOG_ENABLE) Log.e(TAG, "The notification could not be created (" + e.getMessage() + ")", e); } }
From source file:com.SpeechEd.SpeechEdEditActivity.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 va 2 s . c o m*/ 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 SpeechEd 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(SpeechEdEditActivity.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(SpeechEdEditActivity.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(SpeechEdEditActivity.this, RingtoneManager.TYPE_RINGTONE, newUri); Toast.makeText(SpeechEdEditActivity.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.daiv.android.twitter.utils.NotificationUtils.java
public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs, String type) {//from w w w.j a v a 2 s .c o m String title = ""; String text = ""; String smallText = ""; Bitmap icon = null; AppSettings settings = AppSettings.getInstance(context); int newFollowers = sharedPrefs.getInt("new_followers", 0); int newRetweets = sharedPrefs.getInt("new_retweets", 0); int newFavorites = sharedPrefs.getInt("new_favorites", 0); int newQuotes = sharedPrefs.getInt("new_quotes", 0); // set title if (newFavorites + newRetweets + newFollowers > 1) { title = context.getResources().getString(R.string.new_interactions); } else { title = context.getResources().getString(R.string.new_interaction_upper); } // set text String currText = sharedPrefs.getString("old_interaction_text", ""); if (!currText.equals("")) { currText += "<br>"; } if (settings.displayScreenName) { text = currText + "<b>" + interactor.getScreenName() + "</b> " + type; } else { text = currText + "<b>" + interactor.getName() + "</b> " + type; } sharedPrefs.edit().putString("old_interaction_text", text).commit(); // set icon int types = 0; if (newFavorites > 0) { types++; } if (newFollowers > 0) { types++; } if (newRetweets > 0) { types++; } if (newQuotes > 0) { types++; } if (types > 1) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon); } else { if (newFavorites > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_important_dark); } else if (newRetweets > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark); } else { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } } // set shorter text int total = newFavorites + newFollowers + newRetweets + newQuotes; if (total > 1) { smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower); } else { smallText = text; } Intent markRead = new Intent(context, ReadInteractionsService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(Html.fromHtml( settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setTicker(title) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true); if (context.getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText( Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text))); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(4, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, text); } // Light Flow notification sendToLightFlow(context, title, text); } }