amlcurran/ShowcaseView — pull request #134 by bwp (2014-01-03 15:40:50+00:00)
Title: Added Optional Skip Button, Added support for manual trigger 

-Added ability to manually trigger a showcase even if its set to show once and it has already shown. This was done to add support for an on demand showcase trigger.
-Moved test libraries into seperate folder 'libstest' so they could be given a scope of test. This will prevent their inclusion in the apk and avoid potential out of memory errors with roboelectric.
-Added Junit library for test compilation.
-Added a gradle project which can likely be ignored.
-Small cleanup.

To Turn off the skip button:

ShowcaseView.ConfigOptions options = new ShowcaseView.ConfigOptions();
options.noSkipButton = true;

Sample Implementation:

public class SomeClass {
Activity mActivity;
OnShowcaseEventListener mAnalyticsListener;
ShowcaseView mShowcaseView;
int counter = -1;

public SomeClass(Activity activity) {
mActivity = activity;
initAnalyticsHandler();
}

/**
* some method thats called to either programmatically or manually trigger a series of showcase views
*/
public void showcaseSomething(final boolean manualTrigger) {
new Handler().post(new Runnable() {
@Override
public void run() {
try {
mShowcaseView = ShowcaseView.insertShowcaseView(new ViewTarget(R.id.showcase_id, mActivity),
mActivity, R.string.some_title, R.string.some_description,
createConfigOptions(R.id.showcase_id), manualTrigger);
counter = 0;
mShowcaseView.setScaleMultiplier(.50f);
mShowcaseView.overrideOKButtonClick(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "showcase ok click counter " + counter);
switch (counter) {
case 0:
mShowcaseView.setShowcase(new ViewTarget(R.id.showcase_id2, mActivity), false);
mShowcaseView.setText(R.string.some_title2, R.string.some_description2);
mShowcaseView.setScaleMultiplier(.35f);
break;
case 1:
markAsShownAndReset();
break;
}
counter++;
}
});
mShowcaseView.overrideSKIPButtonClick(new View.OnClickListener() {
@Override
public void onClick(View v) {
markAsShownAndReset();
}
});
} catch (Exception ex) {
Log.e(TAG, "showcaseSomething", ex);
}
}
});
}

protected ShowcaseView.ConfigOptions createConfigOptions(int id) {
ShowcaseView.ConfigOptions options = new ShowcaseView.ConfigOptions();
options.hideOnClickOutside = false;
options.shotType = ShowcaseView.TYPE_ONE_SHOT;
options.block = true;
options.showcaseId = id;
return options;
}

protected void markAsShownAndReset() {
mShowcaseView.markViewAsShown();
mShowcaseView.hide();
counter = -1;
removeShowcaseViewFromActivity();
}

protected void removeShowcaseViewFromActivity() {
if (mShowcaseView.getConfigOptions().insert == ShowcaseView.INSERT_TO_DECOR) {
Log.d(TAG, "removeShowcaseViewFromActivity Decor");
ViewGroup decorViewGroup = (ViewGroup) mActivity.getWindow().getDecorView();
mShowcaseView.removeShowcaseViews(decorViewGroup);
} else {
Log.d(TAG, "removeShowcaseViewFromActivity View");
ViewGroup contentViewGroup = (ViewGroup) mActivity.findViewById(android.R.id.content);
mShowcaseView.removeShowcaseViews(contentViewGroup);
}
}