Skip to content

Commit f3db717

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Show content description popups when long-pressing action bar tabs" into jb-mr1-dev
2 parents 236d052 + c7752a3 commit f3db717

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

core/java/com/android/internal/widget/ScrollingTabContainerView.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import android.app.ActionBar;
2424
import android.content.Context;
2525
import android.content.res.Configuration;
26+
import android.graphics.Rect;
2627
import android.graphics.drawable.Drawable;
28+
import android.text.TextUtils;
2729
import android.text.TextUtils.TruncateAt;
2830
import android.view.Gravity;
2931
import android.view.View;
@@ -38,6 +40,7 @@
3840
import android.widget.ListView;
3941
import android.widget.Spinner;
4042
import android.widget.TextView;
43+
import android.widget.Toast;
4144

4245
/**
4346
* This widget implements the dynamic action bar tab behavior that can change
@@ -352,7 +355,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
352355
tabView.getTab().select();
353356
}
354357

355-
private class TabView extends LinearLayout {
358+
private class TabView extends LinearLayout implements OnLongClickListener {
356359
private ActionBar.Tab mTab;
357360
private TextView mTextView;
358361
private ImageView mIconView;
@@ -426,7 +429,8 @@ public void update() {
426429
mIconView.setImageDrawable(null);
427430
}
428431

429-
if (text != null) {
432+
final boolean hasText = !TextUtils.isEmpty(text);
433+
if (hasText) {
430434
if (mTextView == null) {
431435
TextView textView = new TextView(getContext(), null,
432436
com.android.internal.R.attr.actionBarTabTextStyle);
@@ -448,9 +452,35 @@ public void update() {
448452
if (mIconView != null) {
449453
mIconView.setContentDescription(tab.getContentDescription());
450454
}
455+
456+
if (!hasText && !TextUtils.isEmpty(tab.getContentDescription())) {
457+
setOnLongClickListener(this);
458+
} else {
459+
setOnLongClickListener(null);
460+
setLongClickable(false);
461+
}
451462
}
452463
}
453464

465+
public boolean onLongClick(View v) {
466+
final int[] screenPos = new int[2];
467+
getLocationOnScreen(screenPos);
468+
469+
final Context context = getContext();
470+
final int width = getWidth();
471+
final int height = getHeight();
472+
final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
473+
474+
Toast cheatSheet = Toast.makeText(context, mTab.getContentDescription(),
475+
Toast.LENGTH_SHORT);
476+
// Show under the tab
477+
cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
478+
(screenPos[0] + width / 2) - screenWidth / 2, height);
479+
480+
cheatSheet.show();
481+
return true;
482+
}
483+
454484
public ActionBar.Tab getTab() {
455485
return mTab;
456486
}

0 commit comments

Comments
 (0)