android.graphics.drawable.InsetDrawable Java Examples

The following examples show how to use android.graphics.drawable.InsetDrawable. 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: DrawableParser.java    From Folivora with Apache License 2.0 6 votes vote down vote up
@Override
public Drawable parse(ParseRequest request) {
  final Context ctx = request.context();
  final AttributeSet attrs = request.attrs();
  TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.Folivora_Inset);
  int insetAll = a.getDimensionPixelSize(R.styleable.Folivora_Inset_insetAll, 0);
  int[] ints = {
    R.styleable.Folivora_Inset_insetLeft,
    R.styleable.Folivora_Inset_insetTop,
    R.styleable.Folivora_Inset_insetRight,
    R.styleable.Folivora_Inset_insetBottom
  };
  for (int i = 0; i < ints.length; i++) {
    ints[i] = a.getDimensionPixelSize(ints[i], insetAll);
  }
  final Drawable child = getDrawable(ctx, a, attrs, R.styleable.Folivora_Inset_insetDrawable);
  a.recycle();
  return new InsetDrawable(child, ints[0], ints[1], ints[2], ints[3]);
}
 
Example #2
Source File: EmTintManager.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
private static boolean shouldMutateBackground(Drawable drawable) {
    if (Build.VERSION.SDK_INT >= 16) {
        // For SDK 16+, we should be fine mutating the drawable
        return true;
    }

    if (drawable instanceof LayerDrawable) {
        return Build.VERSION.SDK_INT >= 16;
    } else if (drawable instanceof InsetDrawable) {
        return Build.VERSION.SDK_INT >= 14;
    } else if (drawable instanceof DrawableContainer) {
        // If we have a DrawableContainer, let's traverse it's child array
        final Drawable.ConstantState state = drawable.getConstantState();
        if (state instanceof DrawableContainer.DrawableContainerState) {
            final DrawableContainer.DrawableContainerState containerState =
                    (DrawableContainer.DrawableContainerState) state;
            for (Drawable child : containerState.getChildren()) {
                if (!shouldMutateBackground(child)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example #3
Source File: ThemeUtils.java    From MagicaSakura with Apache License 2.0 6 votes vote down vote up
public static boolean containsNinePatch(Drawable drawable) {
    drawable = getWrapperDrawable(drawable);
    if (drawable instanceof NinePatchDrawable
            || drawable instanceof InsetDrawable
            || drawable instanceof LayerDrawable) {
        return true;
    } else if (drawable instanceof StateListDrawable) {
        final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
        //can't get containState from drawable which is containing DrawableWrapperDonut
        //https://code.google.com/p/android/issues/detail?id=169920
        if (containerState == null) {
            return true;
        }
        for (Drawable dr : containerState.getChildren()) {
            dr = getWrapperDrawable(dr);
            if (dr instanceof NinePatchDrawable
                    || dr instanceof InsetDrawable
                    || dr instanceof LayerDrawable) {
                return true;
            }
        }
    }
    return false;
}
 
Example #4
Source File: PickerDialog.java    From ColorPickerDialog with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    Window window = getDialog().getWindow();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowmanager = window.getWindowManager();
    windowmanager.getDefaultDisplay().getMetrics(displayMetrics);

    window.setLayout(
            Math.min(DimenUtils.dpToPx(displayMetrics.widthPixels > displayMetrics.heightPixels ? 800 : 500),
                    (int) (displayMetrics.widthPixels * 0.9f)),
            WindowManager.LayoutParams.WRAP_CONTENT
    );

    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(ColorUtils.fromAttr(new ContextThemeWrapper(getContext(), getTheme()),
            android.R.attr.colorBackground, Color.WHITE));
    drawable.setCornerRadius(cornerRadius);

    window.setBackgroundDrawable(new InsetDrawable(drawable, DimenUtils.dpToPx(12)));
}
 
Example #5
Source File: NavigationView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link MaterialShapeDrawable} to use as the {@code itemBackground} and wraps it in an
 * {@link InsetDrawable} for margins.
 *
 * @param a The TintTypedArray containing the resolved NavigationView style attributes.
 */
@NonNull
private final Drawable createDefaultItemBackground(@NonNull TintTypedArray a) {
  int shapeAppearanceResId = a.getResourceId(R.styleable.NavigationView_itemShapeAppearance, 0);
  int shapeAppearanceOverlayResId =
      a.getResourceId(R.styleable.NavigationView_itemShapeAppearanceOverlay, 0);
  MaterialShapeDrawable materialShapeDrawable =
      new MaterialShapeDrawable(
          ShapeAppearanceModel.builder(
                  getContext(), shapeAppearanceResId, shapeAppearanceOverlayResId)
              .build());
  materialShapeDrawable.setFillColor(
      MaterialResources.getColorStateList(
          getContext(), a, R.styleable.NavigationView_itemShapeFillColor));

  int insetLeft = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetStart, 0);
  int insetTop = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetTop, 0);
  int insetRight = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetEnd, 0);
  int insetBottom = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetBottom, 0);
  return new InsetDrawable(materialShapeDrawable, insetLeft, insetTop, insetRight, insetBottom);
}
 
