Search in sources :

Example 1 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    NotificationManagerCompat mgr = NotificationManagerCompat.from(this);
    NotificationCompat.Builder normal = buildNormal();
    NotificationCompat.Action.Builder wearActionBuilder = new NotificationCompat.Action.Builder(android.R.drawable.ic_media_pause, getString(R.string.pause), buildPendingIntent(Settings.ACTION_DATE_SETTINGS));
    NotificationCompat.Builder extended = new NotificationCompat.WearableExtender().addAction(wearActionBuilder.build()).extend(normal);
    mgr.notify(NOTIFY_ID, extended.build());
    finish();
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 2 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    NotificationManagerCompat mgr = NotificationManagerCompat.from(this);
    NotificationCompat.Builder normal = buildNormal();
    NotificationCompat.InboxStyle big = new NotificationCompat.InboxStyle();
    big.setSummaryText(getString(R.string.summary)).addLine(getString(R.string.entry)).addLine(getString(R.string.another_entry)).addLine(getString(R.string.third_entry)).addLine(getString(R.string.yet_another_entry)).addLine(getString(R.string.low));
    NotificationCompat.Builder bigPage = new NotificationCompat.Builder(this).setStyle(big);
    NotificationCompat.Builder twoPages = new NotificationCompat.WearableExtender().addPage(bigPage.build()).extend(normal);
    mgr.notify(NOTIFY_ID, twoPages.build());
    finish();
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 3 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project SeriesGuide by UweTrottmann.

the class QuickCheckInActivity method onEvent.

@SuppressWarnings("unused")
@Subscribe
public void onEvent(TraktTask.TraktActionCompleteEvent event) {
    if (event.mTraktAction != TraktAction.CHECKIN_EPISODE) {
        return;
    }
    // display status toast about trakt action
    event.handle(this);
    // dismiss notification on successful check-in
    if (event.mWasSuccessful) {
        NotificationManagerCompat manager = NotificationManagerCompat.from(getApplicationContext());
        manager.cancel(SgApp.NOTIFICATION_EPISODE_ID);
        // replicate delete intent
        NotificationService.handleDeleteIntent(this, getIntent());
    }
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 4 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.

the class NotificationUtils method notifySecondDMs.

public static void notifySecondDMs(Context context, int secondAccount) {
    DMDataSource data = DMDataSource.getInstance(context);
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0);
    int smallIcon = R.drawable.ic_stat_icon;
    Bitmap largeIcon;
    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);
        // 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);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 5 with NotificationManagerCompat

use of android.preview.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.

the class NotificationUtils method newInteractions.

// type is either " retweeted your status", " favorited your status", or " followed you"
public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs, String type) {
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;
    AppSettings settings = AppSettings.getInstance(context);
    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    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_heart_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).setContentIntent(resultPendingIntent).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);
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)38 NotificationCompat (android.support.v4.app.NotificationCompat)17 PendingIntent (android.app.PendingIntent)15 Intent (android.content.Intent)15 SharedPreferences (android.content.SharedPreferences)7 PowerManager (android.os.PowerManager)7 Bitmap (android.graphics.Bitmap)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)6 Notification (android.app.Notification)5 Context (android.content.Context)4 Cursor (android.database.Cursor)4 RemoteInput (android.support.v4.app.RemoteInput)4 Bundle (android.os.Bundle)3 ComponentName (android.content.ComponentName)2 ContentResolver (android.content.ContentResolver)2 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 Builder (android.support.v4.app.NotificationCompat.Builder)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 ArrayList (java.util.ArrayList)2