盲盒礼物开箱动画

This commit is contained in:
18401019693 2023-05-31 13:22:14 +08:00
parent b0008405e2
commit db165cc05d
4 changed files with 256 additions and 139 deletions

View File

@ -20,6 +20,28 @@ public class BlindBoxInfoModel extends BaseModel {
private String blindBoxType;
@SerializedName("blind_box_id")
private String blindBoxId;
@SerializedName("blind_box_swf")
private String blindBoxSwf;
@SerializedName("threshold_effect_src")
private String thresholdEffectSrc;
public String getThresholdEffectSrc() {
return thresholdEffectSrc;
}
public BlindBoxInfoModel setThresholdEffectSrc(String thresholdEffectSrc) {
this.thresholdEffectSrc = thresholdEffectSrc;
return this;
}
public String getBlindBoxSwf() {
return blindBoxSwf;
}
public BlindBoxInfoModel setBlindBoxSwf(String blindBoxSwf) {
this.blindBoxSwf = blindBoxSwf;
return this;
}
public List<String> getItemName() {
return itemName;

View File

@ -40,6 +40,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
@ -47,6 +48,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.BlindBoxInfoModel;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveGiftBean;
import com.yunbao.common.bean.LiveGiftBean2;
import com.yunbao.common.bean.UserBean;
@ -66,8 +68,10 @@ import com.yunbao.common.utils.NobleUtil;
import com.yunbao.common.utils.SVGAViewUtils;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.adapter.GiftTopAdapter;
import com.yunbao.live.adapter.LiveGiftCountAdapter;
import com.yunbao.live.adapter.LiveGiftPagerAdapter;
@ -83,6 +87,8 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -139,7 +145,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
public int type = 0;
private static String type_name = "熱門";
JSONArray list;
private ImageView mVipGoldIcon;
private ImageView mVipGoldIcon, description;
private TextView mVipGoldTitle;
private TextView mVipGoldDesc;
private TextView mGiftPackage, blindNumber, textBlindProgress, textBlindGiftName;
@ -147,7 +153,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
private int isContactGift = 0;
DialogInterface.OnDismissListener onDismissListener;
DialogInterface.OnShowListener onShowListener;
private SVGAImageView blindSvga;
private SVGAImageView blindSvga, blindBoxOpen;
@Override
protected int getLayoutId() {
@ -217,6 +223,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mArrow = mRootView.findViewById(R.id.arrow);
iconMasking = mRootView.findViewById(R.id.icon_masking);
blindSvga = mRootView.findViewById(R.id.blind_svga);
blindBoxOpen = mRootView.findViewById(R.id.blind_box_open);
mBtnSend = mRootView.findViewById(R.id.btn_send);
mBtnSendGroup = mRootView.findViewById(R.id.btn_send_group);
mBtnSendLian = mRootView.findViewById(R.id.btn_send_lian);
@ -306,6 +313,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mTvGoldCoin.setOnClickListener(this);
mVipGold = mRootView.findViewById(R.id.btn_luck_gift_tip);
mVipGoldIcon = mRootView.findViewById(R.id.vipGoldIcon);
description = mRootView.findViewById(R.id.description);
mVipGoldTitle = mRootView.findViewById(R.id.vipGoldTitle);
mVipGoldDesc = mRootView.findViewById(R.id.vipGoldDesc);
mVipGold.setOnClickListener(this);
@ -348,6 +356,23 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mVipGold.setVisibility(View.GONE);
}
getBlindBoxInfo();
ViewClicksAntiShake.clicksAntiShake(description, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo();
StringBuffer htmlUrl = new StringBuffer();
htmlUrl.append(CommonAppConfig.HOST)
.append("/h5/info/index.html?uid=")
.append(userInfo.getId())
.append("&token=")
.append(userInfo.getToken());
Bundle bundle = new Bundle();
bundle.putString("url", htmlUrl.toString());
LiveHDDialogFragment fragment = new LiveHDDialogFragment();
fragment.setArguments(bundle);
fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");
}
});
}
public List<BlindBoxInfoModel> blindBoxInfoModels = new ArrayList<>();
@ -743,21 +768,28 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
model = boxInfoModel;
}
}
if (model == null) return;
new SVGAParser(mContext).decodeFromAssets("hdsn.svga", new SVGAParser.ParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem);
blindSvga.setImageDrawable(drawable);
SVGAViewUtils.playEndClear(blindSvga, false);
if (model == null) return;
blindBoxOpen.clear();
blindBoxOpen.setVisibility(View.GONE);
try {
blindSvga.clear();
new SVGAParser(mContext).parse(new URL(model.getThresholdEffectSrc()), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem);
blindSvga.setImageDrawable(drawable);
SVGAViewUtils.playEndClear(blindSvga, false);
}
}
@Override
public void onError() {
Log.e("errqs", "errl");
}
}, null);
@Override
public void onError() {
Log.e("errqs", "errl");
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
mArrow.setVisibility(View.GONE);
mBtnChooseCount.setEnabled(false);
mVipGold.setVisibility(View.GONE);
@ -1043,6 +1075,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSendBlindGiftEvent(SendBlindGiftEvent event) {
BlindBoxInfoModel model = null;
@ -1053,8 +1086,53 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
model = blindBoxInfoModels.get(i);
}
}
long userID = IMLoginManager.get(mContext).getUserInfo().getId();
String boxBlindName;
try {
if (!blindBoxOpen.isAnimating()) {
new SVGAParser(mContext).parse(new URL(model.getBlindBoxSwf()), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity videoItem) {
blindBoxOpen.setVisibility(View.VISIBLE);
SVGADrawable drawable = new SVGADrawable(videoItem);
blindBoxOpen.setImageDrawable(drawable);
blindBoxOpen.setLoops(1);
blindBoxOpen.startAnimation();
}
@Override
public void onError() {
}
});
blindBoxOpen.setCallback(new SVGACallback() {
@Override
public void onPause() {
}
@Override
public void onFinished() {
blindBoxOpen.clear();
blindBoxOpen.setVisibility(View.GONE);
Log.e("礼物盲盒", "结束播放");
}
@Override
public void onRepeat() {
}
@Override
public void onStep(int i, double v) {
Log.e("礼物盲盒", "onStep: frame " + i + " percentage " + v);
}
});
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
//判断送礼用户更新送礼用户进度
if (TextUtils.equals(String.valueOf(userID), event.getUid()) && blindBoxType == Integer.parseInt(event.getBoxType())) {
switch (blindBoxType) {
@ -1159,7 +1237,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
if (stringBuilders != null && stringBuilders.size() > 0) {
SpannableStringBuilder stringBuilder = stringBuilders.get(0);
textBlindGiftName.setText(stringBuilder);
boxBlindHandler.postDelayed(boxBlindRunnable, 1100);
boxBlindHandler.postDelayed(boxBlindRunnable, 1500);
stringBuilders.remove(0);
} else {
textBlindGiftName.setText(String.format(mContext.getString(R.string.random_availability), blindGiftNamesBuffer.toString()));

View File

@ -343,7 +343,7 @@ public class LiveHDDialogFragment extends AbsDialogFragment {
dismiss();
((LiveAudienceActivity) mContext).openGiftWindow();
} else if (TextUtils.equals(event.getMethod(), "androidGoBack")) {
// dismiss();
dismiss();
} else if (TextUtils.equals(event.getMethod(), "androidMethodLookToLive")) {
if (mContext instanceof LiveRyAnchorActivity) {
return;

View File

@ -1,127 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="159dp"
android:layout_height="110dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<!--凤凰,龙,麒麟-->
<FrameLayout
android:id="@+id/frame_blind_top"
android:layout_width="match_parent"
android:layout_height="86.5dp"
android:background="@mipmap/bg_kirin">
<RelativeLayout
android:layout_width="29dp"
android:layout_height="29dp"
android:layout_marginStart="14dp"
android:layout_marginTop="51dp">
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/blind_svga"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/icon_masking"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/icon_masking" />
</RelativeLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="170dp"
android:layout_height="110dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="51dp"
android:layout_marginTop="59dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress_blind3"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="30"
android:progressDrawable="@drawable/bg_blind_progres"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progress_blind1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress"
android:visibility="visible" />
<ProgressBar
android:id="@+id/progress_blind2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress1"
android:visibility="gone" />
<TextView
android:id="@+id/text_blind_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="6sp" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/blind_number"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginStart="47dp"
android:layout_marginTop="71dp"
android:textColor="@color/white"
android:textSize="8sp" />
<ImageView
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_gravity="end"
android:layout_marginTop="40dp"
android:layout_marginEnd="15dp"
android:src="@mipmap/icon_what" />
</FrameLayout>
<FrameLayout
android:layout_width="149dp"
<LinearLayout
android:layout_gravity="end"
android:layout_width="159dp"
android:layout_height="match_parent"
android:background="@mipmap/bg_blind_bottom">
android:gravity="center_horizontal"
android:orientation="vertical">
<!--凤凰,龙,麒麟-->
<FrameLayout
android:id="@+id/frame_blind_top"
android:layout_width="match_parent"
android:layout_height="86.5dp"
android:background="@mipmap/bg_kirin">
<com.yunbao.common.views.weight.MarqueeTextView
android:id="@+id/text_blind_gift_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="10sp" />
</FrameLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="29dp"
android:layout_height="29dp"
android:layout_marginStart="14dp"
android:layout_marginTop="51dp">
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/blind_svga"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/icon_masking"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/icon_masking" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="51dp"
android:layout_marginTop="59dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress_blind3"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="30"
android:progressDrawable="@drawable/bg_blind_progres"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progress_blind1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress"
android:visibility="visible" />
<ProgressBar
android:id="@+id/progress_blind2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="8dp"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/bg_blind_progress1"
android:visibility="gone" />
<TextView
android:id="@+id/text_blind_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="6sp" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/blind_number"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginStart="47dp"
android:layout_marginTop="71dp"
android:textColor="@color/white"
android:textSize="8sp" />
<ImageView
android:id="@+id/description"
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_gravity="end"
android:layout_marginTop="40dp"
android:layout_marginEnd="15dp"
android:src="@mipmap/icon_what" />
</FrameLayout>
<FrameLayout
android:layout_width="149dp"
android:layout_height="match_parent"
android:background="@mipmap/bg_blind_bottom">
<com.yunbao.common.views.weight.MarqueeTextView
android:id="@+id/text_blind_gift_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="10sp" />
</FrameLayout>
</LinearLayout>
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/blind_box_open"
android:layout_width="61dp"
android:layout_marginTop="1dp"
android:layout_height="110dp"
android:layout_marginStart="7dp" />
</FrameLayout>