Example #6
Source File: MaterialButtonHelper.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Nullable
private MaterialShapeDrawable getMaterialShapeDrawable(boolean getSurfaceColorStrokeDrawable) {
  if (rippleDrawable != null && rippleDrawable.getNumberOfLayers() > 0) {
    if (IS_LOLLIPOP) {
      InsetDrawable insetDrawable = (InsetDrawable) rippleDrawable.getDrawable(0);
      LayerDrawable layerDrawable = (LayerDrawable) insetDrawable.getDrawable();
      return (MaterialShapeDrawable)
          layerDrawable.getDrawable(getSurfaceColorStrokeDrawable ? 0 : 1);
    } else {
      return (MaterialShapeDrawable)
          rippleDrawable.getDrawable(getSurfaceColorStrokeDrawable ? 0 : 1);
    }
  }

  return null;
}
 
Example #7
Source File: MaterialDatePicker.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
  super.onStart();
  Window window = requireDialog().getWindow();
  // Dialogs use a background with an InsetDrawable by default, so we have to replace it.
  if (fullscreen) {
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawable(background);
  } else {
    window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    int inset =
        getResources().getDimensionPixelOffset(R.dimen.mtrl_calendar_dialog_background_inset);
    Rect insets = new Rect(inset, inset, inset, inset);
    window.setBackgroundDrawable(new InsetDrawable(background, inset, inset, inset, inset));
    window
        .getDecorView()
        .setOnTouchListener(new InsetDialogOnTouchListener(requireDialog(), insets));
  }
  startPickerFragment();
}
 
Example #8
Source File: SUtils.java    From SublimePicker with Apache License 2.0 6 votes vote down vote up
private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources()
            .getDimensionPixelSize(R.dimen.button_inset_vertical_material);

    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable,
            insetH, insetV, insetH, insetV);
}
 
Example #9
Source File: VoteArticleButton.java    From kaif-android with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
  setBackground(new InsetDrawable(new Triangle(context.getResources()
      .getColor(R.color.vote_state_empty)),
      (int) Views.convertDpToPixel(12, context),
      (int) Views.convertDpToPixel(4, context),
      (int) Views.convertDpToPixel(12, context),
      (int) Views.convertDpToPixel(4, context)));
  voteState = Vote.VoteState.EMPTY;
  setOnClickListener(v -> {
    if (onVoteClickListener != null) {
      Vote.VoteState from = this.voteState;
      Vote.VoteState to = (this.voteState == Vote.VoteState.EMPTY
                           ? Vote.VoteState.UP
                           : Vote.VoteState.EMPTY);
      onVoteClickListener.onVoteClicked(from, to);
    }
  });
}
 
Example #10
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
public static Drawable tintDrawable(Drawable drawable, int fillColor, int strokeColor, int strokePixels)
{
    Drawable d = null;
    try {
        d = tintDrawable((InsetDrawable)drawable, fillColor, strokeColor, strokePixels);

    } catch (ClassCastException e) {
        try {
            //noinspection ConstantConditions
            d = tintDrawable((LayerDrawable)drawable, fillColor, strokeColor, strokePixels);

        } catch (ClassCastException e2) {
            try {
                //noinspection ConstantConditions
                d = tintDrawable((GradientDrawable)drawable, fillColor, strokeColor, strokePixels);

            } catch (ClassCastException e3) {
                Log.e("tintDrawable", "");
            }
        }
    }
    return d;
}
 
Example #11
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param drawable a ShapeDrawable
 * @param fillColor the fill color
 * @param strokeColor the stroke color
 * @return a GradientDrawable with the given fill and stroke
 */
