Java Code Examples for android.view.View.getBackground()

The following are Jave code examples for showing how to use getBackground() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: WechatChatroomHelper   File: BGASwipeBackLayout2.java   Source Code and License Vote up 7 votes
private static boolean viewIsOpaque(View v) {
    if (v.isOpaque()) {
        return true;
    }

    // View#isOpaque didn't take all valid opaque scrollbar modes into account
    // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false
    // here. On older devices, check the view's background drawable directly as a fallback.
    if (Build.VERSION.SDK_INT >= 18) {
        return false;
    }

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 2
Project: weex-uikit   File: WXViewUtils.java   Source Code and License Vote up 6 votes
public static void clipCanvasWithinBorderBox(View targetView, Canvas canvas) {
  Drawable drawable;
  /* According to https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
    API 18 or higher supports clipPath to canvas based on hardware acceleration.
   */
  if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 ||
       !canvas.isHardwareAccelerated()) &&
      ((drawable = targetView.getBackground()) instanceof BorderDrawable)) {
    BorderDrawable borderDrawable = (BorderDrawable) drawable;
    if(borderDrawable.isRounded()) {
      Path path = borderDrawable.getContentPath(
          new RectF(0, 0, targetView.getWidth(), targetView.getHeight()));
      canvas.clipPath(path);
    }
  }
}
 
Example 3
Project: weex-uikit   File: WXViewUtils.java   Source Code and License Vote up 6 votes
public static @Nullable
BorderDrawable getBorderDrawable(@NonNull View view){
  Drawable drawable=view.getBackground();
  if(drawable instanceof BorderDrawable){
    return (BorderDrawable) drawable;
  }
  else if(drawable instanceof LayerDrawable){
    if(((LayerDrawable) drawable).getNumberOfLayers()>1) {
      Drawable innerDrawable=((LayerDrawable) drawable).getDrawable(0);
      if(innerDrawable instanceof BorderDrawable){
        return (BorderDrawable) innerDrawable;
      }
    }
  }
  return null;
}
 
Example 4
Project: GitHub   File: SmartViewHolder.java   Source Code and License Vote up 6 votes
public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener) {
    super(itemView);
    this.mListener = mListener;
    itemView.setOnClickListener(this);

    /**
     * 设置水波纹背景
     */
    if (itemView.getBackground() == null) {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = itemView.getContext().getTheme();
        int top = itemView.getPaddingTop();
        int bottom = itemView.getPaddingBottom();
        int left = itemView.getPaddingLeft();
        int right = itemView.getPaddingRight();
        if (theme.resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true)) {
            itemView.setBackgroundResource(typedValue.resourceId);
        }
        itemView.setPadding(left, top, right, bottom);
    }
}
 
Example 5
Project: https-github.com-hyb1996-NoRootScriptDroid   File: LayoutHierarchyView.java   Source Code and License Vote up 5 votes
private void setClickedItem(View view, NodeInfo item) {
    mClickedNodeInfo = item;
    if (mClickedView == null) {
        mOriginalBackground = view.getBackground();
    } else {
        mClickedView.setBackground(mOriginalBackground);
    }
    view.setBackgroundColor(mClickedColor);
    mClickedView = view;
    invalidate();
}
 
Example 6
Project: ChromeLikeTabSwitcher   File: TabletTabRecyclerAdapter.java   Source Code and License Vote up 5 votes
/**
 * Adapts the color of a button, which allows to add a new tab.
 *
 * @param addTabItem
 *         The add tab item, which corresponds to the button, whose color should be adapted, as
 *         an instance of the class {@link AddTabItem}. The add tab item may not be null
 */
private void adaptAddTabButtonColor(@NonNull final AddTabItem addTabItem) {
    ColorStateList colorStateList = getStyle().getAddTabButtonColor();
    int[] stateSet = new int[]{};
    int color = colorStateList.getColorForState(stateSet, colorStateList.getDefaultColor());
    View view = addTabItem.getView();
    Drawable background = view.getBackground();
    background.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
 
Example 7
Project: SmingZZick_App   File: Util.java   Source Code and License Vote up 5 votes
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);
        }
    }
}
 
Example 8
Project: ucar-weex-core   File: BackgroundColorProperty.java   Source Code and License Vote up 5 votes
@Override
public Integer get(View object) {
  int color;
  BorderDrawable borderDrawable;
  if ((borderDrawable = WXViewUtils.getBorderDrawable(object)) != null) {
    color = borderDrawable.getColor();
  } else if (object.getBackground() instanceof ColorDrawable) {
    color = ((ColorDrawable) object.getBackground()).getColor();
  } else {
    color = Color.TRANSPARENT;
    WXLogUtils.e(TAG, "Unsupported background type");
  }
  return color;
}
 
