Example usage for android.widget RemoteViews setImageViewResource

List of usage examples for android.widget RemoteViews setImageViewResource

Introduction

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

Prototype

public void setImageViewResource(int viewId, int srcId) 

Source Link

Document

Equivalent to calling ImageView#setImageResource(int)

Usage

From source file:uk.org.ngo.squeezer.service.SqueezeService.java

/**
 * Manages the state of any ongoing notification based on the player and connection state.
 *///  w w w .ja v a 2s. c  o m
private void updateOngoingNotification() {
    Player activePlayer = this.mActivePlayer.get();
    PlayerState activePlayerState = getActivePlayerState();

    // Update scrobble state, if either we're currently scrobbling, or we
    // were (to catch the case where we started scrobbling a song, and the
    // user went in to settings to disable scrobbling).
    if (scrobblingEnabled || scrobblingPreviouslyEnabled) {
        scrobblingPreviouslyEnabled = scrobblingEnabled;
        Scrobble.scrobbleFromPlayerState(this, activePlayerState);
    }

    // If there's no active player then kill the notification and get out.
    // TODO: Have a "There are no connected players" notification text.
    if (activePlayer == null || activePlayerState == null) {
        clearOngoingNotification();
        return;
    }

    boolean playing = activePlayerState.isPlaying();

    // If the song is not playing and the user wants notifications only when playing then
    // kill the notification and get out.
    if (!playing && !mShowNotificationWhenNotPlaying) {
        clearOngoingNotification();
        return;
    }

    // If there's no current song then kill the notification and get out.
    // TODO: Have a "There's nothing playing" notification text.
    final Song currentSong = activePlayerState.getCurrentSong();
    if (currentSong == null) {
        clearOngoingNotification();
        return;
    }

    // Compare the current state with the state when the notification was last updated.
    // If there are no changes (same song, same playing state) then there's nothing to do.
    String songName = currentSong.getName();
    String albumName = currentSong.getAlbumName();
    String artistName = currentSong.getArtist();
    Uri url = currentSong.getArtworkUrl();
    String playerName = activePlayer.getName();

    if (mNotifiedPlayerState == null) {
        mNotifiedPlayerState = new PlayerState();
    } else {
        boolean lastPlaying = mNotifiedPlayerState.isPlaying();
        Song lastNotifiedSong = mNotifiedPlayerState.getCurrentSong();

        // No change in state
        if (playing == lastPlaying && currentSong.equals(lastNotifiedSong)) {
            return;
        }
    }

    mNotifiedPlayerState.setCurrentSong(currentSong);
    mNotifiedPlayerState.setPlayStatus(activePlayerState.getPlayStatus());
    final NotificationManagerCompat nm = NotificationManagerCompat.from(this);

    PendingIntent nextPendingIntent = getPendingIntent(ACTION_NEXT_TRACK);
    PendingIntent prevPendingIntent = getPendingIntent(ACTION_PREV_TRACK);
    PendingIntent playPendingIntent = getPendingIntent(ACTION_PLAY);
    PendingIntent pausePendingIntent = getPendingIntent(ACTION_PAUSE);
    PendingIntent closePendingIntent = getPendingIntent(ACTION_CLOSE);

    Intent showNowPlaying = new Intent(this, NowPlayingActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, showNowPlaying, 0);
    Notification notification;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final Notification.Builder builder = new Notification.Builder(this);
        builder.setContentIntent(pIntent);
        builder.setSmallIcon(R.drawable.squeezer_notification);
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        builder.setShowWhen(false);
        builder.setContentTitle(songName);
        builder.setContentText(albumName);
        builder.setSubText(playerName);
        builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(1, 2)
                .setMediaSession(mMediaSession.getSessionToken()));

        final MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder();
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, artistName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM, albumName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, songName);
        mMediaSession.setMetadata(metaBuilder.build());

        // Don't set an ongoing notification, otherwise wearable's won't show it.
        builder.setOngoing(false);

        builder.setDeleteIntent(closePendingIntent);
        if (playing) {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_pause, "Pause", pausePendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        } else {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_play, "Play", playPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        }

        ImageFetcher.getInstance(this).loadImage(url,
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height),
                new ImageWorker.ImageWorkerCallback() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                    public void process(Object data, @Nullable Bitmap bitmap) {
                        if (bitmap == null) {
                            bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_album_noart);
                        }

                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                        mMediaSession.setMetadata(metaBuilder.build());
                        builder.setLargeIcon(bitmap);
                        nm.notify(PLAYBACKSERVICE_STATUS, builder.build());
                    }
                });
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

        builder.setOngoing(true);
        builder.setCategory(NotificationCompat.CATEGORY_SERVICE);
        builder.setSmallIcon(R.drawable.squeezer_notification);

        RemoteViews normalView = new RemoteViews(this.getPackageName(), R.layout.notification_player_normal);
        RemoteViews expandedView = new RemoteViews(this.getPackageName(),
                R.layout.notification_player_expanded);

        normalView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        expandedView.setOnClickPendingIntent(R.id.previous, prevPendingIntent);
        expandedView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        builder.setContent(normalView);

        normalView.setTextViewText(R.id.trackname, songName);
        normalView.setTextViewText(R.id.albumname, albumName);

        expandedView.setTextViewText(R.id.trackname, songName);
        expandedView.setTextViewText(R.id.albumname, albumName);
        expandedView.setTextViewText(R.id.player_name, playerName);

        if (playing) {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            normalView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            expandedView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);
        } else {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            normalView.setOnClickPendingIntent(R.id.pause, playPendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            expandedView.setOnClickPendingIntent(R.id.pause, playPendingIntent);
        }

        builder.setContentTitle(songName);
        builder.setContentText(getString(R.string.notification_playing_text, playerName));
        builder.setContentIntent(pIntent);

        notification = builder.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification.bigContentView = expandedView;
        }

        nm.notify(PLAYBACKSERVICE_STATUS, notification);

        ImageFetcher.getInstance(this).loadImage(this, url, normalView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
        ImageFetcher.getInstance(this).loadImage(this, url, expandedView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
    }
}

From source file:ua.mkh.weather.MainActivity.java

private void create_notif() {
    // TODO Auto-generated method stub
    // Prepare intent which is triggered if the
    // notification is selected
    String tittle = textView3.getText().toString();
    String subject = textView3.getText().toString();
    String body = "";
    /*/* w  w w. j  a  v  a 2 s  .co  m*/
    NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis());
    PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
            
    notify.setLatestEventInfo(getApplicationContext(),subject,body,pending);
    notif.notify(0, notify);
            
            
    final NotificationManager mgr=
    (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note=new Notification((Integer)img1.getTag(),
      "",
                                                System.currentTimeMillis());
                 
        // This pending intent will open after notification click
        PendingIntent i=PendingIntent.getActivity(this, 0,
                                        new Intent(),
                                        0);
                 
        note.setLatestEventInfo(this, tittle,
      "", i);
                 
        //After uncomment this line you will see number of notification arrived
        //note.number=2;
        mgr.notify(1, note);
                
                
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        Resources r = getResources();
        Notification notification = new NotificationCompat.Builder(this)
        .setTicker("Tiket")
        .setSmallIcon(android.R.drawable.ic_menu_report_image)
        .setContentTitle("Title")
        .setContentText("Context Text")
        .setContentIntent(pi)
        .setAutoCancel(true)
        .build();
            
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    */

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews);
    // Creates an explicit intent for an Activity in your app  
    Intent resultIntent = new Intent(this, MainActivity.class);
    // The stack builder object will contain an artificial back stack for  
    // the  
    // started Activity.  
    // This ensures that navigating backward from the Activity leads out of  
    // your application to the Home screen.  
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)  
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack  
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
    remoteViews.setTextViewText(R.id.textView1, nnn);
    remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white));
    remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag());
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.  
    mNotificationManager.notify(100, mBuilder.build());

}

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   ww w  .j  av a 2  s  .  c om*/
    }

    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.android.launcher3.widget.DigitalAppWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;/*w w  w .  j ava2  s  . com*/
    String action = intent.getAction();
    Log.i("sai", "onReceive: " + action);

    super.onReceive(context, intent);

    if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action)
            || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action)
            || Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId);
                // SPRD for bug421127 add am/pm for widget
                WidgetUtils.setTimeFormat(widget,
                        (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
                        R.id.the_clock);
                WidgetUtils.setClockSize(context, widget, ratio);
                //refreshAlarm(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
        if (!ACTION_ON_QUARTER_HOUR.equals(action)) {
            cancelAlarmOnQuarterHour(context);
        }
        startAlarmOnQuarterHour(context);
    }
    // cg sai.pan begin
    else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshBtStatus(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e("sai", "wifiStatus" + wifiStatus);
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                if (WifiManager.WIFI_STATE_ENABLED == wifiStatus
                        || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
                } else {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
                }
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshWifiStatus(context, widget);
            }
        }
    } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
        if (isNetworkConnected(context)) {
            Log.e("sai", "isNetworkConnected true");
            requestLocation(context);
        } else {
            Log.e("sai", "isNetworkConnected false");
        }
    }
}

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

private void setupContentView(RemoteViews rv, boolean updateNotification) {
    String contentText;/*  www .  j a v  a 2 s  .c  o  m*/

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

From source file:org.torproject.android.service.TorService.java

@SuppressLint("NewApi")
private void showToolbarNotification(String notifyMsg, int notifyType, int icon) {

    //Reusable code.
    Intent intent = new Intent(TorService.this, OrbotMainActivity.class);
    PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);

    if (mNotifyBuilder == null) {

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (mNotifyBuilder == null) {
            mNotifyBuilder = new Notification.Builder(this).setContentTitle(getString(R.string.app_name))
                    .setSmallIcon(R.drawable.ic_stat_tor);

            mNotifyBuilder.setContentIntent(pendIntent);
        }//from  w w  w .j a  va 2  s.  c o m

    }

    mNotifyBuilder.setContentText(notifyMsg);
    mNotifyBuilder.setSmallIcon(icon);

    if (notifyType != NOTIFY_ID) {
        mNotifyBuilder.setTicker(notifyMsg);
        //    mNotifyBuilder.setLights(Color.GREEN, 1000, 1000);
    } else {
        mNotifyBuilder.setTicker(null);
    }

    mNotifyBuilder.setOngoing(Prefs.persistNotifications());

    mNotification = mNotifyBuilder.build();

    if (Build.VERSION.SDK_INT >= 16 && Prefs.expandedNotifications()) {
        // Create remote view that needs to be set as bigContentView for the notification.
        RemoteViews expandedView = new RemoteViews(this.getPackageName(),
                R.layout.layout_notification_expanded);

        StringBuffer sbInfo = new StringBuffer();

        if (notifyType == NOTIFY_ID)
            expandedView.setTextViewText(R.id.text, notifyMsg);
        else {
            expandedView.setTextViewText(R.id.info, notifyMsg);
        }

        if (hmBuiltNodes.size() > 0) {
            Set<String> itBuiltNodes = hmBuiltNodes.keySet();
            for (String key : itBuiltNodes) {
                Node node = hmBuiltNodes.get(key);

                if (node.ipAddress != null) {
                    sbInfo.append(node.ipAddress);

                    if (node.country != null)
                        sbInfo.append(' ').append(node.country);

                    if (node.organization != null)
                        sbInfo.append(" (").append(node.organization).append(')');

                    sbInfo.append('\n');
                }

            }

            expandedView.setTextViewText(R.id.text2, sbInfo.toString());
        }

        expandedView.setTextViewText(R.id.title, getString(R.string.app_name));

        expandedView.setImageViewResource(R.id.icon, icon);
        mNotification.bigContentView = expandedView;
    }

    if (Prefs.persistNotifications() && (!mNotificationShowing)) {
        startForeground(NOTIFY_ID, mNotification);
        logNotice("Set background service to FOREGROUND");
    } else {
        mNotificationManager.notify(NOTIFY_ID, mNotification);
    }

    mNotificationShowing = true;
}

From source file:saphion.services.ForegroundService.java

private void setResourceImages(RemoteViews rv) {

    // Keeping this...even though it doesn't matter..value will always be
    // false//from   w  w  w  .j a  v  a 2s . c o m
    // CameraDevice mCameraDevice = new CameraDevice();
    // mCameraDevice.acquireCamera();

    if (mPref.getBoolean(PreferenceHelper.SHOW_WIFIHOTSPOT, false))
        rv.setViewVisibility(R.id.ibwifihotspot_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibwifihotspot_large, View.GONE);

    rv.setImageViewResource(R.id.ibwifihotspot_large,
            new WifiApManager(getBaseContext()).isWifiApEnabled() ? R.drawable.wifi_hotspot_on
                    : R.drawable.wifi_hotspot_off);

    rv.setImageViewResource(R.id.ibtorch_large, (isOn) ? R.drawable.lightbulb_on : R.drawable.lightbulb_off);
    // mCameraDevice.releaseCamera();
    if (mPref.getBoolean(PreferenceHelper.SHOW_TORCH, false))
        rv.setViewVisibility(R.id.ibtorch_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibtorch_large, View.GONE);

    if (mPref.getBoolean(PreferenceHelper.SHOW_AROTATE, false))
        rv.setViewVisibility(R.id.ibarotate_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibarotate_large, View.GONE);

    rv.setImageViewResource(R.id.ibarotate_large,
            ToggleHelper.isRotationEnabled(getBaseContext()) ? R.drawable.orientation_on
                    : R.drawable.orientation_off);

    if (mPref.getBoolean(PreferenceHelper.SHOW_WIFI, true))
        rv.setViewVisibility(R.id.ibwifi_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibwifi_large, View.GONE);
    rv.setImageViewResource(R.id.ibwifi_large,
            ToggleHelper.isWifiEnabled(getBaseContext()) ? R.drawable.wifi_on : R.drawable.wifi_off);
    if (mPref.getBoolean(PreferenceHelper.SHOW_MDATA, true))
        rv.setViewVisibility(R.id.ibmdata_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibmdata_large, View.GONE);
    rv.setImageViewResource(R.id.ibmdata_large,
            ToggleHelper.isDataEnable(getBaseContext()) ? R.drawable.mdata_on : R.drawable.mdata_off);
    if (mPref.getBoolean(PreferenceHelper.SHOW_BTOOTH, true))
        rv.setViewVisibility(R.id.ibbtooth_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibbtooth_large, View.GONE);
    rv.setImageViewResource(R.id.ibbtooth_large,
            ToggleHelper.isBluetoothEnabled(getBaseContext()) ? R.drawable.btooth_on : R.drawable.btooth_off);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        rv.setViewVisibility(R.id.ibamode_large, View.GONE);
    else {
        rv.setImageViewResource(R.id.ibamode_large,
                ToggleHelper.isAModeEnabled(getBaseContext()) ? R.drawable.amode_on : R.drawable.amode_off);
        if (mPref.getBoolean(PreferenceHelper.SHOW_AMODE, true))
            rv.setViewVisibility(R.id.ibamode_large, View.VISIBLE);
        else
            rv.setViewVisibility(R.id.ibamode_large, View.GONE);
    }

    if (mPref.getBoolean(PreferenceHelper.SHOW_SYNC, true))
        rv.setViewVisibility(R.id.ibsync_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibsync_large, View.GONE);
    rv.setImageViewResource(R.id.ibsync_large,
            ToggleHelper.isSyncEnabled() ? R.drawable.sync_on : R.drawable.sync_off);
    if (mPref.getBoolean(PreferenceHelper.SHOW_BNESS, true))
        rv.setViewVisibility(R.id.ibbrightness_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibbrightness_large, View.GONE);
    switch (ToggleHelper.getBrightnessMode(getBaseContext())) {
    case 1:
        rv.setImageViewResource(R.id.ibbrightness_large, R.drawable.blow_on);
        break;
    case 2:
        rv.setImageViewResource(R.id.ibbrightness_large, R.drawable.bhalf_on);
        break;
    case 3:
        rv.setImageViewResource(R.id.ibbrightness_large, R.drawable.bfull_on);
        break;
    case 0:
        rv.setImageViewResource(R.id.ibbrightness_large, R.drawable.bauto_on);
        break;
    }
    if (mPref.getBoolean(PreferenceHelper.SHOW_PSWITCHER, false))
        rv.setViewVisibility(R.id.ibpowersaver_toggle_large, View.VISIBLE);
    else
        rv.setViewVisibility(R.id.ibpowersaver_toggle_large, View.GONE);
    ArrayList<PowerProfItems> poweritems = PowerPreference.retPower(getBaseContext());
    if (mPref.getInt(PreferenceHelper.PROF2, 0) < poweritems.size()
            && mPref.getInt(PreferenceHelper.PROF1, 0) < poweritems.size()) {
        if (poweritems.get(mPref.getInt(PreferenceHelper.PROF2, 0)).isPowerProfequal(
                ToggleHelper.isWifiEnabled(getBaseContext()), ToggleHelper.isDataEnable(getBaseContext()),
                ToggleHelper.isBluetoothEnabled(getBaseContext()),
                ToggleHelper.isAModeEnabled(getBaseContext()), ToggleHelper.isSyncEnabled(),
                ToggleHelper.getBrightness(getBaseContext()), ToggleHelper.isHapticFback(getBaseContext()),
                ToggleHelper.isRotationEnabled(getBaseContext()), ToggleHelper.getRingerMode(getBaseContext()),
                String.valueOf(ToggleHelper.getScreenTimeOut(getBaseContext()))))
            rv.setImageViewResource(R.id.ibpowersaver_toggle_large, R.drawable.power_on);
        else if (poweritems.get(mPref.getInt(PreferenceHelper.PROF1, 0)).isPowerProfequal(
                ToggleHelper.isWifiEnabled(getBaseContext()), ToggleHelper.isDataEnable(getBaseContext()),
                ToggleHelper.isBluetoothEnabled(getBaseContext()),
                ToggleHelper.isAModeEnabled(getBaseContext()), ToggleHelper.isSyncEnabled(),
                ToggleHelper.getBrightness(getBaseContext()), ToggleHelper.isHapticFback(getBaseContext()),
                ToggleHelper.isRotationEnabled(getBaseContext()), ToggleHelper.getRingerMode(getBaseContext()),
                String.valueOf(ToggleHelper.getScreenTimeOut(getBaseContext()))))
            rv.setImageViewResource(R.id.ibpowersaver_toggle_large, R.drawable.power_off);
        else
            rv.setImageViewResource(R.id.ibpowersaver_toggle_large, R.drawable.power_custom);
    } else {
        rv.setImageViewResource(R.id.ibpowersaver_toggle_large, R.drawable.power_custom);
    }

}

