Skip to content

Commit

Permalink
Fixed #89
Browse files Browse the repository at this point in the history
  • Loading branch information
heinrichreimer committed Jul 6, 2016
1 parent 75601f2 commit 17cf16d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.Button;
Expand Down Expand Up @@ -96,6 +98,8 @@ public class IntroActivity extends AppCompatActivity {
public static final int INFINITE = -1;
public static final int DEFAULT_AUTOPLAY_REPEAT_COUNT = INFINITE;

public static final Interpolator ACCELERATE_DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();

private final ArgbEvaluator evaluator = new ArgbEvaluator();
private LinearLayout frame;
private FadeableViewPager pager;
Expand Down Expand Up @@ -716,7 +720,7 @@ private void updateButtonCta() {
if (position + positionOffset < adapter.getCount()) {
//Before fade
Pair<CharSequence, ? extends View.OnClickListener> button = getButtonCta(position);
Pair<CharSequence, ? extends View.OnClickListener> buttonNext = getButtonCta(position + 1);
Pair<CharSequence, ? extends View.OnClickListener> buttonNext = positionOffset == 0 ? null : getButtonCta(position + 1);

if (button == null) {
if (buttonNext == null) {
Expand All @@ -731,6 +735,11 @@ private void updateButtonCta() {
buttonCta.getChildAt(0).setOnClickListener(buttonNext.second);
buttonCta.getChildAt(1).setOnClickListener(buttonNext.second);
buttonCta.setAlpha(positionOffset);
buttonCta.setScaleX(positionOffset);
buttonCta.setScaleY(positionOffset);
ViewGroup.LayoutParams layoutParams = buttonCta.getLayoutParams();
layoutParams.height = Math.round(getResources().getDimensionPixelSize(R.dimen.mi_button_cta_height) * ACCELERATE_DECELERATE_INTERPOLATOR.getInterpolation(positionOffset));
buttonCta.setLayoutParams(layoutParams);
}
}
else {
Expand All @@ -742,9 +751,17 @@ private void updateButtonCta() {
buttonCta.getChildAt(0).setOnClickListener(button.second);
buttonCta.getChildAt(1).setOnClickListener(button.second);
buttonCta.setAlpha(1 - positionOffset);
buttonCta.setScaleX(1 - positionOffset);
buttonCta.setScaleY(1 - positionOffset);
ViewGroup.LayoutParams layoutParams = buttonCta.getLayoutParams();
layoutParams.height = Math.round(getResources().getDimensionPixelSize(R.dimen.mi_button_cta_height) * ACCELERATE_DECELERATE_INTERPOLATOR.getInterpolation(1 - positionOffset));
buttonCta.setLayoutParams(layoutParams);
}
else {
buttonCta.setVisibility(View.VISIBLE);
ViewGroup.LayoutParams layoutParams = buttonCta.getLayoutParams();
layoutParams.height = getResources().getDimensionPixelSize(R.dimen.mi_button_cta_height);
buttonCta.setLayoutParams(layoutParams);
//Fade text
if (positionOffset >= 0.5f) {
if (!((Button) buttonCta.getCurrentView()).getText().equals(buttonNext.first))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ public static void applyShakeAnimation(Context context, View view) {
shake = AnimationUtils.loadAnimation(context, R.anim.shake);
view.startAnimation(shake);
}

}
15 changes: 9 additions & 6 deletions library/src/main/res/layout/activity_intro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,28 @@
<TextSwitcher
android:id="@id/mi_button_cta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="@dimen/mi_button_cta_height"
android:layout_marginBottom="@dimen/mi_baseline"
android:layout_gravity="center_horizontal"
android:visibility="gone"
android:clipChildren="false">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingTop="@dimen/mi_baseline_half"
android:paddingBottom="@dimen/mi_baseline_half"
android:paddingLeft="@dimen/mi_baseline"
android:paddingRight="@dimen/mi_baseline"
android:gravity="center"
android:text="@string/mi_label_button_cta"
android:textColor="?android:textColorPrimaryInverse"/>
android:textColor="?android:textColorPrimaryInverse"
android:maxLines="1"
android:minLines="1"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingTop="@dimen/mi_baseline_half"
android:paddingBottom="@dimen/mi_baseline_half"
Expand All @@ -66,7 +67,9 @@
android:gravity="center"
android:text="@string/mi_label_button_cta"
android:textColor="?android:textColorPrimaryInverse"
android:visibility="gone"/>
android:visibility="gone"
android:maxLines="1"
android:minLines="1"/>

</TextSwitcher>

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<dimen name="mi_baseline_half">8dp</dimen>
<dimen name="mi_margin_bottom_pager_indicator">39dp</dimen>
<dimen name="mi_y_offset">144dp</dimen>
<dimen name="mi_button_cta_height">48dp</dimen>
</resources>
1 change: 1 addition & 0 deletions library/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<item name="mi_frame" type="id"/>
<item name="mi_pager" type="id"/>
<item name="mi_button_cta_wrapper" type="id"/>
<item name="mi_button_cta" type="id"/>
<item name="mi_pager_indicator" type="id"/>
<item name="mi_button_next" type="id"/>
Expand Down

0 comments on commit 17cf16d

Please sign in to comment.