Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

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

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:com.serenegiant.testmediastore.MediaStorePhotoAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // this method is called within UI thread and should return as soon as possible
    final ViewHolder holder = getViewHolder(view);
    final ImageView iv = holder.mImageView;
    final TextView tv = holder.mTitleView;
    Drawable drawable = iv.getDrawable();
    if ((drawable == null) || !(drawable instanceof LoaderDrawable)) {
        drawable = new LoaderDrawable(mCr);
        iv.setImageDrawable(drawable);/*  w  w w  .  j a v a 2s .c  o  m*/
    }
    ((LoaderDrawable) drawable).startLoad(cursor.getLong(PROJ_INDEX_ID));
    if (tv != null) {
        tv.setVisibility(mShowTitle ? View.VISIBLE : View.GONE);
        if (mShowTitle)
            tv.setText(cursor
                    .getString(mDisplayType == DISPLAY_IMAGE ? PROJ_INDEX_TITLE : PROJ_INDEX_BUCKET_NAME));
    }
}

From source file:com.he5ed.lib.cloudprovider.picker.PickerFragment.java

private View swapOutEmptyViewDetails(View oldView, View newView) {
    if (oldView == null && newView == null) {
        return null;
    } else if (oldView == null) {
        return newView;
    } else if (newView == null) {
        return oldView;
    }/*  w  ww.j  av  a  2 s . co m*/

    ImageView oldIcon = (ImageView) oldView.findViewById(R.id.empty_icon_image_view);
    TextView oldTitle = (TextView) oldView.findViewById(R.id.empty_title_text_view);
    TextView oldDetail = (TextView) oldView.findViewById(R.id.empty_detail_text_view);

    ImageView newIcon = (ImageView) newView.findViewById(R.id.empty_icon_image_view);
    TextView newTitle = (TextView) newView.findViewById(R.id.empty_title_text_view);
    TextView newDetail = (TextView) newView.findViewById(R.id.empty_detail_text_view);
    newIcon.setImageDrawable(oldIcon.getDrawable());
    newTitle.setText(oldTitle.getText());
    newDetail.setText(oldDetail.getText());

    return newView;
}

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  w ww  .  java2 s . c  o  m*/
    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.master.metehan.filtereagle.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//  www  .j  ava2 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) && tvDest.getTag() == null)
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                tvDest.setTag(id);
            }

            @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) {
                Object tag = tvDest.getTag();
                if (tag != null && (Long) tag == id)
                    tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                            + (dport > 0 ? "/" + dport : ""));
                tvDest.setTag(null);
            }
        }.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:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java

protected void displayAccountBanner(@NonNull ParcelableAccount account) {
    final int bannerWidth = mAccountProfileBannerView.getWidth();
    final Resources res = getResources();
    final int defWidth = res.getDisplayMetrics().widthPixels;
    final int width = bannerWidth > 0 ? bannerWidth : defWidth;
    final ImageView bannerView = (ImageView) mAccountProfileBannerView.getNextView();
    if (bannerView.getDrawable() == null || !CompareUtils.objectEquals(account, bannerView.getTag())) {
        mMediaLoader.displayProfileBanner(bannerView, account, width);
        bannerView.setTag(account);//from   www .jav  a 2 s.  c o  m
    } else {
        mMediaLoader.cancelDisplayTask(bannerView);
    }
}

From source file:com.musenkishi.wally.fragments.SearchFragment.java

