Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

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

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.google.wolff.androidhunt.Hunt.java

/** Return value: Whether or not it needs to load from web. */
public void setClueImage(Resources res, ImageView imgView) {
    final Clue clue = getCurrentClue();

    if (hrm.drawables.get(clue.displayImage) == null) {
        imgView.setImageDrawable(res.getDrawable(R.drawable.ab_icon));
    } else {/*from   w w w  . j  ava2 s. c o m*/
        imgView.setImageDrawable(hrm.drawables.get(clue.displayImage));
    }
}

From source file:at.zone.madeleine.slideshow.ImageDownloader.java

/**
 * Same as download but the image is always downloaded.
 *//*from  ww  w.  ja  va 2 s . c  o m*/
private void doDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(url);
    }
}

From source file:com.example.imagedownloader.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the
 * provided ImageView. The binding is immediate if the image is found in the
 * cache and will be done asynchronously otherwise. A null bitmap will be
 * associated to the ImageView if an error occurs.
 * /*from w w w .  j a  v a 2  s  .c  o m*/
 * @param url
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 */
public void download(String url, ImageView imageView) {
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }
    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(context.getResources(),
                mPlaceHolderBitmap, task);
        imageView.setImageDrawable(downloadedDrawable);
        imageView.setMinimumHeight(156);
        task.execute(url);
    }
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

public BGAViewHolderHelper setImageDrawable(@IdRes int viewId, Drawable drawable) {
    ImageView view = getView(viewId);
    view.setImageDrawable(drawable);
    return this;
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

private ImageView getRotationImage() {
    RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setDuration(1000L);//from ww w  .j a v a 2s  .c  o  m
    rotateAnimation.setRepeatMode(Animation.INFINITE);
    rotateAnimation.setRepeatCount(Animation.INFINITE);
    rotateAnimation.setFillEnabled(false);
    rotateAnimation.setInterpolator(new LinearInterpolator());

    Drawable drawable = MBResourceService.getInstance().getImageByID(_refreshToolDef.getIcon());
    ImageView rotationImage = new ImageView(_context);
    rotationImage.setImageDrawable(drawable);
    rotationImage.setAnimation(rotateAnimation);

    return rotationImage;
}

From source file:smartparking.smartparking.util.ImageDownloader.java

/**
 * Same as download but the image is always downloaded and the cache is not used.
 * Kept private at the moment as its interest is not clear.
 *//*from ww  w . j a v a  2 s.c  o  m*/
private void forceDownload(String url, ImageView imageView, String cookie) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }
    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        task.execute(url, cookie);
    }
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

public BaseViewHolderHelper setImageDrawable(@IdRes int viewId, Drawable drawable) {
    ImageView view = getView(viewId);
    view.setImageDrawable(drawable);
    return this;
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

private void setMdmIcon(String packageName) {
    if (packageName != null) {
        PackageManager pm = getPackageManager();
        try {/*from   ww  w  .j  av  a 2s. co m*/
            ApplicationInfo ai = pm.getApplicationInfo(packageName, /* default flags */ 0);
            if (ai != null) {
                Drawable packageIcon = pm.getApplicationIcon(packageName);
                ImageView imageView = (ImageView) findViewById(R.id.mdm_icon_view);
                imageView.setImageDrawable(packageIcon);

                String appLabel = pm.getApplicationLabel(ai).toString();
                TextView deviceManagerName = (TextView) findViewById(R.id.device_manager_name);
                deviceManagerName.setText(appLabel);
            }
        } catch (PackageManager.NameNotFoundException e) {
            // Package does not exist, ignore. Should never happen.
            ProvisionLogger.loge("Package does not exist. Should never happen.");
        }
    }
}

From source file:com.google.android.apps.muzei.TutorialFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    view.findViewById(R.id.tutorial_icon_affordance).setOnClickListener(new View.OnClickListener() {
        @Override/*from   w ww.j  av a2  s .c  om*/
        public void onClick(View view) {
            FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE,
                    null);
            final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
            sp.edit().putBoolean(PREF_SEEN_TUTORIAL, true).apply();
        }
    });

    if (savedInstanceState == null) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = view.findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = view.findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = view.findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = view.findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(500);
        mAnimator.setDuration(250);
        mAnimator.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        mAnimator.start();
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        mAnimator.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (isAdded()) {
                        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
                        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
                        emanateView.setImageDrawable(avd);
                        avd.start();
                    }
                }
            });
        }
        mAnimator.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
        emanateView.setImageDrawable(avd);
        avd.start();
    }
}

From source file:com.google.android.apps.santatracker.games.SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    // Immersive mode (to hide nav).
    ImmersiveModeHelper.setImmersiveSticky(getWindow());

    // Get Views//from   w  w w  . jav  a 2s  . c om
    ImageView splashImageView = (ImageView) findViewById(R.id.splash_image);
    TextView splashTitleView = (TextView) findViewById(R.id.splash_title);

    // Set Image
    mSplashImage = ContextCompat.getDrawable(this, getIntent().getIntExtra(EXTRA_SPLASH_IMAGE_ID, -1));
    if (mSplashImage != null) {
        splashImageView.setImageDrawable(mSplashImage);
    }

    // Set Title
    mSplashTitle = getString(getIntent().getIntExtra(EXTRA_SPLASH_TITLE_ID, -1));
    splashTitleView.setText(mSplashTitle);

    // Make text "Lobster" font
    FontHelper.makeLobster(splashTitleView);

    // Start new activity in 1000ms
    final Class classToLaunch = (Class) getIntent().getSerializableExtra(EXTRA_GAME_CLASS);
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(SplashActivity.this, classToLaunch));
            finish();
        }
    }, DELAY_MILLIS);
}