From source file:com.wm.remusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;
    final int PAUSE_FLAG = 0x1;
    final int NEXT_FLAG = 0x2;
    final int STOP_FLAG = 0x3;
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();

    remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;
    remoteViews.setTextViewText(R.id.title, getTrackName());
    remoteViews.setTextViewText(R.id.text, text);

    //action?  ?flag??
    Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION);
    pauseIntent.putExtra("FLAG", PAUSE_FLAG);
    PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
    remoteViews.setImageViewResource(R.id.iv_pause,
            isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play);
    remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent);

    Intent nextIntent = new Intent(NEXT_ACTION);
    nextIntent.putExtra("FLAG", NEXT_FLAG);
    PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent);

    Intent preIntent = new Intent(STOP_ACTION);
    preIntent.putExtra("FLAG", STOP_FLAG);
    PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent);

    //        PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0,
    //                new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    final Intent nowPlayingIntent = new Intent();
    //nowPlayingIntent.setAction("com.wm.remusic.LAUNCH_NOW_PLAYING_ACTION");
    nowPlayingIntent/* w w  w .j a v a 2s. c  o  m*/
            .setComponent(new ComponentName("com.wm.remusic", "com.wm.remusic.activity.PlayingActivity"));
    nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160);
    if (bitmap != null) {
        remoteViews.setImageViewBitmap(R.id.image, bitmap);
        // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId()));
        mNoBit = null;

    } else if (!isTrackLocal()) {
        if (mNoBit != null) {
            remoteViews.setImageViewBitmap(R.id.image, mNoBit);
            mNoBit = null;

        } else {
            Uri uri = null;
            if (getAlbumPath() != null) {
                try {
                    uri = Uri.parse(getAlbumPath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (getAlbumPath() == null || uri == null) {
                mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                updateNotification();
            } else {
                ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
                        .setProgressiveRenderingEnabled(true).build();
                ImagePipeline imagePipeline = Fresco.getImagePipeline();
                DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
                        .fetchDecodedImage(imageRequest, MediaService.this);

                dataSource.subscribe(new BaseBitmapDataSubscriber() {

                    @Override
                    public void onNewResultImpl(@Nullable Bitmap bitmap) {
                        // You can use the bitmap in only limited ways
                        // No need to do any cleanup.
                        if (bitmap != null) {
                            mNoBit = bitmap;
                        }
                        updateNotification();
                    }

                    @Override
                    public void onFailureImpl(DataSource dataSource) {
                        // No cleanup required here.
                        mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                        updateNotification();
                    }
                }, CallerThreadExecutor.getInstance());
            }
        }

    } else {
        remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }
    if (mNotification == null) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews)
                .setSmallIcon(R.drawable.ic_notification).setContentIntent(click)
                .setWhen(mNotificationPostTime);
        if (CommonUtils.isJellyBeanMR1()) {
            builder.setShowWhen(false);
        }
        mNotification = builder.build();
    } else {
        mNotification.contentView = remoteViews;
    }

    return mNotification;
}

