Example usage for android.widget RemoteViews RemoteViews

List of usage examples for android.widget RemoteViews RemoteViews

Introduction

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

Prototype

public RemoteViews(RemoteViews landscape, RemoteViews portrait) 

Source Link

Document

Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.

Usage

From source file:au.com.wallaceit.reddinator.Rservice.java

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row;/*from   w ww . j a v a  2s  . com*/
    if (position > data.length()) {
        return null; //  prevent errornous views
    }
    // check if its the last view and return loading view instead of normal row
    if (position == data.length()) {
        // build load more item
        //System.out.println("load more getViewAt("+position+") firing");
        RemoteViews loadmorerow = new RemoteViews(mContext.getPackageName(), R.layout.listrowloadmore);
        if (endOfFeed) {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "There's nothing more here");
        } else {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "Load more...");
        }
        loadmorerow.setTextColor(R.id.loadmoretxt, themeColors[0]);
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, "0"); // zero will be an indicator in the onreceive function of widget provider if its not present it forces a reload
        i.putExtras(extras);
        loadmorerow.setOnClickFillInIntent(R.id.listrowloadmore, i);
        return loadmorerow;
    } else {
        // build normal item
        String title = "";
        String url = "";
        String permalink = "";
        String thumbnail = "";
        String domain = "";
        String id = "";
        int score = 0;
        int numcomments = 0;
        boolean nsfw = false;
        try {
            JSONObject tempobj = data.getJSONObject(position).getJSONObject("data");
            title = tempobj.getString("title");
            //userlikes = tempobj.getString("likes");
            domain = tempobj.getString("domain");
            id = tempobj.getString("name");
            url = tempobj.getString("url");
            permalink = tempobj.getString("permalink");
            thumbnail = (String) tempobj.get("thumbnail"); // we have to call get and cast cause its not in quotes
            score = tempobj.getInt("score");
            numcomments = tempobj.getInt("num_comments");
            nsfw = tempobj.getBoolean("over_18");
        } catch (JSONException e) {
            e.printStackTrace();
            // return null; // The view is invalid;
        }
        // create remote view from specified layout
        if (bigThumbs) {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrowbigthumb);
        } else {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrow);
        }
        // build view
        row.setTextViewText(R.id.listheading, Html.fromHtml(title).toString());
        row.setFloat(R.id.listheading, "setTextSize", Integer.valueOf(titleFontSize)); // use for compatibility setTextViewTextSize only introduced in API 16
        row.setTextColor(R.id.listheading, themeColors[0]);
        row.setTextViewText(R.id.sourcetxt, domain);
        row.setTextColor(R.id.sourcetxt, themeColors[3]);
        row.setTextColor(R.id.votestxt, themeColors[4]);
        row.setTextColor(R.id.commentstxt, themeColors[4]);
        row.setTextViewText(R.id.votestxt, String.valueOf(score));
        row.setTextViewText(R.id.commentstxt, String.valueOf(numcomments));
        row.setInt(R.id.listdivider, "setBackgroundColor", themeColors[2]);
        row.setViewVisibility(R.id.nsfwflag, nsfw ? TextView.VISIBLE : TextView.GONE);
        // add extras and set click intent
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, id);
        extras.putInt("itemposition", position);
        extras.putString(WidgetProvider.ITEM_URL, url);
        extras.putString(WidgetProvider.ITEM_PERMALINK, permalink);
        i.putExtras(extras);
        row.setOnClickFillInIntent(R.id.listrow, i);
        // load thumbnail if they are enabled for this widget
        if (loadThumbnails) {
            // load big image if preference is set
            if (!thumbnail.equals("")) { // check for thumbnail; self is used to display the thinking logo on the reddit site, we'll just show nothing for now
                if (thumbnail.equals("nsfw") || thumbnail.equals("self") || thumbnail.equals("default")) {
                    int resource = 0;
                    switch (thumbnail) {
                    case "nsfw":
                        resource = R.drawable.nsfw;
                        break;
                    case "default":
                    case "self":
                        resource = R.drawable.self_default;
                        break;
                    }
                    row.setImageViewResource(R.id.thumbnail, resource);
                    row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    //System.out.println("Loading default image: "+thumbnail);
                } else {
                    Bitmap bitmap;
                    String fileurl = mContext.getCacheDir() + "/thumbcache-" + appWidgetId + "/" + id + ".png";
                    // check if the image is in cache
                    if (new File(fileurl).exists()) {
                        bitmap = BitmapFactory.decodeFile(fileurl);
                        saveImageToStorage(bitmap, id);
                    } else {
                        // download the image
                        bitmap = loadImage(thumbnail);
                    }
                    if (bitmap != null) {
                        row.setImageViewBitmap(R.id.thumbnail, bitmap);
                        row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    } else {
                        // row.setImageViewResource(R.id.thumbnail, android.R.drawable.stat_notify_error); for later
                        row.setViewVisibility(R.id.thumbnail, View.GONE);
                    }
                }
            } else {
                row.setViewVisibility(R.id.thumbnail, View.GONE);
            }
        } else {
            row.setViewVisibility(R.id.thumbnail, View.GONE);
        }
        // hide info bar if options set
        if (hideInf) {
            row.setViewVisibility(R.id.infbox, View.GONE);
        } else {
            row.setViewVisibility(R.id.infbox, View.VISIBLE);
        }
    }
    //System.out.println("getViewAt("+position+");");
    return row;
}

From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java

private void startNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
    contentView.setImageViewResource(R.id.notification_icon, R.drawable.notification_icon);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.notification_title));
    contentView.setTextViewText(R.id.notification_text, urlToStream);
    if (isPreparing) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_loading);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0));
    } else if (isStreamError) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_error);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
    } else if (isPlaying) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.stop_button);
        PendingIntent stopIntentPending = PendingIntent.getService(this, 0,
                new Intent(MainActivity.STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, stopIntentPending);
    } else {/*from   www  .  j ava  2s  . c  om*/
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.play_button);
        Intent playIntent = new Intent(MainActivity.PLAY_INTENT);
        playIntent.putExtra(MainActivity.URL_EXTRA, urlToStream);

        PendingIntent playIntentPending = PendingIntent.getService(this, 0, playIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, playIntentPending);
    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    contentView.setOnClickPendingIntent(R.id.notification_layout, contentIntent);

    PendingIntent killIntentPending = PendingIntent.getService(this, 0,
            new Intent(MainActivity.KILL_SERVICE_INTENT), 0);
    contentView.setOnClickPendingIntent(R.id.close_notification_icon, killIntentPending);

    builder.setContent(contentView);

    builder.setSmallIcon(R.drawable.notification_icon);

    builder.setAutoCancel(false);

    startForeground(NOTIFICATION_ID, builder.build());
}

From source file:com.b44t.messenger.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(MessageObject messageObject) {
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();

    MrPoortext pt = MrMailbox.getMsg(messageObject.getId()).getMediainfo();
    String authorName = pt.getText1();
    String songName = pt.getText2();
    if (songName == null || songName.length() == 0) {
        TLRPC.Document document = messageObject.messageOwner.media.document;
        for (int i = 0; i < document.attributes.size(); i++) {
            TLRPC.DocumentAttribute attr = document.attributes.get(i);
            if (attr instanceof TLRPC.TL_documentAttributeAudio) {
                authorName = attr.performer;
                songName = attr.title;/*from  w  w w .j a  v  a  2  s .c  om*/
                break;
            }
        }
    }

    if (songName == null || songName.length() == 0) {
        // preview of just recorded and not send voice messages
        authorName = ApplicationLoader.applicationContext.getString(R.string.FromSelf);
        songName = ApplicationLoader.applicationContext.getString(R.string.AttachVoiceMessage);
    }

    RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.player_small_notification);

    //Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
    //intent.setAction("com.b44t.messenger.openchat"+messageObject.getDialogId());
    //intent.setFlags(32768);
    //PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_player)
            //.setContentIntent(contentIntent)
            .setContentTitle(songName).build();

    notification.contentView = simpleContentView;

    setListeners(simpleContentView);

    Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
    if (albumArt != null) {
        notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
        notification.contentView.setViewVisibility(R.id.player_album_art, View.VISIBLE);
    } else {
        notification.contentView.setViewVisibility(R.id.player_album_art, View.GONE);
    }

    {
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
        }
    }

    notification.contentView.setTextViewText(R.id.player_song_name, songName);
    notification.contentView.setTextViewText(R.id.player_author_name, authorName);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(5, notification);

    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
        if (audioInfo != null && audioInfo.getCover() != null) {
            try {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover());
            } catch (Throwable e) {
                FileLog.e("messenger", e);
            }
        }
        metadataEditor.apply();
    }
}

From source file:com.online.fullsail.SaveWebMedia.java

@Override
protected void onPreExecute() {

    Intent intent = new Intent();
    final PendingIntent pendingIntent = PendingIntent.getActivity(this.context, 0, intent, 0);
    notification = new Notification(R.drawable.icon_notification, "Downloading...", System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.contentView = new RemoteViews(this.context.getPackageName(), R.layout.download_notify);
    notification.contentIntent = pendingIntent;
    notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon);
    notification.contentView.setTextViewText(R.id.status_text, "Downloading Content...");
    notification.contentView.setProgressBar(R.id.status_progress, 100, 0, false);
    mNM.notify(timestamp, notification);
}

From source file:com.dmplayer.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {//w ww.j  a  v  a2s  .co m
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext)
                : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationDMPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.frostwire.android.gui.NotificationUpdateDemon.java

private void setupNotification() {
    if (!ConfigurationManager.instance()
            .getBoolean(Constants.PREF_KEY_GUI_ENABLE_PERMANENT_STATUS_NOTIFICATION)) {
        return;/*from www . j a va2 s . c  om*/
    }

    RemoteViews remoteViews = new RemoteViews(mParentContext.getPackageName(),
            R.layout.view_permanent_status_notification);

    PendingIntent showFrostWireIntent = createShowFrostwireIntent();
    PendingIntent shutdownIntent = createShutdownIntent();

    remoteViews.setOnClickPendingIntent(R.id.view_permanent_status_shutdown, shutdownIntent);
    remoteViews.setOnClickPendingIntent(R.id.view_permanent_status_text_title, showFrostWireIntent);
    Notification notification = new NotificationCompat.Builder(mParentContext,
            Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.frostwire_notification_flat)
                    .setContentIntent(showFrostWireIntent).setContent(remoteViews).build();

    notification.flags |= Notification.FLAG_NO_CLEAR;

    notificationViews = remoteViews;
    notificationObject = notification;
}

From source file:kz.qobyzbook.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {//from  w  w w. j a  v a2  s . co  m
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        String songImage = mSongDetail.getImage_url();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext)
                : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
            //                notification.bigContentView.setTextViewText(R.id.player_albumname, albumName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationDMPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java

/**
 * Updates the widget./*www  .  j  a  v a  2s.c om*/
 * 
 * @param action the action
 */
private void updateTrack(String action) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget);

    if (action != null) {
        updateButton(remoteViews, action);
    }
    updateView(remoteViews);

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = appWidgetManager
            .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class));
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

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

@SuppressLint("NewApi")
private void createNotification(MessageObject messageObject) {
    String songName = messageObject.getMusicTitle();
    String authorName = messageObject.getMusicAuthor();
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();

    RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.player_small_notification);
    RemoteViews expandedView = null;/*from w ww. j a  v  a2s. co m*/
    if (supportBigNotifications) {
        expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_big_notification);
    }

    Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
    intent.setAction("com.tmessages.openplayer");
    intent.setFlags(32768);
    PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName).build();

    notification.contentView = simpleContentView;
    if (supportBigNotifications) {
        notification.bigContentView = expandedView;
    }

    setListeners(simpleContentView);
    if (supportBigNotifications) {
        setListeners(expandedView);
    }

    Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
    if (albumArt != null) {
        notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
        if (supportBigNotifications) {
            notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
        }
    } else {
        notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small);
        if (supportBigNotifications) {
            notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big);
        }
    }
    if (MediaController.getInstance().isDownloadingCurrentMessage()) {
        notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
        }
    } else {
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }
    }

    notification.contentView.setTextViewText(R.id.player_song_name, songName);
    notification.contentView.setTextViewText(R.id.player_author_name, authorName);
    if (supportBigNotifications) {
        notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
        notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
    }
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(5, notification);

    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
        if (audioInfo != null && audioInfo.getCover() != null) {
            metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                    audioInfo.getCover());
        }
        metadataEditor.apply();
        audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    }
}

From source file:org.appd.login.V_Connection.java

/**
 * Action Initial Synchronization//from w w w .  j a  va 2 s  .c om
 * @author Yamel Senih 24/04/2012, 00:14:42
 *          Carlos Parada 17/05/2012 Se Coloco la carga inicial automatica desde adempiere
 * @return void
 */
private void synchronize() {

    m_load = new InitialLoad(this) {

        @Override
        protected void onPostExecute(Object result) {
            super.onPostExecute(result);
            //   Load Context
            loadContext();
        }
    };

    m_load.LoadSoapFromContext(getActivity());

    if (!Env.isEnvLoad(getActivity())) {
        RemoteViews contentView = new RemoteViews(getActivity().getPackageName(), R.layout.v_progressdialog);
        contentView.setImageViewResource(R.id.iV_Synchronizing, R.drawable.syncserver_m);
        contentView.setTextViewText(R.id.tV_CurrentSinchronizing,
                getResources().getString(R.string.msg_CallingWebService));
        contentView.setTextViewText(R.id.tV_Percentaje, "0%");

        NotificationManager notify = Msg.notificationMsg(getActivity(), R.drawable.syncserver_h, "", 0,
                getActivity().getIntent(), contentView);
        m_load.setContentView(contentView);
        m_load.setM_NotificationManager(notify);
        m_load.execute();

    } else {
        loadContext();
    }

}