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:cat.joronya.utils.image.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 www  . j a  v a 2s  .  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(defaultDrawable);
        return;
    }

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

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.CharacterCardView.java

public void updateUi(Card card) {
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    primaryText.setText(card.getTitle());
    if (card.getLocalImageResourceName() != null) {
        int resourceId = card.getLocalImageResourceId(getContext());
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resourceId);
        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(),
                bitmap);// w w w.j  a  v  a  2s . c om
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.koushikdutta.superuser.MultitaskSuRequestActivity.java

void requestReady() {
    findViewById(R.id.incoming).setVisibility(View.GONE);
    findViewById(R.id.ready).setVisibility(View.VISIBLE);

    final View packageInfo = findViewById(R.id.packageinfo);
    final PackageManager pm = getPackageManager();
    String[] pkgs = pm.getPackagesForUid(mCallerUid);
    TextView unknown = (TextView) findViewById(R.id.unknown);
    unknown.setText(getString(R.string.unknown_uid, mCallerUid));

    final View appInfo = findViewById(R.id.app_info);
    appInfo.setOnClickListener(new OnClickListener() {
        @Override/*from w w  w  .j  a  v  a  2s  .  c  om*/
        public void onClick(View v) {
            if (packageInfo.getVisibility() == View.GONE) {
                appInfo.setVisibility(View.GONE);
                packageInfo.setVisibility(View.VISIBLE);
            }
        }
    });

    packageInfo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (appInfo.getVisibility() == View.GONE) {
                appInfo.setVisibility(View.VISIBLE);
                packageInfo.setVisibility(View.GONE);
            }
        }
    });

    ((TextView) findViewById(R.id.uid_header)).setText(Integer.toString(mDesiredUid));
    ((TextView) findViewById(R.id.command_header)).setText(mDesiredCmd);

    boolean superuserDeclared = false;
    boolean granted = false;
    if (pkgs != null && pkgs.length > 0) {
        for (String pkg : pkgs) {
            try {
                PackageInfo pi = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS);
                ((TextView) findViewById(R.id.request))
                        .setText(getString(R.string.application_request, pi.applicationInfo.loadLabel(pm)));
                ImageView icon = (ImageView) packageInfo.findViewById(R.id.image);
                icon.setImageDrawable(pi.applicationInfo.loadIcon(pm));
                ((TextView) packageInfo.findViewById(R.id.title)).setText(pi.applicationInfo.loadLabel(pm));

                ((TextView) findViewById(R.id.app_header)).setText(pi.applicationInfo.loadLabel(pm));
                ((TextView) findViewById(R.id.package_header)).setText(pi.packageName);

                if (pi.requestedPermissions != null) {
                    for (String perm : pi.requestedPermissions) {
                        if (PERMISSION.equals(perm)) {
                            superuserDeclared = true;
                            break;
                        }
                    }
                }

                granted |= checkPermission(PERMISSION, mPid, mCallerUid) == PackageManager.PERMISSION_GRANTED;

                // could display them all, but screw it...
                // maybe a better ux for this later
                break;
            } catch (Exception ex) {
            }
        }
        findViewById(R.id.unknown).setVisibility(View.GONE);
    }

    if (!superuserDeclared) {
        findViewById(R.id.developer_warning).setVisibility(View.VISIBLE);
    }

    // handle automatic responses
    // these will be considered permanent user policies
    // even though they are automatic.
    // this is so future su requests dont invoke ui

    // handle declared permission
    if (Settings.getRequirePermission(MultitaskSuRequestActivity.this) && !superuserDeclared) {
        Log.i(LOGTAG, "Automatically denying due to missing permission");
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (!mHandled)
                    handleAction(false, 0);
            }
        });
        return;
    }

    // automatic response
    switch (Settings.getAutomaticResponse(MultitaskSuRequestActivity.this)) {
    case Settings.AUTOMATIC_RESPONSE_ALLOW:
        //            // automatic response and pin can not be used together
        //            if (Settings.isPinProtected(MultitaskSuRequestActivity.this))
        //                break;
        // check if the permission must be granted 
        if (Settings.getRequirePermission(MultitaskSuRequestActivity.this) && !granted)
            break;
        Log.i(LOGTAG, "Automatically allowing due to user preference");
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (!mHandled)
                    handleAction(true, 0);
            }
        });
        return;
    case Settings.AUTOMATIC_RESPONSE_DENY:
        Log.i(LOGTAG, "Automatically denying due to user preference");
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (!mHandled)
                    handleAction(false, 0);
            }
        });
        return;
    }

    new Runnable() {
        public void run() {
            mAllow.setText(getString(R.string.allow) + " (" + mTimeLeft + ")");
            if (mTimeLeft-- <= 0) {
                mAllow.setText(getString(R.string.allow));
                if (!mHandled)
                    mAllow.setEnabled(true);
                return;
            }
            mHandler.postDelayed(this, 1000);
        };
    }.run();
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPlayView.java