public static Drawable tintDrawable(InsetDrawable drawable, int fillColor, int strokeColor, int strokePixels)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        try {
            GradientDrawable gradient = (GradientDrawable)drawable.getDrawable();
            if (gradient != null)
            {
                SuntimesUtils.tintDrawable(gradient, fillColor, strokeColor, strokePixels);
                return drawable;

            } else {
                Log.w("tintDrawable", "failed to apply color! Null inset drawable.");
                return drawable;
            }
        } catch (ClassCastException e) {
            Log.w("tintDrawable", "failed to apply color! " + e);
            return drawable;
        }
    } else {
        Log.w("tintDrawable", "failed to apply color! InsetDrawable.getDrawable requires api 19+");
        return drawable;   // not supported
    }
}
 
Example #12
Source File: WeekdaysDrawableProvider.java    From weekdays-buttons-bar with MIT License 6 votes vote down vote up
public Drawable getRectWithCustomSize(Context context, String leftText, String rightText, boolean selected) {

        TextDrawable.IBuilder builder = TextDrawable.builder()
                .beginConfig()
                .width(toPx(context, 29))
                .withBorder(toPx(context, 2))
                .textColor(selected ? getTextColorSelected() : getTextColorUnselected())
                .endConfig()
                .rect();


        TextDrawable left = builder
                .build(leftText, mGenerator.getColor(leftText));


        TextDrawable right = builder
                .build(rightText, mGenerator.getColor(rightText));


        Drawable[] layerList = {
                new InsetDrawable(left, 0, 0, toPx(context, 31), 0),
                new InsetDrawable(right, toPx(context, 31), 0, 0, 0)
        };
        return new LayerDrawable(layerList);
    }
 
Example #13
Source File: ThemeUtils.java    From timecat with Apache License 2.0 6 votes vote down vote up
public static boolean containsNinePatch(Drawable drawable) {
    drawable = getWrapperDrawable(drawable);
    if (drawable instanceof NinePatchDrawable || drawable instanceof InsetDrawable || drawable instanceof LayerDrawable) {
        return true;
    } else if (drawable instanceof StateListDrawable) {
        final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
        //can't get containState from drawable which is containing DrawableWrapperDonut
        //https://code.google.com/p/android/issues/detail?id=169920
        if (containerState == null) {
            return true;
        }
        for (Drawable dr : containerState.getChildren()) {
            dr = getWrapperDrawable(dr);
            if (dr instanceof NinePatchDrawable || dr instanceof InsetDrawable || dr instanceof LayerDrawable) {
                return true;
            }
        }
    }
    return false;
}
 
Example #14
Source File: RecyclerFastScroller.java    From recycler-fast-scroll with Apache License 2.0 6 votes vote down vote up
private void updateHandleColorsAndInset() {
    StateListDrawable drawable = new StateListDrawable();

    if (!RecyclerFastScrollerUtils.isRTL(getContext())) {
        drawable.addState(View.PRESSED_ENABLED_STATE_SET,
                new InsetDrawable(new ColorDrawable(mHandlePressedColor), mBarInset, 0, 0, 0));
        drawable.addState(View.EMPTY_STATE_SET,
                new InsetDrawable(new ColorDrawable(mHandleNormalColor), mBarInset, 0, 0, 0));
    } else {
        drawable.addState(View.PRESSED_ENABLED_STATE_SET,
                new InsetDrawable(new ColorDrawable(mHandlePressedColor), 0, 0, mBarInset, 0));
        drawable.addState(View.EMPTY_STATE_SET,
                new InsetDrawable(new ColorDrawable(mHandleNormalColor), 0, 0, mBarInset, 0));
    }
    RecyclerFastScrollerUtils.setViewBackground(mHandle, drawable);
}
 
Example #15
Source File: FastScrollDelegate.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
private Drawable makeDefaultThumbDrawable() {
	StateListDrawable stateListDrawable = new StateListDrawable();
	GradientDrawable pressedDrawable = new GradientDrawable();
	pressedDrawable.setColor(thumbPressedColor);
	final float radius = width / 2f;
	final int inset = dp2px(FASTSCROLLER_THUMB_INSET_TOP_BOTTOM_RIGHT);// inset
	final int insetLeft = width - inset - dp2px(FASTSCROLLER_THUMB_WIDTH);
	pressedDrawable.setCornerRadius(radius);
	stateListDrawable.addState(DRAWABLE_STATE_PRESSED, new InsetDrawable(pressedDrawable, insetLeft, inset,
			inset, inset));
	GradientDrawable normalDrawable = new GradientDrawable();
	normalDrawable.setColor(thumbNormalColor);
	normalDrawable.setCornerRadius(radius);
	stateListDrawable.addState(DRAWABLE_STATE_DEFAULT, new InsetDrawable(normalDrawable, insetLeft, inset,
			inset, inset));
	return stateListDrawable;
}
 
