Example usage for android.widget ImageView setBackgroundColor

List of usage examples for android.widget ImageView setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:org.runbuddy.tomahawk.adapters.ViewHolder.java

public void fillView(Resolver resolver) {
    TextView textView1 = (TextView) findViewById(R.id.textview1);
    textView1.setText(resolver.getPrettyName());
    ImageView imageView1 = (ImageView) findViewById(R.id.imageview1);
    imageView1.clearColorFilter();/*from  ww w .j  a  v  a  2 s .c o m*/
    if (!(resolver instanceof ScriptResolver)
            || ((ScriptResolver) resolver).getScriptAccount().getMetaData().manifest.iconBackground != null) {
        resolver.loadIconBackground(imageView1, !resolver.isEnabled());
    } else {
        if (resolver.isEnabled()) {
            imageView1.setBackgroundColor(
                    TomahawkApp.getContext().getResources().getColor(android.R.color.black));
        } else {
            imageView1.setBackgroundColor(
                    TomahawkApp.getContext().getResources().getColor(R.color.fallback_resolver_bg));
        }
    }
    ImageView imageView2 = (ImageView) findViewById(R.id.imageview2);
    if (!(resolver instanceof ScriptResolver)
            || ((ScriptResolver) resolver).getScriptAccount().getMetaData().manifest.iconWhite != null) {
        resolver.loadIconWhite(imageView2, 0);
    } else {
        resolver.loadIcon(imageView2, !resolver.isEnabled());
    }
    View connectImageViewContainer = findViewById(R.id.connect_imageview);
    if (resolver.isEnabled()) {
        connectImageViewContainer.setVisibility(View.VISIBLE);
    } else {
        connectImageViewContainer.setVisibility(View.GONE);
    }
}

From source file:image_cache.ImageWorker.java

public void toGrayscale(String buildFBFriendImageUrl, ImageView imageView) {
    if (buildFBFriendImageUrl == null) {
        return;/*from  w w w  . j a v a 2  s.c o m*/
    }

    Bitmap bmpOriginal = null;

    if (mImageCache != null) {
        bmpOriginal = mImageCache.getBitmapFromMemCache(String.valueOf(buildFBFriendImageUrl));
    }

    if (bmpOriginal != null) {
        // Bitmap found in memory cache
        imageView.setImageBitmap(bmpOriginal);
        imageView.setBackgroundColor(0);
    } else if (cancelPotentialWork(buildFBFriendImageUrl, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been
        // pulled from the
        // framework and slightly modified. Refer to the docs at the top of
        // the class
        // for more info on what was changed.
        task.executeOnExecutor(ImageTask.DUAL_THREAD_EXECUTOR, buildFBFriendImageUrl);
    }
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    imageView.setImageBitmap(bmpGrayscale);

}

From source file:com.android.tv.settings.dialog.SettingsLayoutFragment.java

private void initializeContentView(View content) {
    TextView titleView = (TextView) content.findViewById(R.id.title);
    TextView breadcrumbView = (TextView) content.findViewById(R.id.breadcrumb);
    TextView descriptionView = (TextView) content.findViewById(R.id.description);
    titleView.setText(mTitle);/*w  w w  .  j  a v a2 s .  co  m*/
    breadcrumbView.setText(mBreadcrumb);
    descriptionView.setText(mDescription);
    final ImageView iconImageView = (ImageView) content.findViewById(R.id.icon);
    iconImageView.setBackgroundColor(mIconBackgroundColor);

    // Force text fields to be focusable when accessibility is enabled.
    if (AccessibilityHelper.forceFocusableViews(getActivity())) {
        titleView.setFocusable(true);
        titleView.setFocusableInTouchMode(true);
        descriptionView.setFocusable(true);
        descriptionView.setFocusableInTouchMode(true);
        breadcrumbView.setFocusable(true);
        breadcrumbView.setFocusableInTouchMode(true);
    }

    if (mIcon != null) {
        iconImageView.setImageDrawable(mIcon);
        updateViewSize(iconImageView);
    } else if (mIconBitmap != null) {
        iconImageView.setImageBitmap(mIconBitmap);
        updateViewSize(iconImageView);
    } else if (mIconUri != null) {
        iconImageView.setVisibility(View.INVISIBLE);
        /*
                
        BitmapDownloader bitmapDownloader = BitmapDownloader.getInstance(
            content.getContext());
        mBitmapCallBack = new BitmapCallback() {
        @Override
        public void onBitmapRetrieved(Bitmap bitmap) {
            if (bitmap != null) {
                mIconBitmap = bitmap;
                iconImageView.setVisibility(View.VISIBLE);
                iconImageView.setImageBitmap(bitmap);
                updateViewSize(iconImageView);
            }
        }
        };
                
        bitmapDownloader.getBitmap(new BitmapWorkerOptions.Builder(
            content.getContext()).resource(mIconUri)
            .width(iconImageView.getLayoutParams().width).build(),
            mBitmapCallBack);
        */
    } else {
        iconImageView.setVisibility(View.GONE);
    }

    content.setTag(R.id.title, titleView);
    content.setTag(R.id.breadcrumb, breadcrumbView);
    content.setTag(R.id.description, descriptionView);
    content.setTag(R.id.icon, iconImageView);
}

From source file:com.github.colorchief.colorchief.MainActivity.java

public void resetColorControl(View view) {
    ImageView colourBlock21 = (ImageView) findViewById(R.id.colour21);
    ColorDrawable colourDrawable = (ColorDrawable) colourBlock21.getBackground();
    int[] verticeCoords = colorLUT.getNearestVerticeCoords(colourDrawable.getColor());

    int resetColor = colorLUT.getLUTElement(verticeCoords[0], verticeCoords[1], verticeCoords[2]);

    ImageView colourBlock22 = (ImageView) findViewById(R.id.colour22);
    colourBlock22.setBackgroundColor(resetColor);
}

From source file:ch.bfh.instacircle.MessageCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {

    // extracting the labels of the layout
    TextView content = (TextView) view.findViewById(R.id.content);
    TextView description = (TextView) view.findViewById(R.id.description);
    ImageView icon = (ImageView) view.findViewById(R.id.icon);

    // setting the content label
    content.setText(cursor.getString(cursor.getColumnIndex("message")));

    SimpleDateFormat sdf = new SimpleDateFormat();

    // create a readable date from the timestamp
    Date date = new Date(cursor.getLong(cursor.getColumnIndex("timestamp")));

    int messageType = cursor.getInt(cursor.getColumnIndex("message_type"));

    // setting the icon according to the message type
    switch (messageType) {
    case Message.MSG_CONTENT:

        if (cursor.getInt(cursor.getColumnIndex("sequence_number")) == -1) {
            description.setText("Unicast message received from "
                    + cursor.getString(cursor.getColumnIndex("identification")) + ",\n" + sdf.format(date));
            icon.setImageResource(R.drawable.glyphicons_120_message_full);
            icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_purple));
        } else {// ww  w .j a v  a 2s .  c om
            description.setText("Broadcast message received from "
                    + cursor.getString(cursor.getColumnIndex("identification")) + ",\n" + sdf.format(date));
            icon.setImageResource(R.drawable.glyphicons_120_message_full);
            icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_blue_light));
        }
        break;
    case Message.MSG_MSGJOIN:
        description.setText("Participant joined,\n" + sdf.format(date));
        icon.setImageResource(R.drawable.glyphicons_006_user_add);
        break;
    case Message.MSG_MSGLEAVE:
        description.setText("Participant left,\n" + sdf.format(date));
        icon.setImageResource(R.drawable.glyphicons_007_user_remove);
        break;
    }
}

