Search in sources :

Example 21 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project ride-read-android by Ride-Read.

the class MapFragment method addMomentToMap.

private void addMomentToMap(MapMoment moment) {
    LatLng latLng = new LatLng(moment.getLatitude(), moment.getLongitude());
    // imageView.setImageResource(R.raw.landing_hot_product_1);
    String uri01 = moment.getPictures().get(0);
    String uri02 = moment.getPictures().get(0) + QiNiuUtils.CROP_SMALL_100;
    SimpleTarget target = new SimpleTarget<Bitmap>() {

        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
            Bitmap bitmap1 = convertBitmapFromXML(getActivity(), moment.getCount(), bitmap);
            addMarker(latLng, bitmap1, moment);
        }
    };
    Glide.with(this).load(uri01).asBitmap().into(target);
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) LatLng(com.amap.api.maps.model.LatLng) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Example 22 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project MusicLake by caiyonglong.

the class PlayControlsPresenter method updateNowPlayingCard.

@Override
public void updateNowPlayingCard() {
    Log.d(TAG, "updateNowPlayingCard" + mProgress);
    Music music = PlayManager.getPlayingMusic();
    if (music == null || PlayManager.getPlayList().size() == 0) {
        Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.default_cover);
        mView.setAlbumArt(bitmap);
        mView.setTitle(mContext.getResources().getString(R.string.app_name));
        mView.setArtist("");
        mView.updatePanelLayout(false);
        return;
    } else {
        mView.updatePanelLayout(true);
    }
    final String title = PlayManager.getSongName();
    final String artist = PlayManager.getSongArtist();
    if (TextUtils.isEmpty(title) && TextUtils.isEmpty(artist)) {
        mView.setTitle(mContext.getResources().getString(R.string.app_name));
        mView.setArtist("");
    } else {
        mView.setTitle(title);
        mView.setArtist(artist);
    }
    String picUrl = CoverLoader.getInstance().getCoverUriByMusic(music);
    // 设置音乐来源
    mView.setOtherInfo(music.getTypeName(false));
    // 获取当前歌曲状态
    AppRepository.getMusicInfo(mContext, music).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(music1 -> mView.updateFavorite(music1.isLove()));
    if (!isPlayPauseClick && !activity.isFinishing()) {
        loadLyric();
        GlideApp.with(mContext).asBitmap().load(picUrl != null ? picUrl : CoverLoader.getInstance().getCoverUriByRandom()).error(CoverLoader.getInstance().getCoverUriByRandom()).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Bitmap>() {

            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                mView.setAlbumArt(resource);
                mView.setAlbumArt(ImageUtils.createBlurredImageFromBitmap(resource, mContext, 12));
                new Palette.Builder(resource).generate(palette -> mView.setPalette(palette));
            }
        });
    }
    isPlayPauseClick = false;
    mHandler.post(updateProgress);
}
Also used : GlideApp(com.cyl.musiclake.api.GlideApp) Context(android.content.Context) Palette(android.support.v7.graphics.Palette) LogUtil(com.cyl.musiclake.utils.LogUtil) FileUtils(com.cyl.musiclake.utils.FileUtils) R(com.cyl.musiclake.R) BitmapFactory(android.graphics.BitmapFactory) MusicApi(com.cyl.musiclake.api.MusicApi) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SuppressLint(android.annotation.SuppressLint) CoverLoader(com.cyl.musiclake.utils.CoverLoader) Handler(android.os.Handler) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) PlayControlsContract(com.cyl.musiclake.ui.music.local.contract.PlayControlsContract) MetaChangedEvent(com.cyl.musiclake.event.MetaChangedEvent) Log(android.util.Log) PlayManager(com.cyl.musiclake.service.PlayManager) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Music(com.cyl.musiclake.bean.Music) TextUtils(android.text.TextUtils) AppRepository(com.cyl.musiclake.data.source.AppRepository) ImageUtils(com.cyl.musiclake.utils.ImageUtils) StatusChangedEvent(com.cyl.musiclake.event.StatusChangedEvent) Disposable(io.reactivex.disposables.Disposable) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) Observer(io.reactivex.Observer) RxBus(com.cyl.musiclake.RxBus) Activity(android.app.Activity) Bitmap(android.graphics.Bitmap) Music(com.cyl.musiclake.bean.Music)

Example 23 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.

the class DrawerActivity method updateHeader.

