huangxinbao

modify callback framenwork for observer replace interface callback

正在显示 45 个修改的文件 包含 2913 行增加571 行删除
... ... @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.mang.xdy.demo"
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 22
versionCode 1
versionName "1.0"
... ... @@ -42,4 +42,11 @@ dependencies {
compile project(':xdy')
compile 'com.rockerhieu.emojicon:library:1.3.1'
compile 'org.kymjs.kjframe:kjframe:2.6'
compile 'io.reactivex:rxjava:1.0.9'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'me.yokeyword:fragmentation:0.10.3'
}
... ...
... ... @@ -41,9 +41,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.VideoPlayActivity" />
<activity android:name=".activity.VideoPublisherActivity"></activity>
<activity android:name=".activity.AudioPublisherActivity"/>
<activity android:name=".activity.VideoPlayActivity"
android:screenOrientation="portrait"
>
</activity>
<activity android:name=".activity.VideoPublisherActivity"
android:screenOrientation="portrait"></activity>
<activity android:name=".activity.AudioPublisherActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
\ No newline at end of file
... ...
... ... @@ -114,7 +114,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
break;
case 7:
//停止播放
xdySdk.onPlayStop();
// xdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
... ...
package com.mang.xdy.demo.activity;
;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.Gravity;
... ... @@ -18,18 +21,25 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.google.gson.Gson;
import com.google.gson.JsonNull;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.ErrorEntity;
import com.mang.xdy.demo.bean.GetDocImageEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.ResponseEntity;
import com.mang.xdy.demo.bean.VideoOrAudioStopEntity;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
... ... @@ -37,158 +47,77 @@ import com.mang.xdy.utils.XdyStringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
public class VideoPlayActivity extends AppCompatActivity {
import static com.mang.xdy.demo.application.XdyApplicaiton.getActivity;
public class VideoPlayActivity extends AppCompatActivity implements ObserverListener{
private final static String TAG = "VideoPlayActivity";
@BindView(R.id.img_playVideo_novideo)
ImageView img_playVideo_novideo;
private String username="";
private String userpwd="";
private PersonDialog personDialog;
private SimpleFragmentPagerAdapter pagerAdapter;
private ViewPager viewPager;
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
private String initClass = "";
private XdySdk xdySdk;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case -2:
//加入课堂输入用户名,密码
joinClass("", (Boolean) msg.obj);
break;
case -1:
//退出
xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 1:
//播放视频
String playvideo= (String) msg.obj;
ToastUtil.showToastshort(playvideo,VideoPlayActivity.this);
playVideo(playvideo);
XdyLogUtil.e("播放视频URL",""+playvideo);
XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
break;
case 2:
//播放音频
playAudio((String) msg.obj);
break;
case 3:
getDoc((String) msg.obj);
break;
case 4:
break;
case 5:
break;
case 6:
//图片
break;
case 7:
//停止播放
xdySdk.onPlayStop();
img_playVideo_novideo.setVisibility(View.VISIBLE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
break;
}
}
};
private LoginDialog mLoginDialog;
private ProgressDialog mProgressDialog;
private Handler mHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
ResponseEntity responseEntity= (ResponseEntity) msg.obj;
switch (responseEntity.getType()){
case Constants.ERROR_CODE:
handError(responseEntity.getType(),responseEntity.getParam());
break;
case Constants.CLASS_INIT_SUCCESS:
String login=responseEntity.getParam();
parseJoinClass(login,true);
ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
break;
case Constants.CLASS_JOIN_SUCCESS:
//加入课堂成功
progressDialogDismiss();
UIUtils.closeDialog(mLoginDialog);
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
String userJson=responseEntity.getParam();
SPUtil.putString(VideoPlayActivity.this, Constants.CLASS_JOIN_SUCCESS,userJson);
break;
case Constants.VIDEO_PLAY:
//播放视频
playVideo(responseEntity.getParam());
break;
case Constants.AUDIO_PLAY:
//播放音频
playAudio(responseEntity.getParam());
break;
case Constants.VIDEO_STOP:
//停止播放
case Constants.AUDIO_STOP:
//停止播放
stopPlay(responseEntity.getParam());
break;
case "video_success":
img_playVideo_novideo.setVisibility(View.GONE);
break;
}
}
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_play);
ButterKnife.bind(this);
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
progressDialogShow();
setTablayout();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
Message message = Message.obtain();
switch (type) {
case "class_init_success":
ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
message.obj = response;
message.what = 0;
handler.sendMessage(message);
break;
case "video_play":
//播放视频
XdyLogUtil.e("当前视频", "执行了" + response);
XdyLogUtil.e(TAG,"当前线程 listerne:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
Message message1=Message.obtain();
message1.obj = response;
message1.what = 1;
handler.sendMessageDelayed(message1,500);
break;
case "audio_play":
//播放音频
Message message2=Message.obtain();
message2.obj = response;
message2.what = 2;
handler.sendMessageDelayed(message2,500);
break;
case "class_join_success":
//加入课堂成功
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
String userJson=response;
SPUtil.putString(VideoPlayActivity.this, Constants.CLASS_JOIN_SUCCESS,userJson);
break;
case "class_delete_roster":
// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
//人员离开
break;
case "chat_receive_message":
//监听聊天信息
message.obj = response;
message.what = 5;
handler.sendMessage(message);
break;
case "document_update":
//监听文档信息
Message message3=Message.obtain();
message3.obj = response;
message3.what = 3;
handler.sendMessage(message3);
ToastUtil.showToastshort("文档更新" + response, VideoPlayActivity.this);
break;
case "whiteboard_annotation_update":
ToastUtil.showToastshort("白板信息更新" + response, VideoPlayActivity.this);
break;
case "getDocImageFullPath":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
//推流直播
Message message6=Message.obtain();
message6.obj = response;
message6.what = 6;
handler.sendMessage(message6);
ToastUtil.showToast("文档更新的" + response, VideoPlayActivity.this);
break;
case "video_stop":
handler.sendEmptyMessage(7);
break;
case "audio_stop":
break;
default:{
XdyLogUtil.e("xuedianyunlog",response);
}
}
}
});
}
public void init() {
... ... @@ -208,15 +137,33 @@ public class VideoPlayActivity extends AppCompatActivity {
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null)
if(initClassSuccessEntity.isPasswordRequired()){
personDialog=new PersonDialog(this,true);
}else{
personDialog=new PersonDialog(this,false);
userpwd="123321";
}
personDialog.show();
if(initClassSuccessEntity!=null) {
if (initClassSuccessEntity.isPasswordRequired()) {
isShowPwd=true;
} else {
isShowPwd=false;
userpwd = "123321";
}
}
if (mLoginDialog == null) {
mLoginDialog = new LoginDialog(this, isShowPwd, null);
mLoginDialog.show();
progressDialogDismiss();
mLoginDialog.setCanceledOnTouchOutside(false);
final boolean finalIsShowPwd = isShowPwd;
mLoginDialog.setBtnClick(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] nameAndPwd = mLoginDialog.getNameAndPwd();
joinClass(nameAndPwd[0], nameAndPwd[1], finalIsShowPwd);
progressDialogShow();
}
});
}else if (mLoginDialog != null) {
UIUtils.closeDialog(mLoginDialog);
}
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
JoinClass joinClass=new JoinClass();
... ... @@ -234,13 +181,31 @@ public class VideoPlayActivity extends AppCompatActivity {
xdySdk.api("joinClass", jsonParmp);
}
//加入课堂
public void joinClass(String username,String userpwd,boolean isShowPwd) {
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
/**
* 播放视频
* @param response
*/
public void playVideo(String response) {
xdySdk.api("playVideo", response+"", surfaceviewPlayVideo, VideoPlayActivity.this);
img_playVideo_novideo.setVisibility(View.GONE);
// img_playVideo_novideo.setVisibility(View.GONE);
img_playVideo_novideo.setImageResource(R.mipmap.no_video);
ToastUtil.showToastshort("视频播放初始化",VideoPlayActivity.this);
}
... ... @@ -250,105 +215,129 @@ public class VideoPlayActivity extends AppCompatActivity {
*/
public void playAudio(String response) {
xdySdk.api("playAudio", response, null, VideoPlayActivity.this);
img_playVideo_novideo.setVisibility(View.GONE);
img_playVideo_novideo.setImageResource(R.mipmap.audio_mode);
img_playVideo_novideo.setVisibility(View.VISIBLE);
ToastUtil.showToastshort("音频播放初始化",VideoPlayActivity.this);
}
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getRelativeUrl() != null) {
String url = docEntity.getRelativeUrl();
GetDocImageEntity getDocImageEntity=new GetDocImageEntity();
getDocImageEntity.setPageNum(1);
getDocImageEntity.setRelativeUrl(url);
getDocImageEntity.setType("jpg");
String jsonParmp = new Gson().toJson(getDocImageEntity);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
xdySdk.api("getDocImageFullPath", jsonParmp);
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
xdySdk.onPlayStop();
}
final AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("是否离开课堂")
.setNegativeButton("在看看", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
})
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
xdySdk.onPlayDestroy();
xdySdk.api("leaveClass","");
UIUtils.closeDialog(mLoginDialog);
mHandler.removeCallbacksAndMessages(null);
VideoPlayActivity.super.onBackPressed();
}
})
.create();
alertDialog.show();
public void onViewClicked(View view) {
switch (view.getId()) {
// case R.id.bt_stop:
// //停止视频
// if(videoPlayBean!=null) {
// xdySdk.api("stopVideo", videoPlayBean.getMediaId() + "");
// }
// break;
}
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
/**
* 错误处理
* @param errorId
* @param errorMsg
*/
public void handError(String errorId,String errorMsg){
ErrorEntity errorEntity=JsonUtil.parseJsonToBean(errorMsg,ErrorEntity.class);
if(errorEntity==null){
return;
}
public PersonDialog(Context context, boolean showPwd) {
this(context, R.style.bottom_dialog, showPwd);
switch (errorEntity.getCode()+""){
case "100":
case "101":
case "102":
case "103":
case "104":
case "105":
case "106":
case "107":
case "200":
case "201":
case "202":
case "203":
case "204":
case "205":
case "206":
case "207":
case "208":
ToastUtil.showToastshort(errorEntity.getReson(),this);
Exit();
break;
case "10000":
ToastUtil.showToastshort(errorEntity.getReson(),this);
break;
case "10001":
ToastUtil.showToastshort(errorEntity.getReson(),this);
break;
case "20000":
ToastUtil.showToastshort(errorEntity.getReson(),this);
break;
}
public PersonDialog(Context context, int themeResId, boolean showPwd) {
super(context, themeResId);
init(context, showPwd);
}
public void init(Context context, boolean showPwd) {
View view = View.inflate(context, R.layout.dialog_item, null);
setContentView(view);
initView(view,showPwd);
setCanceledOnTouchOutside(false);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = dp2px(context, 220);
window.setAttributes(params);
window.setGravity(Gravity.CENTER);
}
}
/**
* 错误情况退出
*/
public void Exit(){
xdySdk.remove(this);
UIUtils.closeDialog(mLoginDialog);
mHandler.removeCallbacksAndMessages(null);
this.finish();
}
public int dp2px(Context context, float dp) {
return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
public void progressDialogDismiss(){
if(mProgressDialog!=null){
mProgressDialog.dismiss();
}
}
public void progressDialogShow(){
if(mProgressDialog==null){
mProgressDialog=ProgressDialog.show(VideoPlayActivity.this,"","加载中");
}else {
mProgressDialog.show();
}
public void initView(View view, final boolean showPwd){
final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
if(showPwd){
edt_userpwd.setVisibility(View.VISIBLE);
}else{
edt_userpwd.setVisibility(View.GONE);
}
/**
* 停止播放
* @param response
*/
public void stopPlay(String response){
VideoOrAudioStopEntity entity= JsonUtil.parseJsonToBean(response,VideoOrAudioStopEntity.class);
if(entity!=null) {
if(xdySdk.onPlayStop(entity.getMediaId()+"")){
img_playVideo_novideo.setImageResource(R.mipmap.novideo);
img_playVideo_novideo.setVisibility(View.VISIBLE);
}
Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
btn_enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username=edt_uername.getText().toString();
userpwd=edt_userpwd.getText().toString();
if(TextUtils.isEmpty(username)){
ToastUtil.showToastshort("用户名不能为空",VideoPlayActivity.this);
return;
}
if(showPwd&&TextUtils.isEmpty(userpwd)){
ToastUtil.showToastshort("密码不能为空",VideoPlayActivity.this);
return;
}
dismiss();
Message message=Message.obtain();
message.what=-2;
message.obj=showPwd;
handler.sendMessage(message);
}
});
}
}
@Override
public void observerUpData(String type, String parameter) {
XdyLogUtil.e(TAG+"observer:",Thread.currentThread().getId()+"");
ResponseEntity responseEntity=new ResponseEntity(type,parameter);
Message message=Message.obtain();
message.obj=responseEntity;
mHandler.sendMessage(message);
}
}
... ...
... ... @@ -42,6 +42,8 @@ package com.mang.xdy.demo.activity;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
... ... @@ -93,43 +95,12 @@ public class VideoPublisherActivity extends AppCompatActivity {
break;
case -1:
//退出
xdySdk.api("leaveClass", "");
// xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 1:
//播放视频
playVideo((String) msg.obj);
XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
break;
case 2:
//播放音频
playAudio((String) msg.obj);
break;
case 3:
getDoc((String) msg.obj);
break;
case 4:
//发送消息
sendMeg();
break;
case 5:
//接受消息
getMsg((String) msg.obj);
break;
case 6:
//推流video
// publisherVideo((String) msg.obj);
// publisherVideoText();
// publisherAudioText();
break;
case 7:
//停止播放
xdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
break;
case 8:
btnVideoPlayPubsherVideo.setEnabled(true);
... ... @@ -165,19 +136,11 @@ public class VideoPublisherActivity extends AppCompatActivity {
break;
case "class_join_success":
//加入课堂成功
UIUtils.closeDialog(mLoginDialog);
ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this);
//只有加入课堂成功才可以点击推流的按钮
handler.sendEmptyMessage(8);
break;
// case "live":
// case "publishVideo":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
//推流直播
// Message message1=Message.obtain();
// message1.obj = response;
// message1.what = 6;
// handler.sendMessage(message1);
// break;
case "video_stop":
// handler.sendEmptyMessage(7);
break;
... ... @@ -195,18 +158,52 @@ public class VideoPublisherActivity extends AppCompatActivity {
xdySdk.api("init", initClass);
}
private LoginDialog mLoginDialog;
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null)
if(initClassSuccessEntity.isPasswordRequired()){
personDialog=new PersonDialog(this,true);
}else{
personDialog=new PersonDialog(this,false);
userpwd="123321";
if(initClassSuccessEntity!=null) {
if (initClassSuccessEntity.isPasswordRequired()) {
isShowPwd=true;
} else {
isShowPwd=false;
userpwd = "123321";
}
personDialog.show();
}
if (mLoginDialog == null) {
mLoginDialog = new LoginDialog(this, isShowPwd, null);
mLoginDialog.show();
mLoginDialog.setCanceledOnTouchOutside(false);
final boolean finalIsShowPwd = isShowPwd;
mLoginDialog.setBtnClick(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] nameAndPwd = mLoginDialog.getNameAndPwd();
joinClass(nameAndPwd[0], nameAndPwd[1], finalIsShowPwd);
}
});
}else if (mLoginDialog != null) {
UIUtils.closeDialog(mLoginDialog);
}
}
//加入课堂
public void joinClass(String username,String userpwd,boolean isShowPwd) {
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
... ... @@ -230,47 +227,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
xdySdk.api("joinClass", jsonParmp);
}
public void playVideo(String response) {
// VideoPlayBean videoPlayBean = JsonUtil.parseJsonToBean(response, VideoPlayBean.class);
// if (videoPlayBean != null && videoPlayBean.getRtmpUrl() != null)
// XdyLogUtil.e(TAG, "执行了ss" + videoPlayBean.getRtmpUrl());
// xdySdk.api("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, VideoPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("视频播放初始化",VideoPublisherActivity.this);
}
public void playAudio(String response) {
// AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
// if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
// XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
// xdySdk.api("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("音频播放初始化",VideoPublisherActivity.this);
// }
}
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getRelativeUrl() != null) {
String url = docEntity.getRelativeUrl();
String temp = "{\n" +
" \"type\": \"jpg\",\n" +
" \"pageNum\": 1,\n" +
" \"relativeUrl\": \" '" + url + "'\"\n" +
"}";
// String temp = "{\n" +
// " \"type\": \"jpg\",\n" +
// " \"pageNum\": 1,\n" +
// " \"relativeUrl\": \"/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg\"\n" +
// "}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
xdySdk.api("getDocImageFullPath", jsonParmp);
}
}
public void sendMeg() {
String temp = "{\n" +
... ... @@ -283,23 +240,6 @@ public class VideoPublisherActivity extends AppCompatActivity {
}
//获取聊天信息
public void getMsg(String msg) {
ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
if (chatBean != null) {
btnVideoPlayChat.setText(chatBean.getMessage());
}
}
//获取推流地址
public void getPublish() {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
xdySdk.api(ids_new, s);
}
/**
* 获取封装的推流地址
*/
... ... @@ -308,56 +248,6 @@ public class VideoPublisherActivity extends AppCompatActivity {
}
/**
* 测试Audio
*/
public void publisherAudioText(){
// XdySdk.setAsyncApi(Constants.PUBLISH_AUDIO, "", surfaceview_pubisherVideo, VideoPublisherActivity.this,"");
}
public void publisherVideo(String response) {
// String url = XdyStringUtils.stringToJson(response);
// XdyLogUtil.e("调用任务了播url:", "" + url);
// String us = response.substring(1, response.length() - 1);
// try {
// LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
// if (liveBean != null&&liveBean.getCode()==0&&liveBean.getPublishUrl()!=null) {
//// String url_text="rtmp://player.daniulive.com:1935/hls/stream";
//// String url_text="rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";
// publisherSuccess=liveBean.getPublishUrl();
// if(isPusherAudio){
// xdySdk.api("publishAudio", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送纯音频初始化中",VideoPublisherActivity.this);
// }else{
// xdySdk.api("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送视频初始化中",VideoPublisherActivity.this);
// }
// isAbleback=true;
// XdyLogUtil.e(TAG,liveBean.getPublishUrl());
// PublisherEntity publisherEntity=new PublisherEntity();
// if(!TextUtils.isEmpty(publisherSuccess)) {
// publisherEntity.setPublishUrl(publisherSuccess);
// String pamp= new Gson().toJson(publisherEntity);
// XdyLogUtil.e("推流成功",""+pamp);
// xdySdk.api("publishVideo",pamp);
// }
//
// }
// } catch (Exception e) {
// XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
//// publisherVideoReturnBean=JsonUtil.parseJsonToBean(response,PublisherVideoReturnBean.class);
// }
}
@Override
public void onBackPressed() {
//退出课堂
xdySdk.api("unPublishVideo","");
super.onBackPressed();
}
... ... @@ -384,7 +274,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
case R.id.btn_videoPlay_stop:
ToastUtil.showToastshort("正在退出,请稍等",this);
xdySdk.api("unPublishVideo","");
finish();
// finish();
break;
}
}
... ... @@ -427,39 +317,6 @@ public class VideoPublisherActivity extends AppCompatActivity {
}
class EventHande_Video implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
... ...
... ... @@ -21,13 +21,13 @@ public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
private String tabTitles[] = new String[]{"文档","聊天"};
private Context context;
private DocFragment docFragment=new DocFragment();
private ChatFragment chatFragment=new ChatFragment();
// private ChatFragment chatFragment=new ChatFragment();
private List<Fragment> fragmentList=new ArrayList<>();
public SimpleFragmentPagerAdapter(FragmentManager fm,Context context) {
super(fm);
this.context = context;
fragmentList.add(docFragment);
fragmentList.add(chatFragment);
// fragmentList.add(chatFragment);
}
@Override
... ...
package com.mang.xdy.demo.bean;
public class ErrorEntity {
/**
* code : 20000
* reson : MCU断开连接,已经离开课堂
*/
private int code;
private String reson;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getReson() {
return reson;
}
public void setReson(String reson) {
this.reson = reson;
}
}
... ...
package com.mang.xdy.demo.bean;
public class ResponseEntity {
private String type;
private String param;
public ResponseEntity(String type, String param) {
this.type = type;
this.param = param;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/19.
*/
public class VideoOrAudioStopEntity {
/**
* mediaId : 565646
* fromNodeId : 73130286
* userName : base
* userRole : host
*/
private int mediaId;
private int fromNodeId;
private String userName;
private String userRole;
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public int getFromNodeId() {
return fromNodeId;
}
public void setFromNodeId(int fromNodeId) {
this.fromNodeId = fromNodeId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
}
... ...
package com.mang.xdy.demo.bean;
import android.graphics.Bitmap;
public class WrapDocBitMapEntity {
/**
* 是否显示没有文档的图片
*/
private boolean noDoc;
private Bitmap bitmap;
public boolean showNoDoc() {
return noDoc;
}
public void setNoDoc(boolean doc) {
noDoc = doc;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.view.View;
import android.view.animation.Interpolator;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.view.ViewHelper;
public abstract class BaseAnimatorSet {
/** 动画时长,系统默认250 */
protected long duration = 500;
protected AnimatorSet animatorSet = new AnimatorSet();
private Interpolator interpolator;
private long delay;
private AnimatorListener listener;
public abstract void setAnimation(View view);
protected void start(final View view) {
/** 设置动画中心点:pivotX--->X轴方向动画中心点,pivotY--->Y轴方向动画中心点 */
// ViewHelper.setPivotX(view, view.getMeasuredWidth() / 2.0f);
// ViewHelper.setPivotY(view, view.getMeasuredHeight() / 2.0f);
reset(view);
setAnimation(view);
animatorSet.setDuration(duration);
if (interpolator != null) {
animatorSet.setInterpolator(interpolator);
}
if (delay > 0) {
animatorSet.setStartDelay(delay);
}
if (listener != null) {
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
listener.onAnimationStart(animator);
}
@Override
public void onAnimationRepeat(Animator animator) {
listener.onAnimationRepeat(animator);
}
@Override
public void onAnimationEnd(Animator animator) {
listener.onAnimationEnd(animator);
}
@Override
public void onAnimationCancel(Animator animator) {
listener.onAnimationCancel(animator);
}
});
}
animatorSet.start();
}
public static void reset(View view) {
ViewHelper.setAlpha(view, 1);
ViewHelper.setScaleX(view, 1);
ViewHelper.setScaleY(view, 1);
ViewHelper.setTranslationX(view, 0);
ViewHelper.setTranslationY(view, 0);
ViewHelper.setRotation(view, 0);
ViewHelper.setRotationY(view, 0);
ViewHelper.setRotationX(view, 0);
}
/** 设置动画时长 */
public BaseAnimatorSet duration(long duration) {
this.duration = duration;
return this;
}
/** 设置动画时长 */
public BaseAnimatorSet delay(long delay) {
this.delay = delay;
return this;
}
/** 设置动画插补器 */
public BaseAnimatorSet interpolator(Interpolator interpolator) {
this.interpolator = interpolator;
return this;
}
/** 动画监听 */
public BaseAnimatorSet listener(AnimatorListener listener) {
this.listener = listener;
return this;
}
/** 在View上执行动画 */
public void playOn(View view) {
start(view);
}
public interface AnimatorListener {
void onAnimationStart(Animator animator);
void onAnimationRepeat(Animator animator);
void onAnimationEnd(Animator animator);
void onAnimationCancel(Animator animator);
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import com.mang.xdy.demo.utils.DisplayUtil;
import com.nineoldandroids.animation.Animator;
import java.lang.ref.WeakReference;
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// .............................................
// 佛祖保佑 永无BUG
// 佛曰:
// 写字楼里写字间,写字间里程序员;
// 程序人员写程序,又拿程序换酒钱。
// 酒醒只在网上坐,酒醉还来网下眠;
// 酒醉酒醒日复日,网上网下年复年。
// 但愿老死电脑间,不愿鞠躬老板前;
// 奔驰宝马贵者趣,公交自行程序员。
// 别人笑我忒疯癫,我笑自己命太贱;
// 不见满街漂亮妹,哪个归得程序员?
public abstract class BaseDialog extends Dialog {
/**
* TAG(日志)
*/
protected String TAG;
/**
* context(上下文)
*/
protected WeakReference<Context> context;
/**
* (DisplayMetrics)设备密度
*/
protected DisplayMetrics dm;
/**
* enable dismiss outside dialog(设置点击对话框以外区域,是否dismiss)
*/
protected boolean cancel;
/**
* dialog width scale(宽度比例)
*/
protected float widthScale = 1;
/**
* dialog height scale(高度比例)
*/
protected float heightScale;
/**
* showAnim(对话框显示动画)
*/
private BaseAnimatorSet showAnim;
/**
* dismissAnim(对话框消失动画)
*/
private BaseAnimatorSet dismissAnim;
/**
* top container(最上层容器)
*/
protected LinearLayout ll_top;
/**
* container to control dialog height(用于控制对话框高度)
*/
protected LinearLayout ll_control_height;
/**
* is showAnim running(显示动画是否正在执行)
*/
private boolean isShowAnim;
/**
* is DismissAnim running(消失动画是否正在执行)
*/
private boolean isDismissAnim;
/**
* max height(最大高度)
*/
protected float maxHeight;
/**
* dialog是否可以移动
*/
private boolean isMove = true;
/**
* method execute order:
* show:constrouctor---show---oncreate---onStart---onAttachToWindow
* dismiss:dismiss---onDetachedFromWindow---onStop
*
* @param context
*/
public BaseDialog(Context context) {
super(context);
setDialogTheme();
this.context = new WeakReference<Context>(context);
this.TAG = this.getClass().getSimpleName();
Log.d(TAG, "constructor");
}
/**
* set dialog theme(设置对话框主题)
*/
private void setDialogTheme() {
requestWindowFeature(Window.FEATURE_NO_TITLE);// android:windowNoTitle
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));// android:windowBackground
getWindow().addFlags(LayoutParams.FLAG_DIM_BEHIND);// android:backgroundDimEnabled默认是true的
}
/**
* inflate layout for dialog ui and return (填充对话框所需要的布局并返回)
* <pre>
*
* public View onCreateView() {
* View inflate = View.inflate(context, R.layout.dialog_share, null);
* return inflate;
* }
* </pre>
*/
public abstract View onCreateView();
/**
* set Ui data or logic opreation before attatched window(在对话框显示之前,设置界面数据或者逻辑)
*
* @return true dialog show,fasle dialog not show
*/
public abstract boolean setUiBeforShow();
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
dm = context.get().getResources().getDisplayMetrics();
ll_top = new LinearLayout(context.get());
ll_top.setGravity(Gravity.CENTER);
ll_control_height = new LinearLayout(context.get());
ll_control_height.setOrientation(LinearLayout.VERTICAL);
ll_control_height.addView(onCreateView());
ll_top.addView(ll_control_height);
maxHeight = dm.heightPixels - DisplayUtil.getStatusBarHeight(getContext());
// maxHeight = dm.heightPixels;
if (isMove) {
setContentView(ll_top);
} else {
setContentView(ll_top, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) maxHeight));
}
setCanceledOnTouchOutside(true);
ll_top.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cancel) {
dismiss();
}
}
});
}
/**
* when dailog attached to window,set dialog width and height and show anim
* (当dailog依附在window上,设置对话框宽高以及显示动画)
*/
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Log.d(TAG, "onAttachedToWindow");
setUiBeforShow();
int width;
if (widthScale == 0) {
width = ViewGroup.LayoutParams.WRAP_CONTENT;
} else {
width = (int) (dm.widthPixels * widthScale);
}
int height;
if (heightScale == 0) {
height = ViewGroup.LayoutParams.WRAP_CONTENT;
} else if (heightScale == 1) {
height = ViewGroup.LayoutParams.MATCH_PARENT;
} else {
height = (int) (maxHeight * heightScale);
}
ll_control_height.setLayoutParams(new LinearLayout.LayoutParams(width, height));
if (showAnim != null) {
showAnim.listener(new BaseAnimatorSet.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
isShowAnim = true;
}
@Override
public void onAnimationRepeat(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
isShowAnim = false;
}
@Override
public void onAnimationCancel(Animator animator) {
isShowAnim = false;
}
}).playOn(ll_control_height);
} else {
BaseAnimatorSet.reset(ll_control_height);
}
}
@Override
public void setCanceledOnTouchOutside(boolean cancel) {
this.cancel = cancel;
super.setCanceledOnTouchOutside(cancel);
}
@Override
public void show() {
Log.d(TAG, "show");
super.show();
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop");
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
Log.d(TAG, "onDetachedFromWindow");
}
@Override
public void dismiss() {
Log.d(TAG, "dismiss");
if (dismissAnim != null)
dismissAnim.listener(new BaseAnimatorSet.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
isDismissAnim = true;
}
@Override
public void onAnimationRepeat(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
isDismissAnim = false;
superDismiss();
}
@Override
public void onAnimationCancel(Animator animator) {
isDismissAnim = false;
superDismiss();
}
}).playOn(ll_control_height);
else
superDismiss();
}
/**
* dismiss without anim(无动画dismiss)
*/
public void superDismiss() {
super.dismiss();
}
/**
* dialog anim by styles(动画弹出对话框,style动画资源) @param animStyle
*/
public void show(int animStyle) {
Window window = getWindow();
window.setWindowAnimations(animStyle);
show();
}
/**
* set window dim or not(设置背景是否昏暗)
*
* @param isDimEnabled
* @return BaseDialog
*/
public BaseDialog dimEnabled(boolean isDimEnabled) {
if (isDimEnabled) {
getWindow().addFlags(LayoutParams.FLAG_DIM_BEHIND);
} else {
getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);
}
return this;
}
/**
* set dialog width scale:0-1(设置对话框宽度,占屏幕宽的比例0-1) @param widthScale @return BaseDialog
*/
public BaseDialog widthScale(float widthScale) {
this.widthScale = widthScale;
return this;
}
/**
* set dialog height scale:0-1(设置对话框高度,占屏幕宽的比例0-1) @param heightScale @return BaseDialog
*/
public BaseDialog heightScale(float heightScale) {
this.heightScale = heightScale;
return this;
}
/**
* set show anim(设置显示的动画) @param showAnim @return BaseDialog
*/
public BaseDialog showAnim(BaseAnimatorSet showAnim) {
this.showAnim = showAnim;
return this;
}
/**
* set dismiss anim(设置隐藏的动画) @param dismissAnim @return BaseDialog
*/
public BaseDialog dismissAnim(BaseAnimatorSet dismissAnim) {
this.dismissAnim = dismissAnim;
return this;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (isDismissAnim || isShowAnim)
return true;
return super.dispatchTouchEvent(ev);
}
@Override
public void onBackPressed() {
if (isDismissAnim || isShowAnim)
return;
super.onBackPressed();
}
/**
* dp to px
*
* @param dp
* @return
*/
protected int dp2px(float dp) {
final float scale = context.get().getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
/**
* @param gravity
* @brief 设置dialog的位置
*/
protected void setGravity(int gravity) {
if (ll_top != null) {
ll_top.setGravity(gravity);
}
}
/**
* dialog位置是否固定
* @param isMove
*/
protected void setIsMove(boolean isMove) {
this.isMove = isMove;
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import com.nineoldandroids.animation.ObjectAnimator;
public abstract class BottomBaseDialog extends BottomTopBaseDialog {
public BottomBaseDialog(Context context, View animateView) {
super(context);
this.animateView = animateView;
innerShowAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0);
innerDismissAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1);
}
public BottomBaseDialog(Context context) {
this(context, null);
}
@Override
protected void onStart() {
super.onStart();
ll_top.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
ll_top.setGravity(Gravity.BOTTOM);
getWindow().setGravity(Gravity.BOTTOM);
ll_top.setPadding(left, top, right, bottom);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
showWithAnim();
}
@Override
public void dismiss() {
dismissWithAnim();
}
private BaseAnimatorSet windowInAs;
private BaseAnimatorSet windowOutAs;
@Override
protected BaseAnimatorSet getWindowInAs() {
if (windowInAs == null) {
windowInAs = new WindowInAs();
}
return windowInAs;
}
@Override
protected BaseAnimatorSet getWindowOutAs() {
if (windowOutAs == null) {
windowOutAs = new WindowOutAs();
}
return windowOutAs;
}
private class WindowInAs extends BaseAnimatorSet {
@Override
public void setAnimation(View view) {
ObjectAnimator oa1 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.9f);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.9f);
animatorSet.playTogether(oa1, oa2);
}
}
private class WindowOutAs extends BaseAnimatorSet {
@Override
public void setAnimation(View view) {
ObjectAnimator oa1 = ObjectAnimator.ofFloat(view, "scaleX", 0.9f, 1f);
ObjectAnimator oa2 = ObjectAnimator.ofFloat(view, "scaleY", 0.9f, 1f);
animatorSet.playTogether(oa1, oa2);
}
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
public abstract class BottomTopBaseDialog extends BaseDialog {
protected View animateView;
private BaseAnimatorSet windowInAs;
private BaseAnimatorSet windowOutAs;
protected Animation innerShowAnim;
protected Animation innerDismissAnim;
protected long innerAnimDuration = 350;
protected boolean isInnerShowAnim;
protected boolean isInnerDismissAnim;
protected int left, top, right, bottom;
public BottomTopBaseDialog(Context context) {
super(context);
}
/**
* set duration for inner animation of animateView(设置animateView内置动画时长)
* @param innerAnimDuration
*/
public void innerAnimDuration(long innerAnimDuration) {
this.innerAnimDuration = innerAnimDuration;
}
public void padding(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
/**
* show dialog and animateView with inner show animation(设置dialog和animateView显示动画)
*/
protected void showWithAnim() {
if (innerShowAnim != null) {
innerShowAnim.setDuration(innerAnimDuration);
innerShowAnim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
isInnerShowAnim = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
isInnerShowAnim = false;
}
});
ll_control_height.startAnimation(innerShowAnim);
}
if (animateView != null) {
if (getWindowInAs() != null) {
windowInAs = getWindowInAs();
}
windowInAs.duration(innerAnimDuration).playOn(animateView);
}
}
/**
* dimiss dialog and animateView with inner dismiss animation(设置dialog和animateView消失动画)
*/
protected void dismissWithAnim() {
if (innerDismissAnim != null) {
innerDismissAnim.setDuration(innerAnimDuration);
innerDismissAnim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
isInnerDismissAnim = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
isInnerDismissAnim = false;
superDismiss();
}
});
ll_control_height.startAnimation(innerDismissAnim);
} else {
superDismiss();
}
if (animateView != null) {
if (getWindowOutAs() != null) {
windowOutAs = getWindowOutAs();
}
windowOutAs.duration(innerAnimDuration).playOn(animateView);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (isInnerDismissAnim || isInnerShowAnim) {
return true;
}
return super.dispatchTouchEvent(ev);
}
@Override
public void onBackPressed() {
if (isInnerDismissAnim || isInnerShowAnim) {
return;
}
super.onBackPressed();
}
protected abstract BaseAnimatorSet getWindowInAs();
protected abstract BaseAnimatorSet getWindowOutAs();
}
... ...
package com.mang.xdy.demo.dialog;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
/**
* Utils to get corner drawable
*/
public class CornerUtils {
public static Drawable cornerDrawable(final int bgColor, float cornerradius) {
final GradientDrawable bg = new GradientDrawable();
bg.setCornerRadius(cornerradius);
bg.setColor(bgColor);
return bg;
}
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius) {
final GradientDrawable bg = new GradientDrawable();
bg.setCornerRadii(cornerradius);
bg.setColor(bgColor);
return bg;
}
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius, int borderwidth, int bordercolor) {
final GradientDrawable bg = new GradientDrawable();
bg.setCornerRadii(cornerradius);
bg.setStroke(borderwidth, bordercolor);
bg.setColor(bgColor);
return bg;
}
/**
* set btn selector with corner drawable for special position
*/
public static StateListDrawable btnSelector(float radius, int normalColor, int pressColor, int postion) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = null;
Drawable pressed = null;
if (postion == 0) {// left btn
normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, 0, 0, radius, radius});
} else if (postion == 1) {// right btn
normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, 0, 0});
} else if (postion == -1) {// only one btn
normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
}
bg.addState(new int[]{-android.R.attr.state_pressed}, normal);
bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
return bg;
}
/**
* set ListView item selector with corner drawable for the last position
* (ListView的item点击效果,只处理最后一项圆角处理)
*/
public static StateListDrawable listItemSelector(float radius, int normalColor, int pressColor, boolean isLastPostion) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = null;
Drawable pressed = null;
if (!isLastPostion) {
normal = new ColorDrawable(normalColor);
pressed = new ColorDrawable(pressColor);
} else {
normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
}
bg.addState(new int[]{-android.R.attr.state_pressed}, normal);
bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
return bg;
}
/**
* set ListView item selector with corner drawable for the first and the last position
* (ListView的item点击效果,第一项和最后一项圆角处理)
*/
public static StateListDrawable listItemSelector(float radius, int normalColor, int pressColor, int itemTotalSize,
int itemPosition) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = null;
Drawable pressed = null;
if (itemPosition == 0 && itemPosition == itemTotalSize - 1) {// 只有一项
normal = cornerDrawable(normalColor, new float[]{radius, radius, radius, radius, radius, radius, radius,
radius});
pressed = cornerDrawable(pressColor, new float[]{radius, radius, radius, radius, radius, radius, radius,
radius});
} else if (itemPosition == 0) {
normal = cornerDrawable(normalColor, new float[]{radius, radius, radius, radius, 0, 0, 0, 0,});
pressed = cornerDrawable(pressColor, new float[]{radius, radius, radius, radius, 0, 0, 0, 0});
} else if (itemPosition == itemTotalSize - 1) {
normal = cornerDrawable(normalColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
pressed = cornerDrawable(pressColor, new float[]{0, 0, 0, 0, radius, radius, radius, radius});
} else {
normal = new ColorDrawable(normalColor);
pressed = new ColorDrawable(pressColor);
}
bg.addState(new int[]{-android.R.attr.state_pressed}, normal);
bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
return bg;
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mang.xdy.demo.R;
public class NormalDialog extends BaseDialog {
/**
* container
*/
private LinearLayout ll_container;
/**
* title
*/
private TextView tv_title;
/**
* title underline
*/
private View v_line_title;
/**
* content
*/
private TextView tv_content;
/**
* left btn
*/
private TextView tv_btn_left;
/**
* right btn
*/
private TextView tv_btn_right;
/**
* vertical line between btns
*/
private View v_line_vertical;
/**
* horizontal line above btns
*/
private View v_line_horizontal;
/**
* title content(标题)
*/
private String title = "温馨提示";
/**
* title textcolor(标题颜色)
*/
private int titleTextColor = Color.parseColor("#61AEDC");
/**
* title textsize(标题字体大小,单位sp)
*/
private float titleTextSize_PX = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_28_0PX);
/**
* enable title show(是否显示标题)
*/
private boolean isTitleShow = true;
/**
* title underline color(标题下划线颜色)
*/
private int titleLineColor = Color.parseColor("#61AEDC");
/**
* title underline height(标题下划线高度)
*/
private float titleLineHeight_DP = 1f;
/**
* content text
*/
private String content;
/**
* show gravity of content(正文内容显示位置)
*/
private int contentGravity = Gravity.CENTER_VERTICAL;
/**
* content textcolor(正文字体颜色)
*/
private int contentTextColor = Color.parseColor("#383838");
/**
* content textsize(正文字体大小)
*/
private float contentTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_28_0PX);
/**
* btn textcolor(按钮字体颜色)
*/
private int btnLeftTextColor = Color.parseColor("#383838");
private int btnRightTextColor = Color.parseColor("#383838");
/**
* btn textsize(按钮字体大小)
*/
private float btnLeftTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_26_0PX);
private float btnRightTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_26_0PX);
/**
* btn press color(按钮点击颜色)
*/
private int btnColorPress = Color.parseColor("#E3E3E3");// #85D3EF,#ffcccccc,#E3E3E3
/**
* left btn text(左按钮内容)
*/
private String btnLeftText = "确定";
/**
* right btn text(右按钮内容)
*/
private String btnRightText = "取消";
/**
* corner radius,dp(圆角程度,单位dp)
*/
private float cornerRadius_DP = 3;
/**
* background color(背景颜色)
*/
private int bgColor = Color.parseColor("#ffffff");
/**
* btn divider line color(对话框之间的分割线颜色(水平+垂直))
*/
private int dividerColor = Color.parseColor("#DADADE");
/**
* left btn click listener(左按钮接口)
*/
private OnBtnLeftClick onBtnLeftClickL;
/**
* right btn click listener(右按钮接口)
*/
private OnBtnRightClick onBtnRightClickL;
public static final int STYLE_ONE = 0;
public static final int STYLE_TWO = 1;
private int style = STYLE_ONE;
public NormalDialog(Context context) {
super(context);
}
@Override
public View onCreateView() {
widthScale(0.88f);
ll_container = new LinearLayout(context.get());
ll_container.setOrientation(LinearLayout.VERTICAL);
/** title */
tv_title = new TextView(context.get());
tv_title.setGravity(Gravity.CENTER);
tv_title.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll_container.addView(tv_title);
/** title underline */
v_line_title = new View(context.get());
ll_container.addView(v_line_title);
/** content */
tv_content = new TextView(context.get());
tv_content.setGravity(Gravity.CENTER);
tv_content.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll_container.addView(tv_content);
v_line_horizontal = new View(context.get());
v_line_horizontal.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
ll_container.addView(v_line_horizontal);
/** btns */
LinearLayout ll_btns = new LinearLayout(context.get());
ll_btns.setOrientation(LinearLayout.HORIZONTAL);
tv_btn_left = new TextView(context.get());
tv_btn_left.setGravity(Gravity.CENTER);
tv_btn_left.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
ll_btns.addView(tv_btn_left);
v_line_vertical = new View(context.get());
v_line_vertical.setLayoutParams(new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT));
ll_btns.addView(v_line_vertical);
tv_btn_right = new TextView(context.get());
tv_btn_right.setGravity(Gravity.CENTER);
tv_btn_right.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
ll_btns.addView(tv_btn_right);
ll_container.addView(ll_btns);
return ll_container;
}
@Override
public boolean setUiBeforShow() {
float radius = dp2px(cornerRadius_DP);
/** title */
if (style == STYLE_ONE) {
tv_title.setMinHeight(dp2px(48));
tv_title.setGravity(Gravity.CENTER_VERTICAL);
tv_title.setPadding(dp2px(15), dp2px(5), dp2px(0), dp2px(5));
tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE);
} else if (style == STYLE_TWO) {
tv_title.setGravity(Gravity.CENTER);
tv_title.setPadding(dp2px(0), dp2px(15), dp2px(0), dp2px(0));
tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.INVISIBLE);
}
tv_title.setText(TextUtils.isEmpty(title) ? "温馨提示" : title);
tv_title.setTextColor(titleTextColor);
tv_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize_PX);
/** title underline */
v_line_title.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
dp2px(titleLineHeight_DP)));
v_line_title.setBackgroundColor(titleLineColor);
v_line_title.setVisibility(isTitleShow && style == STYLE_ONE ? View.VISIBLE : View.GONE);
/** content */
if (style == STYLE_ONE) {
tv_content.setPadding(dp2px(15), dp2px(10), dp2px(15), dp2px(10));
tv_content.setMinHeight(dp2px(100));
tv_content.setGravity(contentGravity);
} else if (style == STYLE_TWO) {
tv_content.setPadding(dp2px(15), dp2px(7), dp2px(15), dp2px(20));
tv_content.setMinHeight(dp2px(56));
tv_content.setGravity(Gravity.CENTER);
}
tv_content.setText(content);
tv_content.setTextColor(contentTextColor);
tv_content.setTextSize(TypedValue.COMPLEX_UNIT_PX, contentTextSize_SP);
/** btns */
tv_btn_left.setText(btnLeftText);
tv_btn_right.setText(btnRightText);
tv_btn_left.setTextColor(btnLeftTextColor);
tv_btn_right.setTextColor(btnRightTextColor);
tv_btn_left.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnLeftTextSize_SP);
tv_btn_right.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnRightTextSize_SP);
v_line_horizontal.setBackgroundColor(dividerColor);
v_line_vertical.setBackgroundColor(dividerColor);
/**set background color and corner radius */
ll_container.setBackgroundDrawable(CornerUtils.cornerDrawable(bgColor, radius));
tv_btn_left.setBackgroundDrawable(CornerUtils.btnSelector(radius, bgColor, btnColorPress, 0));
tv_btn_right.setBackgroundDrawable(CornerUtils.btnSelector(radius, bgColor, btnColorPress, 1));
tv_btn_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onBtnLeftClickL != null) {
onBtnLeftClickL.onBtnLeftClick();
}
}
});
tv_btn_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onBtnRightClickL != null) {
onBtnRightClickL.onBtnRightClick();
}
}
});
return false;
}
// --->属性设置
/**
* set style(设置style)
*
* @param style
* @return NormalDialog
*/
public NormalDialog style(int style) {
this.style = style;
return this;
}
/**
* set title text(设置标题内容)
*
* @param title
* @return NormalDialog
*/
public NormalDialog title(String title) {
this.title = title;
return this;
}
/**
* set title textcolor(设置标题字体颜色)
*
* @param titleTextColor
* @return NormalDialog
*/
public NormalDialog titleTextColor(int titleTextColor) {
this.titleTextColor = titleTextColor;
return this;
}
/**
* set title textsize(设置标题字体大小)
*
* @param titleTextSize_px
* @return NormalDialog
*/
public NormalDialog titleTextSize(float titleTextSize_px) {
this.titleTextSize_PX = titleTextSize_px;
return this;
}
/**
* set title underline color(设置标题下划线颜色)
*
* @param titleLineColor
* @return NormalDialog
*/
public NormalDialog titleLineColor(int titleLineColor) {
this.titleLineColor = titleLineColor;
return this;
}
/**
* set title underline height(设置标题下划线高度)
*
* @param titleLineHeight_DP
* @return NormalDialog
*/
public NormalDialog titleLineHeight(float titleLineHeight_DP) {
this.titleLineHeight_DP = titleLineHeight_DP;
return this;
}
/**
* enable title show(设置标题是否显示)
*
* @param isTitleShow
* @return NormalDialog
*/
public NormalDialog isTitleShow(boolean isTitleShow) {
this.isTitleShow = isTitleShow;
return this;
}
/**
* set content text(设置正文内容)
*
* @param content
* @return NormalDialog
*/
public NormalDialog content(String content) {
this.content = content;
return this;
}
/**
* set content gravity(设置正文内容,显示位置)
*
* @param contentGravity
* @return NormalDialog
*/
public NormalDialog contentGravity(int contentGravity) {
this.contentGravity = contentGravity;
return this;
}
/**
* set content textcolor(设置正文字体颜色)
*
* @param contentTextColor
* @return NormalDialog
*/
public NormalDialog contentTextColor(int contentTextColor) {
this.contentTextColor = contentTextColor;
return this;
}
/**
* set content textsize(设置正文字体大小,单位sp)
*
* @param contentTextSize_SP
* @return NormalDialog
*/
public NormalDialog contentTextSize(float contentTextSize_SP) {
this.contentTextSize_SP = contentTextSize_SP;
return this;
}
/**
* set btn text(设置按钮文字内容)
*
* @param btnLeftText
* @param btnRightText
* @return NormalDialog
*/
public NormalDialog btnText(String btnLeftText, String btnRightText) {
this.btnLeftText = btnLeftText;
this.btnRightText = btnRightText;
return this;
}
/**
* set btn textcolor(设置按钮字体颜色)
*
* @param btnLeftTextColor
* @param btnRightTextColor
* @return NormalDialog
*/
public NormalDialog btnTextColor(int btnLeftTextColor, int btnRightTextColor) {
this.btnLeftTextColor = btnLeftTextColor;
this.btnRightTextColor = btnRightTextColor;
return this;
}
/**
* set btn textsize(设置字体大小,单位sp,默认17f)
*
* @param btnLeftTextSize_SP
* @param btnRightTextSize_SP
* @return NormalDialog
*/
public NormalDialog btnTextSize(float btnLeftTextSize_SP, float btnRightTextSize_SP) {
this.btnLeftTextSize_SP = btnLeftTextSize_SP;
this.btnRightTextSize_SP = btnRightTextSize_SP;
return this;
}
/**
* set btn press color(设置按钮点击颜色)
*
* @param btnColorPress
* @return NormalDialog
*/
public NormalDialog btnColorPress(int btnColorPress) {
this.btnColorPress = btnColorPress;
return this;
}
/**
* set leftbtn click listener(设置左侧按钮监听事件)
*
* @param onBtnLeftClickL
*/
public void setOnBtnLeftClick(OnBtnLeftClick onBtnLeftClickL) {
this.onBtnLeftClickL = onBtnLeftClickL;
}
/**
* set rightbtn click listener(设置右侧按钮监听事件)
*
* @param onBtnRightClickL
*/
public void setOnBtnRightClick(OnBtnRightClick onBtnRightClickL) {
this.onBtnRightClickL = onBtnRightClickL;
}
/**
* set divider color between btns(设置btn分割线的颜色)
*
* @param dividerColor
* @return NormalDialog
*/
public NormalDialog dividerColor(int dividerColor) {
this.dividerColor = dividerColor;
return this;
}
/**
* set corner radius (设置圆角程度)
*
* @param cornerRadius_DP
* @return NormalDialog
*/
public NormalDialog cornerRadius(float cornerRadius_DP) {
this.cornerRadius_DP = cornerRadius_DP;
return this;
}
/**
* set backgroud color(设置背景色)
*
* @param bgColor
* @return NormalDialog
*/
public NormalDialog bgColor(int bgColor) {
this.bgColor = bgColor;
return this;
}
}
... ...
package com.mang.xdy.demo.dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mang.xdy.demo.R;
/**
* 只有一个按钮的普通dialog “取消”或者“确定” 根据type类型判断 如果type=2 表示只有一个确定按钮 type=3“取消”和“确定”都有
*/
public class NormalOnlyOneButtonDialog extends BaseDialog {
private final String type;
/**
* container
*/
private LinearLayout ll_container;
/**
* title
*/
private TextView tv_title;
/**
* title underline
*/
private View v_line_title;
/**
* content
*/
private TextView tv_content;
/**
* left btn
*/
private TextView tv_btn_left;
/**
* right btn
*/
private TextView tv_btn_right;
/**
* vertical line between btns
*/
private View v_line_vertical;
/**
* horizontal line above btns
*/
private View v_line_horizontal;
/**
* title content(标题)
*/
private String title = "温馨提示";
/**
* title textcolor(标题颜色)
*/
private int titleTextColor = Color.parseColor("#61AEDC");
/**
* title textsize(标题字体大小,单位sp)
*/
private float titleTextSize_PX =context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_28_0PX);
/**
* enable title show(是否显示标题)
*/
private boolean isTitleShow = true;
/**
* title underline color(标题下划线颜色)
*/
private int titleLineColor = Color.parseColor("#61AEDC");
/**
* title underline height(标题下划线高度)
*/
private float titleLineHeight_DP = 1f;
/**
* content text
*/
private String content;
/**
* show gravity of content(正文内容显示位置)
*/
private int contentGravity = Gravity.CENTER_VERTICAL;
/**
* content textcolor(正文字体颜色)
*/
private int contentTextColor = Color.parseColor("#383838");
/**
* content textsize(正文字体大小)
*/
private float contentTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_28_0PX);
/**
* btn textcolor(按钮字体颜色)
*/
private int btnLeftTextColor = Color.parseColor("#383838");
private int btnRightTextColor = Color.parseColor("#383838");
/**
* btn textsize(按钮字体大小)
*/
private float btnLeftTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_26_0PX);
private float btnRightTextSize_SP = context.get().getResources().getDimensionPixelSize(R.dimen.ui_DIMEN_26_0PX);
/**
* btn press color(按钮点击颜色)
*/
private int btnColorPress = Color.parseColor("#E3E3E3");// #85D3EF,#ffcccccc,#E3E3E3
/**
* left btn text(左按钮内容)
*/
private String btnLeftText = "确定";
/**
* right btn text(右按钮内容)
*/
private String btnRightText = "取消";
/**
* corner radius,dp(圆角程度,单位dp)
*/
private float cornerRadius_DP = 3;
/**
* background color(背景颜色)
*/
private int bgColor = Color.parseColor("#ffffff");
/**
* btn divider line color(对话框之间的分割线颜色(水平+垂直))
*/
private int dividerColor = Color.parseColor("#DADADE");
/**
* left btn click listener(左按钮接口)
*/
private OnBtnLeftClick onBtnLeftClickL;
/**
* right btn click listener(右按钮接口)
*/
private OnBtnRightClick onBtnRightClickL;
public static final int STYLE_ONE = 0;
public static final int STYLE_TWO = 1;
private int style = STYLE_ONE;
public NormalOnlyOneButtonDialog(Context context, String type) {
super(context);
this.type=type;
}
@Override
public View onCreateView() {
widthScale(0.88f);
ll_container = new LinearLayout(context.get());
ll_container.setOrientation(LinearLayout.VERTICAL);
/** title */
tv_title = new TextView(context.get());
tv_title.setGravity(Gravity.CENTER);
tv_title.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll_container.addView(tv_title);
/** title underline */
v_line_title = new View(context.get());
ll_container.addView(v_line_title);
/** content */
tv_content = new TextView(context.get());
tv_content.setGravity(Gravity.CENTER);
tv_content.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
ll_container.addView(tv_content);
v_line_horizontal = new View(context.get());
v_line_horizontal.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
ll_container.addView(v_line_horizontal);
/** btns */
LinearLayout ll_btns = new LinearLayout(context.get());
ll_btns.setOrientation(LinearLayout.HORIZONTAL);
if ("3".equals(type)){
tv_btn_left = new TextView(context.get());
tv_btn_left.setGravity(Gravity.CENTER);
tv_btn_left.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
ll_btns.addView(tv_btn_left);
}
v_line_vertical = new View(context.get());
v_line_vertical.setLayoutParams(new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT));
ll_btns.addView(v_line_vertical);
tv_btn_right = new TextView(context.get());
tv_btn_right.setGravity(Gravity.CENTER);
tv_btn_right.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
ll_btns.addView(tv_btn_right);
ll_container.addView(ll_btns);
return ll_container;
}
@Override
public boolean setUiBeforShow() {
float radius = dp2px(cornerRadius_DP);
/** title */
if (style == STYLE_ONE) {
tv_title.setMinHeight(dp2px(48));
tv_title.setGravity(Gravity.CENTER_VERTICAL);
tv_title.setPadding(dp2px(15), dp2px(5), dp2px(0), dp2px(5));
tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.GONE);
} else if (style == STYLE_TWO) {
tv_title.setGravity(Gravity.CENTER);
tv_title.setPadding(dp2px(0), dp2px(15), dp2px(0), dp2px(0));
tv_title.setVisibility(isTitleShow ? View.VISIBLE : View.INVISIBLE);
}
tv_title.setText(TextUtils.isEmpty(title) ? "温馨提示" : title);
tv_title.setTextColor(titleTextColor);
tv_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize_PX);
/** title underline */
v_line_title.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
dp2px(titleLineHeight_DP)));
v_line_title.setBackgroundColor(titleLineColor);
v_line_title.setVisibility(isTitleShow && style == STYLE_ONE ? View.VISIBLE : View.GONE);
/** content */
if (style == STYLE_ONE) {
tv_content.setPadding(dp2px(15), dp2px(10), dp2px(15), dp2px(10));
tv_content.setMinHeight(dp2px(100));
tv_content.setGravity(contentGravity);
} else if (style == STYLE_TWO) {
tv_content.setPadding(dp2px(15), dp2px(7), dp2px(15), dp2px(20));
tv_content.setMinHeight(dp2px(56));
tv_content.setGravity(Gravity.CENTER);
}
tv_content.setText(content);
tv_content.setTextColor(contentTextColor);
tv_content.setTextSize(TypedValue.COMPLEX_UNIT_PX, contentTextSize_SP);
/** btns */
if ("3".equals(type)){
tv_btn_left.setText(btnLeftText);
tv_btn_left.setTextColor(btnLeftTextColor);
tv_btn_left.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnLeftTextSize_SP);
}
tv_btn_right.setText(btnRightText);
tv_btn_right.setTextColor(btnRightTextColor);
tv_btn_right.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnRightTextSize_SP);
v_line_horizontal.setBackgroundColor(dividerColor);
v_line_vertical.setBackgroundColor(dividerColor);
/**set background color and corner radius */
ll_container.setBackgroundDrawable(CornerUtils.cornerDrawable(bgColor, radius));
tv_btn_right.setBackgroundDrawable(CornerUtils.btnSelector(radius, bgColor, btnColorPress, 1));
if ("3".equals(type)){
tv_btn_left.setBackgroundDrawable(CornerUtils.btnSelector(radius, bgColor, btnColorPress, 0));
tv_btn_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onBtnLeftClickL != null) {
onBtnLeftClickL.onBtnLeftClick();
}
}
});
}
tv_btn_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onBtnRightClickL != null) {
onBtnRightClickL.onBtnRightClick();
}
}
});
return false;
}
// --->属性设置
/**
* set style(设置style)
*
* @param style
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog style(int style) {
this.style = style;
return this;
}
/**
* set title text(设置标题内容)
*
* @param title
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog title(String title) {
this.title = title;
return this;
}
/**
* set title textcolor(设置标题字体颜色)
*
* @param titleTextColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog titleTextColor(int titleTextColor) {
this.titleTextColor = titleTextColor;
return this;
}
/**
* set title textsize(设置标题字体大小)
*
* @param titleTextSize_PX
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog titleTextSize(float titleTextSize_PX) {
this.titleTextSize_PX = titleTextSize_PX;
return this;
}
/**
* set title underline color(设置标题下划线颜色)
*
* @param titleLineColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog titleLineColor(int titleLineColor) {
this.titleLineColor = titleLineColor;
return this;
}
/**
* set title underline height(设置标题下划线高度)
*
* @param titleLineHeight_DP
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog titleLineHeight(float titleLineHeight_DP) {
this.titleLineHeight_DP = titleLineHeight_DP;
return this;
}
/**
* enable title show(设置标题是否显示)
*
* @param isTitleShow
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog isTitleShow(boolean isTitleShow) {
this.isTitleShow = isTitleShow;
return this;
}
/**
* set content text(设置正文内容)
*
* @param content
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog content(String content) {
this.content = content;
return this;
}
/**
* set content gravity(设置正文内容,显示位置)
*
* @param contentGravity
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog contentGravity(int contentGravity) {
this.contentGravity = contentGravity;
return this;
}
/**
* set content textcolor(设置正文字体颜色)
*
* @param contentTextColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog contentTextColor(int contentTextColor) {
this.contentTextColor = contentTextColor;
return this;
}
/**
* set content textsize(设置正文字体大小,单位sp)
*
* @param contentTextSize_SP
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog contentTextSize(float contentTextSize_SP) {
this.contentTextSize_SP = contentTextSize_SP;
return this;
}
/**
* set btn text(设置按钮文字内容)
*
* @param btnLeftText
* @param btnRightText
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog btnText(String btnLeftText, String btnRightText) {
this.btnLeftText = btnLeftText;
this.btnRightText = btnRightText;
return this;
}
/**
* set btn textcolor(设置按钮字体颜色)
*
* @param btnLeftTextColor
* @param btnRightTextColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog btnTextColor(int btnLeftTextColor, int btnRightTextColor) {
this.btnLeftTextColor = btnLeftTextColor;
this.btnRightTextColor = btnRightTextColor;
return this;
}
/**
* set btn textsize(设置字体大小,单位sp,默认17f)
*
* @param btnLeftTextSize_SP
* @param btnRightTextSize_SP
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog btnTextSize(float btnLeftTextSize_SP, float btnRightTextSize_SP) {
this.btnLeftTextSize_SP = btnLeftTextSize_SP;
this.btnRightTextSize_SP = btnRightTextSize_SP;
return this;
}
/**
* set btn press color(设置按钮点击颜色)
*
* @param btnColorPress
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog btnColorPress(int btnColorPress) {
this.btnColorPress = btnColorPress;
return this;
}
/**
* set leftbtn click listener(设置左侧按钮监听事件)
*
* @param onBtnLeftClickL
*/
public void setOnBtnLeftClick(OnBtnLeftClick onBtnLeftClickL) {
this.onBtnLeftClickL = onBtnLeftClickL;
}
/**
* set rightbtn click listener(设置右侧按钮监听事件)
*
* @param onBtnRightClickL
*/
public void setOnBtnRightClick(OnBtnRightClick onBtnRightClickL) {
this.onBtnRightClickL = onBtnRightClickL;
}
/**
* set divider color between btns(设置btn分割线的颜色)
*
* @param dividerColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog dividerColor(int dividerColor) {
this.dividerColor = dividerColor;
return this;
}
/**
* set corner radius (设置圆角程度)
*
* @param cornerRadius_DP
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog cornerRadius(float cornerRadius_DP) {
this.cornerRadius_DP = cornerRadius_DP;
return this;
}
/**
* set backgroud color(设置背景色)
*
* @param bgColor
* @return NormalDialog
*/
public NormalOnlyOneButtonDialog bgColor(int bgColor) {
this.bgColor = bgColor;
return this;
}
}
... ...
package com.mang.xdy.demo.dialog;
public interface OnBtnClick {
void onBtnClick();
}
... ...
package com.mang.xdy.demo.dialog;
public interface OnBtnLeftClick {
void onBtnLeftClick();
}
... ...
package com.mang.xdy.demo.dialog;
public interface OnBtnRightClick {
void onBtnRightClick();
}
\ No newline at end of file
... ...
... ... @@ -23,6 +23,7 @@ import com.mang.xdy.demo.base.BaseRunnable;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.GetDocImageEntity;
import com.mang.xdy.demo.bean.WhiteboardUpdateEntity;
import com.mang.xdy.demo.bean.WrapDocBitMapEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.CanvasView;
... ... @@ -35,6 +36,11 @@ import java.util.concurrent.ExecutionException;
import butterknife.BindView;
import butterknife.ButterKnife;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
/**
* Created by abao on 2017/4/14.
... ... @@ -46,7 +52,6 @@ public class DocFragment extends Fragment implements ObserverListener{
CanvasView mCanvasView;
private Bitmap bitmap;
private Context mContext;
private String whritebroad="";
private XdySdk xdySdk;
int winWidth;
int winHeight;
... ... @@ -57,8 +62,8 @@ public class DocFragment extends Fragment implements ObserverListener{
super.onActivityCreated(savedInstanceState);
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
mContext=this.getContext();
init();
}
private Handler mHandler=new Handler(){
... ... @@ -81,14 +86,14 @@ public class DocFragment extends Fragment implements ObserverListener{
public void init(){
DisplayMetrics metric = new DisplayMetrics();
getWindowWith(metric);
mCanvasView.setBitmap(getEmptyBitmap(),false);
docUrlTransformBitmap(null);
}
private void getWindowWith(DisplayMetrics metric) {
this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
winWidth = metric.widthPixels; // 屏幕宽度(像素)
winHeight = metric.heightPixels; // 屏幕高度(像素)
XdyLogUtil.e(TAG,"获取屏幕的宽:"+winWidth+":"+mCanvasView.getWidth()+" 获取屏幕的高:"+winHeight);
XdyLogUtil.e(TAG,"获取屏幕的宽:"+winWidth+":"+" 获取屏幕的高:"+winHeight);
}
/**
... ... @@ -97,11 +102,9 @@ public class DocFragment extends Fragment implements ObserverListener{
*/
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getImages()!= null&&docEntity.getImages().size()>=1) {
//默认显示第一张
setDocImage(docEntity.getImages().get(0));
}else{
mHandler.sendEmptyMessage(0);
if (docEntity != null && docEntity.isVisible()==true&&docEntity.getImages()!= null&&docEntity.getImages().size()>=1) {
int currentPic=docEntity.getCurPageNo();
setDocImage(docEntity.getImages().get((currentPic>0) ? currentPic-1:0));
}
}
... ... @@ -110,33 +113,34 @@ public class DocFragment extends Fragment implements ObserverListener{
* @param url
*/
public void setDocImage(String url){
getBitmap(url);
// getBitmap(url);
docUrlTransformBitmap(url);
}
public void getBitmap(final String url){
new Thread(){
@Override
public void run() {
super.run();
try {
bitmap= Glide.with(mContext).load(url).asBitmap().centerCrop() .into(winWidth,winWidth).get();
if(bitmap!=null) {
mHandler.post(new Runnable() {
@Override
public void run() {
mCanvasView.setZOrderMediaOverlay(true);
mCanvasView.setBitmap(bitmap,true);
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}.start();
// new Thread(){
// @Override
// public void run() {
// super.run();
// try {
// bitmap= Glide.with(mContext).load(url).asBitmap().into(480,480).get();
// if(bitmap!=null) {
//// mHandler.post(new Runnable() {
//// @Override
//// public void run() {
// mCanvasView.setZOrderMediaOverlay(true);
// mCanvasView.setBitmap(bitmap,false);
//// }
//// });
//
// }
// } catch (InterruptedException e) {
// e.printStackTrace();
// } catch (ExecutionException e) {
// e.printStackTrace();
// }
// }
// }.start();
}
/**
* 展示文档
... ... @@ -144,14 +148,8 @@ public class DocFragment extends Fragment implements ObserverListener{
* @param response
*/
public void showDoc(String type,String response){
WhiteboardUpdateEntity whiteboardUpdateEntity= JsonUtil.parseJsonToBean(response,WhiteboardUpdateEntity.class);
if(whiteboardUpdateEntity!=null){
mCanvasView.setZOrderMediaOverlay(true);
// if(bitmap!=null) {
// mCanvasView.setBitmap(bitmap,!whiteboardUpdateEntity.isFresh);
// }
if (intervalTime != 0) {
intervalTime = System.currentTimeMillis() - intervalTime;
if (intervalTime < 150) {//小于100毫秒 不执行?
... ... @@ -166,6 +164,7 @@ public class DocFragment extends Fragment implements ObserverListener{
}
private void delayDraw(final WhiteboardUpdateEntity entity) {
mHandler.postDelayed(new BaseRunnable<WhiteboardUpdateEntity>() {
@Override
... ... @@ -194,7 +193,56 @@ public class DocFragment extends Fragment implements ObserverListener{
}
}
}
private void docUrlTransformBitmap(final String url) {
XdyLogUtil.i(TAG, url != null ? url : "显示没有文档界面");
Observable.just(url)
.subscribeOn(Schedulers.io())
.map(new Func1<String, WrapDocBitMapEntity>() {
@Override
public WrapDocBitMapEntity call(String s) {
WrapDocBitMapEntity wrapDocBitMapEntity = new WrapDocBitMapEntity();
try {
if (s == null) {
wrapDocBitMapEntity.setNoDoc(true);
wrapDocBitMapEntity.setBitmap(getEmptyBitmap());
//直接使用无文档图片
} else {
Bitmap bitmap = Glide.with(mContext)
.load(s)
.asBitmap()
.into(winWidth, winWidth)
.get();
wrapDocBitMapEntity.setNoDoc(false);
wrapDocBitMapEntity.setBitmap(bitmap);
}
return wrapDocBitMapEntity;
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
wrapDocBitMapEntity.setNoDoc(true);
return wrapDocBitMapEntity;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<WrapDocBitMapEntity>() {
@Override
public void call(WrapDocBitMapEntity resource) {
if (resource.getBitmap() == null) {
ToastUtil.showToastshort("图片获取失败",mContext);
Bitmap bitmap = getEmptyBitmap();
mCanvasView.setBitmap(bitmap, false);
} else {
mCanvasView.setBitmap(resource.getBitmap(), !resource.showNoDoc());
}
}
});
}
@Override
public void observerUpData(String type, String parameter) {
XdyLogUtil.e(TAG,"type:"+type+" response:"+parameter);
... ... @@ -202,15 +250,11 @@ public class DocFragment extends Fragment implements ObserverListener{
case Constants.DOCUMENT_UPDATE:
getDoc(parameter);
break;
// case "getDocImageFullPath":
// setDocImage(parameter);
// break;
case Constants.WHITEBOARD_ANNOTATION_UPDATE:
showDoc(type,parameter);
break;
case Constants.DOCUMENT_DELETE:
bitmap=null;
mCanvasView.setBitmap(getEmptyBitmap(),false);
docUrlTransformBitmap(null);
break;
}
... ... @@ -218,6 +262,7 @@ public class DocFragment extends Fragment implements ObserverListener{
@Override
public void onDestroyView() {
super.onDestroyView();
xdySdk.remove(this);
mHandler.removeCallbacksAndMessages(null);
}
}
... ...
... ... @@ -65,21 +65,21 @@ public class CanvasView extends SurfaceView implements SurfaceHolder.Callback, V
*/
private int currentOffsetY;
private void initRect() {
mCurrentMaxScale = Math.max(
MIN_ZOOM_SCALE,
4 * Math.min(FLOAT_TYPE * mImageHeight / mSurfaceHeight, 1.0f
* mImageWidth / mSurfaceWidth));
mCurrentScale = MIN_ZOOM_SCALE;
//最大的缩放比例为图片宽度与屏幕宽度的比例,就是不能缩放
mCurrentScale = mCurrentMaxScale = (FLOAT_TYPE * screenWidth) / (FLOAT_TYPE * mImageWidth);
mCenterX = mImageWidth / 2;
mCenterY = mImageHeight / 2;
calcRect();
}
// private void initRect() {
// mCurrentMaxScale = Math.max(
// MIN_ZOOM_SCALE,
// 4 * Math.min(FLOAT_TYPE * mImageHeight / mSurfaceHeight, 1.0f
// * mImageWidth / mSurfaceWidth));
//
// mCurrentScale = MIN_ZOOM_SCALE;
//
// //最大的缩放比例为图片宽度与屏幕宽度的比例,就是不能缩放
// mCurrentScale = mCurrentMaxScale = (FLOAT_TYPE * screenWidth) / (FLOAT_TYPE * mImageWidth);
//
// mCenterX = mImageWidth / 2;
// mCenterY = mImageHeight / 2;
// calcRect();
// }
private void adjustCenter() {
int w = mRectSrc.right - mRectSrc.left;
... ...
package com.mang.xdy.demo.widget.dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.dialog.BaseDialog;
import com.mang.xdy.utils.UIUtils;
import me.yokeyword.fragmentation.SupportFragment;
public class LoginDialog extends BaseDialog {
private SupportFragment fragment;
private boolean pwdIsRequired;
private Button mLogin;
private EditText mPassword;
private EditText mUsername;
/**
* method execute order:
* showMediaContainer:constrouctor---showMediaContainer---oncreate---onStart---onAttachToWindow
* dismiss:dismiss---onDetachedFromWindow---onStop
* @param context
*/
public LoginDialog(Context context, boolean pwdIsRequired, SupportFragment fragment) {
super(context);
this.pwdIsRequired = pwdIsRequired;
this.fragment = fragment;
}
@Override
public View onCreateView() {
widthScale(1f);
heightScale(1f);
setGravity(Gravity.CENTER);
View inflate = View.inflate(context.get(), R.layout.home_dialog_login, null);
mLogin = (Button) inflate.findViewById(R.id.btn_login);
mUsername = (EditText) inflate.findViewById(R.id.et_username);
mPassword = (EditText) inflate.findViewById(R.id.et_password);
if (pwdIsRequired) {
mPassword.setVisibility(View.VISIBLE);
}
return inflate;
}
@Override
public boolean setUiBeforShow() {
return false;
}
public void setBtnClick(View.OnClickListener click) {
mLogin.setOnClickListener(click);
}
public String[] getNameAndPwd() {
String username = UIUtils.getViewText(mUsername);
String password = UIUtils.getViewText(mPassword);
String[] strings = {username, password};
return strings;
}
@Override
public void onBackPressed() {
if (fragment != null && fragment.isAdded()) {
fragment.pop();
}
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
<stroke
android:width="@dimen/ui_DIMEN_1.0PX"
android:color="@color/black"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimaryDark" android:state_pressed="true"></item>
<item android:drawable="@color/colorPrimaryDark" android:state_checked="true"></item>
<item android:drawable="@color/colorPrimary"></item>
</selector>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/bg_btn" />
<stroke
android:width="1px"
android:color="@color/font_blue" />
<corners android:radius="@dimen/ui_general_stroke_radius" />
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/ui_white"/>
<!-- 00000000全透明 -->
<stroke
android:width="@dimen/ui_DIMEN_1.0PX"
android:color="@color/ui_font_secondary_color"/>
<corners android:radius="@dimen/ui_general_stroke_radius"/>
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="#0076FF" />
</shape>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/ui_loading_color"/>
<corners android:radius="@dimen/ui_DIMEN_10.0PX"/>
</shape>
\ No newline at end of file
... ...
... ... @@ -8,7 +8,7 @@
tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp">
android:layout_height="@dimen/ui_DIMEN_500.0PX">
<SurfaceView
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:gravity="center"
android:background="#ffffff"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="@dimen/ui_DIMEN_500.0PX"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/radius_solid_white_stroke_999"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/ui_DIMEN_20.0PX"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="@+id/dialog_edt_username"
android:layout_width="100dp"
android:layout_height="wrap_content"
style="@style/home_login_edit_style"
android:hint="用户名"/>
<EditText
android:id="@+id/dialog_edt_userpwd"
android:layout_width="100dp"
android:layout_height="wrap_content"
style="@style/home_login_edit_style"
android:hint="密码"/>
<Button
android:id="@+id/dialog_btn_enter"
android:layout_width="100dp"
android:layout_height="wrap_content"
style="@style/home_site_btn_style"
android:text="登录"
/>
</LinearLayout>
\ No newline at end of file
... ...
... ... @@ -4,6 +4,6 @@
android:layout_height="match_parent">
<com.mang.xdy.demo.widget.CanvasView
android:id="@+id/canvas_doc_show"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="@dimen/ui_DIMEN_500.0PX"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/radius_solid_white_stroke_999"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/ui_DIMEN_20.0PX">
<EditText
android:id="@+id/et_username"
style="@style/home_login_edit_style"
android:hint="用户名"/>
<EditText
android:id="@+id/et_password"
style="@style/home_login_edit_style"
android:hint="密码"
android:inputType="textPassword"
android:visibility="gone"/>
<Button
android:id="@+id/btn_login"
style="@style/home_site_btn_style"
android:text="登录"
android:textColor="@color/white"/>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
... ...
... ... @@ -111,7 +111,75 @@
<!--WheelView 遮盖未选中item的蒙层-->
<color name="ui_wheel_unselect_color">#B1FFFFFF</color>
<color name="ui_loading_color">#88000000</color>
<color name="black">#000000</color>
<color name="stroke_color">#b2b2b2</color>
<color name="divider_color">@color/Color_EFEFEF</color>
<!-- 刷新背景色 -->
<color name="refresh_background">#333333</color>
<!--分割块 -->
<color name="divider_block_color">@color/Color_EFEFF4</color>
<color name="tab_unselect">#c9c9c9</color>
<color name="bg_btn">#dadada</color>
<color name="result_price">#EE2B39</color>
<color name="white">#ffffff</color>
<color name="COLOR_808080">#808080</color>
<color name="unfocus">#55FFFFFF</color>
<color name="titlebar_background">@color/Color_FAFAFA</color>
<color name="titlebar_background_dark_theme">@color/male_themeColor</color>
<color name="titlebar_divider_color">#b2b2b2</color>
<color name="titlebar_title_color">#262626</color>
<color name="bottom_btn_default_color">#262626</color>
<color name="bottom_btn_press_color">#373737</color>
<color name="bottom_btn_red_color">@color/Color_FA4C55</color>
<color name="bottom_btn_redpress_color">@color/Color_FCB7BB</color>
<color name="saveaddress_dialog">#007aff</color>
<color name="font_title_color">@color/Color_262626</color>
<color name="font_primary_color">#666666</color>
<color name="font_secondary_color">@color/Color_999999</color>
<color name="font_good_result_color">#3E3A39</color>
<color name="font_edit_hint_color">#B5B5B6</color>
<color name="purple">#663AB7</color>
<color name="font_blue">#007aff</color>
<color name="Color_262626">#262626</color>
<color name="Color_FAFAFA">#FAFAFA</color>
<color name="Color_FCB7BB">#Fcb7bb</color>
<color name="Color_EFEFF4">#EFEFF4</color>
<color name="Color_999999">#999999</color>
<color name="Color_383838">#383838</color>
<color name="Color_F9F9F9">#F9F9F9</color>
<color name="Color_F74a55">#f74a55</color>
<color name="Color_E2E2E2">#E2E2E2</color>
<color name="Color_F74A55">#f74a55</color>
<color name="Color_D44040">#D44040</color>
<color name="Color_161618">#161618</color>
<color name="Color_3E3538">#3E3538</color>
<color name="Color_FA4C55">#FA4C55</color>
<color name="Color_7f000000">#1a191e</color>
<color name="Color_E24343">#e14245</color>
<color name="Color_33FFFFFF">#33FFFFFF</color>
<color name="Color_ABFFFFFF">#ABFFFFFF</color>
<color name="Color_7FFFFFFF">#7FFFFFFF</color>
<color name="Color_030303">#030303</color>
<color name="Color_0076ff">#0076ff</color>
<color name="Color_EFEFEF">#EFEFEF</color>
<color name="Color_F2F2F2">#F2F2F2</color>
<color name="Color_DEDEDE">#DEDEDE</color>
<color name="COLOR_760E19">#760e19</color>
<color name="COLOR_3E3A39">#3E3A39</color>
<color name="COLOR_F00033">#F00033</color>
<color name="COLOR_D0D0D0">#D0D0D0</color>
<color name="COLOR_E1E1E1">#E1E1E1</color>
<color name="COLOR_727171">#727171</color>
<color name="COLOR_970000">#970000</color>
<color name="COLOR_F9CB15">#F9CB15</color>
<color name="COLOR_FACD00">#facd00</color>
<color name="COLOR_10CF73">#10CF73</color>
<color name="COLOR_F1F1F1">#F1F1F1</color>
<color name="COLOR_EBEBEB">#ebebeb</color>
<color name="COLOR_808080">#808080</color>
<!--WheelView 遮盖未选中item的蒙层-->
<color name="wheel_unselect_color">#B1FFFFFF</color>
</resources>
... ...
... ... @@ -2,4 +2,39 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- yalantis -->
<dimen name="ui_refresh_header_height_yalantis">136dp</dimen>
<!-- jd -->
<dimen name="ui_refresh_header_height_jd">100dp</dimen>
<!-- 标题栏高度 -->
<dimen name="ui_titlebar_height">@dimen/ui_DIMEN_96.0PX</dimen>
<!-- 默认内边距 -->
<dimen name="ui_default_padding">@dimen/ui_DIMEN_20.0PX</dimen>
<!-- 收货地址默认内边距 -->
<dimen name="ui_address_padding">@dimen/ui_DIMEN_40.0PX</dimen>
<!-- Navigator的高度 -->
<dimen name="ui_navigator_height">@dimen/ui_DIMEN_98.0PX</dimen>
<!-- 设置里每一个ITEM的高度 -->
<dimen name="ui_setting_item_height">@dimen/ui_DIMEN_102.0PX</dimen>
<!-- 边框的角度 -->
<dimen name="ui_general_stroke_radius">8px</dimen>
<!-- 边框的宽度 -->
<dimen name="ui_general_stroke_width">1px</dimen>
<dimen name="ui_xxs_font_size">@dimen/ui_DIMEN_20.0PX</dimen>
<dimen name="ui_xs_font_size">@dimen/ui_DIMEN_22.0PX</dimen>
<dimen name="ui_s_font_size">@dimen/ui_DIMEN_24.0PX</dimen>
<dimen name="ui_m_font_size">@dimen/ui_DIMEN_26.0PX</dimen>
<dimen name="ui_l_font_size">@dimen/ui_DIMEN_28.0PX</dimen>
<dimen name="ui_xl_font_size">@dimen/ui_DIMEN_30.0PX</dimen>
<dimen name="ui_xxl_font_size">@dimen/ui_DIMEN_32.0PX</dimen>
<dimen name="ui_xxxl_font_size">@dimen/ui_DIMEN_34.0PX</dimen>
<dimen name="ui_xxxxl_font_size">@dimen/ui_DIMEN_36.0PX</dimen>
<dimen name="ui_primary_font_size">@dimen/ui_DIMEN_26.0PX</dimen>
<dimen name="ui_second_font_size">@dimen/ui_DIMEN_24.0PX</dimen>
<dimen name="home_avigator_height">@dimen/ui_DIMEN_60.0PX</dimen>
<!-- BTN的高度 -->
<dimen name="home_btn_height">@dimen/ui_DIMEN_88.0PX</dimen>
</resources>
... ...
... ... @@ -74,4 +74,35 @@
<!-- 进入时的动画 -->
<item name="android:includeFontPadding">false</item>
</style>
<!-- EditTextView统一样式-->
<style name="ui_etBaseStyle" parent="ui_tvBaseStyle">
<!-- 进入时的动画 -->
<item name="android:background">@null</item>
<item name="android:textCursorDrawable">@drawable/ui_cursor_style</item>
</style>
<style name="home_login_edit_style" parent="ui_etBaseStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">@dimen/ui_DIMEN_82.0PX</item>
<item name="android:background">@drawable/home_noradius_solid_white_stroke_black</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/Color_262626</item>
<item name="android:layout_marginLeft">@dimen/ui_default_padding</item>
<item name="android:layout_marginRight">@dimen/ui_default_padding</item>
<item name="android:layout_marginTop">@dimen/ui_default_padding</item>
<item name="android:textColorHint">@color/font_edit_hint_color</item>
</style>
<style name="home_site_btn_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">@dimen/home_btn_height</item>
<item name="android:layout_marginLeft">@dimen/ui_default_padding</item>
<item name="android:layout_marginRight">@dimen/ui_default_padding</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:background">@drawable/home_selector_bottom_btn_blue</item>
<item name="android:gravity">center</item>
<item name="android:layout_marginTop">@dimen/ui_DIMEN_20.0PX</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">@dimen/ui_DIMEN_34.0PX</item>
</style>
</resources>
... ...
... ... @@ -7,14 +7,17 @@ package com.mang.xdy.bean;
public class GetPublishPathReceiveBean {
/**
* code : 0
* data :
* publishUrl : rtmp: 123.56.205.116: 6000/live/h5dev_1184939098_0_983041_1491555151
* mediaId : 983042
* publishUrl : rtmp://127.0.0.1:6000/flash/h5dev_403074980_0_983042_1487670051
*/
private int code;
private String data;
private int mediaId;
private String publishUrl;
public int getCode() {
... ... @@ -33,6 +36,14 @@ public class GetPublishPathReceiveBean {
this.data = data;
}
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public String getPublishUrl() {
return publishUrl;
}
... ...
... ... @@ -155,9 +155,18 @@ public interface Constants {
String PUBLISH_AUDIO="publishAudio";
/**
* 获取Video推流地址
* @deprecated
*/
String GET_VIDEO_PUBLISH_PATH="getVideoPublishPath";
/**
* 异步获取视频推流返回地址
*/
String VIDEO_GET_PUBLISH_PATH="video_get_publish_path";
/**
* 异步获取音频推流地址
*/
String AUDIO_GET_PUBLISH_PATH="audio_get_publish_path";
/**
* 获取Audio推流地址
*/
String GET_AUDIO_PUBLISH_PATH="getAudioPublishPath";
... ... @@ -177,5 +186,5 @@ public interface Constants {
/**
* 推流成功
*/
String PUBLISH_RERUEN_SUCCESS="";
String PUBLISH_RERUEN_SUCCESS="publishSuccess";
}
... ...
... ... @@ -106,12 +106,16 @@ public class XdyJsCore {
* @param id
* @param parameter
*/
protected void native2js(final String id, String parameter){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
protected void native2js(final String id, final String parameter) {
XdyLogUtil.e("推流线程native2js:",Thread.currentThread().getId()+"");
// mWebView.post(new Runnable() {
// @Override
// public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+parameter+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
XdyLogUtil.e(TAG, value);
XdyLogUtil.e(TAG+"同步获取的数据", value);
//TODO
// if (!TextUtils.isEmpty(value)&&value.length()>10) {
// if(mOnXdyAsyncMessageListener !=null){
... ... @@ -126,8 +130,10 @@ public class XdyJsCore {
}
});
}else{
mWebView.loadUrl("javascript:_native2js('" + id + "','"+parameter+"')");
mWebView.loadUrl("javascript:_native2js('" + id + "','"+parameter+"')");
}
}
}
// });
// }
}
... ...
... ... @@ -54,27 +54,22 @@ public class XdyPlayerCore {
// if (isPlaying) {
// return;
// }
if(libPlayer==null){
if(libPlayer==null)
libPlayer = new SmartPlayerJni();
}
//TODO
if(playerHandle==0) {
playerHandle = libPlayer.SmartPlayerInit(mContext);
}
XdyLogUtil.e(TAG, "playVideoId" + playerHandle);
if (playerHandle == 0) {
XdyLogUtil.e(TAG, "视频初始化失败 ");
return;
}
libPlayer.SetSmartPlayerEventCallback(playerHandle, smartEventCallback);
// libPlayer.SetSmartPlayerEventCallback(playerHandle, new EventHande());
if(surfaceView!=null) {
libPlayer.SmartPlayerSetSurface(playerHandle, surfaceView);
}
libPlayer.SmartPlayerSetSurface(playerHandle, surfaceView);
libPlayer.SmartPlayerSetAudioOutputType(playerHandle, 0);
libPlayer.SmartPlayerSetBuffer(playerHandle, 200);
int isPlaySuccessful = libPlayer.SmartPlayerStartPlayback(playerHandle, rtmpUrl);
if (isPlaySuccessful != 0) {
XdyLogUtil.e(TAG, "视频播放失败" + rtmpUrl);
}
// XdySdk.getXdyInstance().notifyObserver("video_success","");
XdyLogUtil.e(TAG, "视频播放成功" + rtmpUrl);
// isPlaying = true;
... ...
... ... @@ -68,6 +68,7 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
// if(isStart){
// return;
// }
mPreviewRunning = false;
this.mSurfaceView=pubSurfaceView;
if (xdyPublisher == null) {
xdyPublisher = new SmartPublisherJni();
... ... @@ -162,6 +163,7 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
@SuppressLint("NewApi")
private Camera openCamera(int type) {
int frontIndex = -1;
int backIndex = -1;
int cameraCount = Camera.getNumberOfCameras();
Log.i(TAG, "cameraCount: " + cameraCount);
... ... @@ -171,12 +173,18 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
frontIndex = cameraIndex;
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
backIndex = cameraIndex;
}
}
currentCameraType = type; //type 是等于1的
currentCameraType = type;
if (type == FRONT && frontIndex != -1) {
curCameraIndex = frontIndex;
return Camera.open(frontIndex);
} else if (type == BACK && backIndex != -1) {
curCameraIndex = backIndex;
return Camera.open(backIndex);
}
return null;
}
... ... @@ -413,6 +421,10 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
if (xdyPublisher != null) {
xdyPublisher.SmartPublisherStop();
}
if(mCamera!=null){
mCamera.release();//释放相机资源
mCamera=null;
}
XdyLogUtil.e("audio","执行");
isStart=false;
}
... ...
... ... @@ -9,8 +9,11 @@ import android.util.Log;
import android.view.SurfaceView;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.bean.AudioPlayBean;
import com.mang.xdy.bean.ErrorCodeEntity;
import com.mang.xdy.bean.GetPublishPathReceiveBean;
import com.mang.xdy.bean.PublisherSuccessEntity;
import com.mang.xdy.bean.PublisherVideoReturnBean;
import com.mang.xdy.bean.VideoPlayBean;
import com.mang.xdy.cache.ACache;
... ... @@ -48,11 +51,14 @@ public class XdySdk implements SubjectListener{
private static MsgManage mMsgManage;
public static String TAG="xdysdk";
private String currentPlayId="";
/*缓存管理*/
private static ACache aCache;
//TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏)
private SurfaceView mSurfaceView;
private Activity mActivity;
/*是否正在推流,mcu自动断开的时候使用,推流成功后才表示正在使用*/
private boolean isPublisher=false;
private List<ObserverListener> observerListenerList=new ArrayList<ObserverListener>();
@Override
... ... @@ -63,6 +69,7 @@ public class XdySdk implements SubjectListener{
@Override
public void notifyObserver(String type, String parameter) {
handleData(type,parameter);
XdyLogUtil.e("notifyObserVer","type:"+type+" parameter:"+parameter);
... ... @@ -148,7 +155,7 @@ public class XdySdk implements SubjectListener{
* @param type 类型
* @param argument 参数
*/
public void api(String type,String argument){
public void api(final String type, final String argument){
judgeCore();
//再次停止播放器
switch (type){
... ... @@ -162,49 +169,17 @@ public class XdySdk implements SubjectListener{
//停止播放audio()
case"stopVideo":
//停止播放video( 停止播放:根据api)
onPlayStop();
// onPlayStop();
break;
}
mXdyJsCore.native2js(type, argument);
}
handler.post(new Runnable() {
@Override
public void run() {
mXdyJsCore.native2js(type, argument);
}
});
// /**
// * 重载推流
// * @param type
// * @param rtmpUrl
// * @param surfaceView
// * @param activity
// */
// public void api(String type, String rtmpUrl, SurfaceView surfaceView, Activity activity, SmartEventCallback smartEventCallback) {
// judgeString(type);
// judgeUrl(rtmpUrl);
// switch (type) {
// case Constants.PLAY_AUDIO:
// //播放音频
// mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,null, activity);
// mXdyPlayerCore.playAudio(rtmpUrl,smartEventCallback);
// break;
// case Constants.PLAY_VIDEO:
// //播放视频
// mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,surfaceView, activity);
// mXdyPlayerCore.playVideo(rtmpUrl, surfaceView,smartEventCallback);
// break;
// case Constants.PUBLISH_VIDEO:
// //打开推流视频
// //用户打开推流的时候应该主动去获取推流地址
// if(mXdyPublisherCore==null)
// mXdyPublisherCore=new XdyPublisherCore(1,1,activity);
// mXdyPublisherCore.publisher(rtmpUrl,surfaceView,smartEventCallback);
// break;
// case Constants.PUBLISH_AUDIO:
// //只推送音频
// if(mXdyPublisherCore==null)
// mXdyPublisherCore=new XdyPublisherCore(1,0,activity);
// mXdyPublisherCore.publisherAudio(rtmpUrl,smartEventCallback);
// break;
//
// }
// }
}
/**
* 测试封装 用过时标识区分
... ... @@ -230,6 +205,7 @@ public class XdySdk implements SubjectListener{
XdyLogUtil.e(TAG,"Play Audio Can not find this AudioId");
return;
}
currentPlayId=mediaId;
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(json_audio,AudioPlayBean.class);
if(audioPlayBean!=null) {
if(mXdyPlayerCore==null) {
... ... @@ -252,6 +228,7 @@ public class XdySdk implements SubjectListener{
XdyLogUtil.e(TAG,"Play Video Can not find this VideoId");
return;
}
currentPlayId=mediaId;
VideoPlayBean videoPlayBean=JsonUtil.parseJsonToBean(json_video,VideoPlayBean.class);
if(videoPlayBean!=null){
if(mXdyPlayerCore==null) {
... ... @@ -281,9 +258,6 @@ public class XdySdk implements SubjectListener{
getPublishPathAudio();
mSurfaceView=surfaceView;
mActivity=activity;
// if(mXdyPublisherCore==null)
// mXdyPublisherCore=new XdyPublisherCore(1,0,rtmpUrl,surfaceView,activity);
// mXdyPublisherCore.publisherAudio(rtmpUrl,smartEventCallback);
break;
}
... ... @@ -339,17 +313,18 @@ public class XdySdk implements SubjectListener{
*/
switch (type) {
case Constants.GET_VIDEO_PUBLISH_PATH:
case Constants.VIDEO_GET_PUBLISH_PATH:
//推流地址的返回值拿到正确的推流地址直接开始推流
//打开推流视频
String publishPath=XdyStringUtils.stringToJson(response);
// String publishPath=XdyStringUtils.stringToJson(response);
String publishPath=response;
GetPublishPathReceiveBean getPublishPathReceiveBean=JsonUtil.parseJsonToBean(publishPath,GetPublishPathReceiveBean.class);
if(getPublishPathReceiveBean!=null) {
//可以推流了
if (getPublishPathReceiveBean.getCode() == 0) {
//TODO 成功存储数据 文档上有mediaId ,实际获取没有,下个版本会加上,现在暂时用getvideopublishpath 做关键字
String video_url = getPublishPathReceiveBean.getPublishUrl();
aCache.put(Constants.GET_VIDEO_PUBLISH_PATH, video_url);
aCache.put(Constants.VIDEO_GET_PUBLISH_PATH, video_url);
//判断
if (mSurfaceView == null) {
//todo 输出提示
... ... @@ -359,12 +334,13 @@ public class XdySdk implements SubjectListener{
//TODo 给出提示
return;
}
if (mXdyPublisherCore == null)
if (mXdyPublisherCore == null) {
mXdyPublisherCore = new XdyPublisherCore(1, 1, mActivity);
}
mXdyPublisherCore.publisher(video_url,mSurfaceView, new EventHande());
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
PlayerUtils.setPublishSendSuccessVideo(video_url);
setPublishSendSuccessVideo(video_url);
}else{
mMsgManage.getPublishVideoPathError();
}
... ... @@ -373,7 +349,7 @@ public class XdySdk implements SubjectListener{
mMsgManage.getPublishVideoPathError();
}
break;
case Constants.GET_AUDIO_PUBLISH_PATH:
case Constants.AUDIO_GET_PUBLISH_PATH:
//推流地址的返回值拿到正确的推流地址直接开始推流
//打开推流视频
String audio_path=XdyStringUtils.stringToJson(response);
... ... @@ -386,11 +362,12 @@ public class XdySdk implements SubjectListener{
//判断
if (mSurfaceView==null){
//todo 输出提示
XdyLogUtil.e(TAG,"surfaceView is null");
return;
}
if(mActivity==null){
//TODo 给出提示
XdyLogUtil.e(TAG,"activity is null");
return;
}
if(mXdyPublisherCore==null)
... ... @@ -412,18 +389,18 @@ public class XdySdk implements SubjectListener{
if(publisherVideoReturnBean_audio!=null&&publisherVideoReturnBean_audio.getCode()==0){
XdyLogUtil.e(TAG,"后台成功接收到,推流的地址");
//TODO
isPublisher=true;
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
}else{
//TODO
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
}
break;
case Constants.PUBLISH_VIDEO:
case "video_publish_result":
//接收发送推流地址给后台返回的信息
String publishReplay=response;
XdyLogUtil.e(TAG,"后台成功接收到,返回值"+XdyStringUtils.stringToJson(publishReplay));
PublisherVideoReturnBean publisherVideoReturnBean=JsonUtil.parseJsonToBean(XdyStringUtils.stringToJson(publishReplay),PublisherVideoReturnBean.class);
PublisherVideoReturnBean publisherVideoReturnBean=JsonUtil.parseJsonToBean(publishReplay,PublisherVideoReturnBean.class);
if(publisherVideoReturnBean!=null&&publisherVideoReturnBean.getCode()==0){
XdyLogUtil.e(TAG,"后台成功接收到,推流的地址");
//TODO
... ... @@ -452,6 +429,23 @@ public class XdySdk implements SubjectListener{
handleListener(type,audioPlayBean.getMediaId()+"");
}
break;
case Constants.ERROR_CODE:
ErrorCodeEntity errorCodeEntity =JsonUtil.parseJsonToBean(response,ErrorCodeEntity.class);
if(errorCodeEntity!=null){
if(errorCodeEntity.getCode()==Constants.LEAVE_CLASS_CODE){
/**
* 正在直播的时候mcu无故断开,需要重新连接
*/
//mcu 断开,页面也断开,用户需要重新调用
// if(isPublisher) {
// onPublisherStop();
// api("publishVideo", "", mSurfaceView, mActivity);
// }
onPublisherStop();
}
}
handleListener(type,response);
break;
default:{
handleListener(type,response);
}
... ... @@ -473,14 +467,33 @@ public class XdySdk implements SubjectListener{
o.observerUpData(type,parameter);
}
}
/**
* 销毁播放音视频
* @param id
* @return
*/
public boolean onPlayStop(String id){
if(currentPlayId.equals(id)) {
if (mXdyPlayerCore != null) {
mXdyPlayerCore.onStopPlay();
// mXdyPlayerCore = null;
}
return true;
}
return false;
}
/**
* 播放视频音频销毁方法
* 结束时调用
*/
public void onPlayStop(){
if(mXdyPlayerCore!=null) {
mXdyPlayerCore.onStopPlay();
mXdyPlayerCore=null;
public void onPlayDestroy(){
if (mXdyPlayerCore != null) {
mXdyPlayerCore.onStopPlay();
mXdyPlayerCore = null;
}
}
/**
... ... @@ -491,12 +504,16 @@ public class XdySdk implements SubjectListener{
mXdyPublisherCore.onStopPublisher();
mXdyPublisherCore=null;
}
if(mSurfaceView!=null){
mSurfaceView=null;
}
if(mActivity!=null){
mActivity=null;
//如果正在推流,msurfaceView ,mActivity不清空
if(!isPublisher) {
if (mSurfaceView != null) {
mSurfaceView = null;
}
if (mActivity != null) {
mActivity = null;
}
}
// isPublisher=false;
}
class EventHande implements SmartEventCallback {
... ... @@ -505,7 +522,6 @@ public class XdySdk implements SubjectListener{
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
mMsgManage.getPublishVideoPathError();
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
... ... @@ -517,15 +533,18 @@ public class XdySdk implements SubjectListener{
Log.i(TAG, "连接成功。。");
//TODO //如果连接成功发送连接成功信息,判断的方式有待考虑
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
// XdySdk.getXdyInstance().notifyObserver("video_success","");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
XdySdk.getXdyInstance().notifyObserver("play_stop",currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
XdySdk.getXdyInstance().notifyObserver("video_success",currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
... ... @@ -533,4 +552,33 @@ public class XdySdk implements SubjectListener{
}
}
/**
* 向后台发送推流数据(Auido)成功信息
* @param url
*/
public static void setPublishSendSuccessAudio(String url) {
PublisherSuccessEntity publisherEntity = new PublisherSuccessEntity();
if (!TextUtils.isEmpty(url)) {
publisherEntity.setPublishUrl(url);
final String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流成功", "" + pamp);
XdySdk.getXdyInstance().api(Constants.PUBLISH_AUDIO, pamp);
}
}
/**
* 向后台发送推流(Video)成功的信息
* @param url
*/
public static void setPublishSendSuccessVideo(String url) {
PublisherSuccessEntity publisherEntity = new PublisherSuccessEntity();
if (!TextUtils.isEmpty(url)) {
publisherEntity.setPublishUrl(url);
final String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流线程setPublishSendSuccessVideo:",Thread.currentThread().getId()+"");
XdySdk.getXdyInstance().api(Constants.PUBLISH_VIDEO, pamp);
}
}
}
... ...
package com.mang.xdy.utils;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.PopupWindow;
import android.widget.TextView;
public class UIUtils {
/**
* @param window 需要关闭的window对象
* @brief 关闭PopupWindow的方法
*/
public static void closePopupWindow(PopupWindow window) {
if (window != null && window.isShowing())
window.dismiss();
}
/**
* @param dialog 需要关闭的dialog的对象
* @brief 关闭Dialog的方法
*/
public static void closeDialog(Dialog dialog) {
//关闭这个dialog还得看是否是当前的Activity
if (dialog != null && dialog.isShowing())
dialog.dismiss();
}
/**
* 关闭软键盘
* @param mEditText 输入框
* @param mContext 上下文
*/
public static void closeKeybord(View mEditText, Context mContext) {
if (mEditText != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}
}
/**
* 为了减少findViewById太冗余,直接在Activity提供该方法
* @param id
* @param <T>
* @return
*/
public static <T extends View> T $(View view, int id) {
return (T) view.findViewById(id);
}
public static String getViewText(TextView view) {
return view.getText().toString().trim();
}
}
... ...