Example usage for android.widget RemoteViews setImageViewResource

List of usage examples for android.widget RemoteViews setImageViewResource

Introduction

In this page you can find the example usage for android.widget RemoteViews setImageViewResource.

Prototype

public void setImageViewResource(int viewId, int srcId) 

Source Link

Document

Equivalent to calling ImageView#setImageResource(int)

Usage

From source file:github.popeen.dsub.util.Notifications.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded,
        boolean playing, boolean remote, boolean isSingleFile, boolean shouldFastForward) {
    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();
    String arist = song.getArtist();
    String album = song.getAlbum();

    // Set the album art.
    try {//from ww  w.  j av a2 s . c  o  m
        ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context);
        Bitmap bitmap = null;
        if (imageLoader != null) {
            bitmap = imageLoader.getCachedImage(context, song, false);
        }
        if (bitmap == null) {
            // set default album art
            rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            imageLoader.setNowPlayingSmall(bitmap);
            rv.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        Log.w(TAG, "Failed to get notification cover art", x);
        rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.notification_title, title);
    rv.setTextViewText(R.id.notification_artist, arist);
    rv.setTextViewText(R.id.notification_album, album);

    boolean persistent = Util.getPreferences(context)
            .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false);
    if (persistent) {
        if (expanded) {
            rv.setImageViewResource(R.id.control_pause,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);

            if (shouldFastForward) {
                rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
                rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
            } else {
                rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
                rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
            }
        } else {
            rv.setImageViewResource(R.id.control_previous,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
            if (shouldFastForward) {
                rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward);
            } else {
                rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
            }
            rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
        }
    } else if (shouldFastForward) {
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
        rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
    } else {
        // Necessary for switching back since it appears to re-use the same layout
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
        rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
    }

    // Create actions for media buttons

    int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0;
    if (expanded) {
        pause = R.id.control_pause;

        if (shouldFastForward) {
            rewind = R.id.control_previous;
            fastForward = R.id.control_next;
        } else {
            previous = R.id.control_previous;
            next = R.id.control_next;
        }

        if (remote || persistent) {
            close = R.id.notification_close;
            rv.setViewVisibility(close, View.VISIBLE);
        }
    } else {
        if (persistent) {
            pause = R.id.control_previous;
            if (shouldFastForward) {
                fastForward = R.id.control_pause;
            } else {
                next = R.id.control_pause;
            }
            close = R.id.control_next;
        } else {
            if (shouldFastForward) {
                rewind = R.id.control_previous;
                fastForward = R.id.control_next;
            } else {
                previous = R.id.control_previous;
                next = R.id.control_next;
            }

            pause = R.id.control_pause;
        }
    }

    if (isSingleFile) {
        if (previous > 0) {
            rv.setViewVisibility(previous, View.GONE);
            previous = 0;
        }
        if (rewind > 0) {
            rv.setViewVisibility(rewind, View.GONE);
            rewind = 0;
        }

        if (next > 0) {
            rv.setViewVisibility(next, View.GONE);
            next = 0;
        }

        if (fastForward > 0) {
            rv.setViewVisibility(fastForward, View.GONE);
            fastForward = 0;
        }
    }

    PendingIntent pendingIntent;
    if (previous > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));

        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(previous, pendingIntent);
    }
    if (rewind > 0) {
        Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND");
        rewindIntent.setComponent(new ComponentName(context, DownloadService.class));
        rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND));
        pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0);
        rv.setOnClickPendingIntent(rewind, pendingIntent);
    }
    if (pause > 0) {
        if (playing) {
            Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
            pauseIntent.setComponent(new ComponentName(context, DownloadService.class));

            pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
            pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        } else {
            Intent prevIntent = new Intent("KEYCODE_MEDIA_START");
            prevIntent.setComponent(new ComponentName(context, DownloadService.class));

            prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY));
            pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        }
    }
    if (next > 0) {
        Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
        nextIntent.setComponent(new ComponentName(context, DownloadService.class));

        nextIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
        pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
        rv.setOnClickPendingIntent(next, pendingIntent);
    }
    if (fastForward > 0) {
        Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD");
        fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class));
        fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD));
        pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0);
        rv.setOnClickPendingIntent(fastForward, pendingIntent);
    }
    if (close > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));

        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(close, pendingIntent);
    }
}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

