[android] Implemented banner ratio calculation for changing its size in future

This commit is contained in:
Александр Зацепин 2019-02-04 14:58:27 +03:00 committed by yoksnod
parent 5a1940e1fc
commit 69423bb58f
2 changed files with 67 additions and 1 deletions

View file

@ -8,6 +8,7 @@ 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;
@ -270,6 +271,14 @@ final class BannerController
}
void zoomIn(float ratio)
{
}
void zoomOut(float ratio)
{
}
boolean close()
{
if (!isBannerContainerVisible() || mBanners == null || !mOpened)
@ -383,6 +392,11 @@ final class BannerController
return mOpened;
}
boolean hasAd()
{
return mCurrentAd != null;
}
private class MyNativeAdsListener implements NativeAdListener
{
@Nullable

View file

@ -53,6 +53,8 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@NonNull
private Toolbar mToolbar;
private int mViewportMinHeight;
private int mCurrentTop;
private boolean mPeekHeightAnimating;
@SuppressWarnings("NullableProblems")
@NonNull
private BannerController mBannerController;
@ -87,11 +89,61 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset)
{
if (slideOffset < 0)
return;
updateViewPortRect();
resizeBanner();
}
};
private boolean mPeekHeightAnimating;
private void resizeBanner()
{
int lastTop = mCurrentTop;
mCurrentTop = mPlacePage.getTop();
if (!mBannerController.hasAd())
return;
int bannerMaxY = calculateBannerMaxY();
int bannerMinY = calculateBannerMinY();
int maxDistance = Math.abs(bannerMaxY - bannerMinY);
int yDistance = Math.abs(mCurrentTop - bannerMinY);
float ratio = (float) yDistance / maxDistance;
if (ratio >= 1)
{
mBannerController.open();
return;
}
if (ratio == 0)
{
mBannerController.close();
return;
}
if (mCurrentTop < lastTop)
mBannerController.zoomOut(ratio);
else
mBannerController.zoomIn(ratio);
}
private int calculateBannerMaxY()
{
View coordinatorLayout = (ViewGroup) mPlacePage.getParent();
int height = coordinatorLayout.getHeight();
return mPlacePage.getHeight() > height * (1 - ANCHOR_RATIO)
? (int) (height * ANCHOR_RATIO) : height - mPlacePage.getHeight();
}
private int calculateBannerMinY()
{
View coordinatorLayout = (ViewGroup) mPlacePage.getParent();
int height = coordinatorLayout.getHeight();
return height - mPlacePageBehavior.getPeekHeight();
}
public BottomSheetPlacePageController(@NonNull Activity activity,
@NonNull AdsRemovalPurchaseControllerProvider provider)