Search in sources :

Example 6 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project BaseProject by feer921.

the class ImageUtil method loadImage.

// public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, Drawable holderDrawable,
// Drawable errorDrawable, ImageView targetIv
// , Callback callback) {
// RequestCreator loadRequest = loadImageRequest(context, picUrl,null,0);
// 
// if (newWidth > 0 && newHeight > 0) {
// loadRequest.resize(newWidth, newHeight);
// loadRequest.centerCrop();
// }
// else{
// //            loadRequest.fit();
// }
// if (holderDrawable != null) {
// loadRequest.placeholder(holderDrawable);
// }
// else{
// loadRequest.noPlaceholder();
// }
// if (errorDrawable != null) {
// loadRequest.error(errorDrawable);
// }
// loadRequest.noFade();
// loadRequest.into(targetIv, callback);
// }
public static void loadImage(Context context, String picUrl, int newWidth, int newHeight, Drawable holderDrawable, Drawable errorDrawable, ImageView targetIv, RequestListener callback) {
    RequestBuilder requestBuilder = loadImageRequest(context, picUrl);
    RequestOptions options = new RequestOptions();
    if (newWidth > 0 && newHeight > 0) {
        options.override(newWidth, newHeight).centerCrop();
    } else {
    // loadRequest.fit();
    }
    if (holderDrawable != null) {
        options.placeholder(holderDrawable);
    } else {
    // loadRequest.noPlaceholder();
    }
    if (errorDrawable != null) {
        options.error(errorDrawable);
    }
    options.dontAnimate();
    if (callback != null) {
        requestBuilder.listener(callback);
    }
    requestBuilder.apply(options).into(targetIv);
}
Also used : RequestBuilder(com.bumptech.glide.RequestBuilder) RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 7 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project ARD by MobileApplicationsClub.

the class NavigationDrawerListener method onDataChange.

@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
    if (dataSnapshot.child(AHC.FDR_NAV_DRAWER_TITLE).exists()) {
        final String navDrawerTitleText = dataSnapshot.child(AHC.FDR_NAV_DRAWER_TITLE).getValue(String.class);
        if (!Objects.equals(navDrawerTitleText, MainActivity.navDrawerTitleText)) {
            navDrawerTitle.setText(navDrawerTitleText);
            MainActivity.navDrawerTitleText = navDrawerTitleText;
        }
    }
    if (dataSnapshot.child(AHC.FDR_NAV_DRAWER_SUBTITLE).exists()) {
        final String navDrawerSubtitleText = dataSnapshot.child(AHC.FDR_NAV_DRAWER_SUBTITLE).getValue(String.class);
        if (!Objects.equals(navDrawerSubtitleText, MainActivity.navDrawerSubtitleText)) {
            navDrawerSubtitle.setText(navDrawerSubtitleText);
            MainActivity.navDrawerSubtitleText = navDrawerSubtitleText;
        }
    }
    if (dataSnapshot.child(AHC.FDR_NAV_DRAWER_IMAGE_LIST).exists() && dataSnapshot.child(AHC.FDR_NAV_DRAWER_IMAGE_LIST).getChildrenCount() > 0) {
        final ArrayList<String> navDrawerImageList = new ArrayList<>();
        for (final DataSnapshot childSnapshot : dataSnapshot.child(AHC.FDR_NAV_DRAWER_IMAGE_LIST).getChildren()) {
            navDrawerImageList.add(childSnapshot.getValue(String.class));
        }
        if (!Objects.equals(navDrawerImageList, MainActivity.navDrawerImageList)) {
            final Random rand = new Random();
            final String navDrawerImageURL = navDrawerImageList.get(rand.nextInt(navDrawerImageList.size()));
            final RequestOptions navDrawerImageOptions = new RequestOptions().placeholder(context.getDrawable(R.drawable.nav_drawer_default_image));
            Glide.with(context).load(navDrawerImageURL).transition(DrawableTransitionOptions.withCrossFade().crossFade(MainActivity.NAV_DRAWER_BACKGROUND_ANIM_DUR)).apply(navDrawerImageOptions).into(navDrawerImageView);
            MainActivity.navDrawerImageURL = navDrawerImageURL;
            MainActivity.navDrawerImageList = navDrawerImageList;
        }
    }
}
Also used : Random(java.util.Random) RequestOptions(com.bumptech.glide.request.RequestOptions) ArrayList(java.util.ArrayList) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 8 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project Simple-Dilbert by smarek.

the class WidgetProvider method updateAppWidget.

