Example usage for android.content Intent FLAG_FROM_BACKGROUND

List of usage examples for android.content Intent FLAG_FROM_BACKGROUND

Introduction

In this page you can find the example usage for android.content Intent FLAG_FROM_BACKGROUND.

Prototype

int FLAG_FROM_BACKGROUND

To view the source code for android.content Intent FLAG_FROM_BACKGROUND.

Click Source Link

Document

Can be set by the caller to indicate that this Intent is coming from a background operation, not from direct user interaction.

Usage

From source file:com.goftagram.telegram.messenger.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;// w  w w .  j  av  a 2 s  . c  o m
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                boolean isChat = (int) dialog_id < 0;
                popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            MessageObject messageObject = messageObjects.get(0);
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:org.cafemember.messenger.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;// w w w .j  a va 2  s  . c o m
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    if (!allowPinned
                            && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        continue;
                    }
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                boolean isChat = (int) dialog_id < 0;
                popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            MessageObject messageObject = messageObjects.get(0);
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:com.cerema.cloud2.files.services.FileDownloader.java

/**
 * Updates the status notification with the result of a download operation.
 *
 * @param downloadResult Result of the download operation.
 * @param download       Finished download operation
 */// w  ww. j  a  va 2s .c  o  m
private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) {
    mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
    if (!downloadResult.isCancelled()) {
        int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker
                : R.string.downloader_download_failed_ticker;

        boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED
                || downloadResult.isIdPRedirection());
        tickerId = (needsToUpdateCredentials) ? R.string.downloader_download_failed_credentials_error
                : tickerId;

        mNotificationBuilder.setTicker(getString(tickerId)).setContentTitle(getString(tickerId))
                .setAutoCancel(true).setOngoing(false).setProgress(0, 0, false);

        if (needsToUpdateCredentials) {

            // let the user update credentials with one click
            Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                    AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
            mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this,
                    (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));

        } else {
            // TODO put something smart in showDetailsIntent
            Intent showDetailsIntent = new Intent();
            mNotificationBuilder.setContentIntent(
                    PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showDetailsIntent, 0));
        }

        mNotificationBuilder.setContentText(
                ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources()));
        mNotificationManager.notify(tickerId, mNotificationBuilder.build());

        // Remove success notification
        if (downloadResult.isSuccess()) {
            // Sleep 2 seconds, so show the notification before remove it
            NotificationDelayer.cancelWithDelay(mNotificationManager,
                    R.string.downloader_download_succeeded_ticker, 2000);
        }

    }
}

From source file:ir.besteveryeverapp.telegram.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;/*from   w ww. j a va 2s  . c  o m*/
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    if (!allowPinned
                            && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        continue;
                    }
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                boolean isChat = (int) dialog_id < 0;
                popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0
                        && !messageObject.isMegagroup()) {
                    popup = 0;
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            MessageObject messageObject = messageObjects.get(0);
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:ir.irani.telecam.messenger.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;/*from w  w w  .j a v a 2  s  . co m*/
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    if (!allowPinned
                            && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        continue;
                    }
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                boolean isChat = (int) dialog_id < 0;
                //if(HiddenController.IsHidden(dialog_id))continue;
                popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0
                        && !messageObject.isMegagroup()) {
                    popup = 0;
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            MessageObject messageObject = messageObjects.get(0);
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:kr.wdream.storyshop.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;// w  w  w .  j  ava2  s  .  c  om
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    if (!allowPinned
                            && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        continue;
                    }
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                boolean isChat = (int) dialog_id < 0;
                popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0
                        && !messageObject.isMegagroup()) {
                    popup = 0;
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Set or update the Notification/*  www .j  av  a 2  s  .  c om*/
 */
public void setNotification() {

    String tickerText;
    String contentText = "Phone Type " + mDevice.getPhoneType();

    String iconType = prefs.getString(this.getString(R.string.pref_ui_icons_key), "sense");

    int status;

    if (mFemtoDetected || mTypeZeroSmsDetected) {
        status = 4; //ALARM
    } else if (mChangedLAC) {
        status = 3; //MEDIUM
        contentText = "Hostile Service Area: Changing LAC Detected";
    } else if (mTrackingFemtocell || mTrackingCell || mLoaded) {
        status = 2; //NORMAL
        if (mTrackingFemtocell) {
            contentText = "FemtoCell Detection Active";
        } else if (mTrackingCell) {
            contentText = "Cell Tracking Active";
        }
    } else {
        status = 1; //IDLE
    }

    int icon = R.drawable.sense_idle;

    switch (status) {
    case 1: //IDLE
        switch (iconType) {
        case "flat":
            icon = R.drawable.flat_idle;
            break;
        case "sense":
            icon = R.drawable.sense_idle;
            break;
        case "white":
            icon = R.drawable.white_idle;
            break;
        }
        tickerText = getResources().getString(R.string.app_name_short) + " - Status: Idle";
        break;
    case 2: //NORMAL
        switch (iconType) {
        case "flat":
            icon = R.drawable.flat_ok;
            break;
        case "sense":
            icon = R.drawable.sense_ok;
            break;
        case "white":
            icon = R.drawable.white_ok;
            break;
        }
        tickerText = getResources().getString(R.string.app_name_short) + " - Status: Good No Threats Detected";
        break;
    case 3: //MEDIUM
        switch (iconType) {
        case "flat":
            icon = R.drawable.flat_medium;
            break;
        case "sense":
            icon = R.drawable.sense_medium;
            break;
        case "white":
            icon = R.drawable.white_medium;
            break;
        }
        tickerText = getResources().getString(R.string.app_name_short)
                + " - Hostile Service Area: Changing LAC Detected";
        break;
    case 4: //DANGER
        switch (iconType) {
        case "flat":
            icon = R.drawable.flat_danger;
            break;
        case "sense":
            icon = R.drawable.sense_danger;
            break;
        case "white":
            icon = R.drawable.white_danger;
            break;
        }
        tickerText = getResources().getString(R.string.app_name_short) + " - ALERT!! Threat Detected";
        if (mFemtoDetected) {
            contentText = "ALERT!! FemtoCell Connection Threat Detected";
        } else if (mTypeZeroSmsDetected) {
            contentText = "ALERT!! Type Zero Silent SMS Intercepted";
        }

        break;
    default:
        icon = R.drawable.sense_idle;
        tickerText = getResources().getString(R.string.app_name);
        break;
    }

    Intent notificationIntent = new Intent(mContext, AIMSICD.class);
    notificationIntent.putExtra("silent_sms", mTypeZeroSmsDetected);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND);
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, NOTIFICATION_ID, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Notification mBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon).setTicker(tickerText)
            .setContentTitle(this.getResources().getString(R.string.app_name)).setContentText(contentText)
            .setOngoing(true).setAutoCancel(false).setContentIntent(contentIntent).build();

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder);
}

From source file:com.ferdi2005.secondgram.NotificationsController.java

public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;/*from   ww  w . j  a  va 2 s. com*/
    }
    final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean added = false;

            int oldCount = popupArray.size();
            HashMap<Long, Boolean> settingsCache = new HashMap<>();
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
            int popup = 0;

            for (int a = 0; a < messageObjects.size(); a++) {
                MessageObject messageObject = messageObjects.get(a);
                long mid = messageObject.messageOwner.id;
                if (messageObject.messageOwner.to_id.channel_id != 0) {
                    mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                }
                if (pushMessagesDict.containsKey(mid)) {
                    continue;
                }
                long dialog_id = messageObject.getDialogId();
                long original_dialog_id = dialog_id;
                if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
                    playInChatSound();
                    continue;
                }
                if (messageObject.messageOwner.mentioned) {
                    if (!allowPinned
                            && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                        continue;
                    }
                    dialog_id = messageObject.messageOwner.from_id;
                }
                if (isPersonalMessage(messageObject)) {
                    personal_count++;
                }
                added = true;

                Boolean value = settingsCache.get(dialog_id);
                int lower_id = (int) dialog_id;
                boolean isChat = lower_id < 0;
                if (lower_id != 0) {
                    if (preferences.getBoolean("custom_" + dialog_id, false)) {
                        popup = preferences.getInt("popup_" + dialog_id, 0);
                    } else {
                        popup = 0;
                    }
                    if (popup == 0) {
                        popup = preferences.getInt((int) dialog_id < 0 ? "popupGroup" : "popupAll", 0);
                    } else if (popup == 1) {
                        popup = 3;
                    } else if (popup == 2) {
                        popup = 0;
                    }
                }
                if (value == null) {
                    int notifyOverride = getNotifyOverride(preferences, dialog_id);
                    value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                            || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
                    settingsCache.put(dialog_id, value);
                }
                if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0
                        && !messageObject.isMegagroup()) {
                    popup = 0;
                }
                if (value) {
                    if (popup != 0) {
                        popupArray.add(0, messageObject);
                    }
                    delayedPushMessages.add(messageObject);
                    pushMessages.add(0, messageObject);
                    pushMessagesDict.put(mid, messageObject);
                    if (original_dialog_id != dialog_id) {
                        pushDialogsOverrideMention.put(original_dialog_id, 1);
                    }
                }
            }

            if (added) {
                notifyCheck = isLast;
            }

            if (!popupArray.isEmpty() && oldCount != popupArray.size()
                    && !AndroidUtilities.needShowPasscode(false)) {
                final int popupFinal = popup;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        if (ApplicationLoader.mainInterfacePaused
                                || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
                            if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn
                                    || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
                                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                                        PopupNotificationActivity.class);
                                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                        | Intent.FLAG_ACTIVITY_NO_ANIMATION
                                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                                ApplicationLoader.applicationContext.startActivity(popupIntent);
                            }
                        }
                    }
                });
            }
        }
    });
}

From source file:com.digitalarx.android.files.services.FileUploader.java

/**
 * Updates the status notification with the result of an upload operation.
 * //from  w  w w.  jav  a 2 s.c  o m
 * @param uploadResult Result of the upload operation.
 * @param upload Finished upload operation
 */
private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) {
    Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode());
    // / cancelled operation or success -> silent removal of progress notification
    mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker);

    // Show the result: success or fail notification
    if (!uploadResult.isCancelled()) {
        int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker
                : R.string.uploader_upload_failed_ticker;

        NotificationCompat.Builder resultBuilder = new NotificationCompat.Builder(this);

        String content = null;

        // check credentials error
        boolean needsToUpdateCredentials = (uploadResult.getCode() == ResultCode.UNAUTHORIZED
                || uploadResult.isIdPRedirection());
        tickerId = (needsToUpdateCredentials) ? R.string.uploader_upload_failed_credentials_error : tickerId;

        resultBuilder.setSmallIcon(R.drawable.notification_icon).setTicker(getString(tickerId))
                .setContentTitle(getString(tickerId)).setAutoCancel(true);

        content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources());

        if (needsToUpdateCredentials) {
            // let the user update credentials with one click
            Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount());
            updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
                    AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
            resultBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                    updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));

            mUploadClient = null; // grant that future retries on the same account will get the fresh credentials
        } else {
            // TODO put something smart in the contentIntent below

            // we add only for instant-uploads the InstantUploadActivity and the
            // db entry
            Intent detailUploadIntent = new Intent(this, InstantUploadActivity.class);
            detailUploadIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount());
            resultBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                    detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT))
                    .setContentText(content);

            if (upload.isInstant()) {
                DbHandler db = null;
                try {
                    db = new DbHandler(this.getBaseContext());
                    String message = uploadResult.getLogMessage() + " errorCode: " + uploadResult.getCode();
                    Log_OC.e(TAG, message + " Http-Code: " + uploadResult.getHttpCode());
                    if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) {
                        message = getString(R.string.failed_upload_quota_exceeded_text);
                        if (db.updateFileState(upload.getOriginalStoragePath(),
                                DbHandler.UPLOAD_STATUS_UPLOAD_FAILED, message) == 0) {
                            db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name,
                                    message);
                        }
                    }
                } finally {
                    if (db != null) {
                        db.close();
                    }
                }
            }
        }

        resultBuilder.setContentText(content);
        mNotificationManager.notify(tickerId, resultBuilder.build());

        if (uploadResult.isSuccess()) {

            DbHandler db = new DbHandler(this.getBaseContext());
            db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
            db.close();

            // remove success notification, with a delay of 2 seconds
            NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
                    2000);

        }
    }
}

From source file:org.mareatlantica.android.NotificationsController.java

public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean isLast) {
    if (messageObjects.isEmpty()) {
        return;/* ww  w.j ava2  s  . co m*/
    }
    boolean added = false;

    int oldCount = popupMessages.size();
    HashMap<Long, Boolean> settingsCache = new HashMap<Long, Boolean>();
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    int popup = 0;

    for (MessageObject messageObject : messageObjects) {
        if (pushMessagesDict.containsKey(messageObject.messageOwner.id)) {
            continue;
        }
        long dialog_id = messageObject.getDialogId();
        if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
            continue;
        }
        added = true;

        Boolean value = settingsCache.get(dialog_id);
        boolean isChat = (int) dialog_id < 0;
        popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
        if (value == null) {
            int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
            value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true)
                    || isChat && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
            settingsCache.put(dialog_id, value);
        }
        if (value) {
            if (popup != 0) {
                popupMessages.add(0, messageObject);
            }
            pushMessagesDict.put(messageObject.messageOwner.id, messageObject);
            pushMessages.add(0, messageObject);
        }
    }

    if (added) {
        notifyCheck = isLast;
    }

    if (!popupMessages.isEmpty() && oldCount != popupMessages.size()) {
        if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn) {
            MessageObject messageObject = messageObjects.get(0);
            if (popup == 3 || popup == 1 && ApplicationLoader.isScreenOn
                    || popup == 2 && !ApplicationLoader.isScreenOn) {
                Intent popupIntent = new Intent(ApplicationLoader.applicationContext,
                        PopupNotificationActivity.class);
                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                        | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
                ApplicationLoader.applicationContext.startActivity(popupIntent);
            }
        }
    }
}