Skip to content

Commit da2d826

Browse files
wcshidsn5ft
authored andcommitted
[Tabs][BottomNav] Do not show tooltip on long press for L and M devices to avoid freezing devices on repeated long press.
PiperOrigin-RevId: 355428951
1 parent e13610e commit da2d826

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/java/com/google/android/material/navigation/NavigationBarItemView.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import android.content.Context;
2424
import android.content.res.ColorStateList;
2525
import android.graphics.drawable.Drawable;
26+
import android.os.Build.VERSION;
27+
import android.os.Build.VERSION_CODES;
2628
import androidx.core.graphics.drawable.DrawableCompat;
2729
import androidx.core.view.PointerIconCompat;
2830
import androidx.core.view.ViewCompat;
@@ -150,7 +152,11 @@ public void initialize(@NonNull MenuItemImpl itemData, int menuType) {
150152
!TextUtils.isEmpty(itemData.getTooltipText())
151153
? itemData.getTooltipText()
152154
: itemData.getTitle();
153-
TooltipCompat.setTooltipText(this, tooltipText);
155+
156+
// Avoid calling tooltip for L and M devices because long pressing twuice may freeze devices.
157+
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP || VERSION.SDK_INT > VERSION_CODES.M) {
158+
TooltipCompat.setTooltipText(this, tooltipText);
159+
}
154160
setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
155161
}
156162

@@ -202,7 +208,10 @@ public void setTitle(@Nullable CharSequence title) {
202208
itemData == null || TextUtils.isEmpty(itemData.getTooltipText())
203209
? title
204210
: itemData.getTooltipText();
205-
TooltipCompat.setTooltipText(this, tooltipText);
211+
// Avoid calling tooltip for L and M devices because long pressing twuice may freeze devices.
212+
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP || VERSION.SDK_INT > VERSION_CODES.M) {
213+
TooltipCompat.setTooltipText(this, tooltipText);
214+
}
206215
}
207216

208217
@Override

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,10 @@ private void updateTextAndIcon(
28762876
}
28772877

28782878
final CharSequence contentDesc = tab != null ? tab.contentDesc : null;
2879-
TooltipCompat.setTooltipText(this, hasText ? text : contentDesc);
2879+
// Avoid calling tooltip for L and M devices because long pressing twuice may freeze devices.
2880+
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP || VERSION.SDK_INT > VERSION_CODES.M) {
2881+
TooltipCompat.setTooltipText(this, hasText ? text : contentDesc);
2882+
}
28802883
}
28812884

28822885
private void tryUpdateBadgeDrawableBounds(@NonNull View anchor) {

0 commit comments

Comments
 (0)