From source file:com.cloud9.netmusic.service.MediaService.java

private Notification getNotification() {
    RemoteViews remoteViews;
    final int PAUSE_FLAG = 0x1;
    final int NEXT_FLAG = 0x2;
    final int STOP_FLAG = 0x3;
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();

    remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;
    remoteViews.setTextViewText(R.id.title, getTrackName());
    remoteViews.setTextViewText(R.id.text, text);

    //action?  ?flag??
    Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION);
    pauseIntent.putExtra("FLAG", PAUSE_FLAG);
    PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
    remoteViews.setImageViewResource(R.id.iv_pause,
            isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play);
    remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent);

    Intent nextIntent = new Intent(NEXT_ACTION);
    nextIntent.putExtra("FLAG", NEXT_FLAG);
    PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent);

    Intent preIntent = new Intent(STOP_ACTION);
    preIntent.putExtra("FLAG", STOP_FLAG);
    PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent);

    //        PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0,
    //                new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    final Intent nowPlayingIntent = new Intent();
    //nowPlayingIntent.setAction("com.cloud9.netmusic.LAUNCH_NOW_PLAYING_ACTION");
    nowPlayingIntent.setComponent(new ComponentName("com.wm.remusic", "PlayingActivity"));
    nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160);
    if (bitmap != null) {
        remoteViews.setImageViewBitmap(R.id.image, bitmap);
        // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId()));
        mNoBit = null;//from  w w  w. j a  va  2 s  .co m

    } else if (!isTrackLocal()) {
        if (mNoBit != null) {
            remoteViews.setImageViewBitmap(R.id.image, mNoBit);
            mNoBit = null;

        } else {
            Uri uri = null;
            if (getAlbumPath() != null) {
                try {
                    uri = Uri.parse(getAlbumPath());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (getAlbumPath() == null || uri == null) {
                mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                updateNotification();
            } else {
                ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri)
                        .setProgressiveRenderingEnabled(true).build();
                ImagePipeline imagePipeline = Fresco.getImagePipeline();
                DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
                        .fetchDecodedImage(imageRequest, MediaService.this);

                dataSource.subscribe(new BaseBitmapDataSubscriber() {

                    @Override
                    public void onNewResultImpl(@Nullable Bitmap bitmap) {
                        // You can use the bitmap in only limited ways
                        // No need to do any cleanup.
                        if (bitmap != null) {
                            mNoBit = bitmap;
                        }
                        updateNotification();
                    }

                    @Override
                    public void onFailureImpl(DataSource dataSource) {
                        // No cleanup required here.
                        mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
                        updateNotification();
                    }
                }, CallerThreadExecutor.getInstance());
            }
        }

    } else {
        remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }
    if (mNotification == null) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews)
                .setSmallIcon(R.drawable.ic_notification).setContentIntent(click)
                .setWhen(mNotificationPostTime);
        if (CommonUtils.isJellyBeanMR1()) {
            builder.setShowWhen(false);
        }
        mNotification = builder.build();
    } else {
        mNotification.contentView = remoteViews;
    }

    return mNotification;
}