Skip to content

Commit

Permalink
Added aupport for custom animation + change in sample app for example…
Browse files Browse the repository at this point in the history
… + removed unused files
  • Loading branch information
muditpant13 committed Mar 14, 2017
1 parent 8ed53e6 commit ae0f2b1
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 133 deletions.
40 changes: 24 additions & 16 deletions coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.AnimRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
Expand All @@ -17,6 +18,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand All @@ -39,7 +42,6 @@
import com.myntra.coachmarks.ui.common.BaseViews;
import com.myntra.coachmarks.ui.presentation.IPopUpCoachMarkPresentation;
import com.myntra.coachmarks.ui.presenter.PopUpCoachMarkPresenter;
import com.myntra.coachmarks.ui.utils.TransitionUtils;

import butterknife.BindView;
import zeta.android.utils.view.ViewUtils;
Expand Down Expand Up @@ -215,6 +217,27 @@ public void setPopUpViewPositionWithRespectToImage(@CoachMarkAlignPosition int a
mViews.llPopUpCoachMarkParent.setLayoutParams(layoutParams);
}

@Override
public void startAnimationOnImage(@AnimRes int animationRes) {
Animation animation = AnimationUtils.loadAnimation(getContext(), animationRes);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
mViews.ivCoachMarkImage.startAnimation(animation);
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
mViews.ivCoachMarkImage.startAnimation(animation);
}

@Override
public void setPopUpViewTopLeft(@NonNull Rect margin, @CoachMarkLayoutOrientation int orientation) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.llPopUpCoachMarkParent.getLayoutParams();
Expand Down Expand Up @@ -259,21 +282,6 @@ public void setDismissButtonPositionRight() {
mViews.tvPopUpDismissButton.setLayoutParams(okButtonLayoutParams);
}

@Override
public void startScaleAnimationOnImage() {
mViews.ivCoachMarkImage.startAnimation(TransitionUtils.createScaleAnimation());
}

@Override
public void startThrobAnimationOnImage() {
mViews.ivCoachMarkImage.startAnimation(TransitionUtils.createThrobAnimation());
}

@Override
public void startAlphaAnimationOnImage() {
mViews.ivCoachMarkImage.startAnimation(TransitionUtils.createAlphaAnimation());
}

