Java Code Examples for android.widget.RemoteViews#setViewVisibility()

The following examples show how to use android.widget.RemoteViews#setViewVisibility() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomNotificationBuilder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the work profile badge if it is needed.
 */
private void addWorkProfileBadge(RemoteViews view) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
    int[] colors = new int[size * size];

    // Create an immutable bitmap, so that it can not be reused for painting a badge into it.
    Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);

    Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
    Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
            mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);

    // The input bitmap is immutable, so the output drawable will be a different instance from
    // the input drawable if the work profile badge was applied.
    if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
        view.setImageViewBitmap(
                R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
        view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
    }
}
 
Example 2
Source File: SunPosLayout_1X1_0.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateViews(Context context, int appWidgetId, RemoteViews views, SuntimesRiseSetDataset dataset)
{
    super.updateViews(context, appWidgetId, views, dataset);
    SuntimesCalculator calculator = dataset.calculator();
    SuntimesCalculator.SunPosition sunPosition = (calculator != null ? calculator.getSunPosition(dataset.now()) : null);

    SuntimesRiseSetData noonData = dataset.dataNoon;
    Calendar noonTime = (noonData != null ? noonData.sunriseCalendarToday() : null);
    SuntimesCalculator.SunPosition noonPosition = (noonTime != null && calculator != null ? calculator.getSunPosition(noonTime) : null);

    updateViewsAzimuthElevationText(context, views, sunPosition, noonPosition);

    boolean showLabels = WidgetSettings.loadShowLabelsPref(context, appWidgetId);
    int visibility = (showLabels ? View.VISIBLE : View.GONE);
    views.setViewVisibility(R.id.info_sun_azimuth_current_label, visibility);
    views.setViewVisibility(R.id.info_sun_elevation_current_label, visibility);
}
 
Example 3
Source File: UrlDeviceDiscoveryService.java    From physical-web with Apache License 2.0 6 votes vote down vote up
private void updateSummaryNotificationRemoteViewsSecondBeacon(PwPair pwPair,
                                                              RemoteViews remoteViews) {
  PwsResult pwsResult = pwPair.getPwsResult();
  remoteViews.setImageViewBitmap(
      R.id.icon_secondBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult));
  remoteViews.setTextViewText(R.id.title_secondBeacon, pwsResult.getTitle());
  remoteViews.setTextViewText(R.id.url_secondBeacon, pwsResult.getSiteUrl());
  remoteViews.setTextViewText(R.id.description_secondBeacon, pwsResult.getDescription());
  // Recolor notifications to have light text for non-Lollipop devices
  if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
    remoteViews.setTextColor(R.id.title_secondBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR);
    remoteViews.setTextColor(R.id.url_secondBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR);
    remoteViews.setTextColor(R.id.description_secondBeacon,
                             NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR);
  }

  // Create an intent that will open the browser to the beacon's url
  // if the user taps the notification
  remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout,
      Utils.createNavigateToUrlPendingIntent(pwsResult, this));
  remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE);
}
 
Example 4
Source File: UrlDeviceDiscoveryService.java    From physical-web with Apache License 2.0 6 votes vote down vote up
private void updateSummaryNotificationRemoteViewsFirstBeacon(PwPair pwPair,
                                                             RemoteViews remoteViews) {
  PwsResult pwsResult = pwPair.getPwsResult();
  remoteViews.setImageViewBitmap(
      R.id.icon_firstBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult));
  remoteViews.setTextViewText(R.id.title_firstBeacon, pwsResult.getTitle());
  remoteViews.setTextViewText(R.id.url_firstBeacon, pwsResult.getSiteUrl());
  remoteViews.setTextViewText(R.id.description_firstBeacon, pwsResult.getDescription());
  // Recolor notifications to have light text for non-Lollipop devices
  if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
    remoteViews.setTextColor(R.id.title_firstBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR);
    remoteViews.setTextColor(R.id.url_firstBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR);
    remoteViews.setTextColor(R.id.description_firstBeacon,
                             NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR);
  }

  // Create an intent that will open the browser to the beacon's url
  // if the user taps the notification
  remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout,
      Utils.createNavigateToUrlPendingIntent(pwsResult, this));
  remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE);
}
 
