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:com.rossier.shclechelles.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  w  ww  . j  ava 2 s  .  c  om
 */
private void sendNotification(String from, String message) {
    Gson gson = new GsonBuilder().create();
    String messageUTF8 = "";
    try {
        messageUTF8 = new String(message.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    Log.i("MyGCMListenerService", message);
    Log.i("MyGCMListenerService", messageUTF8);
    if (messageUTF8 == "")
        return;
    MatchNotification match = gson.fromJson(messageUTF8, MatchNotification.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    int icon = R.drawable.ic_launcher_shc;
    long when = System.currentTimeMillis();
    // Notification notification = new Notification(icon, "Nouveaux rsultats", when);
    Notification notification = new Notification.Builder(this.getBaseContext())
            .setContentText("Nouveaux rsultats").setSmallIcon(icon).setWhen(when).build();

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.match_notif_layout);
    contentView.setTextViewText(R.id.notif_team_home, match.getTeam_home());
    contentView.setTextViewText(R.id.notif_team_away, match.getTeam_away());
    contentView.setTextViewText(R.id.notif_result_home, match.getResult_home() + "");
    contentView.setTextViewText(R.id.notif_result_away, match.getResult_away() + "");
    contentView.setTextViewText(R.id.notif_ligue, match.getLigue());
    contentView.setImageViewResource(R.id.notif_team_loc_logo, Utils.getLogo(match.getTeam_home()));
    contentView.setImageViewResource(R.id.notif_team_away_logo, Utils.getLogo(match.getTeam_away()));
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;

    //notification.flags |= Notification.FLAG_ONGOING_EVENT; //Do not clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    //get topics name
    String[] topic = from.split("/");

    mNotificationManager.notify(topic[2].hashCode(), notification);
}

From source file:com.meiste.greg.ptw.WidgetProvider.java

@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    Util.log("WidgetProvider.onUpdate: num=" + appWidgetIds.length);

    final RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
    appWidgetManager.updateAppWidget(appWidgetIds, rViews);

    new UpdateWidgetThread(context).start();

    /* Set alarm to update widget when device is awake. */
    setAlarm(context);/*  w ww. j  a  va  2 s  .  c om*/
}

From source file:com.amaze.filemanager.asynchronous.services.ExtractService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    String file = intent.getStringExtra(KEY_PATH_ZIP);
    String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT);
    String[] entries = intent.getStringArrayExtra(KEY_ENTRIES_ZIP);

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference()
            .getCurrentUserColorPreferences(this, sharedPreferences).accent;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small);
    customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big);

    Intent stopIntent = new Intent(TAG_BROADCAST_EXTRACT_CANCEL);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 1234, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_zip_box_grey600_36dp,
            getString(R.string.stop_ftp), stopPendingIntent);

    mBuilder = new NotificationCompat.Builder(context, NotificationConstants.CHANNEL_NORMAL_ID);
    mBuilder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp)
            .setContentIntent(pendingIntent).setCustomContentView(customSmallContentViews)
            .setCustomBigContentView(customBigContentViews).setCustomHeadsUpContentView(customSmallContentViews)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true)
            .setColor(accentColor);//  www .ja v  a 2 s .c o  m

    NotificationConstants.setMetadata(getApplicationContext(), mBuilder, NotificationConstants.TYPE_NORMAL);
    startForeground(NotificationConstants.EXTRACT_ID, mBuilder.build());
    initNotificationViews();

    long totalSize = getTotalSize(file);

    progressHandler.setSourceSize(1);
    progressHandler.setTotalSize(totalSize);
    progressHandler.setProgressListener((speed) -> publishResults(speed, false, false));

    super.onStartCommand(intent, flags, startId);
    super.progressHalted();
    new DoWork(this, progressHandler, file, extractPath, entries).execute();

    return START_STICKY;
}

