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