开屏图片转Banner特效

This commit is contained in:
zlzw 2023-04-18 16:31:31 +08:00
parent f913248fa1
commit 369f3f2cae
5 changed files with 87 additions and 25 deletions

View File

@ -9,9 +9,9 @@ ext {
]
manifestPlaceholders = [
//
// serverHost : "https://napi.yaoulive.com",
serverHost : "https://napi.yaoulive.com",
//
serverHost : "https://ceshi.yaoulive.com",
// serverHost : "https://ceshi.yaoulive.com",
//
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",

View File

@ -7,7 +7,6 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.NotificationChannel;
import android.app.PendingIntent;
@ -18,14 +17,13 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.transition.ChangeBounds;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
@ -75,7 +73,6 @@ import com.yunbao.common.event.MessageIMEvent;
import com.yunbao.common.event.NoviceInstructorEvent;
import com.yunbao.common.event.RongIMConnectionStatusEvent;
import com.yunbao.common.event.UpdateTablePointMe;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.CommonHttpConsts;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
@ -92,9 +89,7 @@ import com.yunbao.common.utils.LocationUtil;
import com.yunbao.common.utils.ProcessResultUtil;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.SpUtil;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.ToastUtils;
import com.yunbao.common.utils.VersionUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.views.APKUpdateCustomPopup;
@ -108,6 +103,7 @@ import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.utils.LiveStorge;
import com.yunbao.live.views.ChatListViewHolder;
import com.yunbao.main.R;
import com.yunbao.main.adapter.FullAdToBannerTransition;
import com.yunbao.main.dialog.MainStartDialogFragment;
import com.yunbao.main.dialog.ReturnUserDialog;
import com.yunbao.main.dialog.SigninDialog;
@ -204,9 +200,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
protected void create() {
super.create();
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
ChangeBounds bounds = new ChangeBounds();
bounds.setDuration(1000);
getWindow().setSharedElementEnterTransition(bounds);
getWindow().setSharedElementEnterTransition(new FullAdToBannerTransition(1,0.4f,new DecelerateInterpolator()));
}
@Override

View File

@ -0,0 +1,63 @@
package com.yunbao.main.adapter;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.transition.ChangeBounds;
import android.view.View;
import android.view.ViewGroup;
import android.transition.TransitionValues;
public class FullAdToBannerTransition extends ChangeBounds {
private static final String ALPHA = "android:faderay:alpha";
private final float startAlpha;
private final float endAlpha;
public FullAdToBannerTransition(final float startAlpha, final float endAlpha, final TimeInterpolator timeInterpolator) {
this.startAlpha = startAlpha;
this.endAlpha = endAlpha;
setInterpolator(timeInterpolator);
setDuration(1000);
setStartDelay(500);
}
@Override
public void captureStartValues(final TransitionValues transitionValues) {
super.captureStartValues(transitionValues);
captureValues(transitionValues);
}
@Override
public void captureEndValues(final TransitionValues transitionValues) {
super.captureEndValues(transitionValues);
captureValues(transitionValues);
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
Animator animator = super.createAnimator(sceneRoot, startValues, endValues);
ObjectAnimator fade = ObjectAnimator.ofFloat(endValues.view, View.ALPHA, startAlpha, endAlpha);
return mergeAnimators(animator, fade);
}
private void captureValues(final TransitionValues transitionValues) {
transitionValues.values.put(ALPHA, transitionValues.view.getAlpha());
}
private Animator mergeAnimators(Animator animator1, Animator animator2) {
if (animator1 == null) {
return animator2;
} else if (animator2 == null) {
return animator1;
} else {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animator1, animator2);
return animatorSet;
}
}
}

View File

@ -1,5 +1,6 @@
package com.yunbao.main.views;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.Dialog;
@ -16,8 +17,13 @@ import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowInsets;
import android.view.WindowInsetsAnimation;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
@ -332,24 +338,22 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement
mBanner.setClipToOutline(true);
String adUrl = ((Activity) mContext).getIntent().getStringExtra("ad_url");
ImageView ad = headView.findViewById(R.id.ad_img);
ToastUtil.showDebug(adUrl);
if (StringUtil.isEmpty(adUrl)) {
ad.setVisibility(View.GONE);
} else {
//ImgLoader.display(mContext, adUrl, ad);
Glide.with(mContext)
.load(adUrl)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
ToastUtil.showDebug("加载失败");
ActivityCompat.startPostponedEnterTransition((Activity) mContext);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
ToastUtil.showDebug("加载完成");
ActivityCompat.startPostponedEnterTransition((Activity) mContext);
return false;
}

View File

@ -11,7 +11,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/ad_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="0dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop"
android:src="@drawable/bg_tmp_s"
android:transitionName="ad_img_0" />
<com.ms.banner.Banner
android:id="@+id/banner"
@ -29,16 +38,7 @@
</com.ms.banner.Banner>
<ImageView
android:id="@+id/ad_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="110dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop"
android:src="@drawable/bg_tmp_s"
android:transitionName="ad_img_0" />
</RelativeLayout>