Example #16
Source File: DefaultScrollerViewProvider.java    From recycler-fast-scroll with Apache License 2.0 6 votes vote down vote up
@Override
public View provideHandleView(ViewGroup container) {
    handle = new View(getContext());

    int verticalInset = getScroller().isVertical() ? 0 : getContext().getResources().getDimensionPixelSize(R.dimen.fastscroll__handle_inset);
    int horizontalInset = !getScroller().isVertical() ? 0 : getContext().getResources().getDimensionPixelSize(R.dimen.fastscroll__handle_inset);
    InsetDrawable handleBg = new InsetDrawable(ContextCompat.getDrawable(getContext(), R.drawable.fastscroll__default_handle), horizontalInset, verticalInset, horizontalInset, verticalInset);
    Utils.setBackground(handle, handleBg);

    int handleWidth = getContext().getResources().getDimensionPixelSize(getScroller().isVertical() ? R.dimen.fastscroll__handle_clickable_width : R.dimen.fastscroll__handle_height);
    int handleHeight = getContext().getResources().getDimensionPixelSize(getScroller().isVertical() ? R.dimen.fastscroll__handle_height : R.dimen.fastscroll__handle_clickable_width);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(handleWidth, handleHeight);
    handle.setLayoutParams(params);

    return handle;
}
 
Example #17
Source File: DrawableProvider.java    From TextDrawable with MIT License 6 votes vote down vote up
public Drawable getRectWithCustomSize() {
    String leftText = "I";
    String rightText = "J";

    TextDrawable.IBuilder builder = TextDrawable.builder()
            .beginConfig()
                .width(toPx(29))
                .withBorder(toPx(2))
            .endConfig()
            .rect();

    TextDrawable left = builder
            .build(leftText, mGenerator.getColor(leftText));

    TextDrawable right = builder
            .build(rightText, mGenerator.getColor(rightText));

    Drawable[] layerList = {
            new InsetDrawable(left, 0, 0, toPx(31), 0),
            new InsetDrawable(right, toPx(31), 0, 0, 0)
    };
    return new LayerDrawable(layerList);
}
 
Example #18
Source File: SuntimesUtils.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context context used to get resources
 * @param resourceID drawable resource ID to an InsetDrawable
 * @param fillColor fill color to apply to drawable
 * @param strokeColor stroke color to apply to drawable
 * @param strokePx width of stroke (pixels)
 * @return a Bitmap of the drawable
 * @deprecated all insetDrawables were replaced with layerDrawables (2/26/2018), continued use of this method probably signifies a bug.
 */
@Deprecated
public static Bitmap insetDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor, int strokePx)
{
    Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null);
    InsetDrawable inset = (InsetDrawable)drawable;

    int w = 1, h = 1;
    if (inset != null)
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            Drawable wrapped = inset.getDrawable();
            if (wrapped != null)
            {
                w = wrapped.getIntrinsicWidth();
                h = wrapped.getIntrinsicHeight();
            }
        } else {
            w = inset.getIntrinsicWidth();
            h = inset.getIntrinsicHeight();
        }
    }

    Drawable tinted = tintDrawable(inset, fillColor, strokeColor, strokePx);
    return drawableToBitmap(context, tinted, w, h, true);
}
 
Example #19
Source File: ShareMenuButtonFactory.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static StateListDrawable get(int color, Context context) {
    ShapeDrawable bg = new ShapeDrawable(new OvalShape());
    int padding = Screen.dp(5);
    bg.getPaint().setColor(color);
    ShapeDrawable bgPressed = new ShapeDrawable(new OvalShape());
    bgPressed.getPaint().setColor(ActorStyle.getDarkenArgb(color, 0.95));
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[]{android.R.attr.state_pressed},
            new InsetDrawable(bgPressed, padding));
    states.addState(StateSet.WILD_CARD,
            new InsetDrawable(bg, padding));
    return states;
}
 