@Override
protected void updateView(Context context, RemoteViews remoteViews, Bundle widgetOptions) {
    if ((wifiState == WifiManager.WIFI_STATE_DISABLED) || (wifiState == WifiManager.WIFI_STATE_UNKNOWN)) {
        setStateColor(context, remoteViews, STATE_OFF);
        remoteViews.setTextViewText(R.id.wifiNameTextView, context.getString(R.string.wifi));
        remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_off);
        remoteViews.setViewVisibility(R.id.wifiInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.tap_to_change));
        remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.GONE);
    } else if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
        remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_on);
        remoteViews.setViewVisibility(R.id.wifiInfoTopTextView, View.VISIBLE);

        if (wifiInfo.getIpAddress() != 0) {
            setStateColor(context, remoteViews, STATE_ON);
            remoteViews.setTextViewText(R.id.wifiNameTextView, wifiInfo.getSSID().replace("\"", ""));

            if (!detailsString.isEmpty()) {
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, detailsString);
                remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.VISIBLE);
                remoteViews.setTextViewText(R.id.wifiInfoBottomTextView,
                        WifiUtils.getIpAddressString(wifiInfo.getIpAddress()));
            }//from   w w w. ja  va  2  s.  co m
        } else {
            remoteViews.setViewVisibility(R.id.wifiInfoBottomTextView, View.GONE);

            if (detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.connecting));
            } else {
                setStateColor(context, remoteViews, STATE_ON);
                remoteViews.setTextViewText(R.id.wifiNameTextView, context.getString(R.string.wifi));
                remoteViews.setImageViewResource(R.id.wifiStateImageView, R.drawable.ic_signal_wifi_enabled);
                remoteViews.setTextViewText(R.id.wifiInfoTopTextView, context.getString(R.string.no_network));
            }
        }
    }
}

From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

@Override
protected void updateView(Context context, RemoteViews remoteViews, Bundle widgetOptions) {
    if (isMobileDataEnabled && isMobileOutOfService) {
        setStateColor(context, remoteViews, STATE_ON);
        remoteViews.setTextViewText(R.id.mobileNameTextView, context.getString(R.string.mobile_data));
        remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled);
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.no_service));
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE);
        return;/*from ww w.j av a  2  s  . c  om*/
    }

    if (dataState == TelephonyManager.DATA_DISCONNECTED) {
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE);

        if (isMobileDataEnabled && !isAirplaneModeOn) {
            setStateColor(context, remoteViews, STATE_ON);
            remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider);
            remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_enabled);
            remoteViews.setTextViewText(R.id.mobileInfoTopTextView, context.getString(R.string.not_connected));
            remoteViews.setTextColor(R.id.mobileInfoBottomTextView,
                    ContextCompat.getColor(context, R.color.medium_gray));
            remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                    MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes()));
        } else {
            setStateColor(context, remoteViews, STATE_OFF);
            remoteViews.setTextViewText(R.id.mobileNameTextView,
                    isAirplaneModeOn ? context.getString(R.string.mobile_data)
                            : networkOperatorAndServiceProvider);
            remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_off);

            if (isAirplaneModeOn) {
                remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                        context.getString(R.string.flight_mode));
                remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.GONE);
            } else {
                remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                        MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType())
                                + (isDataRoaming ? " - " + context.getString(R.string.roaming) : ""));
                remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                        MobileDataUtils.getDataUsageString(context, NetworkStateService.getDataUsageBytes()));
            }
        }
    } else {
        setStateColor(context, remoteViews, STATE_ON);
        remoteViews.setTextViewText(R.id.mobileNameTextView, networkOperatorAndServiceProvider);
        remoteViews.setImageViewResource(R.id.mobileStateImageView, R.drawable.ic_signal_cellular_on);
        remoteViews.setViewVisibility(R.id.mobileInfoTopTextView, View.VISIBLE);
        remoteViews.setTextViewText(R.id.mobileInfoTopTextView,
                MobileDataUtils.getNetworkTypeString(telephonyManager.getNetworkType())
                        + (isDataRoaming ? " - " + context.getString(R.string.roaming) : ""));
        remoteViews.setViewVisibility(R.id.mobileInfoBottomTextView, View.VISIBLE);

        boolean isConnecting = ((dataState == TelephonyManager.DATA_CONNECTING)
                || NetworkStateService.isWaitingForDataUsage());
        remoteViews.setTextViewText(R.id.mobileInfoBottomTextView,
                isConnecting ? context.getString(R.string.connecting)
                        : MobileDataUtils.getDataUsageString(context, dataUsageBytes));
    }
}