private static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
    final DilbertPreferences prefs = new DilbertPreferences(context);
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    views.setOnClickPendingIntent(R.id.widget_previous, getPendingIntent(INTENT_PREVIOUS, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_next, getPendingIntent(INTENT_NEXT, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_latest, getPendingIntent(INTENT_LATEST, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_random, getPendingIntent(INTENT_RANDOM, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_image, getPendingIntent(INTENT_DISPLAY, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_refresh, getPendingIntent(INTENT_REFRESH, context, appWidgetId));
    views.setOnClickPendingIntent(R.id.widget_full_layout, getPendingIntent(INTENT_DISPLAY, context, appWidgetId));
    final LocalDate currentDate = prefs.getDateForWidgetId(appWidgetId);
    views.setViewVisibility(R.id.widget_next, prefs.isWidgetAlwaysShowLatest() ? View.GONE : View.VISIBLE);
    views.setViewVisibility(R.id.widget_previous, prefs.isWidgetAlwaysShowLatest() ? View.GONE : View.VISIBLE);
    views.setViewVisibility(R.id.widget_random, prefs.isWidgetAlwaysShowLatest() ? View.GONE : View.VISIBLE);
    views.setViewVisibility(R.id.widget_latest, prefs.isWidgetAlwaysShowLatest() ? View.GONE : View.VISIBLE);
    final String cachedUrl = prefs.getCachedUrl(currentDate);
    final String cachedTitle = prefs.getCachedTitle(currentDate);
    views.setViewVisibility(R.id.widget_progress, View.VISIBLE);
    views.setTextViewText(R.id.widget_title, prefs.getDateForWidgetId(appWidgetId).toString(DilbertPreferences.NICE_DATE_FORMATTER));
    if (prefs.isWidgetShowTitle() && cachedTitle != null && !cachedTitle.isEmpty()) {
        views.setViewVisibility(R.id.widget_strip_title, View.VISIBLE);
        views.setTextViewText(R.id.widget_strip_title, cachedTitle);
    } else {
        views.setViewVisibility(R.id.widget_strip_title, View.GONE);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
    if (cachedUrl == null) {
        new GetStripUrl(new GetStripUrlInterface() {

            @Override
            public void imageLoadFailed(String url, Throwable reason) {
                currentToast = Toast.makeText(context, "Image Loading failed", Toast.LENGTH_SHORT);
                currentToast.show();
                views.setImageViewResource(R.id.widget_image, R.drawable.cancel);
                views.setViewVisibility(R.id.widget_progress, View.GONE);
                appWidgetManager.updateAppWidget(appWidgetId, views);
            }

            @Override
            public void displayImage(String url, String title) {
                updateAppWidget(context, appWidgetManager, appWidgetId);
            }
        }, prefs, currentDate).execute();
    } else {
        Glide.with(context).asBitmap().load(cachedUrl).apply(new RequestOptions().dontAnimate()).listener(new RequestListener<Bitmap>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                updateAppWidget(context, appWidgetManager, appWidgetId);
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                views.setViewVisibility(R.id.widget_progress, View.GONE);
                appWidgetManager.updateAppWidget(appWidgetId, views);
                Glide.with(context).asBitmap().load(cachedUrl).apply(new RequestOptions().dontAnimate()).into(new AppWidgetTarget(context, R.id.widget_image, views, appWidgetId));
                return false;
            }
        }).into(new AppWidgetTarget(context, R.id.widget_image, views, appWidgetId));
    }
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) RequestOptions(com.bumptech.glide.request.RequestOptions) LocalDate(org.joda.time.LocalDate) GetStripUrl(com.mareksebera.simpledilbert.utilities.GetStripUrl) DataSource(com.bumptech.glide.load.DataSource) RemoteViews(android.widget.RemoteViews) Target(com.bumptech.glide.request.target.Target) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) Bitmap(android.graphics.Bitmap) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) GetStripUrlInterface(com.mareksebera.simpledilbert.utilities.GetStripUrlInterface) DilbertPreferences(com.mareksebera.simpledilbert.preferences.DilbertPreferences) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable)

Example 9 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project Camera-Roll-Android-App by kollerlukas.

the class GifViewHolder method loadImage.

@Override
public void loadImage(final ImageView imageView, final AlbumItem albumItem) {
    // super.loadImage(imageView, albumItem);
    RequestOptions options = new RequestOptions().error(R.drawable.error_placeholder).signature(albumItem.getGlideSignature());
    Glide.with(imageView.getContext()).asGif().load(albumItem.getPath()).listener(new RequestListener<GifDrawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
            if (!albumItem.hasFadedIn) {
                fadeIn();
            } else {
                imageView.clearColorFilter();
            }
            resource.start();
            return false;
        }
    }).apply(options).into(imageView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) GlideException(com.bumptech.glide.load.engine.GlideException) DataSource(com.bumptech.glide.load.DataSource)

Example 10 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MyNewCC98 by 6769.

the class PhotoViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_view);
    ButterKnife.bind(this);
    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    url = bundle.getString(URL_KEY);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setTitle(getString(R.string.activity_photo_view_title));
    try {
        RequestOptions options = new RequestOptions().fitCenter().error(// 占位图片;
        R.drawable.image_load_error);
        Glide.with(this).load(url).apply(// 淡入淡出动画500ms
        options).transition(withCrossFade()).into(activityPhotoview);
    } catch (Exception e) {
        loge(e, "Glide load custom failed");
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Bundle(android.os.Bundle) Intent(android.content.Intent) ActionBar(android.support.v7.app.ActionBar)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)104 ImageView (android.widget.ImageView)23 Drawable (android.graphics.drawable.Drawable)18 View (android.view.View)18 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)11 File (java.io.File)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)9 ColorDrawable (android.graphics.drawable.ColorDrawable)7 Uri (android.net.Uri)7 DataSource (com.bumptech.glide.load.DataSource)6 GlideException (com.bumptech.glide.load.engine.GlideException)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3