Example usage for android.widget RemoteViews setOnClickPendingIntent

List of usage examples for android.widget RemoteViews setOnClickPendingIntent

Introduction

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

Prototype

public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent) 

Source Link

Document

Equivalent to calling android.view.View#setOnClickListener(android.view.View.OnClickListener) to launch the provided PendingIntent .

Usage

From source file:github.madmarty.madsonic.util.Util.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) {

    // 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 {//  w w w  .j  av  a 2 s  .  c o  m
        int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
        Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
        if (bitmap == null) {
            // set default album art
            rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            rv.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        LOG.warn("Failed to get notification cover art", x);
        rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    rv.setImageViewResource(R.id.control_starred,
            song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);

    // 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);

    Pair<Integer, Integer> colors = getNotificationTextColors(context);
    if (colors.getFirst() != null) {
        rv.setTextColor(R.id.notification_title, colors.getFirst());
    }
    if (colors.getSecond() != null) {
        rv.setTextColor(R.id.notification_artist, colors.getSecond());
    }

    if (!playing) {
        rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play);
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop);
    }

    // Create actions for media buttons
    PendingIntent pendingIntent;
    if (playing) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
        prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
    } else {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
        prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
    }

    Intent starredIntent = new Intent("KEYCODE_MEDIA_STARRED");
    starredIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    starredIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_STAR));
    pendingIntent = PendingIntent.getService(context, 0, starredIntent, 0);
    rv.setOnClickPendingIntent(R.id.control_starred, pendingIntent);

    Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
    pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
    pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
    rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent);

    Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
    nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    nextIntent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
    pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
    rv.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}

From source file:com.irccloud.android.data.collection.NotificationsList.java

@SuppressLint("NewApi")
private android.app.Notification buildNotification(String ticker, int cid, int bid, long[] eids, String title,
        String text, int count, Intent replyIntent, String network, ArrayList<Notification> messages,
        NotificationCompat.Action otherAction, Bitmap largeIcon, Bitmap wearBackground) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel c = new NotificationChannel(String.valueOf(bid), title,
                NotificationManager.IMPORTANCE_HIGH);
        c.setGroup(String.valueOf(cid));
        ((NotificationManager) IRCCloudApplication.getInstance().getApplicationContext()
                .getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(c);
    }/*from   w  w w  . jav  a  2  s  .  co m*/
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext());
    int defaults = 0;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            IRCCloudApplication.getInstance().getApplicationContext(), String.valueOf(bid))
                    .setContentTitle(
                            title + ((network != null && !network.equals(title)) ? (" (" + network + ")") : ""))
                    .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker)
                    .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify).setLargeIcon(largeIcon)
                    .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources()
                            .getColor(R.color.ic_background))
                    .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setPriority(hasTouchWiz() ? NotificationCompat.PRIORITY_DEFAULT
                            : NotificationCompat.PRIORITY_HIGH)
                    .setOnlyAlertOnce(false);

    if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000) {
        String ringtone = prefs.getString("notify_ringtone",
                "android.resource://"
                        + IRCCloudApplication.getInstance().getApplicationContext().getPackageName() + "/"
                        + R.raw.digit);
        if (ringtone.length() > 0)
            builder.setSound(Uri.parse(ringtone));
    }

    int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1"));
    if (led_color == 1) {
        defaults = android.app.Notification.DEFAULT_LIGHTS;
    } else if (led_color == 2) {
        builder.setLights(0xFF0000FF, 500, 500);
    }

    if (prefs.getBoolean("notify_vibrate", true) && ticker != null
            && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000)
        defaults |= android.app.Notification.DEFAULT_VIBRATE;
    else
        builder.setVibrate(new long[] { 0L });

    builder.setDefaults(defaults);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putLong("lastNotificationTime", System.currentTimeMillis());
    editor.commit();

    Intent i = new Intent();
    i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
            "com.irccloud.android.MainActivity"));
    i.putExtra("bid", bid);
    i.setData(Uri.parse("bid://" + bid));
    Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources()
            .getString(R.string.DISMISS_NOTIFICATION));
    dismiss.setData(Uri.parse("irccloud-dismiss://" + bid));
    dismiss.putExtra("bid", bid);
    dismiss.putExtra("eids", eids);

    PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(
            IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(
            PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT));
    builder.setDeleteIntent(dismissPendingIntent);

    WearableExtender wearableExtender = new WearableExtender();
    wearableExtender.setBackground(wearBackground);
    if (messages != null && messages.size() > 0) {
        StringBuilder weartext = new StringBuilder();
        String servernick = getServerNick(messages.get(0).cid);
        NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle(servernick);
        style.setConversationTitle(title + ((network != null) ? (" (" + network + ")") : ""));
        for (Notification n : messages) {
            if (n != null && n.message != null && n.message.length() > 0) {
                if (weartext.length() > 0)
                    weartext.append("<br/>");
                if (n.message_type.equals("buffer_me_msg")) {
                    style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000,
                            " " + ((n.nick == null) ? servernick : n.nick));
                    weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick).append("</b> ")
                            .append(n.message);
                } else {
                    style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000, n.nick);
                    weartext.append("<b>&lt;").append((n.nick == null) ? servernick : n.nick)
                            .append("&gt;</b> ").append(n.message);
                }
            }
        }

        ArrayList<String> history = new ArrayList<>(messages.size());
        for (int j = messages.size() - 1; j >= 0; j--) {
            Notification n = messages.get(j);
            if (n != null) {
                if (n.nick == null)
                    history.add(Html.fromHtml(n.message).toString());
                else
                    break;
            }
        }
        builder.setRemoteInputHistory(history.toArray(new String[history.size()]));
        builder.setStyle(style);

        if (messages.size() > 1) {
            wearableExtender.addPage(
                    new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext())
                            .setContentText(Html.fromHtml(weartext.toString()))
                            .extend(new WearableExtender().setStartScrollBottom(true)).build());
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
                && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            weartext.setLength(0);
            int j = 0;
            for (Notification n : messages) {
                if (messages.size() - ++j < 3) {
                    if (n != null && n.message != null && n.message.length() > 0) {
                        if (weartext.length() > 0)
                            weartext.append("<br/>");
                        if (n.message_type.equals("buffer_me_msg")) {
                            weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick)
                                    .append("</b> ").append(n.message);
                        } else {
                            weartext.append("<b>&lt;").append((n.nick == null) ? servernick : n.nick)
                                    .append("&gt;</b> ").append(n.message);
                        }
                    }
                }
            }

            RemoteViews bigContentView = new RemoteViews(
                    IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                    R.layout.notification_expanded);
            bigContentView.setTextViewText(R.id.title,
                    title + (!title.equals(network) ? (" (" + network + ")") : ""));
            bigContentView.setTextViewText(R.id.text, Html.fromHtml(weartext.toString()));
            bigContentView.setImageViewBitmap(R.id.image, largeIcon);
            bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000);
            if (count > 3) {
                bigContentView.setViewVisibility(R.id.more, View.VISIBLE);
                bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more");
            } else {
                bigContentView.setViewVisibility(R.id.more, View.GONE);
            }
            if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) {
                bigContentView.setViewVisibility(R.id.actions, View.VISIBLE);
                bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE);
                i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(),
                        QuickReplyActivity.class);
                i.setData(Uri.parse("irccloud-bid://" + bid));
                i.putExtras(replyIntent);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent quickReplyIntent = PendingIntent.getActivity(
                        IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent);
            }
            builder.setCustomBigContentView(bigContentView);
        }
    }

    if (replyIntent != null) {
        PendingIntent replyPendingIntent = PendingIntent.getService(
                IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            builder.addAction(new NotificationCompat.Action.Builder(0, "Reply", replyPendingIntent)
                    .setAllowGeneratedReplies(true)
                    .addRemoteInput(
                            new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build())
                    .build());
        }

        NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder(
                R.drawable.ic_wearable_reply, "Reply", replyPendingIntent).setAllowGeneratedReplies(true)
                        .addRemoteInput(
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build());

        NotificationCompat.Action.WearableExtender actionExtender = new NotificationCompat.Action.WearableExtender()
                .setHintLaunchesActivity(true).setHintDisplayActionInline(true);

        wearableExtender.addAction(actionBuilder.extend(actionExtender).build());

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                title + ((network != null) ? (" (" + network + ")") : ""))
                        .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent,
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build());

        if (messages != null) {
            for (Notification n : messages) {
                if (n != null && n.nick != null && n.message != null && n.message.length() > 0) {
                    if (n.buffer_type.equals("conversation")) {
                        if (n.message_type.equals("buffer_me_msg"))
                            unreadConvBuilder
                                    .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString());
                        else
                            unreadConvBuilder.addMessage(Html.fromHtml(n.message).toString());
                    } else {
                        if (n.message_type.equals("buffer_me_msg"))
                            unreadConvBuilder
                                    .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString());
                        else
                            unreadConvBuilder
                                    .addMessage(n.nick + " said: " + Html.fromHtml(n.message).toString());
                    }
                }
            }
        } else {
            unreadConvBuilder.addMessage(text);
        }
        unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000);

        builder.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()));
    }

    if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class);
        i.setData(Uri.parse("irccloud-bid://" + bid));
        i.putExtras(replyIntent);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent quickReplyIntent = PendingIntent.getActivity(
                IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent);
    }

    if (otherAction != null) {
        int drawable = 0;
        if (otherAction.getIcon() == R.drawable.ic_wearable_add)
            drawable = R.drawable.ic_action_add;
        else if (otherAction.getIcon() == R.drawable.ic_wearable_reply)
            drawable = R.drawable.ic_action_reply;
        builder.addAction(
                new NotificationCompat.Action(drawable, otherAction.getTitle(), otherAction.getActionIntent()));
        wearableExtender.addAction(otherAction);
    }

    builder.extend(wearableExtender);

    return builder.build();
}

