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.securecomcode.text.service.KeyCachingService.java

private void foregroundServiceICS() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification);

    remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, buildLockIntent());

    builder.setSmallIcon(R.drawable.icon_cached);
    builder.setContent(remoteViews);/*  ww w.j  a  va2 s  . c  om*/
    builder.setContentIntent(buildLaunchIntent());

    stopForeground(true);
    startForeground(SERVICE_RUNNING_ID, builder.build());
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

/**
 * Method to generate the remote view for the progress notification
 * /*w  w  w  .  j a v  a2 s .co  m*/
 * 
 */
private RemoteViews generateProgressNotificationView(final int progress, final int total) {
    final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout_upload);
    contentView.setProgressBar(R.id.UploadProgress, total, progress, false);
    contentView.setTextViewText(R.id.text, "Uploaded " + progress + " of " + total + " bytes");
    return contentView;
}

From source file:org.droidkit.app.UpdateService.java

private void notifyDownloading(String json) {
    Intent intent = new Intent(this, UpdateActivity.class);
    intent.putExtra("downloading", true);
    intent.putExtra("json", json);

    String desc = "Downloading " + getString(getApplicationInfo().labelRes);
    PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
    Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...",
            System.currentTimeMillis());
    n.flags = Notification.FLAG_ONGOING_EVENT;
    n.contentIntent = pending;//ww w . ja v  a  2s . c  om

    RemoteViews view = new RemoteViews(getPackageName(),
            Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT));
    view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc);
    view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true);
    view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID),
            android.R.drawable.stat_sys_download);

    n.contentView = view;

    mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n);
}

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);
        }//  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:com.sxt.chat.utils.NotificationHelper.java

/**
 * View/*from  www  . j a v  a  2 s  .c o  m*/
 */
public NotificationCompat.Builder buildCustomNotificationDefault(String title, String body,
        PendingIntent pendingIntent) {
    NotificationCompat.Builder builder = getNotificationBuilderByChannel();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // ?
        RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
        RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
        builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setCustomContentView(notificationLayout).setCustomBigContentView(notificationLayoutExpanded);
    } else {
        builder.setSound(soundUri)
                .setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle(title).bigText(body));
    }
    return builder.setAutoCancel(true).setSmallIcon(getSmallIcon()).setLargeIcon(getLargeIcon())
            .setContentTitle(title).setContentText(body).setContentIntent(pendingIntent);
}

From source file:org.messic.android.smartphone.notifications.MessicPlayerNotification.java

private void createNotification() {
    if (this.notification != null) {
        return;//w  w  w . j a  v a 2  s.  c om
    }

    mNotificationManager = (NotificationManager) this.service.getSystemService(Context.NOTIFICATION_SERVICE);
    RemoteViews smallContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_small);
    RemoteViews bigContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_big);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.service);
    mBuilder.setSmallIcon(R.mipmap.ic_launcher);
    mBuilder.setContentTitle("title");
    mBuilder.setPriority(Notification.PRIORITY_MAX);
    mBuilder.setContent(bigContentView);

    Notification n = mBuilder.build();

    n.contentView = smallContentView;
    n.bigContentView = bigContentView;

    Intent intentClose = new Intent(ACTION_CLOSE);
    PendingIntent pintentClose = PendingIntent.getBroadcast(this.service, 0, intentClose, 0);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivclose, pintentClose);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivclose, pintentClose);

    Intent intentBack = new Intent(ACTION_BACK);
    PendingIntent pintentBack = PendingIntent.getBroadcast(this.service, 0, intentBack, 0);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivback, pintentBack);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivback, pintentBack);

    Intent intentPlay = new Intent(ACTION_PLAY);
    PendingIntent pintentPlay = PendingIntent.getBroadcast(this.service, 0, intentPlay, 0);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivplay, pintentPlay);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivplay, pintentPlay);

    Intent intentPause = new Intent(ACTION_PAUSE);
    PendingIntent pintentPause = PendingIntent.getBroadcast(this.service, 0, intentPause, 0);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivpause, pintentPause);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivpause, pintentPause);

    Intent intentNext = new Intent(ACTION_NEXT);
    PendingIntent pintentNext = PendingIntent.getBroadcast(this.service, 0, intentNext, 0);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivnext, pintentNext);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivnext, pintentNext);

    Intent intentAlbum = new Intent(ACTION_ALBUM);
    PendingIntent pintentAlbum = PendingIntent.getBroadcast(this.service, 0, intentAlbum,
            PendingIntent.FLAG_CANCEL_CURRENT);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_ivcurrent_cover, pintentAlbum);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_author, pintentAlbum);
    bigContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_song, pintentAlbum);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_ivcurrent_cover, pintentAlbum);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_author, pintentAlbum);
    smallContentView.setOnClickPendingIntent(R.id.bignotification_tvcurrent_song, pintentAlbum);

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

From source file:org.exobel.routerkeygen.AutoConnectService.java

