This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Added support for tooltips #1400
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TooltipWidget.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package org.mozilla.vrbrowser.ui.widgets; | ||
|
|
||
| import android.content.Context; | ||
| import android.graphics.PointF; | ||
| import android.graphics.Rect; | ||
| import android.view.View; | ||
| import android.widget.TextView; | ||
|
|
||
| import org.mozilla.vrbrowser.R; | ||
| import org.mozilla.vrbrowser.utils.ViewUtils; | ||
|
|
||
| public class TooltipWidget extends UIWidget { | ||
|
|
||
| private View mTargetView; | ||
| private UIWidget mParentWidget; | ||
| protected TextView mText; | ||
| private PointF mTranslation; | ||
| private float mRatio; | ||
| private float mDensityRatio; | ||
|
|
||
| public TooltipWidget(Context aContext) { | ||
| super(aContext); | ||
|
|
||
| initialize(); | ||
| } | ||
|
|
||
| private void initialize() { | ||
| inflate(getContext(), R.layout.tooltip, this); | ||
|
|
||
| mText = findViewById(R.id.tooltipText); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { | ||
| aPlacement.visible = false; | ||
| aPlacement.width = 0; | ||
| aPlacement.height = 0; | ||
| aPlacement.parentAnchorX = 0.0f; | ||
| aPlacement.parentAnchorY = 1.0f; | ||
| aPlacement.anchorX = 0.5f; | ||
| aPlacement.anchorY = 0.5f; | ||
| aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.tooltip_z_distance); | ||
| } | ||
|
|
||
| @Override | ||
| public void show(@ShowFlags int aShowFlags) { | ||
| measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), | ||
| MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); | ||
| mWidgetPlacement.translationX = mTranslation.x * (mRatio / mWidgetPlacement.density); | ||
|
keianhzo marked this conversation as resolved.
|
||
| mWidgetPlacement.translationY = mTranslation.y * (mRatio / mWidgetPlacement.density); | ||
| int paddingH = getPaddingStart() + getPaddingEnd(); | ||
| int paddingV = getPaddingTop() + getPaddingBottom(); | ||
| mWidgetPlacement.width = (int)(WidgetPlacement.convertPixelsToDp(getContext(), getMeasuredWidth() + paddingH)/mDensityRatio); | ||
| mWidgetPlacement.height = (int)(WidgetPlacement.convertPixelsToDp(getContext(), getMeasuredHeight() + paddingV)/mDensityRatio); | ||
|
|
||
| super.show(aShowFlags); | ||
| } | ||
|
|
||
| public void setLayoutParams(View targetView) { | ||
| this.setLayoutParams(targetView, ViewUtils.TooltipPosition.BOTTOM); | ||
| } | ||
|
|
||
| public void setLayoutParams(View targetView, ViewUtils.TooltipPosition position) { | ||
| this.setLayoutParams(targetView, position, mWidgetPlacement.density); | ||
| } | ||
|
|
||
| public void setLayoutParams(View targetView, ViewUtils.TooltipPosition position, float density) { | ||
| mTargetView = targetView; | ||
| mParentWidget = ViewUtils.getParentWidget(mTargetView); | ||
| if (mParentWidget != null) { | ||
| mRatio = WidgetPlacement.worldToWidgetRatio(mParentWidget); | ||
| mWidgetPlacement.density = density; | ||
| mDensityRatio = mWidgetPlacement.density / getContext().getResources().getDisplayMetrics().density; | ||
|
|
||
| Rect offsetViewBounds = new Rect(); | ||
| getDrawingRect(offsetViewBounds); | ||
| mParentWidget.offsetDescendantRectToMyCoords(mTargetView, offsetViewBounds); | ||
|
|
||
| mWidgetPlacement.parentHandle = mParentWidget.getHandle(); | ||
| // At the moment we only support showing tooltips on top or bottom of the target view | ||
| if (position == ViewUtils.TooltipPosition.BOTTOM) { | ||
| mWidgetPlacement.anchorY = 1.0f; | ||
| mWidgetPlacement.parentAnchorY = 0.0f; | ||
| mTranslation = new PointF( | ||
| (offsetViewBounds.left + mTargetView.getWidth() / 2) * mDensityRatio, | ||
| -offsetViewBounds.top * mDensityRatio); | ||
| } else { | ||
| mWidgetPlacement.anchorY = 0.0f; | ||
| mWidgetPlacement.parentAnchorY = 1.0f; | ||
| mTranslation = new PointF( | ||
| (offsetViewBounds.left + mTargetView.getWidth() / 2) * mDensityRatio, | ||
| offsetViewBounds.top * mDensityRatio); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void setText(String text) { | ||
| mText.setText(text); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/common/shared/org/mozilla/vrbrowser/utils/ViewUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.mozilla.vrbrowser.utils; | ||
|
|
||
| import android.view.View; | ||
| import android.view.ViewParent; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| import org.mozilla.vrbrowser.ui.widgets.UIWidget; | ||
|
|
||
| public class ViewUtils { | ||
|
|
||
| public enum TooltipPosition { | ||
| TOP(0), BOTTOM(1); | ||
| int id; | ||
|
|
||
| TooltipPosition(int id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public static TooltipPosition fromId(int id) { | ||
| for (TooltipPosition f : values()) { | ||
| if (f.id == id) return f; | ||
| } | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| public static UIWidget getParentWidget(@NonNull View view) { | ||
| if (view == null) | ||
| return null; | ||
|
|
||
| ViewParent v = view.getParent(); | ||
| if (v instanceof UIWidget) { | ||
| return (UIWidget)v; | ||
|
|
||
| } else if (v instanceof View){ | ||
| return getParentWidget((View)v); | ||
|
|
||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <item> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
| <corners android:radius="30dp" /> | ||
| <stroke android:width="@dimen/blur_radius" android:color="@color/fog_blur" /> | ||
| </shape> | ||
| </item> | ||
| <item android:start="@dimen/blur_radius_half" android:end="@dimen/blur_radius_half" android:top="@dimen/blur_radius_half" android:bottom="@dimen/blur_radius_half"> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
| <corners android:radius="30dp" /> | ||
| <solid android:color="@color/rhino" /> | ||
| <stroke android:width="2dp" android:color="@color/rhino_blur" /> | ||
| </shape> | ||
| </item> | ||
| </layer-list> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.