From source file:saphion.services.ForegroundService.java

private void setIntents(RemoteViews rv) {
    PendingIntent contentIntent = PendingIntent.getBroadcast(this, 34341, new Intent(this, WifiRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibwifi_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 323, new Intent(this, MdataRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibmdata_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 546, new Intent(this, BtoothRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibbtooth_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 324, new Intent(this, AmodeRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibamode_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 545, new Intent(this, SyncRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibsync_large, contentIntent);

    contentIntent = PendingIntent.getActivity(this, 543, new Intent(this, BrightnessRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibbrightness_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 765, new Intent(this, PowerProfileRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibpowersaver_toggle_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 1765, new Intent(this, HotspotRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibwifihotspot_large, contentIntent);

    contentIntent = PendingIntent.getBroadcast(this, 987, new Intent(this, ArotateRcvr.class), 0);
    rv.setOnClickPendingIntent(R.id.ibarotate_large, contentIntent);

    Intent intent = new Intent(this, TorchService.class);
    // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
    rv.setOnClickPendingIntent(R.id.ibtorch_large, pendingIntent);

}

From source file:mp.teardrop.PlaybackService.java

/**
 * Create a song notification. Call through the NotificationManager to
 * display it.//from   www.java 2  s  .co  m
 *
 * @param song The Song to display information about.
 * @param state The state. Determines whether to show paused or playing icon.
 */
public Notification createNotification(Song song, int state) {
    boolean playing = (state & FLAG_PLAYING) != 0;

    RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
    RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);

    Bitmap cover = song.getCover(this);
    if (cover == null) {
        views.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
        expanded.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
    } else {
        views.setImageViewBitmap(R.id.cover, cover);
        expanded.setImageViewBitmap(R.id.cover, cover);
    }

    int playButton = getPlayButtonResource(playing);

    views.setImageViewResource(R.id.play_pause, playButton);
    expanded.setImageViewResource(R.id.play_pause, playButton);

    ComponentName service = new ComponentName(this, PlaybackService.class);

    Intent previous = new Intent(PlaybackService.ACTION_PREVIOUS_SONG);
    previous.setComponent(service);
    expanded.setOnClickPendingIntent(R.id.previous, PendingIntent.getService(this, 0, previous, 0));

    Intent playPause = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK_NOTIFICATION);
    playPause.setComponent(service);
    views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));
    expanded.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));

    Intent next = new Intent(PlaybackService.ACTION_NEXT_SONG);
    next.setComponent(service);
    views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
    expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));

    Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION);
    close.setComponent(service);
    views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
    expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));

    views.setTextViewText(R.id.title, song.title);
    views.setTextViewText(R.id.artist, song.artist);
    expanded.setTextViewText(R.id.title, song.title);
    expanded.setTextViewText(R.id.album, song.album);
    expanded.setTextViewText(R.id.artist, song.artist);

    Notification notification = new Notification();
    notification.contentView = views;
    notification.icon = R.drawable.status_icon;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.contentIntent = mNotificationAction;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // expanded view is available since 4.1
        notification.bigContentView = expanded;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    //        if(mNotificationNag) {
    //            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //                notification.priority = Notification.PRIORITY_MAX;
    //                notification.vibrate = new long[0]; // needed to get headsup
    //            } else {
    //                notification.tickerText = song.title + " - " + song.artist;
    //            }
    //        }

    return notification;
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

private RemoteViews buildLayout(Context context, int appWidgetId, boolean showProgress) {
    RemoteViews rv;
    // Specify the service to provide data for the collection widget. Note
    // that we need to
    // embed the appWidgetId via the data otherwise it will be ignored.
    final Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv = new RemoteViews(context.getPackageName(), R.layout.listwidget);
    rv.setRemoteAdapter(R.id.widget_list, intent);

    // Set the empty view to be displayed if the collection is empty. It
    // must be a sibling
    // view of the collection view.
    rv.setEmptyView(R.id.widget_list, R.id.empty_view);

    // Set click listener for the logo
    //        Intent clickIntent = new Intent(context, LoginScreen.class);
    //        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0);
    //        rv.setOnClickPendingIntent(R.id.listwidget_header, pendingIntent);

    // Set click listener for the 'add' button
    //        if (isAuthenticated(context)) {
    //            PendingIntent taskStackBuilderPendingIntent = TaskStackBuilder
    //                    .create(context)
    //                    .addNextIntent(new Intent(context, TodoTxtTouch.class))
    //                    .addNextIntent(new Intent(context, AddTask.class))
    //                    .getPendingIntent(0, 0);
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem,
    //                    taskStackBuilderPendingIntent);
    //        } else {
    //            // if not logged in, just go to login screen
    //            rv.setOnClickPendingIntent(R.id.listwidget_additem, pendingIntent);
    //        }/*from w  ww .  j  a v a2 s  .c o m*/

    // Bind a click listener template for the contents of the list.
    // Note that we
    // need to update the intent's data if we set an extra, since the extras
    // will be
    // ignored otherwise.
    final Intent onClickIntent = new Intent(context, TodoTxtTouch.class);
    onClickIntent.setAction(ListWidgetProvider.ITEM_ACTION);
    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent onClickPendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0);
    rv.setPendingIntentTemplate(R.id.widget_list, onClickPendingIntent);

    // Bind the click intent for the refresh button on the widget
    final Intent refreshIntent = new Intent(context, ListWidgetProvider.class);
    refreshIntent.setAction(ListWidgetProvider.REFRESH_ACTION);
    refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.listwidget_refresh, refreshPendingIntent);

    if (showProgress) {
        rv.setViewVisibility(R.id.listwidget_progress, View.VISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.listwidget_progress, View.INVISIBLE);
        rv.setViewVisibility(R.id.listwidget_refresh, View.VISIBLE);
    }

    return rv;
}

From source file:com.piusvelte.sonet.core.SonetService.java

private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons,
        int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile,
        int margin) {
    final String widget = Integer.toString(appWidgetId);
    // Push update for this widget to the home screen
    int layout;/*from w  w w.j a va 2  s .c  om*/
    if (hasbuttons) {
        if (sNativeScrollingSupported) {
            if (margin > 0)
                layout = R.layout.widget_margin_scrollable;
            else
                layout = R.layout.widget_scrollable;
        } else if (display_profile) {
            if (margin > 0)
                layout = R.layout.widget_margin;
            else
                layout = R.layout.widget;
        } else {
            if (margin > 0)
                layout = R.layout.widget_noprofile_margin;
            else
                layout = R.layout.widget_noprofile;
        }
    } else {
        if (sNativeScrollingSupported) {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_margin_scrollable;
            else
                layout = R.layout.widget_nobuttons_scrollable;
        } else if (display_profile) {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_margin;
            else
                layout = R.layout.widget_nobuttons;
        } else {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_noprofile_margin;
            else
                layout = R.layout.widget_nobuttons_noprofile;
        }
    }
    // wrap RemoteViews for backward compatibility
    RemoteViews views = new RemoteViews(getPackageName(), layout);
    if (hasbuttons) {
        Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
        Canvas buttons_bg_canvas = new Canvas(buttons_bg);
        buttons_bg_canvas.drawColor(buttons_bg_color);
        views.setImageViewBitmap(R.id.buttons_bg, buttons_bg);
        views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color);
        views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(SonetService.this, 0,
                Sonet.getPackageIntent(SonetService.this, SonetCreatePost.class)
                        .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK)
                        .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)),
                0));
        views.setTextColor(R.id.button_post, buttons_color);
        views.setFloat(R.id.button_post, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(SonetService.this, 0,
                Sonet.getPackageIntent(SonetService.this, ManageAccounts.class).setAction(widget), 0));
        views.setTextColor(R.id.button_configure, buttons_color);
        views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(SonetService.this, 0,
                Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(widget), 0));
        views.setTextColor(R.id.button_refresh, buttons_color);
        views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize);
        views.setTextColor(R.id.page_up, buttons_color);
        views.setFloat(R.id.page_up, "setTextSize", buttons_textsize);
        views.setTextColor(R.id.page_down, buttons_color);
        views.setFloat(R.id.page_down, "setTextSize", buttons_textsize);
    }
    // set margin
    if (scrollable == 0) {
        final AppWidgetManager mgr = AppWidgetManager.getInstance(SonetService.this);
        // check if native scrolling is supported
        if (sNativeScrollingSupported) {
            // native scrolling
            try {
                final Intent intent = SonetRemoteViewsServiceWrapper.getRemoteAdapterIntent(SonetService.this);
                if (intent != null) {
                    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                    intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile);
                    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
                    sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent);
                    // empty
                    sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages);
                    // onclick
                    // Bind a click listener template for the contents of the message list
                    final Intent onClickIntent = Sonet.getPackageIntent(SonetService.this, SonetWidget.class);
                    onClickIntent.setAction(ACTION_ON_CLICK);
                    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
                    final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(SonetService.this, 0,
                            onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent);
                } else {
                    // fallback on non-scrolling widget
                    sNativeScrollingSupported = false;
                }
            } catch (NumberFormatException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.toString());
            } catch (InvocationTargetException e) {
                Log.e(TAG, e.toString());
            }

        }
        if (!sNativeScrollingSupported) {
            Cursor statuses_styles = getContentResolver().query(
                    Uri.withAppendedPath(Statuses_styles.getContentUri(SonetService.this), widget),
                    new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE,
                            Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT,
                            Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR,
                            Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE,
                            Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE,
                            Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG,
                            Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE },
                    null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1");
            if (statuses_styles.moveToFirst()) {
                int count_status = 0;
                views.removeAllViews(R.id.messages);
                while (!statuses_styles.isAfterLast() && (count_status < 16)) {
                    int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7),
                            friend_textsize = statuses_styles.getInt(9),
                            created_textsize = statuses_styles.getInt(10),
                            messages_color = statuses_styles.getInt(5),
                            messages_textsize = statuses_styles.getInt(8);
                    // get the item wrapper
                    RemoteViews itemView;
                    if (display_profile) {
                        itemView = new RemoteViews(getPackageName(), R.layout.widget_item);
                        // set profiles background
                        byte[] profile_bg = statuses_styles.getBlob(13);
                        if (profile_bg != null) {
                            Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0,
                                    profile_bg.length, sBFOptions);
                            if (profile_bgbmp != null)
                                itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp);
                        }
                        byte[] profile = statuses_styles.getBlob(2);
                        if (profile != null) {
                            Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length,
                                    sBFOptions);
                            if (profilebmp != null)
                                itemView.setImageViewBitmap(R.id.profile, profilebmp);
                        }
                    } else
                        itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile);
                    itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1));
                    itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize);
                    itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3));
                    itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize);
                    // set friends background
                    byte[] friend_bg = statuses_styles.getBlob(14);
                    if (friend_bg != null) {
                        Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length,
                                sBFOptions);
                        if (friend_bgbmp != null)
                            itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp);
                    }
                    // set messages background
                    byte[] status_bg = statuses_styles.getBlob(11);
                    if (status_bg != null) {
                        Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length,
                                sBFOptions);
                        if (status_bgbmp != null)
                            itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp);
                    }
                    // set an image
                    byte[] image_bg = statuses_styles.getBlob(15);
                    byte[] image = statuses_styles.getBlob(16);
                    if ((image_bg != null) && (image != null)) {
                        Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length,
                                sBFOptions);
                        if (image_bgBmp != null) {
                            Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions);
                            itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp);
                            itemView.setImageViewBitmap(R.id.image, imageBmp);
                        }
                    }
                    itemView.setTextViewText(R.id.message, statuses_styles.getString(3));
                    itemView.setTextColor(R.id.message, messages_color);
                    itemView.setFloat(R.id.message, "setTextSize", messages_textsize);
                    itemView.setOnClickPendingIntent(R.id.item,
                            PendingIntent.getActivity(SonetService.this, 0,
                                    Sonet.getPackageIntent(SonetService.this, StatusDialog.class)
                                            .setData(Uri.withAppendedPath(
                                                    Statuses_styles.getContentUri(SonetService.this),
                                                    Long.toString(statuses_styles.getLong(0)))),
                                    0));
                    itemView.setTextViewText(R.id.friend, statuses_styles.getString(1));
                    itemView.setTextColor(R.id.friend, friend_color);
                    itemView.setFloat(R.id.friend, "setTextSize", friend_textsize);
                    itemView.setTextViewText(R.id.created, statuses_styles.getString(4));
                    itemView.setTextColor(R.id.created, created_color);
                    itemView.setFloat(R.id.created, "setTextSize", created_textsize);
                    // set icons
                    byte[] icon = statuses_styles.getBlob(12);
                    if (icon != null) {
                        Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions);
                        if (iconbmp != null)
                            itemView.setImageViewBitmap(R.id.icon, iconbmp);
                    }
                    views.addView(R.id.messages, itemView);
                    count_status++;
                    statuses_styles.moveToNext();
                }
                if (hasbuttons && (page < statuses_styles.getCount())) {
                    // there are more statuses to show, allow paging down
                    views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(SonetService.this, 0,
                            Sonet.getPackageIntent(SonetService.this, SonetService.class)
                                    .setAction(ACTION_PAGE_DOWN)
                                    .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this),
                                            widget))
                                    .putExtra(ACTION_PAGE_DOWN, page + 1),
                            PendingIntent.FLAG_UPDATE_CURRENT));
                }
            }
            statuses_styles.close();
            if (hasbuttons && (page > 0))
                views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(SonetService.this, 0,
                        Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(ACTION_PAGE_UP)
                                .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget))
                                .putExtra(ACTION_PAGE_UP, page - 1),
                        PendingIntent.FLAG_UPDATE_CURRENT));
        }
        Log.d(TAG, "update native widget: " + appWidgetId);
        mgr.updateAppWidget(appWidgetId, views);
        if (sNativeScrollingSupported) {
            Log.d(TAG, "trigger widget query: " + appWidgetId);
            try {
                // trigger query
                sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.toString());
            } catch (InvocationTargetException e) {
                Log.e(TAG, e.toString());
            }
        }
    } else if (updatesReady) {
        //         Log.d(TAG, "notify updatesReady");
        getContentResolver().notifyChange(Statuses_styles.getContentUri(SonetService.this), null);
    } else {
        AppWidgetManager.getInstance(SonetService.this).updateAppWidget(Integer.parseInt(widget), views);
        buildScrollableWidget(appWidgetId, scrollable, display_profile);
    }
}

From source file:com.shafiq.myfeedle.core.MyfeedleService.java

private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons,
        int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile,
        int margin) {
    final String widget = Integer.toString(appWidgetId);
    // Push update for this widget to the home screen
    int layout;//from  w w w  .  j a va2s . c  o m
    if (hasbuttons) {
        if (sNativeScrollingSupported) {
            if (margin > 0)
                layout = R.layout.widget_margin_scrollable;
            else
                layout = R.layout.widget_scrollable;
        } else if (display_profile) {
            if (margin > 0)
                layout = R.layout.widget_margin;
            else
                layout = R.layout.widget;
        } else {
            if (margin > 0)
                layout = R.layout.widget_noprofile_margin;
            else
                layout = R.layout.widget_noprofile;
        }
    } else {
        if (sNativeScrollingSupported) {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_margin_scrollable;
            else
                layout = R.layout.widget_nobuttons_scrollable;
        } else if (display_profile) {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_margin;
            else
                layout = R.layout.widget_nobuttons;
        } else {
            if (margin > 0)
                layout = R.layout.widget_nobuttons_noprofile_margin;
            else
                layout = R.layout.widget_nobuttons_noprofile;
        }
    }
    // wrap RemoteViews for backward compatibility
    RemoteViews views = new RemoteViews(getPackageName(), layout);
    if (hasbuttons) {
        Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
        Canvas buttons_bg_canvas = new Canvas(buttons_bg);
        buttons_bg_canvas.drawColor(buttons_bg_color);
        views.setImageViewBitmap(R.id.buttons_bg, buttons_bg);
        views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color);
        views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_post,
                PendingIntent.getActivity(MyfeedleService.this, 0,
                        Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleCreatePost.class)
                                .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(Uri
                                        .withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)),
                        0));
        views.setTextColor(R.id.button_post, buttons_color);
        views.setFloat(R.id.button_post, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(MyfeedleService.this, 0,
                Myfeedle.getPackageIntent(MyfeedleService.this, ManageAccounts.class).setAction(widget), 0));
        views.setTextColor(R.id.button_configure, buttons_color);
        views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize);
        views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(MyfeedleService.this, 0,
                Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class).setAction(widget), 0));
        views.setTextColor(R.id.button_refresh, buttons_color);
        views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize);
        views.setTextColor(R.id.page_up, buttons_color);
        views.setFloat(R.id.page_up, "setTextSize", buttons_textsize);
        views.setTextColor(R.id.page_down, buttons_color);
        views.setFloat(R.id.page_down, "setTextSize", buttons_textsize);
    }
    // set margin
    if (scrollable == 0) {
        final AppWidgetManager mgr = AppWidgetManager.getInstance(MyfeedleService.this);
        // check if native scrolling is supported
        if (sNativeScrollingSupported) {
            // native scrolling
            try {
                final Intent intent = MyfeedleRemoteViewsServiceWrapper
                        .getRemoteAdapterIntent(MyfeedleService.this);
                if (intent != null) {
                    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                    intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile);
                    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
                    sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent);
                    // empty
                    sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages);
                    // onclick
                    // Bind a click listener template for the contents of the message list
                    final Intent onClickIntent = Myfeedle.getPackageIntent(MyfeedleService.this,
                            MyfeedleWidget.class);
                    onClickIntent.setAction(ACTION_ON_CLICK);
                    onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
                    final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(MyfeedleService.this,
                            0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent);
                } else {
                    // fallback on non-scrolling widget
                    sNativeScrollingSupported = false;
                }
            } catch (NumberFormatException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.toString());
            } catch (InvocationTargetException e) {
                Log.e(TAG, e.toString());
            }

        }
        if (!sNativeScrollingSupported) {
            Cursor statuses_styles = getContentResolver().query(
                    Uri.withAppendedPath(Statuses_styles.getContentUri(MyfeedleService.this), widget),
                    new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE,
                            Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT,
                            Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR,
                            Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE,
                            Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE,
                            Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG,
                            Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE },
                    null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1");
            if (statuses_styles.moveToFirst()) {
                int count_status = 0;
                views.removeAllViews(R.id.messages);
                while (!statuses_styles.isAfterLast() && (count_status < 16)) {
                    int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7),
                            friend_textsize = statuses_styles.getInt(9),
                            created_textsize = statuses_styles.getInt(10),
                            messages_color = statuses_styles.getInt(5),
                            messages_textsize = statuses_styles.getInt(8);
                    // get the item wrapper
                    RemoteViews itemView;
                    if (display_profile) {
                        itemView = new RemoteViews(getPackageName(), R.layout.widget_item);
                        // set profiles background
                        byte[] profile_bg = statuses_styles.getBlob(13);
                        if (profile_bg != null) {
                            Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0,
                                    profile_bg.length, sBFOptions);
                            if (profile_bgbmp != null)
                                itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp);
                        }
                        byte[] profile = statuses_styles.getBlob(2);
                        if (profile != null) {
                            Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length,
                                    sBFOptions);
                            if (profilebmp != null)
                                itemView.setImageViewBitmap(R.id.profile, profilebmp);
                        }
                    } else
                        itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile);
                    itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1));
                    itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize);
                    itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3));
                    itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize);
                    // set friends background
                    byte[] friend_bg = statuses_styles.getBlob(14);
                    if (friend_bg != null) {
                        Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length,
                                sBFOptions);
                        if (friend_bgbmp != null)
                            itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp);
                    }
                    // set messages background
                    byte[] status_bg = statuses_styles.getBlob(11);
                    if (status_bg != null) {
                        Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length,
                                sBFOptions);
                        if (status_bgbmp != null)
                            itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp);
                    }
                    // set an image
                    byte[] image_bg = statuses_styles.getBlob(15);
                    byte[] image = statuses_styles.getBlob(16);
                    if ((image_bg != null) && (image != null)) {
                        Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length,
                                sBFOptions);
                        if (image_bgBmp != null) {
                            Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions);
                            itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp);
                            itemView.setImageViewBitmap(R.id.image, imageBmp);
                        }
                    }
                    itemView.setTextViewText(R.id.message, statuses_styles.getString(3));
                    itemView.setTextColor(R.id.message, messages_color);
                    itemView.setFloat(R.id.message, "setTextSize", messages_textsize);
                    itemView.setOnClickPendingIntent(R.id.item,
                            PendingIntent.getActivity(MyfeedleService.this, 0,
                                    Myfeedle.getPackageIntent(MyfeedleService.this, StatusDialog.class)
                                            .setData(Uri.withAppendedPath(
                                                    Statuses_styles.getContentUri(MyfeedleService.this),
                                                    Long.toString(statuses_styles.getLong(0)))),
                                    0));
                    itemView.setTextViewText(R.id.friend, statuses_styles.getString(1));
                    itemView.setTextColor(R.id.friend, friend_color);
                    itemView.setFloat(R.id.friend, "setTextSize", friend_textsize);
                    itemView.setTextViewText(R.id.created, statuses_styles.getString(4));
                    itemView.setTextColor(R.id.created, created_color);
                    itemView.setFloat(R.id.created, "setTextSize", created_textsize);
                    // set icons
                    byte[] icon = statuses_styles.getBlob(12);
                    if (icon != null) {
                        Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions);
                        if (iconbmp != null)
                            itemView.setImageViewBitmap(R.id.icon, iconbmp);
                    }
                    views.addView(R.id.messages, itemView);
                    count_status++;
                    statuses_styles.moveToNext();
                }
                if (hasbuttons && (page < statuses_styles.getCount())) {
                    // there are more statuses to show, allow paging down
                    views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(MyfeedleService.this,
                            0,
                            Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class)
                                    .setAction(ACTION_PAGE_DOWN)
                                    .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this),
                                            widget))
                                    .putExtra(ACTION_PAGE_DOWN, page + 1),
                            PendingIntent.FLAG_UPDATE_CURRENT));
                }
            }
            statuses_styles.close();
            if (hasbuttons && (page > 0))
                views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(MyfeedleService.this, 0,
                        Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class)
                                .setAction(ACTION_PAGE_UP)
                                .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this),
                                        widget))
                                .putExtra(ACTION_PAGE_UP, page - 1),
                        PendingIntent.FLAG_UPDATE_CURRENT));
        }
        Log.d(TAG, "update native widget: " + appWidgetId);
        mgr.updateAppWidget(appWidgetId, views);
        if (sNativeScrollingSupported) {
            Log.d(TAG, "trigger widget query: " + appWidgetId);
            try {
                // trigger query
                sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.toString());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.toString());
            } catch (InvocationTargetException e) {
                Log.e(TAG, e.toString());
            }
        }
    } else if (updatesReady) {
        //         Log.d(TAG, "notify updatesReady");
        getContentResolver().notifyChange(Statuses_styles.getContentUri(MyfeedleService.this), null);
    } else {
        AppWidgetManager.getInstance(MyfeedleService.this).updateAppWidget(Integer.parseInt(widget), views);
        buildScrollableWidget(appWidgetId, scrollable, display_profile);
    }
}