private Notification createProgressBar(CharSequence title, CharSequence content, int progress) {
    final NotificationCompat.Builder builder = getSimple(title, content);
    final PendingIntent i = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(this, CancelOperationActivity.class)
                    .putExtra(CancelOperationActivity.SERVICE_TO_TERMINATE, AutoConnectService.class.getName())
                    .putExtra(CancelOperationActivity.MESSAGE, getString(R.string.cancel_auto_test)),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(i);// w  w w  . j av a 2 s.c  o m
    builder.setOngoing(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setProgress(keys.size(), progress, false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(android.R.string.cancel),
                    i);
        }
    } else {
        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
        contentView.setTextViewText(R.id.text1, content);
        contentView.setProgressBar(R.id.progress, keys.size(), progress, false);
        final Notification not = builder.build();
        not.contentView = contentView;
        return not;
    }
    return builder.build();
}

From source file:com.oasisfeng.nevo.decorators.bundle.BundleDecorator.java

/** Preview the last a few notifications vertically as expanded view of bundle notification. */
private RemoteViews buildExpandedView(final List<StatusBarNotificationEvo> sbns) {
    if (sbns.isEmpty())
        return null;
    final RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.bundle_expanded_notification);

    // Since Lollipop, "reapply()" is used with remote views onto the current one when updating notification.
    // We must clear the view group before adding new content.
    expanded.removeAllViews(R.id.bundle_expanded_container);

    for (final StatusBarNotificationEvo sbn : sbns)
        try {//  w w  w.  ja  v  a2 s  . co  m
            expanded.addView(R.id.bundle_expanded_container, sbn.notification().getContentView());
        } catch (final RemoteException ignored) {
        } // Should not happen
    return expanded;
}

From source file:eu.power_switch.widget.activity.ConfigureReceiverWidgetActivity.java

private void saveCurrentConfiguration() {
    try {//from   w  w w .  j  a v  a 2 s .c  o m
        // First, get the App Widget ID from the Intent that launched the Activity:
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null && extras.containsKey(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            // Perform your App Widget configuration:
            Apartment selectedApartment = getSelectedApartment();
            Room selectedRoom = selectedApartment.getRoom(spinnerRoom.getSelectedItem().toString());
            Receiver selectedReceiver = selectedRoom.getReceiver(spinnerReceiver.getSelectedItem().toString());

            // save new widget data to database
            ReceiverWidget receiverWidget = new ReceiverWidget(appWidgetId, selectedRoom.getId(),
                    selectedReceiver.getId());
            DatabaseHandler.addReceiverWidget(receiverWidget);
            // When the configuration is complete, get an instance of
            // the AppWidgetManager by calling getInstance(Context):
            AppWidgetManager appWidgetManager = AppWidgetManager
                    .getInstance(ConfigureReceiverWidgetActivity.this);
            // Update the App Widget with a RemoteViews layout by
            // calling updateAppWidget(int, RemoteViews):
            RemoteViews remoteViews = new RemoteViews(getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                    R.layout.widget_receiver);

            LinkedList<Button> buttons = selectedReceiver.getButtons();

            remoteViews.setTextViewText(R.id.textView_receiver_widget_name, selectedApartment.getName() + ": "
                    + selectedRoom.getName() + ": " + selectedReceiver.getName());

            int buttonOffset = 0;
            for (Button button : buttons) {
                // set button action
                RemoteViews buttonView = new RemoteViews(
                        getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                        R.layout.widget_receiver_button_layout);
                SpannableString s = new SpannableString(button.getName());
                s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0);
                buttonView.setTextViewText(R.id.button_widget_universal, s);

                if (SmartphonePreferencesHandler.getHighlightLastActivatedButton()
                        && selectedReceiver.getLastActivatedButtonId().equals(button.getId())) {
                    buttonView.setTextColor(R.id.button_widget_universal,
                            ContextCompat.getColor(getApplicationContext(), R.color.color_light_blue_a700));
                }

                PendingIntent pendingIntent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent(
                        getApplicationContext(), selectedApartment, selectedRoom, selectedReceiver, button,
                        appWidgetId * 15 + buttonOffset);

                buttonView.setOnClickPendingIntent(R.id.button_widget_universal, pendingIntent);

                remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView);
                buttonOffset++;
            }

            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

            // Finally, create the return Intent, set it with the
            // Activity result, and finish the Activity:
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            setResult(RESULT_OK, resultValue);
            finish();
        }
    } catch (Exception e) {
        StatusMessageHandler.showErrorMessage(this, e);
    }
}

From source file:de.hackerspacebremen.fragments.StatusFragment.java

private void updateAppWidget(SpaceData data) {
    SharedPreferences dataPersistence = getActivity().getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();/*  www.  ja v  a  2 s .  c  o m*/

    RemoteViews remoteViews = new RemoteViews(getActivity().getPackageName(), R.layout.appwidget);
    remoteViews.setViewVisibility(R.id.indicatorImage, View.VISIBLE);
    remoteViews.setViewVisibility(R.id.errorText, View.GONE);

    if (data.isSpaceOpen()) {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner);
    } else {
        remoteViews.setImageViewResource(R.id.indicatorImage, R.drawable.banner_blur);
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
    ComponentName componentName = new ComponentName(getActivity(), HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}