Java Code Examples for android.widget.ImageView#getBackground()

The following examples show how to use android.widget.ImageView#getBackground() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //TODO solve unconditional layout inflation
    View rowView = inflater.inflate(R.layout.dialog_grid_item, parent, false);

    int color = getColor(getColorResAt(position));

    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
    if (color == selectedColor)
        imageView.setImageResource(R.drawable.ic_checkmark_selected);
    GradientDrawable gradientDrawable = (GradientDrawable) imageView.getBackground();

    gradientDrawable.setColor(color);

    return rowView;
}
 
Example 2
/**
 * 自己去调整
 */
private void initAnimation() {
    // 获取ImageView上的动画背景
    AnimationDrawable spinnerLive = (AnimationDrawable) mIvLive.getBackground();

    // 开始动画
    spinnerLive.start();

    mIvImg = (ImageView) findViewById(R.id.img_img);

    // 获取ImageView上的动画背景
    AnimationDrawable spinnerImg = (AnimationDrawable) mIvImg.getBackground();
    // 开始动画
    spinnerImg.start();

}
 
Example 3
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	Log.setDefaultLevel(Log.SUPPRESS);
	
	// If there is no intent scheduled, set a repeating alarm for library updates.
	setupRepeatingLibraryUpdateAlarm();
	
	setContentView(R.layout.activity_home);
	
	// According to http://stackoverflow.com/a/2791816/931277, setting dither="true" on the shape tag in xml doesn't work.
	// However, using the debugger on the Nexus 7 (4.2), when it's set in xml it is in fact set on this Drawable, so this
	// *should* be unnecessary. It won't hurt, though.
	ImageView splash = (ImageView) findViewById(R.id.activity_home_imageview);
	Drawable background = splash.getBackground();
	if (background instanceof GradientDrawable) {
		((GradientDrawable) background).setDither(true);
	}
}
 
Example 4
Source Project: FoodOrdering   File: CommProgressDialog.java    License: Apache License 2.0 5 votes vote down vote up
public void onWindowFocusChanged(boolean hasFocus){

        if (commProgressDialog == null){
            return;
        }

        ImageView imageView = (ImageView) commProgressDialog.findViewById(R.id.iv_loading);
        if(anim!=0) {
            imageView.setBackgroundResource(anim);
        }
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        animationDrawable.start();
    }
 
Example 5
Source Project: Ticket-Analysis   File: XinxinRefreshLayout.java    License: MIT License 5 votes vote down vote up
public RefreshHeader(Context context) {
    super(context);
    View header = LayoutInflater.from(context).inflate(R.layout.header_refresh_common, this);
    imageMoneyDown = (ImageView) header.findViewById(R.id.imageDown);

    animationDrawable = (AnimationDrawable) imageMoneyDown.getBackground();
    animationDrawable.stop();
}
 
Example 6
Source Project: GravityBox   File: ModNavigationBar.java    License: Apache License 2.0 5 votes vote down vote up
private static void setKeyColorRecursive(ViewGroup vg) {
    if (vg == null) return;
    final int childCount = vg.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = vg.getChildAt(i);
        if (child instanceof ViewGroup) {
            setKeyColorRecursive((ViewGroup) child);
        } else if (child instanceof ImageView) {
            ImageView imgv = (ImageView) vg.getChildAt(i);
            if (mNavbarColorsEnabled) {
                imgv.setColorFilter(mKeyColor, PorterDuff.Mode.SRC_ATOP);
            } else {
                imgv.clearColorFilter();
            }
            if (imgv.getClass().getName().equals(CLASS_KEY_BUTTON_VIEW) &&
                    !mNavbarColorsEnabled) {
                Drawable ripple = imgv.getBackground();
                if (ripple != null &&
                        ripple.getClass().getName().equals(CLASS_KEY_BUTTON_RIPPLE)) {
                    Paint paint = (Paint) XposedHelpers.getObjectField(ripple, "mRipplePaint");
                    if (paint != null) {
                        paint.setColor(0xffffffff);
                    }
                }
            } else if (imgv instanceof KeyButtonView) {
                ((KeyButtonView) imgv).setGlowColor(mNavbarColorsEnabled ?
                        mKeyGlowColor : mKeyDefaultGlowColor);
            }
        }
    }
}
 