@Override
public void setNotchPositionIfPopUpTopLeft(@NonNull Rect margin, float rotation) {
mViews.vRightBottomNotch.setRotation(rotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Point;
import android.os.Parcelable;
import android.support.annotation.AnimRes;
import android.support.annotation.ColorRes;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
Expand All @@ -11,7 +12,6 @@

import com.google.auto.value.AutoValue;
import com.myntra.coachmarks.R;
import com.myntra.coachmarks.common.AnimationType;
import com.myntra.coachmarks.common.CoachMarkTextGravity;
import com.myntra.coachmarks.common.DialogDismissButtonPosition;
import com.myntra.coachmarks.common.PopUpPosition;
Expand All @@ -33,13 +33,13 @@ public static Builder create(Point coachMarkViewAnchorTop,
.setActionBarHeight(R.dimen.coach_mark_zero_dp)
.setCoachMarkTextGravity(CoachMarkTextGravity.LEFT)
.setInfoForViewToMaskList(new ArrayList<InfoForViewToMask>(0))
.setAnimationTypeOnImage(AnimationType.THROB_ANIMATION)
.setImageDrawableRes(R.drawable.coachmark_drawable_no_image)
.setBackGroundTintForImage(R.color.coach_mark_transparent_color)
.setCoachMarkLayoutMargin(CoachMarkLayoutMargin.create().build())
.setUserDesiredPopUpPositionWithRespectToView(PopUpPosition.RIGHT)
.setImageLayoutInformation(ImageLayoutInformation.create(R.dimen.coach_mark_zero_dp, R.dimen.coach_mark_zero_dp).build())
.setPopUpCoachMarkDismissButtonPosition(DialogDismissButtonPosition.RIGHT);
.setPopUpCoachMarkDismissButtonPosition(DialogDismissButtonPosition.RIGHT)
.setAnimationOnImage(R.anim.coach_mark_animation);
}

@NonNull
Expand All @@ -64,9 +64,6 @@ public Builder newBuilder() {
@Nullable
public abstract ArrayList<InfoForViewToMask> getInfoForViewToMaskList();

@AnimationType
public abstract int getAnimationTypeOnImage();

@CoachMarkTextGravity
public abstract int getCoachMarkTextGravity();

Expand Down Expand Up @@ -94,6 +91,9 @@ public Builder newBuilder() {

public abstract ImageLayoutInformation getImageLayoutInformation();

@AnimRes
public abstract int getAnimationOnImage();

@AutoValue.Builder
public static abstract class Builder {

Expand All @@ -115,8 +115,6 @@ public static abstract class Builder {

public abstract Builder setInfoForViewToMaskList(@Nullable ArrayList<InfoForViewToMask> infoForViewToMaskList);

public abstract Builder setAnimationTypeOnImage(@AnimationType int animationTypeOnImage);

public abstract Builder setPopUpCoachMarkDismissButtonPosition(@DialogDismissButtonPosition int popUpCoachMarkDismissButtonPosition);

public abstract Builder setNotchPosition(double notchPosition);
Expand All @@ -131,6 +129,8 @@ public static abstract class Builder {

public abstract Builder setImageLayoutInformation(ImageLayoutInformation imageLayoutInformation);

public abstract Builder setAnimationOnImage(@AnimRes int animationOnImage);

public abstract CoachMarkBuilder build();

}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Rect;
import android.graphics.Typeface;
import android.support.annotation.AnimRes;

import com.myntra.coachmarks.common.CoachMarkAlignPosition;
import com.myntra.coachmarks.common.CoachMarkLayoutOrientation;
Expand All @@ -17,16 +18,10 @@ void setImageInformation(double centerX, double centerY, int imageWidth,

void closeCoachMarkDialog();

void startThrobAnimationOnImage();

void setDismissButtonPositionLeft();

void setDismissButtonPositionRight();

void startScaleAnimationOnImage();

void startAlphaAnimationOnImage();

void setTypeFaceForDismissButton(Typeface typeface);

void setTypeFaceForPopUpText(Typeface typeface);
Expand All @@ -49,4 +44,6 @@ void setImageInformation(double centerX, double centerY, int imageWidth,

void setPopUpViewPositionWithRespectToImage(@CoachMarkAlignPosition int alignPosition);

void startAnimationOnImage(@AnimRes int animationRes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.myntra.coachmarks.builder.CoachMarkLayoutMargin;
import com.myntra.coachmarks.builder.CoachMarkPixelInfo;
import com.myntra.coachmarks.builder.InfoForViewToMask;
import com.myntra.coachmarks.common.AnimationType;
import com.myntra.coachmarks.common.CoachMarkAlignPosition;
import com.myntra.coachmarks.common.CoachMarkLayoutOrientation;
import com.myntra.coachmarks.common.CoachMarkTextGravity;
Expand Down Expand Up @@ -129,7 +128,7 @@ private void displayCoachMark() {
coachMarkDimenInPixel.getImageHeightInPixels(),
mCoachMarkBuilder.getBackGroundTintForImage(),
mCoachMarkBuilder.getImageDrawableRes());
createAnimationOnImage(mCoachMarkBuilder.getAnimationTypeOnImage());
mPresentation.startAnimationOnImage(mCoachMarkBuilder.getAnimationOnImage());
showCoachMark(mCoachMarkBuilder.getPopUpCoachMarkDismissButtonPosition(),
popUpPosition);
}
Expand Down Expand Up @@ -331,21 +330,7 @@ private int findCoachMarkTextPopUpDisplayPosition(Point anchorTop,
defaultPopUpPosition, coachMarkDimenInPixel);
}

private void createAnimationOnImage(@AnimationType int animationType) {
switch (animationType) {
case AnimationType.THROB_ANIMATION:
mPresentation.startThrobAnimationOnImage();
break;
case AnimationType.ALPHA_ANIMATION:
mPresentation.startAlphaAnimationOnImage();
break;
case AnimationType.SCALE_ANIMATION:
mPresentation.startScaleAnimationOnImage();
break;
case AnimationType.ANIMATION_NONE:
break;
}
}


private void setImageParamsAndPosition(Point anchorTop, Point anchorBottom,
int imageWidth, int imageHeight,
Expand Down

This file was deleted.

20 changes: 20 additions & 0 deletions coachmarks/src/main/res/anim/coach_mark_animation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">

<scale
android:fromXScale="@dimen/coach_mark_scale_anim_from" android:toXScale="@dimen/coach_mark_scale_anim_to"
android:fromYScale="@dimen/coach_mark_scale_anim_from" android:toYScale="@dimen/coach_mark_scale_anim_to"
android:pivotX="50%" android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:startOffset="@integer/coach_mark_animation_start_offset"
android:duration="@integer/coach_mark_animation_duration"/>
<alpha
android:fromAlpha="@dimen/coach_mark_alpha_anim_from"
android:toAlpha="@dimen/coach_mark_alpha_anim_to"
android:duration="@integer/coach_mark_animation_duration"
android:startOffset="@integer/coach_mark_animation_start_offset"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
/>
</set>

4 changes: 2 additions & 2 deletions coachmarks/src/main/res/layout/pop_up_coach_mark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
android:backgroundTint="@color/coach_mark_transparent_color"
android:ellipsize="end"
android:gravity="center"
android:maxLength="@integer/coachmark_text_max_lines"
android:maxLength="@integer/coach_mark_text_max_lines"
android:text="@string/coachmark_ok_button_text"
android:textAllCaps="true"
android:textColor="@color/coach_mark_button_text_color"
Expand All @@ -71,7 +71,7 @@
android:layout_marginRight="@dimen/coach_mark_pop_up_text_padding_left"
android:layout_marginTop="@dimen/coach_mark_text_margin_top"
android:lineSpacingExtra="@dimen/coach_mark_similar_item_coach_mark_stroke"
android:maxLines="@integer/coachmark_text_max_lines"
android:maxLines="@integer/coach_mark_text_max_lines"
android:text="@null"
android:textColor="@color/coach_mark_text_color"
android:textSize="@dimen/coach_mark_text_size" />
Expand Down
4 changes: 4 additions & 0 deletions coachmarks/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@
<dimen name="coach_mark_notch_bottom_invisible_height">17dp</dimen>
<dimen name="coach_mark_notch_margin_offset">1dp</dimen>

<item name="coach_mark_scale_anim_from" format="float" type="dimen">1.0</item>
<item name="coach_mark_scale_anim_to" format="float" type="dimen">1.5</item>
<item name="coach_mark_alpha_anim_from" format="float" type="dimen">1.0</item>
<item name="coach_mark_alpha_anim_to" format="float" type="dimen">0.0</item>

</resources>
6 changes: 4 additions & 2 deletions coachmarks/src/main/res/values/integers.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="coachmark_text_max_lines">2</integer>
<integer name="coachmark_max_char_button">3</integer>
<integer name="coach_mark_text_max_lines">2</integer>
<integer name="coach_mark_max_char_button">3</integer>
<integer name="coach_mark_animation_duration">2000</integer>
<integer name="coach_mark_animation_start_offset">500</integer>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private void showCoachMark() {
.setNotchPosition(.34).setInfoForViewToMaskList(infoForViewToMaskArrayList)
.setImageDrawableRes(R.drawable.similar_item_drawable)
.setFontStyleForCoachMarkText(FILE_NAME_MYNTRA_FONT_REGULAR)
.setAnimationOnImage(R.anim.coach_mark_smaple_animation)
.setFontStyleForDismissButton(FILE_NAME_MYNTRA_FONT_BOLD).build();
PopUpCoachMark popUpCoachMark = PopUpCoachMark.newInstance(testBuilder);
popUpCoachMark.show(getSupportFragmentManager(), "Test");
Expand Down
19 changes: 19 additions & 0 deletions sample/src/main/res/anim/coach_mark_smaple_animation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">

<scale
android:fromXScale="1.0" android:toXScale="2.5"
android:fromYScale="1.0" android:toYScale="2.5"
android:pivotX="50%" android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="1000"/>

<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
/>

</set>

0 comments on commit ae0f2b1

Please sign in to comment.