/**
 * .// www.java 2 s .c  o  m
 */
public void creatIndex() {
    //?
    navLinearLayout.removeAllViews();
    mNavLayoutParent.setHorizontalGravity(navHorizontalGravity);
    navLinearLayout.setGravity(Gravity.CENTER);
    navLinearLayout.setVisibility(View.VISIBLE);
    count = mListViews.size();
    navLayoutParams.setMargins(5, 5, 5, 5);
    navLayoutParams.width = 15;
    navLayoutParams.height = 15;
    for (int j = 0; j < count; j++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(navLayoutParams);
        if (j == 0) {
            imageView.setImageDrawable(displayDrawable);
        } else {
            imageView.setImageDrawable(hideDrawable);
        }
        AbViewUtil.scaleView(imageView);
        navLinearLayout.addView(imageView, j);
    }

}

From source file:co.tinode.tindroid.ImageLoader.java

/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageLoader#processBitmap(Object)} to define the processing logic). If the image is
 * found in the memory cache, it is set immediately, otherwise an {@link AsyncTask} will be
 * created to asynchronously load the bitmap.
 *
 * @param data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//*  w  w w  . j  ava  2  s  .c o  m*/
public void loadImage(Object data, ImageView imageView) {
    if (data == null) {
        return;
    }

    Bitmap bitmap = getBitmapFromCache(String.valueOf(data));

    if (bitmap != null) {
        // Bitmap found in memory cache
        imageView.setImageDrawable(new RoundedImage(bitmap));
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);
        task.execute(data);
    }
}

From source file:com.bangqu.eshow.view.sliding.ESSlidingPlayView.java

/**
 * ./*from   ww  w  .  ja v  a 2  s  .com*/
 */
public void creatIndex() {
    //?
    navLinearLayout.removeAllViews();
    mNavLayoutParent.setHorizontalGravity(navHorizontalGravity);
    navLinearLayout.setGravity(Gravity.CENTER);
    navLinearLayout.setVisibility(View.VISIBLE);
    count = mListViews.size();
    navLayoutParams.setMargins(5, 5, 5, 5);
    navLayoutParams.width = 15;
    navLayoutParams.height = 15;
    for (int j = 0; j < count; j++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(navLayoutParams);
        if (j == 0) {
            imageView.setImageDrawable(displayDrawable);
        } else {
            imageView.setImageDrawable(hideDrawable);
        }
        ESViewUtil.scaleView(imageView);
        navLinearLayout.addView(imageView, j);
    }

}

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

/**
 * Hides all the menu items flagged with "ifRoom"
 *
 * @param withAnim/*from w  w  w  .ja v  a  2s  .  c  o m*/
 */
public void hideIfRoomItems(boolean withAnim) {

    if (mMenu == -1)
        return;

    mActionShowAlwaysItems.clear();
    cancelChildAnimListAndClear();

    List<MenuItemImpl> showAlwaysActionItems = filter(mMenuItems, new MenuItemImplPredicate() {
        @Override
        public boolean apply(MenuItemImpl menuItem) {
            return menuItem.requiresActionButton();
        }
    });

    int actionItemIndex;
    for (actionItemIndex = 0; actionItemIndex < mActionItems.size()
            && actionItemIndex < showAlwaysActionItems.size(); actionItemIndex++) {

        final MenuItemImpl actionItem = showAlwaysActionItems.get(actionItemIndex);

        if (mActionItems.get(actionItemIndex).getItemId() != showAlwaysActionItems.get(actionItemIndex)
                .getItemId()) {

            ImageView action = (ImageView) getChildAt(actionItemIndex);
            action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor));

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

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

        }

        mActionShowAlwaysItems.add(actionItem);
    }

    final int diff = mActionItems.size() - actionItemIndex + (mHasOverflow ? 1 : 0);

    anims = new ArrayList<>();

    for (int i = 0; i < actionItemIndex; i++) {
        final View currentChild = getChildAt(i);
        final float destTransX = ACTION_DIMENSION_PX * diff - (mHasOverflow ? Util.dpToPx(8) : 0);
        anims.add(ViewPropertyObjectAnimator.animate(currentChild)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .setInterpolator(new AccelerateInterpolator()).addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentChild.setTranslationX(destTransX);
                    }
                }).translationXBy(destTransX).get());
    }

    for (int i = actionItemIndex; i < diff + actionItemIndex; i++) {

        final View currentView = getChildAt(i);

        currentView.setClickable(false);

        if (i != getChildCount() - 1)
            anims.add(ViewPropertyObjectAnimator.animate(currentView)
                    .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                    .addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {

                            currentView.setTranslationX(ACTION_DIMENSION_PX);
                        }
                    }).translationXBy(ACTION_DIMENSION_PX).get());

        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleX(0.5f);
                    }
                }).scaleX(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(currentView)
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setScaleY(0.5f);
                    }
                }).scaleY(.5f).get());
        anims.add(ViewPropertyObjectAnimator.animate(getChildAt(i))
                .setDuration(withAnim ? HIDE_IF_ROOM_ITEMS_ANIM_DURATION : 0)
                .addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {

                        currentView.setAlpha(0.0f);
                    }
                }).alpha(0.0f).get());
    }

    final int actinItemsCount = actionItemIndex;
    if (!anims.isEmpty()) {

        AnimatorSet animSet = new AnimatorSet();
        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(((int) ACTION_DIMENSION_PX * actinItemsCount));
            }
        });
        animSet.start();
    }

}