Example #20
Source File: WidgetsContainerView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onUpdateBackgroundAndPaddings(Rect searchBarBounds, Rect padding) {
    boolean isRtl = Utilities.isRtl(getResources());
    // Apply the top-bottom padding to the content itself so that the launcher transition is
    // clipped correctly
    mContent.setPadding(0, padding.top, 0, padding.bottom);

    // TODO: Use quantum_panel_dark instead of quantum_panel_shape_dark.
    InsetDrawable background = new InsetDrawable(
            getResources().getDrawable(R.drawable.quantum_panel_shape_dark), padding.left, 0,
            padding.right, 0);
    Rect bgPadding = new Rect();
    background.getPadding(bgPadding);
    mView.setBackground(background);
    getRevealView().setBackground(background.getConstantState().newDrawable());
    mView.updateBackgroundPadding(bgPadding);

    int startInset = mView.getMaxScrollbarWidth();
    int topBottomPadding =  getPaddingTop();
    final boolean useScrollerScrubber = useScroller() && useScrubber();
    if (isRtl) {
        mView.setPadding(padding.left + mView.getMaxScrollbarWidth(),
                topBottomPadding, padding.right + startInset, useScrollerScrubber ?
                mScrubberHeight + topBottomPadding : topBottomPadding);
        if (useScrollerScrubber) {
            mScrubberContainerView.setPadding(padding.left, 0, padding.right, 0);
        }
    } else {
        mView.setPadding(padding.left + startInset, topBottomPadding,
                padding.right + mView.getMaxScrollbarWidth(), useScrollerScrubber ?
                mScrubberHeight + topBottomPadding : topBottomPadding);
        if (useScrollerScrubber) {
            mScrubberContainerView.setPadding(padding.left, 0, padding.right, 0);
            mScrubberContainerView.setEnabled(true);
            mScrubberContainerView.bringToFront();
        }
    }
}
 
Example #21
Source File: PasswordEntry.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
private int getTextLeft() {
    int left = 0;
    if (getBackground() instanceof InsetDrawable) {
        InsetDrawable back = (InsetDrawable) getBackground();
        Rect padding = new Rect();
        back.getPadding(padding);
        left = padding.left;
    }
    return left;
}
 
Example #22
Source File: MaterialCardViewHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link Drawable} that insets the given drawable by the amount of padding CardView
 * would add for the shadow. This will always use an {@link InsetDrawable} even if there is no
 * inset.
 *
 * <p>Always use an InsetDrawable even when the insets are 0 instead of only wrapping in an
 * InsetDrawable when there is an inset. Replacing the background (or foreground) of a {@link
 * View} with the same Drawable wrapped into an InsetDrawable will result in the View clearing the
 * original Drawable's callback which should refer to the InsetDrawable.
 */
@NonNull
private Drawable insetDrawable(Drawable originalDrawable) {
  int insetVertical = 0;
  int insetHorizontal = 0;
  boolean isPreLollipop = Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP;
  if (isPreLollipop || materialCardView.getUseCompatPadding()) {
    // Calculate the shadow padding used by CardView
    insetVertical = (int) Math.ceil(calculateVerticalBackgroundPadding());
    insetHorizontal = (int) Math.ceil(calculateHorizontalBackgroundPadding());
  }
  return new InsetDrawable(
      originalDrawable, insetHorizontal, insetVertical, insetHorizontal, insetVertical) {
    @Override
    public boolean getPadding(Rect padding) {
      // Our very own special InsetDrawable that pretends it does not have padding so that
      // using it as the background will *not* change the padding of the view.
      return false;
    }

    /** Don't force the card to be as big as this drawable */
    @Override
    public int getMinimumWidth() {
      return -1;
    }

    /** Don't force the card to be as big as this drawable */
    @Override
    public int getMinimumHeight() {
      return -1;
    }
  };
}
 
Example #23
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void onPaddingUpdated(@NonNull Rect padding) {
  Preconditions.checkNotNull(contentBackground, "Didn't initialize content background");
  if (shouldAddPadding()) {
    InsetDrawable insetDrawable = new InsetDrawable(
        contentBackground, padding.left, padding.top, padding.right, padding.bottom);
    shadowViewDelegate.setBackgroundDrawable(insetDrawable);
  } else {
    shadowViewDelegate.setBackgroundDrawable(contentBackground);
  }
}
 
Example #24
Source File: MaterialCardViewHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to update the {@link InsetDrawable} foreground to use the given {@link Drawable}.
 * Changing the Drawable is only available in M+, so earlier versions will create a new
 * InsetDrawable.
 */
