直播间开通贵族
This commit is contained in:
@@ -5,8 +5,13 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
|
||||
@@ -16,6 +21,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/6/22.
|
||||
@@ -138,4 +144,55 @@ public class BitmapUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转圆形图片
|
||||
*
|
||||
* @param context
|
||||
* @param url
|
||||
* @param width
|
||||
* @param height
|
||||
* @param radius
|
||||
* @return
|
||||
*/
|
||||
public Bitmap getBitmap(Context context, String url, int width, int height, int radius) {
|
||||
Bitmap myBitmap = null;
|
||||
try {
|
||||
myBitmap = Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.submit(width, height).get();
|
||||
Bitmap bitmap = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
|
||||
return toRoundBitmap(bitmap, width, height, radius);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/***
|
||||
* 转圆形图片
|
||||
* @param bitmap
|
||||
* @param width
|
||||
* @param height
|
||||
* @param radius
|
||||
* @return
|
||||
*/
|
||||
public Bitmap toRoundBitmap(Bitmap bitmap, int width, int height, int radius) {
|
||||
// 前面同上,绘制图像分别需要bitmap,canvas,paint对象
|
||||
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
|
||||
Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bm);
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
// 这里需要先画出一个圆
|
||||
canvas.drawCircle(width / 2, height / 2, radius, paint);
|
||||
// 圆画好之后将画笔重置一下
|
||||
paint.reset();
|
||||
// 设置图像合成模式,该模式为只在源图像和目标图像相交的地方绘制源图像
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||
return bm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,6 @@ public class FullServiceNotificationView extends FrameLayout {
|
||||
|
||||
private void setFullServiceStart(String svgaName) {
|
||||
svagaBc.setCallback(svgaCallback);
|
||||
svagaBc.setLoops(1);
|
||||
svagaBc.startAnimation();
|
||||
new SVGAParser(mContext)
|
||||
.decodeFromAssets(svgaName, new SVGAParser.ParseCompletion() {
|
||||
@Override
|
||||
@@ -138,6 +136,7 @@ public class FullServiceNotificationView extends FrameLayout {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
svagaBc.setLoops(1);
|
||||
svagaBc.startAnimation();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
package com.yunbao.common.views.weight;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.opensource.svgaplayer.SVGACallback;
|
||||
import com.opensource.svgaplayer.SVGADrawable;
|
||||
import com.opensource.svgaplayer.SVGADynamicEntity;
|
||||
import com.opensource.svgaplayer.SVGAImageView;
|
||||
import com.opensource.svgaplayer.SVGAParser;
|
||||
import com.opensource.svgaplayer.SVGAVideoEntity;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.utils.BitmapUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* 开通贵族的通知
|
||||
*/
|
||||
public class NobleNoticeView extends FrameLayout {
|
||||
|
||||
private Context mContext;
|
||||
private View rootView;
|
||||
private SVGAImageView svagaBc;
|
||||
private RelativeLayout rootLayout;
|
||||
private long animationTime = 8000;
|
||||
private TextView gotoRoomView, nobleNickname;
|
||||
private String mSvgaName;
|
||||
private RoleType roleType;
|
||||
private HorizontalScrollView contextLayout;
|
||||
private RelativeLayout scrollLayout;
|
||||
private ImageView nobleIcon;
|
||||
|
||||
public NobleNoticeView(@NonNull Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public NobleNoticeView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public NobleNoticeView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
rootView = LayoutInflater.from(mContext).inflate(R.layout.view_noble_notice, this, true);
|
||||
svagaBc = rootView.findViewById(R.id.svaga_bc);
|
||||
rootLayout = rootView.findViewById(R.id.root_layout);
|
||||
gotoRoomView = rootView.findViewById(R.id.goto_room_view);
|
||||
contextLayout = rootView.findViewById(R.id.context_layout);
|
||||
scrollLayout = rootView.findViewById(R.id.scroll_layout);
|
||||
nobleIcon = rootView.findViewById(R.id.noble_icon);
|
||||
nobleNickname = rootView.findViewById(R.id.noble_nickname);
|
||||
contextLayout.setVisibility(GONE);
|
||||
gotoRoomView.setVisibility(GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置展示的类型
|
||||
*
|
||||
* @param roleType
|
||||
* @return
|
||||
*/
|
||||
public NobleNoticeView setRoleType(RoleType roleType) {
|
||||
this.roleType = roleType;
|
||||
// setButtonPosition(roleType);
|
||||
switch (roleType) {
|
||||
//男爵
|
||||
case BARON:
|
||||
nobleNoticeStart("icon_noble_nanjue.svga");
|
||||
break;
|
||||
//子爵
|
||||
case VISCOUNT:
|
||||
nobleNoticeStart("icon_noble_zijue.svga");
|
||||
break;
|
||||
//侯爵
|
||||
case MARQUIS:
|
||||
nobleNoticeStart("icon_noble_houjue.svga");
|
||||
break;
|
||||
//公爵
|
||||
case DUKE:
|
||||
nobleNoticeStart("icon_noble_gongjue.svga");
|
||||
break;
|
||||
//国王
|
||||
case KING:
|
||||
nobleNoticeStart("icon_noble_guowang.svga");
|
||||
break;
|
||||
//皇帝
|
||||
case EMPEROR:
|
||||
nobleNoticeStart("icon_noble_huangdi.svga");
|
||||
break;
|
||||
//超皇
|
||||
case BETTER_EMPEROR:
|
||||
nobleNoticeStart("icon_noble_chaohuang.svga");
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void nobleNoticeStart(String svgaName) {
|
||||
svagaBc.setCallback(svgaCallback);
|
||||
mSvgaName = svgaName;
|
||||
observable.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程处理用户头像
|
||||
*/
|
||||
private Observable<Bitmap> observable = Observable.create(new ObservableOnSubscribe<Bitmap>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<Bitmap> emitter) throws Exception {
|
||||
Bitmap bitmap = BitmapUtil.getInstance()
|
||||
.getBitmap(mContext,
|
||||
"https://downs.yaoulive.com/20220818/372776fa38774814d601e68fcfc70f35.jpeg?imageView2/2/w/600/h/600",
|
||||
174,
|
||||
174,
|
||||
87);
|
||||
emitter.onNext(bitmap);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 线程调度展示SVGA
|
||||
*/
|
||||
private Observer<Bitmap> observer = new Observer<Bitmap>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Bitmap bitmap) {
|
||||
new SVGAParser(mContext)
|
||||
.decodeFromAssets(mSvgaName, new SVGAParser.ParseCompletion() {
|
||||
@Override
|
||||
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
|
||||
svagaBc.setVisibility(VISIBLE);
|
||||
SVGADynamicEntity dynamicEntity = new SVGADynamicEntity();
|
||||
dynamicEntity.setDynamicImage(bitmap, "psd_31");
|
||||
SVGADrawable imageView = new SVGADrawable(svgaVideoEntity, dynamicEntity);
|
||||
svagaBc.setImageDrawable(imageView);
|
||||
try {
|
||||
Field mAnimator = svagaBc.getClass().getDeclaredField("mAnimator");
|
||||
mAnimator.setAccessible(true);
|
||||
ValueAnimator animator = (ValueAnimator) mAnimator.get(svagaBc);
|
||||
animationTime = animator.getDuration();
|
||||
System.out.println("播放时间 = " + animator.getDuration());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
svagaBc.setLoops(1);
|
||||
svagaBc.startAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* SVGA播放监听
|
||||
*/
|
||||
private SVGACallback svgaCallback = new SVGACallback() {
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinished() {
|
||||
svagaBc.clear();
|
||||
svagaBc.setVisibility(GONE);
|
||||
contextLayout.setVisibility(GONE);
|
||||
gotoRoomView.setVisibility(GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRepeat() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStep(int frame, double v) {
|
||||
System.out.println("frame = " + frame);
|
||||
if (frame == 10) {
|
||||
setButtonPosition(roleType);
|
||||
observable.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(bitmap -> {
|
||||
TranslateAnimation animationTranslate = new TranslateAnimation(0, -scrollLayout.getMeasuredWidth(), 0, 0);
|
||||
AnimationSet animationSet1 = new AnimationSet(true);
|
||||
animationSet1.addAnimation(animationTranslate);
|
||||
animationSet1.setFillAfter(true);
|
||||
animationSet1.setDuration((animationTime - 1000) / 2);
|
||||
animationSet1.setAnimationListener(animationListener);
|
||||
scrollLayout.startAnimation(animationSet1);
|
||||
}, throwable -> {
|
||||
|
||||
}).isDisposed();
|
||||
|
||||
}
|
||||
if (frame == 150) {
|
||||
contextLayout.setVisibility(GONE);
|
||||
gotoRoomView.setVisibility(GONE);
|
||||
scrollLayout.clearAnimation();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
//设置围观按钮/文字內容位置
|
||||
private void setButtonPosition(RoleType roleType) {
|
||||
rootLayout.post(() -> {
|
||||
int measuredHeight = rootLayout.getMeasuredHeight();
|
||||
int measuredWidth = rootLayout.getMeasuredWidth();
|
||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) gotoRoomView.getLayoutParams();
|
||||
RelativeLayout.LayoutParams contextLayoutParams = (RelativeLayout.LayoutParams) contextLayout.getLayoutParams();
|
||||
switch (roleType) {
|
||||
case BARON:
|
||||
layoutParams.rightMargin = measuredWidth / 7;
|
||||
layoutParams.topMargin = measuredHeight / 12 * 5;
|
||||
contextLayoutParams.leftMargin = (int) (measuredWidth / 13 * 3.5);
|
||||
contextLayoutParams.topMargin = measuredHeight / 12 * 5;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_baron_station_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_nanjue, nobleIcon);
|
||||
nobleNickname.setText(R.string.baron);
|
||||
break;
|
||||
case VISCOUNT:
|
||||
layoutParams.rightMargin = measuredWidth / 7;
|
||||
layoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
contextLayoutParams.leftMargin = measuredWidth / 15 * 4;
|
||||
contextLayoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_viscount_station_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_zijue, nobleIcon);
|
||||
nobleNickname.setText(R.string.viscount);
|
||||
break;
|
||||
case MARQUIS:
|
||||
layoutParams.rightMargin = measuredWidth / 6;
|
||||
layoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
contextLayoutParams.leftMargin = measuredWidth / 15 * 4;
|
||||
contextLayoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_marquis_station_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_houjue, nobleIcon);
|
||||
nobleNickname.setText(R.string.marquis);
|
||||
break;
|
||||
case DUKE:
|
||||
layoutParams.rightMargin = measuredWidth / 6;
|
||||
layoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
contextLayoutParams.leftMargin = measuredWidth / 15 * 4;
|
||||
contextLayoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_duke_station_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_gongjue, nobleIcon);
|
||||
nobleNickname.setText(R.string.duke);
|
||||
break;
|
||||
case KING:
|
||||
layoutParams.rightMargin = measuredWidth / 6;
|
||||
layoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
contextLayoutParams.leftMargin = (int) (measuredWidth / 15 * 4.2);
|
||||
contextLayoutParams.topMargin = measuredHeight / 15 * 6;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_duke_king_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_guowang, nobleIcon);
|
||||
nobleNickname.setText(R.string.king);
|
||||
break;
|
||||
case EMPEROR:
|
||||
layoutParams.rightMargin = measuredWidth / 5;
|
||||
layoutParams.topMargin = measuredHeight / 15 * 7;
|
||||
contextLayoutParams.leftMargin = (int) (measuredWidth / 15 * 4.2);
|
||||
contextLayoutParams.topMargin = measuredHeight / 15 * 7;
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_duke_king_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_huangdi, nobleIcon);
|
||||
nobleNickname.setText(R.string.emperor);
|
||||
break;
|
||||
case BETTER_EMPEROR:
|
||||
layoutParams.rightMargin = measuredWidth / 5;
|
||||
layoutParams.topMargin = (int) (measuredHeight / 15 * 6.7);
|
||||
contextLayoutParams.leftMargin = (int) (measuredWidth / 15 * 4.5);
|
||||
contextLayoutParams.topMargin = (int) (measuredHeight / 15 * 6.5);
|
||||
gotoRoomView.setBackgroundResource(R.drawable.background_duke_king_horn);
|
||||
ImgLoader.display(mContext, R.mipmap.icon_open_chaohuang, nobleIcon);
|
||||
nobleNickname.setText(R.string.better_emperor);
|
||||
break;
|
||||
}
|
||||
gotoRoomView.setLayoutParams(layoutParams);
|
||||
contextLayout.setLayoutParams(contextLayoutParams);
|
||||
contextLayout.setVisibility(VISIBLE);
|
||||
gotoRoomView.setVisibility(VISIBLE);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Animation.AnimationListener animationListener = new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
|
||||
scrollLayout.clearAnimation();
|
||||
if (svagaBc.isAnimating()) {
|
||||
TranslateAnimation animationTranslate = new TranslateAnimation(0, -scrollLayout.getMeasuredWidth(), 0, 0);
|
||||
AnimationSet animationSet1 = new AnimationSet(true);
|
||||
animationSet1.addAnimation(animationTranslate);
|
||||
animationSet1.setFillAfter(true);
|
||||
animationSet1.setDuration((animationTime - 600) / 2);
|
||||
animationSet1.setAnimationListener(animationListener);
|
||||
scrollLayout.startAnimation(animationSet1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public enum RoleType {
|
||||
BARON("男爵", 1),
|
||||
VISCOUNT("子爵", 2),
|
||||
MARQUIS("侯爵", 3),
|
||||
DUKE("公爵", 4),
|
||||
KING("国王", 5),
|
||||
EMPEROR("皇帝", 6),
|
||||
BETTER_EMPEROR("超皇", 7);
|
||||
private String name;
|
||||
private int type;
|
||||
|
||||
|
||||
RoleType(String name, int type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public RoleType setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public RoleType setType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user