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:org.openbitcoinwidget.WidgetProvider.java

private static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    WidgetPreferences preferences = PreferencesActivity.getWidgetPreferences(context, appWidgetId);

    if (preferences == null) {
        // Don't do anything unless the rate service has been chosen.
        // Show a "please remove this widget and add a new one"
        appWidgetManager.updateAppWidget(appWidgetId,
                new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me));
        return;/*  ww w .  ja v  a  2  s .c o m*/
    }

    boolean isOnLockScreen = isWidgetShownOnLockScreen(appWidgetManager, appWidgetId);

    RemoteViews views;
    if (isOnLockScreen) {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_lock_screen);
    } else {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
    }

    Intent clickIntent = new Intent(context, GraphPopupActivity.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call
    // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE
    //      cached intent will be used for all widget instances!
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent);
    views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName());

    DataOpenHelper dbHelper = new DataOpenHelper(context);
    TickerData prevData = dbHelper.getLastTickerData(preferences);

    TickerData newData;
    String latestQuote = getLatestQuote(preferences);
    if (latestQuote != null && !latestQuote.equals("")) {
        newData = preferences.getRateService().parseJSON(latestQuote);
        newData.setCurrencyConversion(preferences.getCurrencyConversion());
        storeLastValueIfNotNull(dbHelper, newData);
        updateViews(views, prevData, newData, preferences);
    } else if (prevData != null) {
        newData = prevData;
        updateViews(views, prevData, newData, preferences);
    } else {
        updateViewsWithError(views, preferences);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:info.bits.phoneastablet.utils.NotificationHandler.java

/**
 * Shows the notification at the notification area.
 *///  ww  w  .j a  v  a2  s.  c  o  m
public void enableNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setTicker(context.getResources().getString(R.string.notification_ticker)).setAutoCancel(false)
            .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.notification_private_text))
            .setSmallIcon(R.drawable.ic_launcher);
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    //set the button listeners
    setListeners(contentView);
    notification.contentView = contentView;
    nm.notify(NOTIFICATION_ID, notification);

}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//from ww w.j a va  2s . c  o  m
 */
private static void updateWidget(Context context, int appWidgetId) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    //        }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
        throws JSONException {

    Log.i(TAG_SERVICE, "start    updateAppWidget" + "  appWidgetId = "
            + String.valueOf(appWidgetId));

    String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId));
    CityModel mCityModel = new CityModel(nameCity);

    //   ? //from  ww  w .  j  ava2  s .c  om
    mCityModel = GetWeatherCityService.restoreCityInfoFromFile(context, mCityModel);
    Log.i(TAG_SERVICE, "updateAppWidget  ->  ??   " + mCityModel.getName()
            + " -> " + mCityModel.getTemp());

    if (!nameCity.trim().equals("")) {
        Log.i(TAG_SERVICE, "   updateAppWidget - >: " + nameCity
                + "  appWidgetId = " + String.valueOf(appWidgetId));
        //    ? CLICK_WIDGET_BUTTON      onReceive
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget);
        // Intent ? Broadcast
        Intent active = new Intent(context, AnWeatherWidget.class);
        active.setAction(CLICK_WIDGET_BUTTON);
        //?  ?
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
        //?  ?
        remoteViews.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent);
        //? 
        remoteViews.setTextViewText(R.id.cityNameText, mCityModel.getName());
        remoteViews.setTextViewText(R.id.tempCityText, mCityModel.getTemp() + "C");
        remoteViews.setTextViewText(R.id.windText, Utils.windGradus2Rumb(mCityModel.getWinddirection()) + " ("
                + Float.toString(mCityModel.getWindspeed()) + " /?)");
        remoteViews.setTextViewText(R.id.timeRefreshText, mCityModel.getTimeRefresh());
        remoteViews.setTextViewText(R.id.descriptionWeatherText, mCityModel.getWeather("description"));
        remoteViews.setImageViewUri(R.id.weatherImageView,
                Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather"
                        + mCityModel.getWeather("icon")));

        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        // END -    ? CLICK_WIDGET_BUTTON      onReceive

        startGetWeatherCityService(context, appWidgetId, mCityModel);

    } else {
        Log.i(TAG_SERVICE, "   updateAppWidget - > ? "
                + "  appWidgetId = " + String.valueOf(appWidgetId));
    }
}

