Skip to content

Commit

Permalink
Merge pull request chyrta#2 from GrenderG/master
Browse files Browse the repository at this point in the history
Ability to use Floating Action Button or not and to change divider color, its height and visibility.
  • Loading branch information
Dzmitry Chyrta committed Apr 9, 2016
2 parents c5b44ac + 311cc49 commit 2fb1f5b
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 23 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Android Onboarder is a lightweight library that helps you to create a simple and

<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo1.gif" width="250px">
<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo2.gif" width="250px">
<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo3.gif" width="250px">

## Usage

Expand Down Expand Up @@ -77,14 +78,21 @@ public class IntroActivity extends OnboarderActivity {

#### Tips

Remember that you can change dot's colors (active and inactive) and darken the layout where buttons are placed.
(Inside your Activity that extends ```OnboarderActivity```):
Remember that you can (Inside your Activity that extends ```OnboarderActivity```):
- Change dot's colors (active and inactive)
- Darken the layout where buttons are placed
- Change divider color, height (in dp) and visibility
- Choose to use ```FloatingActionButton``` or not

```java

setActiveIndicatorColor(android.R.color.white);
setInactiveIndicatorColor(android.R.color.darker_gray);
shouldDarkenButtonsLayout(true);
setDividerColor(Color.WHITE);
setDividerHeight(2);
setDividerVisibility(View.GONE);
shouldUseFloatingActionButton(true);

```

Expand Down
128 changes: 128 additions & 0 deletions README.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidOnboarder-green.svg?style=true)](https://android-arsenal.com/details/1/3393)

![Maven Badge](https://maven-badges.herokuapp.com/maven-central/com.github.chyrta/AndroidOnboarder/badge.svg)

# Android Onboarder
Android Onboarder is a lightweight library that helps you to create a simple and beautiful welcome screen (as known as App Intro, Onboarding Experience and etc.) for your users.

<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo1.gif" width="250px">
<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo2.gif" width="250px">
<image src="https://raw.githubusercontent.com/GrenderG/AndroidOnboarder/master/art/demo3.gif" width="250px">

## Usage

#### Gradle

Add dependency in your build.gradle

```groovy
compile 'com.github.chyrta:AndroidOnboarder:0.4'
```
#### Maven

```
<dependency>
<groupId>com.github.chyrta</groupId>
<artifactId>AndroidOnboarder</artifactId>
<version>0.4</version>
<type>pom</type>
</dependency>
```

#### Implementation

Create an activity which should inherits from OnboarderActivity. Look at the example below to see how that library works.

```java

public class IntroActivity extends OnboarderActivity {

List<OnboarderPage> onboarderPages;

@Override
protected void onCreate(Bundle savedInstanceState) {
onboarderPages = new ArrayList<OnboarderPage>();

// Create your first page
OnboarderPage onboarderPage1 = new OnboarderPage("Title 1", "Description 1");
OnboarderPage onboarderPage2 = new OnboarderPage(R.string.app_title, R.string.app_description, R.drawable.my_awesome_image);

// You can define title and description colors (by default white)
onboarderPage1.setTitleColor(R.color.black);
onboarderPage1.setDescriptionColor(R.color.white);

// Don't forget to set background color for your page
onboarderPage1.setBackgroundColor(R.color.my_awesome_color);

// Add your pages to the list
onboarderPages.add(onboarderPage1);
onboarderPages.add(onboarderPage2);

// And pass your pages to 'setOnboardPagesReady' method
setOnboardPagesReady(onboarderPages);

}

@Override
public void onSkipButtonPressed() {
// Define your actions when the user press 'Skip' button
}

@Override
public void onFinishButtonPressed()
// Define your actions when the user press 'Finish' button
}

}
```

#### Tips

Remember that you can (Inside your Activity that extends ```OnboarderActivity```):
- Change dot's colors (active and inactive)
- Darken the layout where buttons are placed
- Change divider color, height (in dp) and visibility
- Chose to use ```FloatingActionButton``` or not

```java

setActiveIndicatorColor(android.R.color.white);
setInactiveIndicatorColor(android.R.color.darker_gray);
shouldDarkenButtonsLayout(true);
setDividerColor(Color.WHITE);
setDividerHeight(2);
setDividerVisibility(View.GONE);
shouldUseFloatingActionButton(true);

```


## Contributions

Feel free to create issues and pull requests

## License

```
MIT License

Copyright (c) 2016 Dzmitry Chyrta, Daniel Morales

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
Binary file added art/demo3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.chyrta.onboarder;

import android.animation.ArgbEvaluator;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
Expand All @@ -27,10 +30,12 @@ public abstract class OnboarderActivity extends AppCompatActivity implements Vie
private ImageButton ibNext;
private Button btnSkip, btnFinish;
private FrameLayout buttonsLayout;
private FloatingActionButton fab;
private View divider;
private ArgbEvaluator evaluator;

private boolean shouldDarkenButtonsLayout = false;
private boolean shouldUseFloatingActionButton = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -43,12 +48,14 @@ protected void onCreate(Bundle savedInstanceState) {
btnSkip = (Button) findViewById(R.id.btn_skip);
btnFinish = (Button) findViewById(R.id.btn_finish);
buttonsLayout = (FrameLayout) findViewById(R.id.buttons_layout);
fab = (FloatingActionButton) findViewById(R.id.fab);
divider = findViewById(R.id.divider);
vpOnboarderPager = (ViewPager) findViewById(R.id.vp_onboarder_pager);
vpOnboarderPager.addOnPageChangeListener(this);
ibNext.setOnClickListener(this);
btnSkip.setOnClickListener(this);
btnFinish.setOnClickListener(this);
fab.setOnClickListener(this);
evaluator = new ArgbEvaluator();
}

Expand All @@ -71,6 +78,41 @@ public void shouldDarkenButtonsLayout(boolean shouldDarkenButtonsLayout) {
this.shouldDarkenButtonsLayout = shouldDarkenButtonsLayout;
}

public void setDividerColor(@ColorInt int color) {
if (!this.shouldDarkenButtonsLayout)
this.divider.setBackgroundColor(color);
}

public void setDividerHeight(int heightInDp) {
if (!this.shouldDarkenButtonsLayout)
this.divider.getLayoutParams().height =
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightInDp,
getResources().getDisplayMetrics());
}

public void setDividerVisibility(int dividerVisibility) {
this.divider.setVisibility(dividerVisibility);
}

public void shouldUseFloatingActionButton(boolean shouldUseFloatingActionButton) {

this.shouldUseFloatingActionButton = shouldUseFloatingActionButton;

if (shouldUseFloatingActionButton) {
this.fab.setVisibility(View.VISIBLE);
this.setDividerVisibility(View.GONE);
this.shouldDarkenButtonsLayout(false);
this.btnFinish.setVisibility(View.GONE);
this.btnSkip.setVisibility(View.GONE);
this.ibNext.setVisibility(View.GONE);
this.ibNext.setFocusable(false);
this.buttonsLayout.getLayoutParams().height =
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96,
getResources().getDisplayMetrics());
}

}

private int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
Expand All @@ -90,12 +132,13 @@ public void setStatusBackgroundColor() {
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.ib_next) {
boolean isInLastPage = vpOnboarderPager.getCurrentItem() == onboarderAdapter.getCount() - 1;
if (i == R.id.ib_next || i == R.id.fab && !isInLastPage) {
vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() + 1);
} else if (i == R.id.btn_skip) {
vpOnboarderPager.setCurrentItem(onboarderAdapter.getCount());
onSkipButtonPressed();
} else if (i == R.id.btn_finish) {
} else if (i == R.id.btn_finish || i == R.id.fab && isInLastPage) {
onFinishButtonPressed();
}
}
Expand All @@ -121,8 +164,10 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
public void onPageSelected(int position) {
int lastPagePosition = onboarderAdapter.getCount() - 1;
circleIndicatorView.setCurrentPage(position);
ibNext.setVisibility(position == lastPagePosition ? View.GONE : View.VISIBLE);
btnFinish.setVisibility(position == lastPagePosition ? View.VISIBLE : View.GONE);
ibNext.setVisibility(position == lastPagePosition && !this.shouldUseFloatingActionButton ? View.GONE : View.VISIBLE);
btnFinish.setVisibility(position == lastPagePosition && !this.shouldUseFloatingActionButton ? View.VISIBLE : View.GONE);
if (this.shouldUseFloatingActionButton)
this.fab.setImageResource(position == lastPagePosition ? R.drawable.ic_done_white_24dp : R.drawable.ic_arrow_forward_white_24dp);
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions onboarder/src/main/res/layout/activity_onboarder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
android:layout_height="1dp"
android:layout_gravity="bottom"
android:layout_marginBottom="?attr/actionBarSize"
android:alpha="0.12"
android:background="@android:color/white"/>
android:background="?android:attr/listDivider"/>

<FrameLayout
android:id="@+id/buttons_layout"
Expand Down Expand Up @@ -77,4 +76,13 @@

</FrameLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/activity_margin"
android:visibility="gone"
android:src="@drawable/ic_arrow_forward_white_24dp" />

</android.support.design.widget.CoordinatorLayout>
21 changes: 7 additions & 14 deletions onboarder/src/main/res/layout/fragment_onboarder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
android:layout_height="match_parent"
android:padding="@dimen/activity_margin">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_onboarder_image"
android:layout_width="@dimen/section_image_item"
android:layout_height="@dimen/section_image_item"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:alpha="1.0"
android:scaleType="fitCenter"/>

</FrameLayout>
<ImageView
android:id="@+id/iv_onboarder_image"
android:layout_width="@dimen/section_image_item"
android:layout_height="@dimen/section_image_item"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:scaleType="fitCenter"/>

<LinearLayout
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chyrta.androidonboarder;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Toast;

import com.chyrta.onboarder.OnboarderActivity;
Expand Down Expand Up @@ -35,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

setOnboardPagesReady(pages);

}

@Override
Expand Down

0 comments on commit 2fb1f5b

Please sign in to comment.