From source file:com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    packageManager = getActivity().getPackageManager();
    List<DisplayInfo> displayInfos = getDisplayInfos();

    ArrayAdapter<DisplayInfo> arrayAdapter = new ArrayAdapter<DisplayInfo>(getActivity(),
            R.layout.choose_activity_list_item, R.id.choose_activity_list_item_text1, displayInfos) {
        @Override//www . ja  va 2s  .co m
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            if (convertView == null) {
                view = getActivity().getLayoutInflater().inflate(R.layout.choose_activity_list_item, parent,
                        false);
            } else {
                view = convertView;
            }
            DisplayInfo displayInfo = getItem(position);
            TextView text1 = (TextView) view.findViewById(R.id.choose_activity_list_item_text1);
            TextView text2 = (TextView) view.findViewById(R.id.choose_activity_list_item_text2);
            ImageView icon = (ImageView) view.findViewById(R.id.choose_activity_list_item_icon);
            text1.setText(displayInfo.primaryLabel);
            if (displayInfo.secondaryLabel != null) {
                text2.setVisibility(View.VISIBLE);
                text2.setText(displayInfo.secondaryLabel);
            } else {
                text2.setVisibility(View.GONE);
            }
            icon.setImageDrawable(displayInfo.icon);
            return view;
        }
    };
    return new AlertDialog.Builder(getActivity())
            .setSingleChoiceItems(arrayAdapter, 0, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AlertDialog alertDialog = (AlertDialog) dialog;
                    DisplayInfo displayInfo = (DisplayInfo) alertDialog.getListView().getItemAtPosition(which);
                    ActivityInfo activityInfo = displayInfo.resolveInfo.activityInfo;
                    String packageName = activityInfo.applicationInfo.packageName;
                    String className = activityInfo.name;

                    long trackId = getArguments().getLong(KEY_TRACK_ID);
                    String trackUrl = getArguments().getString(KEY_TRACK_URL);
                    if (trackUrl == null) {
                        SendRequest sendRequest = new SendRequest(trackId);
                        sendRequest.setSendMaps(true);
                        sendRequest.setNewMap(true);
                        sendRequest.setSharingAppPackageName(packageName);
                        sendRequest.setSharingAppClassName(className);
                        Intent intent = IntentUtils.newIntent(getActivity(), ConfirmSharingActivity.class)
                                .putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
                        startActivity(intent);
                        dismiss();
                    } else {
                        Intent intent = IntentUtils.newShareUrlIntent(getActivity(), trackId, trackUrl,
                                packageName, className);
                        startActivity(intent);
                        getActivity().finish();
                    }
                }
            }).setTitle(R.string.share_track_picker_title).create();
}

From source file:com.kiddobloom.bucketlist.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 ww . j av  a  2  s.  co m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    //Log.d("tag", "download " + url + " imageView: " + imageView);

    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);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java

/**
 * Private convenience methods used by this class.
 */// www  .  jav a  2  s .  c om
private void setActiveIndicator(int position) {
    if (mIndicatorContainer.findViewWithTag(TAG_CIRCLE) == null) {
        // No indicators yet, let's make some. Only run once per configuration.
        for (int i = 0; i < getCount(); i++) {
            ImageView indicator = (ImageView) View.inflate(mContext, R.layout.swipeselector_circle_item, null);

            if (i == position) {
                indicator.setImageDrawable(mActiveCircleDrawable);
            } else {
                indicator.setImageDrawable(mInActiveCircleDrawable);
            }

            indicator.setLayoutParams(mCircleParams);
            indicator.setTag(TAG_CIRCLE);
            mIndicatorContainer.addView(indicator);
        }
        return;
    }

    ImageView previousActiveIndicator = (ImageView) mIndicatorContainer.getChildAt(mCurrentPosition);
    ImageView nextActiveIndicator = (ImageView) mIndicatorContainer.getChildAt(position);

    previousActiveIndicator.setImageDrawable(mInActiveCircleDrawable);
    nextActiveIndicator.setImageDrawable(mActiveCircleDrawable);

    mCurrentPosition = position;

    if (mOnItemSelectedListener != null) {
        mOnItemSelectedListener.onItemSelected(getSelectedItem());
    }
}