盲盒礼物开箱动画

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; private String blindBoxType;
@SerializedName("blind_box_id") @SerializedName("blind_box_id")
private String blindBoxId; 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() { public List<String> getItemName() {
return itemName; return itemName;

View File

@ -40,6 +40,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser; import com.opensource.svgaplayer.SVGAParser;
@ -47,6 +48,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.BlindBoxInfoModel; import com.yunbao.common.bean.BlindBoxInfoModel;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveGiftBean; import com.yunbao.common.bean.LiveGiftBean;
import com.yunbao.common.bean.LiveGiftBean2; import com.yunbao.common.bean.LiveGiftBean2;
import com.yunbao.common.bean.UserBean; 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.SVGAViewUtils;
import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.adapter.GiftTopAdapter; import com.yunbao.live.adapter.GiftTopAdapter;
import com.yunbao.live.adapter.LiveGiftCountAdapter; import com.yunbao.live.adapter.LiveGiftCountAdapter;
import com.yunbao.live.adapter.LiveGiftPagerAdapter; import com.yunbao.live.adapter.LiveGiftPagerAdapter;
@ -83,6 +87,8 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -139,7 +145,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
public int type = 0; public int type = 0;
private static String type_name = "熱門"; private static String type_name = "熱門";
JSONArray list; JSONArray list;
private ImageView mVipGoldIcon; private ImageView mVipGoldIcon, description;
private TextView mVipGoldTitle; private TextView mVipGoldTitle;
private TextView mVipGoldDesc; private TextView mVipGoldDesc;
private TextView mGiftPackage, blindNumber, textBlindProgress, textBlindGiftName; private TextView mGiftPackage, blindNumber, textBlindProgress, textBlindGiftName;
@ -147,7 +153,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
private int isContactGift = 0; private int isContactGift = 0;
DialogInterface.OnDismissListener onDismissListener; DialogInterface.OnDismissListener onDismissListener;
DialogInterface.OnShowListener onShowListener; DialogInterface.OnShowListener onShowListener;
private SVGAImageView blindSvga; private SVGAImageView blindSvga, blindBoxOpen;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -217,6 +223,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mArrow = mRootView.findViewById(R.id.arrow); mArrow = mRootView.findViewById(R.id.arrow);
iconMasking = mRootView.findViewById(R.id.icon_masking); iconMasking = mRootView.findViewById(R.id.icon_masking);
blindSvga = mRootView.findViewById(R.id.blind_svga); blindSvga = mRootView.findViewById(R.id.blind_svga);
blindBoxOpen = mRootView.findViewById(R.id.blind_box_open);
mBtnSend = mRootView.findViewById(R.id.btn_send); mBtnSend = mRootView.findViewById(R.id.btn_send);
mBtnSendGroup = mRootView.findViewById(R.id.btn_send_group); mBtnSendGroup = mRootView.findViewById(R.id.btn_send_group);
mBtnSendLian = mRootView.findViewById(R.id.btn_send_lian); mBtnSendLian = mRootView.findViewById(R.id.btn_send_lian);
@ -306,6 +313,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mTvGoldCoin.setOnClickListener(this); mTvGoldCoin.setOnClickListener(this);
mVipGold = mRootView.findViewById(R.id.btn_luck_gift_tip); mVipGold = mRootView.findViewById(R.id.btn_luck_gift_tip);
mVipGoldIcon = mRootView.findViewById(R.id.vipGoldIcon); mVipGoldIcon = mRootView.findViewById(R.id.vipGoldIcon);
description = mRootView.findViewById(R.id.description);
mVipGoldTitle = mRootView.findViewById(R.id.vipGoldTitle); mVipGoldTitle = mRootView.findViewById(R.id.vipGoldTitle);
mVipGoldDesc = mRootView.findViewById(R.id.vipGoldDesc); mVipGoldDesc = mRootView.findViewById(R.id.vipGoldDesc);
mVipGold.setOnClickListener(this); mVipGold.setOnClickListener(this);
@ -348,6 +356,23 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
mVipGold.setVisibility(View.GONE); mVipGold.setVisibility(View.GONE);
} }
getBlindBoxInfo(); 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<>(); public List<BlindBoxInfoModel> blindBoxInfoModels = new ArrayList<>();
@ -743,21 +768,28 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
model = boxInfoModel; model = boxInfoModel;
} }
} }
if (model == null) return; if (model == null) return;
new SVGAParser(mContext).decodeFromAssets("hdsn.svga", new SVGAParser.ParseCompletion() { blindBoxOpen.clear();
@Override blindBoxOpen.setVisibility(View.GONE);
public void onComplete(SVGAVideoEntity videoItem) { try {
SVGADrawable drawable = new SVGADrawable(videoItem); blindSvga.clear();
blindSvga.setImageDrawable(drawable); new SVGAParser(mContext).parse(new URL(model.getThresholdEffectSrc()), new SVGAParser.ParseCompletion() {
SVGAViewUtils.playEndClear(blindSvga, false); @Override
public void onComplete(SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem);
blindSvga.setImageDrawable(drawable);
SVGAViewUtils.playEndClear(blindSvga, false);
} }
@Override @Override
public void onError() { public void onError() {
Log.e("errqs", "errl"); Log.e("errqs", "errl");
} }
}, null); });
} catch (MalformedURLException e) {
e.printStackTrace();
}
mArrow.setVisibility(View.GONE); mArrow.setVisibility(View.GONE);
mBtnChooseCount.setEnabled(false); mBtnChooseCount.setEnabled(false);
mVipGold.setVisibility(View.GONE); mVipGold.setVisibility(View.GONE);
@ -1043,6 +1075,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onSendBlindGiftEvent(SendBlindGiftEvent event) { public void onSendBlindGiftEvent(SendBlindGiftEvent event) {
BlindBoxInfoModel model = null; BlindBoxInfoModel model = null;
@ -1053,8 +1086,53 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
model = blindBoxInfoModels.get(i); model = blindBoxInfoModels.get(i);
} }
} }
long userID = IMLoginManager.get(mContext).getUserInfo().getId(); long userID = IMLoginManager.get(mContext).getUserInfo().getId();
String boxBlindName; 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())) { if (TextUtils.equals(String.valueOf(userID), event.getUid()) && blindBoxType == Integer.parseInt(event.getBoxType())) {
switch (blindBoxType) { switch (blindBoxType) {
@ -1159,7 +1237,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
if (stringBuilders != null && stringBuilders.size() > 0) { if (stringBuilders != null && stringBuilders.size() > 0) {
SpannableStringBuilder stringBuilder = stringBuilders.get(0); SpannableStringBuilder stringBuilder = stringBuilders.get(0);
textBlindGiftName.setText(stringBuilder); textBlindGiftName.setText(stringBuilder);
boxBlindHandler.postDelayed(boxBlindRunnable, 1100); boxBlindHandler.postDelayed(boxBlindRunnable, 1500);
stringBuilders.remove(0); stringBuilders.remove(0);
} else { } else {
textBlindGiftName.setText(String.format(mContext.getString(R.string.random_availability), blindGiftNamesBuffer.toString())); textBlindGiftName.setText(String.format(mContext.getString(R.string.random_availability), blindGiftNamesBuffer.toString()));

View File

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

View File

@ -1,127 +1,144 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="159dp" android:layout_width="170dp"
android:layout_height="110dp" 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>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_gravity="end"
android:layout_height="wrap_content" android:layout_width="159dp"
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"
android:layout_height="match_parent" 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 <RelativeLayout
android:id="@+id/text_blind_gift_name" android:layout_width="29dp"
android:layout_width="wrap_content" android:layout_height="29dp"
android:layout_height="wrap_content" android:layout_marginStart="14dp"
android:layout_gravity="center" android:layout_marginTop="51dp">
android:layout_margin="5dp"
android:ellipsize="marquee" <com.opensource.svgaplayer.SVGAImageView
android:focusable="true" android:id="@+id/blind_svga"
android:focusableInTouchMode="true" android:layout_width="match_parent"
android:gravity="center" android:layout_height="match_parent" />
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true" <ImageView
android:singleLine="true" android:id="@+id/icon_masking"
android:textColor="@color/white" android:layout_width="match_parent"
android:textSize="10sp" /> android:layout_height="match_parent"
</FrameLayout> android:src="@mipmap/icon_masking" />
</LinearLayout> </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>