Commit 9eefff8e by 霍志良

Merge remote-tracking branch 'origin/dev_mdt_av' into dev_mdt_av

parents b353a587 cb8081b3
......@@ -74,7 +74,7 @@
<activity
android:name=".home.HomeActivity"
android:launchMode="singleTask"
android:noHistory="true"></activity>
android:noHistory="true"/>
<activity
......
......@@ -33,7 +33,7 @@ ext {
//-------------- 功能组件 --------------
//mdt 组件
"ydl-tuicore" : "0.0.12",
"ydl-tuicore" : "0.0.15",
// "m-tuicore-ydl" : "0.0.10",
//第一步
"ydl-platform" : "0.0.40.95",
......
......@@ -19,11 +19,15 @@
<activity
android:name=".calling.videocall.VideoCallingActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/VideoCallActivityTheme"
/>
<!--接听界面-->
<activity
android:name=".calling.videocall.YDLInvitionActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/VideoCallActivityTheme"
/>
</application>
</manifest>
\ No newline at end of file
package com.tencent.liteav.login
package com.tencent.qcloud.tuicore.calling.login
import android.content.Context
import android.util.Log
......
......@@ -111,7 +111,7 @@ public class TRTCCalling {
/**
* 当前是否在TRTC房间中
*/
private boolean mIsInRoom = false;
public boolean mIsInRoom = false;
private long mEnterRoomTime = 0;
/**
* 当前邀请列表
......@@ -318,8 +318,7 @@ public class TRTCCalling {
*/
private V2TIMSignalingListener mTIMSignallingListener = new V2TIMSignalingListener() {
@Override
public void onReceiveNewInvitation(String inviteID, String inviter, String groupID,
List<String> inviteeList, String data) {
public void onReceiveNewInvitation(String inviteID, String inviter, String groupID, List<String> inviteeList, String data) {
TRTCLogger.e(TAG, "onReceiveNewInvitation inviteID:" + inviteID + ", inviter:" + inviter
+ ", groupID:" + groupID + ", inviteeList:" + inviteeList + " data:" + data);
......@@ -332,11 +331,14 @@ public class TRTCCalling {
intent.putExtra(Constant.USER_ID, userModel.userId);
intent.putExtra(Constant.INVITE_ID, inviter);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
// handleRecvCallModel(inviteID, inviter, groupID, inviteeList, data);
if (!mIsInRoom){
// 响铃
startRing();
}
}
@Override
......@@ -926,6 +928,7 @@ public class TRTCCalling {
@Override
public void onExitRoom(int reason) {
TRTCLogger.d(TAG, "onExitRoom reason:" + reason);
mIsInRoom = false;
}
@Override
......@@ -1038,7 +1041,6 @@ public class TRTCCalling {
TRTCLogger.d(TAG, "stopCall");
mInviteMap.clear();
isOnCalling = false;
mIsInRoom = false;
mIsBeingCalled = true;
mEnterRoomTime = 0;
mCurCallID = "";
......@@ -1274,6 +1276,7 @@ public class TRTCCalling {
* trtc 退房
*/
private void exitRoom() {
mIsInRoom = false;
mTRTCCloud.stopLocalPreview();
mTRTCCloud.stopLocalAudio();
mTRTCCloud.exitRoom();
......@@ -2083,7 +2086,8 @@ public class TRTCCalling {
}
}
private void stopRing() {
public void stopRing() {
stopMusic();
}
......
package com.tencent.qcloud.tuicore.calling.videocall;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import com.blankj.utilcode.util.ToastUtils;
import com.tencent.liteav.TXLiteAVCode;
import com.tencent.liteav.device.TXDeviceManager;
import com.tencent.qcloud.tuicore.R;
import com.tencent.qcloud.tuicore.calling.basic.UserModel;
import com.tencent.qcloud.tuicore.calling.basic.UserModelManager;
import com.tencent.qcloud.tuicore.calling.trtccalling.model.TRTCCalling;
import com.tencent.qcloud.tuicore.calling.trtccalling.model.impl.base.CallingInfoManager;
import com.tencent.qcloud.tuicore.util.StatusBarUtil;
import com.tencent.rtmp.ui.TXCloudVideoView;
import com.tencent.trtc.TRTCCloud;
import com.tencent.trtc.TRTCCloudDef;
......@@ -26,7 +36,7 @@ import java.util.List;
/**
* TRTC视频通话的主页面
*
* <p>
* 包含如下简单功能:
* - 进入视频通话房间{@link VideoCallingActivity#enterRoom()}
* - 退出视频通话房间{@link VideoCallingActivity#exitRoom()}
......@@ -34,7 +44,7 @@ import java.util.List;
* - 打开/关闭摄像头{@link VideoCallingActivity#muteVideo()}
* - 打开/关闭麦克风{@link VideoCallingActivity#muteAudio()}
* - 显示房间内其他用户的视频画面(当前示例最多可显示6个其他用户的视频画面){@link TRTCCloudImplListener#refreshRemoteVideoViews()}
*
* <p>
* - 详见接入文档{https://cloud.tencent.com/document/product/647/42045}
*/
public class VideoCallingActivity extends TRTCBaseActivity implements View.OnClickListener {
......@@ -50,23 +60,36 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
private LinearLayout btnAudio;
private ImageView ivVideo;
private ImageView ivAudio;
private ImageView ivNetworkMe;
private ImageView ivAudioMe;
private TextView tvMe;
private LinearLayout llMe;
private TRTCCloud mTRTCCloud;
private TXDeviceManager mTXDeviceManager;
private boolean mIsFrontCamera = true;
private List<String> mRemoteUidList;
private List<TXCloudVideoView> mRemoteViewList;
// 远端用户的昵称、网络状态、麦克风状态控件
private List<LinearLayout> mLlUserViewList;
private List<ImageView> mIvNetWorkViewList;
private List<ImageView> mIvAudioViewList;
private List<LinearLayout> mLlUserViewList;
private List<TextView> mTvNameViewList;
private TextView tvAudio;
private TextView tvVideo;
private int mUserCount = 0;
private String mRoomId;
private String mUserId;
private boolean mAudioRouteFlag = true;
private UserModel mUserModel;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StatusBarUtil.StatusBarLightMode(this);
handleIntent();
setContentView(R.layout.videocall_activity_calling);
if (checkPermission()) {
......@@ -91,14 +114,20 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
private void initView() {
mTextTitle = findViewById(R.id.tv_room_number);
mImageBack = findViewById(R.id.iv_back);
mTXCVVLocalPreviewView = findViewById(R.id.trtc_view_main);
mTXCVVLocalPreviewView = findViewById(R.id.trtc_view_me);
btnVideo = findViewById(R.id.btn_video);
btnAudio = findViewById(R.id.btn_audio);
btnVideo.setSelected(true);
btnAudio.setSelected(false);
ivVideo = findViewById(R.id.iv_video);
tvVideo = findViewById(R.id.tv_video);
ivAudio = findViewById(R.id.iv_audio);
tvAudio = findViewById(R.id.tv_audio);
tvLeave = findViewById(R.id.tv_leave);
ivNetworkMe = findViewById(R.id.iv_network_me);
ivAudioMe = findViewById(R.id.iv_audio_me);
tvMe = findViewById(R.id.tv_me);
llMe = findViewById(R.id.ll_me);
if (!TextUtils.isEmpty(mRoomId)) {
......@@ -111,9 +140,10 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
mRemoteUidList = new ArrayList<>();
mRemoteViewList = new ArrayList<>();
mLlUserViewList = new ArrayList<>();
mIvNetWorkViewList = new ArrayList<>();
mIvAudioViewList = new ArrayList<>();
mLlUserViewList = new ArrayList<>();
mTvNameViewList = new ArrayList<>();
mRemoteViewList.add(findViewById(R.id.trtc_view_1));
mRemoteViewList.add(findViewById(R.id.trtc_view_2));
mRemoteViewList.add(findViewById(R.id.trtc_view_3));
......@@ -138,19 +168,25 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
mLlUserViewList.add(findViewById(R.id.ll_user_4));
mLlUserViewList.add(findViewById(R.id.ll_user_5));
mLlUserViewList.add(findViewById(R.id.ll_user_6));
mTvNameViewList.add(findViewById(R.id.tv_name_1));
mTvNameViewList.add(findViewById(R.id.tv_name_2));
mTvNameViewList.add(findViewById(R.id.tv_name_3));
mTvNameViewList.add(findViewById(R.id.tv_name_4));
mTvNameViewList.add(findViewById(R.id.tv_name_5));
mTvNameViewList.add(findViewById(R.id.tv_name_5));
}
private void enterRoom() {
mTRTCCloud = TRTCCloud.sharedInstance(getApplicationContext());
mTRTCCloud.setListener(new TRTCCloudImplListener(VideoCallingActivity.this));
mTXDeviceManager = mTRTCCloud.getDeviceManager();
UserModel userModel = UserModelManager.getInstance().getUserModel();
mUserModel = UserModelManager.getInstance().getUserModel();
TRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();
trtcParams.sdkAppId = userModel.appId;
trtcParams.sdkAppId = mUserModel.appId;
trtcParams.userId = mUserId;
trtcParams.roomId = Integer.parseInt(mRoomId);
Log.d("userSig",userModel.userSig);
trtcParams.userSig = userModel.userSig;
Log.d("userSig", mUserModel.userSig);
trtcParams.userSig = mUserModel.userSig;
mTRTCCloud.startLocalPreview(mIsFrontCamera, mTXCVVLocalPreviewView);
mTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH);
......@@ -171,6 +207,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
}
private void exitRoom() {
TRTCCalling.sharedInstance(this).mIsInRoom = false;
if (mTRTCCloud != null) {
mTRTCCloud.stopLocalAudio();
mTRTCCloud.stopLocalPreview();
......@@ -196,12 +233,12 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.iv_back|| id == R.id.tv_leave) {
if (id == R.id.iv_back || id == R.id.tv_leave) {
exitRoom();
finish();
} else if (id == R.id.btn_audio){
} else if (id == R.id.btn_audio) {
muteAudio();
} else if (id == R.id.btn_video){
} else if (id == R.id.btn_video) {
muteVideo();
}
}
......@@ -215,9 +252,13 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
if (isSelected) {
mTRTCCloud.stopLocalPreview();
ivVideo.setImageResource(R.drawable.trtccalling_ic_me_video_close);
tvVideo.setText("摄像头已关闭");
llMe.setVisibility(View.GONE);
} else {
mTRTCCloud.startLocalPreview(mIsFrontCamera, mTXCVVLocalPreviewView);
ivVideo.setImageResource(R.drawable.trtccalling_ic_me_video_open);
tvVideo.setText("摄像头已开启");
llMe.setVisibility(View.VISIBLE);
}
btnVideo.setSelected(!isSelected);
}
......@@ -230,9 +271,13 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
if (!isSelected) {
mTRTCCloud.muteLocalAudio(true);
ivAudio.setImageResource(R.drawable.trtccalling_ic_me_audio_close);
tvAudio.setText("麦克风已关闭");
ivAudioMe.setImageResource(R.drawable.trtccalling_ic_other_audio_close);
} else {
mTRTCCloud.muteLocalAudio(false);
ivAudio.setImageResource(R.drawable.trtccalling_ic_me_audio_open);
tvAudio.setText("麦克风已开启");
ivAudioMe.setImageResource(R.drawable.trtccalling_ic_other_audio_open);
}
btnAudio.setSelected(!isSelected);
}
......@@ -243,9 +288,9 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
private void switchCamera() {
mIsFrontCamera = !mIsFrontCamera;
mTXDeviceManager.switchCamera(mIsFrontCamera);
if(mIsFrontCamera){
if (mIsFrontCamera) {
// mButtonSwitchCamera.setText( "使用后置摄像头");
}else{
} else {
// mButtonSwitchCamera.setText("使用前置摄像头");
}
}
......@@ -254,11 +299,11 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
* 听筒和扬声器切换
*/
private void audioRoute() {
if(mAudioRouteFlag){
if (mAudioRouteFlag) {
mAudioRouteFlag = false;
mTXDeviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteEarpiece);
// mButtonAudioRoute.setText("使用扬声器");
}else{
} else {
mAudioRouteFlag = true;
mTXDeviceManager.setAudioRoute(TXDeviceManager.TXAudioRoute.TXAudioRouteSpeakerphone);
// mButtonAudioRoute.setText("使用听筒");
......@@ -280,42 +325,82 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
}
/**
* 自己进入房间
*
* @param result
*/
@Override
public void onEnterRoom(long result) {
super.onEnterRoom(result);
TRTCCalling.sharedInstance(VideoCallingActivity.this).mIsInRoom = true;
llMe.setVisibility(View.VISIBLE);
if (mUserModel != null) {
tvMe.setText(mUserModel.userName);
}
}
/**
* 离开房间
* */
*/
@Override
public void onExitRoom(int reason) {
super.onExitRoom(reason);
TRTCCalling.sharedInstance(VideoCallingActivity.this).mIsInRoom = false;
finish();
}
/**
* 远端用户进入房间
*
* @param userId
*/
@Override
public void onRemoteUserEnterRoom(String userId) {
super.onRemoteUserEnterRoom(userId);
refreshRemoteUserName();
}
/**
* 网络质量的实时统计回调
*
* @param localQuality
* @param remoteQuality
*/
@Override
public void onNetworkQuality(TRTCCloudDef.TRTCQuality localQuality, ArrayList<TRTCCloudDef.TRTCQuality> remoteQuality) {
Log.e(TAG,"网络质量的实时统计回调 userId:"+localQuality.userId+"uid:"+localQuality.quality+remoteQuality.get(0).userId+"quality:"+localQuality.quality+remoteQuality.get(0).quality);
// if (remoteQuality.size()>0){
// refreshNetWorkStatus(remoteQuality);
// }
Log.e(TAG, "网络质量的实时统计回调 userId:" + localQuality.userId + "uid:" + localQuality.quality + "quality:" + localQuality.quality);
Log.e(TAG, "远端用户数量:" + remoteQuality.size());
if (localQuality.quality == TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_0) {
ivNetworkMe.setImageResource(R.drawable.trtccalling_ic_network_bad);
} else if (localQuality.quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_3) {
ivNetworkMe.setImageResource(R.drawable.trtccalling_ic_network_poor);
} else if (localQuality.quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_8) {
ivNetworkMe.setImageResource(R.drawable.trtccalling_ic_network_good);
} else if (localQuality.quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_11) {
ivNetworkMe.setImageResource(R.drawable.trtccalling_ic_network_excellent);
}
if (remoteQuality.size() > 0) {
refreshRemoteUserNetWorkStatus(remoteQuality);
}
}
/**
* 音频麦克风开启或关闭回调
*
* @param userId
* @param available
*/
@Override
public void onUserAudioAvailable(String userId, boolean available) {
Log.e(TAG, "onUserAudioAvailable userId " + userId + ", mUserCount " + mUserCount + ",available " + available);
if (!TextUtils.isEmpty(userId)){
refreshAudioStatus(userId, available);
if (!TextUtils.isEmpty(userId) && mRemoteUidList.size() > 0) {
refreshRemoteUserAudioStatus(userId, available);
}
}
/**
* 视频开启或关闭回调
*
* @param userId
* @param available
*/
......@@ -336,6 +421,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
mRemoteUidList.remove(index);
}
refreshRemoteVideoViews();
refreshRemoteUserName();
}
......@@ -344,39 +430,11 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
if (i < mRemoteUidList.size()) {
String remoteUid = mRemoteUidList.get(i);
mRemoteViewList.get(i).setVisibility(View.VISIBLE);
mTRTCCloud.startRemoteView(remoteUid, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL,mRemoteViewList.get(i));
mLlUserViewList.get(i).setVisibility(View.VISIBLE);
mTRTCCloud.startRemoteView(remoteUid, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, mRemoteViewList.get(i));
} else {
mRemoteViewList.get(i).setVisibility(View.GONE);
}
}
}
private void refreshAudioStatus(String userId,boolean available){
if (mRemoteUidList.size()>0){
for (int i = 0; i < mIvAudioViewList.size(); i++) {
if (userId.equals(mRemoteUidList.get(i))){
if (available){
mIvAudioViewList.get(i).setImageResource(R.drawable.trtccalling_ic_other_audio_open);
}else {
mIvAudioViewList.get(i).setImageResource(R.drawable.trtccalling_ic_other_audio_close);
}
return;
}
}
}
}
private void refreshNetWorkStatus(ArrayList<TRTCCloudDef.TRTCQuality> remoteQuality){
for (int i = 0; i < mIvNetWorkViewList.size(); i++) {
int quality = remoteQuality.get(i).quality;
if (quality==TRTCCloudDef.TRTC_QUALITY_Excellent){
mIvNetWorkViewList.get(i).setImageResource(R.drawable.trtccalling_ic_network_excellent);
}else if (quality==TRTCCloudDef.TRTC_QUALITY_Good){
mIvNetWorkViewList.get(i).setImageResource(R.drawable.trtccalling_ic_network_good);
}else if (quality==TRTCCloudDef.TRTC_QUALITY_Poor){
mIvNetWorkViewList.get(i).setImageResource(R.drawable.trtccalling_ic_network_poor);
}else if (quality==TRTCCloudDef.TRTC_QUALITY_Bad){
mIvNetWorkViewList.get(i).setImageResource(R.drawable.trtccalling_ic_network_bad);
mLlUserViewList.get(i).setVisibility(View.GONE);
}
}
}
......@@ -386,7 +444,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
Log.d(TAG, "sdk callback onError");
VideoCallingActivity activity = mContext.get();
if (activity != null) {
Toast.makeText(activity, "onError: " + errMsg + "[" + errCode+ "]" , Toast.LENGTH_SHORT).show();
Toast.makeText(activity, "onError: " + errMsg + "[" + errCode + "]", Toast.LENGTH_SHORT).show();
if (errCode == TXLiteAVCode.ERR_ROOM_ENTER_FAIL) {
activity.exitRoom();
}
......@@ -395,4 +453,71 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
}
/**
* 更新远端用户的麦开启或者关闭
*
* @param userId
* @param available
*/
private void refreshRemoteUserAudioStatus(String userId, boolean available) {
for (int i = 0; i < mRemoteUidList.size(); i++) {
if (userId.equals(mRemoteUidList.get(i))) {
if (available) {
mIvAudioViewList.get(i).setImageResource(R.drawable.trtccalling_ic_other_audio_open);
} else {
mIvAudioViewList.get(i).setImageResource(R.drawable.trtccalling_ic_other_audio_close);
}
return;
}
}
}
/**
* 更新远端用户的网络状态
*
* @param remoteQuality
*/
private void refreshRemoteUserNetWorkStatus(ArrayList<TRTCCloudDef.TRTCQuality> remoteQuality) {
for (int i = 0; i < remoteQuality.size(); i++) {
if (mLlUserViewList.get(i).getVisibility() == View.GONE) {
mLlUserViewList.get(i).setVisibility(View.VISIBLE);
}
ImageView ivNetWorkView = mIvNetWorkViewList.get(i);
int quality = remoteQuality.get(i).quality;
if (quality == TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_0) {
ivNetWorkView.setImageResource(R.drawable.trtccalling_ic_network_excellent);
} else if (quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_3) {
ivNetWorkView.setImageResource(R.drawable.trtccalling_ic_network_good);
} else if (quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_8) {
ivNetWorkView.setImageResource(R.drawable.trtccalling_ic_network_poor);
} else if (quality <= TRTCCloudDef.TRTC_VOICE_CHANGER_TYPE_11) {
ivNetWorkView.setImageResource(R.drawable.trtccalling_ic_network_bad);
}
}
}
/**
* 更新远端用户的昵称
*/
private void refreshRemoteUserName() {
for (int i = 0; i < mRemoteUidList.size(); i++) {
TextView tvName = mTvNameViewList.get(i);
CallingInfoManager.getInstance().getUserInfoByUserId(mRemoteUidList.get(i), new CallingInfoManager.UserCallback() {
@Override
public void onSuccess(UserModel model) {
tvName.setText(model.userName);
}
@Override
public void onFailed(int code, String msg) {
if (code == 206) {
ToastUtils.showLong("用户不存在");
} else {
ToastUtils.showLong(getString(R.string.trtccalling_toast_search_fail, msg));
}
}
});
}
}
}
......@@ -14,6 +14,7 @@ import com.tencent.qcloud.tuicore.calling.basic.UserModel;
import com.tencent.qcloud.tuicore.calling.trtccalling.model.TRTCCalling;
import com.tencent.qcloud.tuicore.calling.trtccalling.model.impl.base.CallingInfoManager;
import com.tencent.qcloud.tuicore.calling.trtccalling.ui.common.RoundCornerImageView;
import com.tencent.qcloud.tuicore.util.StatusBarUtil;
/**
* @Author: 刘鹏
......@@ -50,6 +51,7 @@ public class YDLInvitionActivity extends TRTCBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StatusBarUtil.transparencyBar(this);
handleIntent();
setContentView(R.layout.video_invition_activity);
initView();
......@@ -98,6 +100,8 @@ public class YDLInvitionActivity extends TRTCBaseActivity {
mIvVideoInviteRefuse = findViewById(R.id.iv_video_invite_refuse);
//接听
mIvVideoInviteAccept.setOnClickListener(v -> {
// 接听后停止响铃
TRTCCalling.sharedInstance(YDLInvitionActivity.this).stopRing();
Intent intent = new Intent(YDLInvitionActivity.this, VideoCallingActivity.class);
intent.putExtra(Constant.ROOM_ID, mRoomId);
intent.putExtra(Constant.USER_ID, mUserId);
......
package com.tencent.qcloud.tuicore.util;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Created by Ykai on 2022/4/24.
*/
public class StatusBarUtil {
/**
* 修改状态栏为全透明
*
* @param activity
*/
@SuppressLint("ObsoleteSdkInt")
@TargetApi(19)
public static void transparencyBar(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = activity.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
/**
* 状态栏亮色模式,设置状态栏黑色文字、图标,
* <p>
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
*
* @param activity
* @return 1:MIUUI 2:Flyme 3:android6.0
*/
public static int StatusBarLightMode(Activity activity) {
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (MIUISetStatusBarLightMode(activity, true)) {
//小米
result = 1;
} else if (FlymeSetStatusBarLightMode(activity.getWindow(), true)) {
//魅族
result = 2;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//6.0以上
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
result = 3;
}
}
return result;
}
/**
* 设置状态栏图标为深色和魅族特定的文字风格
* <p>
* 可以用来判断是否为Flyme用户
*
* @param window 需要设置的窗口
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
boolean result = false;
if (window != null) {
try {
WindowManager.LayoutParams lp = window.getAttributes();
Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
darkFlag.setAccessible(true);
meizuFlags.setAccessible(true);
int bit = darkFlag.getInt(null);
int value = meizuFlags.getInt(lp);
if (dark) {
value |= bit;
} else {
value &= ~bit;
}
meizuFlags.setInt(lp, value);
window.setAttributes(lp);
result = true;
} catch (Exception e) {
}
}
return result;
}
/**
* 需要MIUIV6以上
*
* @param activity
* @param dark 是否把状态栏文字及图标颜色设置为深色
* @return boolean 成功执行返回true
*/
public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) {
boolean result = false;
Window window = activity.getWindow();
if (window != null) {
Class clazz = window.getClass();
try {
int darkModeFlag = 0;
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
darkModeFlag = field.getInt(layoutParams);
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
if (dark) {
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
} else {
extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
}
result = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
if (dark) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
} catch (Exception e) {
}
}
return result;
}
}
......@@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#f6f7f9">
<LinearLayout
......@@ -18,7 +19,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:background="@drawable/common_ic_back" />
android:background="@drawable/ic_back_video" />
<TextView
android:id="@+id/tv_room_number"
......@@ -49,7 +50,7 @@
android:id="@+id/trtc_view_1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/trtc_view_main"
app:layout_constraintBottom_toTopOf="@id/trtc_view_me"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/trtc_view_2"
......@@ -158,7 +159,7 @@
</LinearLayout>
<com.tencent.rtmp.ui.TXCloudVideoView
android:id="@+id/trtc_view_main"
android:id="@+id/trtc_view_me"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/trtc_view_5"
......@@ -168,6 +169,49 @@
app:layout_constraintTop_toBottomOf="@id/trtc_view_1"
app:layout_constraintVertical_weight="1" />
<LinearLayout
android:id="@+id/ll_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="@id/trtc_view_me"
app:layout_constraintBottom_toBottomOf="@id/trtc_view_me"
android:layout_marginStart="4dp"
android:layout_marginBottom="4dp"
android:background="@drawable/trtccalling_shape_white_r_10"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:gravity="center_vertical"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:visibility="gone"
>
<TextView
android:id="@+id/tv_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_2D2F33"
android:textSize="12sp"
/>
<ImageView
android:id="@+id/iv_network_me"
android:layout_width="17dp"
android:layout_height="10dp"
android:src="@drawable/trtccalling_ic_network_excellent"
android:layout_marginStart="8dp"
/>
<ImageView
android:id="@+id/iv_audio_me"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="8dp"
android:src="@drawable/trtccalling_ic_other_audio_open" />
</LinearLayout>
<com.tencent.rtmp.ui.TXCloudVideoView
android:id="@+id/trtc_view_3"
......@@ -175,11 +219,11 @@
android:layout_height="0dp"
android:layout_below="@id/trtc_view_2"
android:layout_alignParentRight="true"
app:layout_constraintBottom_toBottomOf="@id/trtc_view_main"
app:layout_constraintBottom_toBottomOf="@id/trtc_view_me"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toRightOf="@id/trtc_view_main"
app:layout_constraintLeft_toRightOf="@id/trtc_view_me"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/trtc_view_main"
app:layout_constraintTop_toTopOf="@id/trtc_view_me"
app:layout_constraintVertical_weight="1" />
<LinearLayout
......@@ -292,8 +336,8 @@
app:layout_constraintBottom_toTopOf="@id/ll_bottom"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="@id/trtc_view_main"
app:layout_constraintTop_toBottomOf="@id/trtc_view_main"
app:layout_constraintRight_toRightOf="@id/trtc_view_me"
app:layout_constraintTop_toBottomOf="@id/trtc_view_me"
app:layout_constraintVertical_weight="1" />
<LinearLayout
......@@ -414,15 +458,16 @@
<ImageView
android:id="@+id/iv_audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/trtccalling_ic_me_audio_open" />
<TextView
android:id="@+id/tv_audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="麦克风"
android:text="麦克风已开启"
android:textColor="@color/color_8595a9"
android:textSize="14sp" />
</LinearLayout>
......@@ -437,15 +482,16 @@
<ImageView
android:id="@+id/iv_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/trtccalling_ic_me_video_open" />
<TextView
android:id="@+id/tv_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="摄像头"
android:text="摄像头已开启"
android:textColor="@color/color_8595a9"
android:textSize="14sp" />
</LinearLayout>
......
......@@ -18,4 +18,13 @@
<item name="android:windowBackground">@color/trtccalling_color_countrycode_bg_dialog</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
<style name="VideoCallActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/white</item>
<!--<item name="android:windowIsTranslucent">true</item>-->
<!--<item name="android:windowNoTitle">true</item>-->
</style>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment