Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.miz.introactivity;

import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -14,7 +17,8 @@
*/
public abstract class BaseIntroFragment extends Fragment {

public static final int RESOURCE_TYPE_LAYOUT = 0, RESOURCE_TYPE_DRAWABLE = 1;
public static final int RESOURCE_TYPE_LAYOUT = 0;
public static final int RESOURCE_TYPE_DRAWABLE = 1;

/**
* Get the title for the intro screen.
Expand All @@ -26,7 +30,7 @@ public abstract class BaseIntroFragment extends Fragment {
* Get the text color of the intro screen title.
* @return Text color of the title.
*/
protected abstract int getTitleColor();
@ColorInt protected abstract int getTitleColor();

/**
* Get the description for the intro screen.
Expand All @@ -38,19 +42,19 @@ public abstract class BaseIntroFragment extends Fragment {
* Get the text color of the intro screen description.
* @return Text color of the description.
*/
protected abstract int getDescriptionColor();
@ColorInt protected abstract int getDescriptionColor();

/**
* Get the layout ID of the layout to inflate.
* @return Layout ID to inflate.
*/
protected abstract int getLayoutId();
@LayoutRes protected abstract int getLayoutId();

/**
* Get the drawable ID of the drawable to show.
* @return ID of the drawable to show.
*/
protected abstract int getDrawableId();
@DrawableRes protected abstract int getDrawableId();

/**
* Get the type of resource ID. Can be either RESOURCE_TYPE_LAYOUT
Expand Down
54 changes: 47 additions & 7 deletions library/src/main/java/com/miz/introactivity/IntroActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.animation.ArgbEvaluator;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -25,7 +27,7 @@ public abstract class IntroActivity extends AppCompatActivity {
private IntroScreenPagerAdapter mPagerAdapter;
private LinearLayout mProgressLayout;
private boolean mShowSkipButton, mShowNextButton;
private int mProgressCircleColor;
private int mProgressCircleColor = Integer.MIN_VALUE;

@Override
protected final void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -183,7 +185,7 @@ private void setProgressSelection(int position) {
R.drawable.progress_circle_selected :
R.drawable.progress_circle);

if (mProgressCircleColor == 0) {
if (mProgressCircleColor == Integer.MIN_VALUE) {
mProgressCircleColor = ContextCompat.getColor(this, R.color.progress_circle_color);
}

Expand All @@ -197,10 +199,19 @@ private void setProgressSelection(int position) {
* of the intro screen.
* @param color Progress circle color to set.
*/
protected void setProgressCircleColor(int color) {
protected void setProgressCircleColor(@ColorInt int color) {
mProgressCircleColor = color;
}

/**
* Set the color of the progress circles at the bottom
* of the intro screen.
* @param colorResId Progress circle color resource to set.
*/
protected void setProgressCircleColorRes(@ColorRes int colorResId) {
mProgressCircleColor = ContextCompat.getColor(this, colorResId);
}

/**
* Use this method to initialize your intro screens
* and set up various styling options.
Expand All @@ -210,8 +221,9 @@ protected void setProgressCircleColor(int color) {
/**
* Add an intro screen (Fragment) to the ViewPager.
* @param introScreen Fragment to add.
* @param backgroundColor The background color to apply
*/
protected void addIntroScreen(BaseIntroFragment introScreen, int backgroundColor) {
protected void addIntroScreen(BaseIntroFragment introScreen, @ColorInt int backgroundColor) {
mPagerAdapter.addFragment(introScreen, backgroundColor);
}

Expand All @@ -237,7 +249,16 @@ protected void setShowSkipButton(boolean showSkipButton) {
* Set the text color of the Skip button. Default color is white (#F0F0F0).
* @param color Text color to set.
*/
protected void setSkipButtonTextColor(int color) {
protected void setSkipButtonTextColor(@ColorInt int color) {
mSkipButton.setTextColor(color);
}

/**
* Set the text color of the Skip button. Default color is white (#F0F0F0).
* @param color Text color to set.
*/
protected void setSkipButtonTextColorRes(@ColorRes int colorResId) {
int color = ContextCompat.getColor(this, colorResId);
mSkipButton.setTextColor(color);
}

Expand All @@ -246,7 +267,17 @@ protected void setSkipButtonTextColor(int color) {
* will be 25 percent opaque. Default color is white (#FFFFFF).
* @param color Background color for the Next / Done button.
*/
protected void setNextButtonBackgroundColor(int color) {
protected void setNextButtonBackgroundColor(@ColorInt int color) {
mNextButton.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

/**
* Set the background color of the Next / Done button. The selected color
* will be 25 percent opaque. Default color is white (#FFFFFF).
* @param colorResId Background color resource for the Next / Done button.
*/
protected void setNextButtonBackgroundColorRes(@ColorRes int colorResId) {
int color = ContextCompat.getColor(this, colorResId);
mNextButton.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

Expand All @@ -255,10 +286,19 @@ protected void setNextButtonBackgroundColor(int color) {
* Default color is white (#F0F0F0).
* @param color
*/
protected void setNextButtonIconColor(int color) {
protected void setNextButtonIconColor(@ColorInt int color) {
mNextButton.setColor(color);
}

/**
* Set the color of the arrow / done icon for the Next / Done button.
* Default color is white (#F0F0F0).
* @param colorResId
*/
protected void setNextButtonIconColorRes(@ColorRes int colorResId) {
mNextButton.setColorRes(colorResId);
}

/**
* Callback when the "Skip" button is pressed.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.miz.introactivity;

import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;

/**
Expand Down Expand Up @@ -61,8 +62,8 @@ public static IntroFragment newInstance(String title, String description, int re
* @param descriptionColor Text color for the description.
* @return IntroFragment with title, description and custom colors.
*/
public static IntroFragment newInstance(String title, int titleColor, String description,
int descriptionColor) {
public static IntroFragment newInstance(String title, @ColorInt int titleColor, String description,
@ColorInt int descriptionColor) {
Bundle args = new Bundle();
args.putString(TITLE, title);
args.putInt(TITLE_COLOR, titleColor);
Expand All @@ -85,8 +86,8 @@ public static IntroFragment newInstance(String title, int titleColor, String des
* @param resourceIdType Type for the reference ID
* @return
*/
public static IntroFragment newInstance(String title, int titleColor, String description,
int descriptionColor, int resourceId, int resourceIdType) {
public static IntroFragment newInstance(String title, @ColorInt int titleColor, String description,
@ColorInt int descriptionColor, int resourceId, int resourceIdType) {
Bundle args = new Bundle();
args.putString(TITLE, title);
args.putInt(TITLE_COLOR, titleColor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.miz.introactivity;

import android.support.annotation.ColorInt;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Expand All @@ -24,7 +25,7 @@ public IntroScreenPagerAdapter(FragmentManager fm) {
* @param fragment BaseIntroFragment to add.
* @param backgroundColor Background color for the Fragment to add.
*/
public void addFragment(BaseIntroFragment fragment, int backgroundColor) {
public void addFragment(BaseIntroFragment fragment, @ColorInt int backgroundColor) {
mBackgroundColors.put(mFragments.size(), backgroundColor);
mFragments.add(fragment);
}
Expand All @@ -47,4 +48,4 @@ public Fragment getItem(int position) {
public int getCount() {
return mFragments.size();
}
}
}
13 changes: 12 additions & 1 deletion library/src/main/java/com/miz/introactivity/NextDoneButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.AttributeSet;
Expand Down Expand Up @@ -72,11 +74,20 @@ private int getNextDrawable() {
* Set the color of the button icon.
* @param color Color for the button icon.
*/
public void setColor(int color) {
public void setColor(@ColorInt int color) {
mColor = color;
tintDrawables();
}

/**
* Set the color of the button icon.
* @param colorResId Color resource for the button icon.
*/
public void setColorRes(@ColorRes int colorResId) {
mColor = ContextCompat.getColor(getContext(), colorResId);
tintDrawables();
}

private void tintDrawables() {
if (Utils.hasLollipop()) {
mNextDrawable.setTint(mColor);
Expand Down