Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2807 Fixes forward compatibility of the tooltip text tag #2819

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 31 additions & 18 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/views/UIButton.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,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 @@ -416,14 +416,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