From source file:com.makotosan.vimeodroid.TransferService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    counter++;/* w w w .  j av a  2  s  .com*/
    transfer = new Transfer();
    final String videoUri = intent.getStringExtra("videouri");
    final TransferType transferType = TransferType.valueOf(intent.getStringExtra("transferType"));
    final String fileName = intent.getStringExtra("fileName");
    Bitmap bitmapThumbnail = null;
    int transferIcon = android.R.drawable.stat_sys_download;

    if (transferType == TransferType.Upload) {
        // Get the resource ID for the video
        final long resourceId = ContentUris.parseId(Uri.parse(videoUri));

        bitmapThumbnail = android.provider.MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(),
                resourceId, android.provider.MediaStore.Video.Thumbnails.MICRO_KIND, null);
        transfer.setIcon(bitmapThumbnail);
        transferIcon = android.R.drawable.stat_sys_upload;
    }

    // Initialize our notification
    final Notification notification = new Notification(transferIcon, "Transferring...",
            System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(this.getPackageName(), R.layout.transferprogress);

    final Intent manageIntent = new Intent(this, ManageTransfersActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, manageIntent, 0);

    notification.contentIntent = pendingIntent;
    if (bitmapThumbnail != null) {
        notification.contentView.setImageViewBitmap(R.id.transferprogressIcon, bitmapThumbnail);
    } else {
        notification.contentView.setImageViewResource(R.id.transferprogressIcon, R.drawable.icon);
    }

    notification.contentView.setProgressBar(R.id.transferprogressBar, 100, 0, false);
    notification.contentView.setTextViewText(R.id.transferprogressText, "Transferring... ");
    notification.contentView.setOnClickPendingIntent(R.layout.transferprogress, pendingIntent);

    // Add it to the collection of notifications
    notifications.put(counter, notification);

    // Add our notification to the notification tray
    notificationManager.notify(counter, notification);

    // Initialize our asynchronous transfer task
    final TransferTask task = new TransferTask(counter, transferType);

    task.execute(videoUri, fileName);
    return Service.START_STICKY;
}

From source file:org.messic.android.player.MessicPlayerNotification.java

private void createNotification() {
    if (this.notification != null) {
        return;//from w w w  .jav a 2s  .  c o m
    }

    mNotificationManager = (NotificationManager) this.service.getSystemService(Context.NOTIFICATION_SERVICE);
    RemoteViews contentView = new RemoteViews(this.service.getPackageName(),
            R.layout.bignotification_player_layout);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.service)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title")
            .setPriority(Notification.PRIORITY_MAX).setContent(contentView);

    Notification n = mBuilder.build();
    n.bigContentView = contentView;

    Intent intentClose = new Intent(ACTION_CLOSE);
    PendingIntent pintentClose = PendingIntent.getBroadcast(this.service, 0, intentClose, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivclose, pintentClose);
    Intent intentBack = new Intent(ACTION_BACK);
    PendingIntent pintentBack = PendingIntent.getBroadcast(this.service, 0, intentBack, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivback, pintentBack);
    Intent intentPlay = new Intent(ACTION_PLAY);
    PendingIntent pintentPlay = PendingIntent.getBroadcast(this.service, 0, intentPlay, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivplay, pintentPlay);
    Intent intentPause = new Intent(ACTION_PAUSE);
    PendingIntent pintentPause = PendingIntent.getBroadcast(this.service, 0, intentPause, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivpause, pintentPause);
    Intent intentNext = new Intent(ACTION_NEXT);
    PendingIntent pintentNext = PendingIntent.getBroadcast(this.service, 0, intentNext, 0);
    contentView.setOnClickPendingIntent(R.id.base_ivnext, pintentNext);

    this.notification = n;
    this.service.startForeground(ONGOING_NOTIFICATION_ID, notification);
    this.registerBroadcastActions();
}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

private void updateWidget(@Nonnull Context context, @Nonnull AppWidgetManager manager, @Nonnull int[] widgetIds,
        boolean partially) {
    final EditorState editorState = editor.getState();
    final DisplayState displayState = display.getState();

    final Resources resources = context.getResources();
    final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme());
    for (int widgetId : widgetIds) {
        final RemoteViews views = new RemoteViews(context.getPackageName(),
                getLayout(manager, widgetId, resources, theme));

        if (!partially || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            for (CppButton button : CppButton.values()) {
                final PendingIntent intent = intents.get(context, button);
                if (intent != null) {
                    final int buttonId;
                    if (button == CppButton.settings_widget) {
                        // overriding default settings button behavior
                        buttonId = CppButton.settings.id;
                    } else {
                        buttonId = button.id;
                    }//from w  ww . j a va 2 s.co m
                    views.setOnClickPendingIntent(buttonId, intent);
                }
            }
        }

        updateEditorState(context, views, editorState, theme);
        updateDisplayState(context, views, displayState, theme);

        views.setTextViewText(R.id.cpp_button_multiplication, engine.getMultiplicationSign());

        if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            manager.partiallyUpdateAppWidget(widgetId, views);
        } else {
            manager.updateAppWidget(widgetId, views);
        }
    }
}