Example 5
Source File: MoonLayout_2x1_0.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateViews(Context context, int appWidgetId, RemoteViews views, SuntimesMoonData data)
{
    super.updateViews(context, appWidgetId, views, data);
    boolean showLabels = WidgetSettings.loadShowLabelsPref(context, appWidgetId);
    boolean showSeconds = WidgetSettings.loadShowSecondsPref(context, appWidgetId);
    updateViewsMoonRiseSetText(context, views, data, showSeconds, order);

    NumberFormat percentage = NumberFormat.getPercentInstance();
    String illum = percentage.format(data.getMoonIlluminationToday());
    String illumNote = context.getString(R.string.moon_illumination, illum);
    SpannableString illumNoteSpan = (boldTime ? SuntimesUtils.createBoldColorSpan(null, illumNote, illum, illumColor) : SuntimesUtils.createColorSpan(null, illumNote, illum, illumColor));
    views.setTextViewText(R.id.text_info_moonillum, illumNoteSpan);

    for (MoonPhaseDisplay moonPhase : MoonPhaseDisplay.values())
    {
        views.setViewVisibility(moonPhase.getView(), View.GONE);
    }

    MoonPhaseDisplay phase = data.getMoonPhaseToday();
    if (phase != null)
    {
        if (phase == MoonPhaseDisplay.FULL || phase == MoonPhaseDisplay.NEW) {
            SuntimesCalculator.MoonPhase majorPhase = (phase == MoonPhaseDisplay.FULL ? SuntimesCalculator.MoonPhase.FULL : SuntimesCalculator.MoonPhase.NEW);
            views.setTextViewText(R.id.text_info_moonphase, data.getMoonPhaseLabel(context, majorPhase));
        } else views.setTextViewText(R.id.text_info_moonphase, phase.getLongDisplayString());

        views.setViewVisibility(R.id.text_info_moonphase, (showLabels ? View.VISIBLE : View.GONE));
        views.setViewVisibility(phase.getView(), View.VISIBLE);

        Integer phaseColor = phaseColors.get(phase);
        if (phaseColor != null)
        {
            views.setTextColor(R.id.text_info_moonphase, phaseColor);
        }
    }
}
 
Example 6
Source File: AppWidgetSmall.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_small);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 7
Source File: AppWidgetClassic.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
private void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
    appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));
    appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 8
Source File: WidgetView.java    From ministocks with MIT License 5 votes vote down vote up
private void hideUnusedRows(RemoteViews views, int count) {
    for (int i = 0; i < 11; i++) {
        int viewId = ReflectionTools.getField("line" + i);
        if (viewId > 0) {
            views.setViewVisibility(ReflectionTools.getField("line" + i), View.GONE);
        }
    }
    for (int i = 1; i < count + 1; i++) {
        views.setViewVisibility(ReflectionTools.getField("line" + i), View.VISIBLE);
    }
}
 
Example 9
Source File: TrackWidgetProvider.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a widget item.
 * 
 * @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);
  }
}
 
Example 10
Source File: OverclockingWidgetView.java    From rpicheck with MIT License 5 votes vote down vote up
public static void startRefreshing(RemoteViews views, Context context, int appWidgetId) {
    LOGGER.debug("Showing refresh view for Widget[ID={}].", appWidgetId);
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    views.setViewVisibility(R.id.textStatusValue, View.GONE);
    views.setViewVisibility(R.id.buttonRefresh, View.GONE);
    views.setViewVisibility(R.id.refreshProgressBar, View.VISIBLE);
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 11
Source File: AppWidgetClassicDark.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic_dark);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 12
Source File: RemoteViewsFactory.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private RemoteViews setError(RemoteViews remote, String title) {
    remote.setTextViewText(R.id.title, title);
    remote.setOnClickPendingIntent(R.id.control_play, server.status().pendingGet());
    remote.setImageViewResource(R.id.control_play, R.drawable.ic_menu_refresh);
    remote.setImageViewResource(R.id.art, R.drawable.albumart_mp_unknown);
    remote.setViewVisibility(R.id.control_prev, View.GONE);
    remote.setViewVisibility(R.id.control_next, View.GONE);
    resetText(remote, R.id.text, R.id.text1, R.id.text2);
    return remote;
}
 
Example 13
Source File: WidgetLatestProvider.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(RealmComic comic) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), WidgetLatestProvider.class.getName());
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_latest_layout);
    AppWidgetTarget appWidgetTarget = new AppWidgetTarget(context, R.id.ivComic, remoteViews, appWidgetIds) {
        @Override
        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
            try {
                super.onResourceReady(resource, transition);
            } catch (IllegalArgumentException e) {
                Timber.e(e, "Loading image failed for %d", comic.getComicNumber());
            }
        }
    };

    if (comic != null) {
        newestComicNumber = comic.getComicNumber();
        GlideApp.with(context)
                .asBitmap()
                .load(comic.getUrl())
                .into(appWidgetTarget);
        String title = prefHelper.widgetShowComicNumber() ? (newestComicNumber + ": ") : "";
        remoteViews.setTextViewText(R.id.tvTitle, title + comic.getTitle());
        remoteViews.setTextViewText(R.id.tvAlt, comic.getAltText());
        if (prefHelper.widgetShowAlt())
            remoteViews.setViewVisibility(R.id.tvAlt, View.VISIBLE);

    }
}
 
Example 14
Source File: V3CustomNotification.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Notification updateNotification(Context c) {
    Notification n = mNotification;

    n.icon = mIcon;

    n.flags |= Notification.FLAG_ONGOING_EVENT;

    if (android.os.Build.VERSION.SDK_INT > 10) {
        n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for
                                                      // Honeycomb
    }

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

    expandedView.setTextViewText(R.id.title, mTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(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,
            c.getString(R.string.time_remaining_notification,
                    Helpers.getTimeRemaining(mTimeRemaining)));
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);
    n.contentView = expandedView;
    n.contentIntent = mPendingIntent;
    return n;
}
 
Example 15
Source File: AppWidgetBig.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_big);

    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();

    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
    }

    // Set correct drawable for pause state
    int playPauseRes = isPlaying ? R.drawable.ic_pause_white : R.drawable.ic_play_white;
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getPrimaryTextColor(service, false))));

    // Set prev/next button drawables
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));

    // Link actions buttons to intents
    linkButtons(service, appWidgetView);

    // Load the album cover async and push the update on completion
    Point p = Util.getScreenSize(service);
    final int widgetImageSize = Math.min(p.x, p.y);
    final Context appContext = service.getApplicationContext();
    service.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (target != null) {
                //Glide.clear(target);
            }
            AppWidgetTarget awt = new AppWidgetTarget(appContext,R.id.image, appWidgetView, appWidgetIds) {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    super.onResourceReady(resource, transition);
                    pushUpdate(appContext, appWidgetIds, appWidgetView);
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    update(null);
                }
            };
            target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
                    .checkIgnoreMediaStore(appContext)
                    .asBitmap().build()
                    .into(awt);

                /*    .into(new SimpleTarget<Bitmap>(widgetImageSize, widgetImageSize) {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                            update(resource);
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            update(null);
                        }
                        */


        }
        private void update(@Nullable Bitmap bitmap) {
            if (bitmap == null) {
                appWidgetView.setImageViewResource(R.id.image, R.drawable.music_style);
            } else {
                appWidgetView.setImageViewBitmap(R.id.image, bitmap);
            }
            pushUpdate(appContext, appWidgetIds, appWidgetView);
        }
    });
}
 
Example 16
Source File: DailyTrendWidgetIMP.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint("WrongThread")
@WorkerThread
private static RemoteViews getRemoteViews(Context context, @Nullable View drawableView,
                                         Location location, int width,
                                          boolean darkCard, int cardAlpha) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_remote);
    if (drawableView == null) {
        return views;
    }

    WidgetItemView[] items = new WidgetItemView[] {
            drawableView.findViewById(R.id.widget_trend_daily_item_1),
            drawableView.findViewById(R.id.widget_trend_daily_item_2),
            drawableView.findViewById(R.id.widget_trend_daily_item_3),
            drawableView.findViewById(R.id.widget_trend_daily_item_4),
            drawableView.findViewById(R.id.widget_trend_daily_item_5),
    };
    for (WidgetItemView i : items) {
        i.setSize(width / 5f);
    }
    drawableView.measure(
            View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
    );
    drawableView.layout(
            0,
            0,
            drawableView.getMeasuredWidth(),
            drawableView.getMeasuredHeight()
    );

    Bitmap cache = Bitmap.createBitmap(
            drawableView.getMeasuredWidth(),
            drawableView.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888
    );
    Canvas canvas = new Canvas(cache);
    drawableView.draw(canvas);

    views.setImageViewBitmap(R.id.widget_remote_drawable, cache);
    views.setViewVisibility(R.id.widget_remote_progress, View.GONE);

    views.setImageViewResource(
            R.id.widget_remote_card,
            getCardBackgroundId(context, darkCard, cardAlpha)
    );

    setOnClickPendingIntent(
            context,
            views,
            location,
            SettingsOptionManager.getInstance(context).isWidgetClickToRefreshEnabled()
    );

    return views;
}
 
