Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Update UIButton to better manage multiple states. Fixes #1837 (#1920)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin authored and keianhzo committed Oct 7, 2019
1 parent 4f9f8cf commit 4f7e54f
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/views/UIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@

public class UIButton extends AppCompatImageButton implements CustomUIButton {

private enum State {
NORMAL,
PRIVATE,
ACTIVE,
NOTIFICATION
}

private ColorStateList mTintColorList;
private Drawable mPrivateModeBackground;
private Drawable mActiveModeBackground;
Expand All @@ -46,11 +39,13 @@ private enum State {
private @IdRes int mNotificationModeTintColorListRes;
private TooltipWidget mTooltipView;
private String mTooltipText;
private State mState;
private int mTooltipDelay;
private float mTooltipDensity;
private boolean mCurvedTooltip = true;
private ViewUtils.TooltipPosition mTooltipPosition;
private boolean mIsPrivate;
private boolean mIsActive;
private boolean mIsNotification;

public UIButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.imageButtonStyle);
Expand Down Expand Up @@ -79,8 +74,6 @@ public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
attributes.recycle();

mBackground = getBackground();

mState = State.NORMAL;
}

@TargetApi(Build.VERSION_CODES.O)
Expand Down Expand Up @@ -152,42 +145,41 @@ protected void drawableStateChanged() {

@Override
public void setPrivateMode(boolean isPrivateMode) {
if (isPrivateMode) {
setPrivate();

} else {
setNormal();
}
mIsPrivate = isPrivateMode;
updateButtonColor();
}

public void setActiveMode(boolean isActive) {
if (isActive) {
setActive();

} else {
setNormal();
}
mIsActive = isActive;
updateButtonColor();
}

public void setNotificationMode(boolean isNotification) {
if (isNotification) {
setNotification();

} else {
setNormal();
}
mIsNotification = isNotification;
updateButtonColor();
}

public boolean isActive() {
return mState == State.ACTIVE;
return mIsActive;
}

public boolean isPrivate() {
return mState == State.PRIVATE;
return mIsPrivate;
}

private void updateButtonColor() {
if (mIsNotification) {
setNotification();
} else if (mIsPrivate) {
setPrivate();
} else if (mIsActive) {
setActive();
} else {
setNormal();
}
}

private void setPrivate() {
mState = State.PRIVATE;
if (mPrivateModeBackground != null) {
setBackground(mPrivateModeBackground);
}
Expand All @@ -198,7 +190,6 @@ private void setPrivate() {
}

private void setNormal() {
mState = State.NORMAL;
if (mBackground != null) {
setBackground(mBackground);
}
Expand All @@ -209,7 +200,6 @@ private void setNormal() {
}

private void setActive() {
mState = State.ACTIVE;
if (mActiveModeBackground != null) {
setBackground(mActiveModeBackground);
}
Expand All @@ -220,7 +210,6 @@ private void setActive() {
}

private void setNotification() {
mState = State.NOTIFICATION;
if (mActiveModeTintColorListRes != 0) {
setTintColorList(mNotificationModeTintColorListRes);
}
Expand Down

0 comments on commit 4f7e54f

Please sign in to comment.