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:Main.java

/**
 * @param packageName//  w w w .ja va  2  s  .com
 * @param layoutId
 * @return {@link RemoteViews}
 */
public static RemoteViews createRemoteViews(final String packageName, final int layoutId) {
    return new RemoteViews(packageName, layoutId);
}

From source file:HomescreenWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for (int count = 0; count < appWidgetIds.length; count++) {
        RemoteViews appWidgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget);
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        appWidgetLayout.setOnClickPendingIntent(R.id.analogClock, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds[count], appWidgetLayout);
    }/*  w w w.  ja va 2 s  . co m*/
}

From source file:dev.datvt.cloudtracks.noti_service.NotificationUtil.java

public NotificationUtil(Context context) {
    this.context = context;
    bigViews = new RemoteViews(context.getPackageName(), R.layout.noti_layout);
    remoteViews1 = new RemoteViews(context.getPackageName(), R.layout.noti_small_layout);
}

From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    title = "";// www  . j  a v  a2 s  .  c o m
    altText = "";
    image = null;

    updateComicInfo();

    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget_layout);
        updateRemoteViews(context, views);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:cat.mvmike.minimalcalendarwidget.service.DayService.java

public static void setDays(final Context context, final Calendar cal, final SpannableString ss,
        final RemoteViews remoteViews) {

    int firstDayOfWeek = ConfigurationService.getStartWeekDay(context);
    Theme theme = ConfigurationService.getTheme(context);
    CalendarStatus cs = new CalendarStatus(context, cal, firstDayOfWeek);

    Set<InstanceDto> instanceSet = PermissionsActivity.isPermitted(context)
            ? CalendarResolver.readAllInstances(context.getContentResolver(), cal)
            : new HashSet<>();

    RemoteViews rowRv;/*w w w  . java 2 s.  c o m*/
    for (int week = 0; week < NUM_WEEKS; week++) {

        rowRv = new RemoteViews(context.getPackageName(), R.layout.row_week);

        DayStatus ds;
        for (int day = 0; day < Calendar.DAY_OF_WEEK; day++) {

            ds = new DayStatus(cal, cs.getTodayYear(), cs.getThisMonth(), cs.getToday());
            RemoteViews cellRv = new RemoteViews(context.getPackageName(), getDayLayout(theme, ds));

            int numberOfInstances = getNumberOfInstances(instanceSet, ds);
            setInstanceNumber(context, cellRv, Integer.toString(ds.getDayOfMonth()), ds.isToday(),
                    numberOfInstances);
            checkMonthBeginningStyleChange(cs.getCalendar(), cellRv, ss);

            cs.getCalendar().add(Calendar.DAY_OF_MONTH, 1);

            rowRv.addView(R.id.row_container, cellRv);
        }

        remoteViews.addView(R.id.calendar_widget, rowRv);
    }
}

From source file:net.sarangnamu.common.notification.NotificationBase.java

protected void init(Context context) {
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    remoteView = new RemoteViews(context.getPackageName(), getRemoteId());

    initLayout();//www .j  a v a 2  s. c o m

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    if (getSmallIcon() != 0) {
        builder.setSmallIcon(getSmallIcon());
    }

    builder.setAutoCancel(isAutoCancel());
    builder.setOngoing(isOngoing());
    builder.setContent(remoteView);

    if (getPendingIntent() != null) {
        builder.setContentIntent(getPendingIntent());
    }

    // TODO id  ? ? . ? ? ?   .
    //
    nm.notify(0, builder.build());
}

From source file:com.rks.musicx.services.NotificationHandler.java

