diff --git a/LICENSE b/LICENSE index 8dada3e..0aa8d22 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright 2017 Manjunath Chandrashekar & Mudit Pant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index b21bb7d..0af58f1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) ![SDK](https://img.shields.io/badge/SDK-16%2B-green.svg) -![Release](https://img.shields.io/badge/release-0.0.2-green.svg) +![Release](https://img.shields.io/badge/release-0.0.3-green.svg) [![Jitpack](https://jitpack.io/v/myntra/CoachMarks.svg)](https://jitpack.io/#myntra/CoachMarks) [![Build Status](https://travis-ci.org/myntra/CoachMarks.svg?branch=master)](https://travis-ci.org/myntra/CoachMarks) [![CircleCI](https://circleci.com/gh/myntra/CoachMarks.svg?style=svg)](https://circleci.com/gh/myntra/CoachMarks) @@ -23,7 +23,7 @@ Add jitpack to your root `build.gradle` Add the dependency ``` dependencies { - compile 'com.github.myntra:CoachMarks:0.0.2' + compile 'com.github.myntra:CoachMarks:0.0.3' } ``` @@ -31,7 +31,7 @@ Add the dependency License ------- - Copyright Manjunath Chandrashekar & Mudit Pant 2017 + Copyright 2017 Manjunath Chandrashekar & Mudit Pant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/coachmarks/build.gradle b/coachmarks/build.gradle index 41a748e..eddcf30 100644 --- a/coachmarks/build.gradle +++ b/coachmarks/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk versionCode 1 - versionName "0.0.2" + versionName "0.0.3" vectorDrawables.useSupportLibrary = true } @@ -38,8 +38,9 @@ dependencies { //SUPPORT LIB compile libraries.supportAppCompat + compile libraries.supportAnnotations - //Utils + //ZETA COMPONENTS compile libraries.zetaUtils //PROGRAMMING diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java b/coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java index 077dce2..5b5523f 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java @@ -45,13 +45,14 @@ import zeta.android.utils.view.ViewUtils; public class PopUpCoachMark extends DialogFragment implements IPopUpCoachMarkPresentation, View.OnClickListener { + private static final String TAG = PopUpCoachMark.class.getSimpleName(); private static final int NO_MARGIN = 0; private static final String ARG_POP_UP_COACH_MARK_BUILDER_PARCEL = "ARG_POP_UP_COACH_MARK_BUILDER_PARCEL"; private Views mViews; - private PopUpCoachMarkPresenter mPopUpCoachMarkPresenter; + private PopUpCoachMarkPresenter mPresenter; static class Views extends BaseViews { @@ -91,10 +92,10 @@ static class Views extends BaseViews { @BindView(R2.id.v_notch_base_white_top) View vNotchBaseWhiteTop; - @BindView(R2.id.test) - LinearLayout test; + @BindView(R2.id.ll_coachmark_text_wrapper_layout) + LinearLayout llCoachMarkTextWrapperLayout; - Views(View root) { + Views(@NonNull View root) { super(root); } } @@ -132,20 +133,24 @@ public void onCreate(@Nullable Bundle savedInstanceState) { final ITypeFaceProvider typeFaceProvider = new DefaultTypeFaceProvider(context); final IScreenInfoProvider screenInfoProvider = new DefaultScreenInfoProvider(context); - mPopUpCoachMarkPresenter = new PopUpCoachMarkPresenter(stringResourceProvider, dimensionResourceProvider, + mPresenter = new PopUpCoachMarkPresenter(stringResourceProvider, dimensionResourceProvider, typeFaceProvider, screenInfoProvider); - //coach mark bundle is injected in onCreate as its available from bundle only + //coach mark presenter params is injected in onCreate as it's available from bundle //If we decide to migrate to DI pattern this will be useful - mPopUpCoachMarkPresenter.onCreate(getCoachMarkBuilderFromBundle()); + final CoachMarkBuilder coachMarkBuilderFromBundle = getCoachMarkBuilderFromBundle(); + assert coachMarkBuilderFromBundle != null; + mPresenter.onCreate(coachMarkBuilderFromBundle); } @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final View view = inflater.inflate(R.layout.pop_up_coach_mark, container, false); mViews = new Views(view); - mPopUpCoachMarkPresenter.onCreateView(this); + mPresenter.onCreateView(this); registerClickListener(); return view; } @@ -153,12 +158,13 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - mPopUpCoachMarkPresenter.onViewCreated(); + mPresenter.onViewCreated(); } @Override public void onDestroyView() { super.onDestroyView(); + mPresenter.onDestroyView(); unRegisterClickListener(); mViews = null; } @@ -166,8 +172,8 @@ public void onDestroyView() { @Override public void onDestroy() { super.onDestroy(); - mPopUpCoachMarkPresenter.onDestroy(); - mPopUpCoachMarkPresenter = null; + mPresenter.onDestroy(); + mPresenter = null; } //region presentation methods @@ -188,7 +194,7 @@ public void dismissWithError(String message) { } @Override - public void onDismiss() { + public void closeCoachMarkDialog() { dismiss(); } @@ -210,7 +216,7 @@ public void setPopUpViewPositionWithRespectToImage(@CoachMarkAlignPosition int a } @Override - public void setPopUpViewTopLeft(Rect margin, @CoachMarkLayoutOrientation int orientation) { + public void setPopUpViewTopLeft(@NonNull Rect margin, @CoachMarkLayoutOrientation int orientation) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.llPopUpCoachMarkParent.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); mViews.llPopUpCoachMarkParent.setLayoutParams(layoutParams); @@ -220,7 +226,7 @@ public void setPopUpViewTopLeft(Rect margin, @CoachMarkLayoutOrientation int ori } @Override - public void setPopUpViewBottomRight(Rect margin, @CoachMarkLayoutOrientation int orientation) { + public void setPopUpViewBottomRight(@NonNull Rect margin, @CoachMarkLayoutOrientation int orientation) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.llPopUpCoachMarkParent.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); mViews.llPopUpCoachMarkParent.setLayoutParams(layoutParams); @@ -233,23 +239,23 @@ public void setPopUpViewBottomRight(Rect margin, @CoachMarkLayoutOrientation int public void setDismissButtonPositionLeft() { RelativeLayout.LayoutParams okButtonLayoutParams = (RelativeLayout.LayoutParams) mViews.tvPopUpDismissButton.getLayoutParams(); RelativeLayout.LayoutParams separatorLayoutParams = (RelativeLayout.LayoutParams) mViews.vSeparator.getLayoutParams(); - RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.test.getLayoutParams(); + RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.llCoachMarkTextWrapperLayout.getLayoutParams(); okButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, mViews.rlCoachMarkTextPart.getId()); mViews.tvPopUpDismissButton.setLayoutParams(okButtonLayoutParams); separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.tvPopUpDismissButton.getId()); mViews.vSeparator.setLayoutParams(separatorLayoutParams); coachMarkTextParams.addRule(RelativeLayout.RIGHT_OF, mViews.vSeparator.getId()); - mViews.test.setLayoutParams(coachMarkTextParams); + mViews.llCoachMarkTextWrapperLayout.setLayoutParams(coachMarkTextParams); } @Override public void setDismissButtonPositionRight() { RelativeLayout.LayoutParams okButtonLayoutParams = (RelativeLayout.LayoutParams) mViews.tvPopUpDismissButton.getLayoutParams(); RelativeLayout.LayoutParams separatorLayoutParams = (RelativeLayout.LayoutParams) mViews.vSeparator.getLayoutParams(); - RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.test.getLayoutParams(); + RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.llCoachMarkTextWrapperLayout.getLayoutParams(); coachMarkTextParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, mViews.rlCoachMarkTextPart.getId()); - mViews.test.setLayoutParams(coachMarkTextParams); - separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.test.getId()); + mViews.llCoachMarkTextWrapperLayout.setLayoutParams(coachMarkTextParams); + separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.llCoachMarkTextWrapperLayout.getId()); mViews.vSeparator.setLayoutParams(separatorLayoutParams); okButtonLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.vSeparator.getId()); mViews.tvPopUpDismissButton.setLayoutParams(okButtonLayoutParams); @@ -272,7 +278,7 @@ public void startAlphaAnimationOnImage() { } @Override - public void setNotchPositionIfPopUpTopLeft(Rect margin, float rotation) { + public void setNotchPositionIfPopUpTopLeft(@NonNull Rect margin, float rotation) { mViews.vRightBottomNotch.setRotation(rotation); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViews.vRightBottomNotch.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); @@ -280,7 +286,7 @@ public void setNotchPositionIfPopUpTopLeft(Rect margin, float rotation) { } @Override - public void setNotchPositionIfPopUpBottomRight(Rect margin, float rotation) { + public void setNotchPositionIfPopUpBottomRight(@NonNull Rect margin, float rotation) { mViews.vLeftTopNotch.setRotation(rotation); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViews.vLeftTopNotch.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); @@ -303,7 +309,7 @@ public void setUpGravityForCoachMarkText(@CoachMarkTextGravity int gravity) { } @Override - public void uiAdjustmentForNotchIfPopUpRight(Rect margin) { + public void uiAdjustmentForNotchIfPopUpRight(@NonNull Rect margin) { ViewUtils.setToVisible(mViews.vNotchBaseWhiteLeft); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.vNotchBaseWhiteLeft.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); @@ -311,7 +317,7 @@ public void uiAdjustmentForNotchIfPopUpRight(Rect margin) { } @Override - public void uiAdjustmentForNotchIfPopUpBottom(Rect margin) { + public void uiAdjustmentForNotchIfPopUpBottom(@NonNull Rect margin) { ViewUtils.setToVisible(mViews.vNotchBaseWhiteTop); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.vNotchBaseWhiteTop.getLayoutParams(); layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom); @@ -327,18 +333,22 @@ public void setCoachMarkMessage(String message) { //region click listeners @Override - public void onClick(View v) { + public void onClick(@Nullable View v) { + if (v == null) { + return; + } if (v.getId() == R.id.tv_ok_button) { - if (mPopUpCoachMarkPresenter != null) { - mPopUpCoachMarkPresenter.onOkButtonClicked(); + if (mPresenter != null) { + mPresenter.onOkButtonClicked(); } } else if (v.getId() == R.id.rl_shim_out_view_parent) { - mPopUpCoachMarkPresenter.onShimClicked(); + mPresenter.onShimClicked(); } } //endregion //region helper methods + @Nullable private CoachMarkBuilder getCoachMarkBuilderFromBundle() { return getArguments().getParcelable(ARG_POP_UP_COACH_MARK_BUILDER_PARCEL); } diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/builder/CoachMarkBuilder.java b/coachmarks/src/main/java/com/myntra/coachmarks/builder/CoachMarkBuilder.java index 454a70b..d19c9de 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/builder/CoachMarkBuilder.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/builder/CoachMarkBuilder.java @@ -5,6 +5,7 @@ import android.support.annotation.ColorRes; import android.support.annotation.DimenRes; import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -41,6 +42,7 @@ public static Builder create(Point coachMarkViewAnchorTop, .setImageLayoutInformation(ImageLayoutInformation.create(R.dimen.coach_mark_zero_dp, R.dimen.coach_mark_zero_dp).build()); } + @NonNull @SuppressWarnings("unused") public Builder newBuilder() { return new AutoValue_CoachMarkBuilder.Builder(this); diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/providers/DefaultTypeFaceProvider.java b/coachmarks/src/main/java/com/myntra/coachmarks/providers/DefaultTypeFaceProvider.java index b6199e7..9073a4f 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/providers/DefaultTypeFaceProvider.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/providers/DefaultTypeFaceProvider.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.Typeface; +import android.support.annotation.Nullable; import android.util.Log; import com.myntra.coachmarks.providers.interfaces.ITypeFaceProvider; @@ -18,6 +19,7 @@ public DefaultTypeFaceProvider(final Context context) { } @Override + @Nullable public Typeface getTypeFaceFromAssets(final String fontFilePath) { try { return Typeface.createFromAsset(mContext.getAssets(), fontFilePath); diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/providers/interfaces/ITypeFaceProvider.java b/coachmarks/src/main/java/com/myntra/coachmarks/providers/interfaces/ITypeFaceProvider.java index d01fbad..683168b 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/providers/interfaces/ITypeFaceProvider.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/providers/interfaces/ITypeFaceProvider.java @@ -1,7 +1,9 @@ package com.myntra.coachmarks.providers.interfaces; import android.graphics.Typeface; +import android.support.annotation.Nullable; public interface ITypeFaceProvider { + @Nullable Typeface getTypeFaceFromAssets(final String fontFilePath); } diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/ui/common/BaseViews.java b/coachmarks/src/main/java/com/myntra/coachmarks/ui/common/BaseViews.java index a64f229..10b14a4 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/ui/common/BaseViews.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/ui/common/BaseViews.java @@ -1,19 +1,23 @@ package com.myntra.coachmarks.ui.common; import android.support.annotation.CallSuper; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import butterknife.ButterKnife; public abstract class BaseViews { + @Nullable private View mRoot; - protected BaseViews(View root) { + protected BaseViews(@NonNull View root) { mRoot = root; ButterKnife.bind(this, root); } + @Nullable public View getRootView() { return mRoot; } diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/ui/presentation/IPopUpCoachMarkPresentation.java b/coachmarks/src/main/java/com/myntra/coachmarks/ui/presentation/IPopUpCoachMarkPresentation.java index 4b7bb45..f8d3e8f 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/ui/presentation/IPopUpCoachMarkPresentation.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/ui/presentation/IPopUpCoachMarkPresentation.java @@ -15,7 +15,7 @@ void setImageInformation(double centerX, double centerY, int imageWidth, void dismissWithError(String message); - void onDismiss(); + void closeCoachMarkDialog(); void startThrobAnimationOnImage(); diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/ui/presenter/PopUpCoachMarkPresenter.java b/coachmarks/src/main/java/com/myntra/coachmarks/ui/presenter/PopUpCoachMarkPresenter.java index 18208f2..4eb7bd8 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/ui/presenter/PopUpCoachMarkPresenter.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/ui/presenter/PopUpCoachMarkPresenter.java @@ -47,7 +47,7 @@ public class PopUpCoachMarkPresenter { private static final int MULTIPLICATION_FACTOR_FOR_NOTCH_UI_ADJUSTMENT = 3; private CoachMarkBuilder mCoachMarkBuilder; - private IPopUpCoachMarkPresentation mPopUpCoachMarkPresentation; + private IPopUpCoachMarkPresentation mPresentation; private ITypeFaceProvider mTypeFaceProvider; private IScreenInfoProvider mScreenInfoProvider; @@ -69,15 +69,18 @@ public void onCreate(CoachMarkBuilder coachMarkBuilder) { } public void onCreateView(IPopUpCoachMarkPresentation popUpCoachMarkPresentation) { - mPopUpCoachMarkPresentation = popUpCoachMarkPresentation; + mPresentation = popUpCoachMarkPresentation; } public void onViewCreated() { displayCoachMark(); } + public void onDestroyView() { + mPresentation = null; + } + public void onDestroy() { - mPopUpCoachMarkPresentation = null; mScreenInfoProvider = null; mDimensionResourceProvider = null; mStringResourceProvider = null; @@ -85,14 +88,12 @@ public void onDestroy() { } public void onOkButtonClicked() { - if (mPopUpCoachMarkPresentation != null) { - mPopUpCoachMarkPresentation.onDismiss(); - } + mPresentation.closeCoachMarkDialog(); } public void onShimClicked() { - if (mPopUpCoachMarkPresentation != null) { - mPopUpCoachMarkPresentation.onDismiss(); + if (mPresentation != null) { + mPresentation.closeCoachMarkDialog(); } } @@ -105,7 +106,7 @@ private void displayCoachMark() { mCoachMarkBuilder.getUserDesiredPopUpPositionWithRespectToView(), coachMarkDimenInPixel); if (popUpPosition == PopUpPosition.NONE) { - mPopUpCoachMarkPresentation.dismissWithError( + mPresentation.dismissWithError( mStringResourceProvider.getStringFromResource(R.string.coachmark_no_position_found)); return; } @@ -123,35 +124,37 @@ private void displayCoachMark() { } private void setMessageForCoachMarkText(@StringRes int messageForCoachMarkTextRes) { - mPopUpCoachMarkPresentation.setCoachMarkMessage(mStringResourceProvider.getStringFromResource(messageForCoachMarkTextRes)); + mPresentation.setCoachMarkMessage(mStringResourceProvider.getStringFromResource(messageForCoachMarkTextRes)); } private void setTypeFaceForDismissButton(@Nullable String fontFileForDismissButton) { if (StringUtils.isNotNullOrEmpty(fontFileForDismissButton)) { Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(fontFileForDismissButton); - if (typeface != null) - mPopUpCoachMarkPresentation.setTypeFaceForDismissButton(typeface); + if (typeface != null) { + mPresentation.setTypeFaceForDismissButton(typeface); + } } } private void setTypeFaceForCoachMarkText(@Nullable String fontFileForPopUpText) { if (StringUtils.isNotNullOrEmpty(fontFileForPopUpText)) { Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(fontFileForPopUpText); - if (typeface != null) - mPopUpCoachMarkPresentation.setTypeFaceForPopUpText(typeface); + if (typeface != null) { + mPresentation.setTypeFaceForPopUpText(typeface); + } } } private void setGravityForCoachMarkText(int textAlignmentForPopUpText) { switch (textAlignmentForPopUpText) { case CoachMarkTextGravity.CENTER: - mPopUpCoachMarkPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.CENTER); + mPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.CENTER); break; case CoachMarkTextGravity.LEFT: - mPopUpCoachMarkPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.LEFT); + mPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.LEFT); break; case CoachMarkTextGravity.RIGHT: - mPopUpCoachMarkPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.RIGHT); + mPresentation.setUpGravityForCoachMarkText(CoachMarkTextGravity.RIGHT); break; } } @@ -168,38 +171,38 @@ private void setNotchDisplayEdge(int position, int anchorTopY, int anchorBottomY case PopUpPosition.LEFT: actualTopMargin = getActualTopMargin(centerY, coachMarkDimenInPixel); coachMarkMarginRect = new Rect(coachMarkDimenInPixel.getMarginRectInPixels().left, actualTopMargin - coachMarkDimenInPixel.getMarginRectInPixels().bottom, coachMarkDimenInPixel.getMarginRectInPixels().right + coachMarkDimenInPixel.getImageWidthInPixels(), NO_MARGIN); - mPopUpCoachMarkPresentation.setPopUpViewTopLeft(coachMarkMarginRect, CoachMarkLayoutOrientation.HORIZONTAL); + mPresentation.setPopUpViewTopLeft(coachMarkMarginRect, CoachMarkLayoutOrientation.HORIZONTAL); notchPosition = getMarginTopForNotch(mCoachMarkBuilder.getNotchPosition(), coachMarkDimenInPixel.getPopUpHeightInPixels(), coachMarkDimenInPixel.getNotchDimenInPixels()); notchMarginRect = new Rect(-coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), notchPosition, NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.setNotchPositionIfPopUpTopLeft(notchMarginRect, ROTATION_90); + mPresentation.setNotchPositionIfPopUpTopLeft(notchMarginRect, ROTATION_90); break; case PopUpPosition.TOP: actualLeftMargin = getActualLeftMargin(anchorTopX, coachMarkDimenInPixel); coachMarkMarginRect = new Rect(actualLeftMargin - coachMarkDimenInPixel.getMarginRectInPixels().right, coachMarkDimenInPixel.getMarginRectInPixels().top, NO_MARGIN, coachMarkDimenInPixel.getMarginRectInPixels().bottom + coachMarkDimenInPixel.getImageHeightInPixels()); - mPopUpCoachMarkPresentation.setPopUpViewTopLeft(coachMarkMarginRect, CoachMarkLayoutOrientation.VERTICAL); + mPresentation.setPopUpViewTopLeft(coachMarkMarginRect, CoachMarkLayoutOrientation.VERTICAL); notchPosition = getMarginLeftForNotch(mCoachMarkBuilder.getNotchPosition(), coachMarkDimenInPixel.getPopUpWidthInPixels(), coachMarkDimenInPixel.getNotchDimenInPixels()); notchMarginRect = new Rect(notchPosition + coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), -coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.setNotchPositionIfPopUpTopLeft(notchMarginRect, ROTATION_180); + mPresentation.setNotchPositionIfPopUpTopLeft(notchMarginRect, ROTATION_180); break; case PopUpPosition.RIGHT: actualTopMargin = getActualTopMargin(centerY, coachMarkDimenInPixel); coachMarkMarginRect = new Rect(coachMarkDimenInPixel.getMarginRectInPixels().left + coachMarkDimenInPixel.getImageWidthInPixels(), actualTopMargin - coachMarkDimenInPixel.getMarginRectInPixels().bottom, coachMarkDimenInPixel.getMarginRectInPixels().right, NO_MARGIN); - mPopUpCoachMarkPresentation.setPopUpViewBottomRight(coachMarkMarginRect, CoachMarkLayoutOrientation.HORIZONTAL); + mPresentation.setPopUpViewBottomRight(coachMarkMarginRect, CoachMarkLayoutOrientation.HORIZONTAL); notchPosition = getMarginTopForNotch(mCoachMarkBuilder.getNotchPosition(), coachMarkDimenInPixel.getPopUpHeightInPixels(), coachMarkDimenInPixel.getNotchDimenInPixels()); notchMarginRect = new Rect(NO_MARGIN, notchPosition - (2 * coachMarkDimenInPixel.getMarginOffsetForNotchInPixels()), NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.setNotchPositionIfPopUpBottomRight(notchMarginRect, ROTATION_270); + mPresentation.setNotchPositionIfPopUpBottomRight(notchMarginRect, ROTATION_270); notchUiAdjustmentMarginRect = new Rect(NO_MARGIN, notchPosition - coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.uiAdjustmentForNotchIfPopUpRight(notchUiAdjustmentMarginRect); + mPresentation.uiAdjustmentForNotchIfPopUpRight(notchUiAdjustmentMarginRect); break; case PopUpPosition.BOTTOM: actualLeftMargin = getActualLeftMargin(anchorTopX, coachMarkDimenInPixel); coachMarkMarginRect = new Rect(actualLeftMargin - coachMarkDimenInPixel.getMarginRectInPixels().right, coachMarkDimenInPixel.getMarginRectInPixels().top + coachMarkDimenInPixel.getImageHeightInPixels(), NO_MARGIN, coachMarkDimenInPixel.getMarginRectInPixels().bottom); - mPopUpCoachMarkPresentation.setPopUpViewBottomRight(coachMarkMarginRect, CoachMarkLayoutOrientation.VERTICAL); + mPresentation.setPopUpViewBottomRight(coachMarkMarginRect, CoachMarkLayoutOrientation.VERTICAL); notchPosition = getMarginLeftForNotch(mCoachMarkBuilder.getNotchPosition(), coachMarkDimenInPixel.getPopUpWidthInPixels(), coachMarkDimenInPixel.getNotchDimenInPixels()); notchMarginRect = new Rect(notchPosition + coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), NO_MARGIN, NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.setNotchPositionIfPopUpBottomRight(notchMarginRect, ROTATION_0); + mPresentation.setNotchPositionIfPopUpBottomRight(notchMarginRect, ROTATION_0); notchUiAdjustmentMarginRect = new Rect(notchPosition + MULTIPLICATION_FACTOR_FOR_NOTCH_UI_ADJUSTMENT * coachMarkDimenInPixel.getMarginOffsetForNotchInPixels(), NO_MARGIN, NO_MARGIN, NO_MARGIN); - mPopUpCoachMarkPresentation.uiAdjustmentForNotchIfPopUpBottom(notchUiAdjustmentMarginRect); + mPresentation.uiAdjustmentForNotchIfPopUpBottom(notchUiAdjustmentMarginRect); break; } } @@ -231,7 +234,7 @@ private void detectAndCreateShimOutViews(@Nullable List infoF return; } for (InfoForViewToMask infoForViewToMask : infoForViewToMaskList) { - mPopUpCoachMarkPresentation.createViewToBeMaskedOut( + mPresentation.createViewToBeMaskedOut( infoForViewToMask.getViewToMaskStartPosition().x, infoForViewToMask.getViewToMaskStartPosition().y, infoForViewToMask.getViewToMaskHeight(), @@ -254,13 +257,13 @@ private int findCoachMarkTextPopUpDisplayPosition(Point anchorTop, Point anchorB private void createAnimationOnImage(@AnimationType int animationType) { switch (animationType) { case AnimationType.THROB_ANIMATION: - mPopUpCoachMarkPresentation.startThrobAnimationOnImage(); + mPresentation.startThrobAnimationOnImage(); break; case AnimationType.ALPHA_ANIMATION: - mPopUpCoachMarkPresentation.startAlphaAnimationOnImage(); + mPresentation.startAlphaAnimationOnImage(); break; case AnimationType.SCALE_ANIMATION: - mPopUpCoachMarkPresentation.startScaleAnimationOnImage(); + mPresentation.startScaleAnimationOnImage(); break; case AnimationType.ANIMATION_NONE: break; @@ -273,7 +276,7 @@ private void setImageParamsAndPosition(Point anchorTop, Point anchorBottom, @DrawableRes int imageDrawableRes) { double centerX = (anchorTop.x + anchorBottom.x) / 2; double centerY = (anchorTop.y + anchorBottom.y) / 2; - mPopUpCoachMarkPresentation.setImageInformation(centerX, centerY, imageWidth, + mPresentation.setImageInformation(centerX, centerY, imageWidth, imageHeight, backGroundTintForImage, imageDrawableRes); } @@ -282,16 +285,16 @@ private void showCoachMark(@DialogDismissButtonPosition int dismissButtonPositio switch (popUpPosition) { case PopUpPosition.LEFT: - mPopUpCoachMarkPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_RIGHT); + mPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_RIGHT); break; case PopUpPosition.TOP: - mPopUpCoachMarkPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_BOTTOM); + mPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_BOTTOM); break; case PopUpPosition.RIGHT: - mPopUpCoachMarkPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_LEFT); + mPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_LEFT); break; case PopUpPosition.BOTTOM: - mPopUpCoachMarkPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_TOP); + mPresentation.setPopUpViewPositionWithRespectToImage(CoachMarkAlignPosition.ALIGN_TOP); break; case PopUpPosition.NONE: //TODO:: Handle this case @@ -300,17 +303,16 @@ private void showCoachMark(@DialogDismissButtonPosition int dismissButtonPositio switch (dismissButtonPosition) { case DialogDismissButtonPosition.LEFT: - mPopUpCoachMarkPresentation.setDismissButtonPositionLeft(); + mPresentation.setDismissButtonPositionLeft(); break; case DialogDismissButtonPosition.RIGHT: - mPopUpCoachMarkPresentation.setDismissButtonPositionRight(); + mPresentation.setDismissButtonPositionRight(); break; } } @PopUpPosition - private int getDisplayPosition(Point viewCenterPoint, - @PopUpPosition int defaultPopUpPosition, + private int getDisplayPosition(Point viewCenterPoint, @PopUpPosition int defaultPopUpPosition, CoachMarkPixelInfo coachMarkDimenInPixel) { @PopUpPosition int correctPosition = 0; @@ -375,7 +377,8 @@ private boolean checkIfBottomPossible(Point viewCenterPoint, CoachMarkPixelInfo @PopUpPosition private int getCorrectPositionOfCoachMarkIfDefaultFails(Point viewCenterPoint, CoachMarkPixelInfo coachMarkDimenInPixel) { - @PopUpPosition int correctPopUpPosition = PopUpPosition.NONE; + @PopUpPosition + int correctPopUpPosition = PopUpPosition.NONE; if (checkIfRightPossible(viewCenterPoint, coachMarkDimenInPixel)) correctPopUpPosition = PopUpPosition.RIGHT; diff --git a/coachmarks/src/main/java/com/myntra/coachmarks/ui/utils/TransitionUtils.java b/coachmarks/src/main/java/com/myntra/coachmarks/ui/utils/TransitionUtils.java index 2c5eba4..18b9fbc 100644 --- a/coachmarks/src/main/java/com/myntra/coachmarks/ui/utils/TransitionUtils.java +++ b/coachmarks/src/main/java/com/myntra/coachmarks/ui/utils/TransitionUtils.java @@ -1,6 +1,7 @@ package com.myntra.coachmarks.ui.utils; import android.animation.ValueAnimator; +import android.support.annotation.NonNull; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; @@ -9,17 +10,21 @@ public class TransitionUtils { - private static final int ALPHA_ANIMATION_DURATION = 2000; private static final double ALPHA_ANIMATION_FROM = 1; private static final double ALPHA_ANIMATION_TO = 0; + private static final double SCALE_ANIMATION_FROM_X = 1; private static final double SCALE_ANIMATION_TO_X = 1.5; private static final double SCALE_ANIMATION_FROM_Y = 1; private static final double SCALE_ANIMATION_TO_Y = 1.5; + private static final double SCALE_ANIMATION_PIVOT_X = .5; private static final double SCALE_ANIMATION_PIVOT_Y = .5; + + private static final int ALPHA_ANIMATION_DURATION = 2000; private static final int SCALE_ANIMATION_DURATION = 2000; + @NonNull public static AnimationSet createThrobAnimation() { AnimationSet animationSet = new AnimationSet(false); animationSet.addAnimation(createAlphaAnimation()); @@ -27,6 +32,7 @@ public static AnimationSet createThrobAnimation() { return animationSet; } + @NonNull public static Animation createAlphaAnimation() { ScaleAnimation scaleAnimation = new ScaleAnimation((float) SCALE_ANIMATION_FROM_X, (float) SCALE_ANIMATION_TO_X, (float) SCALE_ANIMATION_FROM_Y, @@ -40,6 +46,7 @@ public static Animation createAlphaAnimation() { return scaleAnimation; } + @NonNull public static Animation createScaleAnimation() { AlphaAnimation alphaAnimation = new AlphaAnimation((float) ALPHA_ANIMATION_FROM, (float) ALPHA_ANIMATION_TO); @@ -49,4 +56,5 @@ public static Animation createScaleAnimation() { alphaAnimation.setRepeatMode(ValueAnimator.RESTART); return alphaAnimation; } + } diff --git a/coachmarks/src/main/res/layout/pop_up_coach_mark.xml b/coachmarks/src/main/res/layout/pop_up_coach_mark.xml index c956f04..e827148 100644 --- a/coachmarks/src/main/res/layout/pop_up_coach_mark.xml +++ b/coachmarks/src/main/res/layout/pop_up_coach_mark.xml @@ -56,7 +56,7 @@ android:textSize="@dimen/coach_mark_text_size_ok_button" /> @@ -92,6 +92,7 @@ android:id="@+id/v_notch_base_white_top" android:layout_width="@dimen/coach_mark_notch_bottom_invisible_width" android:layout_height="1dp" + android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@color/coach_mark_white" @@ -101,6 +102,7 @@ android:id="@+id/v_notch_base_white_left" android:layout_width="1dp" android:layout_height="@dimen/coach_mark_notch_bottom_invisible_height" + android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@color/coach_mark_white" diff --git a/coachmarks/src/main/res/values/dimens.xml b/coachmarks/src/main/res/values/dimens.xml index e8a3deb..599f5b6 100644 --- a/coachmarks/src/main/res/values/dimens.xml +++ b/coachmarks/src/main/res/values/dimens.xml @@ -27,9 +27,10 @@ 6dp 14sp + 16sp + 6dp 8dp - 16dp 20dp 16dp diff --git a/sample/build.gradle b/sample/build.gradle index e478843..7588a9a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk versionCode 1 - versionName "0.0.2" + versionName "0.0.3" } buildTypes { @@ -31,4 +31,5 @@ dependencies { compile libraries.supportAppCompat testCompile 'junit:junit:4.12' + compile 'com.android.support:support-annotations:25.2.0' }