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

The following examples show how to use android.widget.ImageView#getBackground() . 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 check out the related API usage on the sidebar.
Example 1
Source File: HomeActivity.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: ColorPref.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@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 3
Source File: MainActivityDrawerLayout.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
/**
 * 自己去调整
 */
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 4
Source File: ColorChooserPreference.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: GraphicsFrameAnimationActivity.java    From coursera-android with MIT License 5 votes vote down vote up
@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 6
Source File: MoreHolder.java    From miappstore with 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 7
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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 8
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@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 9
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@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 10
Source File: ColorAdapter.java    From MaterialPreference with 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 11
Source File: CustomPrograss.java    From MyHearts with 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 12
Source File: ModNavigationBar.java    From GravityBox with 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 13
Source File: XinxinRefreshLayout.java    From Ticket-Analysis with 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 14
Source File: CommProgressDialog.java    From FoodOrdering with 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 15
Source File: AndroidProgressHUD.java    From reader with 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 16
Source File: PXVirtualActionBarOverflowAdapter.java    From pixate-freestyle-android with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: AndroidProgressHUD.java    From reader with 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 18
Source File: TestUtils.java    From twitter-kit-android with 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 19
Source File: PhotoEditActivity.java    From zulip-android with 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 20
Source File: SharedElementCallback.java    From letv with 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;
}