private void updateInsetForeground(Drawable insetForeground) {
  if (VERSION.SDK_INT >= VERSION_CODES.M
      && materialCardView.getForeground() instanceof InsetDrawable) {
    ((InsetDrawable) materialCardView.getForeground()).setDrawable(insetForeground);
  } else {
    materialCardView.setForeground(insetDrawable(insetForeground));
  }
}
 
Example #25
Source File: MaterialDialogs.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
public static InsetDrawable insetDrawable(
    @Nullable Drawable drawable, @NonNull Rect backgroundInsets) {
  return new InsetDrawable(
      drawable,
      backgroundInsets.left,
      backgroundInsets.top,
      backgroundInsets.right,
      backgroundInsets.bottom);
}
 
Example #26
Source File: AllAppsContainerView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void updateBackground(
        int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
    if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
        getRevealView().setBackground(new InsetDrawable(mBaseDrawable,
                paddingLeft, paddingTop, paddingRight, paddingBottom));
        getContentView().setBackground(
                new InsetDrawable(new ColorDrawable(Color.TRANSPARENT),
                        paddingLeft, paddingTop, paddingRight, paddingBottom));
    } else {
        getRevealView().setBackground(mBaseDrawable);
    }
}
 
Example #27
Source File: SimpleRecyclerView.java    From SimpleRecyclerView with Apache License 2.0 5 votes vote down vote up
private void addDividerItemDecoration(@ColorInt int color, int orientation,
                                      int paddingLeft, int paddingTop,
                                      int paddingRight, int paddingBottom) {
  DividerItemDecoration decor = new DividerItemDecoration(getContext(), orientation);
  if (color != 0) {
    ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    shapeDrawable.setIntrinsicHeight(Utils.dpToPx(getContext(), 1));
    shapeDrawable.setIntrinsicWidth(Utils.dpToPx(getContext(), 1));
    shapeDrawable.getPaint().setColor(color);
    InsetDrawable insetDrawable = new InsetDrawable(shapeDrawable, paddingLeft, paddingTop, paddingRight, paddingBottom);
    decor.setDrawable(insetDrawable);
  }
  decor.setShowLastDivider(showLastDivider);
  addItemDecoration(decor);
}
 
Example #28
Source File: BaseContainerView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the background for the reveal view and content view based on the background padding.
 */
protected void updateBackground(int paddingLeft, int paddingTop,
        int paddingRight, int paddingBottom) {
    mRevealView.setBackground(new InsetDrawable(mBaseDrawable,
            paddingLeft, paddingTop, paddingRight, paddingBottom));
    mContent.setBackground(new InsetDrawable(mBaseDrawable,
            paddingLeft, paddingTop, paddingRight, paddingBottom));
}
 
Example #29
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	final Context context = inflater.getContext();
       final Resources res = context.getResources();
	final View view = inflater.inflate(R.layout.fragment_directory, container, false);

       mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);

	mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);

	mListView = (ListView) view.findViewById(R.id.list);
	mListView.setOnItemClickListener(mItemListener);
	mListView.setMultiChoiceModeListener(mMultiListener);
	mListView.setRecyclerListener(mRecycleListener);

       // Indent our list divider to align with text
       final Drawable divider = mListView.getDivider();
       final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
       final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
       if (insetLeft) {
           mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
       } else {
           mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
       }

	mGridView = (GridView) view.findViewById(R.id.grid);
	mGridView.setOnItemClickListener(mItemListener);
	mGridView.setMultiChoiceModeListener(mMultiListener);
	mGridView.setRecyclerListener(mRecycleListener);

	return view;
}
 
Example #30
Source File: ConnectionsFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    final Resources res = getActivity().getResources();

    fab = (FloatingActionButton)view.findViewById(R.id.fab);
    fab.setOnClickListener(this);
    if(isTelevision()){
        fab.setVisibility(View.GONE);
    }

    mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);
    mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);
    mListView = (ListView) view.findViewById(R.id.list);
    mListView.setOnItemClickListener(mItemListener);
    if(isTelevision()) {
        mListView.setOnItemLongClickListener(mItemLongClickListener);
    }
    fab.attachToListView(mListView);

    // Indent our list divider to align with text
    final Drawable divider = mListView.getDivider();
    final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
    final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
    if (insetLeft) {
        mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
    } else {
        mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
    }
}