Skip to content

Commit

Permalink
Add borderless support for tint widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Apr 22, 2021
1 parent e59e222 commit 9f30de8
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,16 @@ public class Defaults {

/**
* Default borderless value for the widgets.
* <p>{@code true} if the widget is borderless.
* <p>{@code true} if the widget has borderless style.
*/
public static final boolean ADS_STYLE_BORDERLESS = false;

/**
* Default borderless value for the group widgets.
* <p>{@code true} if the widget has borderless style.
*/
public static final boolean ADS_STYLE_BORDERLESS_GROUP = true;

/**
* Default tint background value for the widgets.
* <p>{@code true} to enable the background tinting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public class DynamicButton extends MaterialButton implements DynamicWidget,
private @Theme.BackgroundAware int mBackgroundAware;

/**
* {@code true} if style applied to this view is borderless.
* {@code true} to tint background according to the widget color.
*/
private boolean mStyleBorderless;
private boolean mTintBackground;

/**
* {@code true} to tint background according to the widget color.
* {@code true} if the style applied to this view is borderless.
*/
private boolean mTintBackground;
private boolean mStyleBorderless;

public DynamicButton(@NonNull Context context) {
this(context, null);
Expand All @@ -114,25 +114,6 @@ public DynamicButton(@NonNull Context context,
loadFromAttributes(attrs);
}

/**
* @return {@code true} if style applied to this view is borderless.
*/
public boolean isStyleBorderless() {
return mStyleBorderless;
}

/**
* Set the value of {@link #mStyleBorderless}.
*
* @param styleBorderless {@code true} if style applied to this view
* is borderless.
*/
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void loadFromAttributes(@Nullable AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
Expand All @@ -154,12 +135,12 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
mBackgroundAware = a.getInteger(
R.styleable.DynamicButton_ads_backgroundAware,
Defaults.getBackgroundAware());
mStyleBorderless = a.getBoolean(
R.styleable.DynamicButton_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS);
mTintBackground = a.getBoolean(
R.styleable.DynamicButton_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicButton_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -268,6 +249,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class DynamicFrameLayout extends FrameLayout implements DynamicWidget, Dy
*/
private boolean mTintBackground;

/**
* {@code true} if the style applied to this view is borderless.
*/
private boolean mStyleBorderless;

public DynamicFrameLayout(@NonNull Context context) {
this(context, null);
}
Expand Down Expand Up @@ -129,8 +134,11 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
R.styleable.DynamicFrameLayout_ads_backgroundAware,
Defaults.getBackgroundAware());
mTintBackground = a.getBoolean(
R.styleable.DynamicImageButton_ads_tintBackground,
R.styleable.DynamicFrameLayout_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicFrameLayout_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS_GROUP);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -273,6 +281,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void setColor() {
if (mColor != Theme.Color.UNKNOWN) {
Expand All @@ -289,7 +309,7 @@ public void setColor() {
}

if (isBackgroundAware() && isTintBackground()) {
Dynamic.tintBackground(this, mContrastWithColor);
Dynamic.tintBackground(this, mContrastWithColor, isStyleBorderless());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public class DynamicImageButton extends AppCompatImageButton
private @Theme.BackgroundAware int mBackgroundAware;

/**
* {@code true} if style applied to this view is borderless.
* {@code true} to tint background according to the widget color.
*/
private boolean mStyleBorderless;
private boolean mTintBackground;

/**
* {@code true} to tint background according to the widget color.
* {@code true} if the style applied to this view is borderless.
*/
private boolean mTintBackground;
private boolean mStyleBorderless;

public DynamicImageButton(@NonNull Context context) {
this(context, null);
Expand All @@ -116,25 +116,6 @@ public DynamicImageButton(@NonNull Context context,
loadFromAttributes(attrs);
}

/**
* @return {@code true} if style applied to this view is borderless.
*/
public boolean isStyleBorderless() {
return mStyleBorderless;
}

/**
* Set the value of {@link #mStyleBorderless}.
*
* @param styleBorderless {@code true} if style applied to this view
* is borderless.
*/
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void loadFromAttributes(@Nullable AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
Expand All @@ -156,12 +137,12 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
mBackgroundAware = a.getInteger(
R.styleable.DynamicImageButton_ads_backgroundAware,
Defaults.getBackgroundAware());
mStyleBorderless = a.getBoolean(
R.styleable.DynamicImageButton_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS);
mTintBackground = a.getBoolean(
R.styleable.DynamicImageButton_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicImageButton_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -290,6 +271,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@SuppressLint("RestrictedApi")
@Override
public void setColor() {
Expand All @@ -308,7 +301,7 @@ public void setColor() {
}

if (isBackgroundAware() && isTintBackground()) {
Dynamic.tintBackground(this, mContrastWithColor, mStyleBorderless);
Dynamic.tintBackground(this, mContrastWithColor, isStyleBorderless());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class DynamicImageView extends AppCompatImageView
*/
private boolean mTintBackground;

/**
* {@code true} if the style applied to this view is borderless.
*/
private boolean mStyleBorderless;

public DynamicImageView(@NonNull Context context) {
this(context, null);
}
Expand Down Expand Up @@ -139,8 +144,11 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
R.styleable.DynamicImageView_ads_backgroundAware,
Defaults.getBackgroundAware());
mTintBackground = a.getBoolean(
R.styleable.DynamicImageButton_ads_tintBackground,
R.styleable.DynamicImageView_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicImageView_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS);

if (mColorType == Theme.ColorType.NONE && mColor == Theme.Color.UNKNOWN) {
if (getId() == R.id.submenuarrow) {
Expand Down Expand Up @@ -289,6 +297,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void setColor() {
if (mColor != Theme.Color.UNKNOWN) {
Expand All @@ -309,7 +329,7 @@ public void setColor() {
}

if (isBackgroundAware() && isTintBackground()) {
Dynamic.tintBackground(this, mContrastWithColor);
Dynamic.tintBackground(this, mContrastWithColor, isStyleBorderless());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class DynamicLinearLayout extends LinearLayout implements DynamicWidget,
*/
private boolean mTintBackground;

/**
* {@code true} if the style applied to this view is borderless.
*/
private boolean mStyleBorderless;

public DynamicLinearLayout(@NonNull Context context) {
this(context, null);
}
Expand Down Expand Up @@ -131,6 +136,9 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
mTintBackground = a.getBoolean(
R.styleable.DynamicImageButton_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicImageButton_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS_GROUP);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -273,6 +281,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void setColor() {
if (mColor != Theme.Color.UNKNOWN) {
Expand All @@ -289,7 +309,7 @@ public void setColor() {
}

if (isBackgroundAware() && isTintBackground()) {
Dynamic.tintBackground(this, mContrastWithColor);
Dynamic.tintBackground(this, mContrastWithColor, isStyleBorderless());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class DynamicRelativeLayout extends RelativeLayout
*/
private boolean mTintBackground;

/**
* {@code true} if the style applied to this view is borderless.
*/
private boolean mStyleBorderless;

public DynamicRelativeLayout(@NonNull Context context) {
this(context, null);
}
Expand Down Expand Up @@ -130,8 +135,11 @@ public void loadFromAttributes(@Nullable AttributeSet attrs) {
R.styleable.DynamicRelativeLayout_ads_backgroundAware,
Defaults.getBackgroundAware());
mTintBackground = a.getBoolean(
R.styleable.DynamicImageButton_ads_tintBackground,
R.styleable.DynamicRelativeLayout_ads_tintBackground,
Defaults.ADS_TINT_BACKGROUND);
mStyleBorderless = a.getBoolean(
R.styleable.DynamicRelativeLayout_ads_styleBorderless,
Defaults.ADS_STYLE_BORDERLESS_GROUP);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -274,6 +282,18 @@ public void setTintBackground(boolean tintBackground) {
setColor();
}

@Override
public boolean isStyleBorderless() {
return mStyleBorderless;
}

@Override
public void setStyleBorderless(boolean styleBorderless) {
this.mStyleBorderless = styleBorderless;

setColor();
}

@Override
public void setColor() {
if (mColor != Theme.Color.UNKNOWN) {
Expand All @@ -290,7 +310,7 @@ public void setColor() {
}

if (isBackgroundAware() && isTintBackground()) {
Dynamic.tintBackground(this, mContrastWithColor);
Dynamic.tintBackground(this, mContrastWithColor, isStyleBorderless());
}
}
}

0 comments on commit 9f30de8

Please sign in to comment.