com.bumptech.glide.request.target.AppWidgetTarget Java Examples

The following examples show how to use com.bumptech.glide.request.target.AppWidgetTarget. 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 Project: android-tutorials-glide   Author: futurestudio   File: FSAppWidgetProvider.java    License: MIT License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {

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

    appWidgetTarget = new AppWidgetTarget(context, remoteViews, R.id.custom_view_image, appWidgetIds) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            super.onResourceReady(resource, glideAnimation);
        }
    };

    Glide
            .with(context.getApplicationContext())
            .load(GlideExampleActivity.eatFoodyImages[3])
            .asBitmap()
            .into(appWidgetTarget);

    pushWidgetUpdate(context, remoteViews);
}
 
Example #2
Source Project: earth   Author: oxoooo   File: EarthAppWidgetProvider.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final Intent intent = new Intent(context, MainActivity.class);
    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget);
    views.setOnClickPendingIntent(R.id.earth, pendingIntent);

    final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    final int size = Math.min(metrics.widthPixels, metrics.heightPixels);

    Glide.with(context)
            .load(getLatestEarth())
            .asBitmap()
            .error(R.drawable.preview)
            .transform(new MaskTransformation(context, R.drawable.mask))
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(new AppWidgetTarget(context, views, R.id.earth, size, size, appWidgetIds));
}
 
Example #3
Source Project: Android-Tech   Author: devilWwj   File: FSAppWidgetProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio);

    appWidgetTarget = new AppWidgetTarget(context, rv, R.id.custom_view_image, appWidgetIds);

    Glide.with(context.getApplicationContext()).load(MainActivity.eatFoodyImages[3])
            .asBitmap().into(appWidgetTarget);

    pushWidgetUpdate(context, rv);
}
 
Example #4
Source Project: Easy_xkcd   Author: tom-anders   File: WidgetLatestProvider.java    License: 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 #5
Source Project: MusicPlayer   Author: dtrung98   File: AppWidgetBig.java    License: 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 #6
Source Project: Easy_xkcd   Author: tom-anders   File: WidgetRandomProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    if (prefHelper == null)
        prefHelper = new PrefHelper(context);
    if (lastComicNumber == 0)
        lastComicNumber = prefHelper.getRandomNumber(prefHelper.getLastComic());
    else
        lastComicNumber = prefHelper.getRandomNumber(lastComicNumber);

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

    Intent intent = new Intent(context, WidgetRandomProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.tvAlt, pendingIntent); //Use tvAlt instead of shuffle if available

    Intent intent2 = new Intent("de.tap.easy_xkcd.ACTION_COMIC");
    intent2.putExtra("number", lastComicNumber);
    PendingIntent openInApp = PendingIntent.getActivity(context, 1, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.ivComic, openInApp);

    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);

    RealmComic comic = (new DatabaseManager(context)).getRealmComic(lastComicNumber);

    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) {
        if (prefHelper.fullOfflineEnabled()) {
            remoteViews.setImageViewBitmap(R.id.ivComic, RealmComic.getOfflineBitmap(lastComicNumber, context, prefHelper));
        } else {
            GlideApp.with(context)
                    .asBitmap()
                    .load(comic.getUrl())
                    .into(appWidgetTarget);
        }

        String title = prefHelper.widgetShowComicNumber() ? (lastComicNumber + ": ") : "";
        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);
    }
}