From source file:com.android.deskclock.data.StopwatchNotificationBuilderPreN.java

@Override
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
    @StringRes/*from w  ww  .  j a v  a2  s . c o  m*/
    final int eventLabel = R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = context.getPackageName();
    final Resources res = context.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed);
    collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running);
    collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp);
    collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded);
    expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running);
    expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp);
    expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    @IdRes
    final int leftButtonId = R.id.swn_left_button;
    @IdRes
    final int rightButtonId = R.id.swn_right_button;
    if (running) {
        // Left button: Pause
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp);
        final Intent pause = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingPause = Utils.pendingServiceIntent(context, pause);
        expanded.setOnClickPendingIntent(leftButtonId, pendingPause);

        // Right button: Add Lap
        if (DataModel.getDataModel().canAddMoreLaps()) {
            expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button));
            setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp);

            final Intent lap = new Intent(context, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
            final PendingIntent pendingLap = Utils.pendingServiceIntent(context, lap);
            expanded.setOnClickPendingIntent(rightButtonId, pendingLap);
            expanded.setViewVisibility(rightButtonId, VISIBLE);
        } else {
            expanded.setViewVisibility(rightButtonId, INVISIBLE);
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = DataModel.getDataModel().getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber);
            collapsed.setTextViewText(R.id.swn_collapsed_laps, lap);
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
            expanded.setTextViewText(R.id.swn_expanded_laps, lap);
            expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
        } else {
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE);
            expanded.setViewVisibility(R.id.swn_expanded_laps, GONE);
        }
    } else {
        // Left button: Start
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp);
        final Intent start = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingStart = Utils.pendingServiceIntent(context, start);
        expanded.setOnClickPendingIntent(leftButtonId, pendingStart);

        // Right button: Reset (dismisses notification and resets stopwatch)
        expanded.setViewVisibility(rightButtonId, VISIBLE);
        expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button));
        setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp);
        final Intent reset = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingReset = Utils.pendingServiceIntent(context, reset);
        expanded.setOnClickPendingIntent(rightButtonId, pendingReset);

        // Indicate the stopwatch is paused.
        collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused));
        collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
        expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused));
        expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(context, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final Notification notification = new NotificationCompat.Builder(context).setLocalOnly(true)
            .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused())
            .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch)
            .setDeleteIntent(Utils.pendingServiceIntent(context, reset))
            .setColor(ContextCompat.getColor(context, R.color.default_background)).build();
    notification.bigContentView = expanded;
    return notification;
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);//  www . ja  v  a2 s .com

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setFinishedNotification(int apkidHash, String localPath) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.finished_download_message) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES,
            size * KBYTES_TO_BYTES, false);

    Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid));
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.putExtra("localPath", localPath);
    onClick.putExtra("apkid", apkid);
    onClick.putExtra("apkidHash", apkidHash);
    onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate")));
    /*Changed by Rafael Campos*/
    onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version"));
    Log.d("Aptoide-DownloadQueuService",
            "finished notification apkidHash: " + apkidHash + " localPath: " + localPath);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");

}

From source file:com.devbrackets.android.exomedia.EMNotification.java

/**
 * Updates the images for the play/pause, next, and previous buttons so that only valid ones are
 * displayed with the correct state.//ww  w.j av a 2 s .com
 *
 * @param bigContent The RemoteViews to use to modify the state
 */
private void updateBigNotificationMediaState(RemoteViews bigContent) {
    NotificationMediaState state = notificationInfo.getMediaState();
    if (bigContent == null || state == null) {
        return;
    }

    bigContent.setImageViewResource(R.id.exomedia_big_notification_playpause,
            state.isPlaying() ? R.drawable.exomedia_notification_pause : R.drawable.exomedia_notification_play);
    bigContent.setInt(R.id.exomedia_big_notification_prev, "setVisibility",
            state.isPreviousEnabled() ? View.VISIBLE : View.INVISIBLE);
    bigContent.setInt(R.id.exomedia_big_notification_next, "setVisibility",
            state.isNextEnabled() ? View.VISIBLE : View.INVISIBLE);
}