From source file:github.daneren2005.dsub.util.Notifications.java

public static void showPlayingNotification(final Context context, final DownloadService downloadService,
        final Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());

    final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (playing) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }/*ww w .  j a  v  a 2s  . com*/
    boolean remote = downloadService.isRemoteEnabled();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, true, playing, remote);
        notification.bigContentView = expandedContentView;
        notification.priority = Notification.PRIORITY_HIGH;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, false, playing, remote);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
    notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    playShowing = true;
    if (downloadForeground && downloadShowing) {
        downloadForeground = false;
        handler.post(new Runnable() {
            @Override
            public void run() {
                downloadService.stopForeground(true);
                showDownloadingNotification(context, downloadService, handler,
                        downloadService.getCurrentDownloading(),
                        downloadService.getBackgroundDownloads().size());
                downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                if (playing) {
                    downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
                } else {
                    playShowing = false;
                    persistentPlayingShowing = true;
                    NotificationManager notificationManager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    downloadService.stopForeground(false);
                    notificationManager.notify(NOTIFICATION_ID_PLAYING, notification);
                }
            }
        });
    }

    // Update widget
    DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}

From source file:org.aankor.animenforadio.RadioNotification.java

void init() {
    views = new RemoteViews(context.getPackageName(), R.layout.radio_notification);
    // default action
    views.setOnClickPendingIntent(R.id.playStopButton,
            PendingIntent.getBroadcast(context, 0, new Intent(AnfoService.KEY_STOP), 0));
}

From source file:com.cerema.cloud2.notifications.NotificationBuilderWithProgressBar.java

/**
 * Constructor./*  ww w. ja  va2s.  c  o m*/
 * 
 * @param context       Context that will use the builder to create notifications.
 */
private NotificationBuilderWithProgressBar(Context context) {
    super(context);
    mContentView = new RemoteViews(context.getPackageName(), R.layout.notification_with_progress_bar);
    setContent(mContentView);
}

From source file:com.teclib.service.NotificationRemoveService.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, RemoveApplicationActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.removeAsk_string))
            .setOngoing(true).setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.removeAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(3, builder.build());
}

From source file:org.kontalk.ui.ProgressNotificationBuilder.java

/**
 * Updates the notification progress bar.
 * @param progress if less than 0, progress bar will be indeterminate
 *///w  ww  .  j a  v  a  2 s .c o m
public ProgressNotificationBuilder progress(int progress, int contentTitle, int contentText) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        this.setSmallIcon(R.drawable.ic_stat_notify).setContentTitle(mContext.getString(contentTitle))
                .setContentText(mContext.getString(contentText));

        if (progress < 0)
            setProgress(0, 0, true);
        else
            setProgress(100, progress, false);

        // not using custom content view
        mContentView = null;
    } else {
        mContentView = new RemoteViews(mContext.getPackageName(), mLayout);
        // this should not be needed -- contentView.setOnClickPendingIntent(R.id.progress_notification, null);
        mContentView.setTextViewText(R.id.title, mContext.getString(contentText));
        mContentView.setTextViewText(R.id.progress_text,
                (progress < 0) ? "" : String.format(Locale.US, "%d%%", progress));

        if (progress < 0)
            mContentView.setProgressBar(R.id.progress_bar, 0, 0, true);
        else
            mContentView.setProgressBar(R.id.progress_bar, 100, progress, false);

        setContent(mContentView);
    }

    return this;
}

From source file:com.guayaba.tapir.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *///from  w ww  .j  ava2 s  . co  m
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt, final boolean isPlaying) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    // Notification Builder
    mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
            .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
            .setContent(mNotificationTemplate).build();
    // Control playback from the notification
    initPlaybackActions(isPlaying);
    if (ApolloUtils.hasJellyBean()) {
        // Expanded notifiction style
        mExpandedView = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_expanded_base);
        mNotification.bigContentView = mExpandedView;
        // Control playback from the notification
        initExpandedPlaybackActions(isPlaying);
        // Set up the expanded content view
        initExpandedLayout(trackName, albumName, artistName, albumArt);
    }
    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}