Java 类com.bumptech.glide.request.target.AppWidgetTarget 实例源码

项目:Easy_xkcd    文件:WidgetRandomProvider.java   
@Override
protected void onPostExecute(Comic comic) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), WidgetRandomProvider.class.getName());
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_random_layout);
    AppWidgetTarget appWidgetTarget = new AppWidgetTarget(context, remoteViews, R.id.ivComic, appWidgetIds);

    if (comic != null) {
        Glide.with(context)
                .load(comic.getComicData()[2])
                .asBitmap()
                .into(appWidgetTarget);

        String title = prefHelper.widgetShowComicNumber() ? (lastComicNumber + ": ") : "";
        remoteViews.setTextViewText(R.id.tvTitle, title + comic.getComicData()[0]);
        remoteViews.setTextViewText(R.id.tvAlt, comic.getComicData()[1]);
        if (prefHelper.widgetShowAlt())
            remoteViews.setViewVisibility(R.id.tvAlt, View.VISIBLE);
    }
}
项目:Easy_xkcd    文件:WidgetLatestProvider.java   
@Override
protected void onPostExecute(Comic 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, remoteViews, R.id.ivComic, appWidgetIds);

    if (comic != null) {
        newestComicNumber = comic.getComicNumber();
        Glide.with(context)
                .load(comic.getComicData()[2])
                .asBitmap()
                .into(appWidgetTarget);
        String title = prefHelper.widgetShowComicNumber() ? (newestComicNumber + ": ") : "";
        remoteViews.setTextViewText(R.id.tvTitle, title + comic.getComicData()[0]);
        remoteViews.setTextViewText(R.id.tvAlt, comic.getComicData()[1]);
        if (prefHelper.widgetShowAlt())
            remoteViews.setViewVisibility(R.id.tvAlt, View.VISIBLE);

    }
}
项目:android-tutorials-glide    文件:FSAppWidgetProvider.java   
@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);
}
项目:Android-Tech    文件:FSAppWidgetProvider.java   
@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);
}
项目:reark    文件:WidgetService.java   
private void updateWidget(final int widgetId) {
    AppWidgetManager appWidgetManager = AppWidgetManager
            .getInstance(getApplicationContext());

    RemoteViews remoteViews = new RemoteViews(getApplication().getPackageName(), R.layout.widget_layout);
    remoteViews.setTextViewText(R.id.widget_layout_title, "Loading repository..");
    appWidgetManager.updateAppWidget(widgetId, remoteViews);

    clearDisposable();

    compositeDisposable.add(
            getUserSettings.call()
                    .map(UserSettings::getSelectedRepositoryId)
                    .doOnNext(repositoryId -> Log.d(TAG, "Changed repository to " + repositoryId))
                    .switchMap(fetchAndGetGitHubRepository::call)
                    .filter(DataStreamNotification::isOnNext)
                    .map(DataStreamNotification::getValue)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(repository -> {
                        remoteViews.setTextViewText(R.id.widget_layout_title, repository.getName());
                        remoteViews.setTextViewText(R.id.widget_layout_stargazers,
                                "stars: " + repository.getStargazersCount());
                        remoteViews.setTextViewText(R.id.widget_layout_forks,
                                "forks: " + repository.getForksCount());

                        AppWidgetTarget widgetTarget = new AppWidgetTarget(WidgetService.this,
                                                                remoteViews,
                                                                R.id.widget_avatar_image_view,
                                                                widgetId);
                        Glide.with(WidgetService.this)
                             .load(repository.getOwner().getAvatarUrl())
                             .asBitmap()
                             .fitCenter()
                             .into(widgetTarget);
                        appWidgetManager.updateAppWidget(widgetId, remoteViews);
                    }));
}
项目:reark    文件:WidgetService.java   
private void updateWidget(final int widgetId) {
    AppWidgetManager appWidgetManager = AppWidgetManager
            .getInstance(getApplicationContext());

    RemoteViews remoteViews = new RemoteViews(getApplication().getPackageName(), R.layout.widget_layout);
    remoteViews.setTextViewText(R.id.widget_layout_title, "Loading repository..");
    appWidgetManager.updateAppWidget(widgetId, remoteViews);

    clearDisposable();

    compositeDisposable.add(
            getUserSettings.call()
                    .map(UserSettings::getSelectedRepositoryId)
                    .doOnNext(repositoryId -> Log.d(TAG, "Changed repository to " + repositoryId))
                    .switchMap(fetchAndGetGitHubRepository::call)
                    .filter(DataStreamNotification::isOnNext)
                    .map(DataStreamNotification::getValue)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(repository -> {
                        remoteViews.setTextViewText(R.id.widget_layout_title, repository.getName());
                        remoteViews.setTextViewText(R.id.widget_layout_stargazers,
                                "stars: " + repository.getStargazersCount());
                        remoteViews.setTextViewText(R.id.widget_layout_forks,
                                "forks: " + repository.getForksCount());

                        AppWidgetTarget widgetTarget = new AppWidgetTarget(WidgetService.this,
                                                                remoteViews,
                                                                R.id.widget_avatar_image_view,
                                                                widgetId);
                        Glide.with(WidgetService.this)
                             .load(repository.getOwner().getAvatarUrl())
                             .asBitmap()
                             .fitCenter()
                             .into(widgetTarget);
                        appWidgetManager.updateAppWidget(widgetId, remoteViews);
                    }));
}
项目:OSRSHelper    文件:GrandExchangeAppWidgetProvider.java   
private void refreshWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
    Intent intentSync = new Intent(context, GrandExchangeAppWidgetProvider.class);
    intentSync.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intentSync.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    PendingIntent pendingSync = PendingIntent.getBroadcast(context, appWidgetId, intentSync, PendingIntent.FLAG_UPDATE_CURRENT);

    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_grand_exchange_layout);
    views.setOnClickPendingIntent(R.id.update_btn, pendingSync);

    //Username
    final Item item = DBController.getGrandExchangeByWidgetId(context, appWidgetId);
    if(item != null) {
        views.setTextViewText(R.id.item_name, item.name);
        views.setTextViewText(R.id.item_price, "");
        views.setViewVisibility(R.id.item_member, item.members ? View.VISIBLE : View.GONE);

        AppWidgetTarget appWidgetTarget = new AppWidgetTarget(context, R.id.item_image, views, appWidgetId) {
            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                super.onResourceReady(resource, transition);
            }
        };

        Glide
            .with(context.getApplicationContext())
            .asBitmap()
            .load(item.iconLarge)
            .into(appWidgetTarget);
    }

    Logger.add(TAG, ": appWidgetId=" + appWidgetId);
    //Config
    Intent configIntent = WidgetGrandExchangeSearchActivity.getIntent(context, appWidgetId);
    configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    configIntent.setAction(ACTION_WIDGET_CONFIGURE + Integer.toString(appWidgetId));
    PendingIntent configPendingIntent = PendingIntent.getActivity(context, appWidgetId, configIntent, 0);
    views.setOnClickPendingIntent(R.id.change_item_btn, configPendingIntent);

    //Info
    if(item != null) {
        views.setViewVisibility(R.id.info_item_btn, View.VISIBLE);
        Intent infoIntent = MainActivity.getGrandExchangeDetailIntent(context, item.id);
        infoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent infoPendingIntent = PendingIntent.getActivity(context, appWidgetId, infoIntent, 0);
        views.setOnClickPendingIntent(R.id.info_item_btn, infoPendingIntent);
    } else {
        views.setViewVisibility(R.id.info_item_btn, View.GONE);
    }

    if(item != null) {
        Intent intentService = new Intent(context, GrandExchangeWidgetService.class);
        // Add the app widget ID to the intent extras.
        intentService.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        intentService.putExtra(GrandExchangeWidgetRemoteViewsFactory.EXTRA_ITEM_ID, item.id);
        intentService.setData(Uri.parse(intentService.toUri(Intent.URI_INTENT_SCHEME)));
        views.setRemoteAdapter(R.id.grid_view, intentService);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.grid_view);
    }

    appWidgetManager.updateAppWidget(appWidgetId, views);
}
项目:Filmy    文件:FilmyWidgetProvider.java   
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {


        final int N = appWidgetIds.length;

        String movie_id=" ";
        String movie_title= " ";
        String movie_poster=" ";

        for (int i=0; i<N; i++) {

            int appWidgetId = appWidgetIds[i];

            Uri moviesForTheUri = FilmContract.MoviesEntry.CONTENT_URI;
            String selection = null;
            String[] selectionArgs = null;
            Cursor cursor = context.getContentResolver().query(moviesForTheUri,MovieProjection.MOVIE_COLUMNS, selection, selectionArgs, null);

            if (cursor != null && cursor.getCount() > 0) {

                cursor.moveToFirst();

                int id_index = cursor.getColumnIndex(FilmContract.MoviesEntry.MOVIE_ID);
                int title_index = cursor.getColumnIndex(FilmContract.MoviesEntry.MOVIE_TITLE);
                int poster_index = cursor.getColumnIndex(FilmContract.MoviesEntry.MOVIE_POSTER_LINK);
                int year_index = cursor.getColumnIndex(FilmContract.MoviesEntry.MOVIE_YEAR);

                movie_id = cursor.getString(id_index);
                movie_title = cursor.getString(title_index);
                movie_poster = cursor.getString(poster_index);
                //String imdb_id = cursor.getString(id_index);
                //int movie_year = cursor.getInt(year_index);



            } else {

            }

            cursor.close();

            final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.filmy_appwidget);
            remoteViews.setTextViewText(R.id.widget_movie_name,movie_title);

            appWidgetTarget = new AppWidgetTarget( context, remoteViews, R.id.widget_movie_image, appWidgetIds );


            Glide.with(context)
                    .load(movie_poster)
                    .asBitmap()
                    .into(appWidgetTarget);


            Intent intent = new Intent(context,MovieDetailsActivity.class);
            intent.putExtra("title", movie_title);
            intent.putExtra("activity", true);
            intent.putExtra("type", -1);
            intent.putExtra("database_applicable", false);
            intent.putExtra("network_applicable", true);
            intent.putExtra("id", movie_id);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            remoteViews.setOnClickPendingIntent(R.id.activity_opener, pendingIntent);

            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

        }
    }