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.dm.wallpaper.board.adapters.WallpapersAdapter.java

private void setFavorite(@NonNull ImageView imageView, @ColorInt int color, int position, boolean animate) {
    if (position < 0 || position > mWallpapers.size())
        return;//from ww  w  . j av  a 2 s . c om

    if (mIsFavoriteMode) {
        if (!Preferences.get(mContext).isColoredWallpapersCard())
            color = ContextCompat.getColor(mContext, R.color.favoriteColor);
        imageView.setImageDrawable(
                DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_love, color));
        return;
    }

    final int favoriteColor;
    boolean isFavorite = mWallpapers.get(position).isFavorite();
    if (!Preferences.get(mContext).isColoredWallpapersCard() && isFavorite)
        favoriteColor = ContextCompat.getColor(mContext, R.color.favoriteColor);
    else
        favoriteColor = color;

    if (animate) {
        AnimationHelper.show(imageView).interpolator(new LinearOutSlowInInterpolator())
                .callback(new AnimationHelper.Callback() {
                    @Override
                    public void onAnimationStart() {
                        imageView.setImageDrawable(DrawableHelper.getTintedDrawable(mContext,
                                isFavorite ? R.drawable.ic_toolbar_love : R.drawable.ic_toolbar_unlove,
                                favoriteColor));
                    }

                    @Override
                    public void onAnimationEnd() {

                    }
                }).start();
        return;
    }

    imageView.setImageDrawable(DrawableHelper.getTintedDrawable(mContext,
            isFavorite ? R.drawable.ic_toolbar_love : R.drawable.ic_toolbar_unlove, favoriteColor));
}

From source file:com.arlib.floatingsearchview.util.view.MenuView.java

/**
 * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
 *
 * @param withAnim// w w  w .j a v a2  s.co m
 */
public void showIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    cancelChildAnimListAndClear();

    if (mMenuItems.isEmpty())
        return;

    anims = new ArrayList<>();

    for (int i = 0; i < getChildCount(); i++) {

        final View currentView = getChildAt(i);

        if (i < mActionItems.size()) {
            ImageView action = (ImageView) currentView;
            final MenuItem actionItem = mActionItems.get(i);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

            action.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mMenuCallback != null)
                        mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
                }
            });
        }

        //todo go over logic
        int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0;

        Interpolator interpolator = new DecelerateInterpolator();

        //todo check logic
        if (i > mActionShowAlwaysItems.size() - 1)
            interpolator = new LinearInterpolator();

        currentView.setClickable(true);
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setTranslationX(0);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleX(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setScaleY(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {

                currentView.setAlpha(1.0f);
            }
        }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get());
    }

    AnimatorSet animSet = new AnimatorSet();

    //temporary, from laziness
    if (!withAnim)
        animSet.setDuration(0);
    animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
    animSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            if (mOnVisibleWidthChanged != null)
                mOnVisibleWidthChanged.onVisibleWidthChanged(
                        (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0));
        }
    });
    animSet.start();

}

From source file:com.c4mprod.utils.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.
 *//*w w  w  .  j  av a  2 s.c  o m*/
private void forceDownload(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)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            task = new BitmapDownloaderTask(imageView);
            imageView.setBackgroundDrawable((default_img));
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);

            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:cat.joronya.utils.image.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.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *///from   w w w  .  ja  va 2s.  c o  m