public void updateHeader() {
    if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
        OCCapability capability = getStorageManager().getCapability(getAccount().name);
        String logo = capability.getServerLogo();
        int primaryColor = ThemeColorUtils.primaryColor(getAccount(), false, this);
        // set background to primary color
        LinearLayout drawerHeader = mNavigationViewHeader.findViewById(R.id.drawer_header_view);
        drawerHeader.setBackgroundColor(ThemeColorUtils.unchangedPrimaryColor(getAccount(), this));
        if (!TextUtils.isEmpty(logo) && URLUtil.isValidUrl(logo)) {
            // background image
            GenericRequestBuilder<Uri, InputStream, SVGorImage, Bitmap> requestBuilder = Glide.with(this).using(Glide.buildStreamModelLoader(Uri.class, this), InputStream.class).from(Uri.class).as(SVGorImage.class).transcode(new SvgOrImageBitmapTranscoder(128, 128), Bitmap.class).sourceEncoder(new StreamEncoder()).cacheDecoder(new FileToStreamDecoder<>(new SvgOrImageDecoder())).decoder(new SvgOrImageDecoder());
            // background image
            SimpleTarget target = new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                    Bitmap logo = resource;
                    int width = resource.getWidth();
                    int height = resource.getHeight();
                    int max = Math.max(width, height);
                    if (max > MAX_LOGO_SIZE_PX) {
                        logo = BitmapUtils.scaleBitmap(resource, MAX_LOGO_SIZE_PX, width, height, max);
                    }
                    Drawable[] drawables = { new ColorDrawable(primaryColor), new BitmapDrawable(logo) };
                    LayerDrawable layerDrawable = new LayerDrawable(drawables);
                    String name = capability.getServerName();
                    setDrawerHeaderLogo(layerDrawable, name);
                }
            };
            requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE).load(Uri.parse(logo)).into(target);
        }
    }
}
Also used : SVGorImage(com.owncloud.android.utils.svg.SVGorImage) FileToStreamDecoder(com.bumptech.glide.load.resource.file.FileToStreamDecoder) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) InputStream(java.io.InputStream) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) Uri(android.net.Uri) MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) SvgOrImageDecoder(com.owncloud.android.utils.svg.SvgOrImageDecoder) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) SvgOrImageBitmapTranscoder(com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder) LinearLayout(android.widget.LinearLayout) StreamEncoder(com.bumptech.glide.load.model.StreamEncoder)

Example 24 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.

the class DrawerActivity method updateQuotaLink.

private void updateQuotaLink() {
    if (mQuotaTextLink != null) {
        if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
            List<ExternalLink> quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA);
            float density = getResources().getDisplayMetrics().density;
            final int size = Math.round(24 * density);
            if (quotas.size() > 0) {
                final ExternalLink firstQuota = quotas.get(0);
                mQuotaTextLink.setText(firstQuota.getName());
                mQuotaTextLink.setClickable(true);
                mQuotaTextLink.setVisibility(View.VISIBLE);
                mQuotaTextLink.setOnClickListener(v -> {
                    Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, firstQuota.getName());
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, firstQuota.getUrl());
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, true);
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1);
                    startActivity(externalWebViewIntent);
                });
                SimpleTarget target = new SimpleTarget<Drawable>() {

                    @Override
                    public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                        Drawable test = resource.getCurrent();
                        test.setBounds(0, 0, size, size);
                        mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(test, null, null, null);
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable);
                        Drawable test = errorDrawable.getCurrent();
                        test.setBounds(0, 0, size, size);
                        mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(test, null, null, null);
                    }
                };
                DisplayUtils.downloadIcon(getUserAccountManager(), clientFactory, this, firstQuota.getIconUrl(), target, R.drawable.ic_link, size, size);
            } else {
                mQuotaTextLink.setVisibility(View.GONE);
            }
        } else {
            mQuotaTextLink.setVisibility(View.GONE);
        }
    }
}
Also used : MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Intent(android.content.Intent) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ExternalLink(com.owncloud.android.lib.common.ExternalLink) AuthenticatorException(android.accounts.AuthenticatorException) OperationCanceledException(android.accounts.OperationCanceledException) IOException(java.io.IOException)

Example 25 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.

the class ContactListAdapter method setPhoto.

private void setPhoto(ImageView imageView, Photo firstPhoto) {
    String url = firstPhoto.getUrl();
    byte[] data = firstPhoto.getData();
    if (data != null && data.length > 0) {
        Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
        RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(), thumbnail);
        imageView.setImageDrawable(drawable);
    } else if (url != null) {
        SimpleTarget target = new SimpleTarget<Drawable>() {

            @Override
            public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                imageView.setImageDrawable(resource);
            }

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                imageView.setImageDrawable(errorDrawable);
            }
        };
        DisplayUtils.downloadIcon(accountManager, clientFactory, context, url, target, R.drawable.ic_user, imageView.getWidth(), imageView.getHeight());
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Aggregations

SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)25 Drawable (android.graphics.drawable.Drawable)18 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)18 Bitmap (android.graphics.Bitmap)17 ColorDrawable (android.graphics.drawable.ColorDrawable)6 ImageView (android.widget.ImageView)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 View (android.view.View)5 Target (com.bumptech.glide.request.target.Target)5 LayerDrawable (android.graphics.drawable.LayerDrawable)4 Nullable (android.support.annotation.Nullable)4 RequestListener (com.bumptech.glide.request.RequestListener)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 Palette (android.support.v7.graphics.Palette)3 ViewGroup (android.view.ViewGroup)3 TextDrawable (com.owncloud.android.ui.TextDrawable)3 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)3 PendingIntent (android.app.PendingIntent)2 SQLiteException (android.database.sqlite.SQLiteException)2