[android] Implemented open/close banner animation

This commit is contained in:
Александр Зацепин 2019-02-04 17:36:46 +03:00 committed by yoksnod
parent 69423bb58f
commit acf289e3de
6 changed files with 34 additions and 27 deletions

View file

@ -2,9 +2,9 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/placepage_banner_height"
android:background="?bannerBackground"
android:clipToPadding="false"
tools:layout_height="wrap_content">

View file

@ -76,18 +76,21 @@
android:maxLines="1"
android:minLines="1"
android:textAppearance="@style/MwmTextAppearance.Body4"
android:textSize="12dp"
android:textColor="?textBannerTitle"
android:fontFamily="@string/robotoMedium"
android:textStyle="bold"
android:ellipsize="end"
tools:text="Закажи одежду в интернет-магазине Wildberries."
tools:targetApi="jelly_bean"/>
tools:targetApi="jelly_bean"
tools:ignore="SpUsage"/>
</LinearLayout>
<TextView
android:id="@+id/tv__banner_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body4"
android:textSize="12dp"
android:maxLines="3"
android:ellipsize="end"
tools:text="Бесплатная курьерская доставка по России!\n\nКоллекции женской, мужской и детской одежды, обуви,
@ -95,7 +98,8 @@
tools:maxLines="5"
android:layout_below="@+id/banner_title"
android:layout_toRightOf="@+id/iv__banner_icon"
android:layout_toEndOf="@+id/iv__banner_icon"/>
android:layout_toEndOf="@+id/iv__banner_icon"
tools:ignore="SpUsage"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/action_container"
@ -119,6 +123,7 @@
android:paddingEnd="@dimen/margin_quarter"
android:minHeight="@dimen/placepage_banner_button_height"
android:textAppearance="@style/MwmTextAppearance.Body3"
android:textSize="14dp"
android:textAllCaps="true"
android:background="?bannerRemoveButtonBackground"
android:gravity="center"
@ -128,7 +133,8 @@
android:singleLine="true"
tools:visibility="visible"
android:fontFamily="@string/robotoMedium"
tools:targetApi="jelly_bean"/>
tools:targetApi="jelly_bean"
tools:ignore="SpUsage"/>
<TextView
android:id="@+id/tv__action_large"
android:layout_width="@dimen/dp_0"
@ -140,6 +146,7 @@
android:paddingEnd="@dimen/margin_quarter"
android:minHeight="@dimen/placepage_banner_button_height"
android:textAppearance="@style/MwmTextAppearance.Body3"
android:textSize="14dp"
android:textAllCaps="true"
android:background="?bannerButtonBackground"
android:gravity="center"
@ -149,7 +156,8 @@
tools:text="Заказать"
tools:visibility="visible"
android:fontFamily="@string/robotoMedium"
tools:targetApi="jelly_bean"/>
tools:targetApi="jelly_bean"
tools:ignore="SpUsage"/>
</LinearLayout>
<ImageButton
android:id="@+id/remove_btn"

View file

@ -2,12 +2,11 @@
<com.google.android.gms.ads.formats.NativeContentAdView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/placepage_banner_height">
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/placepage_banner_height"
android:paddingLeft="@dimen/margin_quarter"
android:paddingStart="@dimen/margin_quarter"
android:background="?bannerBackground"

View file

@ -182,7 +182,8 @@
<dimen name="placepage_facilities_item">32dp</dimen>
<!-- Banner-->
<dimen name="placepage_banner_height">64dp</dimen>
<dimen name="placepage_banner_small_height">66dp</dimen>
<dimen name="placepage_banner_large_height">108dp</dimen>
<dimen name="placepage_banner_icon_size">40dp</dimen>
<dimen name="placepage_banner_button_height">@dimen/primary_button_min_height</dimen>
<dimen name="placepage_banner_button_margin_top">5dp</dimen>

View file

@ -8,7 +8,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -35,7 +34,6 @@ import com.mapswithme.util.statistics.Statistics;
import java.util.Collections;
import java.util.List;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_SHOW;
import static com.mapswithme.util.statistics.Statistics.PP_BANNER_STATE_DETAILS;
@ -103,8 +101,6 @@ final class BannerController
@NonNull
private View mAdsRemovalButton;
private final float mCloseFrameHeight;
private boolean mOpened = false;
private boolean mError = false;
@Nullable
@ -117,6 +113,8 @@ final class BannerController
private MyNativeAdsListener mAdsListener = new MyNativeAdsListener();
@NonNull
private final AdsRemovalPurchaseControllerProvider mAdsRemovalProvider;
private int mClosedHeight;
private int mOpentHeight;
BannerController(@NonNull ViewGroup bannerContainer, @NonNull CompoundNativeAdLoader loader,
@Nullable AdTracker tracker,
@ -129,7 +127,8 @@ final class BannerController
mAdsLoader = loader;
mAdTracker = tracker;
Resources resources = mBannerView.getResources();
mCloseFrameHeight = resources.getDimension(R.dimen.placepage_banner_height);
mClosedHeight = resources.getDimensionPixelSize(R.dimen.placepage_banner_small_height);
mOpentHeight = resources.getDimensionPixelSize(R.dimen.placepage_banner_large_height);
mAdsRemovalProvider = adsRemovalProvider;
initBannerViews();
}
@ -258,7 +257,6 @@ final class BannerController
return;
mOpened = true;
setFrameHeight(WRAP_CONTENT);
mMessage.setMaxLines(MAX_MESSAGE_LINES);
mTitle.setMaxLines(MAX_TITLE_LINES);
updateVisibility();
@ -268,38 +266,37 @@ final class BannerController
Statistics.INSTANCE.trackPPBanner(PP_BANNER_SHOW, mCurrentAd, 1);
mCurrentAd.registerView(mBannerView);
}
}
void zoomIn(float ratio)
{
ViewGroup banner = mContainerView.findViewById(R.id.banner);
ViewGroup.LayoutParams lp = banner.getLayoutParams();
lp.height = (int) ((mOpentHeight - mClosedHeight) * ratio + mClosedHeight);
banner.setLayoutParams(lp);
}
void zoomOut(float ratio)
{
ViewGroup banner = mContainerView.findViewById(R.id.banner);
ViewGroup.LayoutParams lp = banner.getLayoutParams();
lp.height = (int) (mClosedHeight - (mClosedHeight - mOpentHeight) * ratio);
banner.setLayoutParams(lp);
}
boolean close()
void close()
{
if (!isBannerContainerVisible() || mBanners == null || !mOpened)
return false;
return;
mOpened = false;
setFrameHeight((int) mCloseFrameHeight);
UiUtils.hide(mIcon);
mMessage.setMaxLines(MIN_MESSAGE_LINES);
mTitle.setMaxLines(MIN_TITLE_LINES);
updateVisibility();
if (mCurrentAd != null)
mCurrentAd.registerView(mBannerView);
return true;
}
private void setFrameHeight(int height)
{
ViewGroup.LayoutParams lp = mBannerView.getLayoutParams();
lp.height = height;
mBannerView.setLayoutParams(lp);
}
private void loadIcon(@NonNull MwmNativeAd ad)

View file

@ -114,12 +114,14 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
if (ratio >= 1)
{
mBannerController.zoomOut(1);
mBannerController.open();
return;
}
if (ratio == 0)
{
mBannerController.zoomIn(ratio);
mBannerController.close();
return;
}