Example 17
Source File: ShotWidgetService.java    From droidddle with Apache License 2.0 4 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.shot_widget_item);
    if (position >= mWidgetItems.size()) {
        return rv;
    }
    Shot shot = mWidgetItems.get(position);
    // Construct a remote views item based on the app widget item XML file,
    // and set the text based on the position.

    // Set the click intent so that we can handle it and show a toast message
    final Intent fillInIntent = new Intent();
    final Bundle extras = new Bundle();
    extras.putLong(ShotAppWidgetProvider.EXTRA_SHOT_ID, shot.id);
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.shot_item_layout, fillInIntent);

    rv.setTextViewText(R.id.shot_title, shot.title);
    //           rv.setTextViewText(R.id.shot_views, UiUtils.getCountValue(shot.viewsCount)+"");

    if (shot.createdAt != null) {
        CharSequence date = DateUtils.getRelativeTimeSpanString(shot.createdAt.getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE | DateUtils.FORMAT_NUMERIC_DATE);
        rv.setTextViewText(R.id.shot_date, date);
    } else {
        rv.setTextViewText(R.id.shot_date, null);
    }
    if (TextUtils.isEmpty(shot.description)) {
        rv.setTextViewText(R.id.shot_description, null);
        rv.setViewVisibility(R.id.shot_description, View.INVISIBLE);
    } else {
        rv.setViewVisibility(R.id.shot_description, View.VISIBLE);
        Spanned spannable = GoURLSpan.hackURLSpan(Html.fromHtml(shot.description));
        rv.setTextViewText(R.id.shot_description, spannable);
    }
    //            AppWidgetTarget target = new AppWidgetTarget(mContext, rv, R.id.shot_image, mAppWidgetId);
    Bitmap bitmap = downloadImage(mContext, shot.images.normal);
    rv.setImageViewBitmap(R.id.shot_image, bitmap);
    //           Glide.with(mContext).load(shot.images.normal).asBitmap().into(target);
    // Return the remote views object.

    return rv;
}
 