From source file:de.ub0r.android.portaltimer.UpdateReceiver.java

private boolean updateNotification(final Context context) {
    Log.d(TAG, "updateNotification()");
    lastUpdate = System.currentTimeMillis();
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    ArrayList<Timer> timers = new ArrayList<Timer>();
    mNow = System.currentTimeMillis();
    mNextTarget = 0;//from  www .  ja  v  a2  s .  c  o  m
    boolean alert = false;
    Log.d(TAG, "mNow: " + mNow);

    for (int j = 0; j < Timer.TIMER_IDS.length; j++) {
        Timer t = new Timer(context, j);
        timers.add(t);
        long tt = t.getTarget();
        Log.d(TAG, "target(" + j + "): " + tt);

        if (tt > 0) {
            if (mNextTarget == 0 || tt < mNextTarget) {
                mNextTarget = tt;
            }
            if (tt < mNow) {
                alert = true;
                t.reset(context);
            }
        }
    }
    Log.d(TAG, "mNextTarget: " + mNextTarget);

    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    b.setPriority(1000);
    Intent i = new Intent(context, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));

    b.setContentTitle(context.getString(R.string.app_name));
    b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
    b.setSmallIcon(R.drawable.ic_stat_timer);
    b.setAutoCancel(false);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB-
        b.setContentText(context.getString(R.string.notification_text, timers.get(0).getFormatted(),
                timers.get(1).getFormatted(), timers.get(2).getFormatted()));
    } else { // HC+
        RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification);
        for (int j = 0; j < Timer.TIMER_IDS.length; j++) {
            v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString());
            Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class);
            v.setOnClickPendingIntent(Timer.TIMER_IDS[j],
                    PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT));
        }
        v.setOnClickPendingIntent(R.id.settings, PendingIntent.getActivity(context, 0,
                new Intent(context, SettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
        b.setContent(v);
    }

    if (mNextTarget <= 0 && !alert) {
        // we don't need any notification
        b.setOngoing(false);
        nm.notify(0, b.build());
        return false;
    } else if (alert) {
        // show notification without running Timer
        b.setOngoing(mNextTarget > 0);
        SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
        if (p.getBoolean("vibrate", true)) {
            b.setVibrate(VIBRATE);
        }
        String n = p.getString("notification", null);
        if (n == null) { // default
            b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        } else if (n.length() > 1) {
            try {
                b.setSound(Uri.parse(n));
            } catch (Exception e) {
                Log.e(TAG, "invalid notification uri", e);
                b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            }
        } // else: silent
        nm.notify(0, b.build());
        return true;
    } else {
        // show notification with running Timer
        b.setOngoing(true);
        nm.notify(0, b.build());
        return true;
    }
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected void onPostExecute(JSONObject jsonObject) {
    if (jsonObject != null) {
        try {//from  w  w  w .  ja  v a2s  .c  om
            Context context = mContext.get();
            if (context == null) {
                return;
            }
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            for (int x : mMap.keySet()) {
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout);
                double price = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getDouble("last");
                String priceString;
                if (price > 1) {
                    priceString = (new DecimalFormat("#.##")).format(price);
                } else {
                    priceString = String.valueOf(price);
                }
                views.setTextViewText(R.id.widgetCurrencyValue, priceString);
                views.setTextViewText(R.id.widgetPair, mMap.get(x));
                String color = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getString("color");
                int colorValue = color.equals("green") ? Color.GREEN : Color.RED;
                views.setTextColor(R.id.widgetCurrencyValue, colorValue);
                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle bundle = new Bundle();
                bundle.putIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS,
                        appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class)));
                intent.putExtras(bundle);
                PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                views.setOnClickPendingIntent(R.id.widgetContainer, pi);
                SimpleDateFormat df = new SimpleDateFormat("EEE HH:mm", Locale.US);
                Calendar calendar = Calendar.getInstance();
                views.setTextViewText(R.id.widgetDate, df.format(calendar.getTime()));
                appWidgetManager.updateAppWidget(x, views);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.ferdi2005.secondgram.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 w w.j a  va2 s  .c  om
    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) {
            try {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover());
            } catch (Throwable e) {
                FileLog.e(e);
            }
        }
        metadataEditor.apply();
    }
}

From source file:com.panahit.telegramma.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 w w . j  a  v a2 s  .c o  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();
    }
}