From source file:org.xbmc.kore.service.NotificationObserver.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void buildNotification(PlayerType.GetActivePlayersReturnType getActivePlayerResult,
        PlayerType.PropertyValue getPropertiesResult, ListType.ItemsAll getItemResult) {
    final String title, underTitle, poster;
    int smallIcon, playPauseIcon, rewindIcon, ffIcon;

    boolean isVideo = ((getItemResult.type.equals(ListType.ItemsAll.TYPE_MOVIE))
            || (getItemResult.type.equals(ListType.ItemsAll.TYPE_EPISODE)));

    switch (getItemResult.type) {
    case ListType.ItemsAll.TYPE_MOVIE:
        title = getItemResult.title;/* w  w w.j  a v a2  s  .c  o  m*/
        underTitle = getItemResult.tagline;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_movie_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_EPISODE:
        title = getItemResult.title;
        String seasonEpisode = String.format(mContext.getString(R.string.season_episode_abbrev),
                getItemResult.season, getItemResult.episode);
        underTitle = String.format("%s | %s", getItemResult.showtitle, seasonEpisode);
        poster = getItemResult.art.poster;
        smallIcon = R.drawable.ic_tv_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_SONG:
        title = getItemResult.title;
        underTitle = getItemResult.displayartist + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    case ListType.ItemsAll.TYPE_MUSIC_VIDEO:
        title = getItemResult.title;
        underTitle = Utils.listStringConcat(getItemResult.artist, ", ") + " | " + getItemResult.album;
        poster = getItemResult.thumbnail;
        smallIcon = R.drawable.ic_headset_white_24dp;
        break;
    default:
        // We don't know what this is, forget it
        return;
    }

    switch (getPropertiesResult.speed) {
    case 1:
        playPauseIcon = R.drawable.ic_pause_white_24dp;
        break;
    default:
        playPauseIcon = R.drawable.ic_play_arrow_white_24dp;
        break;
    }

    // Create the actions, depending on the type of media
    PendingIntent rewindPendingItent, ffPendingItent, playPausePendingIntent;
    playPausePendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid,
            IntentActionsService.ACTION_PLAY_PAUSE);
    if (getItemResult.type.equals(ListType.ItemsAll.TYPE_SONG)) {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_PREVIOUS);
        rewindIcon = R.drawable.ic_skip_previous_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_NEXT);
        ffIcon = R.drawable.ic_skip_next_white_24dp;
    } else {
        rewindPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_REWIND);
        rewindIcon = R.drawable.ic_fast_rewind_white_24dp;
        ffPendingItent = buildActionPendingIntent(getActivePlayerResult.playerid,
                IntentActionsService.ACTION_FAST_FORWARD);
        ffIcon = R.drawable.ic_fast_forward_white_24dp;
    }

    // Setup the collpased and expanded notifications
    final RemoteViews collapsedRV = new RemoteViews(mContext.getPackageName(), R.layout.notification_colapsed);
    collapsedRV.setImageViewResource(R.id.rewind, rewindIcon);
    collapsedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    collapsedRV.setImageViewResource(R.id.play, playPauseIcon);
    collapsedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    collapsedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    collapsedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    collapsedRV.setTextViewText(R.id.title, title);
    collapsedRV.setTextViewText(R.id.text2, underTitle);

    final RemoteViews expandedRV = new RemoteViews(mContext.getPackageName(), R.layout.notification_expanded);
    expandedRV.setImageViewResource(R.id.rewind, rewindIcon);
    expandedRV.setOnClickPendingIntent(R.id.rewind, rewindPendingItent);
    expandedRV.setImageViewResource(R.id.play, playPauseIcon);
    expandedRV.setOnClickPendingIntent(R.id.play, playPausePendingIntent);
    expandedRV.setImageViewResource(R.id.fast_forward, ffIcon);
    expandedRV.setOnClickPendingIntent(R.id.fast_forward, ffPendingItent);
    expandedRV.setTextViewText(R.id.title, title);
    expandedRV.setTextViewText(R.id.text2, underTitle);
    final int expandedIconResId;
    if (isVideo) {
        expandedIconResId = R.id.icon_slim;
        expandedRV.setViewVisibility(R.id.icon_slim, View.VISIBLE);
        expandedRV.setViewVisibility(R.id.icon_square, View.GONE);
    } else {
        expandedIconResId = R.id.icon_square;
        expandedRV.setViewVisibility(R.id.icon_slim, View.GONE);
        expandedRV.setViewVisibility(R.id.icon_square, View.VISIBLE);
    }

    // Build the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    final Notification notification = builder.setSmallIcon(smallIcon).setShowWhen(false).setOngoing(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_TRANSPORT).setContentIntent(mRemoteStartPendingIntent)
            .setContent(collapsedRV).build();

    // This is a convoluted way of loading the image and showing the
    // notification, but it's what works with Picasso and is efficient.
    // Here's what's going on:
    //
    // 1. The image is loaded asynchronously into a Target, and only after
    // it is loaded is the notification shown. Using targets is a lot more
    // efficient than letting Picasso load it directly into the
    // notification imageview, which causes a lot of flickering
    //
    // 2. The target needs to be static, because Picasso only keeps a weak
    // reference to it, so we need to keed a strong reference and reset it
    // to null when we're done. We also need to check if it is not null in
    // case a previous request hasn't finished yet.
    //
    // 3. We can only show the notification after the bitmap is loaded into
    // the target, so it is done in the callback
    //
    // 4. We specifically resize the image to the same dimensions used in
    // the remote, so that Picasso reuses it in the remote and here from the cache
    Resources resources = mContext.getResources();
    final int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    final int posterHeight = isVideo ? resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height)
            : posterWidth;
    if (picassoTarget == null) {
        picassoTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                showNotification(bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                CharacterDrawable avatarDrawable = UIUtils.getCharacterAvatar(mContext, title);
                showNotification(Utils.drawableToBitmap(avatarDrawable, posterWidth, posterHeight));
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }

            private void showNotification(Bitmap bitmap) {
                collapsedRV.setImageViewBitmap(R.id.icon, bitmap);
                if (Utils.isJellybeanOrLater()) {
                    notification.bigContentView = expandedRV;
                    expandedRV.setImageViewBitmap(expandedIconResId, bitmap);
                }

                NotificationManager notificationManager = (NotificationManager) mContext
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(NOTIFICATION_ID, notification);
                picassoTarget = null;
            }
        };

        // Load the image
        HostManager hostManager = HostManager.getInstance(mContext);
        hostManager.getPicasso().load(hostManager.getHostInfo().getImageUrl(poster))
                .resize(posterWidth, posterHeight).into(picassoTarget);
    }
}