private void setupAdapter() {

    imagesAdapter.setOnGetViewListener(new RecyclerImagesAdapter.OnGetViewListener() {
        @Override//from  w  w  w.ja va 2 s  .  c om
        public void onBindView(int position) {
            if (gridView.getAdapter() != null) {
                getMoreImagesIfNeeded(position, imagesAdapter.getItemCount());
            }
        }
    });

    imagesAdapter.setOnItemClickListener(new RecyclerImagesAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Image image = (Image) imagesAdapter.getItem(position);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(image.imagePageURL()), view.getContext(),
                    ImageDetailsActivity.class);

            ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumb_image_view);

            Bitmap thumb = null;

            intent.putExtra(ImageDetailsActivity.INTENT_EXTRA_IMAGE, image);

            if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof GlideBitmapDrawable) {
                GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) thumbnailImageView
                        .getDrawable();
                thumb = glideBitmapDrawable.getBitmap();
            } else if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof TransitionDrawable) {
                GlideBitmapDrawable squaringDrawable = (GlideBitmapDrawable) ((TransitionDrawable) thumbnailImageView
                        .getDrawable()).getDrawable(1);
                thumb = squaringDrawable.getBitmap();
            }
            WallyApplication.setBitmapThumb(thumb);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0)
                        .toBundle();
                getActivity().startActivityForResult(intent, REQUEST_CODE, bundle);
            } else {
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    });
}

From source file:org.mariotaku.twidere.view.CardMediaContainer.java

public void displayMedia(@NonNull final MediaLoaderWrapper loader, @Nullable final ParcelableMedia[] mediaArray,
        final UserKey accountId, @Nullable final OnMediaClickListener mediaClickListener,
        @Nullable final MediaLoadingHandler loadingHandler, final long extraId, boolean withCredentials) {
    if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) {
        for (int i = 0, j = getChildCount(); i < j; i++) {
            final View child = getChildAt(i);
            child.setTag(null);/*from w w  w.ja v a  2  s. co m*/
            child.setVisibility(GONE);
        }
        return;
    }
    final View.OnClickListener clickListener = new ImageGridClickListener(mediaClickListener, accountId,
            extraId);
    for (int i = 0, j = getChildCount(), k = mediaArray.length; i < j; i++) {
        final View child = getChildAt(i);
        if (mediaClickListener != null) {
            child.setOnClickListener(clickListener);
        }
        final ImageView imageView = (ImageView) child.findViewById(R.id.mediaPreview);
        switch (mMediaPreviewStyle) {
        case VALUE_MEDIA_PREVIEW_STYLE_CODE_CROP: {
            imageView.setScaleType(ScaleType.CENTER_CROP);
            break;
        }
        case VALUE_MEDIA_PREVIEW_STYLE_CODE_SCALE: {
            imageView.setScaleType(ScaleType.FIT_CENTER);
            break;
        }
        }
        if (i < k) {
            final ParcelableMedia media = mediaArray[i];
            final String url = TextUtils.isEmpty(media.preview_url) ? media.media_url : media.preview_url;
            if (ObjectUtils.notEqual(url, imageView.getTag()) || imageView.getDrawable() == null) {
                if (withCredentials) {
                    loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler);
                } else {
                    loader.displayPreviewImage(imageView, url, loadingHandler);
                }
            }
            imageView.setTag(url);
            if (imageView instanceof MediaPreviewImageView) {
                ((MediaPreviewImageView) imageView)
                        .setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(media.type));
            }
            if (TextUtils.isEmpty(media.alt_text)) {
                child.setContentDescription(getContext().getString(R.string.media));
            } else {
                child.setContentDescription(media.alt_text);
            }
            child.setTag(media);
            child.setVisibility(VISIBLE);
        } else {
            loader.cancelDisplayTask(imageView);
            imageView.setTag(null);
            child.setVisibility(GONE);
        }
    }
}

From source file:com.bitants.wally.fragments.SearchFragment.java

