Example usage for android.view View getBackground

List of usage examples for android.view View getBackground

Introduction

In this page you can find the example usage for android.view View getBackground.

Prototype

public Drawable getBackground() 

Source Link

Document

Gets the background drawable

Usage

From source file:Main.java

public static void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }//from w w  w.j  av a2 s.c  o m
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
    }
}

From source file:Main.java

public static void changeDefaultViewPressState(View view, float[] press) {
    if (view.getBackground() == null) {

    } else {//  w w w.  ja  v  a 2s.  co  m
        view.getBackground().setColorFilter(new ColorMatrixColorFilter(press));
        view.setBackgroundDrawable(view.getBackground());
    }

}

From source file:Main.java

/**
 * from http://stackoverflow.com/questions/4336286/tiled-drawable-sometimes-stretches/9500334#9500334
 *///  ww w  .j a  va2 s  .  co  m
public static void fixBackgroundRepeat(View view) {
    Drawable bg = view.getBackground();
    if (bg != null) {
        if (bg instanceof BitmapDrawable) {
            BitmapDrawable bmp = (BitmapDrawable) bg;
            bmp.mutate(); // make sure that we aren't sharing state anymore
            bmp.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        }
    }
}

From source file:Main.java

public static void setBackgroundPreservingAlpha(View view, Drawable drawable) {
    if (view.getBackground() != null) {
        drawable.setAlpha(view.getBackground().getAlpha());
    }//from www  .ja  v  a2 s  .co m
    view.setBackground(drawable);
}

From source file:uk.co.bubblebearapps.motionaiclient.view.customsetters.ViewCustomSetters.java

@BindingAdapter("backgroundTint")
public static void setBackgroundTint(final View view, int tint) {

    if (view.getBackground() == null) {
        return;//w w  w. ja  va  2 s  . c  o m
    }

    Drawable wrapped = DrawableCompat.wrap(view.getBackground());
    DrawableCompat.setTint(wrapped, tint);
    ViewCompat.setBackground(view, wrapped);
}

From source file:Main.java

public static void startAnimation(int resId, View view) {
    view.setBackgroundResource(resId);//from  w  w  w .  j ava 2 s  .  c o  m
    ((AnimationDrawable) view.getBackground()).start();
}

From source file:Main.java

static int getColorViewColor(View colorView) {
    int color = Color.TRANSPARENT;
    Drawable background = colorView.getBackground();
    if (background instanceof ColorDrawable)
        color = ((ColorDrawable) background).getColor();
    return color;
}

From source file:Main.java

/**
 * this method should only be called at the onDestroy() method of an activity
 * //from w  w  w .j  a v  a  2 s  .  co  m
 * @param view
 *          a reference to the root View of the current activity
 */
public static void unbindDrawables(View view) {
    if (null != view) {
        if (view.getBackground() != null) {
            view.getBackground().setCallback(null);
        }
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                unbindDrawables(((ViewGroup) view).getChildAt(i));
            }

            // necessary because of AdapterView does not allow removeAllViews,
            // and possibly other ones
            try {

                ((ViewGroup) view).removeAllViews();

            } catch (Exception e) {
                // ignore
            }
        }
    }
}

From source file:Main.java

/**
 * Unbind drawables.//from   w  w w.  j  a  va 2 s.  c o m
 *
 * @param view the view
 */
public static void unbindDrawables(View view) {
    if (view == null)
        return;
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        try {
            ((ViewGroup) view).removeAllViews();
        } catch (UnsupportedOperationException mayHappen) {
            Log.e("Error:", mayHappen.getMessage());
        }
    }
}

From source file:Main.java

public static void setOnTouchBackgroundEffect(View view) {
    view.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (!(v.getBackground() instanceof TransitionDrawable))
                return false;

            TransitionDrawable transition = (TransitionDrawable) v.getBackground();

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                transition.startTransition(500);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                transition.reverseTransition(500);
                break;
            }//  www. java2  s. c  o  m

            return false;
        }
    });
}