Search in sources :

Example 1 with DataSource

use of com.bumptech.glide.load.DataSource in project Robot-Scouter by SUPERCILEX.

the class TeamDetailsDialog method updateUi.

private void updateUi() {
    if (mMedia != null && mName != null && mNameEditText != null && mMediaCapture != null && mWebsiteEditText != null) {
        Team team = mTeamHelper.getTeam();
        mMediaLoadProgress.setVisibility(View.VISIBLE);
        Glide.with(getContext()).load(team.getMedia()).apply(RequestOptions.circleCropTransform().error(R.drawable.ic_memory_grey_48dp).fallback(R.drawable.ic_memory_grey_48dp)).listener(new RequestListener<Drawable>() {

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                mMediaLoadProgress.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                mMediaLoadProgress.setVisibility(View.GONE);
                return false;
            }
        }).into(mMedia);
        mName.setText(team.toString());
        mNameEditText.setText(team.getName());
        mMediaEditText.setText(team.getMedia());
        mWebsiteEditText.setText(team.getWebsite());
    }
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) Team(com.supercilex.robotscouter.data.model.Team) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 2 with DataSource

use of com.bumptech.glide.load.DataSource in project glide by bumptech.

the class FullscreenActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fullscreen_activity);
    String resultJson = getIntent().getStringExtra(EXTRA_RESULT_JSON);
    final Api.GifResult result = new Gson().fromJson(resultJson, Api.GifResult.class);
    ImageView gifView = (ImageView) findViewById(R.id.fullscreen_gif);
    gifView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("giphy_url", result.images.original.url);
            clipboard.setPrimaryClip(clip);
            if (gifDrawable != null) {
                if (gifDrawable.isRunning()) {
                    gifDrawable.stop();
                } else {
                    gifDrawable.start();
                }
            }
        }
    });
    RequestBuilder<Drawable> thumbnailRequest = Glide.with(this).load(result).apply(decodeTypeOf(Bitmap.class));
    Glide.with(this).load(result.images.original.url).thumbnail(thumbnailRequest).listener(new RequestListener<Drawable>() {

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

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            if (resource instanceof GifDrawable) {
                gifDrawable = (GifDrawable) resource;
            } else {
                gifDrawable = null;
            }
            return false;
        }
    }).into(gifView);
}
Also used : ClipboardManager(android.content.ClipboardManager) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) Gson(com.google.gson.Gson) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) ImageView(android.widget.ImageView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) Target(com.bumptech.glide.request.target.Target) ImageView(android.widget.ImageView) ClipData(android.content.ClipData) GlideException(com.bumptech.glide.load.engine.GlideException)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 DataSource (com.bumptech.glide.load.DataSource)2 GlideException (com.bumptech.glide.load.engine.GlideException)2 RequestListener (com.bumptech.glide.request.RequestListener)2 Target (com.bumptech.glide.request.target.Target)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 GifDrawable (com.bumptech.glide.load.resource.gif.GifDrawable)1 Gson (com.google.gson.Gson)1 Team (com.supercilex.robotscouter.data.model.Team)1