private void setupAdapter() {

    imagesAdapter.setOnGetViewListener(new RecyclerImagesAdapter.OnGetViewListener() {
        @Override/*from   w  ww  .j a va 2  s. co  m*/
        public void onBindView(int position) {
            if (gridView.getAdapter() != null) {
                getMoreImagesIfNeeded(position, imagesAdapter.getItemCount());
            }
        }
    });

    imagesAdapter.setOnItemClickListener(new RecyclerImagesAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Image image = (Image) imagesAdapter.getItem(position);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(image.imagePageURL()), view.getContext(),
                    ImageDetailsActivity.class);

            ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumb_image_view);

            Bitmap thumb = null;

            intent.putExtra(ImageDetailsActivity.INTENT_EXTRA_IMAGE, image);

            if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof GlideBitmapDrawable) {
                GlideBitmapDrawable glideBitmapDrawable = (GlideBitmapDrawable) thumbnailImageView
                        .getDrawable();
                thumb = glideBitmapDrawable.getBitmap();
            } else if (thumbnailImageView != null && thumbnailImageView.getDrawable() != null
                    && thumbnailImageView.getDrawable() instanceof TransitionDrawable) {
                GlideBitmapDrawable squaringDrawable = (GlideBitmapDrawable) ((TransitionDrawable) thumbnailImageView
                        .getDrawable()).getDrawable(1);
                thumb = squaringDrawable.getBitmap();
            }
            WallyApplication.setBitmapThumb(thumb);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                String transitionNameImage = getString(R.string.transition_image_details);
                ActivityOptionsCompat options = ActivityOptionsCompat
                        .makeSceneTransitionAnimation(getActivity(), android.support.v4.util.Pair
                                .create(view.findViewById(R.id.thumb_image_view), transitionNameImage));
                ActivityCompat.startActivityForResult(getActivity(), intent,
                        ImageDetailsActivity.REQUEST_EXTRA_TAG, options.toBundle());

            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0)
                        .toBundle();
                getActivity().startActivityForResult(intent, REQUEST_CODE, bundle);
            } else {
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    });
}

From source file:org.messic.android.smartphone.activities.main.fragments.queue.PlayQueueFragment.java

/**
 * Show the AlbumInfo Activity//w w w. j a  va 2s  . c om
 *
 * @param cover
 * @param album
 */
private void showAlbumInfo(final ImageView cover, MDMAlbum album) {
    Observable<MDMAlbum> observable = presenter.getAlbum(album);

    observable.subscribeOn(Schedulers.io()).onBackpressureBuffer().observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<MDMAlbum>() {
                @Override
                public void call(MDMAlbum mdmAlbum) {

                    //lets show the albuminfoactivity
                    Intent ssa = new Intent(getActivity(), AlbumInfoActivity.class);
                    ssa.putExtra(AlbumInfoActivity.EXTRA_ALBUM_SID, mdmAlbum);
                    Bitmap bitmap = ((BitmapDrawable) cover.getDrawable()).getBitmap();
                    AlbumInfoActivity.defaultArt = bitmap;

                    //ssa.putExtra(AlbumInfoActivity.EXTRA_ALBUM_ART, bitmap);

                    ActivityOptionsCompat options = ActivityOptionsCompat
                            .makeSceneTransitionAnimation(getActivity(), cover, "cover");
                    getActivity().startActivity(ssa, options.toBundle());

                }
            });

}

From source file:com.example.PagerCoverFlow.PagerContainer.java

private void transformImageBitmap(ImageView child, Matrix imageMatrix, int rotationAngle) {
    mCamera.save();/*from w  ww  .jav a2 s.  co  m*/
    //        final Matrix imageMatrix = t.getMatrix();;
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    //      mCamera.translate(0.0f, 0.0f, 100.0f);
    Log.i("Select", "imageWidth:" + imageWidth + " " + "imageHeight:" + imageHeight);
    //As the angle of the view gets less, zoom in
    //      if ( rotation < mMaxRotationAngle )
    {
        float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
        Log.i("Select", "rotation:" + rotation + " zoomAmount:" + zoomAmount);
        mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    //Alpha
    int alphaVal = 255 - rotation * 3;
    //      child.setAlpha(alphaVal); //[0,255]
    child.getDrawable().setAlpha(alphaVal);
    //      mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();

    float[] values = new float[9];
    imageMatrix.getValues(values);
    float globalX = values[Matrix.MTRANS_X];
    float globalY = values[Matrix.MTRANS_Y];
    //      float width = values[Matrix.MSCALE_X]*CommonValue.menuWidth ;
    //      float height = values[Matrix.MSCALE_Y]*CommonValue.menuWidth;
    values[Matrix.MSCALE_X] = 2;
    values[Matrix.MSCALE_Y] = 2;
    imageMatrix.setValues(values);
}