From source file:net.sourceforge.servestream.service.MediaPlaybackService.java

private void setupExpandedContentView(RemoteViews rv, boolean updateNotification) {
    String trackName = getTrackName();
    if (trackName == null || trackName.equals(Media.UNKNOWN_STRING)) {
        trackName = getMediaUri();//from   w  w w  .  j  av a2s  . co m
    }

    String artist = getArtistName();
    if (artist == null || artist.equals(Media.UNKNOWN_STRING)) {
        artist = getString(R.string.unknown_artist_name);
    }

    String album = getAlbumName();

    if (updateNotification) {
        if (isPlaying()) {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
        } else {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_play);
        }
    } else {
        rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
    }

    int trackId = getTrackId();
    if (mPreferences.getBoolean(PreferenceConstants.RETRIEVE_ALBUM_ART, false) && trackId != -1) {
        Bitmap bitmap = getAlbumArt(true);
        if (bitmap != null) {
            rv.setImageViewBitmap(R.id.coverart, bitmap);
        }
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.firstLine, trackName);
    rv.setTextViewText(R.id.secondLine, album);
    rv.setTextViewText(R.id.thirdLine, artist);

    rv.setOnClickPendingIntent(R.id.prev, createPendingIntent(1, CMDPREVIOUS));
    rv.setOnClickPendingIntent(R.id.play_pause, createPendingIntent(2, CMDTOGGLEPAUSE));
    rv.setOnClickPendingIntent(R.id.next, createPendingIntent(3, CMDNEXT));
    rv.setOnClickPendingIntent(R.id.close, createPendingIntent(4, CMDSTOP));
}

