Skip to content

Commit

Permalink
Fixes for new Material Design Guidlines
Browse files Browse the repository at this point in the history
Added CTA button
Added bug tracking for demo
Fixed #53
  • Loading branch information
heinrichreimer committed May 27, 2016
1 parent c4c446d commit a805893
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/app/google-services.json
*.iml
.gradle
/local.properties
Expand Down
14 changes: 10 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def versionBuild = 0 // bump for dogfood builds, public betas, etc.

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.heinrichreimersoftware.materialintro.demo"
Expand All @@ -30,7 +30,13 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:design:23.2.0'
//Support
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
//Firebase
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-crash:9.0.0'
}

apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
setButtonBackVisible(showBack);
setButtonNextVisible(showNext);
setButtonCtaVisible(getStartedEnabled);
setButtonCtaTintMode(BUTTON_CTA_TINT_MODE_TEXT);

addSlide(new SimpleSlide.Builder()
.title(R.string.title_material_metaphor)
Expand Down Expand Up @@ -137,12 +138,14 @@ public boolean canGoBackward(int position) {
@Override
public void onNavigationBlocked(int position, int direction) {
View contentView = findViewById(android.R.id.content);
Slide slide = getSlide(position);

if (slide == permissionsSlide) {
Snackbar.make(contentView, R.string.label_grant_permissions, Snackbar.LENGTH_LONG).show();
} else if (slide == loginSlide) {
Snackbar.make(contentView, R.string.label_fill_out_form, Snackbar.LENGTH_LONG).show();
if (contentView != null) {
Slide slide = getSlide(position);

if (slide == permissionsSlide) {
Snackbar.make(contentView, R.string.label_grant_permissions, Snackbar.LENGTH_LONG).show();
} else if (slide == loginSlide) {
Snackbar.make(contentView, R.string.label_fill_out_form, Snackbar.LENGTH_LONG).show();
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def versionBuild = 0 // bump for dogfood builds, public betas, etc.

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 15
Expand All @@ -28,5 +28,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:appcompat-v7:23.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -67,6 +68,14 @@ public class IntroActivity extends AppCompatActivity {
public static final int BUTTON_BACK_FUNCTION_BACK = 1;
public static final int BUTTON_BACK_FUNCTION_SKIP = 2;

@IntDef({BUTTON_CTA_TINT_MODE_BACKGROUND, BUTTON_CTA_TINT_MODE_TEXT})
@Retention(RetentionPolicy.SOURCE)
@interface ButtonCtaTintMode {
}

public static final int BUTTON_CTA_TINT_MODE_BACKGROUND = 1;
public static final int BUTTON_CTA_TINT_MODE_TEXT = 2;

private final ArgbEvaluator evaluator = new ArgbEvaluator();
private LinearLayout frame;
private FadeableViewPager pager;
Expand All @@ -82,6 +91,8 @@ public class IntroActivity extends AppCompatActivity {
private int buttonNextFunction = BUTTON_NEXT_FUNCTION_NEXT_FINISH;
@ButtonBackFunction
private int buttonBackFunction = BUTTON_BACK_FUNCTION_SKIP;
@ButtonCtaTintMode
private int buttonCtaTintMode = BUTTON_CTA_TINT_MODE_BACKGROUND;
private int position = 0;
private float positionOffset = 0;

Expand Down Expand Up @@ -336,9 +347,13 @@ private void updateTaskDescription() {
}

private void updateBackground() {
@ColorInt
int background;
@ColorInt
int backgroundNext;
@ColorInt
int backgroundDark;
@ColorInt
int backgroundDarkNext;

if (position == getCount()) {
Expand Down Expand Up @@ -373,7 +388,7 @@ private void updateBackground() {

if (position + positionOffset >= adapter.getCount() - 1) {
backgroundNext = ColorUtils.setAlphaComponent(background, 0x00);
backgroundDarkNext = Color.TRANSPARENT;
backgroundDarkNext = ColorUtils.setAlphaComponent(backgroundDark, 0x00);
}

background = (Integer) evaluator.evaluate(positionOffset, background, backgroundNext);
Expand All @@ -386,11 +401,15 @@ private void updateBackground() {
//Slightly darken the background color a bit for more contrast
backgroundDarkHsv[2] *= 0.95;
int backgroundDarker = Color.HSVToColor(backgroundDarkHsv);
ViewCompat.setBackgroundTintList(buttonCta, ColorStateList.valueOf(backgroundDarker));
pagerIndicator.setPageIndicatorColor(backgroundDarker);
ViewCompat.setBackgroundTintList(buttonNext, ColorStateList.valueOf(backgroundDarker));
ViewCompat.setBackgroundTintList(buttonBack, ColorStateList.valueOf(backgroundDarker));

@ColorInt
int backgroundButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ?
ContextCompat.getColor(this, android.R.color.white) : backgroundDarker;
ViewCompat.setBackgroundTintList(buttonCta, ColorStateList.valueOf(backgroundButtonCta));

int iconColor;
if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) {
//Light background
Expand All @@ -399,11 +418,15 @@ private void updateBackground() {
//Dark background
iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_dark);
}
buttonCta.setTextColor(iconColor);
pagerIndicator.setCurrentPageIndicatorColor(iconColor);
DrawableCompat.setTint(buttonNext.getDrawable(), iconColor);
DrawableCompat.setTint(buttonBack.getDrawable(), iconColor);

@ColorInt
int textColorButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ?
backgroundDarker : iconColor;
buttonCta.setTextColor(textColorButtonCta);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(backgroundDark);

Expand Down Expand Up @@ -489,6 +512,7 @@ private void updateViewPositions() {
} else {
buttonNext.setTranslationY(-2 * buttonNext.getHeight());
}
buttonCta.setTranslationY(offset * 2 * buttonNext.getWidth());
pagerIndicator.setTranslationY(offset * 2 * buttonNext.getWidth());
updateButtonNextDrawable();
}
Expand All @@ -506,25 +530,29 @@ private void updateViewPositions() {
} else {
buttonCta.setVisibility(View.VISIBLE);
//Fade in
buttonCta.setText(buttonNext.first);
if (!buttonCta.getText().equals(buttonNext.first))
buttonCta.setText(buttonNext.first);
buttonCta.setOnClickListener(buttonNext.second);
buttonCta.setAlpha(offset);
}
} else {
if (buttonNext == null) {
buttonCta.setVisibility(View.VISIBLE);
//Fade out
buttonCta.setText(button.first);
if (!buttonCta.getText().equals(button.first))
buttonCta.setText(button.first);
buttonCta.setOnClickListener(button.second);
buttonCta.setAlpha(1 - offset);
} else {
buttonCta.setVisibility(View.VISIBLE);
//Fade text
if (offset >= 0.5f) {
buttonCta.setText(buttonNext.first);
if (!buttonCta.getText().equals(buttonNext.first))
buttonCta.setText(buttonNext.first);
buttonCta.setOnClickListener(buttonNext.second);
} else {
buttonCta.setText(button.first);
if (!buttonCta.getText().equals(button.first))
buttonCta.setText(button.first);
buttonCta.setOnClickListener(button.second);
}
}
Expand Down Expand Up @@ -580,6 +608,15 @@ public void setButtonCtaVisible(boolean buttonCtaVisible) {
updateViewPositions();
}

@ButtonCtaTintMode
public int getButtonCtaTintMode() {
return buttonCtaTintMode;
}

public void setButtonCtaTintMode(@ButtonCtaTintMode int buttonCtaTintMode) {
this.buttonCtaTintMode = buttonCtaTintMode;
}

@ButtonBackFunction
public int getButtonBackFunction() {
return buttonBackFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.database.DataSetObserver;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.util.AttributeSet;
import android.view.View;
Expand All @@ -25,7 +26,8 @@ public void setAdapter(PagerAdapter adapter) {

@Override
public PagerAdapter getAdapter() {
return ((PagerAdapterWrapper) super.getAdapter()).getAdapter();
PagerAdapterWrapper wrapper = (PagerAdapterWrapper) super.getAdapter();
return wrapper == null ? null : wrapper.getAdapter();
}

@SuppressWarnings("deprecation")
Expand All @@ -36,12 +38,12 @@ public void setOnPageChangeListener(OnPageChangeListener listener) {
}

@Override
public void addOnPageChangeListener(OnPageChangeListener listener) {
public void addOnPageChangeListener(@NonNull OnPageChangeListener listener) {
super.addOnPageChangeListener(new OnPageChangeListenerWrapper(listener));
}

@Override
public void removeOnPageChangeListener(OnPageChangeListener listener) {
public void removeOnPageChangeListener(@NonNull OnPageChangeListener listener) {
super.removeOnPageChangeListener(new OnPageChangeListenerWrapper(listener));
}

Expand All @@ -50,7 +52,6 @@ public void setPageTransformer(boolean reverseDrawingOrder, PageTransformer tran
super.setPageTransformer(reverseDrawingOrder, new PageTransformerWrapper(transformer, getAdapter()));
}


private class OnPageChangeListenerWrapper implements OnPageChangeListener{
private final OnPageChangeListener listener;

Expand All @@ -62,7 +63,7 @@ private OnPageChangeListenerWrapper(OnPageChangeListener listener) {
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int count = listener instanceof OnOverscrollPageChangeListener ?
FadeableViewPager.super.getAdapter().getCount() : getAdapter().getCount();
listener.onPageScrolled(Math.min(position, count),
listener.onPageScrolled(Math.min(position, count - 1),
position < count ? positionOffset : 0,
position < count ? positionOffsetPixels : 0);
}
Expand All @@ -71,7 +72,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
public void onPageSelected(int position) {
int count = listener instanceof OnOverscrollPageChangeListener ?
FadeableViewPager.super.getAdapter().getCount() : getAdapter().getCount();
listener.onPageSelected(Math.min(position, count));
listener.onPageSelected(Math.min(position, count - 1));
}

@Override
Expand Down Expand Up @@ -218,7 +219,7 @@ public CharSequence getPageTitle(int position) {
public float getPageWidth(int position) {
if(position < adapter.getCount())
return adapter.getPageWidth(position);
return 1.f;
return 1f;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.support.annotation.ColorInt;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.Interpolator;

Expand Down Expand Up @@ -76,8 +75,8 @@ public class InkPageIndicator extends View implements ViewPager.OnPageChangeList
private ViewPager viewPager;

// state
private int pageCount;
private int currentPage;
private int pageCount = 0;
private int currentPage = -1;
private int previousPage;
private float selectedDotX;
private boolean selectedDotInPosition;
Expand Down Expand Up @@ -222,8 +221,8 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
@Override
public void onPageSelected(int position) {
if (isAttachedToWindow) {
// this is the main event we're interested in!
setSelectedPage(position);
// this is the main event we're interested in!
} else {
// when not attached, don't animate the move, just store immediately
setCurrentPageImmediate();
Expand All @@ -237,6 +236,7 @@ public void onPageScrollStateChanged(int state) {

private void setPageCount(int pages) {
pageCount = pages;
calculateDotPositions(getWidth(), getHeight());
resetState();
requestLayout();
}
Expand All @@ -245,12 +245,11 @@ private void calculateDotPositions(int width, int height) {
int left = getPaddingLeft();
int top = getPaddingTop();
int right = width - getPaddingRight();
int bottom = height - getPaddingBottom();

int requiredWidth = getRequiredWidth();
float startLeft = left + ((right - left - requiredWidth) / 2) + dotRadius;

dotCenterX = new float[pageCount];
dotCenterX = new float[Math.max(1, pageCount)];
for (int i = 0; i < pageCount; i++) {
dotCenterX[i] = startLeft + i * (dotDiameter + gap);
}
Expand All @@ -263,14 +262,14 @@ private void calculateDotPositions(int width, int height) {
}

private void setCurrentPageImmediate() {
//if (viewPager.getCurrentItem() == currentPage) return;

if (viewPager != null) {
currentPage = viewPager.getCurrentItem();
} else {
currentPage = 0;
}
if (dotCenterX != null) {
selectedDotX = dotCenterX[currentPage];
}
selectedDotX = dotCenterX[Math.max(0, Math.min(currentPage, dotCenterX.length - 1))];
}

private void resetState() {
Expand All @@ -285,7 +284,6 @@ private void resetState() {

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int desiredHeight = getDesiredHeight();
int height;
switch (MeasureSpec.getMode(heightMeasureSpec)) {
Expand Down Expand Up @@ -676,11 +674,6 @@ public void onAnimationEnd(Animator animation) {

private void setJoiningFraction(int leftDot, float fraction) {
if (leftDot < joiningFractions.length) {

if (leftDot == 1) {
Log.d("PageIndicator", "dot 1 fraction:\t" + fraction);
}

joiningFractions[leftDot] = fraction;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
postInvalidateOnAnimation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SwipeBlockableViewPager extends ViewPager {

private static final int SWIPE_DIRECTION_RIGHT = -1;

private static final int SWIPE_THRESHOLD = 10;
private static final int SWIPE_THRESHOLD = 5;

private float initialX;

Expand Down
Loading

0 comments on commit a805893

Please sign in to comment.