public static void buildNotification(MusicXService musicXService, String what) {
    if (musicXService == null) {
        return;/* w  ww. j av  a 2 s.  c o  m*/
    }
    RemoteViews remoteViews = new RemoteViews(musicXService.getPackageName(), R.layout.widget);
    RemoteViews smallremoteView = new RemoteViews(musicXService.getPackageName(), R.layout.small_notification);

    Intent intent = new Intent(musicXService, PlayingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendInt = PendingIntent.getActivity(musicXService, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            musicXService).setWhen(System.currentTimeMillis()).setCategory(Intent.CATEGORY_APP_MUSIC)
                    .setPriority(Notification.PRIORITY_DEFAULT).setShowWhen(false).setAutoCancel(true)
                    .setCustomBigContentView(remoteViews).setContent(smallremoteView)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    remoteViews.setOnClickPendingIntent(R.id.item_view, pendInt);
    smallremoteView.setOnClickPendingIntent(R.id.small_item_view, pendInt);
    remoteViews.setTextViewText(R.id.title, musicXService.getsongTitle());
    remoteViews.setTextViewText(R.id.artist, musicXService.getsongArtistName());
    smallremoteView.setTextViewText(R.id.small_title, musicXService.getsongTitle());
    smallremoteView.setTextViewText(R.id.small_artist, musicXService.getsongArtistName());
    FavHelper favHelper = new FavHelper(musicXService);
    if (favHelper.isFavorite(musicXService.getsongId())) {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite);
    } else {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite_outline);
    }
    if (musicXService.isPlaying()) {
        builder.setSmallIcon(R.drawable.aw_ic_play);
        builder.setOngoing(true);
    } else {
        builder.setSmallIcon(R.drawable.aw_ic_pause);
        builder.setOngoing(false);
    }
    if (what.equals(PLAYSTATE_CHANGED)) {
        if (MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying()) {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_play);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_play);
        } else {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_pause);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_pause);
        }
    }
    handler.post(new Runnable() {
        @Override
        public void run() {
            ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(),
                    musicXService.getsongAlbumID(), new palette() {
                        @Override
                        public void palettework(Palette palette) {
                            int colors[] = Helper.getAvailableColor(musicXService, palette);
                            remoteViews.setInt(R.id.item_view, "setBackgroundColor", colors[0]);
                            remoteViews.setInt(R.id.title, "setTextColor", Color.WHITE);
                            remoteViews.setInt(R.id.artist, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_item_view, "setBackgroundColor", colors[0]);
                            smallremoteView.setInt(R.id.small_title, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_artist, "setTextColor", Color.WHITE);
                        }
                    }, new bitmap() {
                        @Override
                        public void bitmapwork(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }

                        @Override
                        public void bitmapfailed(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }
                    });
        }
    });
    controls(remoteViews, smallremoteView, musicXService);
}

From source file:com.udacity.stockhawk.ui.widget.StockWidget.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int widgetId : appWidgetIds) {

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_stock);

        Intent clickIntentTemplate = new Intent(context, StockChart.class);

        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        remoteViews.setPendingIntentTemplate(R.id.lv_widget_stock, clickPendingIntentTemplate);

        // Set the collection and update the widget
        setRemoteAdapter(context, remoteViews);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

    }//from  w  w  w.ja v  a  2  s  .  c  om

    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

From source file:com.example.olivi.maphap.widget.DetailWidgetProvider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    //Start up DetailWidgetIntentService to query for regions data and see when it was last
    // updated. If the data is too old, the service will update it using MapHapService.
    Intent i = new Intent(context, DetailWidgetIntentService.class);
    context.startService(i);//w ww  .  j  a va2  s . c o m

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail);

        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget_detail, pendingIntent);

        // Set up the collection
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, views);
        } else {
            setRemoteAdapterV11(context, views);
        }

        Intent clickIntentTemplate = new Intent(context, DetailActivity.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        views.setEmptyView(R.id.widget_list, R.id.widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app com.example
        // .olivi.maphap.widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:com.calendaridex.widget.WidgetViewsFactory.java

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(ctxt.getPackageName(), R.layout.widget_list_item);

    Event event = items.get(position);
    row.setTextViewText(R.id.text1, event.getTitle());
    if (event.getAdminEvent()) {
        row.setTextColor(R.id.text1, ContextCompat.getColor(ctxt, R.color.colorPrimaryDark));
    } else {/*from   w w w. j a va 2 s . c  om*/
        row.setTextColor(R.id.text1, ContextCompat.getColor(ctxt, android.R.color.holo_green_dark));

    }

    //        Intent i=new Intent();
    //        Bundle extras=new Bundle();
    //
    //        extras.putString(CalendarWidget.EXTRA_WORD, event.getTitle());
    //        i.putExtras(extras);
    //        row.setOnClickFillInIntent(android.R.id.text1, i);

    return row;
}