Example 9
Project: GitHub   File: ImageUtils.java   Source Code and License Vote up 5 votes
/**
 * view转bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(final View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 10
Project: letv   File: DrawerLayout.java   Source Code and License Vote up 5 votes
private static boolean hasOpaqueBackground(View v) {
    Drawable bg = v.getBackground();
    if (bg == null || bg.getOpacity() != -1) {
        return false;
    }
    return true;
}
 
Example 11
Project: decoy   File: SimpleClickListener.java   Source Code and License Vote up 5 votes
private void setPressViewHotSpot(final MotionEvent e, final View mPressedView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        /**
         * when   click   Outside the region  ,mPressedView is null
         */
        if (mPressedView != null && mPressedView.getBackground() != null) {
            mPressedView.getBackground().setHotspot(e.getRawX(), e.getY() - mPressedView.getY());
        }
    }
}
 
Example 12
Project: decoy   File: ContactsSelectHolder.java   Source Code and License Vote up 5 votes
@Override
public View inflate(LayoutInflater inflater) {
    View view = inflater.inflate(R.layout.nim_contacts_select_item, null);
    defaultBackground = view.getBackground();
    this.image = (HeadImageView) view.findViewById(R.id.img_head);
    this.nickname = (TextView) view.findViewById(R.id.tv_nickname);
    this.select = (ImageView) view.findViewById(R.id.imgSelect);
    return view;
}
 
Example 13
Project: weex-3d-map   File: WXAnimationModule.java   Source Code and License Vote up 5 votes
private static @Nullable
ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target) {
  if(target == null){
    return null;
  }
  WXAnimationBean.Style style = animation.styles;
  if (style != null) {
    ObjectAnimator animator;
    List<PropertyValuesHolder> holders =style.getHolders();
    if (!TextUtils.isEmpty(style.backgroundColor)) {
      BorderDrawable borderDrawable;
      if ((borderDrawable=WXViewUtils.getBorderDrawable(target))!=null) {
        holders.add(PropertyValuesHolder.ofObject(
            WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(),
            borderDrawable.getColor(),
            WXResourceUtils.getColor(style.backgroundColor)));
      } else if (target.getBackground() instanceof ColorDrawable) {
        holders.add(PropertyValuesHolder.ofObject(
            WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(),
            ((ColorDrawable) target.getBackground()).getColor(),
            WXResourceUtils.getColor(style.backgroundColor)));
      }
    }
    if (style.getPivot() != null) {
      Pair<Float, Float> pair = style.getPivot();
      target.setPivotX(pair.first);
      target.setPivotY(pair.second);
    }
    animator = ObjectAnimator.ofPropertyValuesHolder(
        target, holders.toArray(new PropertyValuesHolder[holders.size()]));
    animator.setStartDelay(animation.delay);
    final IntEvaluator intEvaluator=new IntEvaluator();
    if (target.getLayoutParams() != null &&
        (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
      DimensionUpdateListener listener = new DimensionUpdateListener(target);
      ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
      if (!TextUtils.isEmpty(style.width)) {
        listener.setWidth(layoutParams.width,
                          (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width)));
      }
      if (!TextUtils.isEmpty(style.height)) {
        listener.setHeight(layoutParams.height,
                           (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height)));
      }
      animator.addUpdateListener(listener);
    }
    return animator;
  } else {
    return null;
  }
}
 
Example 14
Project: Glitchy   File: SideMenu.java   Source Code and License Vote up 5 votes
private static boolean viewIsOpaque(View v) {
    if (ViewCompat.isOpaque(v)) return true;

    // View#isOpaque didn't take all valid opaque scrollbar modes into account
    // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false
    // here. On older devices, check the view's background drawable directly as a fallback.
    if (Build.VERSION.SDK_INT >= 18) return false;

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 15
Project: EasyTableView   File: MainActivity.java   Source Code and License Vote up 5 votes
public void onChangedTextColor(View view) {
    Drawable background = view.getBackground();
    ColorDrawable colorDrawable = (ColorDrawable) background;

    switch (curSelect) {
        case SELECT_TEXTS:
            if (null != curCellInfo) {
                curCellInfo.textColor = colorDrawable.getColor();
                table.updateData(curCellInfo);
            } else if (null != curMergeInfo) {
                curMergeInfo.textColor = colorDrawable.getColor();
                table.updateMergeData(curMergeInfo);
            }
            break;
        case SELECT_BG:
            if (null != curCellInfo) {
                curCellInfo.bgColor = colorDrawable.getColor();
                table.updateData(curCellInfo);
            } else if (null != curMergeInfo) {
                curMergeInfo.bgColor = colorDrawable.getColor();
                table.updateMergeData(curMergeInfo);
            }
            break;
        case SELECT_STROKE:
            table.setStrokeColor(colorDrawable.getColor());
            table.reset();
            break;
        case SELECT_OUT_STROKE:
            table.setOutStrokeColor(colorDrawable.getColor());
            table.reset();
            break;
    }
}
 
Example 16
Project: ChromeLikeTabSwitcher   File: AbstractTabSwitcherLayout.java   Source Code and License Vote up 5 votes
@Override
public final void onPressStarted(@NonNull final AbstractItem item) {
    ColorStateList colorStateList = null;
    boolean selected = false;

    if (item instanceof TabItem) {
        TabItem tabItem = (TabItem) item;
        Tab tab = tabItem.getTab();
        colorStateList = style.getTabBackgroundColor(tab);
        selected = getModel().getSelectedTab() == tab;
    } else if (item instanceof AddTabItem) {
        colorStateList = style.getAddTabButtonColor();
    }

    if (colorStateList != null) {
        int[] stateSet = selected ?
                new int[]{android.R.attr.state_pressed, android.R.attr.state_selected} :
                new int[]{android.R.attr.state_pressed};
        int color = colorStateList.getColorForState(stateSet, -1);

        if (color != -1) {
            View view = item.getView();
            Drawable background = view.getBackground();
            background.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }
    }
}
 
Example 17
Project: Android-UtilCode   File: ImageUtils.java   Source Code and License Vote up 5 votes
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 18
Project: Linphone4Android   File: CallActivity.java   Source Code and License Vote up 5 votes
private void unbindDrawables(View view) {
	if (view.getBackground() != null) {
		view.getBackground().setCallback(null);
	}
	if (view instanceof ImageView) {
		view.setOnClickListener(null);
	}
	if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
		for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
			unbindDrawables(((ViewGroup) view).getChildAt(i));
		}
		((ViewGroup) view).removeAllViews();
	}
}
 
