Last active
July 13, 2016 11:01
-
-
Save xtools-at/2b67bb1b62f9a8b2c3b3c66b26058348 to your computer and use it in GitHub Desktop.
Show first-time-user explaination for Google Cast (Android)
This file contains 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
//copied from https://github.com/googlesamples/android-UniversalMusicPlayer | |
//modified by xTools | |
/** | |
* Shows the Cast First Time User experience to the user (an overlay that explains what is | |
* the Cast icon) | |
*/ | |
//call this if device was detected | |
private void showFtu(int menuItemId) { | |
//cast=R.id.media_route_menu_item | |
//fling=R.id.menu_fling | |
//get menu item | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
if (toolbar != null) { | |
Menu menu = toolbar.getMenu(); | |
View view = menu.findItem(menuItemId).getActionView(); | |
//change text according to cast service | |
int titleStringId = 0; | |
int descStringId = 0; | |
if (menuItemId == R.id.media_route_menu_item) { | |
titleStringId = R.string.ftu_cast_title; | |
descStringId = R.string.ftu_cast_sub; | |
} else if (menuItemId == R.id.menu_fling){ | |
titleStringId = R.string.ftu_fling_title; | |
descStringId = R.string.ftu_fling_sub; | |
} | |
//show ftu | |
if (view != null && titleStringId != 0) { | |
IntroductoryOverlay overlay = new IntroductoryOverlay.Builder(this) //this = activity context! | |
.setMenuItem(view) | |
.setTitleText(titleStringId) | |
.setSubtitleText(descStringId) | |
.setSingleTime() | |
.build(); | |
overlay.show(); | |
} | |
} | |
} | |
private final VideoCastConsumerImpl mCastConsumer = new VideoCastConsumerImpl() { | |
//... | |
@Override | |
public void onCastAvailabilityChanged(boolean castPresent) { | |
if (castPresent) { | |
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
if (mMediaRouteMenuItem.isVisible()) { | |
LogHelper.d(TAG, "Cast Icon is visible"); | |
showFtu(); | |
} | |
} | |
}, DELAY_MILLIS); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment