Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

In this page you can find the example usage for android.widget ImageView getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:mx.com.adolfogarcia.popularmovies.model.view.MovieDetailViewModel.java

/**
 * Loads the movie's backdrop image from the specified URI into the
 * {@link ImageView}. This method is used by the Data Binding Library.
 *
 * @param view {@link ImageView} to place the image into.
 * @param backdropUri where the backdrop image should be retrieved from.
 *///  w ww  .ja  v a  2  s .  c  om
@BindingAdapter({ "bind:backdropUri" })
public static void loadBackdropImage(ImageView view, String backdropUri) {
    Context context = view.getContext();
    int backdropPixelWidth = context.getResources().getDimensionPixelSize(R.dimen.movie_backdrop_width);
    int backdropPixelHeight = context.getResources().getDimensionPixelSize(R.dimen.movie_backdrop_height);
    Picasso.with(context).load(backdropUri).resize(backdropPixelWidth, backdropPixelHeight)
            .placeholder(R.anim.backdrop_loading).error(R.drawable.logo_the_movie_db_360dp).into(view);
}

From source file:org.matrix.matrixandroidsdk.db.ConsoleMediasCache.java

/**
 * Load a bitmap from an url.//from  w  ww. j a v a2  s . co  m
 * The imageView image is updated when the bitmap is loaded or downloaded.
 * The width/height parameters are optional. If they are > 0, download a thumbnail.
 * @param imageView the imageView to fill when the image is downloaded
 * @param url the image url
 * @param width the expected image width
 * @param height the expected image height
 * @param rotationAngle the rotation angle (degrees)
 * @return a download identifier if the image is not cached
 */
public static String loadBitmap(ImageView imageView, String url, int width, int height, int rotationAngle) {
    return loadBitmap(imageView.getContext(), imageView, url, width, height, rotationAngle);
}

From source file:com.ruesga.rview.misc.Formatter.java

@BindingAdapter("fileTypeDrawable")
public static void toFileTypeDrawable(ImageView view, FileInfo model) {
    if (model == null || model.status == null) {
        view.setImageDrawable(null);//w  ww .  j  a v a 2 s  . c  o m
        return;
    }

    view.setImageDrawable(
            ContextCompat.getDrawable(view.getContext(), ModelHelper.toFileStatusDrawable(model.status)));
}

From source file:com.ruesga.rview.misc.Formatter.java

@BindingAdapter("emptyStateDrawable")
public static void toEmptyStateDrawable(ImageView v, EmptyState state) {
    if (state == null || state.state == EmptyState.NORMAL_STATE) {
        v.setImageDrawable(null);// w  w  w.  j ava 2 s . c om
    } else if (state.state == EmptyState.NO_RESULTS_STATE) {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_empty_results));
    } else if (state.state == EmptyState.ALL_DONE_STATE) {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_duck));
    } else if (state.state == EmptyState.NOT_CONNECTIVITY_STATE) {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_cloud_off));
    } else if (state.state == EmptyState.SERVER_CANNOT_BE_REACHED) {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_server_network_off));
    } else if (state.state == EmptyState.ERROR_STATE) {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), R.drawable.ic_error_outline));
    }
}

From source file:com.synconset.ImageFetcher.java

/**
 * Returns true if the current download has been canceled or if there was no
 * download in progress on this image view. Returns false if the download in
 * progress deals with the same url. The download is not stopped in that
 * case.//  w w w . ja  v  a  2  s.c  o  m
 */
private static boolean cancelPotentialDownload(Integer position, ImageView imageView) {
    BitmapFetcherTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);
    long origId = getOrigId(imageView);

    if (bitmapDownloaderTask != null) {
        Integer bitmapPosition = bitmapDownloaderTask.position;
        if ((bitmapPosition == null) || (!bitmapPosition.equals(position))) {
            // Log.d("DAVID", "Canceling...");
            MediaStore.Images.Thumbnails.cancelThumbnailRequest(imageView.getContext().getContentResolver(),
                    origId, 12345);
            bitmapDownloaderTask.cancel(true);
        } else {
            return false;
        }
    }
    return true;
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Load an image into a {@link ImageView} and apply a color filter
 *//*from  w w w.  j a va 2 s .com*/
public static void setDrawableWithColorToImageView(ImageView imageView, @DrawableRes int drawableResId,
        @ColorRes int colorResId) {
    imageView.setImageResource(drawableResId);
    imageView.setColorFilter(ContextCompat.getColor(imageView.getContext(), colorResId));
}

From source file:com.example.jhordan.euro_cleanarchitecture.view.activity.TeamDetailsActivity.java

private void getImage(String photo, ImageView photoImageView) {
    Picasso.with(photoImageView.getContext()).load(photo).fit().centerCrop().into(photoImageView);
}

From source file:vikrant.khaiwal.displayimage.main.DetailActivity.java

private void getImageDetails(String imageId) {

    RestClient.RestInterface service = RestClient.getClient(mContext);
    Call<MainClass> call = service.getDetailImages("pid:" + imageId, "pid,large_image_url,title", "1", "json");
    call.enqueue(new retrofit2.Callback<MainClass>() {
        @Override/*www  . ja  v a 2  s .c  o m*/
        public void onResponse(Call<MainClass> call, retrofit2.Response<MainClass> response) {
            if (response != null && response.isSuccessful() && response.errorBody() == null) {
                String itemTitle = response.body().getResponse().getDocs().get(0).getTitle();
                collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
                collapsingToolbarLayout.setTitle(response.body().getResponse().getDocs().get(0).getTitle());
                collapsingToolbarLayout
                        .setExpandedTitleColor(getResources().getColor(android.R.color.transparent));

                final ImageView image = (ImageView) findViewById(R.id.image);
                Picasso.with(image.getContext())
                        .load(response.body().getResponse().getDocs().get(0).getLarge_image_url()).into(image);

                TextView title = (TextView) findViewById(R.id.title);
                title.setText(itemTitle);
            }
        }

        @Override
        public void onFailure(Call<MainClass> call, Throwable t) {
            t.printStackTrace();
        }
    });
}

From source file:com.google.samples.apps.topeka.adapter.ScoreAdapter.java

private void setSolvedStateForQuiz(ImageView solvedState, int position) {
    final Context context = solvedState.getContext();
    final Drawable tintedImage;
    if (mCategory.isSolvedCorrectly(getItem(position))) {
        tintedImage = getSuccessIcon(context);
    } else {/*from   w w  w . ja  v  a  2s .  co m*/
        tintedImage = getFailedIcon(context);
    }
    solvedState.setImageDrawable(tintedImage);
}

From source file:sg.fxl.topeka.adapter.ScoreAdapter.java

private void setSolvedStateForQuiz(ImageView solvedState, int position) {
    final Context context = solvedState.getContext();
    final Drawable tintedImage;
    if (mQuiz.isSolvedCorrectly(getItem(position))) {
        tintedImage = getSuccessIcon(context);
    } else {/*from  w ww  .ja v  a 2 s.co  m*/
        tintedImage = getFailedIcon(context);
    }
    solvedState.setImageDrawable(tintedImage);
}