Skip to content

Commit

Permalink
Support for handling clicks. Set default background color to transpar…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
mattec92 committed Sep 18, 2016
1 parent 58dd9d3 commit c16a791
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Overlay background color, text color and border color are specified globally.

`withBorderColor(int borderColorResourceId)`

#### Handling clicks

It is possible to set your own click listener to the onboarding overlay by using `setOnClickListener(View.OnClickListener onClickListener)`,

For closing the onboarding overlay on click, use `clearOnClick(boolean animate)`.

#### Onboarding elements

The following onboarding element types are available.
Expand Down
60 changes: 43 additions & 17 deletions lib/src/main/java/se/mattec/onboardinglayout/OnboardingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class OnboardingScreen
private List<OnboardingElement> onboardingElements;
private Context context;

private int backgroundColorResourceId = -1;
private int backgroundColorResourceId = android.R.color.transparent;
private int textColorResourceId = -1;
private int borderColorResourceId = -1;

private View.OnClickListener onClickListener;

private View backgroundView;

public OnboardingScreen(OnboardingLayout onboardingLayout)
Expand Down Expand Up @@ -100,32 +102,56 @@ public OnboardingScreen withBorderColor(int borderColorResourceId)
return this;
}

public OnboardingScreen show(boolean animate)
public OnboardingScreen setOnClickListener(View.OnClickListener onClickListener)
{
this.onClickListener = onClickListener;
return this;
}

public OnboardingScreen clearOnClick(final boolean animate)
{
if (backgroundColorResourceId != -1)
setOnClickListener(new View.OnClickListener()
{
List<BackgroundView.HoleSpec> holeSpecs = new ArrayList<>();
for (OnboardingElement element : onboardingElements)

@Override
public void onClick(View view)
{
if (element instanceof HoleOnboardingElement)
{
holeSpecs.add(((HoleOnboardingElement) element).getHoleSpec());
}
OnboardingScreen.this.clear(animate);
}

BackgroundView backgroundView = new BackgroundView(context);
backgroundView.setBackgroundColor(backgroundColorResourceId);
backgroundView.setHoleSpecs(holeSpecs);
backgroundView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
onboardingLayout.addView(backgroundView);
this.backgroundView = backgroundView;
});
return this;
}

if (animate)
public OnboardingScreen clearOnClick()
{
return clearOnClick(false);
}

public OnboardingScreen show(boolean animate)
{
List<BackgroundView.HoleSpec> holeSpecs = new ArrayList<>();
for (OnboardingElement element : onboardingElements)
{
if (element instanceof HoleOnboardingElement)
{
AnimationUtils.fadeIn(backgroundView);
holeSpecs.add(((HoleOnboardingElement) element).getHoleSpec());
}
}

BackgroundView backgroundView = new BackgroundView(context);
backgroundView.setBackgroundResource(backgroundColorResourceId);
backgroundView.setHoleSpecs(holeSpecs);
backgroundView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
backgroundView.setOnClickListener(onClickListener);
onboardingLayout.addView(backgroundView);
this.backgroundView = backgroundView;

if (animate)
{
AnimationUtils.fadeIn(backgroundView);
}

for (OnboardingElement element : onboardingElements)
{
View view = element.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected void onDraw(Canvas canvas)
canvas.drawBitmap(bitmap, 0, 0, paint);
}

public void setBackgroundColor(int backgroundResourceId)
@Override
public void setBackgroundResource(int backgroundResourceId)
{
backgroundPaint.setColor(ContextCompat.getColor(getContext(), backgroundResourceId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void openTextOnboarding()
onboardingScreen = Onboard.in(onboardingLayout)
.withOverlayColor(R.color.black_trans)
.withTextColor(R.color.white)
.clearOnClick(true)
.withText("Above the center").above(centerView)
.withText("Below the center").below(centerView)
.withText("To left of the center\nTwo lines").toLeftOf(centerView)
Expand All @@ -137,6 +138,7 @@ private void openArrowOnboarding()
onboardingScreen = Onboard.in(onboardingLayout)
.withOverlayColor(R.color.black_trans)
.withTextColor(R.color.white)
.clearOnClick(true)
.withTextAndArrow("Above the center", ArrowLocation.RIGHT).above(centerView)
.withTextAndArrow("Below the center", ArrowLocation.LEFT).below(centerView)
.withTextAndArrow("To left of the center\nTwo lines", ArrowLocation.ABOVE).toLeftOf(centerView)
Expand All @@ -157,6 +159,7 @@ private void openBorderOnboarding()
onboardingScreen = Onboard.in(onboardingLayout)
.withOverlayColor(R.color.black_trans)
.withBorderColor(R.color.white)
.clearOnClick(true)
.withBorder(true).around(topLeftView)
.withBorder(false).around(topRightView)
.withDashedBorder(false).around(bottomRightView)
Expand All @@ -168,6 +171,7 @@ private void openHoleOnboarding()
{
onboardingScreen = Onboard.in(onboardingLayout)
.withOverlayColor(R.color.black_trans)
.clearOnClick(true)
.withHole(true).around(topLeftView)
.withHole(false).around(topRightView)
.withHole(true).around(bottomLeftView)
Expand All @@ -179,6 +183,7 @@ private void openImageOnboarding()
{
onboardingScreen = Onboard.in(onboardingLayout)
.withOverlayColor(R.color.black_trans)
.clearOnClick(true)
.withImage(R.mipmap.ic_launcher).atop(centerView)
.withImage(R.mipmap.ic_launcher).above(centerView)
.withImage(R.mipmap.ic_launcher).below(centerView)
Expand Down

0 comments on commit c16a791

Please sign in to comment.