Example 19
Project: LaunchEnr   File: SolidWallpaperUtils.java   Source Code and License Vote up 5 votes
static int getColorViewColor(View colorView) {
    int color = Color.TRANSPARENT;
    Drawable background = colorView.getBackground();
    if (background instanceof ColorDrawable)
        color = ((ColorDrawable) background).getColor();
    return color;
}
 
Example 20
Project: MusicX-music-player   File: TagProcessor.java   Source Code and License Vote up 4 votes
/**
 * Returns null if no action should be taken in the tag processors now (e.g. if the view
 * is being added to the post inflation views).
 */
@Nullable
public static ColorResult getColorFromSuffix(@NonNull Context context, @Nullable String key, @NonNull View view, @NonNull String suffix) {
    @ColorInt
    final int result;
    boolean isDependent = false;
    boolean isDark = false;

    switch (suffix) {
        case PRIMARY_COLOR:
            result = Config.primaryColor(context, key);
            break;
        case PRIMARY_COLOR_DARK:
            result = Config.primaryColorDark(context, key);
            break;
        case ACCENT_COLOR:
            result = Config.accentColor(context, key);
            break;
        case PRIMARY_TEXT_COLOR:
            result = Config.textColorPrimary(context, key);
            break;
        case PRIMARY_TEXT_COLOR_INVERSE:
            result = Config.textColorPrimaryInverse(context, key);
            break;
        case SECONDARY_TEXT_COLOR:
            result = Config.textColorSecondary(context, key);
            break;
        case SECONDARY_TEXT_COLOR_INVERSE:
            result = Config.textColorSecondaryInverse(context, key);
            break;

        case PARENT_DEPENDENT: {
            if (view.getParent() == null) {
                // Wait for post inflation when parents are assigned
                ATE.addPostInflationView(view);
                return null;
            }
            isDependent = true;
            final View firstBgView = getBackgroundView(view);
            if (firstBgView == null) {
                Log.d("ATETagProcessor", "No parents with color drawables as backgrounds found, falling back to windowBackground.");
                final int dependentColor = ATEUtil.resolveColor(context, android.R.attr.windowBackground);
                isDark = !ATEUtil.isColorLight(dependentColor);
                result = isDark ? Color.WHITE : Color.BLACK;
            } else {
                final ColorDrawable bg = (ColorDrawable) firstBgView.getBackground();
                isDark = !ATEUtil.isColorLight(bg.getColor());
                result = isDark ? Color.WHITE : Color.BLACK;
            }
            break;
        }
        case PRIMARY_COLOR_DEPENDENT: {
            isDependent = true;
            isDark = !ATEUtil.isColorLight(Config.primaryColor(context, key));
            result = isDark ? Color.WHITE : Color.BLACK;
            break;
        }
        case ACCENT_COLOR_DEPENDENT: {
            isDependent = true;
            isDark = !ATEUtil.isColorLight(Config.accentColor(context, key));
            result = isDark ? Color.WHITE : Color.BLACK;
            break;
        }
        case WINDOW_BG_DEPENDENT: {
            isDependent = true;
            isDark = !ATEUtil.isColorLight(ATEUtil.resolveColor(context, android.R.attr.windowBackground));
            result = isDark ? Color.WHITE : Color.BLACK;
            break;
        }
        default:
            throw new IllegalArgumentException(String.format("Unknown suffix: %s", suffix));
    }
    return new ColorResult(result, isDependent, isDark);
}