public void download(String url, ImageView imageView, Drawable defaultDrawable) {
    this.defaultDrawable = defaultDrawable;
    resetPurgeTimer();

    // esta a notFounds?
    if (notFounds.contains(url)) {
        imageView.setImageDrawable(defaultDrawable);
        return;
    }

    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.avapira.bobroreader.Bober.java

private DrawerBuilder generateBoardsDrawerBuilder(Bundle savedInstanceState, Toolbar toolbar) {
    ImageView image = (ImageView) LayoutInflater.from(getApplicationContext())
            .inflate(R.layout.activity_bober_drawer_boards_header_horo, null);
    Drawable horo = getDrawable(R.drawable.acc39fc867f_transparent);
    image.setImageDrawable(horo);
    return new DrawerBuilder().withActivity(Bober.this).withFullscreen(true).withToolbar(toolbar)
            .withHeaderDivider(false).withHeader(image).withDrawerItems(new BoardItemGenerator().getItems())
            .withSavedInstance(savedInstanceState).withOnDrawerItemClickListener(new BoardSwitcher())
            .withOnDrawerListener(new Drawer.OnDrawerListener() {
                @Override/*from  www. j  a v  a  2s.c  om*/
                public void onDrawerOpened(View drawerView) {
                    Bober.this.invalidateOptionsMenu();
                }

                @Override
                public void onDrawerClosed(View drawerView) {
                    Bober.this.invalidateOptionsMenu();
                }

                @Override
                public void onDrawerSlide(View arg0, float slideOffset) {
                }

            }).withActionBarDrawerToggleAnimated(true);
}

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

protected void setSearchImage(Drawable image, LinearLayout linearLayout) {
    ImageView searchViewIcon = null;

    for (int i = 0; i < linearLayout.getChildCount(); i++) {
        View view = linearLayout.getChildAt(i);
        if (view instanceof ImageView) {
            searchViewIcon = (ImageView) view;
            break;
        }//  w w w.j a  v  a  2s.  c  o  m
    }
    searchViewIcon.setImageDrawable(image);
}

From source file:com.TakeTaxi.jy.OnrouteScreen.java

public void pingpicked(JSONObject json) {

    try {//from   w  w  w  .j  av  a2 s  .c  o m

        int driverpicked = json.getInt("picked");
        int drivercancelled = json.getInt("dcancel");
        int starttime = json.getInt("datetime");

        // /////////////////////////////// DRIVER CANCEL ////////
        if (drivercancelled == 1) {

            // //// DRIVER CANCEL LATE /////

            if (starttime + 300 <= Query.getServerTime()) {
                handlerboolean = false;
                handler.removeCallbacks(r);

                AlertDialog dcancelbuilder = new AlertDialog.Builder(OnrouteScreen.this).create();
                dcancelbuilder
                        .setMessage("Job has been cancelled.\nWould you like to report a late cancellation?.");

                // //// DRIVER CANCEL LATE - NO REPORT LATE/////
                button_cancelJob_noquery(dcancelbuilder);
                // //// DRIVER CANCEL LATE - REPORT LATE /////
                button_drivercancel_reportlate(dcancelbuilder);

                dcancelbuilder.show();

            } else {
                // /////////////////////////////// DRIVER CANCEL NO ALERTS -
                // WITHIN TIME LIMIT///////////////
                handlerboolean = false;
                handler.removeCallbacks(r);

                alertdialog_drivercancelintime();

            }
        }
        if (driverpicked == 1) {
            // /////////////////////////////// CONFIRM PICK UP
            // ///////////////////////////////////////////

            handlerboolean = false;
            handler.removeCallbacks(r);
            AlertDialog.Builder alert = new AlertDialog.Builder(OnrouteScreen.this);
            final Drawable thumbsup = getResources().getDrawable(R.drawable.thumbsup);
            final Drawable thumbsupwhite = getResources().getDrawable(R.drawable.thumbsupwhite);
            final Drawable thumbsdown = getResources().getDrawable(R.drawable.thumbsdown);
            final Drawable thumbsdownwhite = getResources().getDrawable(R.drawable.thumbsdownwhite);
            LinearLayout layout = new LinearLayout(OnrouteScreen.this);
            layout.setOrientation(1);
            layout.setGravity(17);

            TextView tx1 = new TextView(OnrouteScreen.this);
            tx1.setText("Driver says you have been picked up");
            tx1.setGravity(17);
            tx1.setTextSize(20);
            tx1.setTextColor(Color.WHITE);
            tx1.setPadding(10, 10, 10, 10);

            TextView tx2 = new TextView(OnrouteScreen.this);
            tx2.setText("Please rate your driver");
            tx2.setGravity(17);
            tx2.setTextSize(16);

            LinearLayout imglayout = new LinearLayout(OnrouteScreen.this);
            imglayout.setOrientation(0);
            imglayout.setGravity(17);

            final ImageView ivup = new ImageView(OnrouteScreen.this);
            ivup.setImageDrawable(thumbsupwhite);
            ivup.setClickable(true);
            ivup.setPadding(0, 5, 30, 5);
            final ImageView ivdown = new ImageView(OnrouteScreen.this);
            ivdown.setImageDrawable(thumbsdownwhite);
            ivdown.setClickable(true);
            ivup.setPadding(30, 5, 0, 5);
            imglayout.addView(ivup);
            imglayout.addView(ivdown);

            layout.addView(tx1);
            layout.addView(tx2);

            layout.addView(imglayout);
            // /////////////////////////////// CONFIRM PICK UP - RATINGS
            // ///////////////////////////////////////////

            ivup.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsupboolean == false) {
                        thumbsupboolean = true;
                        thumbsdownboolean = false;
                        ivup.setImageDrawable(thumbsup);
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 1;
                    } else {
                        thumbsupboolean = false;
                        ivup.setImageDrawable(thumbsupwhite);
                        rating = 0;
                    }

                }
            });

            ivdown.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    if (thumbsdownboolean == false) {
                        thumbsdownboolean = true;
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdown);
                        ivup.setImageDrawable(thumbsupwhite);

                        AlertDialog alert = new AlertDialog.Builder(OnrouteScreen.this).create();

                        alert.setMessage("Please pick one");
                        alert.setButton("No show", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -1;
                            }
                        });
                        alert.setButton2("Driver late", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -2;
                            }
                        });
                        alert.setButton3("Poor service", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                rating = -3;
                            }
                        });
                        alert.show();

                    } else {
                        thumbsupboolean = false;
                        ivdown.setImageDrawable(thumbsdownwhite);
                        rating = 0;
                    }

                }
            });

            button_completed_finish(alert);

            alert.setView(layout);
            alert.create();
            alert.show();
        } else {
        }

    } catch (JSONException e) {
    }
}

From source file:android_network.hetnet.vpn_service.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*from   www.  j  a  va  2  s  .c om*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
    final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
    TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
    TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    tvDest.setText(
            Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : ""));

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:com.fivetrue.workout.timer.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, Drawable drawable) {

    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);/*from w  w  w  .  java  2s .  com*/
    tab.setImageDrawable(drawable);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tab.setSelected(currentPosition == position);
    LinearLayout.LayoutParams params = defaultTabLayoutParams;
    if (shouldExpand) {
        params = expandedTabLayoutParams;
    }
    tabsContainer.addView(tab, params);

}

From source file:com.hunch.ImageManager.java

public void getTopicImage(final Context context, final ImageView image, final String imgURL) {
    URL url = stringToURL(imgURL);
    Drawable cachedDrawable = getCachedTopicImage(context, url);

    if (cachedDrawable != null) {
        // the image is in the cache
        image.setImageDrawable(cachedDrawable);
    } else {/*from   w  ww .ja v  a  2  s. co  m*/
        // the image is not in the cache, must download
        downloadTopicDrawable(url, context, new Callback() {

            @Override
            public void callComplete(Drawable d) {
                image.setImageDrawable(d);
            }
        });

        // set it to the placeholder image for now
        image.setImageResource(Const.TOPIC_DEFAULT_IMG);
    }
}