Commit 99b0acb47f3d8d4253e3ef5996cd5602d08882f8
1 parent
757f8a97
1 优化网络请求
Showing
31 changed files
with
2431 additions
and
212 deletions
app/strike/build.gradle
| @@ -180,7 +180,7 @@ dependencies { | @@ -180,7 +180,7 @@ dependencies { | ||
| 180 | implementation project(path: ':module:pedometer') | 180 | implementation project(path: ':module:pedometer') |
| 181 | implementation project(path: ':module:shanghaishop') | 181 | implementation project(path: ':module:shanghaishop') |
| 182 | implementation project(path: ':library_baidumap') | 182 | implementation project(path: ':library_baidumap') |
| 183 | - | 183 | + implementation 'com.jakewharton.rxbinding3:rxbinding:3.1.0' |
| 184 | // implementation project(path: ':core:util') | 184 | // implementation project(path: ':core:util') |
| 185 | // implementation project(path: ':core:encipher') | 185 | // implementation project(path: ':core:encipher') |
| 186 | // implementation project(path: ':cloud:user') | 186 | // implementation project(path: ':cloud:user') |
app/strike/src/main/java/com/cnlive/strike/demo/activity/DemoMvpActivity.java
| @@ -5,22 +5,31 @@ import android.content.Intent; | @@ -5,22 +5,31 @@ import android.content.Intent; | ||
| 5 | import android.os.Handler; | 5 | import android.os.Handler; |
| 6 | import android.os.Message; | 6 | import android.os.Message; |
| 7 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
| 8 | +import android.view.LayoutInflater; | ||
| 8 | import android.view.View; | 9 | import android.view.View; |
| 10 | +import android.widget.LinearLayout; | ||
| 11 | +import android.widget.TextView; | ||
| 9 | 12 | ||
| 10 | import androidx.annotation.NonNull; | 13 | import androidx.annotation.NonNull; |
| 11 | 14 | ||
| 12 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 15 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 13 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | 16 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; |
| 14 | -import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 15 | import com.cnlive.core.libs.base.util.QMUITipDialogUtil; | 17 | import com.cnlive.core.libs.base.util.QMUITipDialogUtil; |
| 18 | +import com.cnlive.core.network.HttpConn; | ||
| 19 | +import com.cnlive.core.network.NetCallBack; | ||
| 20 | +import com.cnlive.core.network.model.BaseResult; | ||
| 21 | +import com.cnlive.core.network.request.BaseRequest; | ||
| 22 | +import com.cnlive.libs.wjjpay.pay.WjjPay; | ||
| 16 | import com.cnlive.moudle.collectionTrace.ui.activity.RaceListActivity; | 23 | import com.cnlive.moudle.collectionTrace.ui.activity.RaceListActivity; |
| 17 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; | 24 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 18 | import com.cnlive.moudle.pedometer.ui.activity.RunLineActivity; | 25 | import com.cnlive.moudle.pedometer.ui.activity.RunLineActivity; |
| 19 | -import com.cnlive.strike.MainActivity; | 26 | +import com.cnlive.strike.MyApp; |
| 20 | import com.cnlive.strike.R; | 27 | import com.cnlive.strike.R; |
| 21 | import com.cnlive.strike.databinding.ActivityDemoMvpMainBinding; | 28 | import com.cnlive.strike.databinding.ActivityDemoMvpMainBinding; |
| 22 | import com.cnlive.strike.demo.activity.presenter.DemoActivityPresenter; | 29 | import com.cnlive.strike.demo.activity.presenter.DemoActivityPresenter; |
| 23 | import com.cnlive.strike.demo.activity.view.DemoActivityView; | 30 | import com.cnlive.strike.demo.activity.view.DemoActivityView; |
| 31 | +import com.cnlive.strike.network.api.ApiService; | ||
| 32 | +import com.cnlive.strike.network.bean.TestBean; | ||
| 24 | import com.cnlive.strike.user.auth.UserService; | 33 | import com.cnlive.strike.user.auth.UserService; |
| 25 | import com.cnlive.strike.user.ui.activity.FirstLoginActivity; | 34 | import com.cnlive.strike.user.ui.activity.FirstLoginActivity; |
| 26 | import com.cnlive.strike.user.ui.activity.LoginActivity; | 35 | import com.cnlive.strike.user.ui.activity.LoginActivity; |
| @@ -53,7 +62,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | @@ -53,7 +62,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | ||
| 53 | @Override | 62 | @Override |
| 54 | protected void initView() { | 63 | protected void initView() { |
| 55 | super.initView(); | 64 | super.initView(); |
| 56 | - //登录页 | 65 | +// //登录页 |
| 57 | binding.btnLogin.setOnClickListener(new View.OnClickListener() { | 66 | binding.btnLogin.setOnClickListener(new View.OnClickListener() { |
| 58 | @Override | 67 | @Override |
| 59 | public void onClick(View v) { | 68 | public void onClick(View v) { |
| @@ -168,7 +177,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | @@ -168,7 +177,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | ||
| 168 | requestPermission(permission, new OnPermissionResponseListener() { | 177 | requestPermission(permission, new OnPermissionResponseListener() { |
| 169 | @Override | 178 | @Override |
| 170 | public void onSuccess(String[] permissions) { | 179 | public void onSuccess(String[] permissions) { |
| 171 | - | 180 | + QMUITipDialogUtil.successDialog(me, "成功"); |
| 172 | } | 181 | } |
| 173 | 182 | ||
| 174 | @Override | 183 | @Override |
| @@ -280,6 +289,78 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | @@ -280,6 +289,78 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | ||
| 280 | }); | 289 | }); |
| 281 | } | 290 | } |
| 282 | }); | 291 | }); |
| 292 | + //全局通知,顶部 | ||
| 293 | + binding.btnTopView.setOnClickListener(new View.OnClickListener() { | ||
| 294 | + @Override | ||
| 295 | + public void onClick(View v) { | ||
| 296 | + showTopView(); | ||
| 297 | + } | ||
| 298 | + }); | ||
| 299 | + //全局通知,底部 | ||
| 300 | + binding.btnBottomView.setOnClickListener(new View.OnClickListener() { | ||
| 301 | + @Override | ||
| 302 | + public void onClick(View v) { | ||
| 303 | + showBottomView(); | ||
| 304 | + } | ||
| 305 | + }); | ||
| 306 | + //修改支付秘密码 | ||
| 307 | + binding.btnPay.setOnClickListener(new View.OnClickListener() { | ||
| 308 | + @Override | ||
| 309 | + public void onClick(View v) { | ||
| 310 | + WjjPay.setPassword("", "", new NetCallBack<BaseResult>() { | ||
| 311 | + @Override | ||
| 312 | + public void onRequestState(int state) { | ||
| 313 | + if (state == HttpConn.ON_START) { | ||
| 314 | + QMUITipDialogUtil.loadingDialog(me, "请稍后"); | ||
| 315 | + } else if (state == HttpConn.ON_END) { | ||
| 316 | + QMUITipDialogUtil.dismessDialog(); | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + @Override | ||
| 321 | + public void onSuccess(BaseResult data) { | ||
| 322 | + QMUITipDialogUtil.successDialog(me, data.getMessage()); | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + @Override | ||
| 326 | + public void onFailure(String errCode, String errMsg) { | ||
| 327 | + QMUITipDialogUtil.failedDialog(me, errMsg); | ||
| 328 | + } | ||
| 329 | + }); | ||
| 330 | + } | ||
| 331 | + }); | ||
| 332 | + //连接第三方接口 | ||
| 333 | + binding.btnThird.setOnClickListener(new View.OnClickListener() { | ||
| 334 | + @Override | ||
| 335 | + public void onClick(View v) { | ||
| 336 | + HttpConn.action( | ||
| 337 | + BaseRequest.init() | ||
| 338 | + .setUrl("http://gank.io/api/data/") | ||
| 339 | + .service(ApiService.class) | ||
| 340 | + .getTest(), new NetCallBack<TestBean>() { | ||
| 341 | + @Override | ||
| 342 | + public void onRequestState(int state) { | ||
| 343 | + if (state == HttpConn.ON_START) { | ||
| 344 | + QMUITipDialogUtil.loadingDialog(me, "请稍后"); | ||
| 345 | + } else if (state == HttpConn.ON_END) { | ||
| 346 | + QMUITipDialogUtil.dismessDialog(); | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + @Override | ||
| 351 | + public void onSuccess(TestBean data) { | ||
| 352 | + QMUITipDialogUtil.successDialog(me, "成功"+data.getResults().size()); | ||
| 353 | + } | ||
| 354 | + | ||
| 355 | + @Override | ||
| 356 | + public void onFailure(String errCode, String errMsg) { | ||
| 357 | + QMUITipDialogUtil.failedDialog(me, errMsg); | ||
| 358 | + | ||
| 359 | + } | ||
| 360 | + } | ||
| 361 | + ); | ||
| 362 | + } | ||
| 363 | + }); | ||
| 283 | } | 364 | } |
| 284 | 365 | ||
| 285 | @Subscribe(threadMode = ThreadMode.MAIN) | 366 | @Subscribe(threadMode = ThreadMode.MAIN) |
| @@ -291,7 +372,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | @@ -291,7 +372,7 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | ||
| 291 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 372 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| 292 | super.onReceiveActHandleMessage(msg); | 373 | super.onReceiveActHandleMessage(msg); |
| 293 | if (msg.what == 123) { | 374 | if (msg.what == 123) { |
| 294 | - QMUITipDialogUtil.textDialog(me, "发送的一条空消息", 2); | 375 | + QMUITipDialogUtil.textDialog(me, "发送的一条空消息"); |
| 295 | } | 376 | } |
| 296 | } | 377 | } |
| 297 | 378 | ||
| @@ -304,4 +385,69 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | @@ -304,4 +385,69 @@ public class DemoMvpActivity extends BaseActivity<DemoActivityView, DemoActivity | ||
| 304 | // QMUITipDialogUtil.textDialog(me, (String) data, 2); | 385 | // QMUITipDialogUtil.textDialog(me, (String) data, 2); |
| 305 | } | 386 | } |
| 306 | } | 387 | } |
| 388 | + | ||
| 389 | + | ||
| 390 | + public void showTopView() { | ||
| 391 | + /*创建提示消息View*/ | ||
| 392 | + View view = LayoutInflater.from(this).inflate(R.layout.view_top_msg, null); | ||
| 393 | + if (null == view) { | ||
| 394 | + return; | ||
| 395 | + } | ||
| 396 | + LinearLayout ll_ignore = view.findViewById(R.id.ll_ignore); | ||
| 397 | + LinearLayout ll_lookUp = view.findViewById(R.id.ll_lookUp); | ||
| 398 | + TextView tv_tip = view.findViewById(R.id.tv_tip); | ||
| 399 | + //忽略 | ||
| 400 | + ll_ignore.setOnClickListener(new View.OnClickListener() { | ||
| 401 | + @Override | ||
| 402 | + public void onClick(View v) { | ||
| 403 | + if (null != view) { | ||
| 404 | + MyApp.getInstance().hideTopView(view); | ||
| 405 | + } | ||
| 406 | + } | ||
| 407 | + }); | ||
| 408 | + //查看 | ||
| 409 | + ll_lookUp.setOnClickListener(new View.OnClickListener() { | ||
| 410 | + @Override | ||
| 411 | + public void onClick(View v) { | ||
| 412 | + if (null != view) { | ||
| 413 | + MyApp.getInstance().hideTopView(view); | ||
| 414 | + } | ||
| 415 | + } | ||
| 416 | + }); | ||
| 417 | + | ||
| 418 | + /*添加View到当前显示的Activity*/ | ||
| 419 | + MyApp.getInstance().showTopView(view); | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + public void showBottomView() { | ||
| 423 | + /*创建提示消息View*/ | ||
| 424 | + View view = LayoutInflater.from(this).inflate(R.layout.view_top_msg, null); | ||
| 425 | + if (null == view) { | ||
| 426 | + return; | ||
| 427 | + } | ||
| 428 | + LinearLayout ll_ignore = view.findViewById(R.id.ll_ignore); | ||
| 429 | + LinearLayout ll_lookUp = view.findViewById(R.id.ll_lookUp); | ||
| 430 | + TextView tv_tip = view.findViewById(R.id.tv_tip); | ||
| 431 | + //忽略 | ||
| 432 | + ll_ignore.setOnClickListener(new View.OnClickListener() { | ||
| 433 | + @Override | ||
| 434 | + public void onClick(View v) { | ||
| 435 | + if (null != view) { | ||
| 436 | + MyApp.getInstance().hideBottomView(view); | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + }); | ||
| 440 | + //查看 | ||
| 441 | + ll_lookUp.setOnClickListener(new View.OnClickListener() { | ||
| 442 | + @Override | ||
| 443 | + public void onClick(View v) { | ||
| 444 | + if (null != view) { | ||
| 445 | + MyApp.getInstance().hideBottomView(view); | ||
| 446 | + } | ||
| 447 | + } | ||
| 448 | + }); | ||
| 449 | + | ||
| 450 | + /*添加View到当前显示的Activity*/ | ||
| 451 | + MyApp.getInstance().showBottomView(view); | ||
| 452 | + } | ||
| 307 | } | 453 | } |
app/strike/src/main/java/com/cnlive/strike/imgutil/ImgActivity.java
| @@ -23,6 +23,7 @@ import com.cnlive.core.imageload.preview.PreviewImageViewActivity; | @@ -23,6 +23,7 @@ import com.cnlive.core.imageload.preview.PreviewImageViewActivity; | ||
| 23 | import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo; | 23 | import com.cnlive.core.imageload.preview.model.ImagePreviewShowInfo; |
| 24 | import com.cnlive.core.imageload.preview.model.PreviewData; | 24 | import com.cnlive.core.imageload.preview.model.PreviewData; |
| 25 | import com.cnlive.core.imageload.util.DownLoadImageService; | 25 | import com.cnlive.core.imageload.util.DownLoadImageService; |
| 26 | +import com.cnlive.core.libs.base.util.GlideUtil; | ||
| 26 | import com.cnlive.strike.R; | 27 | import com.cnlive.strike.R; |
| 27 | import com.cnlive.strike.user.auth.UserService; | 28 | import com.cnlive.strike.user.auth.UserService; |
| 28 | 29 | ||
| @@ -175,7 +176,6 @@ public class ImgActivity extends AppCompatActivity { | @@ -175,7 +176,6 @@ public class ImgActivity extends AppCompatActivity { | ||
| 175 | ImageLoader.with(this) | 176 | ImageLoader.with(this) |
| 176 | .asserts(ASSERTS_PATH + "timgs.png") | 177 | .asserts(ASSERTS_PATH + "timgs.png") |
| 177 | .into(iv_test8); | 178 | .into(iv_test8); |
| 178 | - | ||
| 179 | ImageLoader.with(this) | 179 | ImageLoader.with(this) |
| 180 | .raw(ANDROID_RESOURCE+getPackageName()+RAW+R.raw.timgs) | 180 | .raw(ANDROID_RESOURCE+getPackageName()+RAW+R.raw.timgs) |
| 181 | .placeHolder(R.mipmap.ic_launcher) | 181 | .placeHolder(R.mipmap.ic_launcher) |
| @@ -191,7 +191,6 @@ public class ImgActivity extends AppCompatActivity { | @@ -191,7 +191,6 @@ public class ImgActivity extends AppCompatActivity { | ||
| 191 | .into(iv_test10); | 191 | .into(iv_test10); |
| 192 | 192 | ||
| 193 | // .asSquare()//正方形 | 193 | // .asSquare()//正方形 |
| 194 | - | ||
| 195 | findViewById(R.id.down).setOnClickListener(view -> { | 194 | findViewById(R.id.down).setOnClickListener(view -> { |
| 196 | ImageLoader.saveImageIntoGallery(new DownLoadImageService(ImgActivity.this, URL1, true, "lala", new ImageDownLoadCallBack() { | 195 | ImageLoader.saveImageIntoGallery(new DownLoadImageService(ImgActivity.this, URL1, true, "lala", new ImageDownLoadCallBack() { |
| 197 | 196 |
app/strike/src/main/java/com/cnlive/strike/network/api/ApiService.java
| @@ -12,6 +12,7 @@ import retrofit2.http.POST; | @@ -12,6 +12,7 @@ import retrofit2.http.POST; | ||
| 12 | import retrofit2.http.QueryMap; | 12 | import retrofit2.http.QueryMap; |
| 13 | 13 | ||
| 14 | public interface ApiService { | 14 | public interface ApiService { |
| 15 | +// 必应每日壁纸 | ||
| 15 | @GET("福利/10/1") | 16 | @GET("福利/10/1") |
| 16 | Observable<TestBean> getTest(); | 17 | Observable<TestBean> getTest(); |
| 17 | 18 |
app/strike/src/main/java/com/cnlive/strike/network/bean/TestBean.java
| 1 | package com.cnlive.strike.network.bean; | 1 | package com.cnlive.strike.network.bean; |
| 2 | 2 | ||
| 3 | +import com.cnlive.core.network.interfaces.IBaseResult; | ||
| 4 | + | ||
| 3 | import java.util.List; | 5 | import java.util.List; |
| 4 | 6 | ||
| 5 | -public class TestBean { | 7 | +public class TestBean implements IBaseResult { |
| 6 | /** | 8 | /** |
| 7 | * error : false | 9 | * error : false |
| 8 | * results : [{"_id":"5ccdbc219d212239df927a93","createdAt":"2019-05-04T16:21:53.523Z","desc":"2019-05-05","publishedAt":"2019-05-04T16:21:59.733Z","source":"web","type":"福利","url":"http://ww1.sinaimg.cn/large/0065oQSqly1g2pquqlp0nj30n00yiq8u.jpg","used":true,"who":"lijinshanmx"},{"_id":"5cc43919fc3326376038d233","createdAt":"2019-04-27T19:12:25.536Z","desc":"2019-04-27","publishedAt":"2019-04-27T19:12:51.865Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1g2hekfwnd7j30sg0x4djy.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c6a4ae99d212226776d3256","createdAt":"2019-02-18T06:04:25.571Z","desc":"2019-02-18","publishedAt":"2019-04-10T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1g0ajj4h6ndj30sg11xdmj.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c2dabdb9d21226e068debf9","createdAt":"2019-01-03T06:29:47.895Z","desc":"2019-01-03","publishedAt":"2019-01-03T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1fytdr77urlj30sg10najf.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c25db189d21221e8ada8664","createdAt":"2018-12-28T08:13:12.688Z","desc":"2018-12-28","publishedAt":"2018-12-28T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1fymj13tnjmj30r60zf79k.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c12216d9d21223f5a2baea2","createdAt":"2018-12-13T09:07:57.2Z","desc":"2018-12-13","publishedAt":"2018-12-13T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fy58bi1wlgj30sg10hguu.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bfe1a5b9d2122309624cbb7","createdAt":"2018-11-28T04:32:27.338Z","desc":"2018-11-28","publishedAt":"2018-11-28T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fxno2dvxusj30sf10nqcm.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bf22fd69d21223ddba8ca25","createdAt":"2018-11-19T03:36:54.950Z","desc":"2018-11-19","publishedAt":"2018-11-19T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fxd7vcz86nj30qo0ybqc1.jpg","used":true,"who":"lijinshanmx"},{"_id":"5be14edb9d21223dd50660f8","createdAt":"2018-11-06T08:20:43.656Z","desc":"2018-11-06","publishedAt":"2018-11-06T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fwyf0wr8hhj30ie0nhq6p.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bcd71979d21220315c663fc","createdAt":"2018-10-22T06:43:35.440Z","desc":"2018-10-22","publishedAt":"2018-10-22T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fwgzx8n1syj30sg15h7ew.jpg","used":true,"who":"lijinshanmx"}] | 10 | * results : [{"_id":"5ccdbc219d212239df927a93","createdAt":"2019-05-04T16:21:53.523Z","desc":"2019-05-05","publishedAt":"2019-05-04T16:21:59.733Z","source":"web","type":"福利","url":"http://ww1.sinaimg.cn/large/0065oQSqly1g2pquqlp0nj30n00yiq8u.jpg","used":true,"who":"lijinshanmx"},{"_id":"5cc43919fc3326376038d233","createdAt":"2019-04-27T19:12:25.536Z","desc":"2019-04-27","publishedAt":"2019-04-27T19:12:51.865Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1g2hekfwnd7j30sg0x4djy.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c6a4ae99d212226776d3256","createdAt":"2019-02-18T06:04:25.571Z","desc":"2019-02-18","publishedAt":"2019-04-10T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1g0ajj4h6ndj30sg11xdmj.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c2dabdb9d21226e068debf9","createdAt":"2019-01-03T06:29:47.895Z","desc":"2019-01-03","publishedAt":"2019-01-03T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1fytdr77urlj30sg10najf.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c25db189d21221e8ada8664","createdAt":"2018-12-28T08:13:12.688Z","desc":"2018-12-28","publishedAt":"2018-12-28T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqly1fymj13tnjmj30r60zf79k.jpg","used":true,"who":"lijinshanmx"},{"_id":"5c12216d9d21223f5a2baea2","createdAt":"2018-12-13T09:07:57.2Z","desc":"2018-12-13","publishedAt":"2018-12-13T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fy58bi1wlgj30sg10hguu.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bfe1a5b9d2122309624cbb7","createdAt":"2018-11-28T04:32:27.338Z","desc":"2018-11-28","publishedAt":"2018-11-28T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fxno2dvxusj30sf10nqcm.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bf22fd69d21223ddba8ca25","createdAt":"2018-11-19T03:36:54.950Z","desc":"2018-11-19","publishedAt":"2018-11-19T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fxd7vcz86nj30qo0ybqc1.jpg","used":true,"who":"lijinshanmx"},{"_id":"5be14edb9d21223dd50660f8","createdAt":"2018-11-06T08:20:43.656Z","desc":"2018-11-06","publishedAt":"2018-11-06T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fwyf0wr8hhj30ie0nhq6p.jpg","used":true,"who":"lijinshanmx"},{"_id":"5bcd71979d21220315c663fc","createdAt":"2018-10-22T06:43:35.440Z","desc":"2018-10-22","publishedAt":"2018-10-22T00:00:00.0Z","source":"web","type":"福利","url":"https://ws1.sinaimg.cn/large/0065oQSqgy1fwgzx8n1syj30sg15h7ew.jpg","used":true,"who":"lijinshanmx"}] |
| @@ -27,6 +29,27 @@ public class TestBean { | @@ -27,6 +29,27 @@ public class TestBean { | ||
| 27 | this.results = results; | 29 | this.results = results; |
| 28 | } | 30 | } |
| 29 | 31 | ||
| 32 | + @Override | ||
| 33 | + public boolean isSuccess() { | ||
| 34 | + return error; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public List<ResultsBean> getData() { | ||
| 39 | + return results; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public String getCode() { | ||
| 44 | + return "-2"; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public String getMessage() { | ||
| 49 | + return "状态码错误"; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + | ||
| 30 | public static class ResultsBean { | 53 | public static class ResultsBean { |
| 31 | /** | 54 | /** |
| 32 | * _id : 5ccdbc219d212239df927a93 | 55 | * _id : 5ccdbc219d212239df927a93 |
app/strike/src/main/res/layout/activity_demo_mvp_main.xml
| @@ -93,6 +93,34 @@ | @@ -93,6 +93,34 @@ | ||
| 93 | android:text="动画特效" /> | 93 | android:text="动画特效" /> |
| 94 | 94 | ||
| 95 | <Button | 95 | <Button |
| 96 | + android:id="@+id/btn_pay" | ||
| 97 | + android:layout_width="match_parent" | ||
| 98 | + android:layout_height="wrap_content" | ||
| 99 | + android:layout_margin="5dp" | ||
| 100 | + android:text="修改支付密码" /> | ||
| 101 | + | ||
| 102 | + <Button | ||
| 103 | + android:id="@+id/btn_third" | ||
| 104 | + android:layout_width="match_parent" | ||
| 105 | + android:layout_height="wrap_content" | ||
| 106 | + android:layout_margin="5dp" | ||
| 107 | + android:text="连接第三方接口" /> | ||
| 108 | + | ||
| 109 | + <Button | ||
| 110 | + android:id="@+id/btn_top_view" | ||
| 111 | + android:layout_width="match_parent" | ||
| 112 | + android:layout_height="wrap_content" | ||
| 113 | + android:layout_margin="5dp" | ||
| 114 | + android:text="全局通知,顶部弹窗" /> | ||
| 115 | + | ||
| 116 | + <Button | ||
| 117 | + android:id="@+id/btn_bottom_view" | ||
| 118 | + android:layout_width="match_parent" | ||
| 119 | + android:layout_height="wrap_content" | ||
| 120 | + android:layout_margin="5dp" | ||
| 121 | + android:text="全局通知,底部弹窗" /> | ||
| 122 | + | ||
| 123 | + <Button | ||
| 96 | android:id="@+id/btn_default_permiss" | 124 | android:id="@+id/btn_default_permiss" |
| 97 | android:layout_width="match_parent" | 125 | android:layout_width="match_parent" |
| 98 | android:layout_height="wrap_content" | 126 | android:layout_height="wrap_content" |
cloud/pay/src/main/java/com/cnlive/libs/wjjpay/pay/WjjPay.java
| @@ -2,6 +2,7 @@ package com.cnlive.libs.wjjpay.pay; | @@ -2,6 +2,7 @@ package com.cnlive.libs.wjjpay.pay; | ||
| 2 | 2 | ||
| 3 | import androidx.annotation.NonNull; | 3 | import androidx.annotation.NonNull; |
| 4 | 4 | ||
| 5 | +import com.cnlive.core.libs.base.util.TimerWaitUtil; | ||
| 5 | import com.cnlive.core.network.HttpConn; | 6 | import com.cnlive.core.network.HttpConn; |
| 6 | import com.cnlive.core.network.NetCallBack; | 7 | import com.cnlive.core.network.NetCallBack; |
| 7 | import com.cnlive.core.network.model.BaseResult; | 8 | import com.cnlive.core.network.model.BaseResult; |
| @@ -15,6 +16,7 @@ import java.security.MessageDigest; | @@ -15,6 +16,7 @@ import java.security.MessageDigest; | ||
| 15 | import java.security.NoSuchAlgorithmException; | 16 | import java.security.NoSuchAlgorithmException; |
| 16 | import java.util.HashMap; | 17 | import java.util.HashMap; |
| 17 | import java.util.Map; | 18 | import java.util.Map; |
| 19 | +import java.util.concurrent.TimeUnit; | ||
| 18 | 20 | ||
| 19 | import io.reactivex.Observable; | 21 | import io.reactivex.Observable; |
| 20 | import io.reactivex.ObservableSource; | 22 | import io.reactivex.ObservableSource; |
cloud/user/src/main/java/com/cnlive/strike/user/ui/activity/LoginDialogActivity.java
| @@ -6,9 +6,7 @@ import android.app.ProgressDialog; | @@ -6,9 +6,7 @@ import android.app.ProgressDialog; | ||
| 6 | import android.content.Context; | 6 | import android.content.Context; |
| 7 | import android.content.Intent; | 7 | import android.content.Intent; |
| 8 | import android.net.Uri; | 8 | import android.net.Uri; |
| 9 | -import android.os.Bundle; | ||
| 10 | import android.text.TextUtils; | 9 | import android.text.TextUtils; |
| 11 | -import android.util.Log; | ||
| 12 | import android.view.WindowManager; | 10 | import android.view.WindowManager; |
| 13 | 11 | ||
| 14 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
| @@ -17,7 +15,7 @@ import com.alibaba.android.arouter.facade.annotation.Route; | @@ -17,7 +15,7 @@ import com.alibaba.android.arouter.facade.annotation.Route; | ||
| 17 | import com.cnlive.core.libs.base.application.AppConfig; | 15 | import com.cnlive.core.libs.base.application.AppConfig; |
| 18 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 16 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 19 | import com.cnlive.core.libs.base.util.DoublePressed; | 17 | import com.cnlive.core.libs.base.util.DoublePressed; |
| 20 | -import com.cnlive.core.libs.base.util.ScreenUtil; | 18 | +import com.cnlive.core.libs.base.util.ScreenUtils; |
| 21 | import com.cnlive.strike.user.R; | 19 | import com.cnlive.strike.user.R; |
| 22 | import com.cnlive.strike.user.databinding.ActivityLoginDialogBinding; | 20 | import com.cnlive.strike.user.databinding.ActivityLoginDialogBinding; |
| 23 | import com.cnlive.strike.user.frame.data.QuickLoginData; | 21 | import com.cnlive.strike.user.frame.data.QuickLoginData; |
| @@ -82,7 +80,7 @@ public class LoginDialogActivity extends BaseActivity<LoginDialogView, LoginDial | @@ -82,7 +80,7 @@ public class LoginDialogActivity extends BaseActivity<LoginDialogView, LoginDial | ||
| 82 | super.initView(); | 80 | super.initView(); |
| 83 | WindowManager.LayoutParams p = getWindow().getAttributes(); | 81 | WindowManager.LayoutParams p = getWindow().getAttributes(); |
| 84 | p.height = WindowManager.LayoutParams.MATCH_PARENT; | 82 | p.height = WindowManager.LayoutParams.MATCH_PARENT; |
| 85 | - p.width = (ScreenUtil.getScreenWidth(this) - dp2px(88)); | 83 | + p.width = (ScreenUtils.getScreenWidth(this) - dp2px(88)); |
| 86 | getWindow().setAttributes(p); | 84 | getWindow().setAttributes(p); |
| 87 | // initThreeLogin(); | 85 | // initThreeLogin(); |
| 88 | uri = UserAction.getUri(this); | 86 | uri = UserAction.getUri(this); |
cloud/user/src/main/java/com/cnlive/strike/user/util/AlertDialogUtils.java
| @@ -8,7 +8,7 @@ import android.view.ViewGroup; | @@ -8,7 +8,7 @@ import android.view.ViewGroup; | ||
| 8 | import android.widget.TextView; | 8 | import android.widget.TextView; |
| 9 | 9 | ||
| 10 | import com.cnlive.core.libs.base.util.DensityUtils; | 10 | import com.cnlive.core.libs.base.util.DensityUtils; |
| 11 | -import com.cnlive.core.libs.base.util.ScreenUtil; | 11 | +import com.cnlive.core.libs.base.util.ScreenUtils; |
| 12 | import com.cnlive.strike.user.R; | 12 | import com.cnlive.strike.user.R; |
| 13 | 13 | ||
| 14 | 14 | ||
| @@ -26,7 +26,7 @@ public class AlertDialogUtils { | @@ -26,7 +26,7 @@ public class AlertDialogUtils { | ||
| 26 | ((TextView) (view.findViewById(R.id.btn_left))).setTextColor(context.getResources().getColor(leftTextColor)); | 26 | ((TextView) (view.findViewById(R.id.btn_left))).setTextColor(context.getResources().getColor(leftTextColor)); |
| 27 | ((TextView) (view.findViewById(R.id.btn_right))).setText(rightString); | 27 | ((TextView) (view.findViewById(R.id.btn_right))).setText(rightString); |
| 28 | ((TextView) (view.findViewById(R.id.btn_right))).setTextColor(context.getResources().getColor(rightTextColor)); | 28 | ((TextView) (view.findViewById(R.id.btn_right))).setTextColor(context.getResources().getColor(rightTextColor)); |
| 29 | - ViewGroup.LayoutParams vl = new ViewGroup.LayoutParams(ScreenUtil.getScreenWidth(context) - DensityUtils.dp2px(context, 146), ViewGroup.LayoutParams.WRAP_CONTENT); | 29 | + ViewGroup.LayoutParams vl = new ViewGroup.LayoutParams(ScreenUtils.getScreenWidth(context) - DensityUtils.dp2px(context, 146), ViewGroup.LayoutParams.WRAP_CONTENT); |
| 30 | view.findViewById(R.id.btn_left).setOnClickListener(new View.OnClickListener() { | 30 | view.findViewById(R.id.btn_left).setOnClickListener(new View.OnClickListener() { |
| 31 | @Override | 31 | @Override |
| 32 | public void onClick(View v) { | 32 | public void onClick(View v) { |
core/app_qr/src/main/java/com/cnlive/strike/moudle/qr/frame/presenter/SpeakerBindStatePresenter.java
| @@ -43,7 +43,7 @@ public class SpeakerBindStatePresenter extends BasePresenter<SpeakerBindStateVie | @@ -43,7 +43,7 @@ public class SpeakerBindStatePresenter extends BasePresenter<SpeakerBindStateVie | ||
| 43 | 43 | ||
| 44 | @Override | 44 | @Override |
| 45 | public void onSuccess(BaseResult data) { | 45 | public void onSuccess(BaseResult data) { |
| 46 | - ifViewAttached(view -> view.showSucesss(data.getErrorCode(),data.getMessage())); | 46 | + ifViewAttached(view -> view.showSucesss(data.getCode(),data.getMessage())); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | @Override | 49 | @Override |
core/app_qr/src/main/java/com/cnlive/strike/moudle/qr/uitl/AlertDialogUtils.java
| @@ -10,7 +10,7 @@ import android.widget.EditText; | @@ -10,7 +10,7 @@ import android.widget.EditText; | ||
| 10 | import android.widget.TextView; | 10 | import android.widget.TextView; |
| 11 | 11 | ||
| 12 | import com.cnlive.core.libs.base.util.DensityUtils; | 12 | import com.cnlive.core.libs.base.util.DensityUtils; |
| 13 | -import com.cnlive.core.libs.base.util.ScreenUtil; | 13 | +import com.cnlive.core.libs.base.util.ScreenUtils; |
| 14 | import com.cnlive.strike.moudle.qr.R; | 14 | import com.cnlive.strike.moudle.qr.R; |
| 15 | 15 | ||
| 16 | 16 | ||
| @@ -35,7 +35,7 @@ public class AlertDialogUtils { | @@ -35,7 +35,7 @@ public class AlertDialogUtils { | ||
| 35 | ((TextView) (view.findViewById(R.id.btn_left))).setTextColor(context.getResources().getColor(leftTextColor)); | 35 | ((TextView) (view.findViewById(R.id.btn_left))).setTextColor(context.getResources().getColor(leftTextColor)); |
| 36 | ((TextView) (view.findViewById(R.id.btn_right))).setText(rightString); | 36 | ((TextView) (view.findViewById(R.id.btn_right))).setText(rightString); |
| 37 | ((TextView) (view.findViewById(R.id.btn_right))).setTextColor(context.getResources().getColor(rightTextColor)); | 37 | ((TextView) (view.findViewById(R.id.btn_right))).setTextColor(context.getResources().getColor(rightTextColor)); |
| 38 | - ViewGroup.LayoutParams vl = new ViewGroup.LayoutParams(ScreenUtil.getScreenWidth(context) - DensityUtils.dp2px(context, 100), ViewGroup.LayoutParams.WRAP_CONTENT); | 38 | + ViewGroup.LayoutParams vl = new ViewGroup.LayoutParams(ScreenUtils.getScreenWidth(context) - DensityUtils.dp2px(context, 100), ViewGroup.LayoutParams.WRAP_CONTENT); |
| 39 | view.findViewById(R.id.btn_left).setOnClickListener(v -> { | 39 | view.findViewById(R.id.btn_left).setOnClickListener(v -> { |
| 40 | dialog.dismiss(); | 40 | dialog.dismiss(); |
| 41 | }); | 41 | }); |
core/base/src/main/java/com/cnlive/core/libs/base/application/BaseApplication.java
| 1 | package com.cnlive.core.libs.base.application; | 1 | package com.cnlive.core.libs.base.application; |
| 2 | 2 | ||
| 3 | +import android.animation.Animator; | ||
| 4 | +import android.animation.AnimatorListenerAdapter; | ||
| 5 | +import android.animation.AnimatorSet; | ||
| 6 | +import android.animation.ObjectAnimator; | ||
| 7 | +import android.app.Activity; | ||
| 3 | import android.app.Application; | 8 | import android.app.Application; |
| 9 | +import android.os.Bundle; | ||
| 10 | +import android.os.Handler; | ||
| 11 | +import android.view.View; | ||
| 12 | +import android.view.ViewGroup; | ||
| 13 | +import android.view.animation.AccelerateInterpolator; | ||
| 14 | +import android.view.animation.LinearInterpolator; | ||
| 4 | 15 | ||
| 5 | -import com.cnlive.strike.base.BuildConfig; | 16 | +import androidx.annotation.NonNull; |
| 17 | +import androidx.annotation.Nullable; | ||
| 18 | + | ||
| 19 | +import com.cnlive.core.libs.base.util.ScreenUtils; | ||
| 20 | +import com.cnlive.core.libs.base.util.ViewUtils; | ||
| 6 | import com.orhanobut.logger.AndroidLogAdapter; | 21 | import com.orhanobut.logger.AndroidLogAdapter; |
| 7 | import com.orhanobut.logger.FormatStrategy; | 22 | import com.orhanobut.logger.FormatStrategy; |
| 8 | import com.orhanobut.logger.Logger; | 23 | import com.orhanobut.logger.Logger; |
| 9 | import com.orhanobut.logger.PrettyFormatStrategy; | 24 | import com.orhanobut.logger.PrettyFormatStrategy; |
| 10 | 25 | ||
| 11 | -public class BaseApplication extends Application { | 26 | +public class BaseApplication extends Application implements Application.ActivityLifecycleCallbacks { |
| 12 | private static BaseApplication instance; | 27 | private static BaseApplication instance; |
| 28 | + /*当前显示的Activity*/ | ||
| 29 | + private Activity activity; | ||
| 30 | + private View bottomView; | ||
| 31 | + private Handler myHandler = new Handler(); | ||
| 32 | + private final int animDuration = 200;//动画特效显示时间 | ||
| 33 | + private final int delayTime = 5;//弹框消失时间5秒 | ||
| 13 | 34 | ||
| 14 | @Override | 35 | @Override |
| 15 | public void onCreate() { | 36 | public void onCreate() { |
| 16 | super.onCreate(); | 37 | super.onCreate(); |
| 17 | instance = this; | 38 | instance = this; |
| 39 | + this.registerActivityLifecycleCallbacks(this); | ||
| 18 | FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder() | 40 | FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder() |
| 19 | // .showThreadInfo(true) // (Optional) Whether to show thread info or not. Default true | 41 | // .showThreadInfo(true) // (Optional) Whether to show thread info or not. Default true |
| 20 | // .methodCount(5) // (Optional) How many method line to show. Default 2 | 42 | // .methodCount(5) // (Optional) How many method line to show. Default 2 |
| @@ -33,4 +55,243 @@ public class BaseApplication extends Application { | @@ -33,4 +55,243 @@ public class BaseApplication extends Application { | ||
| 33 | public static BaseApplication getInstance() { | 55 | public static BaseApplication getInstance() { |
| 34 | return instance; | 56 | return instance; |
| 35 | } | 57 | } |
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 显示顶部View | ||
| 61 | + * | ||
| 62 | + * @param view 需要显示到Activity的视图 | ||
| 63 | + */ | ||
| 64 | + public void showTopView(View view) { | ||
| 65 | + if (null == view || this.activity == null || this.activity.isFinishing()) { | ||
| 66 | + return; | ||
| 67 | + } | ||
| 68 | + if (null != bottomView) { | ||
| 69 | + hideView(bottomView); | ||
| 70 | + } | ||
| 71 | + bottomView = view; | ||
| 72 | + /*创建属性动画,从下到上*/ | ||
| 73 | + ObjectAnimator bottomToTop = ObjectAnimator.ofFloat(view, "translationY", -ScreenUtils.getStatusBarHeight(activity), ScreenUtils.getStatusBarHeight(activity)) | ||
| 74 | + .setDuration(animDuration); | ||
| 75 | + /*初始化动画组合器*/ | ||
| 76 | + AnimatorSet animator = new AnimatorSet(); | ||
| 77 | + /*组合动画*/ | ||
| 78 | + animator.play(bottomToTop); | ||
| 79 | + animator.setInterpolator(new LinearInterpolator()); | ||
| 80 | + /*添加动画结束回调*/ | ||
| 81 | + animator.addListener(new AnimatorListenerAdapter() { | ||
| 82 | + @Override | ||
| 83 | + public void onAnimationEnd(Animator animation) { | ||
| 84 | + super.onAnimationEnd(animation); | ||
| 85 | + myHandler.removeCallbacksAndMessages(null); | ||
| 86 | + myHandler.postDelayed(new Runnable() { | ||
| 87 | + @Override | ||
| 88 | + public void run() { | ||
| 89 | + if (null == view) { | ||
| 90 | + return; | ||
| 91 | + } | ||
| 92 | + hideTopView(view); | ||
| 93 | + } | ||
| 94 | + }, delayTime * 1000); | ||
| 95 | + } | ||
| 96 | + }); | ||
| 97 | + /*Activity不为空并且没有被释放掉*/ | ||
| 98 | + if (this.activity != null && !this.activity.isFinishing()) { | ||
| 99 | + /*获取Activity顶层视图,并添加自定义View*/ | ||
| 100 | + ((ViewGroup) this.activity.getWindow().getDecorView()).addView(view); | ||
| 101 | + /*启动动画*/ | ||
| 102 | + animator.start(); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public void hideTopView(View view) { | ||
| 108 | + if (null == view) { | ||
| 109 | + return; | ||
| 110 | + } | ||
| 111 | + myHandler.removeCallbacksAndMessages(null); | ||
| 112 | + if (this.activity != null && !this.activity.isFinishing()) { | ||
| 113 | + /*获取Activity顶层视图*/ | ||
| 114 | + ViewGroup root = ((ViewGroup) this.activity.getWindow().getDecorView()); | ||
| 115 | + if (null == root) { | ||
| 116 | + return; | ||
| 117 | + } | ||
| 118 | + /*如果Activity中存在View对象则删除*/ | ||
| 119 | + ObjectAnimator bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getStatusBarHeight(activity), -ScreenUtils.getStatusBarHeight(activity)) | ||
| 120 | + .setDuration(animDuration); | ||
| 121 | + /*初始化动画组合器*/ | ||
| 122 | + AnimatorSet animator = new AnimatorSet(); | ||
| 123 | + animator.play(bottomToTop); | ||
| 124 | + animator.setInterpolator(new AccelerateInterpolator()); | ||
| 125 | + /*添加动画结束回调*/ | ||
| 126 | + animator.addListener(new AnimatorListenerAdapter() { | ||
| 127 | + @Override | ||
| 128 | + public void onAnimationEnd(Animator animation) { | ||
| 129 | + super.onAnimationEnd(animation); | ||
| 130 | + /*如果Activity中存在View对象则删除*/ | ||
| 131 | + if (root.indexOfChild(view) != -1) { | ||
| 132 | + /*从顶层视图中删除*/ | ||
| 133 | + root.removeView(view); | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + }); | ||
| 137 | + /*启动动画*/ | ||
| 138 | + animator.start(); | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 显示底部View | ||
| 144 | + * | ||
| 145 | + * @param view 需要显示到Activity的视图 | ||
| 146 | + */ | ||
| 147 | + public void showBottomView(View view) { | ||
| 148 | + if (null == view || this.activity == null || this.activity.isFinishing()) { | ||
| 149 | + return; | ||
| 150 | + } | ||
| 151 | + if (null != bottomView) { | ||
| 152 | + hideView(bottomView); | ||
| 153 | + } | ||
| 154 | + bottomView = view; | ||
| 155 | + /*创建属性动画,从下到上*/ | ||
| 156 | + ObjectAnimator bottomToTop = null; | ||
| 157 | + if (0 != ScreenUtils.getNavigationAreaHeight(activity)) { | ||
| 158 | + bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight(activity), ScreenUtils.getScreenHeight(activity) - ScreenUtils.getNavigationAreaHeight(activity)) | ||
| 159 | + .setDuration(animDuration); | ||
| 160 | + } else { | ||
| 161 | + bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight(activity), ScreenUtils.getScreenHeight(activity) - ViewUtils.getViewHeight(view)) | ||
| 162 | + .setDuration(animDuration); | ||
| 163 | + } | ||
| 164 | + /*初始化动画组合器*/ | ||
| 165 | + AnimatorSet animator = new AnimatorSet(); | ||
| 166 | + /*组合动画*/ | ||
| 167 | + animator.play(bottomToTop); | ||
| 168 | + /*添加动画结束回调*/ | ||
| 169 | + animator.addListener(new AnimatorListenerAdapter() { | ||
| 170 | + @Override | ||
| 171 | + public void onAnimationEnd(Animator animation) { | ||
| 172 | + super.onAnimationEnd(animation); | ||
| 173 | + myHandler.removeCallbacksAndMessages(null); | ||
| 174 | + myHandler.postDelayed(new Runnable() { | ||
| 175 | + @Override | ||
| 176 | + public void run() { | ||
| 177 | + if (null == view) { | ||
| 178 | + return; | ||
| 179 | + } | ||
| 180 | + hideBottomView(view); | ||
| 181 | + } | ||
| 182 | + }, delayTime * 1000); | ||
| 183 | + } | ||
| 184 | + }); | ||
| 185 | + /*Activity不为空并且没有被释放掉*/ | ||
| 186 | + if (this.activity != null && !this.activity.isFinishing()) { | ||
| 187 | + /*获取Activity顶层视图,并添加自定义View*/ | ||
| 188 | + ((ViewGroup) this.activity.getWindow().getDecorView()).addView(view); | ||
| 189 | + /*启动动画*/ | ||
| 190 | + animator.start(); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + public void hideBottomView(View view) { | ||
| 196 | + if (null == view) { | ||
| 197 | + return; | ||
| 198 | + } | ||
| 199 | + myHandler.removeCallbacksAndMessages(null); | ||
| 200 | + if (this.activity != null && !this.activity.isFinishing()) { | ||
| 201 | + /*获取Activity顶层视图*/ | ||
| 202 | + ViewGroup root = ((ViewGroup) this.activity.getWindow().getDecorView()); | ||
| 203 | + if (null == root) { | ||
| 204 | + return; | ||
| 205 | + } | ||
| 206 | + /*如果Activity中存在View对象则删除*/ | ||
| 207 | + ObjectAnimator bottomToTop = null; | ||
| 208 | + if (0 != ScreenUtils.getNavigationAreaHeight(activity)) { | ||
| 209 | + bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight(activity) - ScreenUtils.getNavigationAreaHeight(activity), ScreenUtils.getRealScreenHeight(activity)) | ||
| 210 | + .setDuration(animDuration); | ||
| 211 | + } else { | ||
| 212 | + bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight(activity) - ViewUtils.getViewHeight(view), ScreenUtils.getRealScreenHeight(activity)) | ||
| 213 | + .setDuration(animDuration); | ||
| 214 | + } | ||
| 215 | + /*初始化动画组合器*/ | ||
| 216 | + AnimatorSet animator = new AnimatorSet(); | ||
| 217 | + animator.play(bottomToTop); | ||
| 218 | + /*添加动画结束回调*/ | ||
| 219 | + animator.addListener(new AnimatorListenerAdapter() { | ||
| 220 | + @Override | ||
| 221 | + public void onAnimationEnd(Animator animation) { | ||
| 222 | + super.onAnimationEnd(animation); | ||
| 223 | + /*如果Activity中存在View对象则删除*/ | ||
| 224 | + if (root.indexOfChild(view) != -1) { | ||
| 225 | + /*从顶层视图中删除*/ | ||
| 226 | + root.removeView(view); | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + }); | ||
| 230 | + /*启动动画*/ | ||
| 231 | + animator.start(); | ||
| 232 | + } | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + /** | ||
| 236 | + * 隐藏View | ||
| 237 | + * | ||
| 238 | + * @param view 需要从Activity中移除的视图 | ||
| 239 | + */ | ||
| 240 | + private void hideView(View view) { | ||
| 241 | + if (null == view) { | ||
| 242 | + return; | ||
| 243 | + } | ||
| 244 | + /*Activity不为空并且没有被释放掉*/ | ||
| 245 | + if (this.activity != null && !this.activity.isFinishing()) { | ||
| 246 | + /*获取Activity顶层视图*/ | ||
| 247 | + ViewGroup root = ((ViewGroup) this.activity.getWindow().getDecorView()); | ||
| 248 | + if (null == root) { | ||
| 249 | + return; | ||
| 250 | + } | ||
| 251 | + /*如果Activity中存在View对象则删除*/ | ||
| 252 | + if (null != view) { | ||
| 253 | + if (root.indexOfChild(view) != -1) { | ||
| 254 | + /*从顶层视图中删除*/ | ||
| 255 | + root.removeView(view); | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + | ||
| 262 | + @Override | ||
| 263 | + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { | ||
| 264 | + | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + @Override | ||
| 268 | + public void onActivityStarted(@NonNull Activity activity) { | ||
| 269 | + | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + @Override | ||
| 273 | + public void onActivityResumed(@NonNull Activity activity) { | ||
| 274 | + /*获取当前显示的Activity*/ | ||
| 275 | + this.activity = activity; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + @Override | ||
| 279 | + public void onActivityPaused(@NonNull Activity activity) { | ||
| 280 | + | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + @Override | ||
| 284 | + public void onActivityStopped(@NonNull Activity activity) { | ||
| 285 | + | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + @Override | ||
| 289 | + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { | ||
| 290 | + | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + @Override | ||
| 294 | + public void onActivityDestroyed(@NonNull Activity activity) { | ||
| 295 | + | ||
| 296 | + } | ||
| 36 | } | 297 | } |
core/base/src/main/java/com/cnlive/core/libs/base/frame/activity/BaseActivity.java
| @@ -176,6 +176,27 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -176,6 +176,27 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 176 | setSwipeBackEnable(isOpenSwipBack); | 176 | setSwipeBackEnable(isOpenSwipBack); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | + /** | ||
| 180 | + * 显示白色通知栏 | ||
| 181 | + */ | ||
| 182 | + protected void showDefaultWhiteStatusBar() { | ||
| 183 | + setStatusBarTextColor(StatusBarConfig.BLACK); | ||
| 184 | + setStatusBarColor(R.color.white, 0); | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * 显示黑色通知栏 | ||
| 189 | + */ | ||
| 190 | + protected void showDefaultBlackStatusBar() { | ||
| 191 | + setStatusBarTextColor(StatusBarConfig.WHITE); | ||
| 192 | + setStatusBarColor(R.color.black, 0); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * 是否显示默认空视图 | ||
| 197 | + * | ||
| 198 | + * @param enable | ||
| 199 | + */ | ||
| 179 | public void setEnableCreateDefultEmptyView(boolean enable) { | 200 | public void setEnableCreateDefultEmptyView(boolean enable) { |
| 180 | isCreateDefultEmptyView = enable; | 201 | isCreateDefultEmptyView = enable; |
| 181 | } | 202 | } |
| @@ -1173,13 +1194,14 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1173,13 +1194,14 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1173 | public boolean checkPermissions(String[] permissions) { | 1194 | public boolean checkPermissions(String[] permissions) { |
| 1174 | boolean isAllow = true; | 1195 | boolean isAllow = true; |
| 1175 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | 1196 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| 1176 | - return true; | ||
| 1177 | - } | ||
| 1178 | - for (String permission : permissions) { | ||
| 1179 | - if (ContextCompat.checkSelfPermission(this, permission) != | ||
| 1180 | - PackageManager.PERMISSION_GRANTED) { | ||
| 1181 | - isAllow = false; | ||
| 1182 | - break; | 1197 | + isAllow = true; |
| 1198 | + } else { | ||
| 1199 | + for (String permission : permissions) { | ||
| 1200 | + if (ContextCompat.checkSelfPermission(this, permission) != | ||
| 1201 | + PackageManager.PERMISSION_GRANTED) { | ||
| 1202 | + isAllow = false; | ||
| 1203 | + break; | ||
| 1204 | + } | ||
| 1183 | } | 1205 | } |
| 1184 | } | 1206 | } |
| 1185 | return isAllow; | 1207 | return isAllow; |
| @@ -1576,7 +1598,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1576,7 +1598,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1576 | } | 1598 | } |
| 1577 | 1599 | ||
| 1578 | 1600 | ||
| 1579 | - | ||
| 1580 | /** | 1601 | /** |
| 1581 | * 显示fragment栈视图 | 1602 | * 显示fragment栈视图 |
| 1582 | */ | 1603 | */ |
core/base/src/main/java/com/cnlive/core/libs/base/frame/fragment/BaseFragment.java
| @@ -67,6 +67,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -67,6 +67,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 67 | private Handler myFragHandler; | 67 | private Handler myFragHandler; |
| 68 | private List<Observable> observableList; | 68 | private List<Observable> observableList; |
| 69 | private Bundle savedInstanceState; | 69 | private Bundle savedInstanceState; |
| 70 | + private boolean isCreateDefultEmptyView = true;//默认显示空视图 | ||
| 70 | 71 | ||
| 71 | public ViewDataBinding getBaseBinding() { | 72 | public ViewDataBinding getBaseBinding() { |
| 72 | return baseBinding; | 73 | return baseBinding; |
| @@ -113,18 +114,45 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -113,18 +114,45 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 113 | return baseView; | 114 | return baseView; |
| 114 | } | 115 | } |
| 115 | } | 116 | } |
| 116 | - if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { | ||
| 117 | - //加载默认布局 | ||
| 118 | - baseView = inflater.inflate(R.layout.base_fragment_main, container, false); | ||
| 119 | - if (me.isOpenSwipBack()) { | ||
| 120 | - return attachToSwipeBack(baseView); | ||
| 121 | - } else { | ||
| 122 | - return baseView; | 117 | + if (isCreateDefultEmptyView) { |
| 118 | + if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { | ||
| 119 | + //加载默认布局 | ||
| 120 | + baseView = inflater.inflate(R.layout.base_fragment_main, container, false); | ||
| 121 | + if (me.isOpenSwipBack()) { | ||
| 122 | + return attachToSwipeBack(baseView); | ||
| 123 | + } else { | ||
| 124 | + return baseView; | ||
| 125 | + } | ||
| 123 | } | 126 | } |
| 124 | } | 127 | } |
| 125 | return super.onCreateView(inflater, container, savedInstanceState); | 128 | return super.onCreateView(inflater, container, savedInstanceState); |
| 126 | } | 129 | } |
| 127 | 130 | ||
| 131 | + /** | ||
| 132 | + * 显示白色通知栏 | ||
| 133 | + */ | ||
| 134 | + public void showDefaultWhiteStatusBar() { | ||
| 135 | + setStatusBarTextColor(StatusBarConfig.BLACK); | ||
| 136 | + setStatusBarColor(R.color.white, 0); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 显示黑色通知栏 | ||
| 141 | + */ | ||
| 142 | + public void showDefaultBlackStatusBar() { | ||
| 143 | + setStatusBarTextColor(StatusBarConfig.WHITE); | ||
| 144 | + setStatusBarColor(R.color.black, 0); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * 是否显示默认空视图 | ||
| 149 | + * | ||
| 150 | + * @param enable | ||
| 151 | + */ | ||
| 152 | + public void setEnableCreateDefultEmptyView(boolean enable) { | ||
| 153 | + isCreateDefultEmptyView = enable; | ||
| 154 | + } | ||
| 155 | + | ||
| 128 | @Override | 156 | @Override |
| 129 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | 157 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 130 | super.onViewCreated(view, savedInstanceState); | 158 | super.onViewCreated(view, savedInstanceState); |
core/base/src/main/java/com/cnlive/core/libs/base/util/GlideUtil.java
| @@ -144,6 +144,7 @@ public class GlideUtil { | @@ -144,6 +144,7 @@ public class GlideUtil { | ||
| 144 | return this; | 144 | return this; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | + | ||
| 147 | public ViewTarget<ImageView, Drawable> into(ImageView imageView) { | 148 | public ViewTarget<ImageView, Drawable> into(ImageView imageView) { |
| 148 | ViewTarget<ImageView, Drawable> viewTarget = null; | 149 | ViewTarget<ImageView, Drawable> viewTarget = null; |
| 149 | try { | 150 | try { |
core/base/src/main/java/com/cnlive/core/libs/base/util/QMUITipDialogUtil.java
| @@ -24,6 +24,8 @@ public class QMUITipDialogUtil { | @@ -24,6 +24,8 @@ public class QMUITipDialogUtil { | ||
| 24 | private static QMUITipDialog tipDialog; | 24 | private static QMUITipDialog tipDialog; |
| 25 | private static WeakReference<Context> currentContext; | 25 | private static WeakReference<Context> currentContext; |
| 26 | private static Handler handler = new Handler(); | 26 | private static Handler handler = new Handler(); |
| 27 | + private static final int DEFAULT_SECOND = 2;// 默认延时2秒 | ||
| 28 | + | ||
| 27 | /** | 29 | /** |
| 28 | * Loading 类型提示框 | 30 | * Loading 类型提示框 |
| 29 | * | 31 | * |
| @@ -58,6 +60,7 @@ public class QMUITipDialogUtil { | @@ -58,6 +60,7 @@ public class QMUITipDialogUtil { | ||
| 58 | } | 60 | } |
| 59 | 61 | ||
| 60 | } | 62 | } |
| 63 | + | ||
| 61 | /** | 64 | /** |
| 62 | * Loading 类型提示框 | 65 | * Loading 类型提示框 |
| 63 | * | 66 | * |
| @@ -98,6 +101,59 @@ public class QMUITipDialogUtil { | @@ -98,6 +101,59 @@ public class QMUITipDialogUtil { | ||
| 98 | * | 101 | * |
| 99 | * @param context | 102 | * @param context |
| 100 | */ | 103 | */ |
| 104 | + public static void successDialog(Context context, String tipStr) { | ||
| 105 | + try { | ||
| 106 | + if (context instanceof Activity) { | ||
| 107 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 108 | + return; | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + currentContext = new WeakReference<>(context); | ||
| 112 | + if (currentContext == null) { | ||
| 113 | + return; | ||
| 114 | + } | ||
| 115 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 116 | + tipDialog.dismiss(); | ||
| 117 | + } | ||
| 118 | + tipDialog = new QMUITipDialog.Builder(currentContext.get()) | ||
| 119 | + .setIconType(QMUITipDialog.Builder.ICON_TYPE_SUCCESS) | ||
| 120 | + .setTipWord(tipStr) | ||
| 121 | + .create(); | ||
| 122 | + tipDialog.setCanceledOnTouchOutside(false);//屏蔽返回键 | ||
| 123 | + if (!tipDialog.isShowing()) { | ||
| 124 | + tipDialog.show(); | ||
| 125 | + handler.removeCallbacksAndMessages(null); | ||
| 126 | + handler.postDelayed(new Runnable() { | ||
| 127 | + @Override | ||
| 128 | + public void run() { | ||
| 129 | + if (currentContext == null) { | ||
| 130 | + return; | ||
| 131 | + } | ||
| 132 | + if (context instanceof Activity) { | ||
| 133 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 134 | + return; | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + /** | ||
| 138 | + * 延时执行的代码 | ||
| 139 | + */ | ||
| 140 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 141 | + tipDialog.dismiss(); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + }, 2 * 1000); // 延时2秒 | ||
| 145 | + } | ||
| 146 | + } catch (Exception e) { | ||
| 147 | + | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * 成功提示类型提示框 | ||
| 154 | + * | ||
| 155 | + * @param context | ||
| 156 | + */ | ||
| 101 | public static void successDialog(Context context, String tipStr, int second) { | 157 | public static void successDialog(Context context, String tipStr, int second) { |
| 102 | try { | 158 | try { |
| 103 | if (context instanceof Activity) { | 159 | if (context instanceof Activity) { |
| @@ -151,6 +207,63 @@ public class QMUITipDialogUtil { | @@ -151,6 +207,63 @@ public class QMUITipDialogUtil { | ||
| 151 | * | 207 | * |
| 152 | * @param context | 208 | * @param context |
| 153 | */ | 209 | */ |
| 210 | + public static void failedDialog(Context context, String tipStr) { | ||
| 211 | + try { | ||
| 212 | + if (context instanceof Activity) { | ||
| 213 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 214 | + return; | ||
| 215 | + } | ||
| 216 | + } | ||
| 217 | + currentContext = new WeakReference<>(context); | ||
| 218 | + if (currentContext == null) { | ||
| 219 | + return; | ||
| 220 | + } | ||
| 221 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 222 | + tipDialog.dismiss(); | ||
| 223 | + } | ||
| 224 | + tipDialog = new QMUITipDialog.Builder(currentContext.get()) | ||
| 225 | + .setIconType(QMUITipDialog.Builder.ICON_TYPE_FAIL) | ||
| 226 | + .setTipWord(tipStr) | ||
| 227 | + .create(); | ||
| 228 | + tipDialog.setCanceledOnTouchOutside(false);//屏蔽返回键 | ||
| 229 | + if (!tipDialog.isShowing()) { | ||
| 230 | + tipDialog.show(); | ||
| 231 | + handler.removeCallbacksAndMessages(null); | ||
| 232 | + handler.postDelayed(new Runnable() { | ||
| 233 | + @Override | ||
| 234 | + public void run() { | ||
| 235 | + if (currentContext == null) { | ||
| 236 | + return; | ||
| 237 | + } | ||
| 238 | + if (context instanceof Activity) { | ||
| 239 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 240 | + return; | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + /** | ||
| 244 | + * 延时执行的代码 | ||
| 245 | + */ | ||
| 246 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 247 | + tipDialog.dismiss(); | ||
| 248 | + } | ||
| 249 | + } | ||
| 250 | + }, DEFAULT_SECOND * 1000); // 延时2秒 | ||
| 251 | + } | ||
| 252 | + } catch (Exception e) { | ||
| 253 | + | ||
| 254 | + } | ||
| 255 | + if (currentContext == null) { | ||
| 256 | + return; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * 失败提示类型提示框 | ||
| 264 | + * | ||
| 265 | + * @param context | ||
| 266 | + */ | ||
| 154 | public static void failedDialog(Context context, String tipStr, int second) { | 267 | public static void failedDialog(Context context, String tipStr, int second) { |
| 155 | try { | 268 | try { |
| 156 | if (context instanceof Activity) { | 269 | if (context instanceof Activity) { |
| @@ -208,6 +321,57 @@ public class QMUITipDialogUtil { | @@ -208,6 +321,57 @@ public class QMUITipDialogUtil { | ||
| 208 | * | 321 | * |
| 209 | * @param context | 322 | * @param context |
| 210 | */ | 323 | */ |
| 324 | + public static void messageDialog(Context context, String tipStr) { | ||
| 325 | + try { | ||
| 326 | + if (context instanceof Activity) { | ||
| 327 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 328 | + return; | ||
| 329 | + } | ||
| 330 | + } | ||
| 331 | + currentContext = new WeakReference<>(context); | ||
| 332 | + if (currentContext == null) { | ||
| 333 | + return; | ||
| 334 | + } | ||
| 335 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 336 | + tipDialog.dismiss(); | ||
| 337 | + } | ||
| 338 | + tipDialog = new QMUITipDialog.Builder(currentContext.get()) | ||
| 339 | + .setIconType(QMUITipDialog.Builder.ICON_TYPE_INFO) | ||
| 340 | + .setTipWord(tipStr) | ||
| 341 | + .create(); | ||
| 342 | + tipDialog.setCanceledOnTouchOutside(false);//屏蔽返回键 | ||
| 343 | + if (!tipDialog.isShowing()) { | ||
| 344 | + tipDialog.show(); | ||
| 345 | + handler.removeCallbacksAndMessages(null); | ||
| 346 | + handler.postDelayed(new Runnable() { | ||
| 347 | + @Override | ||
| 348 | + public void run() { | ||
| 349 | + if (currentContext == null) { | ||
| 350 | + return; | ||
| 351 | + } | ||
| 352 | + if (context instanceof Activity) { | ||
| 353 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 354 | + return; | ||
| 355 | + } | ||
| 356 | + } | ||
| 357 | + /** | ||
| 358 | + * 延时执行的代码 | ||
| 359 | + */ | ||
| 360 | + tipDialog.dismiss(); | ||
| 361 | + } | ||
| 362 | + }, DEFAULT_SECOND * 1000); // 延时2秒 | ||
| 363 | + } | ||
| 364 | + } catch (Exception e) { | ||
| 365 | + | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + } | ||
| 369 | + | ||
| 370 | + /** | ||
| 371 | + * 信息提示类型提示框 | ||
| 372 | + * | ||
| 373 | + * @param context | ||
| 374 | + */ | ||
| 211 | public static void messageDialog(Context context, String tipStr, int second) { | 375 | public static void messageDialog(Context context, String tipStr, int second) { |
| 212 | try { | 376 | try { |
| 213 | if (context instanceof Activity) { | 377 | if (context instanceof Activity) { |
| @@ -251,12 +415,58 @@ public class QMUITipDialogUtil { | @@ -251,12 +415,58 @@ public class QMUITipDialogUtil { | ||
| 251 | } catch (Exception e) { | 415 | } catch (Exception e) { |
| 252 | 416 | ||
| 253 | } | 417 | } |
| 254 | - if (currentContext == null) { | ||
| 255 | - return; | ||
| 256 | - } | ||
| 257 | 418 | ||
| 258 | } | 419 | } |
| 259 | 420 | ||
| 421 | + /** | ||
| 422 | + * 单独文字类型提示框 | ||
| 423 | + * | ||
| 424 | + * @param context | ||
| 425 | + */ | ||
| 426 | + public static void textDialog(Context context, String tipStr) { | ||
| 427 | + try { | ||
| 428 | + if (context instanceof Activity) { | ||
| 429 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 430 | + return; | ||
| 431 | + } | ||
| 432 | + } | ||
| 433 | + currentContext = new WeakReference<>(context); | ||
| 434 | + if (currentContext == null) { | ||
| 435 | + return; | ||
| 436 | + } | ||
| 437 | + if (tipDialog != null && tipDialog.isShowing()) { | ||
| 438 | + tipDialog.dismiss(); | ||
| 439 | + } | ||
| 440 | + tipDialog = new QMUITipDialog.Builder(currentContext.get()) | ||
| 441 | + .setTipWord(tipStr) | ||
| 442 | + .create(); | ||
| 443 | + tipDialog.setCanceledOnTouchOutside(false);//屏蔽返回键 | ||
| 444 | + if (!tipDialog.isShowing()) { | ||
| 445 | + tipDialog.show(); | ||
| 446 | + handler.removeCallbacksAndMessages(null); | ||
| 447 | + handler.postDelayed(new Runnable() { | ||
| 448 | + @Override | ||
| 449 | + public void run() { | ||
| 450 | + if (currentContext == null) { | ||
| 451 | + return; | ||
| 452 | + } | ||
| 453 | + if (context instanceof Activity) { | ||
| 454 | + if (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()) { | ||
| 455 | + return; | ||
| 456 | + } | ||
| 457 | + } | ||
| 458 | + /** | ||
| 459 | + * 延时执行的代码 | ||
| 460 | + */ | ||
| 461 | + tipDialog.dismiss(); | ||
| 462 | + } | ||
| 463 | + }, DEFAULT_SECOND * 1000); // 延时2秒 | ||
| 464 | + } | ||
| 465 | + } catch (Exception e) { | ||
| 466 | + | ||
| 467 | + } | ||
| 468 | + | ||
| 469 | + } | ||
| 260 | 470 | ||
| 261 | /** | 471 | /** |
| 262 | * 单独文字类型提示框 | 472 | * 单独文字类型提示框 |
core/base/src/main/java/com/cnlive/core/libs/base/util/ScreenUtil.java renamed to core/base/src/main/java/com/cnlive/core/libs/base/util/ScreenUtils.java
| @@ -8,6 +8,7 @@ import android.content.res.Resources; | @@ -8,6 +8,7 @@ import android.content.res.Resources; | ||
| 8 | import android.graphics.Bitmap; | 8 | import android.graphics.Bitmap; |
| 9 | import android.graphics.Point; | 9 | import android.graphics.Point; |
| 10 | import android.util.DisplayMetrics; | 10 | import android.util.DisplayMetrics; |
| 11 | +import android.view.Display; | ||
| 11 | import android.view.Surface; | 12 | import android.view.Surface; |
| 12 | import android.view.View; | 13 | import android.view.View; |
| 13 | import android.view.Window; | 14 | import android.view.Window; |
| @@ -15,6 +16,8 @@ import android.view.WindowManager; | @@ -15,6 +16,8 @@ import android.view.WindowManager; | ||
| 15 | 16 | ||
| 16 | import androidx.annotation.NonNull; | 17 | import androidx.annotation.NonNull; |
| 17 | 18 | ||
| 19 | +import java.lang.reflect.Field; | ||
| 20 | +import java.lang.reflect.Method; | ||
| 18 | import java.text.DecimalFormat; | 21 | import java.text.DecimalFormat; |
| 19 | 22 | ||
| 20 | /** | 23 | /** |
| @@ -40,7 +43,7 @@ import java.text.DecimalFormat; | @@ -40,7 +43,7 @@ import java.text.DecimalFormat; | ||
| 40 | * getSleepDuration : 获取进入休眠时长 | 43 | * getSleepDuration : 获取进入休眠时长 |
| 41 | */ | 44 | */ |
| 42 | 45 | ||
| 43 | -public class ScreenUtil { | 46 | +public class ScreenUtils { |
| 44 | 47 | ||
| 45 | /** | 48 | /** |
| 46 | * 获取手机宽度的分辨率 | 49 | * 获取手机宽度的分辨率 |
| @@ -66,19 +69,30 @@ public class ScreenUtil { | @@ -66,19 +69,30 @@ public class ScreenUtil { | ||
| 66 | return screenHeight; | 69 | return screenHeight; |
| 67 | } | 70 | } |
| 68 | 71 | ||
| 69 | - public static int getRealWidth(Context context, int x1, int x2) { | ||
| 70 | - float num = (float) x1 / x2; | ||
| 71 | - DecimalFormat decimalFormat = new DecimalFormat("0.0000"); | ||
| 72 | - return (int) (Float.parseFloat(decimalFormat.format(num)) * getScreenWidth(context)); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public static int getRealHeight(Context context, int x1, int x2) { | ||
| 76 | - float num = (float) x1 / x2; | ||
| 77 | - DecimalFormat decimalFormat = new DecimalFormat("0.0000"); | ||
| 78 | - return (int) (Float.parseFloat(decimalFormat.format(num)) * getScreenHeight(context)); | 72 | + /** |
| 73 | + * 功能描述:获取整块屏幕的高度 | ||
| 74 | + * | ||
| 75 | + * @param context | ||
| 76 | + * @return int | ||
| 77 | + */ | ||
| 78 | + public static int getRealScreenHeight(Context context) { | ||
| 79 | + int dpi = 0; | ||
| 80 | + Display display = ((Activity) context).getWindowManager() | ||
| 81 | + .getDefaultDisplay(); | ||
| 82 | + DisplayMetrics dm = new DisplayMetrics(); | ||
| 83 | + @SuppressWarnings("rawtypes") | ||
| 84 | + Class c; | ||
| 85 | + try { | ||
| 86 | + c = Class.forName("android.view.Display"); | ||
| 87 | + @SuppressWarnings("unchecked") Method method = c.getMethod("getRealMetrics", DisplayMetrics.class); | ||
| 88 | + method.invoke(display, dm); | ||
| 89 | + dpi = dm.heightPixels; | ||
| 90 | + } catch (Exception e) { | ||
| 91 | + e.printStackTrace(); | ||
| 92 | + } | ||
| 93 | + return dpi; | ||
| 79 | } | 94 | } |
| 80 | 95 | ||
| 81 | - | ||
| 82 | /** | 96 | /** |
| 83 | * 获取应用屏幕的宽度(单位:px) | 97 | * 获取应用屏幕的宽度(单位:px) |
| 84 | * Return the application's width of screen, in pixel. | 98 | * Return the application's width of screen, in pixel. |
| @@ -284,4 +298,58 @@ public class ScreenUtil { | @@ -284,4 +298,58 @@ public class ScreenUtil { | ||
| 284 | decorView.destroyDrawingCache(); | 298 | decorView.destroyDrawingCache(); |
| 285 | return ret; | 299 | return ret; |
| 286 | } | 300 | } |
| 301 | + | ||
| 302 | + | ||
| 303 | + /** | ||
| 304 | + * 功能描述:获取虚拟按键区域的高度 | ||
| 305 | + * | ||
| 306 | + * @param context | ||
| 307 | + * @return int 如果有虚拟按键则返回其高度否则返回0; | ||
| 308 | + */ | ||
| 309 | + public static int getNavigationAreaHeight(Context context) { | ||
| 310 | + int realScreenHeight = getRealScreenHeight(context); | ||
| 311 | + int screenHeight = getScreenHeight(context); | ||
| 312 | + | ||
| 313 | + return realScreenHeight - screenHeight; | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + /** | ||
| 317 | + * 获取通知栏高度 | ||
| 318 | + * | ||
| 319 | + * @param context 上下文 | ||
| 320 | + * @return 通知栏高度 | ||
| 321 | + */ | ||
| 322 | + public static int getStatusBarHeight(Context context) { | ||
| 323 | + int statusBarHeight = 0; | ||
| 324 | + try { | ||
| 325 | + Class<?> clazz = Class.forName("com.android.internal.R$dimen"); | ||
| 326 | + Object obj = clazz.newInstance(); | ||
| 327 | + Field field = clazz.getField("status_bar_height"); | ||
| 328 | + int temp = Integer.parseInt(field.get(obj).toString()); | ||
| 329 | + statusBarHeight = context.getResources().getDimensionPixelSize(temp); | ||
| 330 | + } catch (Exception e) { | ||
| 331 | + e.printStackTrace(); | ||
| 332 | + } | ||
| 333 | + return statusBarHeight; | ||
| 334 | + } | ||
| 335 | + /** | ||
| 336 | + * 获得标题栏高度 | ||
| 337 | + * | ||
| 338 | + * @param context 上下文,为Activity对象 | ||
| 339 | + * @return 标题栏高度 | ||
| 340 | + */ | ||
| 341 | + public static int getTitleBarHeight(Activity context) { | ||
| 342 | + int contentTop = context.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); | ||
| 343 | + return contentTop - getStatusBarHeight(context); | ||
| 344 | + } | ||
| 345 | + /** | ||
| 346 | + * 获取导航栏高度 | ||
| 347 | + * @param c | ||
| 348 | + * @return | ||
| 349 | + */ | ||
| 350 | + public static int getNavigationBarrH(Context c) { | ||
| 351 | + Resources resources = c.getResources(); | ||
| 352 | + int identifier = resources.getIdentifier("navigation_bar_height", "dimen", "android"); | ||
| 353 | + return resources.getDimensionPixelOffset(identifier); | ||
| 354 | + } | ||
| 287 | } | 355 | } |
core/base/src/main/java/com/cnlive/core/libs/base/util/ValidationUtils.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.text.TextUtils; | ||
| 4 | +import android.util.Log; | ||
| 5 | + | ||
| 6 | +import java.io.BufferedReader; | ||
| 7 | +import java.io.IOException; | ||
| 8 | +import java.io.InputStream; | ||
| 9 | +import java.io.InputStreamReader; | ||
| 10 | +import java.text.ParseException; | ||
| 11 | +import java.text.SimpleDateFormat; | ||
| 12 | +import java.util.Calendar; | ||
| 13 | +import java.util.GregorianCalendar; | ||
| 14 | +import java.util.Hashtable; | ||
| 15 | +import java.util.UUID; | ||
| 16 | +import java.util.regex.Matcher; | ||
| 17 | +import java.util.regex.Pattern; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * isEmpty : 验证是否为空串 (包括空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true) | ||
| 21 | + * isNotEmpty : 是否不为空 | ||
| 22 | + * isNotZero : 验证非零正整数 | ||
| 23 | + * isNumber : 验证是数字 | ||
| 24 | + * isUpChar : 验证是大写字母 | ||
| 25 | + * isLowChar : 验证是小写字母 | ||
| 26 | + * isLetter : 验证是英文字母 | ||
| 27 | + * isChinese : 验证输入汉字 | ||
| 28 | + * isRealName : 验证真实姓名 | ||
| 29 | + * isOneCode : 验证是否是条形码 | ||
| 30 | + * isEmail : 验证邮箱是否正确 | ||
| 31 | + * isPhone : 验证手机号是否正确 | ||
| 32 | + * isPlane : 验证座机号码是否正确 | ||
| 33 | + * isPostalCode : 验证邮政编码是否正确 | ||
| 34 | + * isIpAddress : 验证IP地址是否正确 | ||
| 35 | + * isURL : 验证URL地址是否正确 | ||
| 36 | + * isInteger : 验证是否是正整数 | ||
| 37 | + * isPoint : 验证是否是小数 | ||
| 38 | + * isBankNo : 验证是否银行卡号 | ||
| 39 | + * isIDCard : 验证身份证号码是否正确 | ||
| 40 | + * isPeculiarStr : 判断是否有特殊字符 | ||
| 41 | + * isUserName : 判断是否为用户名账号(规则如下:用户名由下划线或字母开头,由数字、字母、下划线、点、减号组成的4-32位字符) | ||
| 42 | + * chineseLength : 获取字符串中文字符的长度(每个中文算2个字符) | ||
| 43 | + * strLength : 获取字符串的长度 | ||
| 44 | + * subStringLength : 获取指定长度的字符所在位置 | ||
| 45 | + * isNumberLetter : 是否只是字母和数字 | ||
| 46 | + * isContainChinese : 是否包含中文 | ||
| 47 | + * convertStreamToString: 从输入流中获得String | ||
| 48 | + * cutString : 截取字符串到指定字节长度 | ||
| 49 | + * cutStringFromChar : 截取字符串从第一个指定字符 | ||
| 50 | + * strlen : 获取字节长度 | ||
| 51 | + * getSizeDesc : 获取大小的描述 | ||
| 52 | + * ip2int : ip地址转换为10进制数 | ||
| 53 | + * gainUUID : 获取UUID | ||
| 54 | + * phoneNoHide : 手机号码,中间4位星号替换 | ||
| 55 | + * cardIdHide : 银行卡号,保留最后4位,其他星号替换 | ||
| 56 | + * idHide : 身份证号,中间10位星号替换 | ||
| 57 | + * checkVehicleNo : 是否为车牌号(沪A88888) | ||
| 58 | + * isContinuousNum : 判断字符串是否为连续数字 45678901等 | ||
| 59 | + * isAlphaBetaString : 是否是纯字母 | ||
| 60 | + * isContinuousWord : 判断字符串是否为连续字母 xyZaBcd等 | ||
| 61 | + * isRealDate : 是否是日期 20120506 共八位,前四位-年,中间两位-月,最后两位-日 | ||
| 62 | + */ | ||
| 63 | +public class ValidationUtils { | ||
| 64 | + private static String TAG; | ||
| 65 | + | ||
| 66 | + //邮箱表达式 | ||
| 67 | + private final static Pattern email_pattern = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"); | ||
| 68 | + | ||
| 69 | + //手机号表达式 | ||
| 70 | + private final static Pattern phone_pattern = Pattern.compile("^(13|15|18)\\d{9}$"); | ||
| 71 | + | ||
| 72 | + //银行卡号表达式 | ||
| 73 | + private final static Pattern bankNo_pattern = Pattern.compile("^[0-9]{16,19}$"); | ||
| 74 | + | ||
| 75 | + //座机号码表达式 | ||
| 76 | + private final static Pattern plane_pattern = Pattern.compile("^((\\(\\d{2,3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}(\\-\\d{1,4})?$"); | ||
| 77 | + | ||
| 78 | + //非零表达式 | ||
| 79 | + private final static Pattern notZero_pattern = Pattern.compile("^\\+?[1-9][0-9]*$"); | ||
| 80 | + | ||
| 81 | + //数字表达式 | ||
| 82 | + private final static Pattern number_pattern = Pattern.compile("^[0-9]*$"); | ||
| 83 | + | ||
| 84 | + //大写字母表达式 | ||
| 85 | + private final static Pattern upChar_pattern = Pattern.compile("^[A-Z]+$"); | ||
| 86 | + | ||
| 87 | + //小写字母表达式 | ||
| 88 | + private final static Pattern lowChar_pattern = Pattern.compile("^[a-z]+$"); | ||
| 89 | + | ||
| 90 | + //大小写字母表达式 | ||
| 91 | + private final static Pattern letter_pattern = Pattern.compile("^[A-Za-z]+$"); | ||
| 92 | + | ||
| 93 | + //中文汉字表达式 | ||
| 94 | + private final static Pattern chinese_pattern = Pattern.compile("^[\u4e00-\u9fa5],{0,}$"); | ||
| 95 | + | ||
| 96 | + //条形码表达式 | ||
| 97 | + private final static Pattern onecode_pattern = Pattern.compile("^(([0-9])|([0-9])|([0-9]))\\d{10}$"); | ||
| 98 | + | ||
| 99 | + //邮政编码表达式 | ||
| 100 | + private final static Pattern postalcode_pattern = Pattern.compile("([0-9]{3})+.([0-9]{4})+"); | ||
| 101 | + | ||
| 102 | + //IP地址表达式 | ||
| 103 | + private final static Pattern ipaddress_pattern = Pattern.compile("[1-9](\\d{1,2})?\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))"); | ||
| 104 | + | ||
| 105 | + //URL地址表达式 | ||
| 106 | + private final static Pattern url_pattern = Pattern.compile("(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?"); | ||
| 107 | + | ||
| 108 | + //用户名表达式 | ||
| 109 | + private final static Pattern username_pattern = Pattern.compile("^[A-Za-z0-9_]{1}[A-Za-z0-9_.-]{3,31}"); | ||
| 110 | + | ||
| 111 | + //真实姓名表达式 | ||
| 112 | + private final static Pattern realnem_pattern = Pattern.compile("[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*"); | ||
| 113 | + | ||
| 114 | + //匹配HTML标签,通过下面的表达式可以匹配出HTML中的标签属性。 | ||
| 115 | + private final static Pattern html_patter = Pattern.compile("<\\\\/?\\\\w+((\\\\s+\\\\w+(\\\\s*=\\\\s*(?:\".*?\"|'.*?'|[\\\\^'\">\\\\s]+))?)+\\\\s*|\\\\s*)\\\\/?>"); | ||
| 116 | + | ||
| 117 | + //抽取注释,如果你需要移除HMTL中的注释,可以使用如下的表达式。 | ||
| 118 | + private final static Pattern notes_patter = Pattern.compile("<!--(.*?)-->"); | ||
| 119 | + | ||
| 120 | + //查找CSS属性,通过下面的表达式,可以搜索到相匹配的CSS属性。 | ||
| 121 | + private final static Pattern css_patter = Pattern.compile("^\\\\s*[a-zA-Z\\\\-]+\\\\s*[:]{1}\\\\s[a-zA-Z0-9\\\\s.#]+[;]{1}"); | ||
| 122 | + | ||
| 123 | + //提取页面超链接,提取html中的超链接。 | ||
| 124 | + private final static Pattern hyperlink_patter = Pattern.compile("(<a\\\\s*(?!.*\\\\brel=)[^>]*)(href=\"https?:\\\\/\\\\/)((?!(?:(?:www\\\\.)?'.implode('|(?:www\\\\.)?', $follow_list).'))[^\"]+)\"((?!.*\\\\brel=)[^>]*)(?:[^>]*)>"); | ||
| 125 | + | ||
| 126 | + //提取网页图片,假若你想提取网页中所有图片信息,可以利用下面的表达式。 | ||
| 127 | + private final static Pattern image_patter = Pattern.compile("\\\\< *[img][^\\\\\\\\>]*[src] *= *[\\\\\"\\\\']{0,1}([^\\\\\"\\\\'\\\\ >]*)"); | ||
| 128 | + | ||
| 129 | + //提取Color Hex Codes,有时需要抽取网页中的颜色代码,可以使用下面的表达式。 | ||
| 130 | + private final static Pattern color_patter = Pattern.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"); | ||
| 131 | + | ||
| 132 | + //文件路径及扩展名校验,验证windows下文件路径和扩展名(下面的例子中为.txt文件) | ||
| 133 | + private final static Pattern route_patter = Pattern.compile("^([a-zA-Z]\\\\:|\\\\\\\\)\\\\\\\\([^\\\\\\\\]+\\\\\\\\)*[^\\\\/:*?\"<>|]+\\\\.txt(l)?$"); | ||
| 134 | + | ||
| 135 | + //提取URL链接,下面的这个表达式可以筛选出一段文本中的URL | ||
| 136 | + // ^(f|ht){1}(tp|tps):\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- ./?%&=]*)? | ||
| 137 | + //检查URL的前缀,应用开发中很多时候需要区分请求是HTTPS还是HTTP,通过下面的表达式可以取出一个url的前缀然后再逻辑判断。 | ||
| 138 | +//if (!s.match(/^[a-zA-Z]+:\\/\\//)) | ||
| 139 | +// { | ||
| 140 | +// s = 'http://' + s; | ||
| 141 | +// } | ||
| 142 | + //校验IP-v6地址 | ||
| 143 | +// (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])) | ||
| 144 | +//校验IP-v4地址 | ||
| 145 | +// \\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b | ||
| 146 | +// 判断IE的版本 | ||
| 147 | +// ^.*MSIE [5-8](?:\\.[0-9]+)?(?!.*Trident\\/[5-9]\\.0).*$ | ||
| 148 | +// 校验金额 | ||
| 149 | +//^[0-9]+(.[0-9]{2})?$ | ||
| 150 | +// 校验密码强度 | ||
| 151 | +//^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$ | ||
| 152 | + public ValidationUtils() { | ||
| 153 | + TAG = this.getClass().getSimpleName(); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 验证是否为空串 (包括空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true) | ||
| 158 | + * | ||
| 159 | + * @param str 验证字符 | ||
| 160 | + * @return boolean | ||
| 161 | + */ | ||
| 162 | + public static boolean isEmpty(String str) { | ||
| 163 | + if (str == null || "".equals(str) || str.length() == 0) { | ||
| 164 | + return true; | ||
| 165 | + } | ||
| 166 | + for (int i = 0; i < str.length(); i++) { | ||
| 167 | + char c = str.charAt(i); | ||
| 168 | + if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + return true; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + /** | ||
| 177 | + * 是否不为空 | ||
| 178 | + * | ||
| 179 | + * @param s | ||
| 180 | + */ | ||
| 181 | + public static boolean isNotEmpty(String s) { | ||
| 182 | + return s != null && !"".equals(s.trim()); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 验证非零正整数 | ||
| 187 | + * | ||
| 188 | + * @param str 验证字符 | ||
| 189 | + * @return boolean | ||
| 190 | + */ | ||
| 191 | + public static boolean isNotZero(String str) { | ||
| 192 | + return notZero_pattern.matcher(str).matches(); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * 验证是数字 | ||
| 198 | + * | ||
| 199 | + * @param str 验证字符 | ||
| 200 | + * @return boolean | ||
| 201 | + */ | ||
| 202 | + public static boolean isNumber(String str) { | ||
| 203 | + return number_pattern.matcher(str).matches(); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 验证是大写字母 | ||
| 209 | + * | ||
| 210 | + * @param str 验证字符 | ||
| 211 | + * @return boolean | ||
| 212 | + */ | ||
| 213 | + public static boolean isUpChar(String str) { | ||
| 214 | + return upChar_pattern.matcher(str).matches(); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * 验证是小写字母 | ||
| 220 | + * | ||
| 221 | + * @param str 验证字符 | ||
| 222 | + * @return boolean | ||
| 223 | + */ | ||
| 224 | + public static boolean isLowChar(String str) { | ||
| 225 | + return lowChar_pattern.matcher(str).matches(); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + | ||
| 229 | + /** | ||
| 230 | + * 验证是英文字母 | ||
| 231 | + * | ||
| 232 | + * @param str 验证字符 | ||
| 233 | + * @return boolean | ||
| 234 | + */ | ||
| 235 | + public static boolean isLetter(String str) { | ||
| 236 | + return letter_pattern.matcher(str).matches(); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + | ||
| 240 | + /** | ||
| 241 | + * 验证输入汉字 | ||
| 242 | + * | ||
| 243 | + * @param str 验证字符 | ||
| 244 | + * @return boolean | ||
| 245 | + */ | ||
| 246 | + public static boolean isChinese(String str) { | ||
| 247 | + return chinese_pattern.matcher(str).matches(); | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * 验证真实姓名 | ||
| 253 | + * | ||
| 254 | + * @param str 验证字符 | ||
| 255 | + * @return | ||
| 256 | + */ | ||
| 257 | + public static boolean isRealName(String str) { | ||
| 258 | + return realnem_pattern.matcher(str).matches(); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * 验证是否是条形码 | ||
| 264 | + * | ||
| 265 | + * @param oneCode 条形码 | ||
| 266 | + * @return boolean | ||
| 267 | + */ | ||
| 268 | + public static boolean isOneCode(String oneCode) { | ||
| 269 | + return onecode_pattern.matcher(oneCode).matches(); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + | ||
| 273 | + /** | ||
| 274 | + * 是否含有特殊符号 | ||
| 275 | + * | ||
| 276 | + * @param str 待验证的字符串 | ||
| 277 | + * @return 是否含有特殊符号 | ||
| 278 | + */ | ||
| 279 | + public static boolean hasSpecialCharacter(String str) { | ||
| 280 | + String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]"; | ||
| 281 | + Pattern p = Pattern.compile(regEx); | ||
| 282 | + Matcher m = p.matcher(str); | ||
| 283 | + return m.find(); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + | ||
| 287 | + /** | ||
| 288 | + * 验证邮箱是否正确 | ||
| 289 | + * | ||
| 290 | + * @param email 邮箱地址 | ||
| 291 | + * @return boolean | ||
| 292 | + */ | ||
| 293 | + public static boolean isEmail(String email) { | ||
| 294 | + return email_pattern.matcher(email).matches(); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + | ||
| 298 | + /** | ||
| 299 | + * 验证手机号是否正确 | ||
| 300 | + * | ||
| 301 | + * @param phone 手机号码 | ||
| 302 | + * @return boolean | ||
| 303 | + */ | ||
| 304 | + public static boolean isPhone(String phone) { | ||
| 305 | + return phone_pattern.matcher(phone).matches(); | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * 验证座机号码是否正确 | ||
| 311 | + * | ||
| 312 | + * @param plane 座机号码 | ||
| 313 | + * @return boolean | ||
| 314 | + */ | ||
| 315 | + public static boolean isPlane(String plane) { | ||
| 316 | + return plane_pattern.matcher(plane).matches(); | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + | ||
| 320 | + /** | ||
| 321 | + * 验证邮政编码是否正确 | ||
| 322 | + * | ||
| 323 | + * @param postalcode 邮政编码 | ||
| 324 | + * @return boolean | ||
| 325 | + */ | ||
| 326 | + public static boolean isPostalCode(String postalcode) { | ||
| 327 | + return postalcode_pattern.matcher(postalcode).matches(); | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + | ||
| 331 | + /** | ||
| 332 | + * 验证IP地址是否正确 | ||
| 333 | + * | ||
| 334 | + * @param ipaddress IP地址 | ||
| 335 | + * @return boolean | ||
| 336 | + */ | ||
| 337 | + public static boolean isIpAddress(String ipaddress) { | ||
| 338 | + return ipaddress_pattern.matcher(ipaddress).matches(); | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + | ||
| 342 | + /** | ||
| 343 | + * 验证URL地址是否正确 | ||
| 344 | + * | ||
| 345 | + * @param url 地址 | ||
| 346 | + * @return boolean | ||
| 347 | + */ | ||
| 348 | + public static boolean isURL(String url) { | ||
| 349 | + return url_pattern.matcher(url).matches(); | ||
| 350 | + } | ||
| 351 | + | ||
| 352 | + | ||
| 353 | + /** | ||
| 354 | + * 验证是否是正整数 | ||
| 355 | + * | ||
| 356 | + * @param str 验证字符 | ||
| 357 | + * @return boolean | ||
| 358 | + */ | ||
| 359 | + public static boolean isInteger(String str) { | ||
| 360 | + try { | ||
| 361 | + Integer.valueOf(str); | ||
| 362 | + return true; | ||
| 363 | + } catch (Exception e) { | ||
| 364 | + return false; | ||
| 365 | + } | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + | ||
| 369 | + /** | ||
| 370 | + * 验证是否是小数 | ||
| 371 | + * | ||
| 372 | + * @param paramString 验证字符 | ||
| 373 | + * @return boolean | ||
| 374 | + */ | ||
| 375 | + public static boolean isPoint(String paramString) { | ||
| 376 | + if (paramString.indexOf(".") > 0) { | ||
| 377 | + if (paramString.substring(paramString.indexOf(".")).length() > 3) { | ||
| 378 | + return false; | ||
| 379 | + } | ||
| 380 | + } | ||
| 381 | + return true; | ||
| 382 | + } | ||
| 383 | + | ||
| 384 | + | ||
| 385 | + /** | ||
| 386 | + * 验证是否银行卡号 | ||
| 387 | + * | ||
| 388 | + * @param bankNo 银行卡号 | ||
| 389 | + * @return | ||
| 390 | + */ | ||
| 391 | + public static boolean isBankNo(String bankNo) { | ||
| 392 | + //替换空格 | ||
| 393 | + bankNo = bankNo.replaceAll(" ", ""); | ||
| 394 | + //银行卡号可为12位数字 | ||
| 395 | + if (12 == bankNo.length()) { | ||
| 396 | + return true; | ||
| 397 | + } | ||
| 398 | + //银行卡号可为16-19位数字 | ||
| 399 | + return bankNo_pattern.matcher(bankNo).matches(); | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + /** | ||
| 403 | + * 验证身份证号码是否正确 | ||
| 404 | + * | ||
| 405 | + * @param IDCardNo 身份证号码 | ||
| 406 | + * @return boolean | ||
| 407 | + */ | ||
| 408 | + public static boolean isIDCard(String IDCardNo) { | ||
| 409 | + //记录错误信息 | ||
| 410 | + String errmsg = ""; | ||
| 411 | + String[] ValCodeArr = {"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"}; | ||
| 412 | + String[] Wi = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"}; | ||
| 413 | + String Ai = ""; | ||
| 414 | + | ||
| 415 | + //================ 身份证号码的长度 15位或18位 ================ | ||
| 416 | + if (IDCardNo.length() != 15 && IDCardNo.length() != 18) { | ||
| 417 | + errmsg = "身份证号码长度应该为15位或18位!"; | ||
| 418 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 419 | + return false; | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + //================ 数字 除最后以为都为数字 ================ | ||
| 423 | + if (IDCardNo.length() == 18) { | ||
| 424 | + Ai = IDCardNo.substring(0, 17); | ||
| 425 | + } else if (IDCardNo.length() == 15) { | ||
| 426 | + Ai = IDCardNo.substring(0, 6) + "19" + IDCardNo.substring(6, 15); | ||
| 427 | + } | ||
| 428 | + if (isNumber(Ai) == false) { | ||
| 429 | + errmsg = "身份证15位号码都应为数字 ; 18位号码除最后一位外,都应为数字"; | ||
| 430 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 431 | + return false; | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + //================ 出生年月是否有效 ================ | ||
| 435 | + //年份 | ||
| 436 | + String strYear = Ai.substring(6, 10); | ||
| 437 | + //月份 | ||
| 438 | + String strMonth = Ai.substring(10, 12); | ||
| 439 | + //日 | ||
| 440 | + String strDay = Ai.substring(12, 14); | ||
| 441 | + if (getDateIsTrue(strYear, strMonth, strDay) == false) { | ||
| 442 | + errmsg = "身份证生日无效"; | ||
| 443 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 444 | + return false; | ||
| 445 | + } | ||
| 446 | + GregorianCalendar gc = new GregorianCalendar(); | ||
| 447 | + SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 448 | + try { | ||
| 449 | + if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150 || (gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) { | ||
| 450 | + errmsg = "身份证生日不在有效范围"; | ||
| 451 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 452 | + return false; | ||
| 453 | + } | ||
| 454 | + } catch (NumberFormatException e) { | ||
| 455 | + e.printStackTrace(); | ||
| 456 | + errmsg = "身份证生日不在有效范围"; | ||
| 457 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 458 | + return false; | ||
| 459 | + } catch (java.text.ParseException e1) { | ||
| 460 | + e1.printStackTrace(); | ||
| 461 | + errmsg = "身份证生日不在有效范围"; | ||
| 462 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 463 | + return false; | ||
| 464 | + } | ||
| 465 | + if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) { | ||
| 466 | + errmsg = "身份证月份无效"; | ||
| 467 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 468 | + return false; | ||
| 469 | + } | ||
| 470 | + if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) { | ||
| 471 | + errmsg = "身份证日期无效"; | ||
| 472 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 473 | + return false; | ||
| 474 | + } | ||
| 475 | + | ||
| 476 | + //================ 地区码时候有效 ================ | ||
| 477 | + Hashtable hashtable = getAreaCodeAll(); | ||
| 478 | + if (hashtable.get(Ai.substring(0, 2)) == null) { | ||
| 479 | + errmsg = "身份证地区编码错误"; | ||
| 480 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 481 | + return false; | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + //================ 判断最后一位的值 ================ | ||
| 485 | + int TotalmulAiWi = 0; | ||
| 486 | + for (int i = 0; i < 17; i++) { | ||
| 487 | + TotalmulAiWi = TotalmulAiWi + Integer.parseInt(String.valueOf(Ai.charAt(i))) * Integer.parseInt(Wi[i]); | ||
| 488 | + } | ||
| 489 | + int modValue = TotalmulAiWi % 11; | ||
| 490 | + String strVerifyCode = ValCodeArr[modValue]; | ||
| 491 | + Ai = Ai + strVerifyCode; | ||
| 492 | + if (IDCardNo.length() == 18) { | ||
| 493 | + if (Ai.equals(IDCardNo) == false) { | ||
| 494 | + errmsg = "身份证无效,不是合法的身份证号码"; | ||
| 495 | + Log.e(TAG, "isIDCard: " + errmsg); | ||
| 496 | + return false; | ||
| 497 | + } | ||
| 498 | + } else { | ||
| 499 | + return true; | ||
| 500 | + } | ||
| 501 | + return true; | ||
| 502 | + } | ||
| 503 | + | ||
| 504 | + | ||
| 505 | + /** | ||
| 506 | + * 判断是否有特殊字符 | ||
| 507 | + * | ||
| 508 | + * @param str 验证字符 | ||
| 509 | + * @return boolean | ||
| 510 | + */ | ||
| 511 | + public static boolean isPeculiarStr(String str) { | ||
| 512 | + boolean flag = false; | ||
| 513 | + String regEx = "[^0-9a-zA-Z\u4e00-\u9fa5]+"; | ||
| 514 | + if (str.length() != (str.replaceAll(regEx, "").length())) { | ||
| 515 | + flag = true; | ||
| 516 | + } | ||
| 517 | + return flag; | ||
| 518 | + } | ||
| 519 | + | ||
| 520 | + | ||
| 521 | + /** | ||
| 522 | + * 判断是否为用户名账号(规则如下:用户名由下划线或字母开头,由数字、字母、下划线、点、减号组成的4-32位字符) | ||
| 523 | + * | ||
| 524 | + * @param username 用户名 | ||
| 525 | + * @return boolean | ||
| 526 | + */ | ||
| 527 | + public static boolean isUserName(String username) { | ||
| 528 | + return username_pattern.matcher(username).matches(); | ||
| 529 | + } | ||
| 530 | + | ||
| 531 | + /** | ||
| 532 | + * 获取字符串中文字符的长度(每个中文算2个字符). | ||
| 533 | + * | ||
| 534 | + * @param str 指定的字符串 | ||
| 535 | + * @return 中文字符的长度 | ||
| 536 | + */ | ||
| 537 | + public static int chineseLength(String str) { | ||
| 538 | + int valueLength = 0; | ||
| 539 | + String chinese = "[\u0391-\uFFE5]"; | ||
| 540 | + /* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */ | ||
| 541 | + if (!isEmpty(str)) { | ||
| 542 | + for (int i = 0; i < str.length(); i++) { | ||
| 543 | + /* 获取一个字符 */ | ||
| 544 | + String temp = str.substring(i, i + 1); | ||
| 545 | + /* 判断是否为中文字符 */ | ||
| 546 | + if (temp.matches(chinese)) { | ||
| 547 | + valueLength += 2; | ||
| 548 | + } | ||
| 549 | + } | ||
| 550 | + } | ||
| 551 | + return valueLength; | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + /** | ||
| 555 | + * 描述:获取字符串的长度. | ||
| 556 | + * | ||
| 557 | + * @param str 指定的字符串 | ||
| 558 | + * @return 字符串的长度(中文字符计2个) | ||
| 559 | + */ | ||
| 560 | + public static int strLength(String str) { | ||
| 561 | + int valueLength = 0; | ||
| 562 | + String chinese = "[\u0391-\uFFE5]"; | ||
| 563 | + if (!isEmpty(str)) { | ||
| 564 | + // 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 | ||
| 565 | + for (int i = 0; i < str.length(); i++) { | ||
| 566 | + // 获取一个字符 | ||
| 567 | + String temp = str.substring(i, i + 1); | ||
| 568 | + // 判断是否为中文字符 | ||
| 569 | + if (temp.matches(chinese)) { | ||
| 570 | + // 中文字符长度为2 | ||
| 571 | + valueLength += 2; | ||
| 572 | + } else { | ||
| 573 | + // 其他字符长度为1 | ||
| 574 | + valueLength += 1; | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + } | ||
| 578 | + return valueLength; | ||
| 579 | + } | ||
| 580 | + | ||
| 581 | + /** | ||
| 582 | + * 描述:获取指定长度的字符所在位置. | ||
| 583 | + * | ||
| 584 | + * @param str 指定的字符串 | ||
| 585 | + * @param maxL 要取到的长度(字符长度,中文字符计2个) | ||
| 586 | + * @return 字符的所在位置 | ||
| 587 | + */ | ||
| 588 | + public static int subStringLength(String str, int maxL) { | ||
| 589 | + int currentIndex = 0; | ||
| 590 | + int valueLength = 0; | ||
| 591 | + String chinese = "[\u0391-\uFFE5]"; | ||
| 592 | + // 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 | ||
| 593 | + for (int i = 0; i < str.length(); i++) { | ||
| 594 | + // 获取一个字符 | ||
| 595 | + String temp = str.substring(i, i + 1); | ||
| 596 | + // 判断是否为中文字符 | ||
| 597 | + if (temp.matches(chinese)) { | ||
| 598 | + // 中文字符长度为2 | ||
| 599 | + valueLength += 2; | ||
| 600 | + } else { | ||
| 601 | + // 其他字符长度为1 | ||
| 602 | + valueLength += 1; | ||
| 603 | + } | ||
| 604 | + if (valueLength >= maxL) { | ||
| 605 | + currentIndex = i; | ||
| 606 | + break; | ||
| 607 | + } | ||
| 608 | + } | ||
| 609 | + return currentIndex; | ||
| 610 | + } | ||
| 611 | + | ||
| 612 | + /** | ||
| 613 | + * 描述:是否只是字母和数字. | ||
| 614 | + * | ||
| 615 | + * @param str 指定的字符串 | ||
| 616 | + * @return 是否只是字母和数字:是为true,否则false | ||
| 617 | + */ | ||
| 618 | + public static Boolean isNumberLetter(String str) { | ||
| 619 | + Boolean isNoLetter = false; | ||
| 620 | + String expr = "^[A-Za-z0-9]+$"; | ||
| 621 | + if (str.matches(expr)) { | ||
| 622 | + isNoLetter = true; | ||
| 623 | + } | ||
| 624 | + return isNoLetter; | ||
| 625 | + } | ||
| 626 | + | ||
| 627 | + /** | ||
| 628 | + * 描述:是否包含中文. | ||
| 629 | + * | ||
| 630 | + * @param str 指定的字符串 | ||
| 631 | + * @return 是否包含中文:是为true,否则false | ||
| 632 | + */ | ||
| 633 | + public static Boolean isContainChinese(String str) { | ||
| 634 | + Boolean isChinese = false; | ||
| 635 | + String chinese = "[\u0391-\uFFE5]"; | ||
| 636 | + if (!isEmpty(str)) { | ||
| 637 | + // 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 | ||
| 638 | + for (int i = 0; i < str.length(); i++) { | ||
| 639 | + // 获取一个字符 | ||
| 640 | + String temp = str.substring(i, i + 1); | ||
| 641 | + // 判断是否为中文字符 | ||
| 642 | + if (temp.matches(chinese)) { | ||
| 643 | + isChinese = true; | ||
| 644 | + } else { | ||
| 645 | + | ||
| 646 | + } | ||
| 647 | + } | ||
| 648 | + } | ||
| 649 | + return isChinese; | ||
| 650 | + } | ||
| 651 | + | ||
| 652 | + /** | ||
| 653 | + * 描述:从输入流中获得String. | ||
| 654 | + * | ||
| 655 | + * @param is 输入流 | ||
| 656 | + * @return 获得的String | ||
| 657 | + */ | ||
| 658 | + public static String convertStreamToString(InputStream is) { | ||
| 659 | + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); | ||
| 660 | + StringBuilder sb = new StringBuilder(); | ||
| 661 | + String line = null; | ||
| 662 | + try { | ||
| 663 | + while ((line = reader.readLine()) != null) { | ||
| 664 | + sb.append(line + "\n"); | ||
| 665 | + } | ||
| 666 | + | ||
| 667 | + // 最后一个\n删除 | ||
| 668 | + if (sb.indexOf("\n") != -1 | ||
| 669 | + && sb.lastIndexOf("\n") == sb.length() - 1) { | ||
| 670 | + sb.delete(sb.lastIndexOf("\n"), sb.lastIndexOf("\n") + 1); | ||
| 671 | + } | ||
| 672 | + | ||
| 673 | + } catch (IOException e) { | ||
| 674 | + e.printStackTrace(); | ||
| 675 | + } finally { | ||
| 676 | + try { | ||
| 677 | + is.close(); | ||
| 678 | + } catch (IOException e) { | ||
| 679 | + e.printStackTrace(); | ||
| 680 | + } | ||
| 681 | + } | ||
| 682 | + return sb.toString(); | ||
| 683 | + } | ||
| 684 | + | ||
| 685 | + /** | ||
| 686 | + * 描述:截取字符串到指定字节长度. | ||
| 687 | + * | ||
| 688 | + * @param str the str | ||
| 689 | + * @param length 指定字节长度 | ||
| 690 | + * @return 截取后的字符串 | ||
| 691 | + */ | ||
| 692 | + public static String cutString(String str, int length) { | ||
| 693 | + return cutString(str, length, ""); | ||
| 694 | + } | ||
| 695 | + | ||
| 696 | + /** | ||
| 697 | + * 描述:截取字符串到指定字节长度. | ||
| 698 | + * | ||
| 699 | + * @param str 文本 | ||
| 700 | + * @param length 字节长度 | ||
| 701 | + * @param dot 省略符号 | ||
| 702 | + * @return 截取后的字符串 | ||
| 703 | + */ | ||
| 704 | + public static String cutString(String str, int length, String dot) { | ||
| 705 | + int strBLen = strlen(str, "GBK"); | ||
| 706 | + if (strBLen <= length) { | ||
| 707 | + return str; | ||
| 708 | + } | ||
| 709 | + int temp = 0; | ||
| 710 | + StringBuffer sb = new StringBuffer(length); | ||
| 711 | + char[] ch = str.toCharArray(); | ||
| 712 | + for (char c : ch) { | ||
| 713 | + sb.append(c); | ||
| 714 | + if (c > 256) { | ||
| 715 | + temp += 2; | ||
| 716 | + } else { | ||
| 717 | + temp += 1; | ||
| 718 | + } | ||
| 719 | + if (temp >= length) { | ||
| 720 | + if (dot != null) { | ||
| 721 | + sb.append(dot); | ||
| 722 | + } | ||
| 723 | + break; | ||
| 724 | + } | ||
| 725 | + } | ||
| 726 | + return sb.toString(); | ||
| 727 | + } | ||
| 728 | + | ||
| 729 | + /** | ||
| 730 | + * 描述:截取字符串从第一个指定字符. | ||
| 731 | + * | ||
| 732 | + * @param str1 原文本 | ||
| 733 | + * @param str2 指定字符 | ||
| 734 | + * @param offset 偏移的索引 | ||
| 735 | + * @return 截取后的字符串 | ||
| 736 | + */ | ||
| 737 | + public static String cutStringFromChar(String str1, String str2, int offset) { | ||
| 738 | + if (isEmpty(str1)) { | ||
| 739 | + return ""; | ||
| 740 | + } | ||
| 741 | + int start = str1.indexOf(str2); | ||
| 742 | + if (start != -1) { | ||
| 743 | + if (str1.length() > start + offset) { | ||
| 744 | + return str1.substring(start + offset); | ||
| 745 | + } | ||
| 746 | + } | ||
| 747 | + return ""; | ||
| 748 | + } | ||
| 749 | + | ||
| 750 | + /** | ||
| 751 | + * 描述:获取字节长度. | ||
| 752 | + * | ||
| 753 | + * @param str 文本 | ||
| 754 | + * @param charset 字符集(GBK) | ||
| 755 | + * @return the int | ||
| 756 | + */ | ||
| 757 | + public static int strlen(String str, String charset) { | ||
| 758 | + if (str == null || str.length() == 0) { | ||
| 759 | + return 0; | ||
| 760 | + } | ||
| 761 | + int length = 0; | ||
| 762 | + try { | ||
| 763 | + length = str.getBytes(charset).length; | ||
| 764 | + } catch (Exception e) { | ||
| 765 | + e.printStackTrace(); | ||
| 766 | + } | ||
| 767 | + return length; | ||
| 768 | + } | ||
| 769 | + | ||
| 770 | + /** | ||
| 771 | + * 获取大小的描述. | ||
| 772 | + * | ||
| 773 | + * @param size 字节个数 | ||
| 774 | + * @return 大小的描述 | ||
| 775 | + */ | ||
| 776 | + public static String getSizeDesc(long size) { | ||
| 777 | + String suffix = "B"; | ||
| 778 | + if (size >= 1024) { | ||
| 779 | + suffix = "K"; | ||
| 780 | + size = size >> 10; | ||
| 781 | + if (size >= 1024) { | ||
| 782 | + suffix = "M"; | ||
| 783 | + // size /= 1024; | ||
| 784 | + size = size >> 10; | ||
| 785 | + if (size >= 1024) { | ||
| 786 | + suffix = "G"; | ||
| 787 | + size = size >> 10; | ||
| 788 | + // size /= 1024; | ||
| 789 | + } | ||
| 790 | + } | ||
| 791 | + } | ||
| 792 | + return size + suffix; | ||
| 793 | + } | ||
| 794 | + | ||
| 795 | + /** | ||
| 796 | + * 描述:ip地址转换为10进制数. | ||
| 797 | + * | ||
| 798 | + * @param ip the ip | ||
| 799 | + * @return the long | ||
| 800 | + */ | ||
| 801 | + public static long ip2int(String ip) { | ||
| 802 | + ip = ip.replace(".", ","); | ||
| 803 | + String[] items = ip.split(","); | ||
| 804 | + return Long.valueOf(items[0]) << 24 | Long.valueOf(items[1]) << 16 | ||
| 805 | + | Long.valueOf(items[2]) << 8 | Long.valueOf(items[3]); | ||
| 806 | + } | ||
| 807 | + | ||
| 808 | + /** | ||
| 809 | + * 获取UUID | ||
| 810 | + * | ||
| 811 | + * @return 32UUID小写字符串 | ||
| 812 | + */ | ||
| 813 | + public static String gainUUID() { | ||
| 814 | + String strUUID = UUID.randomUUID().toString(); | ||
| 815 | + strUUID = strUUID.replaceAll("-", "").toLowerCase(); | ||
| 816 | + return strUUID; | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + | ||
| 820 | + /** | ||
| 821 | + * 手机号码,中间4位星号替换 | ||
| 822 | + * | ||
| 823 | + * @param phone 手机号 | ||
| 824 | + * @return 星号替换的手机号 | ||
| 825 | + */ | ||
| 826 | + public static String phoneNoHide(String phone) { | ||
| 827 | + // 括号表示组,被替换的部分$n表示第n组的内容 | ||
| 828 | + // 正则表达式中,替换字符串,括号的意思是分组,在replace()方法中, | ||
| 829 | + // 参数二中可以使用$n(n为数字)来依次引用模式串中用括号定义的字串。 | ||
| 830 | + // "(\d{3})\d{4}(\d{4})", "$1****$2"的这个意思就是用括号, | ||
| 831 | + // 分为(前3个数字)中间4个数字(最后4个数字)替换为(第一组数值,保持不变$1)(中间为*)(第二组数值,保持不变$2) | ||
| 832 | + return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); | ||
| 833 | + } | ||
| 834 | + | ||
| 835 | + /** | ||
| 836 | + * 银行卡号,保留最后4位,其他星号替换 | ||
| 837 | + * | ||
| 838 | + * @param cardId 卡号 | ||
| 839 | + * @return 星号替换的银行卡号 | ||
| 840 | + */ | ||
| 841 | + public static String cardIdHide(String cardId) { | ||
| 842 | + return cardId.replaceAll("\\d{15}(\\d{3})", "**** **** **** **** $1"); | ||
| 843 | + } | ||
| 844 | + | ||
| 845 | + /** | ||
| 846 | + * 身份证号,中间10位星号替换 | ||
| 847 | + * | ||
| 848 | + * @param id 身份证号 | ||
| 849 | + * @return 星号替换的身份证号 | ||
| 850 | + */ | ||
| 851 | + public static String idHide(String id) { | ||
| 852 | + return id.replaceAll("(\\d{4})\\d{10}(\\d{4})", "$1** **** ****$2"); | ||
| 853 | + } | ||
| 854 | + | ||
| 855 | + /** | ||
| 856 | + * 是否为车牌号(沪A88888) | ||
| 857 | + * | ||
| 858 | + * @param vehicleNo 车牌号 | ||
| 859 | + * @return 是否为车牌号 | ||
| 860 | + */ | ||
| 861 | + | ||
| 862 | + public static boolean checkVehicleNo(String vehicleNo) { | ||
| 863 | + Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{5}$"); | ||
| 864 | + return pattern.matcher(vehicleNo).find(); | ||
| 865 | + | ||
| 866 | + } | ||
| 867 | + | ||
| 868 | +// /** | ||
| 869 | +// * 匹配中国邮政编码 | ||
| 870 | +// * | ||
| 871 | +// * @param postcode 邮政编码 | ||
| 872 | +// * @return 验证成功返回true,验证失败返回false | ||
| 873 | +// */ | ||
| 874 | +// public static boolean checkPostcode(String postcode) { | ||
| 875 | +// String regex = "[1-9]\\d{5}"; | ||
| 876 | +// return Pattern.matches(regex, postcode); | ||
| 877 | +// } | ||
| 878 | + | ||
| 879 | + | ||
| 880 | + /** | ||
| 881 | + * 判断字符串是否为连续数字 45678901等 | ||
| 882 | + * | ||
| 883 | + * @param str 待验证的字符串 | ||
| 884 | + * @return 是否为连续数字 | ||
| 885 | + */ | ||
| 886 | + public static boolean isContinuousNum(String str) { | ||
| 887 | + if (TextUtils.isEmpty(str)) | ||
| 888 | + return false; | ||
| 889 | + if (!isNumber(str)) | ||
| 890 | + return true; | ||
| 891 | + int len = str.length(); | ||
| 892 | + for (int i = 0; i < len - 1; i++) { | ||
| 893 | + char curChar = str.charAt(i); | ||
| 894 | + char verifyChar = (char) (curChar + 1); | ||
| 895 | + if (curChar == '9') | ||
| 896 | + verifyChar = '0'; | ||
| 897 | + char nextChar = str.charAt(i + 1); | ||
| 898 | + if (nextChar != verifyChar) { | ||
| 899 | + return false; | ||
| 900 | + } | ||
| 901 | + } | ||
| 902 | + return true; | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + /** | ||
| 906 | + * 是否是纯字母 | ||
| 907 | + * | ||
| 908 | + * @param str 待验证的字符串 | ||
| 909 | + * @return 是否是纯字母 | ||
| 910 | + */ | ||
| 911 | + public static boolean isAlphaBetaString(String str) { | ||
| 912 | + if (TextUtils.isEmpty(str)) { | ||
| 913 | + return false; | ||
| 914 | + } | ||
| 915 | + | ||
| 916 | + Pattern p = Pattern.compile("^[a-zA-Z]+$");// 从开头到结尾必须全部为字母或者数字 | ||
| 917 | + Matcher m = p.matcher(str); | ||
| 918 | + | ||
| 919 | + return m.find(); | ||
| 920 | + } | ||
| 921 | + | ||
| 922 | + /** | ||
| 923 | + * 判断字符串是否为连续字母 xyZaBcd等 | ||
| 924 | + * | ||
| 925 | + * @param str 待验证的字符串 | ||
| 926 | + * @return 是否为连续字母 | ||
| 927 | + */ | ||
| 928 | + public static boolean isContinuousWord(String str) { | ||
| 929 | + if (TextUtils.isEmpty(str)) | ||
| 930 | + return false; | ||
| 931 | + if (!isAlphaBetaString(str)) | ||
| 932 | + return true; | ||
| 933 | + int len = str.length(); | ||
| 934 | + String local = str.toLowerCase(); | ||
| 935 | + for (int i = 0; i < len - 1; i++) { | ||
| 936 | + char curChar = local.charAt(i); | ||
| 937 | + char verifyChar = (char) (curChar + 1); | ||
| 938 | + if (curChar == 'z') | ||
| 939 | + verifyChar = 'a'; | ||
| 940 | + char nextChar = local.charAt(i + 1); | ||
| 941 | + if (nextChar != verifyChar) { | ||
| 942 | + return false; | ||
| 943 | + } | ||
| 944 | + } | ||
| 945 | + return true; | ||
| 946 | + } | ||
| 947 | + | ||
| 948 | + /** | ||
| 949 | + * 是否是日期 | ||
| 950 | + * 20120506 共八位,前四位-年,中间两位-月,最后两位-日 | ||
| 951 | + * | ||
| 952 | + * @param date 待验证的字符串 | ||
| 953 | + * @param yearlen yearlength | ||
| 954 | + * @return 是否是真实的日期 | ||
| 955 | + */ | ||
| 956 | + public static boolean isRealDate(String date, int yearlen) { | ||
| 957 | + int len = 4 + yearlen; | ||
| 958 | + if (date == null || date.length() != len) | ||
| 959 | + return false; | ||
| 960 | + | ||
| 961 | + if (!date.matches("[0-9]+")) | ||
| 962 | + return false; | ||
| 963 | + | ||
| 964 | + int year = Integer.parseInt(date.substring(0, yearlen)); | ||
| 965 | + int month = Integer.parseInt(date.substring(yearlen, yearlen + 2)); | ||
| 966 | + int day = Integer.parseInt(date.substring(yearlen + 2, yearlen + 4)); | ||
| 967 | + | ||
| 968 | + if (year <= 0) | ||
| 969 | + return false; | ||
| 970 | + if (month <= 0 || month > 12) | ||
| 971 | + return false; | ||
| 972 | + if (day <= 0 || day > 31) | ||
| 973 | + return false; | ||
| 974 | + | ||
| 975 | + switch (month) { | ||
| 976 | + case 4: | ||
| 977 | + case 6: | ||
| 978 | + case 9: | ||
| 979 | + case 11: | ||
| 980 | + return day > 30 ? false : true; | ||
| 981 | + case 2: | ||
| 982 | + if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) | ||
| 983 | + return day > 29 ? false : true; | ||
| 984 | + return day > 28 ? false : true; | ||
| 985 | + default: | ||
| 986 | + return true; | ||
| 987 | + } | ||
| 988 | + } | ||
| 989 | + | ||
| 990 | + | ||
| 991 | + /** | ||
| 992 | + * 检查日期是否有效 | ||
| 993 | + * | ||
| 994 | + * @param year 年 | ||
| 995 | + * @param month 月 | ||
| 996 | + * @param day 日 | ||
| 997 | + * @return boolean | ||
| 998 | + */ | ||
| 999 | + public static boolean getDateIsTrue(String year, String month, String day) { | ||
| 1000 | + try { | ||
| 1001 | + String data = year + month + day; | ||
| 1002 | + SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); | ||
| 1003 | + simpledateformat.setLenient(false); | ||
| 1004 | + simpledateformat.parse(data); | ||
| 1005 | + } catch (ParseException e) { | ||
| 1006 | + e.printStackTrace(); | ||
| 1007 | + Log.e(TAG, "getDateIsTrue: " + e.getMessage().toString()); | ||
| 1008 | + return false; | ||
| 1009 | + } | ||
| 1010 | + return true; | ||
| 1011 | + } | ||
| 1012 | + | ||
| 1013 | + | ||
| 1014 | + /** | ||
| 1015 | + * 获取身份证号所有区域编码设置 | ||
| 1016 | + * | ||
| 1017 | + * @return Hashtable | ||
| 1018 | + */ | ||
| 1019 | + @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| 1020 | + public static Hashtable getAreaCodeAll() { | ||
| 1021 | + Hashtable hashtable = new Hashtable(); | ||
| 1022 | + hashtable.put("11", "北京"); | ||
| 1023 | + hashtable.put("12", "天津"); | ||
| 1024 | + hashtable.put("13", "河北"); | ||
| 1025 | + hashtable.put("14", "山西"); | ||
| 1026 | + hashtable.put("15", "内蒙古"); | ||
| 1027 | + hashtable.put("21", "辽宁"); | ||
| 1028 | + hashtable.put("22", "吉林"); | ||
| 1029 | + hashtable.put("23", "黑龙江"); | ||
| 1030 | + hashtable.put("31", "上海"); | ||
| 1031 | + hashtable.put("32", "江苏"); | ||
| 1032 | + hashtable.put("33", "浙江"); | ||
| 1033 | + hashtable.put("34", "安徽"); | ||
| 1034 | + hashtable.put("35", "福建"); | ||
| 1035 | + hashtable.put("36", "江西"); | ||
| 1036 | + hashtable.put("37", "山东"); | ||
| 1037 | + hashtable.put("41", "河南"); | ||
| 1038 | + hashtable.put("42", "湖北"); | ||
| 1039 | + hashtable.put("43", "湖南"); | ||
| 1040 | + hashtable.put("44", "广东"); | ||
| 1041 | + hashtable.put("45", "广西"); | ||
| 1042 | + hashtable.put("46", "海南"); | ||
| 1043 | + hashtable.put("50", "重庆"); | ||
| 1044 | + hashtable.put("51", "四川"); | ||
| 1045 | + hashtable.put("52", "贵州"); | ||
| 1046 | + hashtable.put("53", "云南"); | ||
| 1047 | + hashtable.put("54", "西藏"); | ||
| 1048 | + hashtable.put("61", "陕西"); | ||
| 1049 | + hashtable.put("62", "甘肃"); | ||
| 1050 | + hashtable.put("63", "青海"); | ||
| 1051 | + hashtable.put("64", "宁夏"); | ||
| 1052 | + hashtable.put("65", "新疆"); | ||
| 1053 | + hashtable.put("71", "台湾"); | ||
| 1054 | + hashtable.put("81", "香港"); | ||
| 1055 | + hashtable.put("82", "澳门"); | ||
| 1056 | + hashtable.put("91", "国外"); | ||
| 1057 | + return hashtable; | ||
| 1058 | + } | ||
| 1059 | +} |
core/base/src/main/java/com/cnlive/core/libs/base/util/ViewUtils.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.app.Activity; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.content.ContextWrapper; | ||
| 6 | +import android.content.res.Resources; | ||
| 7 | +import android.content.res.TypedArray; | ||
| 8 | +import android.graphics.Bitmap; | ||
| 9 | +import android.graphics.Canvas; | ||
| 10 | +import android.graphics.Matrix; | ||
| 11 | +import android.graphics.Paint; | ||
| 12 | +import android.graphics.drawable.BitmapDrawable; | ||
| 13 | +import android.view.LayoutInflater; | ||
| 14 | +import android.view.MotionEvent; | ||
| 15 | +import android.view.View; | ||
| 16 | +import android.view.ViewGroup; | ||
| 17 | +import android.view.ViewParent; | ||
| 18 | +import android.widget.PopupWindow; | ||
| 19 | +import android.widget.TextView; | ||
| 20 | + | ||
| 21 | +import com.cnlive.strike.base.R; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * removeSelfFromParent : 把自身从父View中移除 | ||
| 25 | + * isTouchInView : 判断触点是否落在该View上 | ||
| 26 | + * setTVUnderLine : 给TextView设置下划线 | ||
| 27 | + * showPopupWindow : 显示PopupWindow | ||
| 28 | + * dismissPopup : 关闭PopupWindow | ||
| 29 | + * captureView : 截图 | ||
| 30 | + * createViewBitmap : 截图 | ||
| 31 | + * convertViewToBitmap : 截图 | ||
| 32 | + * getActivityBitmap : 获取Activity的截图 | ||
| 33 | + * getStatusBarHeight : 获取状态栏高度 | ||
| 34 | + * getToolbarHeight : 获取工具栏高度 | ||
| 35 | + * getNavigationBarHeight : 获取导航栏高度 | ||
| 36 | + * measureView : 测量view | ||
| 37 | + * getViewWidth : 获取view的宽度 | ||
| 38 | + * getViewHeight : 获取view的高度 | ||
| 39 | + * getActivity : 获取view的上下文 | ||
| 40 | + */ | ||
| 41 | +public class ViewUtils { | ||
| 42 | + private ViewUtils() { | ||
| 43 | + throw new UnsupportedOperationException("cannot be instantiated"); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 把自身从父View中移除 | ||
| 48 | + */ | ||
| 49 | + public static void removeSelfFromParent(View view) { | ||
| 50 | + if (view != null) { | ||
| 51 | + ViewParent parent = view.getParent(); | ||
| 52 | + if (parent != null && parent instanceof ViewGroup) { | ||
| 53 | + ViewGroup group = (ViewGroup) parent; | ||
| 54 | + group.removeView(view); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 判断触点是否落在该View上 | ||
| 61 | + */ | ||
| 62 | + public static boolean isTouchInView(MotionEvent ev, View v) { | ||
| 63 | + int[] vLoc = new int[2]; | ||
| 64 | + v.getLocationOnScreen(vLoc); | ||
| 65 | + float motionX = ev.getRawX(); | ||
| 66 | + float motionY = ev.getRawY(); | ||
| 67 | + return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth()) | ||
| 68 | + && motionY >= vLoc[1] && motionY <= (vLoc[1] + v.getHeight()); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * @param view | ||
| 73 | + * @param isAll | ||
| 74 | + */ | ||
| 75 | + public static void requestLayoutParent(View view, boolean isAll) { | ||
| 76 | + ViewParent parent = view.getParent(); | ||
| 77 | + while (parent != null && parent instanceof View) { | ||
| 78 | + if (!parent.isLayoutRequested()) { | ||
| 79 | + parent.requestLayout(); | ||
| 80 | + if (!isAll) { | ||
| 81 | + break; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + parent = parent.getParent(); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * @param bmp | ||
| 90 | + * @param big | ||
| 91 | + * @return | ||
| 92 | + */ | ||
| 93 | + public static Bitmap bigImage(Bitmap bmp, float big) { | ||
| 94 | + int bmpWidth = bmp.getWidth(); | ||
| 95 | + int bmpHeight = bmp.getHeight(); | ||
| 96 | + Matrix matrix = new Matrix(); | ||
| 97 | + matrix.postScale(big, big); | ||
| 98 | + return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * 给TextView设置下划线 | ||
| 103 | + * | ||
| 104 | + * @param textView | ||
| 105 | + */ | ||
| 106 | + public static void setTVUnderLine(TextView textView) { | ||
| 107 | + textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); | ||
| 108 | + textView.getPaint().setAntiAlias(true); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + | ||
| 112 | + static PopupWindow popupWindow; | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 显示PopupWindow | ||
| 116 | + * | ||
| 117 | + * @param context | ||
| 118 | + * @param resId | ||
| 119 | + * @param root | ||
| 120 | + * @param paramsType | ||
| 121 | + * @return | ||
| 122 | + */ | ||
| 123 | + public static View showPopupWindow(Context context, int resId, View root, int paramsType) { | ||
| 124 | + View popupView; | ||
| 125 | + popupView = LayoutInflater.from(context).inflate(resId, null); | ||
| 126 | + | ||
| 127 | + switch (paramsType) { | ||
| 128 | + case 1: | ||
| 129 | + popupWindow = new PopupWindow(popupView, | ||
| 130 | + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true); | ||
| 131 | + break; | ||
| 132 | + case 2: | ||
| 133 | + popupWindow = new PopupWindow(popupView, | ||
| 134 | + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); | ||
| 135 | + break; | ||
| 136 | + case 3: | ||
| 137 | + popupWindow = new PopupWindow(popupView, | ||
| 138 | + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, true); | ||
| 139 | + break; | ||
| 140 | + case 4: | ||
| 141 | + popupWindow = new PopupWindow(popupView, | ||
| 142 | + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); | ||
| 143 | + break; | ||
| 144 | + default: | ||
| 145 | + popupWindow = new PopupWindow(popupView, | ||
| 146 | + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true); | ||
| 147 | + break; | ||
| 148 | + } | ||
| 149 | + popupWindow.setFocusable(true); | ||
| 150 | + popupWindow.setOutsideTouchable(true); | ||
| 151 | + popupWindow.setTouchable(true); | ||
| 152 | + popupWindow.setBackgroundDrawable(new BitmapDrawable()); | ||
| 153 | + popupWindow.showAsDropDown(root); | ||
| 154 | + return popupView; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * 关闭PopupWindow | ||
| 159 | + */ | ||
| 160 | + public static void dismissPopup() { | ||
| 161 | + if (popupWindow != null && popupWindow.isShowing()) { | ||
| 162 | + popupWindow.dismiss(); | ||
| 163 | + popupWindow = null; | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * 截图 | ||
| 169 | + * | ||
| 170 | + * @param v | ||
| 171 | + * @return | ||
| 172 | + */ | ||
| 173 | + public static Bitmap captureView(View v) { | ||
| 174 | + v.setDrawingCacheEnabled(true); | ||
| 175 | + v.buildDrawingCache(); | ||
| 176 | + return v.getDrawingCache(); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 截图 | ||
| 181 | + * | ||
| 182 | + * @param v | ||
| 183 | + * @return | ||
| 184 | + */ | ||
| 185 | + public static Bitmap createViewBitmap(View v) { | ||
| 186 | + Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); | ||
| 187 | + Canvas canvas = new Canvas(bitmap); | ||
| 188 | + v.draw(canvas); | ||
| 189 | + return bitmap; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + /** | ||
| 193 | + * 截图 | ||
| 194 | + * | ||
| 195 | + * @param view | ||
| 196 | + * @return | ||
| 197 | + */ | ||
| 198 | + public static Bitmap convertViewToBitmap(View view) { | ||
| 199 | + view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | ||
| 200 | + view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); | ||
| 201 | + view.buildDrawingCache(); | ||
| 202 | + return view.getDrawingCache(); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * 获取Activity的截图 | ||
| 207 | + * | ||
| 208 | + * @param activity | ||
| 209 | + * @return | ||
| 210 | + */ | ||
| 211 | + public static Bitmap getActivityBitmap(Activity activity) { | ||
| 212 | + View view = activity.getWindow().getDecorView().findViewById(android.R.id.content); | ||
| 213 | + view.setDrawingCacheEnabled(true); | ||
| 214 | + return view.getDrawingCache(); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 获取状态栏高度 | ||
| 219 | + * | ||
| 220 | + * @param context | ||
| 221 | + * @return | ||
| 222 | + */ | ||
| 223 | + public static int getStatusBarHeight(Context context) { | ||
| 224 | + int result = 0; | ||
| 225 | + int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); | ||
| 226 | + if (resourceId > 0) { | ||
| 227 | + result = context.getResources().getDimensionPixelSize(resourceId); | ||
| 228 | + } | ||
| 229 | + return result; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * 获取工具栏高度 | ||
| 234 | + * | ||
| 235 | + * @param context | ||
| 236 | + * @return | ||
| 237 | + */ | ||
| 238 | + public static int getToolbarHeight(Context context) { | ||
| 239 | + final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(new int[]{R.attr.actionBarSize}); | ||
| 240 | + int toolbarHeight = (int) styledAttributes.getDimension(0, 0); | ||
| 241 | + styledAttributes.recycle(); | ||
| 242 | + return toolbarHeight; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + /** | ||
| 246 | + * 获取导航栏高度 | ||
| 247 | + * | ||
| 248 | + * @param activity | ||
| 249 | + * @return | ||
| 250 | + */ | ||
| 251 | + public static int getNavigationBarHeight(Activity activity) { | ||
| 252 | + Resources resources = activity.getResources(); | ||
| 253 | + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); | ||
| 254 | + if (resourceId > 0) { | ||
| 255 | + return resources.getDimensionPixelSize(resourceId); | ||
| 256 | + } | ||
| 257 | + return 0; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * 测量view | ||
| 262 | + * | ||
| 263 | + * @param view | ||
| 264 | + */ | ||
| 265 | + public static void measureView(View view) { | ||
| 266 | + ViewGroup.LayoutParams p = view.getLayoutParams(); | ||
| 267 | + if (p == null) { | ||
| 268 | + p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width); | ||
| 272 | + int lpHeight = p.height; | ||
| 273 | + int childHeightSpec; | ||
| 274 | + if (lpHeight > 0) { | ||
| 275 | + childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY); | ||
| 276 | + } else { | ||
| 277 | + childHeightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); | ||
| 278 | + } | ||
| 279 | + view.measure(childWidthSpec, childHeightSpec); | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + /** | ||
| 283 | + * 获取view的宽度 | ||
| 284 | + * | ||
| 285 | + * @param view | ||
| 286 | + * @return | ||
| 287 | + */ | ||
| 288 | + public static int getViewWidth(View view) { | ||
| 289 | + measureView(view); | ||
| 290 | + return view.getMeasuredWidth(); | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + /** | ||
| 294 | + * 获取view的高度 | ||
| 295 | + * | ||
| 296 | + * @param view | ||
| 297 | + * @return | ||
| 298 | + */ | ||
| 299 | + public static int getViewHeight(View view) { | ||
| 300 | + measureView(view); | ||
| 301 | + return view.getMeasuredHeight(); | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + /** | ||
| 305 | + * 获取view的上下文 | ||
| 306 | + * | ||
| 307 | + * @param view | ||
| 308 | + * @return | ||
| 309 | + */ | ||
| 310 | + public static Activity getActivity(View view) { | ||
| 311 | + Context context = view.getContext(); | ||
| 312 | + while (context instanceof ContextWrapper) { | ||
| 313 | + if (context instanceof Activity) { | ||
| 314 | + return (Activity) context; | ||
| 315 | + } | ||
| 316 | + context = ((ContextWrapper) context).getBaseContext(); | ||
| 317 | + } | ||
| 318 | + throw new IllegalStateException("View " + view + " is not attached to an Activity"); | ||
| 319 | + } | ||
| 320 | +} |
core/network/src/main/java/com/cnlive/core/network/HttpConn.java
| @@ -3,6 +3,7 @@ package com.cnlive.core.network; | @@ -3,6 +3,7 @@ package com.cnlive.core.network; | ||
| 3 | 3 | ||
| 4 | import com.cnlive.core.libs.base.application.BaseApplication; | 4 | import com.cnlive.core.libs.base.application.BaseApplication; |
| 5 | import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 5 | import com.cnlive.core.libs.base.network.manager.SubscriptionManager; |
| 6 | +import com.cnlive.core.network.interfaces.IBaseResult; | ||
| 6 | import com.cnlive.core.network.model.BaseObserver; | 7 | import com.cnlive.core.network.model.BaseObserver; |
| 7 | import com.cnlive.core.network.model.BaseResult; | 8 | import com.cnlive.core.network.model.BaseResult; |
| 8 | import com.cnlive.core.libs.base.util.NetworkUtil; | 9 | import com.cnlive.core.libs.base.util.NetworkUtil; |
| @@ -34,107 +35,56 @@ public class HttpConn { | @@ -34,107 +35,56 @@ public class HttpConn { | ||
| 34 | 35 | ||
| 35 | public static <T> Disposable action(Observable<T> observable, final NetCallBack<T> callBack) { | 36 | public static <T> Disposable action(Observable<T> observable, final NetCallBack<T> callBack) { |
| 36 | disposable = null; | 37 | disposable = null; |
| 37 | - if (null != BaseApplication.getInstance()) { | ||
| 38 | - if (!NetworkUtil.isConnectInternet(BaseApplication.getInstance())) { | ||
| 39 | - if (null != callBack) { | ||
| 40 | - callBack.onFailure(API_ERROR_NETWORK, API_MESSAGE_NETWORK); | ||
| 41 | - } | ||
| 42 | - } else { | ||
| 43 | - observable | ||
| 44 | - .subscribeOn(Schedulers.io()) | ||
| 45 | - .observeOn(AndroidSchedulers.mainThread()) | ||
| 46 | - .subscribe(new BaseObserver<T>() { | ||
| 47 | - @Override | ||
| 48 | - protected void onRequestStart(Disposable d) { | ||
| 49 | - super.onRequestStart(d); | ||
| 50 | - disposable = d; | ||
| 51 | - if (null != callBack) { | ||
| 52 | - callBack.onRequestState(ON_START); | ||
| 53 | - } | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - @Override | ||
| 57 | - protected void onRequestEnd() { | ||
| 58 | - super.onRequestEnd(); | ||
| 59 | - if (null != callBack) { | ||
| 60 | - callBack.onRequestState(ON_END); | ||
| 61 | - } | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - @Override | ||
| 65 | - protected void onSuccess(T result) throws Exception { | ||
| 66 | - if (null != callBack) { | ||
| 67 | - callBack.onSuccess(result); | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - @Override | ||
| 72 | - protected void onCodeError(String errCode, String errMsg) throws Exception { | ||
| 73 | - if (null != callBack) { | ||
| 74 | - callBack.onFailure(errCode, errMsg); | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - @Override | ||
| 79 | - protected void onFailure(String errCode, String errMsg) throws Exception { | ||
| 80 | - if (null != callBack) { | ||
| 81 | - callBack.onFailure(errCode, errMsg); | ||
| 82 | - } | ||
| 83 | - } | ||
| 84 | - }); | ||
| 85 | - } | ||
| 86 | - } else { | ||
| 87 | - observable | ||
| 88 | - .subscribeOn(Schedulers.io()) | ||
| 89 | - .observeOn(AndroidSchedulers.mainThread()) | ||
| 90 | - .subscribe(new BaseObserver<T>() { | ||
| 91 | - @Override | ||
| 92 | - protected void onRequestStart(Disposable d) { | ||
| 93 | - super.onRequestStart(d); | ||
| 94 | - disposable = d; | ||
| 95 | - if (null != callBack) { | ||
| 96 | - callBack.onRequestState(ON_START); | ||
| 97 | - } | 38 | + observable |
| 39 | + .subscribeOn(Schedulers.io()) | ||
| 40 | + .observeOn(AndroidSchedulers.mainThread()) | ||
| 41 | + .subscribe(new BaseObserver<T>() { | ||
| 42 | + @Override | ||
| 43 | + protected void onRequestStart(Disposable d) { | ||
| 44 | + super.onRequestStart(d); | ||
| 45 | + disposable = d; | ||
| 46 | + if (null != callBack) { | ||
| 47 | + callBack.onRequestState(ON_START); | ||
| 98 | } | 48 | } |
| 49 | + } | ||
| 99 | 50 | ||
| 100 | - @Override | ||
| 101 | - protected void onRequestEnd() { | ||
| 102 | - super.onRequestEnd(); | ||
| 103 | - if (null != callBack) { | ||
| 104 | - callBack.onRequestState(ON_END); | ||
| 105 | - } | 51 | + @Override |
| 52 | + protected void onRequestEnd() { | ||
| 53 | + super.onRequestEnd(); | ||
| 54 | + if (null != callBack) { | ||
| 55 | + callBack.onRequestState(ON_END); | ||
| 106 | } | 56 | } |
| 57 | + } | ||
| 107 | 58 | ||
| 108 | - @Override | ||
| 109 | - protected void onSuccess(T result) throws Exception { | ||
| 110 | - if (null != callBack) { | ||
| 111 | - callBack.onSuccess(result); | ||
| 112 | - } | 59 | + @Override |
| 60 | + protected void onSuccess(T result) { | ||
| 61 | + if (null != callBack) { | ||
| 62 | + callBack.onSuccess(result); | ||
| 113 | } | 63 | } |
| 64 | + } | ||
| 114 | 65 | ||
| 115 | - @Override | ||
| 116 | - protected void onCodeError(String errCode, String errMsg) throws Exception { | ||
| 117 | - if (null != callBack) { | ||
| 118 | - callBack.onFailure(errCode, errMsg); | ||
| 119 | - } | 66 | + @Override |
| 67 | + protected void onCodeError(String errCode, String errMsg) { | ||
| 68 | + if (null != callBack) { | ||
| 69 | + callBack.onFailure(errCode, errMsg); | ||
| 120 | } | 70 | } |
| 71 | + } | ||
| 121 | 72 | ||
| 122 | - @Override | ||
| 123 | - protected void onFailure(String errCode, String errMsg) throws Exception { | ||
| 124 | - if (null != callBack) { | ||
| 125 | - callBack.onFailure(errCode, errMsg); | ||
| 126 | - } | 73 | + @Override |
| 74 | + protected void onFailure(String errCode, String errMsg) throws Exception { | ||
| 75 | + if (null != callBack) { | ||
| 76 | + callBack.onFailure(errCode, errMsg); | ||
| 127 | } | 77 | } |
| 128 | - }); | ||
| 129 | - } | ||
| 130 | - // .doOnSubscribe(new Consumer<Disposable>() { | ||
| 131 | - // @Override | ||
| 132 | - // public void accept(Disposable disposable) throws Exception { | ||
| 133 | - // if (null != callBack) { | ||
| 134 | - // callBack.onRequestState(ON_START); | ||
| 135 | - // } | ||
| 136 | - // } | ||
| 137 | - // }) | 78 | + } |
| 79 | + }); | ||
| 80 | +// .doOnSubscribe(new Consumer<Disposable>() { | ||
| 81 | +// @Override | ||
| 82 | +// public void accept(Disposable disposable) throws Exception { | ||
| 83 | +// if (null != callBack) { | ||
| 84 | +// callBack.onRequestState(ON_START); | ||
| 85 | +// } | ||
| 86 | +// } | ||
| 87 | +// }) | ||
| 138 | // .doOnNext(new Consumer<T>() { | 88 | // .doOnNext(new Consumer<T>() { |
| 139 | // @Override | 89 | // @Override |
| 140 | // public void accept(T t) throws Exception { | 90 | // public void accept(T t) throws Exception { |
| @@ -179,13 +129,14 @@ public class HttpConn { | @@ -179,13 +129,14 @@ public class HttpConn { | ||
| 179 | // } | 129 | // } |
| 180 | // } | 130 | // } |
| 181 | // }); | 131 | // }); |
| 182 | - if (null != disposable) { | 132 | + //如果未解除订阅 |
| 133 | + if (null != disposable && !disposable.isDisposed()) { | ||
| 183 | SubscriptionManager.getInstance().add(disposable); | 134 | SubscriptionManager.getInstance().add(disposable); |
| 184 | } | 135 | } |
| 185 | return disposable; | 136 | return disposable; |
| 186 | } | 137 | } |
| 187 | 138 | ||
| 188 | - // /** | 139 | +// /** |
| 189 | // * 返回原数据 | 140 | // * 返回原数据 |
| 190 | // * | 141 | // * |
| 191 | // * @param observable | 142 | // * @param observable |
| @@ -260,11 +211,11 @@ public class HttpConn { | @@ -260,11 +211,11 @@ public class HttpConn { | ||
| 260 | * @return | 211 | * @return |
| 261 | */ | 212 | */ |
| 262 | public static <T> Observable error(T t) { | 213 | public static <T> Observable error(T t) { |
| 263 | - if (t instanceof BaseResult) { | ||
| 264 | - BaseResult baseResult = (BaseResult) t; | ||
| 265 | - return Observable.error(new ServerException(baseResult.getErrorCode(), baseResult.getMessage())); | 214 | + if (t instanceof IBaseResult) { |
| 215 | + IBaseResult baseResult = (BaseResult) t; | ||
| 216 | + return Observable.error(new ServerException(baseResult.getCode(), baseResult.getMessage())); | ||
| 266 | } | 217 | } |
| 267 | - return null; | 218 | + return Observable.error(new ServerException(EXCEPTION_CODE, "未知错误")); |
| 268 | } | 219 | } |
| 269 | 220 | ||
| 270 | /** | 221 | /** |
core/network/src/main/java/com/cnlive/core/network/interfaces/IBaseResult.java
0 → 100644
| 1 | +package com.cnlive.core.network.interfaces; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +public interface IBaseResult<T> extends Serializable { | ||
| 6 | + /** | ||
| 7 | + * 是否请求成功 | ||
| 8 | + * | ||
| 9 | + * @return | ||
| 10 | + */ | ||
| 11 | + boolean isSuccess(); | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 想要获取的数据 | ||
| 15 | + * | ||
| 16 | + * @return | ||
| 17 | + */ | ||
| 18 | + T getData(); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 失败错误码 | ||
| 22 | + * | ||
| 23 | + * @return | ||
| 24 | + */ | ||
| 25 | + String getCode(); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 失败错误信息 | ||
| 29 | + * | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + String getMessage(); | ||
| 33 | +} |
core/network/src/main/java/com/cnlive/core/network/model/BaseObserver.java
| 1 | package com.cnlive.core.network.model; | 1 | package com.cnlive.core.network.model; |
| 2 | 2 | ||
| 3 | +import android.accounts.NetworkErrorException; | ||
| 3 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | +import android.text.TextUtils; | ||
| 6 | +import android.util.Log; | ||
| 4 | 7 | ||
| 5 | import com.cnlive.core.network.ServerException; | 8 | import com.cnlive.core.network.ServerException; |
| 9 | +import com.cnlive.core.network.interfaces.IBaseResult; | ||
| 10 | +import com.google.gson.JsonParseException; | ||
| 11 | + | ||
| 12 | +import org.json.JSONException; | ||
| 13 | + | ||
| 14 | +import java.io.InterruptedIOException; | ||
| 15 | +import java.net.ConnectException; | ||
| 16 | +import java.net.UnknownHostException; | ||
| 17 | +import java.text.ParseException; | ||
| 18 | +import java.util.concurrent.TimeoutException; | ||
| 19 | + | ||
| 20 | +import javax.net.ssl.SSLHandshakeException; | ||
| 6 | 21 | ||
| 7 | import io.reactivex.Observer; | 22 | import io.reactivex.Observer; |
| 8 | import io.reactivex.disposables.Disposable; | 23 | import io.reactivex.disposables.Disposable; |
| 24 | +import retrofit2.HttpException; | ||
| 9 | 25 | ||
| 10 | /** | 26 | /** |
| 11 | * ys | 27 | * ys |
| @@ -16,7 +32,19 @@ import io.reactivex.disposables.Disposable; | @@ -16,7 +32,19 @@ import io.reactivex.disposables.Disposable; | ||
| 16 | public abstract class BaseObserver<T> implements Observer<T> { | 32 | public abstract class BaseObserver<T> implements Observer<T> { |
| 17 | protected Context context; | 33 | protected Context context; |
| 18 | private static final String EXCEPTION_CODE = "-1";//异常 | 34 | private static final String EXCEPTION_CODE = "-1";//异常 |
| 35 | + private static final String EXCEPTION_CODE_ERROR = "-2";//连接成功,状态码错误 | ||
| 36 | + | ||
| 37 | + private final String TAG = "BaseObserver"; | ||
| 19 | private T t; | 38 | private T t; |
| 39 | + private static final String CONNECT_ERROR = "网络连接失败,请检查网络"; | ||
| 40 | + private static final String CONNECT_HOST_ERROR = "域名连接失败,请检查域名或网络状态"; | ||
| 41 | + private static final String CONNECT_TIMEOUT = "连接超时,请稍后再试"; | ||
| 42 | + private static final String BAD_NETWORK = "服务器异常"; | ||
| 43 | + private static final String PARSE_ERROR = "解析服务器响应数据失败"; | ||
| 44 | + private static final String UNKNOWN_ERROR = "未知错误"; | ||
| 45 | + private static final String RESPONSE_RETURN_ERROR = "服务器返回数据失败"; | ||
| 46 | + private static final String SSL_ERROR = "安全证书异常"; | ||
| 47 | + private Disposable disposable; | ||
| 20 | 48 | ||
| 21 | public BaseObserver() { | 49 | public BaseObserver() { |
| 22 | } | 50 | } |
| @@ -27,6 +55,7 @@ public abstract class BaseObserver<T> implements Observer<T> { | @@ -27,6 +55,7 @@ public abstract class BaseObserver<T> implements Observer<T> { | ||
| 27 | 55 | ||
| 28 | @Override | 56 | @Override |
| 29 | public void onSubscribe(Disposable d) { | 57 | public void onSubscribe(Disposable d) { |
| 58 | + this.disposable = d; | ||
| 30 | onRequestStart(d); | 59 | onRequestStart(d); |
| 31 | } | 60 | } |
| 32 | 61 | ||
| @@ -35,20 +64,35 @@ public abstract class BaseObserver<T> implements Observer<T> { | @@ -35,20 +64,35 @@ public abstract class BaseObserver<T> implements Observer<T> { | ||
| 35 | //请求结束 | 64 | //请求结束 |
| 36 | onRequestEnd(); | 65 | onRequestEnd(); |
| 37 | //判断是否请求成功(是网家家数据) | 66 | //判断是否请求成功(是网家家数据) |
| 38 | - if (tBaseResult instanceof BaseResult) { | ||
| 39 | - BaseResult baseResult = (BaseResult) tBaseResult; | ||
| 40 | - if (baseResult.isSuccess()) { | ||
| 41 | - try { | ||
| 42 | - onSuccess(tBaseResult); | ||
| 43 | - } catch (Exception e) { | ||
| 44 | - e.printStackTrace(); | ||
| 45 | - } | 67 | +// if (tBaseResult instanceof BaseResult) { |
| 68 | +// BaseResult baseResult = (BaseResult) tBaseResult; | ||
| 69 | +// if (baseResult.isSuccess()) { | ||
| 70 | +// try { | ||
| 71 | +// onSuccess(tBaseResult); | ||
| 72 | +// } catch (Exception e) { | ||
| 73 | +// e.printStackTrace(); | ||
| 74 | +// } | ||
| 75 | +// } else { | ||
| 76 | +// //状态码不对 | ||
| 77 | +// try { | ||
| 78 | +// onCodeError(baseResult.getErrorCode(), baseResult.getMessage()); | ||
| 79 | +// } catch (Exception e) { | ||
| 80 | +// e.printStackTrace(); | ||
| 81 | +// } | ||
| 82 | +// } | ||
| 83 | +// } | ||
| 84 | + //实现的基类接口 | ||
| 85 | + if (tBaseResult instanceof IBaseResult) { | ||
| 86 | + IBaseResult baseOtherResult = (IBaseResult) tBaseResult; | ||
| 87 | + //连接成功 | ||
| 88 | + if (baseOtherResult.isSuccess()) { | ||
| 89 | + onSuccess(tBaseResult); | ||
| 46 | } else { | 90 | } else { |
| 47 | - //状态码不对 | ||
| 48 | - try { | ||
| 49 | - onCodeError(baseResult.getErrorCode(), baseResult.getMessage()); | ||
| 50 | - } catch (Exception e) { | ||
| 51 | - e.printStackTrace(); | 91 | + //连接成功,状态码错误 |
| 92 | + if (!TextUtils.isEmpty(baseOtherResult.getCode()) && !TextUtils.isEmpty(baseOtherResult.getMessage())) { | ||
| 93 | + onCodeError(baseOtherResult.getCode(), baseOtherResult.getMessage()); | ||
| 94 | + } else { | ||
| 95 | + onCodeError(EXCEPTION_CODE_ERROR, "状态码错误"); | ||
| 52 | } | 96 | } |
| 53 | } | 97 | } |
| 54 | } else { | 98 | } else { |
| @@ -65,41 +109,59 @@ public abstract class BaseObserver<T> implements Observer<T> { | @@ -65,41 +109,59 @@ public abstract class BaseObserver<T> implements Observer<T> { | ||
| 65 | public void onError(Throwable e) { | 109 | public void onError(Throwable e) { |
| 66 | //请求结束 | 110 | //请求结束 |
| 67 | onRequestEnd(); | 111 | onRequestEnd(); |
| 68 | -// try { | ||
| 69 | -// //判断是否是网络请求相关错误 | ||
| 70 | -// if (e instanceof ConnectException | ||
| 71 | -// || e instanceof TimeoutException | ||
| 72 | -// || e instanceof NetworkErrorException | ||
| 73 | -// || e instanceof UnknownHostException) { | ||
| 74 | -// onFailure(e, true); | ||
| 75 | -// } else { | ||
| 76 | -// onFailure(e, false); | ||
| 77 | -// } | ||
| 78 | -// } catch (Exception e1) { | ||
| 79 | -// e1.printStackTrace(); | ||
| 80 | -// try { | ||
| 81 | -// onFailure(e1, false); | ||
| 82 | -// } catch (Exception ex) { | ||
| 83 | -// ex.printStackTrace(); | ||
| 84 | -// } | ||
| 85 | -// } | ||
| 86 | - | ||
| 87 | try { | 112 | try { |
| 88 | - if (e instanceof ServerException) { | 113 | + if (e instanceof ConnectException) { |
| 114 | + onFailure(EXCEPTION_CODE, CONNECT_ERROR); | ||
| 115 | + } else if (e instanceof UnknownHostException) { | ||
| 116 | + onFailure(EXCEPTION_CODE, CONNECT_HOST_ERROR); | ||
| 117 | + } else if (e instanceof TimeoutException || e instanceof InterruptedIOException) { | ||
| 118 | + onFailure(EXCEPTION_CODE, CONNECT_TIMEOUT); | ||
| 119 | + } else if (e instanceof NetworkErrorException) { | ||
| 120 | + //连接超时 | ||
| 121 | + onFailure(EXCEPTION_CODE, CONNECT_ERROR); | ||
| 122 | + } else if (e instanceof retrofit2.HttpException) { | ||
| 123 | + int code = ((HttpException) e).code(); | ||
| 124 | + if (code == 504) { | ||
| 125 | + onFailure(EXCEPTION_CODE, "504网络异常,请检查您的网络状态"); | ||
| 126 | + } else if (code == 404) { | ||
| 127 | + onFailure(EXCEPTION_CODE, "404请求的地址不存在"); | ||
| 128 | + } else { | ||
| 129 | + onFailure(EXCEPTION_CODE, BAD_NETWORK); | ||
| 130 | + } | ||
| 131 | + } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) { | ||
| 132 | + //解析错误 | ||
| 133 | + onFailure(EXCEPTION_CODE, PARSE_ERROR); | ||
| 134 | + } else if (e instanceof ServerException) { | ||
| 135 | + //自定义错误 | ||
| 89 | ServerException serverException = (ServerException) e; | 136 | ServerException serverException = (ServerException) e; |
| 90 | onFailure(serverException.getErrorCode(), serverException.getErrorMsg()); | 137 | onFailure(serverException.getErrorCode(), serverException.getErrorMsg()); |
| 138 | + } else if (e instanceof SSLHandshakeException) {//安全证书异常 | ||
| 139 | + onFailure(EXCEPTION_CODE, SSL_ERROR); | ||
| 91 | } else { | 140 | } else { |
| 92 | onFailure(EXCEPTION_CODE, e.toString()); | 141 | onFailure(EXCEPTION_CODE, e.toString()); |
| 93 | } | 142 | } |
| 94 | } catch (Exception ex) { | 143 | } catch (Exception ex) { |
| 95 | - ex.printStackTrace(); | 144 | + try { |
| 145 | + onFailure(EXCEPTION_CODE, ex.toString()); | ||
| 146 | + } catch (Exception e1) { | ||
| 147 | + Log.e(TAG, "onError: " + e1); | ||
| 148 | + } | ||
| 149 | + } finally { | ||
| 150 | + //事件完成取消订阅 | ||
| 151 | + if (disposable != null && !disposable.isDisposed()) { | ||
| 152 | + disposable.dispose(); | ||
| 153 | + disposable = null; | ||
| 154 | + } | ||
| 96 | } | 155 | } |
| 97 | - | ||
| 98 | } | 156 | } |
| 99 | 157 | ||
| 100 | @Override | 158 | @Override |
| 101 | public void onComplete() { | 159 | public void onComplete() { |
| 102 | - | 160 | + //事件完成取消订阅 |
| 161 | + if (disposable != null && !disposable.isDisposed()) { | ||
| 162 | + disposable.dispose(); | ||
| 163 | + disposable = null; | ||
| 164 | + } | ||
| 103 | } | 165 | } |
| 104 | 166 | ||
| 105 | protected void onRequestStart(Disposable d) { | 167 | protected void onRequestStart(Disposable d) { |
| @@ -113,14 +175,14 @@ public abstract class BaseObserver<T> implements Observer<T> { | @@ -113,14 +175,14 @@ public abstract class BaseObserver<T> implements Observer<T> { | ||
| 113 | * | 175 | * |
| 114 | * @throws Exception | 176 | * @throws Exception |
| 115 | */ | 177 | */ |
| 116 | - protected abstract void onSuccess(T result) throws Exception; | 178 | + protected abstract void onSuccess(T result); |
| 117 | 179 | ||
| 118 | /** | 180 | /** |
| 119 | * 返回成功了,但是code错误 | 181 | * 返回成功了,但是code错误 |
| 120 | * | 182 | * |
| 121 | * @throws Exception | 183 | * @throws Exception |
| 122 | */ | 184 | */ |
| 123 | - protected abstract void onCodeError(String errCode, String errMsg) throws Exception; | 185 | + protected abstract void onCodeError(String errCode, String errMsg); |
| 124 | 186 | ||
| 125 | /** | 187 | /** |
| 126 | * 返回失败 | 188 | * 返回失败 |
core/network/src/main/java/com/cnlive/core/network/model/BaseResult.java
| 1 | package com.cnlive.core.network.model; | 1 | package com.cnlive.core.network.model; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.cnlive.core.network.interfaces.IBaseResult; | ||
| 5 | + | ||
| 4 | /** | 6 | /** |
| 5 | * 网家家返回参数基类 | 7 | * 网家家返回参数基类 |
| 6 | * | 8 | * |
| 7 | * @param <T> | 9 | * @param <T> |
| 8 | */ | 10 | */ |
| 9 | -public class BaseResult<T> { | 11 | +public class BaseResult<T> implements IBaseResult { |
| 10 | private static final String CODE_SUCCESS = "0";//响应成功的code | 12 | private static final String CODE_SUCCESS = "0";//响应成功的code |
| 11 | private String errorCode; | 13 | private String errorCode; |
| 12 | private String errorMessage; | 14 | private String errorMessage; |
| 13 | private T data; | 15 | private T data; |
| 14 | 16 | ||
| 15 | - public boolean isSuccess() { | ||
| 16 | - return CODE_SUCCESS.equals(errorCode); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - public String getErrorCode() { | ||
| 20 | - return errorCode; | ||
| 21 | - } | ||
| 22 | 17 | ||
| 23 | public void setErrorCode(String errorCode) { | 18 | public void setErrorCode(String errorCode) { |
| 24 | this.errorCode = errorCode; | 19 | this.errorCode = errorCode; |
| 25 | } | 20 | } |
| 26 | 21 | ||
| 27 | - public String getMessage() { | ||
| 28 | - return errorMessage; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | public void setErrorMessage(String errorMessage) { | 22 | public void setErrorMessage(String errorMessage) { |
| 32 | this.errorMessage = errorMessage; | 23 | this.errorMessage = errorMessage; |
| 33 | } | 24 | } |
| 34 | 25 | ||
| 26 | + public void setData(T data) { | ||
| 27 | + this.data = data; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public boolean isSuccess() { | ||
| 32 | + return CODE_SUCCESS.equals(errorCode); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 35 | public T getData() { | 36 | public T getData() { |
| 36 | return data; | 37 | return data; |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 39 | - public void setData(T data) { | ||
| 40 | - this.data = data; | 40 | + @Override |
| 41 | + public String getCode() { | ||
| 42 | + return errorCode; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public String getMessage() { | ||
| 47 | + return errorMessage; | ||
| 41 | } | 48 | } |
| 42 | 49 | ||
| 50 | + | ||
| 43 | } | 51 | } |
core/network/src/main/java/com/cnlive/core/network/request/HttpConfig.java
| 1 | package com.cnlive.core.network.request; | 1 | package com.cnlive.core.network.request; |
| 2 | 2 | ||
| 3 | public class HttpConfig { | 3 | public class HttpConfig { |
| 4 | - public static final int CONNECT_TIMEOUT = 20;//连接超时时间(秒) | ||
| 5 | - public static final int READ_TIMEOUT = 20;//读取超时时间(秒) | ||
| 6 | - public static final int WRITE_TIMEOUT = 20;//设置写入超时时间(秒) | 4 | + public static final int CONNECT_TIMEOUT = 30;//连接超时时间(秒) |
| 5 | + public static final int READ_TIMEOUT = 30;//读取超时时间(秒) | ||
| 6 | + public static final int WRITE_TIMEOUT = 30;//设置写入超时时间(秒) | ||
| 7 | 7 | ||
| 8 | } | 8 | } |
module/pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunRaceDetailFragmentView.java
| @@ -232,7 +232,7 @@ public class CollRunRaceDetailFragmentView extends BaseView implements SensorEve | @@ -232,7 +232,7 @@ public class CollRunRaceDetailFragmentView extends BaseView implements SensorEve | ||
| 232 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); | 232 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); |
| 233 | // if (line > 1) { | 233 | // if (line > 1) { |
| 234 | // int avgHeight = height / line;//平局高度 | 234 | // int avgHeight = height / line;//平局高度 |
| 235 | -// fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(), 140) + avgHeight * (line - 1)); | 235 | +// fragment.binding.slidingLayout.setPanelHeight(ScreenUtils.dip2px(getContext(), 140) + avgHeight * (line - 1)); |
| 236 | // | 236 | // |
| 237 | // } | 237 | // } |
| 238 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); | 238 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); |
module/pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningFinishFragmentView.java
| @@ -240,7 +240,7 @@ public class CollRunningFinishFragmentView extends BaseView implements OnFenceLi | @@ -240,7 +240,7 @@ public class CollRunningFinishFragmentView extends BaseView implements OnFenceLi | ||
| 240 | // } else { | 240 | // } else { |
| 241 | // //隐藏面板视图 | 241 | // //隐藏面板视图 |
| 242 | //// fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); | 242 | //// fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); |
| 243 | -// fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(),100)); | 243 | +// fragment.binding.slidingLayout.setPanelHeight(ScreenUtils.dip2px(getContext(),100)); |
| 244 | // fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); | 244 | // fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); |
| 245 | // //让运营选择最佳的截图 | 245 | // //让运营选择最佳的截图 |
| 246 | // SelectDialog selectDialog = new SelectDialog(getContext(), "当前赛事图是否\n已经调整到最佳效果?", "否", new SelectDialog.DialogInterface() { | 246 | // SelectDialog selectDialog = new SelectDialog(getContext(), "当前赛事图是否\n已经调整到最佳效果?", "否", new SelectDialog.DialogInterface() { |
module/pedometer/src/main/java/com/cnlive/moudle/collectionTrace/ui/fragment/CollRunRaceDetailFragment.java
| @@ -135,7 +135,7 @@ public class CollRunRaceDetailFragment extends BaseFragment<CollRunRaceDetailFra | @@ -135,7 +135,7 @@ public class CollRunRaceDetailFragment extends BaseFragment<CollRunRaceDetailFra | ||
| 135 | // //以下设置是为了解决:下滑隐藏dialog后,再次调用show方法显示时,不能弹出Dialog----在真机测试时不写下面的方法也未发现问题 | 135 | // //以下设置是为了解决:下滑隐藏dialog后,再次调用show方法显示时,不能弹出Dialog----在真机测试时不写下面的方法也未发现问题 |
| 136 | // View delegateView = bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet); | 136 | // View delegateView = bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet); |
| 137 | // final BottomSheetBehavior<View> sheetBehavior = BottomSheetBehavior.from(delegateView); | 137 | // final BottomSheetBehavior<View> sheetBehavior = BottomSheetBehavior.from(delegateView); |
| 138 | -// sheetBehavior.setPeekHeight(ScreenUtil.getScreenHeight(getActivity()) / 3); | 138 | +// sheetBehavior.setPeekHeight(ScreenUtils.getScreenHeight(getActivity()) / 3); |
| 139 | // sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | 139 | // sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { |
| 140 | // //在下滑隐藏结束时才会触发 | 140 | // //在下滑隐藏结束时才会触发 |
| 141 | // @Override | 141 | // @Override |
module/pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/OnGoingFragmentView.java
| @@ -151,7 +151,7 @@ public class OnGoingFragmentView extends BaseView { | @@ -151,7 +151,7 @@ public class OnGoingFragmentView extends BaseView { | ||
| 151 | int leakWidth = (int) (ScreenUtil.dip2px(getContext(), 15) / 0.6); | 151 | int leakWidth = (int) (ScreenUtil.dip2px(getContext(), 15) / 0.6); |
| 152 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 152 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 153 | int current = (int) (leakWidth * slideOffset); | 153 | int current = (int) (leakWidth * slideOffset); |
| 154 | -// Log.e(TAG, "current: " + current + ",leakWidth:" + leakWidth + ",ScreenUtil:" + ScreenUtil.dip2px(getContext(), 15)); | 154 | +// Log.e(TAG, "current: " + current + ",leakWidth:" + leakWidth + ",ScreenUtils:" + ScreenUtils.dip2px(getContext(), 15)); |
| 155 | if (slideOffset == 0) { | 155 | if (slideOffset == 0) { |
| 156 | layoutParams.setMargins(ScreenUtil.dip2px(getContext(), 15), 0, ScreenUtil.dip2px(getContext(), 15), 0); | 156 | layoutParams.setMargins(ScreenUtil.dip2px(getContext(), 15), 0, ScreenUtil.dip2px(getContext(), 15), 0); |
| 157 | fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams); | 157 | fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams); |
| @@ -251,7 +251,7 @@ public class OnGoingFragmentView extends BaseView { | @@ -251,7 +251,7 @@ public class OnGoingFragmentView extends BaseView { | ||
| 251 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); | 251 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); |
| 252 | // if (line > 1) { | 252 | // if (line > 1) { |
| 253 | // int avgHeight = height / line;//平局高度 | 253 | // int avgHeight = height / line;//平局高度 |
| 254 | -// fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(), 140) + avgHeight * (line - 1)); | 254 | +// fragment.binding.slidingLayout.setPanelHeight(ScreenUtils.dip2px(getContext(), 140) + avgHeight * (line - 1)); |
| 255 | // | 255 | // |
| 256 | // } | 256 | // } |
| 257 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); | 257 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); |
module/pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunRaceDetailFragmentView.java
| @@ -242,7 +242,7 @@ public class RunRaceDetailFragmentView extends BaseView implements SensorEventLi | @@ -242,7 +242,7 @@ public class RunRaceDetailFragmentView extends BaseView implements SensorEventLi | ||
| 242 | int leakWidth = (int) (ScreenUtil.dip2px(getContext(), 15) / 0.6); | 242 | int leakWidth = (int) (ScreenUtil.dip2px(getContext(), 15) / 0.6); |
| 243 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 243 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 244 | int current = (int) (leakWidth * slideOffset); | 244 | int current = (int) (leakWidth * slideOffset); |
| 245 | -// Log.e(TAG, "current: " + current + ",leakWidth:" + leakWidth + ",ScreenUtil:" + ScreenUtil.dip2px(getContext(), 15)); | 245 | +// Log.e(TAG, "current: " + current + ",leakWidth:" + leakWidth + ",ScreenUtils:" + ScreenUtils.dip2px(getContext(), 15)); |
| 246 | if (slideOffset == 0) { | 246 | if (slideOffset == 0) { |
| 247 | layoutParams.setMargins(ScreenUtil.dip2px(getContext(), 15), 0, ScreenUtil.dip2px(getContext(), 15), 0); | 247 | layoutParams.setMargins(ScreenUtil.dip2px(getContext(), 15), 0, ScreenUtil.dip2px(getContext(), 15), 0); |
| 248 | fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams); | 248 | fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams); |
| @@ -382,7 +382,7 @@ public class RunRaceDetailFragmentView extends BaseView implements SensorEventLi | @@ -382,7 +382,7 @@ public class RunRaceDetailFragmentView extends BaseView implements SensorEventLi | ||
| 382 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); | 382 | // int height = fragment.binding.includeStreet.tvRaceTitle.getHeight(); |
| 383 | // if (line > 1) { | 383 | // if (line > 1) { |
| 384 | // int avgHeight = height / line;//平局高度 | 384 | // int avgHeight = height / line;//平局高度 |
| 385 | -// fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(), 181) + avgHeight * (line - 1)); | 385 | +// fragment.binding.slidingLayout.setPanelHeight(ScreenUtils.dip2px(getContext(), 181) + avgHeight * (line - 1)); |
| 386 | // } | 386 | // } |
| 387 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); | 387 | // fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this); |
| 388 | // //显示底部滑动卡片 | 388 | // //显示底部滑动卡片 |
module/pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunRaceDetailFragment.java
| @@ -127,7 +127,7 @@ public class RunRaceDetailFragment extends BaseFragment<RunRaceDetailFragmentVie | @@ -127,7 +127,7 @@ public class RunRaceDetailFragment extends BaseFragment<RunRaceDetailFragmentVie | ||
| 127 | // //以下设置是为了解决:下滑隐藏dialog后,再次调用show方法显示时,不能弹出Dialog----在真机测试时不写下面的方法也未发现问题 | 127 | // //以下设置是为了解决:下滑隐藏dialog后,再次调用show方法显示时,不能弹出Dialog----在真机测试时不写下面的方法也未发现问题 |
| 128 | // View delegateView = bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet); | 128 | // View delegateView = bottomSheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet); |
| 129 | // final BottomSheetBehavior<View> sheetBehavior = BottomSheetBehavior.from(delegateView); | 129 | // final BottomSheetBehavior<View> sheetBehavior = BottomSheetBehavior.from(delegateView); |
| 130 | -// sheetBehavior.setPeekHeight(ScreenUtil.getScreenHeight(getActivity()) / 3); | 130 | +// sheetBehavior.setPeekHeight(ScreenUtils.getScreenHeight(getActivity()) / 3); |
| 131 | // sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | 131 | // sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { |
| 132 | // //在下滑隐藏结束时才会触发 | 132 | // //在下滑隐藏结束时才会触发 |
| 133 | // @Override | 133 | // @Override |
module/xiaojiasoundbox/src/main/res/layout/view_top_msg.xml
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | android:id="@+id/view_top_msg_parent" | 3 | android:id="@+id/view_top_msg_parent" |
| 4 | android:layout_width="match_parent" | 4 | android:layout_width="match_parent" |
| 5 | - android:layout_height="match_parent" | 5 | + android:layout_height="wrap_content" |
| 6 | android:orientation="vertical"> | 6 | android:orientation="vertical"> |
| 7 | 7 | ||
| 8 | <LinearLayout | 8 | <LinearLayout |