Skip to content

Instantly share code, notes, and snippets.

@rcketscientist
Created November 11, 2015 13:41
Show Gist options
  • Save rcketscientist/ae976eb08d8ace762d55 to your computer and use it in GitHub Desktop.
Save rcketscientist/ae976eb08d8ace762d55 to your computer and use it in GitHub Desktop.
SCV examples
//TODO: Hack for showcase appearing behind nav bar
public int getNavigationBarHeight(int orientation) {
try {
Resources resources = getResources();
int id = resources.getIdentifier(
orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape",
"dimen", "android");
if (id > 0) {
return resources.getDimensionPixelSize(id);
}
} catch (NullPointerException | IllegalArgumentException | Resources.NotFoundException e) {
return 0;
}
return 0;
}
//TODO: Hack for showcase appearing behind nav bar
public RelativeLayout.LayoutParams getRightParam(Resources res) {
RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
int margin = ((Number) (res.getDisplayMetrics().density * 12)).intValue();
lps.setMargins(margin, margin, margin, getNavigationBarHeight(res.getConfiguration().orientation) + 5);
return lps;
}
static int bias = 1;
private void setTutorialNoShowcase()
{
//Using the same target multiple times doesn't update the showcase
// tutorial.setTarget(ViewTarget.NONE);
// So this funkiness places the showcase off screen flittering back and forth one pixel
// This doesn't screw up word wrap.
// tutorial.setScaleMultiplier(0.1f);
bias *= -1;
tutorial.setShowcaseX(mDisplayWidth + 1000 + bias);
}
private void setTutorialHomeView(boolean animate)
{
PointTarget home = new PointTarget(16,16); //Design guideline is 32x32
tutorial.setShowcase(home, animate);
}
/**
* Showcase item or overflow if it doesn't exist
* @param itemId menu id
* @param animate Animate the showcase from the previous spot. Recommend FALSE if previous showcase was NONE
*/
private void setTutorialActionView(int itemId, boolean animate)
{
ViewTarget target;
View itemView = findViewById(itemId);
if (itemView == null)
{
//List of all mToolbar items, assuming last is overflow
List<View> views = mToolbar.getTouchables();
target = new ViewTarget(views.get(views.size()-1)); //overflow
}
else
{
target = new ViewTarget(itemView);
}
tutorial.setShowcase(target, animate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment