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:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

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

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

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

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

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

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

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

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

From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java

private static Notification createCustomNotification(Context context, MusicDirectory.Entry song,
        boolean playing) {

    Bitmap albumArt;// www  . j  a  va  2 s.co m
    try {
        albumArt = FileUtil.getUnscaledAlbumArtBitmap(context, song);
        if (albumArt == null) {
            albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large);
        }
    } catch (Exception x) {
        LOG.warn("Failed to get notification cover art", x);
        albumArt = Util.decodeBitmap(context, R.drawable.unknown_album_large);
    }

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    contentView.setTextViewText(R.id.notification_title, song.getTitle());
    contentView.setTextViewText(R.id.notification_artist, song.getArtist());
    contentView.setImageViewBitmap(R.id.notification_image, albumArt);
    contentView.setImageViewResource(R.id.notification_playpause,
            playing ? R.drawable.media_pause : R.drawable.media_start);

    Intent intent = new Intent("1");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
    contentView.setOnClickPendingIntent(R.id.notification_playpause,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("2");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
    contentView.setOnClickPendingIntent(R.id.notification_next,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("4");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true);
    contentView.setOnClickPendingIntent(R.id.notification_close,
            PendingIntent.getService(context, 0, intent, 0));

    Intent notificationIntent = new Intent(context, DownloadActivity.class);

    Notification notification = new NotificationCompat.Builder(context).setOngoing(true)
            .setSmallIcon(R.drawable.stat_notify_playing).setContent(contentView)
            .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)).build();
    if (Build.VERSION.SDK_INT >= 16) {
        notification.bigContentView = createBigContentView(context, song, albumArt, playing);
    }
    return notification;
}

From source file:android.support.v7.app.NotificationCompatImplBase.java

private static RemoteViews generateMediaActionButton(Context context, NotificationCompatBase.Action action) {
    final boolean tombstone = (action.getActionIntent() == null);
    RemoteViews button = new RemoteViews(context.getPackageName(), R.layout.notification_media_action);
    button.setImageViewResource(R.id.action0, action.getIcon());
    if (!tombstone) {
        button.setOnClickPendingIntent(R.id.action0, action.getActionIntent());
    }//from  w w  w .  ja v a  2  s.  co m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        button.setContentDescription(R.id.action0, action.getTitle());
    }
    return button;
}

From source file:org.opensilk.music.playback.NotificationHelper.java

private void buildNotificationInternal() {
    if (mCurrentInfo.hasAnyNull() || mService == null) {
        return;// w  ww.  j  av  a2s  . c o  m
    }
    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mContext.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(mCurrentInfo.track.name, mCurrentInfo.track.artistName, mCurrentInfo.bitmap);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.stat_notify_music)
            .setContentIntent(getPendingIntent()).setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_TRANSPORT).setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(mCurrentInfo.isPlaying);
    if (VersionUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mContext.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(mCurrentInfo.isPlaying);
        // Set up the expanded content view
        initExpandedLayout(mCurrentInfo.track.name, mCurrentInfo.track.albumName, mCurrentInfo.track.artistName,
                mCurrentInfo.bitmap);
    }

    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}

From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java

private RemoteViews getCustomContentView() {
    RemoteViews view = new RemoteViews(_package, R.layout.view_layout_notification);
    int style = settings.getResources().getIdentifier("style_" + settings.getTheme(), "style", _package);
    int backgroundColor;
    int iconColor;

    if (style != 0) {
        backgroundColor = settings.getStyleAttributeColor(style, android.R.attr.colorBackground);
        iconColor = settings.getStyleAttributeColor(style, android.R.attr.colorForeground);
    } else {//from   w w  w .  j  a va  2s . co m
        backgroundColor = settings.getColor(settings.getCustomThemeBackgroundColor());
        iconColor = settings.getColor(settings.getCustomThemeIconColor());
    }
    if (settings.getTranslucent()) {
        backgroundColor = android.R.color.transparent;
    }
    view.setInt(R.id.notification_layout, "setBackgroundColor", backgroundColor);
    view.removeAllViews(R.id.volume_control_wrapper);

    for (int pos = 0; pos < items.size(); pos++) {
        VolumeControl item = model.parseItem(items.get(pos));
        if (item.status == 0) {
            continue;
        }
        RemoteViews btn = new RemoteViews(_package, R.layout.view_widget_volume_control);
        PendingIntent event = PendingIntent.getBroadcast(context.getApplicationContext(), item.id,
                new Intent(context, SetVolumeReceiver.class).putExtra(EXTRA_ITEM_ID, item.id),
                PendingIntent.FLAG_UPDATE_CURRENT);

        btn.setOnClickPendingIntent(R.id.btn_volume_control, event);
        btn.setInt(R.id.btn_volume_control, "setImageResource", model.getIconDrawable(item.icon));
        btn.setInt(R.id.btn_volume_control, "setColorFilter", iconColor);
        view.addView(R.id.volume_control_wrapper, btn);
    }

    return view;
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) {
    String title = dataInfo.getTitle();
    String body = dataInfo.getAlert();
    String message = dataInfo.getPushDataString();
    Builder builder = new Builder(context);
    builder.setAutoCancel(true);/*from   w  w w . j  a  va2  s  .  c  o  m*/
    builder.setContentTitle(title); // 
    builder.setContentText(body); // 
    builder.setTicker(body); // ??

    String[] remindType = dataInfo.getRemindType();
    if (remindType != null) {
        if (remindType.length == 3) {
            builder.setDefaults(Notification.DEFAULT_ALL);
        } else {
            int defaults = 0;
            for (int i = 0; i < remindType.length; i++) {
                if ("sound".equalsIgnoreCase(remindType[i])) {
                    defaults = Notification.DEFAULT_SOUND;
                    continue;
                }
                if ("shake".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_VIBRATE;
                    continue;
                }
                if ("breathe".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_LIGHTS;
                    continue;
                }
            }
            builder.setDefaults(defaults);
        }
    }

    Resources res = context.getResources();
    int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
    builder.setSmallIcon(icon);
    builder.setWhen(System.currentTimeMillis()); // 

    String iconUrl = dataInfo.getIconUrl();
    boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl);
    Bitmap bitmap = null;
    if (!isDefaultIcon) {
        bitmap = getIconBitmap(context, iconUrl);
    }
    String fontColor = dataInfo.getFontColor();
    RemoteViews remoteViews = null;
    if (!TextUtils.isEmpty(fontColor)) {
        int color = BUtility.parseColor(fontColor);
        int alphaColor = parseAlphaColor(fontColor);
        remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view"));
        // Title
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color);
        // Body
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor);
        // LargeIcon
        if (bitmap != null) {
            remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap);
        } else {
            remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"),
                    EUExUtil.getResDrawableID("icon"));
        }
        // Time
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"),
                format.format(System.currentTimeMillis()));
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor);
        builder.setContent(remoteViews);
    }

    Intent notiIntent = new Intent(context, EBrowserActivity.class);
    notiIntent.putExtra("ntype", F_TYPE_PUSH);
    notiIntent.putExtra("data", body);
    notiIntent.putExtra("message", message);
    Bundle bundle = new Bundle();
    bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo);
    notiIntent.putExtras(bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    // Android v4bug2.3?Builder?NotificationRemoteView??
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) {
        notification.contentView = remoteViews;
    }
    manager.notify(notificationNB, notification);
    notificationNB++;
}

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

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {

    Bundle b = new Bundle();
    isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false);
    ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
    String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
    int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
    final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
    accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference()
            .getCurrentUserColorPreferences(this, sharedPreferences).accent;

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt(TAG_COPY_START_ID, startId);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    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_COPY_CANCEL);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(c, 1234, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_content_copy_white_36dp,
            getString(R.string.stop_ftp), stopPendingIntent);

    mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID)
            .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_content_copy_white_36dp)
            .setCustomContentView(customSmallContentViews).setCustomBigContentView(customBigContentViews)
            .setCustomHeadsUpContentView(customSmallContentViews)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true)
            .setColor(accentColor);//from   w  w  w.  j  a  v  a  2s .c om

    // set default notification views text

    NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL);

    startForeground(NotificationConstants.COPY_ID, mBuilder.build());
    initNotificationViews();

    b.putBoolean(TAG_COPY_MOVE, move);
    b.putString(TAG_COPY_TARGET, targetPath);
    b.putInt(TAG_COPY_OPEN_MODE, mode);
    b.putParcelableArrayList(TAG_COPY_SOURCES, files);

    super.onStartCommand(intent, flags, startId);
    super.progressHalted();
    //going async
    new DoInBackground(isRootExplorer).execute(b);

    // If we get killed, after returning from here, restart
    return START_STICKY;
}

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Update the widget.//from   w ww . j  a  va2s.  co  m
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
        final int appWidgetId) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), this.mLayoutId);
    final int idFavori = WidgetConfigureActivity.getFavoriIdFromWidget(context, appWidgetId);
    final Favori favori = FavorisViewManager.getInstance().getSingle(context.getContentResolver(), idFavori);

    if (DBG)
        Log.i(LOG_TAG, Integer.toHexString(hashCode()) + " - " + appWidgetId + " - updateAppWidget " + favori);

    // Initialisation du nombre d'horaires
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        final Bundle bundle = appWidgetManager.getAppWidgetOptions(appWidgetId);
        mHoraireLimit = getHorairesCount(context, bundle);
    } else {
        if (mHoraireLimit == -1) {
            mHoraireLimit = context.getResources().getInteger(mHoraireLimitRes);
        }
    }

    if (favori != null) {
        prepareWidgetView(context, views, favori, appWidgetId);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    } else {
        WidgetConfigureActivity.removeWidgetId(context, appWidgetId);
    }
}

