Example usage for android.widget RemoteViews setViewVisibility

List of usage examples for android.widget RemoteViews setViewVisibility

Introduction

In this page you can find the example usage for android.widget RemoteViews setViewVisibility.

Prototype

public void setViewVisibility(int viewId, int visibility) 

Source Link

Document

Equivalent to calling View#setVisibility(int)

Usage

From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java

/**
 * Initialize given widgets to default state, where we launch ServeStream on default click
 * and hide actions if service not running.
 *//*w  w  w .  jav  a 2 s  .c o  m*/
private void defaultAppWidget(Context context, int[] appWidgetIds) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_one);

    views.setViewVisibility(R.id.title, View.INVISIBLE);
    views.setViewVisibility(R.id.artist, View.INVISIBLE);

    linkButtons(context, views, false /* not playing */);
    pushUpdate(context, appWidgetIds, views);
}

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

private static <T extends NotificationCompatBase.Action> RemoteViews generateContentView(Context context,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number,
        Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions,
        int[] actionsToShowInCompact, boolean showCancelButton, PendingIntent cancelButtonIntent) {
    RemoteViews view = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon,
            subText, useChronometer, when, R.layout.notification_template_media, true /* fitIn1U */);

    final int numActions = actions.size();
    final int N = actionsToShowInCompact == null ? 0
            : Math.min(actionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT);
    view.removeAllViews(R.id.media_actions);
    if (N > 0) {
        for (int i = 0; i < N; i++) {
            if (i >= numActions) {
                throw new IllegalArgumentException(String.format(
                        "setShowActionsInCompactView: action %d out of bounds (max %d)", i, numActions - 1));
            }//w  w  w.  j a  va2s .c o m

            final NotificationCompatBase.Action action = actions.get(actionsToShowInCompact[i]);
            final RemoteViews button = generateMediaActionButton(context, action);
            view.addView(R.id.media_actions, button);
        }
    }
    if (showCancelButton) {
        view.setViewVisibility(R.id.end_padder, View.GONE);
        view.setViewVisibility(R.id.cancel_action, View.VISIBLE);
        view.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
        view.setInt(R.id.cancel_action, "setAlpha",
                context.getResources().getInteger(R.integer.cancel_button_image_alpha));
    } else {
        view.setViewVisibility(R.id.end_padder, View.VISIBLE);
        view.setViewVisibility(R.id.cancel_action, View.GONE);
    }
    return view;
}

From source file:com.google.android.vending.expansion.downloader.impl.V4CustomNotificationBuilder.java

@Override
public Notification build() {
    if (android.os.Build.VERSION.SDK_INT > 10) {
        // only matters for Honeycomb
        setOnlyAlertOnce(true);/*from  w  ww  . j a va  2  s .  co  m*/
    }

    // Build the RemoteView object
    RemoteViews expandedView = new RemoteViews(mContext.getPackageName(),
            R.layout.status_bar_ongoing_event_progress_bar);

    expandedView.setTextViewText(R.id.title, mContentTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(this.mCurrentBytes, mTotalBytes));
    expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
    expandedView.setProgressBar(R.id.progress_bar, (int) (mTotalBytes >> 8), (int) (mCurrentBytes >> 8),
            mTotalBytes <= 0);
    expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
    expandedView.setTextViewText(R.id.time_remaining, mContentInfo);
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);

    Notification n = super.build();
    n.contentView = expandedView;
    return n;
}

From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java

/**
 * Updates button to start/stop recording.
 * /*  w  w w  . ja va  2s  . c  om*/
 * @param remoteViews the remote views
 * @param action the action
 */
private void updateButton(RemoteViews remoteViews, String action) {
    boolean isRecording = trackStartedBroadcastAction.equals(action);
    remoteViews.setViewVisibility(R.id.track_widget_record_button, isRecording ? View.GONE : View.VISIBLE);
    remoteViews.setViewVisibility(R.id.track_widget_stop_button, isRecording ? View.VISIBLE : View.INVISIBLE);
    Intent intent = new Intent(context, ControlRecordingService.class).setAction(
            context.getString(isRecording ? R.string.track_action_end : R.string.track_action_start));
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(
            isRecording ? R.id.track_widget_stop_button : R.id.track_widget_record_button, pendingIntent);
}

From source file:ch.fixme.status.Widget.java

protected static void updateWidget(final Context ctxt, int widgetId, AppWidgetManager manager, Bitmap bitmap,
        String text) {/*from  w w  w  .j  a  va  2s.  co m*/
    RemoteViews views = new RemoteViews(ctxt.getPackageName(), R.layout.widget);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    Editor edit = prefs.edit();
    if (prefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)) {
        views.setInt(R.id.widget_image, "setBackgroundResource", 0);
    } else {
        views.setInt(R.id.widget_image, "setBackgroundResource", android.R.drawable.btn_default_small);
    }
    if (bitmap != null) {
        views.setImageViewBitmap(R.id.widget_image, bitmap);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, false); // Don't
        // need
        // to
        // force
    } else {
        views.setImageViewResource(R.id.widget_image, android.R.drawable.ic_popup_sync);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, true); // Something
        // went
        // wrong
    }
    if (text != null) {
        views.setTextViewText(R.id.widget_status, text);
        views.setViewVisibility(R.id.widget_status, View.VISIBLE);
    } else {
        views.setViewVisibility(R.id.widget_status, View.GONE);
    }
    Intent clickIntent = new Intent(ctxt, Main.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, widgetId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_image, pendingIntent);
    manager.updateAppWidget(widgetId, views);
    // Is initialized
    edit.putBoolean(Main.PREF_INIT_WIDGET + widgetId, true);
    edit.commit();
}

From source file:de.hackerspacebremen.push.PushIntentService.java

private void updateAppWidget(Context context, SpaceData data) {
    SharedPreferences dataPersistence = getSharedPreferences(Constants.SPACE_DATA_PERSISTENCE,
            Context.MODE_PRIVATE);
    Editor editor = dataPersistence.edit();
    editor.putBoolean(Constants.SPACE_OPEN_DATA_KEY, data.isSpaceOpen());
    editor.commit();//from  w ww  .  ja  va 2  s .  c o m

    RemoteViews remoteViews = new RemoteViews(context.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(context);
    ComponentName componentName = new ComponentName(context, HackerspaceWidgetProvider.class);
    appWidgetManager.updateAppWidget(componentName, remoteViews);
}

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();/*from  www.  j  a va  2s. 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);
}

From source file:com.chainsaw.clearweather.OpenWeatherAPI.java

public OpenWeatherAPI(final Context context, final int widgetId) {
    final RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    final AppWidgetManager manager = AppWidgetManager.getInstance(context);

    asyncLoader = new BackgroundFetch(context) {
        @Override/*  w ww. j  a  v  a2 s.  co  m*/
        protected void onPostExecute(WeatherData result) {
            remote.setViewVisibility(R.id.loading, View.INVISIBLE);
            if (OpenWeatherAPI.this.listener != null)
                OpenWeatherAPI.this.listener.onDataReady(result);

        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            remote.setViewVisibility(R.id.temp, View.INVISIBLE);
            remote.setViewVisibility(R.id.tempUnit, View.INVISIBLE);
            remote.setViewVisibility(R.id.humidity, View.INVISIBLE);
            remote.setViewVisibility(R.id.humidityUnit, View.INVISIBLE);
            remote.setViewVisibility(R.id.location, View.INVISIBLE);
            remote.setViewVisibility(R.id.weather, View.INVISIBLE);
            remote.setViewVisibility(R.id.timestamp, View.INVISIBLE);
            remote.setViewVisibility(R.id.loading, View.VISIBLE);
            remote.setProgressBar(R.id.loading, 10, 5, true);
            manager.updateAppWidget(widgetId, remote);

            super.onProgressUpdate(values);

        }
    };
}

From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java

/**
 * Update the collapsed notification view for a "buffering" play state.
 *
 * @param resultView The notification view to edit.
 * @param trackTitle The current track title.
 *//*ww  w . ja v  a 2  s .com*/
private void updateBufferingContent(final RemoteViews resultView, final CharSequence trackTitle) {
    resultView.setViewVisibility(R.id.notificationClose, View.GONE);
    resultView.setTextViewText(R.id.notificationTitle, mServiceContext.getString(R.string.buffering));
    resultView.setTextViewText(R.id.notificationArtist, trackTitle);
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Sets a widget item.//  w ww. j  av a 2s.c  o  m
 * 
 * @param context the context
 * @param remoteViews the remote view
 * @param ids the item's ids
 * @param value the item value
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 * @param reportSpeed try to report speed
 */
private static void setItem(Context context, RemoteViews remoteViews, int[] ids, int value,
        TripStatistics tripStatistics, boolean isRecording, boolean isPaused, boolean metricUnits,
        boolean reportSpeed) {
    switch (value) {
    case 0:
        updateDistance(context, remoteViews, ids, tripStatistics, metricUnits);
        break;
    case 1:
        updateTotalTime(context, remoteViews, ids, tripStatistics, isRecording, isPaused);
        break;
    case 2:
        updateAverageSpeed(context, remoteViews, ids, tripStatistics, metricUnits, reportSpeed);
        break;
    case 3:
        updateMovingTime(context, remoteViews, ids, tripStatistics);
        break;
    case 4:
        updateAverageMovingSpeed(context, remoteViews, ids, tripStatistics, metricUnits, reportSpeed);
        break;
    default:
        updateDistance(context, remoteViews, ids, tripStatistics, metricUnits);
        break;

    }
    if (value != 1) {
        remoteViews.setViewVisibility(ids[1], View.VISIBLE);
        remoteViews.setViewVisibility(ids[2], View.VISIBLE);
        remoteViews.setViewVisibility(ids[3], View.GONE);
        remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime(), null, false);
    }
}