Example 7
Source Project: MyHearts   File: CustomPrograss.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 当窗口焦点改变时调用
 */
public void onWindowFocusChanged(boolean hasFocus) {
    ImageView imageView = (ImageView) findViewById(R.id.spinnerImageView);
    // 获取ImageView上的动画背景
    AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
    // 开始动画
    spinner.start();
}
 
Example 8
Source Project: MaterialPreference   File: ColorAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View getView(final int position, View convertView, ViewGroup parent) {


    LayoutInflater inflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView = inflater.inflate(R.layout.dialog_grid_item, parent, false);

    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);

    if(secondary_position == position){
        imageView.setImageResource(R.drawable.mpref_done);
    }

    GradientDrawable gradientDrawable = (GradientDrawable) imageView.getBackground();
    gradientDrawable.setColor(Color.parseColor(getItem(position)));

    rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MaterialPrefUtil.updateColor(position);
            notifyDataSetChanged();
            mCallback.onColorChanged(position);
        }
    });
    return rowView;
}
 
Example 9
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    //holder.itemView.setClickable(false); // disable parent click
    ImageView imageView = (ImageView) holder.findViewById(R.id.imageViewIcon);
    //noinspection StatementWithEmptyBody
    if (imageView != null) {
        GradientDrawable gradientDrawable = (GradientDrawable) imageView.getBackground();
        gradientDrawable.setColor(Color.parseColor(MaterialPrefUtil.secondaryColor[MaterialPrefUtil.getSecondaryColorPosition()]));

        imageView.setClickable(true); // enable custom view click

    } else {
    }
}
 
Example 10
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	ImageView rocketImage = (ImageView) findViewById(R.id.iv);
	//��֡��������Դ�ļ���Ϊimageview�ı���ͼƬ
	rocketImage.setBackgroundResource(R.drawable.frameanimation);
	//��ȡimageView�ı������ѱ���ǿת�ɶ���Drawable
	AnimationDrawable rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
	//���Ŷ���
	rocketAnimation.start();
}
 
Example 11
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
	rocketImage.setBackgroundResource(R.drawable.anim);
	rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
}
 
Example 12
/**
 * @param view the ImageView
 * @param color color to apply
 */
public static void colorizeImageView(ImageView view, int color)
{
    if (view != null && view.getBackground() != null)
    {
        try {
            GradientDrawable d = (GradientDrawable) view.getBackground().mutate();
            d.setColor(color);
            d.invalidateSelf();

        } catch (ClassCastException e) {
            Log.w("colorizeImageView", "failed to colorize! " + e);
        }
    }
}
 
Example 13
Source Project: miappstore   File: MoreHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View initView() {
    View view = View.inflate(context, R.layout.item_load_more, null);
    load_empty = view.findViewById(R.id.load_empty);
    load_error = view.findViewById(R.id.load_error);
    load_more = view.findViewById(R.id.load_more);
    iv_loadmore = (ImageView) view.findViewById(R.id.iv_loadmore);
    background = (AnimationDrawable) iv_loadmore.getBackground();
    background.start();
    return view;
}
 
Example 14
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	ImageView imageView = findViewById(R.id.countdown_frame);

	imageView.setBackgroundResource(R.drawable.view_animation);

	mAnim = (AnimationDrawable) imageView.getBackground();
}
 
