2323import android .app .ActionBar ;
2424import android .content .Context ;
2525import android .content .res .Configuration ;
26+ import android .graphics .Rect ;
2627import android .graphics .drawable .Drawable ;
28+ import android .text .TextUtils ;
2729import android .text .TextUtils .TruncateAt ;
2830import android .view .Gravity ;
2931import android .view .View ;
3840import android .widget .ListView ;
3941import android .widget .Spinner ;
4042import 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