From source file:com.andrew.apolloMod.service.ApolloService.java

/** Return notification remote views
 * //  w  ww .  jav a 2  s  .com
 * @return [views, bigViews]
 */
public RemoteViews[] getNotificationViews() {
    Bitmap b = getAlbumBitmap();

    RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded);
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar);

    if (b != null) {
        bigViews.setImageViewBitmap(R.id.status_bar_album_art, b);
        views.setViewVisibility(R.id.status_bar_icon, View.GONE);
        views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE);
        views.setImageViewBitmap(R.id.status_bar_album_art, b);
    } else {
        views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE);
        views.setViewVisibility(R.id.status_bar_album_art, View.GONE);
    }

    ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.putExtra(CMDNOTIF, 1);
    mediaButtonIntent.setComponent(rec);
    KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 2);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 4);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent);

    mediaButtonIntent.putExtra(CMDNOTIF, 3);
    mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP);
    mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey);
    mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent);
    bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent);

    views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause);
    bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause);

    views.setTextViewText(R.id.status_bar_track_name, getTrackName());
    bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName());

    views.setTextViewText(R.id.status_bar_artist_name, getArtistName());
    bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName());

    bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName());

    return new RemoteViews[] { views, bigViews };

}

From source file:net.sourceforge.servestream.service.MediaPlaybackService.java

private void setupContentView(RemoteViews rv, boolean updateNotification) {
    String contentText;/*from  ww  w .  j av  a  2  s.  c  om*/

    String trackName = getTrackName();
    if (trackName == null || trackName.equals(Media.UNKNOWN_STRING)) {
        trackName = getMediaUri();
    }

    String artist = getArtistName();
    if (artist == null || artist.equals(Media.UNKNOWN_STRING)) {
        artist = getString(R.string.unknown_artist_name);
    }

    String album = getAlbumName();
    if (album == null || album.equals(Media.UNKNOWN_STRING)) {
        contentText = getString(R.string.notification_alt_info, artist);
    } else {
        contentText = getString(R.string.notification_artist_album, artist, album);
    }

    if (updateNotification) {
        if (isPlaying()) {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
        } else {
            rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_play);
        }
    } else {
        rv.setImageViewResource(R.id.play_pause, android.R.drawable.ic_media_pause);
    }

    int trackId = getTrackId();
    if (mPreferences.getBoolean(PreferenceConstants.RETRIEVE_ALBUM_ART, false) && trackId != -1) {
        Bitmap bitmap = getAlbumArt(true);
        if (bitmap != null) {
            rv.setImageViewBitmap(R.id.coverart, bitmap);
        }
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.title, trackName);
    rv.setTextViewText(R.id.subtitle, contentText);

    rv.setOnClickPendingIntent(R.id.play_pause, createPendingIntent(2, CMDTOGGLEPAUSE));
    rv.setOnClickPendingIntent(R.id.next, createPendingIntent(3, CMDNEXT));
    rv.setOnClickPendingIntent(R.id.close, createPendingIntent(4, CMDSTOP));
}