List of usage examples for android.content Context MODE_WORLD_READABLE
int MODE_WORLD_READABLE
To view the source code for android.content Context MODE_WORLD_READABLE.
Click Source Link
From source file:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java
@Override public void onCreate() { Log.d(TAG, ".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName); wifiLock.setReferenceCounted(false); application = (WalletApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); final int versionCode = application.applicationVersionCode(); prefs.edit().putInt(Constants.PREFS_KEY_LAST_VERSION, versionCode).commit(); bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0);//from w w w. j av a 2s. c om final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); blockChainFile = new File(getDir("blockstore", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { Log.d(TAG, "blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); copyBlockchainSnapshot(blockChainFile); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); if (!blockChainFileExists) { // Starting from scratch try { final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); final InputStream checkpointsFileIn = getAssets().open("checkpoints"); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsFileIn, blockStore, earliestKeyCreationTime); } catch (IOException e) { Log.d("Elysium", "Couldn't find checkpoints file; starting from genesis"); } } blockStore.getChainHead(); // detect corruptions as early as possible } catch (final BlockStoreException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } catch (final NullPointerException x) { blockChainFile.delete(); x.printStackTrace(); throw new Error("blockstore cannot be created", x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } application.getWallet().addEventListener(walletEventListener); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotificationToActivity(ArrayList<String[]> tweets, Context context) { SharedPreferences.Editor e = context.getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit(); e.putString("fav_user_tweet_name", tweets.get(0)[0]); e.putString("fav_user_tweet_text", tweets.get(0)[1]); e.putString("fav_user_tweet_screenname", tweets.get(0)[2]); e.putLong("fav_user_tweet_time", Long.parseLong(tweets.get(0)[3])); e.putString("fav_user_tweet_retweeter", tweets.get(0)[4]); e.putString("fav_user_tweet_webpage", tweets.get(0)[5]); e.putBoolean("fav_user_tweet_picture", tweets.get(0)[6].equals("true") ? true : false); e.putLong("fav_user_tweet_tweet_id", Long.parseLong(tweets.get(0)[7])); e.putString("fav_user_tweet_pro_pic", tweets.get(0)[8]); e.putString("fav_user_tweet_users", tweets.get(0)[9]); e.putString("fav_user_tweet_hashtags", tweets.get(0)[10]); e.putString("fav_user_tweet_links", tweets.get(0)[11]); e.commit();//from ww w.ja va2 s . co m makeFavsNotification(tweets, context, false); }
From source file:com.tct.mail.browse.MessageAttachmentBar.java
private void importXvcard(Attachment attachment, final String type) { new AsyncTask<Attachment, Void, Uri>() { @Override//from ww w .j ava 2 s.c om protected Uri doInBackground(Attachment... params) { final Attachment attach = params[0]; final String[] filenames = mContext.fileList(); for (String file : filenames) { if (file.endsWith(".vcf")) { mContext.deleteFile(file); } } try { InputStream in = null; OutputStream out = null; try { in = mContext.getContentResolver().openInputStream(attach.contentUri); out = mContext.openFileOutput(attach.getName(), Context.MODE_WORLD_READABLE); byte[] buf = new byte[8096]; int seg = 0; while ((seg = in.read(buf)) != -1) { out.write(buf, 0, seg); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } catch (FileNotFoundException e) { LogUtils.e(LOG_TAG, "importVCard, file not found " + attach + ", exception ", e); } catch (IOException e) { LogUtils.e(LOG_TAG, "importVCard, ioexception " + attach + ", exception ", e); } catch (Exception e) { LogUtils.e(LOG_TAG, "importVCard, unknown errror ", e); } final File tempVCard = mContext.getFileStreamPath(attach.getName()); if (!tempVCard.exists() || tempVCard.length() <= 0) { LogUtils.e(LOG_TAG, "importVCard, file is not exists or empty " + tempVCard); return null; } return Uri.fromFile(tempVCard); } @Override protected void onPostExecute(Uri uri) { super.onPostExecute(uri); if (uri == null) return; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); Utils.setIntentDataAndTypeAndNormalize(intent, uri, type); try { getContext().startActivity(intent); } catch (ActivityNotFoundException e) { // couldn't find activity for View intent LogUtils.e(LOG_TAG, e, "Couldn't find Activity for intent"); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); int dialogMessage = R.string.no_application_found; builder.setTitle(R.string.more_info_attachment).setMessage(dialogMessage).show(); } } }.execute(attachment); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotificationToActivity(ArrayList<String[]> tweets, Context context) { SharedPreferences.Editor e = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE).edit(); e.putString("fav_user_tweet_name", tweets.get(0)[0]); e.putString("fav_user_tweet_text", tweets.get(0)[1]); e.putString("fav_user_tweet_screenname", tweets.get(0)[2]); e.putLong("fav_user_tweet_time", Long.parseLong(tweets.get(0)[3])); e.putString("fav_user_tweet_retweeter", tweets.get(0)[4]); e.putString("fav_user_tweet_webpage", tweets.get(0)[5]); e.putBoolean("fav_user_tweet_picture", tweets.get(0)[6].equals("true") ? true : false); e.putLong("fav_user_tweet_tweet_id", Long.parseLong(tweets.get(0)[7])); e.putString("fav_user_tweet_pro_pic", tweets.get(0)[8]); e.putString("fav_user_tweet_users", tweets.get(0)[9]); e.putString("fav_user_tweet_hashtags", tweets.get(0)[10]); e.putString("fav_user_tweet_links", tweets.get(0)[11]); e.commit();//from w w w. jav a2s . c om makeFavsNotification(tweets, context, false); }
From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java
private void importNiLSFPPreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (!prefs.getBoolean("prefs_imported", false)) { Context nilsfpCtx = null; try {//from ww w . j a va2 s . c om nilsfpCtx = createPackageContext("com.roymam.android.nilsplus", 0); SharedPreferences nilsfpPrefs = nilsfpCtx.getSharedPreferences("shared_preferences", Context.MODE_WORLD_READABLE); // copy global_settings Map<String, ?> map = nilsfpPrefs.getAll(); for (String key : map.keySet()) { Object x = map.get(key); if (x instanceof Boolean) prefs.edit().putBoolean(key, (Boolean) x).commit(); else if (x instanceof Integer) prefs.edit().putInt(key, (Integer) x).commit(); else if (x instanceof Float) prefs.edit().putFloat(key, (Float) x).commit(); else if (x instanceof Long) prefs.edit().putLong(key, (Long) x).commit(); else if (x instanceof String) prefs.edit().putString(key, (String) x).commit(); } prefs.edit().putBoolean("prefs_imported", true).commit(); // handling old lock screen detection values if (prefs.getString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .equals("auto")) { prefs.edit() .putString(SettingsManager.LOCKSCREEN_APP, prefs.getString("lockscreenapp_auto", SettingsManager.DEFAULT_LOCKSCREEN_APP)) .commit(); } if (prefs.getString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .equals("android")) { prefs.edit().putString(SettingsManager.LOCKSCREEN_APP, SettingsManager.DEFAULT_LOCKSCREEN_APP) .commit(); } Toast.makeText(getApplicationContext(), "Preferences and license information has been imported successfully from NiLS Floating Panel", Toast.LENGTH_LONG).show(); } catch (PackageManager.NameNotFoundException e) { // NiLS FP not available - do not do anything } } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;/*from w w w .j a va 2 s.co m*/ String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, null, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } 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(2, 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, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.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;//w w w .j a v a 2s .c o m 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).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.klinker.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;//from w w w . ja va 2s . c o m String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; Intent resultIntent; if (toDrawer) { resultIntent = new Intent(context, RedirectToDrawer.class); } else { resultIntent = new Intent(context, NotiTweetPager.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } 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(2, 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, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
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;// w w w . ja va 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;/*from ww w .j a va 2 s. 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); } }