From source file:fi.hut.soberit.sensors.services.BatchDataUploadService.java

private void showBatchUploadNotification(String text, int progress, boolean noClear) {
    if (notification == null) {
        notification = new Notification(R.drawable.ic_icon_export, text, System.currentTimeMillis());

        // final Intent appIntent = new Intent(this, SIDE.class);
        final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, null, 0);

        notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent);

        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.batch_upload_notification_layout);
        contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_icon_export);
        notification.contentView = contentView;
    }/* w w w .j a v  a  2 s. c om*/

    notification.contentView.setTextViewText(R.id.status_text, text);
    notification.contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, progress, false);

    if (noClear) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    } else {
        notificationManager.cancel(R.id.batch_upload);

        notification.flags ^= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }
    notificationManager.notify(R.id.batch_upload, notification);
}

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

public Notification createPaused() {
    Notification notification = new Notification();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download);

    views.setProgressBar(R.id.progressDownload, 100, 0, false);
    views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.paused));
    views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle());
    views.setImageViewResource(R.id.notifPause, R.drawable.widget_play);

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(new ComponentName(context, DownloadingService.class));

    Intent intentPause = new Intent(PlayingService.actionIconPlay);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(new ComponentName(context, DownloadingService.class));

    views.setOnClickPendingIntent(R.id.notifClose,
            PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT));

    views.setOnClickPendingIntent(R.id.notifPause,
            PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT));

    notification.contentView = views;/*from   www  .j  a  v  a  2s  .  c o  m*/
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;
}