Example 18
Source File: LessWidgetProvider.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void preLoadWeather(Context context, RemoteViews remoteViews, int appWidgetId) {
    final CurrentWeatherDbHelper currentWeatherDbHelper = CurrentWeatherDbHelper.getInstance(context);
    final LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(context);
    WidgetSettingsDbHelper widgetSettingsDbHelper = WidgetSettingsDbHelper.getInstance(context);

    Long locationId = widgetSettingsDbHelper.getParamLong(appWidgetId, "locationId");

    if (locationId == null) {
        currentLocation = locationsDbHelper.getLocationByOrderId(0);
        if (!currentLocation.isEnabled()) {
            currentLocation = locationsDbHelper.getLocationByOrderId(1);
        }
    } else {
        currentLocation = locationsDbHelper.getLocationById(locationId);
    }

    if (currentLocation == null) {
        return;
    }

    CurrentWeatherDbHelper.WeatherRecord weatherRecord = currentWeatherDbHelper.getWeather(currentLocation.getId());

    if (weatherRecord != null) {
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_temperature, TemperatureUtil.getTemperatureWithUnit(
                context,
                weatherRecord.getWeather(),
                currentLocation.getLatitude(),
                weatherRecord.getLastUpdatedTime(),
                currentLocation.getLocale()));
        String secondTemperature = TemperatureUtil.getSecondTemperatureWithUnit(
                context,
                weatherRecord.getWeather(),
                currentLocation.getLatitude(),
                weatherRecord.getLastUpdatedTime(),
                currentLocation.getLocale());
        if (secondTemperature != null) {
            remoteViews.setViewVisibility(R.id.widget_less_3x1_widget_second_temperature, View.VISIBLE);
            remoteViews.setTextViewText(R.id.widget_less_3x1_widget_second_temperature, secondTemperature);
        } else {
            remoteViews.setViewVisibility(R.id.widget_less_3x1_widget_second_temperature, View.GONE);
        }
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_city, Utils.getCityAndCountry(context, currentLocation.getOrderId()));
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_description,
                                    Utils.getWeatherDescription(context,
                                                                currentLocation.getLocaleAbbrev(),
                                                                weatherRecord.getWeather()));
        Utils.setWeatherIcon(remoteViews, context, weatherRecord,
                R.id.widget_less_3x1_widget_icon);
        String lastUpdate = Utils.getLastUpdateTime(context, weatherRecord, currentLocation);
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_last_update, lastUpdate);
    } else {
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_temperature, TemperatureUtil.getTemperatureWithUnit(
                context,
                null,
                currentLocation.getLatitude(),
                0,
                currentLocation.getLocale()));
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_second_temperature, TemperatureUtil.getTemperatureWithUnit(
                context,
                null,
                currentLocation.getLatitude(),
                0,
                currentLocation.getLocale()));
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_description, "");

        Utils.setWeatherIcon(remoteViews, context, weatherRecord, R.id.widget_less_3x1_widget_icon);
        remoteViews.setTextViewText(R.id.widget_less_3x1_widget_last_update, "");
    }
}
 
Example 19
Source File: AppWidgetSmallDark.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_small_dark);

    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();

    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
            appWidgetView.setTextViewText(R.id.text_separator, "");
        } else {
            appWidgetView.setTextViewText(R.id.text_separator, "•");
        }

        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, song.artistName);
    }

    // Link actions buttons to intents
    linkButtons(service, appWidgetView);

    if (imageSize == 0)
        imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_small_image_size);
    if (cardRadius == 0f)
        cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);

    // Load the album cover async and push the update on completion
    final Context appContext = service.getApplicationContext();
    service.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
                    .checkIgnoreMediaStore(appContext)
                    .generatePalette(service).build()
                    .centerCrop()
                    .into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {
                        @Override
                        public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
                            Palette palette = resource.getPalette();
                            update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(MaterialValueHelper.getSecondaryTextColor(appContext, false))));
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            update(null, MaterialValueHelper.getSecondaryTextColor(appContext, false));
                        }

                        private void update(@Nullable Bitmap bitmap, int color) {
                            // Set correct drawable for pause state
                            int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
                            appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));

                            // Set prev/next button drawables
                            appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
                            appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));

                            final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
                            final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, 0, 0);
                            appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);

                            pushUpdate(appContext, appWidgetIds, appWidgetView);
                        }
                    });
        }
    });
}
 
Example 20
Source File: AppWidgetSmall.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_small);

    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();

    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
            appWidgetView.setTextViewText(R.id.text_separator, "");
        } else {
            appWidgetView.setTextViewText(R.id.text_separator, "•");
        }

        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, song.artistName);
    }

    // Link actions buttons to intents
    linkButtons(service, appWidgetView);

    if (imageSize == 0)
        imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_small_image_size);
    if (cardRadius == 0f)
        cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);

    // Load the album cover async and push the update on completion
    final Context appContext = service.getApplicationContext();
    service.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
                    .checkIgnoreMediaStore(appContext)
                    .generatePalette(service).build()
                    .centerCrop()
                    .into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {
                        @Override
                        public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
                            Palette palette = resource.getPalette();
                            update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(MaterialValueHelper.getSecondaryTextColor(appContext, true))));
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            update(null, MaterialValueHelper.getSecondaryTextColor(appContext, true));
                        }

                        private void update(@Nullable Bitmap bitmap, int color) {
                            // Set correct drawable for pause state
                            int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
                            appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));

                            // Set prev/next button drawables
                            appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
                            appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));

                            final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
                            final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, 0, 0);
                            appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);

                            pushUpdate(appContext, appWidgetIds, appWidgetView);
                        }
                    });
        }
    });
}