568 lines
22 KiB
Java
568 lines
22 KiB
Java
package com.yunbao.live.views;
|
||
|
||
import android.Manifest;
|
||
import android.annotation.SuppressLint;
|
||
import android.app.Activity;
|
||
import android.content.Context;
|
||
import android.graphics.Bitmap;
|
||
import android.graphics.Canvas;
|
||
import android.graphics.Color;
|
||
import android.os.Bundle;
|
||
import android.os.Handler;
|
||
import android.os.Vibrator;
|
||
import android.util.DisplayMetrics;
|
||
import android.util.Log;
|
||
import android.view.LayoutInflater;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.view.WindowManager;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.TextView;
|
||
import android.widget.ViewFlipper;
|
||
|
||
import androidx.fragment.app.FragmentActivity;
|
||
|
||
import com.lxj.xpopup.XPopup;
|
||
import com.umeng.analytics.MobclickAgent;
|
||
import com.yunbao.common.CommonAppConfig;
|
||
import com.yunbao.common.Constants;
|
||
import com.yunbao.common.bean.NewPeopleInfo;
|
||
import com.yunbao.common.dialog.LiveNewRolePopup;
|
||
import com.yunbao.common.event.MessageIMEvent;
|
||
import com.yunbao.common.glide.ImgLoader;
|
||
import com.yunbao.common.http.API;
|
||
import com.yunbao.common.http.HttpCallback;
|
||
import com.yunbao.common.http.HttpClient;
|
||
import com.yunbao.common.utils.Bus;
|
||
import com.yunbao.common.utils.ProcessResultUtil;
|
||
import com.yunbao.common.utils.SpUtil;
|
||
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.bean.LiveChatBean;
|
||
import com.yunbao.live.dialog.LiveHDDialogFragment;
|
||
import com.yunbao.live.dialog.LiveMicUserDialogFragment;
|
||
import com.yunbao.live.dialog.LivePromotionDialogFragment;
|
||
import com.yunbao.live.dialog.TextHintDialog;
|
||
import com.yunbao.live.dialog.VoiceDialog;
|
||
import com.yunbao.live.event.LiveAudienceEvent;
|
||
import com.yunbao.live.utils.VoiceUtils;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
import org.greenrobot.eventbus.Subscribe;
|
||
import org.greenrobot.eventbus.ThreadMode;
|
||
|
||
import java.util.Locale;
|
||
|
||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||
import io.reactivex.schedulers.Schedulers;
|
||
|
||
/**
|
||
* Created by cxf on 2018/10/9.
|
||
* 观众直播间逻辑
|
||
*/
|
||
|
||
public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||
|
||
private String mLiveUid;
|
||
private String mStream;
|
||
private String url;
|
||
private View v_msg_redpoint, stationHornBanner;
|
||
private Activity context;
|
||
private ViewFlipper viewFlipper;
|
||
private TextView goToRomm;
|
||
private int icon = 0;
|
||
private String nobleName, nobleTtext;
|
||
private ImageView giftImage, liveNewPeople;
|
||
private String newPeopleUrl = null;
|
||
private View mNewPeopleRedDot;
|
||
private LinearLayout voiceButton;
|
||
private ImageView mRole;//特权
|
||
private ImageView mPlay;//玩
|
||
private ImageView mCheat;//整蛊
|
||
|
||
public LiveAudienceViewHolder(Context context, ViewGroup parentView) {
|
||
super(context, parentView);
|
||
this.context = (Activity) context;
|
||
}
|
||
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.view_live_audience;
|
||
}
|
||
|
||
@SuppressLint("ClickableViewAccessibility")
|
||
@Override
|
||
public void init() {
|
||
super.init();
|
||
EventBus.getDefault().register(this);
|
||
findViewById(R.id.btn_close).setOnClickListener(this);
|
||
findViewById(R.id.btn_share).setOnClickListener(this);
|
||
findViewById(R.id.btn_red_pack).setOnClickListener(this);
|
||
findViewById(R.id.btn_gift).setOnClickListener(this);
|
||
findViewById(R.id.btn_zg).setOnClickListener(this);
|
||
voiceButton = (LinearLayout) findViewById(R.id.voice_button);
|
||
giftImage = (ImageView) findViewById(R.id.gift_image);
|
||
liveNewPeople = (ImageView) findViewById(R.id.live_new_people);
|
||
|
||
viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper_banner);
|
||
mRole = (ImageView) findViewById(R.id.live_privilege);
|
||
mCheat = (ImageView) findViewById(R.id.live_cheat);
|
||
mPlay = (ImageView) findViewById(R.id.live_play);
|
||
stationHornBanner = findViewById(R.id.station_horn_banner);
|
||
mNewPeopleRedDot = findViewById(R.id.live_new_people_red_dot);
|
||
liveNewPeople.setOnClickListener(this);
|
||
mRole.setOnClickListener(this);
|
||
mCheat.setOnClickListener(this);
|
||
mPlay.setOnClickListener(this);
|
||
|
||
findViewById(R.id.btn_mic).setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
//获取房间连麦状态
|
||
HttpClient.getInstance().get("live.getDrLm", "live.getDrLm")
|
||
.params("uid", mLiveUid, true)
|
||
.execute(new HttpCallback() {
|
||
@Override
|
||
public void onSuccess(int code, String msg, String[] info) {
|
||
if (code == 0) {
|
||
LiveMicUserDialogFragment fragment = new LiveMicUserDialogFragment();
|
||
Bundle bundle = new Bundle();
|
||
bundle.putString(Constants.LIVE_UID, mLiveUid);
|
||
bundle.putString(Constants.STREAM, mStream);
|
||
bundle.putString("By", "1");
|
||
fragment.setArguments(bundle);
|
||
fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveUserMoreDialogFragment");
|
||
LiveMicUserDialogFragment.activity = ((LiveAudienceActivity) mContext);
|
||
} else {
|
||
ToastUtil.show(mContext.getString(R.string.no_mic_opn));
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
findViewById(R.id.btn_hd).setOnClickListener(new View.OnClickListener() {//游戏,活动按钮
|
||
@Override
|
||
public void onClick(View view) {
|
||
LivePromotionDialogFragment fragment = new LivePromotionDialogFragment();
|
||
fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LivePromotionDialogFragment");
|
||
}
|
||
});
|
||
findViewById(R.id.btn_more).setOnClickListener(this);
|
||
|
||
|
||
v_msg_redpoint = (View) findViewById(R.id.v_msg_redpoint);
|
||
//底部改造
|
||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.total_image), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||
@Override
|
||
public void onViewClicks() {
|
||
MobclickAgent.onEvent(mContext, "live_room_more_sett", "直播间侧边栏更多设置");
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setActivity(false)
|
||
.setType(LiveAudienceEvent.LiveAudienceType.BOTTOM_COLLECTION));
|
||
|
||
}
|
||
});
|
||
//玩
|
||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_play), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||
@Override
|
||
public void onViewClicks() {
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setActivity(true)
|
||
.setType(LiveAudienceEvent.LiveAudienceType.BOTTOM_COLLECTION));
|
||
|
||
}
|
||
});
|
||
//整蛊
|
||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_cheat), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||
@Override
|
||
public void onViewClicks() {
|
||
MobclickAgent.onEvent(mContext, "live_room_h5_game", "直播间下面鼓掌按钮");
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setType(LiveAudienceEvent.LiveAudienceType.WE_CHEAT));
|
||
|
||
}
|
||
});
|
||
// //底部礼物弹窗
|
||
ImgLoader.displayGif(mContext, R.mipmap.live_lw, giftImage);
|
||
|
||
ViewClicksAntiShake.clicksAntiShake(giftImage, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||
@Override
|
||
public void onViewClicks() {
|
||
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP));
|
||
}
|
||
});
|
||
Locale locale = mContext.getResources().getConfiguration().locale;
|
||
String language = locale.getLanguage();
|
||
|
||
// ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.live_icon_new_people_cn : R.mipmap.live_icon_newpeople_en, liveNewPeople);
|
||
// ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.live_icon_role : R.mipmap.live_icon_role_en, mRole);
|
||
// ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.live_icon_play : R.mipmap.live_icon_play_en, mPlay);
|
||
// ImgLoader.display(mContext, TextUtils.equals(language, "zh") ? R.mipmap.live_icon_cheat : R.mipmap.live_icon_cheat_en, mCheat);
|
||
|
||
voiceButton.setOnTouchListener((v, event) -> {
|
||
MobclickAgent.onEvent(mContext, "live_room_voice_chat_btn", "直播间点开最下面的语音输入的聊天按钮");
|
||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||
downY = event.getY();
|
||
if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) {
|
||
//按下
|
||
handler.postDelayed(mLongPressed, 500);
|
||
|
||
} else {
|
||
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||
float moveY = event.getY();
|
||
if (downY - moveY > 120) {
|
||
if (voiceDialog != null && voiceDialog.isAdded())
|
||
voiceDialog.withdraw();
|
||
if (voiceUtils != null)
|
||
voiceUtils.withdraw();
|
||
}
|
||
if ((downY - moveY < 100) && (downY - moveY > 30)) {
|
||
if (voiceDialog != null && voiceDialog.isAdded())
|
||
voiceDialog.notWithdraw(mContext);
|
||
if (voiceUtils != null)
|
||
voiceUtils.notWithdraw(mContext);
|
||
}
|
||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||
//松开
|
||
handler.removeCallbacks(mLongPressed);
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setVoicePress(false)
|
||
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
|
||
|
||
if (voiceDialog != null) {
|
||
voiceDialog.dismiss();
|
||
voiceDialog = null;
|
||
}
|
||
|
||
if (voiceUtils != null) {
|
||
voiceUtils.withdraw();
|
||
voiceUtils.setSendMessage(true);
|
||
voiceUtils = null;
|
||
}
|
||
}
|
||
return true;
|
||
});
|
||
mProcessResultUtil = new ProcessResultUtil((FragmentActivity) mContext);
|
||
}
|
||
|
||
private float downY = 0;
|
||
private ProcessResultUtil mProcessResultUtil;
|
||
private VoiceDialog voiceDialog = null;
|
||
private VoiceUtils voiceUtils = null;
|
||
private Runnable mLongPressed = new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
|
||
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||
vibrator.vibrate(100);//震动时间(ms)
|
||
if (voiceDialog == null) {
|
||
voiceDialog = new VoiceDialog();
|
||
}
|
||
voiceDialog.setListener(new VoiceDialog.VoiceListener() {
|
||
@Override
|
||
public void timeout() {
|
||
//松开
|
||
handler.removeCallbacks(mLongPressed);
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setVoicePress(false)
|
||
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
|
||
if (voiceDialog != null) {
|
||
voiceDialog.dismiss();
|
||
voiceDialog = null;
|
||
}
|
||
|
||
if (voiceUtils != null) {
|
||
voiceUtils.withdraw();
|
||
voiceUtils.setSendMessage(true);
|
||
voiceUtils = null;
|
||
}
|
||
}
|
||
});
|
||
voiceDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "VoiceDialog");
|
||
Bus.get().post(new LiveAudienceEvent()
|
||
.setVoicePress(true)
|
||
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
|
||
voiceUtils = new VoiceUtils(mContext).setCallBack(new VoiceUtils.VoiceUtilsCallBack() {
|
||
@Override
|
||
public void timeOut() {
|
||
if (voiceDialog != null) {
|
||
voiceDialog.dismiss();
|
||
voiceUtils.withdraw();
|
||
voiceUtils = null;
|
||
TextHintDialog textHintDialog = new TextHintDialog();
|
||
textHintDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "TextHintDialog");
|
||
}
|
||
|
||
}
|
||
|
||
@Override
|
||
public void changeBuilder(String builder) {
|
||
if (voiceDialog != null)
|
||
voiceDialog.setVoiceChat(builder);
|
||
}
|
||
|
||
@Override
|
||
public void volumeAnimation(boolean isAnimation) {
|
||
if (voiceDialog != null)
|
||
voiceDialog.startAnimation();
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
public Handler handler = new Handler();
|
||
public Runnable runnable;
|
||
|
||
public Handler handler1 = new Handler();
|
||
public Runnable runnable1;
|
||
|
||
|
||
public void removeCallbacks() {
|
||
handler.removeCallbacks(runnable);
|
||
handler.removeCallbacks(runnable1);
|
||
}
|
||
|
||
public void setLiveInfo(String liveUid, String stream, String urls, int isattention) {
|
||
mLiveUid = liveUid;
|
||
mStream = stream;
|
||
url = urls;
|
||
|
||
handler.postDelayed(runnable = new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
if (!liveUid.equals(mLiveUid)) {
|
||
return;
|
||
}
|
||
LiveChatBean lvBean = new LiveChatBean();
|
||
lvBean.setType(-2);
|
||
lvBean.setId(url);
|
||
lvBean.setAttention(isattention != 0);
|
||
LiveRoomViewHolder.insertChat(lvBean, 1);
|
||
Log.i("chatMgs", liveUid + "|" + mLiveUid);
|
||
}
|
||
}, 10000);//3秒后执行Runnable中的run方法
|
||
}
|
||
|
||
|
||
@Override
|
||
public void onClick(View v) {
|
||
if (!canClick()) {
|
||
return;
|
||
}
|
||
super.onClick(v);
|
||
int i = v.getId();
|
||
if (i == R.id.btn_close) {
|
||
close();
|
||
|
||
} else if (i == R.id.btn_share) {
|
||
((LiveAudienceActivity) mContext).light();
|
||
|
||
} else if (i == R.id.btn_red_pack) {
|
||
((LiveActivity) mContext).openRedPackSendWindow();
|
||
|
||
} else if (i == R.id.btn_gift) {
|
||
openGiftWindow();
|
||
|
||
//全屏
|
||
} else if (i == R.id.btn_more) {
|
||
((LiveActivity) mContext).openMoreWindow();
|
||
} else if (i == R.id.btn_zg) {
|
||
openZGListWindow();
|
||
} else if (i == R.id.live_new_people) {
|
||
openNewPeopleDialog();
|
||
} else if (i == R.id.live_privilege) {
|
||
MobclickAgent.onEvent(mContext, "live_room_privilege", "直播间下面打开皇冠按钮");
|
||
openRoleDialog();
|
||
} else if (i == R.id.live_cheat) {
|
||
|
||
} else if (i == R.id.live_play) {
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 打开新人特惠对话框
|
||
*/
|
||
public void openNewPeopleDialog() {
|
||
if (newPeopleUrl == null) {
|
||
getNewPeopleInfo(true);
|
||
return;
|
||
}
|
||
Bundle bundle = new Bundle();
|
||
String url = newPeopleUrl + (newPeopleUrl.contains("?") ? "&" : "?") + "g=Appapi&m=Turntable&a=tricky";
|
||
url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token="
|
||
+ CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid;
|
||
bundle.putString("url", url);
|
||
bundle.putInt("show_type", 0);
|
||
//bundle.putInt("height", DpUtil.dp2px(1));
|
||
LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment();
|
||
liveHDDialogFragment.setArguments(bundle);
|
||
liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");
|
||
}
|
||
|
||
public void getNewPeopleInfo(boolean show) {
|
||
API.get().pdLiveApi(mContext)
|
||
.getNewPeopleInfo()
|
||
.subscribeOn(Schedulers.io())
|
||
.observeOn(AndroidSchedulers.mainThread())
|
||
.subscribe(stringResponseModel -> {
|
||
NewPeopleInfo peopleInfo = stringResponseModel.getData().getInfo();
|
||
if (peopleInfo.getIsShow()) {
|
||
liveNewPeople.setVisibility(View.VISIBLE);
|
||
if (peopleInfo.getLink().startsWith("http")) {
|
||
newPeopleUrl = peopleInfo.getLink() + "?";
|
||
} else {
|
||
newPeopleUrl = CommonAppConfig.HOST + "/" + peopleInfo.getLink();
|
||
}
|
||
setUserPreferentialRedDot(peopleInfo.getShowRed() == 1);
|
||
if (show) {
|
||
openNewPeopleDialog();
|
||
}
|
||
} else {
|
||
liveNewPeople.setVisibility(View.GONE);
|
||
}
|
||
}, Throwable::printStackTrace).isDisposed();
|
||
}
|
||
|
||
/**
|
||
* 观众打开主播的整蛊惑单窗口
|
||
*/
|
||
public void openZGListWindow() {
|
||
String url = CommonAppConfig.HOST + "/index.php?g=Appapi&m=Turntable&a=tricky";
|
||
url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token="
|
||
+ CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid;
|
||
Log.i("tag", url);
|
||
Bundle bundle1 = new Bundle();
|
||
bundle1.putString("url", url);
|
||
LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment();
|
||
liveHDDialogFragment.setArguments(bundle1);
|
||
liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");
|
||
}
|
||
|
||
/**
|
||
* 身份特权
|
||
*/
|
||
public void openRoleDialog() {
|
||
// LiveRoleDialogFragment fragment = new LiveRoleDialogFragment();
|
||
// Bundle bundle = new Bundle();
|
||
// bundle.putBoolean("showRed", mRedPointPrivilege.getVisibility() == View.VISIBLE);
|
||
// fragment.setArguments(bundle);
|
||
// fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveRoleDialogFragment");
|
||
new XPopup.Builder(mContext)
|
||
.enableDrag(false)
|
||
.asCustom(new LiveNewRolePopup(mContext, mRedPointPrivilege.getVisibility() == View.VISIBLE))
|
||
.show();
|
||
}
|
||
|
||
|
||
//消息中心
|
||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||
public void onMessageIMEvent(MessageIMEvent event) {
|
||
//判断消息中心红点是否已经展示,如果已经展示并且未读消息大于0则不再执行之后的逻辑
|
||
int number = event.getMessage();
|
||
if (v_msg_redpoint.getVisibility() == View.VISIBLE && number > 0 || SpUtil.getInstance().getBooleanValue("private_chat_message_switch"))
|
||
return;
|
||
if (number > 0) {
|
||
v_msg_redpoint.setVisibility(View.VISIBLE);
|
||
} else {
|
||
v_msg_redpoint.setVisibility(View.GONE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 显示/隐藏新人特惠礼物红点
|
||
*
|
||
* @param show true显示 false隐藏
|
||
*/
|
||
private void setUserPreferentialRedDot(boolean show) {
|
||
mNewPeopleRedDot.setVisibility(show ? View.VISIBLE : View.GONE);
|
||
}
|
||
|
||
/**
|
||
* 退出直播间
|
||
*/
|
||
private void close() {
|
||
handler.removeCallbacks(runnable);
|
||
handler1.removeCallbacks(runnable1);
|
||
((LiveAudienceActivity) mContext).onBackPressed();
|
||
}
|
||
|
||
|
||
/**
|
||
* 打开礼物窗口
|
||
*/
|
||
private void openGiftWindow() {
|
||
((LiveAudienceActivity) mContext).openGiftWindow();
|
||
}
|
||
|
||
/**
|
||
* 打开分享窗口
|
||
*/
|
||
private void openShareWindow() {
|
||
((LiveActivity) mContext).openShareWindow();
|
||
}
|
||
|
||
@Override
|
||
public void release() {
|
||
super.release();
|
||
EventBus.getDefault().unregister(this);
|
||
removeCallbacks();
|
||
}
|
||
|
||
/**
|
||
* 绘制全站喇叭的样式
|
||
*
|
||
* @return
|
||
*/
|
||
@SuppressLint("SetTextI18n")
|
||
private Bitmap canvasBitmap(int icon, String name, String text) {
|
||
//计算设备分辨率
|
||
WindowManager manager = ((Activity) mContext).getWindowManager();
|
||
DisplayMetrics metrics = new DisplayMetrics();
|
||
manager.getDefaultDisplay().getMetrics(metrics);
|
||
int width = metrics.widthPixels;
|
||
int height = metrics.heightPixels;
|
||
View view = LayoutInflater.from(mContext).inflate(R.layout.view_whole_station_horn_layout, null, false);
|
||
ViewFlipper viewFlipper = view.findViewById(R.id.viewflipper_banner);
|
||
//展示内容子布局
|
||
View childrenView = LayoutInflater.from(mContext).inflate(R.layout.view_whole_station_horn, null, false);
|
||
ImageView iconImg = childrenView.findViewById(R.id.icon_img);
|
||
TextView userName = childrenView.findViewById(R.id.rc_user_name);
|
||
TextView userText = childrenView.findViewById(R.id.rc_user_text);
|
||
userName.setText(name);
|
||
userText.setText(" : " + text);
|
||
ImgLoader.display2(mContext, icon, iconImg);
|
||
viewFlipper.addView(childrenView);
|
||
//测量使得view指定大小
|
||
int measureWidth = View.MeasureSpec.makeMeasureSpec(width / 3 * 2 - 30, View.MeasureSpec.AT_MOST);
|
||
int measureHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST);
|
||
view.measure(measureWidth, measureHeight);
|
||
//调用layout方法布局后,可以得到view的尺寸
|
||
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
|
||
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
|
||
Canvas bitmapCanvas = new Canvas(bitmap);
|
||
bitmapCanvas.drawColor(Color.TRANSPARENT);
|
||
view.draw(bitmapCanvas);
|
||
return bitmap;
|
||
}
|
||
|
||
|
||
}
|