Example 15
Source Project: letv   File: SharedElementCallback.java    License: Apache License 2.0 4 votes vote down vote up
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) {
    Bitmap bitmap;
    if (sharedElement instanceof ImageView) {
        ImageView imageView = (ImageView) sharedElement;
        Drawable d = imageView.getDrawable();
        Drawable bg = imageView.getBackground();
        if (d != null && bg == null) {
            bitmap = createDrawableBitmap(d);
            if (bitmap != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
                bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE, imageView.getScaleType().toString());
                if (imageView.getScaleType() != ScaleType.MATRIX) {
                    return bundle;
                }
                float[] values = new float[9];
                imageView.getImageMatrix().getValues(values);
                bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
                return bundle;
            }
        }
    }
    int bitmapWidth = Math.round(screenBounds.width());
    int bitmapHeight = Math.round(screenBounds.height());
    bitmap = null;
    if (bitmapWidth > 0 && bitmapHeight > 0) {
        float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (bitmapWidth * bitmapHeight)));
        bitmapWidth = (int) (((float) bitmapWidth) * scale);
        bitmapHeight = (int) (((float) bitmapHeight) * scale);
        if (this.mTempMatrix == null) {
            this.mTempMatrix = new Matrix();
        }
        this.mTempMatrix.set(viewToGlobalMatrix);
        this.mTempMatrix.postTranslate(-screenBounds.left, -screenBounds.top);
        this.mTempMatrix.postScale(scale, scale);
        bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.concat(this.mTempMatrix);
        sharedElement.draw(canvas);
    }
    return bitmap;
}
 
Example 16
Source Project: zulip-android   File: PhotoEditActivity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This function is called when any of the marker colors are chosen.
 * Its sets the color for marker tool and changes its the background.
 *
 * @param view color ImageView
 */
public void handleMarkerColorChange(View view) {
    int colorId = R.color.red_marker_tool;
    switch (view.getId()) {
        case R.id.red_marker:
            colorId = R.color.red_marker_tool;
            break;
        case R.id.yellow_marker:
            colorId = R.color.yellow_marker_tool;
            break;
        case R.id.green_marker:
            colorId = R.color.green_marker_tool;
            break;
        case R.id.white_marker:
            colorId = R.color.white_marker_tool;
            break;
        case R.id.blue_marker:
            colorId = R.color.blue_marker_tool;
            break;
        case R.id.black_marker:
            colorId = R.color.black_marker_tool;
            break;
        default:
            Log.e("Marker Tool", "Invalid color");
            break;
    }

    // change marker tool color
    mDrawCustomView.setBrushColor(ContextCompat.getColor(this, colorId));

    // change background of marker tool
    ImageView markerIcon = (ImageView) findViewById(R.id.marker_btn);
    GradientDrawable markerBackground = (GradientDrawable) markerIcon.getBackground();
    markerBackground.setColor(ContextCompat.getColor(this, colorId));
    // if black color is selected, add a border to the background of marker tool
    if (colorId == R.color.black_marker_tool) {
        markerBackground.setStroke(3, Color.GRAY);
    } else {
        markerBackground.setStroke(0, Color.GRAY);
    }
}
 
Example 17
Source Project: twitter-kit-android   File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static int getBackgroundColor(ImageView imageView) {
    final ColorDrawable drawable = (ColorDrawable) imageView.getBackground();
    return drawable.getColor();
}
 
Example 18
@Override
protected Drawable getViewDrawable(ImageView view) {
    // The states we need exist on the ImageView background (not on the
    // getDrawable(), like in a 'regular' image view).
    return view.getBackground();
}
 
Example 19
Source Project: reader   File: AndroidProgressHUD.java    License: MIT License 4 votes vote down vote up
public void onWindowFocusChanged(boolean hasFocus){
ImageView imageView = (ImageView) findViewById(context.getResources().getIdentifier("spinnerImageView", "id", context.getPackageName()));
       AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
       spinner.start();
   }
 
Example 20
Source Project: reader   File: AndroidProgressHUD.java    License: MIT License 4 votes vote down vote up
public void onWindowFocusChanged(boolean hasFocus){
ImageView imageView = (ImageView) findViewById(context.getResources().getIdentifier("spinnerImageView", "id", context.getPackageName()));
       AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
       spinner.start();
   }