Skip to content

Commit

Permalink
Fixes forward compatibility of the tooltip text tag (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Feb 21, 2020
1 parent fc9fd6d commit 889049d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
49 changes: 31 additions & 18 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/views/UIButton.java
Expand Up @@ -22,6 +22,7 @@
import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton;

import org.mozilla.gecko.util.ThreadUtils;
Expand Down Expand Up @@ -99,42 +100,52 @@ public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
}
}

@TargetApi(Build.VERSION_CODES.O)
public String getTooltip() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return mTooltipText;
@Nullable
@Override
public CharSequence getTooltipText() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return getTooltipTextInternal();

} else {
return getTooltipText() == null ? null : getTooltipText().toString();
return mTooltipText;
}
}

@TargetApi(Build.VERSION_CODES.O)
public void setTooltip(String text) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
mTooltipText = text;
} else {
setTooltipText(text);
private CharSequence getTooltipTextInternal() {
return super.getTooltipText();
}

@Override
public void setTooltipText(@Nullable CharSequence tooltipText) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setTooltipTextInternal(tooltipText);
}

if (mTooltipView != null && mTooltipView.isVisible()) {
mTooltipView.setText(text);
if (tooltipText != null) {
mTooltipText = tooltipText.toString();

if (mTooltipView != null && mTooltipView.isVisible()) {
mTooltipView.setText(tooltipText.toString());
}
}
}

@TargetApi(Build.VERSION_CODES.O)
private void setTooltipTextInternal(@Nullable CharSequence tooltipText) {
super.setTooltipText(tooltipText);
}

public void setCurvedTooltip(boolean aEnabled) {
mCurvedTooltip = aEnabled;
if (mTooltipView != null) {
mTooltipView.setCurvedMode(aEnabled);
}
}

public void setTooltipText(@NonNull String text) {
mTooltipText = text;
}

@Override
public boolean onHoverEvent(MotionEvent event) {
if (getTooltip() != null) {
if (getTooltipText() != null) {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
ThreadUtils.postDelayedToUiThread(mShowTooltipRunnable, mTooltipDelay);

Expand Down Expand Up @@ -256,7 +267,9 @@ public void run() {
mTooltipView = new TooltipWidget(getContext(), mTooltipLayout);
}
mTooltipView.setCurvedMode(mCurvedTooltip);
mTooltipView.setText(getTooltip());
if (getTooltipText() != null) {
mTooltipView.setText(getTooltipText().toString());
}

Rect offsetViewBounds = new Rect();
getDrawingRect(offsetViewBounds);
Expand Down
Expand Up @@ -348,22 +348,22 @@ public void detachFromWindow() {

Observer<ObservableBoolean> mBookmarksVisibleObserver = isBookmarksVisible -> {
if (isBookmarksVisible.get()) {
mBinding.bookmarksButton.setTooltip(getResources().getString(R.string.close_bookmarks_tooltip));
mBinding.bookmarksButton.setTooltipText(getResources().getString(R.string.close_bookmarks_tooltip));
mBinding.bookmarksButton.setActiveMode(true);

} else {
mBinding.bookmarksButton.setTooltip(getResources().getString(R.string.open_bookmarks_tooltip));
mBinding.bookmarksButton.setTooltipText(getResources().getString(R.string.open_bookmarks_tooltip));
mBinding.bookmarksButton.setActiveMode(false);
}
};

Observer<ObservableBoolean> mHistoryVisibleObserver = isHistoryVisible -> {
if (isHistoryVisible.get()) {
mBinding.historyButton.setTooltip(getResources().getString(R.string.close_history_tooltip));
mBinding.historyButton.setTooltipText(getResources().getString(R.string.close_history_tooltip));
mBinding.historyButton.setActiveMode(true);

} else {
mBinding.historyButton.setTooltip(getResources().getString(R.string.open_history_tooltip));
mBinding.historyButton.setTooltipText(getResources().getString(R.string.open_history_tooltip));
mBinding.historyButton.setActiveMode(false);
}
};
Expand Down Expand Up @@ -421,14 +421,14 @@ private void handleSessionState(boolean refresh) {
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
mBinding.privateButton.setImageResource(R.drawable.ic_icon_tray_private_browsing_on_v2);
mBinding.privateButton.setTooltip(getResources().getString(R.string.private_browsing_exit_tooltip));
mBinding.privateButton.setTooltipText(getResources().getString(R.string.private_browsing_exit_tooltip));

} else {
if (!refresh) {
mWidgetManager.popWorldBrightness(this);
}
mBinding.privateButton.setImageResource(R.drawable.ic_icon_tray_private_browsing_v2);
mBinding.privateButton.setTooltip(getResources().getString(R.string.private_browsing_enter_tooltip));
mBinding.privateButton.setTooltipText(getResources().getString(R.string.private_browsing_enter_tooltip));
}
}

Expand Down

0 comments on commit 889049d

Please sign in to comment.