Before 2022/Android

위젯에서 glide 사용하기

Eljoe 2018. 8. 29. 17:49
   // 전역변수 선언
   private AppWidgetTarget appWidgetTarget;
   private RemoteViews views;

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       // RemoteViews 생성
        views = new RemoteViews(context.getPackageName(), R.layout.smart_id_widget);
        
        appWidgetTarget = new AppWidgetTarget(context, R.id.iv_profile, views, appWidgetIds){
            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) {
                super.onResourceReady(resource, transition);
            }
        };

        if(TextUtils.isEmpty(SharedUtil.getString(context, "imgPath"))){
            Glide.with(context.getApplicationContext())
                    .asBitmap()
                    .load(R.drawable.no_profile)
                    .into(appWidgetTarget);
        }else{
            Glide.with(context.getApplicationContext())
                    .asBitmap()
                    .load(SharedUtil.getString(context, "imgPath"))
                    .into(appWidgetTarget);
        }
    }