From source file:com.tct.mail.ui.NestedFolderTeaserView.java

/**
 * Creates a {@link FolderHolder}.//w ww  .j  a  va 2  s.c  o  m
 */
private FolderHolder createFolderHolder(final CharSequence folderName) {
    final View itemView = LayoutInflater.from(getContext()).inflate(R.layout.folder_teaser_item, null);

    final ImageView imageView = (ImageView) itemView.findViewById(R.id.folder_imageView);
    // TS: lin.zhou 2016-01-06 EMAIL BUGFIX-1271032 MOD_S
    imageView.setImageResource(R.drawable.ic_drawer_folder_unread);//TS: junwei-xu 2015-1-11 EMAIL BUGFIX_922163 MOD
    // TS: lin.zhou 2016-01-06 EMAIL BUGFIX-1271032 MOD_E
    // Remove background
    imageView.setBackgroundColor(Color.TRANSPARENT);

    ((TextView) itemView.findViewById(R.id.folder_textView)).setText(folderName);
    //TS: junwei-xu 2015-2-11 EMAIL BUGFIX_922163 MOD_S
    //final TextView sendersTextView = (TextView) itemView.findViewById(R.id.senders_textView);
    //TS: junwei-xu 2015-2-11 EMAIL BUGFIX_922163 MOD_E
    final TextView countTextView = (TextView) itemView.findViewById(R.id.count_textView);
    final FolderHolder holder = new FolderHolder(itemView, countTextView);//TS: junwei-xu 2015-2-11 EMAIL BUGFIX_922163 MOD

    attachOnClickListener(itemView, holder);

    return holder;
}

From source file:com.linhnv.apps.funnybox.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView// w  ww.ja va2s  .c o  m
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
        imageView.setBackgroundColor(Color.BLACK);
    }
}

From source file:com.example.android.displayingbitmaps.imageloader.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./*w w w.jav a 2s.  c o m*/
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(final ImageView imageView, final Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                //                            new ColorDrawable(android.R.color.transparent),
                new BitmapDrawable(mResources, mLoadingBitmap), drawable });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));
        imageView.setBackgroundColor(Color.TRANSPARENT);

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
        imageView.setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:org.matrix.androidsdk.db.MXMediaDownloadWorkerTask.java

@Override
protected void onPostExecute(Void nothing) {
    if (null != mErrorAsJsonElement) {
        dispatchOnDownloadError(mErrorAsJsonElement);
    } else if (isDownloadCancelled()) {
        dispatchDownloadCancel();//  w  w  w  . ja  v a  2s .  co m
    } else {
        dispatchOnDownloadComplete();

        // image download
        // update the linked ImageViews.
        if (isBitmapDownloadTask()) {
            // retrieve the bitmap from the file s
            Bitmap bitmap = MXMediaDownloadWorkerTask.bitmapForURL(mApplicationContext, mDirectoryFile, mUrl,
                    mRotation, mMimeType);

            if (null == bitmap) {
                bitmap = mDefaultBitmap;
            }

            // update the imageViews image
            if (bitmap != null) {
                for (WeakReference<ImageView> weakRef : mImageViewReferences) {
                    final ImageView imageView = weakRef.get();

                    if (imageView != null && TextUtils.equals(mUrl, (String) imageView.getTag())) {
                        imageView.setBackgroundColor(Color.TRANSPARENT);
                        imageView.setImageBitmap(bitmap);
                    }
                }
            }
        }
    }
}

From source file:image_cache.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./*from   w ww.ja  v a2  s .c om*/
 * 
 * @param imageView
 * @param bitmap
 */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        if (Utils.hasJellyBean())
            imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));
        else
            imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setBackgroundColor(0);
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setBackgroundColor(0);
        imageView.setImageBitmap(bitmap);
    }
}