From source file:ti.modules.titanium.audio.streamer.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *///from w  w  w  . j a va  2 s  .  c  o m
public void buildNotification() {

    // Default notfication layout
    if (mViewId == 0 && mExpandedViewId == 0) {
        return;
    }

    try {
        mDrawablePlay = TiRHelper.getResource("drawable." + NOTIFICATION_DRAWBLE_PLAY);
        mDrawablePause = TiRHelper.getResource("drawable." + NOTIFICATION_DRAWBLE_PAUSE);
    } catch (ResourceNotFoundException e1) {
    }

    if (mViewId > 0) {
        mView = new RemoteViews(mService.getPackageName(), mViewId);
        try {
            id_notification_base_title = TiRHelper.getResource("id." + NOTIFICATION_BASE_TITLE);
            id_notification_base_artist = TiRHelper.getResource("id." + NOTIFICATION_BASE_ARTIST);
            id_notification_base_album = TiRHelper.getResource("id." + NOTIFICATION_BASE_ALBUM);
            id_notification_base_image = TiRHelper.getResource("id." + NOTIFICATION_BASE_IMAGE);
            id_notification_base_play = TiRHelper.getResource("id." + NOTIFICATION_BASE_PLAY);
            id_notification_base_prev = TiRHelper.getResource("id." + NOTIFICATION_BASE_PREV);
            id_notification_base_next = TiRHelper.getResource("id." + NOTIFICATION_BASE_NEXT);
        } catch (ResourceNotFoundException e) {
        }
        // Set up the content view
        // initCollapsedLayout(trackName, albumName, artistName, albumArt);
    }

    if (HONEYCOMB_OR_GREATER) {
        // Notification Builder
        mNotification = new NotificationCompat.Builder(mService).setSmallIcon(mIcon)
                .setContentIntent(getPendingIntent()).setOngoing(true)
                .setPriority(Notification.PRIORITY_DEFAULT).setContent(mView).build();
        // Control playback from the notification
        initPlaybackActions();
        if (JELLY_BEAN_OR_GREATER) {
            // Expanded notifiction style
            mExpandedView = new RemoteViews(mService.getPackageName(), mExpandedViewId);
            try {
                id_notification_expanded_title = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_TITLE);
                id_notification_expanded_artist = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_ARTIST);
                id_notification_expanded_album = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_ALBUM);
                id_notification_expanded_image = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_IMAGE);
                id_notification_expanded_play = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_PLAY);
                id_notification_expanded_prev = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_PREV);
                id_notification_expanded_next = TiRHelper.getResource("id." + NOTIFICATION_EXPANDED_NEXT);
                id_notification_expanded_collapse = TiRHelper
                        .getResource("id." + NOTIFICATION_EXPANDED_COLLAPSE);
            } catch (ResourceNotFoundException e) {
            }

            mNotification.bigContentView = mExpandedView;
            // Control playback from the notification
            initExpandedPlaybackActions();
            // Set up the expanded content view
            // initExpandedLayout(trackName, albumName, artistName,
            // albumArt);
        }
        mService.startForeground(mNotificationId, mNotification);
    } else {
        Builder notificationBuilder = new NotificationCompat.Builder(mService);
        notificationBuilder.setSmallIcon(mIcon);
        notificationBuilder.setContentIntent(getPendingIntent());
        notificationBuilder.setOngoing(true);
        mNotification = notificationBuilder.build();
        mNotification.contentView = mView;
        if (JELLY_BEAN_OR_GREATER) {
            mNotification.bigContentView = mExpandedView;

        }
        mService.startForeground(mNotificationId, mNotification);
    }
}

From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java

private RemoteViews getRemoteViews(final String name, final int cellid, final int lac, final int ss,
        final int ssp, final long rxsp, final long txsp) {
    final RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.notifications_main);
    contentView.setImageViewResource(R.id.imagenotileft, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, getString(R.string.app_name));
    contentView.setTextViewText(R.id.textInfo, "CellID: " + cellid + ", LAC: " + lac);
    String speeds = "Rx:" + RecorderCtx.convertToHuman(rxsp, false) + "/s, Tx:"
            + RecorderCtx.convertToHuman(txsp, false) + "/s";
    contentView.setTextViewText(R.id.textNetwork, "Network: " + name + ", " + speeds);
    contentView.setTextViewText(R.id.textSS, "Signal strength: " + ss + " dBm (" + ssp + "%)");
    return contentView;
}