Commit e6959934f8aaf8aa4d0c42a5c2d3ccccf1084ae0

Authored by 朱显松
1 parent 0cce3a59

updata cnlive 0.1.0 lib and demo

Showing 26 changed files with 808 additions and 279 deletions
app/build.gradle
@@ -4,7 +4,7 @@ android { @@ -4,7 +4,7 @@ android {
4 compileSdkVersion 26 4 compileSdkVersion 26
5 buildToolsVersion "26.0.0" 5 buildToolsVersion "26.0.0"
6 defaultConfig { 6 defaultConfig {
7 - applicationId "com.cnlive.libs.base" 7 + applicationId "com.cnlive.libs.demo"
8 minSdkVersion 16 8 minSdkVersion 16
9 targetSdkVersion 26 9 targetSdkVersion 26
10 versionCode 1 10 versionCode 1
@@ -17,6 +17,9 @@ android { @@ -17,6 +17,9 @@ android {
17 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 } 18 }
19 } 19 }
  20 + dataBinding {
  21 + enabled true
  22 + }
20 } 23 }
21 24
22 dependencies { 25 dependencies {
@@ -30,4 +33,5 @@ dependencies { @@ -30,4 +33,5 @@ dependencies {
30 compile 'com.android.support.constraint:constraint-layout:1.0.2' 33 compile 'com.android.support.constraint:constraint-layout:1.0.2'
31 // TODO 本地酷使用说明 代码仓库标识 34 // TODO 本地酷使用说明 代码仓库标识
32 // compile 'com.cnlive.libs:base:1.0.0@aar' 35 // compile 'com.cnlive.libs:base:1.0.0@aar'
  36 + compile 'com.cnlive:cnlive:0.1.0'
33 } 37 }
app/src/main/AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 - package="com.cnlive.libs.base"> 3 + package="com.cnlive.libs.demo">
4 4
5 <application 5 <application
6 android:allowBackup="true" 6 android:allowBackup="true"
@@ -9,10 +9,16 @@ @@ -9,10 +9,16 @@
9 android:roundIcon="@mipmap/ic_launcher_round" 9 android:roundIcon="@mipmap/ic_launcher_round"
10 android:supportsRtl="true" 10 android:supportsRtl="true"
11 android:theme="@style/AppTheme"> 11 android:theme="@style/AppTheme">
12 - <activity android:name=".MainActivity"> 12 +
  13 + <activity android:name=".MainActivity"/>
  14 +
  15 + <activity
  16 + android:name=".mvptest.ui.activity.LaunchActivity"
  17 + android:configChanges="keyboardHidden|screenSize|orientation"
  18 + android:screenOrientation="portrait"
  19 + android:theme="@style/AppFullScreenTheme">
13 <intent-filter> 20 <intent-filter>
14 <action android:name="android.intent.action.MAIN" /> 21 <action android:name="android.intent.action.MAIN" />
15 -  
16 <category android:name="android.intent.category.LAUNCHER" /> 22 <category android:name="android.intent.category.LAUNCHER" />
17 </intent-filter> 23 </intent-filter>
18 </activity> 24 </activity>
app/src/main/java/com/cnlive/libs/base/MainActivity.java renamed to app/src/main/java/com/cnlive/libs/demo/MainActivity.java
1 -package com.cnlive.libs.base; 1 +package com.cnlive.libs.demo;
2 2
3 -import android.support.v7.app.AppCompatActivity;  
4 import android.os.Bundle; 3 import android.os.Bundle;
  4 +import android.support.v7.app.AppCompatActivity;
5 5
6 public class MainActivity extends AppCompatActivity { 6 public class MainActivity extends AppCompatActivity {
7 7
  8 +
8 @Override 9 @Override
9 protected void onCreate(Bundle savedInstanceState) { 10 protected void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState); 11 super.onCreate(savedInstanceState);
11 setContentView(R.layout.activity_main); 12 setContentView(R.layout.activity_main);
  13 +
  14 + //Toast 测试
  15 + ToastTest.test(this);
12 } 16 }
13 } 17 }
app/src/main/java/com/cnlive/libs/demo/ToastTest.java 0 → 100644
  1 +package com.cnlive.libs.demo;
  2 +
  3 +import android.content.Context;
  4 +import android.view.Gravity;
  5 +
  6 +import com.cnlive.libs.base.util.PixelsUtil;
  7 +import com.cnlive.libs.base.util.ToastUtil;
  8 +
  9 +/**
  10 + * Created by xiansong on 2017/8/14.
  11 + */
  12 +
  13 +public class ToastTest {
  14 +
  15 + /**
  16 + * 声明全局ToastUtil.Build对象
  17 + * 通过.build()获得ToastUtil对象
  18 + */
  19 + private static final ToastUtil.Build mainToast = ToastUtil.newBuild()
  20 + //对齐参数设置
  21 + .setGravity(Gravity.BOTTOM, 0, PixelsUtil.dip2px(16))
  22 + //设置布局 Layout Id 文本视图 View Id
  23 + .setView(R.layout.layout_toast_1, R.id.text);
  24 +
  25 +
  26 + public static void test(Context context) {
  27 + //Toast 调用示例
  28 + mainToast.build(context).showToast("Start ~~~");
  29 + }
  30 +}
app/src/main/java/com/cnlive/libs/demo/mvptest/frame/ILaunchView.java 0 → 100644
  1 +package com.cnlive.libs.demo.mvptest.frame;
  2 +
  3 +import com.hannesdorfmann.mosby.mvp.MvpView;
  4 +
  5 +
  6 +public interface ILaunchView extends MvpView {
  7 + /**
  8 + * 开始加载页面数据
  9 + */
  10 + void onLoadDataStart();
  11 +
  12 + /**
  13 + * 完成数据加载
  14 + * @param data 页面数据
  15 + */
  16 + void onLoadDataComplete(Object data);
  17 +
  18 + /**
  19 + * 错误的加载
  20 + * @param code 页面错误码
  21 + * @param message 页面错误信息
  22 + */
  23 + void onLoadDataError(String code, String message);
  24 +
  25 + /**
  26 + * 计时器结束通知
  27 + */
  28 + void onTimerFinish();
  29 +
  30 + /**
  31 + * 计时器剩余时间通知
  32 + * @param time 剩余时间
  33 + */
  34 + void onTimerInterval(long time);
  35 +
  36 + /**
  37 + * 启动主程序
  38 + */
  39 + void startMainPage();
  40 +}
0 \ No newline at end of file 41 \ No newline at end of file
app/src/main/java/com/cnlive/libs/demo/mvptest/frame/presenter/LaunchPresenter.java 0 → 100644
  1 +package com.cnlive.libs.demo.mvptest.frame.presenter;
  2 +
  3 +import android.content.Context;
  4 +
  5 +import com.cnlive.libs.base.util.LogUtil;
  6 +import com.cnlive.libs.base.util.TimerUtil;
  7 +import com.cnlive.libs.demo.mvptest.frame.ILaunchView;
  8 +import com.cnlive.libs.demo.mvptest.frame.view.LaunchView;
  9 +import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
  10 +
  11 +import io.reactivex.disposables.Disposable;
  12 +
  13 +public class LaunchPresenter extends MvpBasePresenter<LaunchView> {
  14 +
  15 + private TimerUtil timerUtil; //计时工具类
  16 + private Disposable subscription;
  17 +
  18 + /**
  19 + * 获取启动页 应用程序信息
  20 + */
  21 + public void initData(Context context) {
  22 + if (subscription != null) subscription.dispose();
  23 +
  24 + ILaunchView view = getView();
  25 + if (view != null) view.onLoadDataComplete(null);
  26 + }
  27 +
  28 + /**
  29 + * 开启定时
  30 + *
  31 + * @param totalTime 总时长
  32 + */
  33 + public void startTimer(long totalTime) {
  34 + if (timerUtil != null) timerUtil.cancel();
  35 +
  36 + timerUtil = new TimerUtil();
  37 + timerUtil.setTotalTime(totalTime);//设置毫秒数
  38 + timerUtil.setIntervalTime(1000);//设置间隔数
  39 + timerUtil.start();
  40 +
  41 + timerUtil.setTimerLiener(new TimerUtil.TimeListener() {
  42 + @Override
  43 + public void onFinish() {
  44 + ILaunchView view = getView();
  45 + if (view != null) view.onTimerFinish();
  46 + }
  47 +
  48 + @Override
  49 + public void onInterval(long remainTime) {
  50 + ILaunchView view = getView();
  51 + if (view != null) view.onTimerInterval(remainTime / 1000);
  52 + LogUtil.d("LaunchView", "剩余时间" + remainTime);
  53 + }
  54 + });
  55 + }
  56 +
  57 + public void startMainPage() {
  58 + if (getView() == null) return;
  59 + if (timerUtil != null) timerUtil.cancel();
  60 + if (subscription != null) subscription.dispose();
  61 + getView().startMainPage();
  62 + }
  63 +
  64 + /**
  65 + * 销毁
  66 + */
  67 + public void destroy() {
  68 + if (timerUtil != null) timerUtil.cancel();
  69 + if (subscription != null) subscription.dispose();
  70 + }
  71 +
  72 +}
app/src/main/java/com/cnlive/libs/demo/mvptest/frame/view/LaunchView.java 0 → 100644
  1 +package com.cnlive.libs.demo.mvptest.frame.view;
  2 +
  3 +import android.content.Intent;
  4 +import android.view.View;
  5 +
  6 +import com.cnlive.libs.demo.MainActivity;
  7 +import com.cnlive.libs.demo.mvptest.frame.ILaunchView;
  8 +import com.cnlive.libs.demo.mvptest.ui.activity.LaunchActivity;
  9 +
  10 +
  11 +public class LaunchView implements ILaunchView {
  12 +
  13 + private static final int launch_time = 2_100;
  14 + private LaunchActivity activity;
  15 +
  16 + public LaunchView(LaunchActivity activity) {
  17 + this.activity = activity;
  18 + }
  19 +
  20 + @Override
  21 + public void onLoadDataStart() {
  22 + activity.binding.getData().setLoading(View.VISIBLE);
  23 + }
  24 +
  25 + @Override
  26 + public void onLoadDataComplete(Object data) {
  27 + loadEnd();
  28 + }
  29 +
  30 + @Override
  31 + public void onLoadDataError(String code, String message) {
  32 + loadEnd();
  33 + }
  34 +
  35 + private void loadEnd() {
  36 + activity.binding.getData().setLoading(View.GONE);
  37 + activity.getPresenter().startTimer(launch_time);
  38 + }
  39 +
  40 + @Override
  41 + public void onTimerFinish() {
  42 + activity.binding.getData().setTime(0);
  43 + startMainPage();
  44 + }
  45 +
  46 + @Override
  47 + public void startMainPage() {
  48 + activity.startActivity(new Intent(activity, MainActivity.class));
  49 + activity.finish();
  50 + }
  51 +
  52 + @Override
  53 + public void onTimerInterval(long time) {
  54 + activity.binding.getData().setTime(time);
  55 + }
  56 +}
app/src/main/java/com/cnlive/libs/demo/mvptest/model/LaunchPage.java 0 → 100644
  1 +package com.cnlive.libs.demo.mvptest.model;
  2 +
  3 +import android.databinding.BaseObservable;
  4 +import android.databinding.Bindable;
  5 +import android.view.View;
  6 +
  7 +import com.cnlive.libs.demo.BR;
  8 +
  9 +
  10 +public class LaunchPage extends BaseObservable {
  11 + private long time = -1;
  12 + private int timing = View.GONE;
  13 + private int loading = View.GONE;
  14 +
  15 + @Bindable
  16 + public long getTime() {
  17 + return time;
  18 + }
  19 +
  20 + public void setTime(long time) {
  21 + this.time = time;
  22 + notifyPropertyChanged(BR.time);
  23 + setTiming(time >= 0 ? View.VISIBLE : View.GONE);
  24 + }
  25 +
  26 + @Bindable
  27 + public int getTiming() {
  28 + return timing;
  29 + }
  30 +
  31 + public void setTiming(int timing) {
  32 + this.timing = timing;
  33 + notifyPropertyChanged(BR.timing);
  34 + }
  35 +
  36 + @Bindable
  37 + public int getLoading() {
  38 + return loading;
  39 + }
  40 +
  41 + public void setLoading(int loading) {
  42 + this.loading = loading;
  43 + notifyPropertyChanged(BR.loading);
  44 + }
  45 +}
app/src/main/java/com/cnlive/libs/demo/mvptest/ui/activity/LaunchActivity.java 0 → 100644
  1 +package com.cnlive.libs.demo.mvptest.ui.activity;
  2 +
  3 +
  4 +import android.content.Intent;
  5 +import android.os.Bundle;
  6 +import android.view.View;
  7 +
  8 +import com.cnlive.libs.base.activity.MvpBindingActivity;
  9 +import com.cnlive.libs.demo.R;
  10 +import com.cnlive.libs.demo.databinding.ActivityLaunchBinding;
  11 +import com.cnlive.libs.demo.mvptest.frame.presenter.LaunchPresenter;
  12 +import com.cnlive.libs.demo.mvptest.frame.view.LaunchView;
  13 +import com.cnlive.libs.demo.mvptest.model.LaunchPage;
  14 +
  15 +public class LaunchActivity extends MvpBindingActivity<LaunchView, LaunchPresenter, LaunchPage, ActivityLaunchBinding> {
  16 +
  17 + @Override
  18 + protected int getLayoutId() {
  19 + return R.layout.activity_launch;
  20 + }
  21 +
  22 + @Override
  23 + protected void onCreate(Bundle savedInstanceState) {
  24 + super.onCreate(savedInstanceState);
  25 + initData();
  26 + }
  27 +
  28 + @Override
  29 + protected void onNewIntent(Intent intent) {
  30 + super.onNewIntent(intent);
  31 + initData();
  32 + }
  33 +
  34 + @Override
  35 + protected void onDestroy() {
  36 + super.onDestroy();
  37 + getPresenter().destroy();
  38 + }
  39 +
  40 + private void initData() {
  41 + getPresenter().initData(this);
  42 + }
  43 +
  44 + public void onClick(View view){
  45 + switch (view.getId()){
  46 + case R.id.click:
  47 + getPresenter().startMainPage();
  48 + break;
  49 + }
  50 + }
  51 +
  52 +}
app/src/main/res/drawable/bg_timing_background.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<shape xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:shape="rectangle"
  4 + android:useLevel="false">
  5 + <solid android:color="#454543" />
  6 + <size
  7 + android:width="36dp"
  8 + android:height="36dp" />
  9 + <corners
  10 + android:bottomLeftRadius="8dp"
  11 + android:bottomRightRadius="8dp"
  12 + android:topLeftRadius="8dp"
  13 + android:topRightRadius="8dp" />
  14 +</shape>
0 \ No newline at end of file 15 \ No newline at end of file
app/src/main/res/drawable/bg_toast_1_background.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<shape xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:shape="rectangle"
  4 + android:useLevel="false">
  5 + <solid android:color="#86868686" />
  6 + <padding
  7 + android:bottom="4dp"
  8 + android:left="4dp"
  9 + android:right="4dp"
  10 + android:top="4dp" />
  11 + <size
  12 + android:width="36dp"
  13 + android:height="36dp" />
  14 + <corners
  15 + android:bottomLeftRadius="8dp"
  16 + android:bottomRightRadius="8dp"
  17 + android:topLeftRadius="8dp"
  18 + android:topRightRadius="8dp" />
  19 +</shape>
0 \ No newline at end of file 20 \ No newline at end of file
app/src/main/res/layout/activity_launch.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<layout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools">
  5 +
  6 + <data>
  7 +
  8 + <variable
  9 + name="data"
  10 + type="com.cnlive.libs.demo.mvptest.model.LaunchPage" />
  11 + </data>
  12 +
  13 + <android.support.constraint.ConstraintLayout
  14 + android:layout_width="match_parent"
  15 + android:layout_height="match_parent"
  16 + android:background="#FFc2c4f6"
  17 + tools:context=".mvptest.ui.activity.LaunchActivity">
  18 +
  19 + <ProgressBar
  20 + android:id="@+id/progressBar"
  21 + android:layout_width="32dp"
  22 + android:layout_height="32dp"
  23 + android:visibility="@{data.loading}"
  24 + app:layout_constraintBottom_toBottomOf="parent"
  25 + app:layout_constraintLeft_toLeftOf="parent"
  26 + app:layout_constraintRight_toRightOf="parent"
  27 + app:layout_constraintTop_toTopOf="parent"
  28 + app:layout_constraintVertical_bias="0.863" />
  29 +
  30 + <TextView
  31 + style="@style/TextViewTiming"
  32 + android:layout_width="wrap_content"
  33 + android:layout_height="wrap_content"
  34 + android:layout_marginEnd="343dp"
  35 + android:layout_marginRight="343dp"
  36 + android:layout_marginTop="4dp"
  37 + android:text="@{String.valueOf(data.time)}"
  38 + android:visibility="@{data.timing}"
  39 + app:layout_constraintRight_toRightOf="parent"
  40 + app:layout_constraintTop_toTopOf="parent"
  41 + tools:text="0" />
  42 +
  43 + <View
  44 + android:id="@+id/click"
  45 + android:layout_width="124dp"
  46 + android:layout_height="42dp"
  47 + android:layout_marginBottom="16dp"
  48 + android:layout_marginLeft="8dp"
  49 + android:layout_marginRight="8dp"
  50 + android:onClick="onClick"
  51 + app:layout_constraintBottom_toBottomOf="parent"
  52 + app:layout_constraintLeft_toLeftOf="parent"
  53 + app:layout_constraintRight_toRightOf="parent" />
  54 + </android.support.constraint.ConstraintLayout>
  55 +
  56 +</layout>
app/src/main/res/layout/activity_main.xml
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent" 5 android:layout_width="match_parent"
6 android:layout_height="match_parent" 6 android:layout_height="match_parent"
7 - tools:context="com.cnlive.libs.base.MainActivity"> 7 + tools:context="com.cnlive.libs.demo.MainActivity">
8 8
9 <TextView 9 <TextView
10 android:layout_width="wrap_content" 10 android:layout_width="wrap_content"
app/src/main/res/layout/layout_toast_1.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + android:layout_width="wrap_content"
  5 + android:layout_height="wrap_content"
  6 + android:background="@drawable/bg_toast_1_background" >
  7 +
  8 + <TextView
  9 + android:id="@+id/text"
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="wrap_content"
  12 + android:text="Hello World!"
  13 + android:padding="4dp"
  14 + app:layout_constraintBottom_toBottomOf="parent"
  15 + app:layout_constraintLeft_toLeftOf="parent"
  16 + app:layout_constraintRight_toRightOf="parent"
  17 + app:layout_constraintTop_toTopOf="parent" />
  18 +
  19 +</android.support.constraint.ConstraintLayout>
app/src/main/res/values/styles.xml
1 <resources> 1 <resources>
2 2
3 <!-- Base application theme. --> 3 <!-- Base application theme. -->
4 - <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">  
5 - <!-- Customize your theme here. --> 4 + <style name="AppTheme" parent="AppBaseTheme"></style>
  5 +
  6 + <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
6 <item name="colorPrimary">@color/colorPrimary</item> 7 <item name="colorPrimary">@color/colorPrimary</item>
7 <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 8 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8 <item name="colorAccent">@color/colorAccent</item> 9 <item name="colorAccent">@color/colorAccent</item>
  10 +
  11 + <item name="windowActionBar">false</item>
  12 + <item name="windowNoTitle">true</item>
  13 +
  14 + <item name="actionMenuTextColor">#ffffff</item>
9 </style> 15 </style>
10 16
  17 + <style name="TextViewTiming">
  18 + <item name="android:layout_margin">6dp</item>
  19 + <item name="android:background">@drawable/bg_timing_background</item>
  20 + <item name="android:gravity">center</item>
  21 + <item name="android:padding">6dp</item>
  22 + <item name="android:textColor">@android:color/white</item>
  23 + <item name="android:textSize">20sp</item>
  24 + </style>
  25 +
  26 + <style name="AppFullScreenTheme" parent="AppBaseTheme">
  27 + <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  28 + <!-- 隐藏状态栏 -->
  29 + <item name="android:windowFullscreen">true</item>
  30 + <!-- 隐藏标题栏 -->
  31 + <item name="android:windowNoTitle">true</item>
  32 + </style>
11 </resources> 33 </resources>
cnlive/build.gradle
@@ -28,10 +28,21 @@ android { @@ -28,10 +28,21 @@ android {
28 28
29 dependencies { 29 dependencies {
30 compile fileTree(include: ['*.jar'], dir: 'libs') 30 compile fileTree(include: ['*.jar'], dir: 'libs')
31 - testCompile 'junit:junit:4.12' 31 +
32 //MVP 32 //MVP
33 compile 'com.hannesdorfmann.mosby:mvp:2.0.1' 33 compile 'com.hannesdorfmann.mosby:mvp:2.0.1'
34 - compile 'com.github.bumptech.glide:okhttp3-integration:4.0.0-RC1' 34 + //GSON
  35 + compile 'com.google.code.gson:gson:2.7'
  36 + //RxJava
  37 + compile 'io.reactivex.rxjava2:rxjava:2.1.0'
  38 + compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
  39 + //Retrofit
  40 + compile 'com.squareup.retrofit2:retrofit:2.0.2'
  41 + compile 'com.squareup.retrofit2:converter-gson:2.0.2'
  42 + compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
  43 + //OKhttp
  44 + compile 'com.squareup.okhttp3:okhttp:3.8.1'
  45 + compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
35 46
36 } 47 }
37 48
@@ -48,7 +59,7 @@ ext { @@ -48,7 +59,7 @@ ext {
48 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo' 59 siteUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo'
49 gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git' 60 gitUrl = 'http://bj.gitlab.cnlive.com/cnlive-team/CNVideoDemo.git'
50 61
51 - libraryVersion = '0.0.4' 62 + libraryVersion = '0.1.0'
52 63
53 developerId = 'CNlive' 64 developerId = 'CNlive'
54 developerName = 'Granzon' 65 developerName = 'Granzon'
cnlive/src/main/java/com/cnlive/libs/base/Test.java deleted 100644 → 0
1 -package com.cnlive.libs.base;  
2 -  
3 -import android.util.Log;  
4 -  
5 -/**  
6 - * Created by Granzon on 2017/8/9.  
7 - */  
8 -  
9 -public class Test {  
10 -  
11 - public void test(){  
12 - Log.e("DemoView","1");  
13 - }  
14 -}  
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpBindingActivity.java
@@ -10,7 +10,13 @@ import com.hannesdorfmann.mosby.mvp.MvpActivity; @@ -10,7 +10,13 @@ import com.hannesdorfmann.mosby.mvp.MvpActivity;
10 import com.hannesdorfmann.mosby.mvp.MvpPresenter; 10 import com.hannesdorfmann.mosby.mvp.MvpPresenter;
11 import com.hannesdorfmann.mosby.mvp.MvpView; 11 import com.hannesdorfmann.mosby.mvp.MvpView;
12 12
13 - 13 +/**
  14 + * MVP Databinding Base Activity
  15 + * @param <V> MVP View {@link MvpView}
  16 + * @param <P> MVP Presenter {@link MvpPresenter}
  17 + * @param <D> Databind Page Data
  18 + * @param <T> Databind Activity ViewDataBinding {@link ViewDataBinding}
  19 + */
14 public abstract class MvpBindingActivity<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpActivity<V, P> { 20 public abstract class MvpBindingActivity<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpActivity<V, P> {
15 21
16 public V view; 22 public V view;
cnlive/src/main/java/com/cnlive/libs/base/activity/MvpLceBindingActivity.java deleted 100644 → 0
1 -package com.cnlive.libs.base.activity;  
2 -  
3 -  
4 -import android.databinding.DataBindingUtil;  
5 -import android.databinding.ViewDataBinding;  
6 -import android.os.Bundle;  
7 -import android.support.annotation.NonNull;  
8 -import android.view.View;  
9 -  
10 -import com.hannesdorfmann.mosby.mvp.MvpPresenter;  
11 -import com.hannesdorfmann.mosby.mvp.MvpView;  
12 -import com.hannesdorfmann.mosby.mvp.lce.MvpLceActivity;  
13 -import com.hannesdorfmann.mosby.mvp.lce.MvpLceView;  
14 -  
15 -/**  
16 - * Created by xiansong on 2017/7/19.  
17 - */  
18 -  
19 -public abstract class MvpLceBindingActivity<CV extends View, M, V extends MvpLceView<M>, P extends MvpPresenter<V>, T extends ViewDataBinding>  
20 - extends MvpLceActivity<CV, M, V, P> {  
21 -  
22 - public V view;  
23 - public T binding;  
24 -  
25 - @Override  
26 - protected void onCreate(Bundle savedInstanceState) {  
27 - super.onCreate(savedInstanceState);  
28 - binding = DataBindingUtil.setContentView(this, getLayoutId());  
29 - }  
30 -  
31 - protected abstract int getLayoutId();  
32 -  
33 - /**  
34 - * Instantiate a view instance  
35 - *  
36 - * @return The {@link MvpView} for this view  
37 - */  
38 - @NonNull  
39 - public abstract V createView();  
40 -  
41 - @NonNull  
42 - @Override  
43 - public V getMvpView() {  
44 - if (view == null) view = createView();  
45 - return view;  
46 - }  
47 -}  
48 \ No newline at end of file 0 \ No newline at end of file
cnlive/src/main/java/com/cnlive/libs/base/fragment/MvpBindingFragment.java
@@ -15,9 +15,12 @@ import com.hannesdorfmann.mosby.mvp.MvpPresenter; @@ -15,9 +15,12 @@ import com.hannesdorfmann.mosby.mvp.MvpPresenter;
15 import com.hannesdorfmann.mosby.mvp.MvpView; 15 import com.hannesdorfmann.mosby.mvp.MvpView;
16 16
17 /** 17 /**
18 - * Created by xiansong on 2017/7/25. 18 + * MVP Databinding Base Fragment
  19 + * @param <V> MVP View {@link MvpView}
  20 + * @param <P> MVP Presenter {@link MvpPresenter}
  21 + * @param <D> Databind Page Data
  22 + * @param <T> Databind Activity ViewDataBinding {@link ViewDataBinding}
19 */ 23 */
20 -  
21 public abstract class MvpBindingFragment<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpFragment<V, P> { 24 public abstract class MvpBindingFragment<V extends MvpView, P extends MvpPresenter<V>, D, T extends ViewDataBinding> extends MvpFragment<V, P> {
22 25
23 public V view; 26 public V view;
cnlive/src/main/java/com/cnlive/libs/base/model/PageModelInfo.java deleted 100644 → 0
1 -package com.cnlive.libs.base.model;  
2 -  
3 -import java.io.Serializable;  
4 -import java.util.List;  
5 -  
6 -/**  
7 - * Created by xiansong on 2017/7/25.  
8 - */  
9 -  
10 -public class PageModelInfo {  
11 - private String title;  
12 - private String name;  
13 -  
14 - private List<PageModelGroup> modelGroup;  
15 -  
16 - public String getTitle() {  
17 - return title;  
18 - }  
19 -  
20 - public void setTitle(String title) {  
21 - this.title = title;  
22 - }  
23 -  
24 - public String getName() {  
25 - return name;  
26 - }  
27 -  
28 - public void setName(String name) {  
29 - this.name = name;  
30 - }  
31 -  
32 - public List<PageModelGroup> getModelGroup() {  
33 - return modelGroup;  
34 - }  
35 -  
36 - public void setModelGroup(List<PageModelGroup> modelGroup) {  
37 - this.modelGroup = modelGroup;  
38 - }  
39 -  
40 - public static class PageModelGroup implements Serializable{  
41 - private String title;  
42 - private String name;  
43 - private List<PageModelFields> modelFields;  
44 -  
45 - public String getTitle() {  
46 - return title;  
47 - }  
48 -  
49 - public void setTitle(String title) {  
50 - this.title = title;  
51 - }  
52 -  
53 - public String getName() {  
54 - return name;  
55 - }  
56 -  
57 - public void setName(String name) {  
58 - this.name = name;  
59 - }  
60 -  
61 - public List<PageModelFields> getModelFields() {  
62 - return modelFields;  
63 - }  
64 -  
65 - public void setModelFields(List<PageModelFields> modelFields) {  
66 - this.modelFields = modelFields;  
67 - }  
68 -  
69 - public static class PageModelFields implements Serializable{  
70 -  
71 - private String name;  
72 - private String value;  
73 - private String title;  
74 - private String type;  
75 - private int rows;  
76 - private boolean required;  
77 - private List<String> options;  
78 -  
79 - public String getValue() {  
80 - return value;  
81 - }  
82 -  
83 - public void setValue(String value) {  
84 - this.value = value;  
85 - }  
86 -  
87 - public String getName() {  
88 - return name;  
89 - }  
90 -  
91 - public void setName(String name) {  
92 - this.name = name;  
93 - }  
94 -  
95 - public String getTitle() {  
96 - return title;  
97 - }  
98 -  
99 - public void setTitle(String title) {  
100 - this.title = title;  
101 - }  
102 -  
103 - public String getType() {  
104 - return type;  
105 - }  
106 -  
107 - public void setType(String type) {  
108 - this.type = type;  
109 - }  
110 -  
111 - public int getRows() {  
112 - return rows;  
113 - }  
114 -  
115 - public void setRows(int rows) {  
116 - this.rows = rows;  
117 - }  
118 -  
119 - public boolean isRequired() {  
120 - return required;  
121 - }  
122 -  
123 - public void setRequired(boolean required) {  
124 - this.required = required;  
125 - }  
126 -  
127 - public List<String> getOptions() {  
128 - return options;  
129 - }  
130 -  
131 - public void setOptions(List<String> options) {  
132 - this.options = options;  
133 - }  
134 -  
135 - }  
136 - }  
137 -  
138 -}  
cnlive/src/main/java/com/cnlive/libs/base/model/TitlePage.java deleted 100644 → 0
1 -package com.cnlive.libs.base.model;  
2 -  
3 -import android.databinding.BaseObservable;  
4 -import android.databinding.Bindable;  
5 -  
6 -import com.cnlive.libs.base.BR;  
7 -  
8 -  
9 -/**  
10 - * Created by Granzon on 2017/7/23.  
11 - */  
12 -  
13 -public abstract class TitlePage extends BaseObservable {  
14 -  
15 -  
16 - private int back;  
17 - private String title;  
18 -  
19 - public TitlePage() {  
20 - title = initTitle();  
21 - back = initBack();  
22 - }  
23 -  
24 - public abstract String initTitle();  
25 -  
26 - public abstract int initBack();  
27 -  
28 -  
29 - @Bindable  
30 - public String getTitle() {  
31 - return title;  
32 - }  
33 -  
34 - public void setTitle(String title) {  
35 - this.title = title;  
36 - notifyPropertyChanged(BR.title);  
37 - }  
38 -  
39 - @Bindable  
40 - public int getBack() {  
41 - return back;  
42 - }  
43 -  
44 - public void setBack(int back) {  
45 - this.back = back;  
46 - notifyPropertyChanged(BR.back);  
47 - }  
48 -}  
cnlive/src/main/java/com/cnlive/libs/base/util/LogUtil.java
@@ -4,7 +4,9 @@ import android.util.Log; @@ -4,7 +4,9 @@ import android.util.Log;
4 4
5 import com.cnlive.libs.base.BuildConfig; 5 import com.cnlive.libs.base.BuildConfig;
6 6
7 - 7 +/**
  8 + * Log output tool
  9 + */
8 public class LogUtil { 10 public class LogUtil {
9 11
10 public static void e(String tag, String msg) { 12 public static void e(String tag, String msg) {
cnlive/src/main/java/com/cnlive/libs/base/util/PixelsUtil.java 0 → 100644
  1 +package com.cnlive.libs.base.util;
  2 +
  3 +import android.content.res.Resources;
  4 +import android.util.TypedValue;
  5 +
  6 +/**
  7 + * Pixel converter
  8 + */
  9 +public class PixelsUtil {
  10 +
  11 + public static int dip2px(float dipValue) {
  12 + final float scale = Resources.getSystem().getDisplayMetrics().density;
  13 + return (int) (dipValue * scale + 0.5f);
  14 + }
  15 +
  16 + public static int px2dip(float pxValue) {
  17 + final float scale = Resources.getSystem().getDisplayMetrics().density;
  18 + return (int) (pxValue / scale + 0.5f);
  19 + }
  20 +
  21 + public static int sp2px(float spVal) {
  22 + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal, Resources.getSystem().getDisplayMetrics());
  23 + }
  24 +
  25 + public static float px2sp(float pxVal) {
  26 + return (pxVal / Resources.getSystem().getDisplayMetrics().scaledDensity);
  27 + }
  28 +
  29 +}
cnlive/src/main/java/com/cnlive/libs/base/util/TimerUtil.java 0 → 100644
  1 +package com.cnlive.libs.base.util;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.Message;
  5 +import android.os.SystemClock;
  6 +
  7 +import java.lang.ref.WeakReference;
  8 +
  9 +public class TimerUtil {
  10 + private long totalTime = -1;
  11 + private long intervalTime = 0;
  12 + private long remainTime;
  13 + private long systemAddTotalTime;
  14 + private static final int TIME = 1;
  15 + private TimeListener listener;
  16 + private long curReminTime;
  17 + private boolean isPause = false;
  18 +
  19 + public TimerUtil() {
  20 + mHandler = new MyHandler(this);
  21 + }
  22 +
  23 + private static class MyHandler extends Handler {
  24 + WeakReference<TimerUtil> mActivity;
  25 +
  26 + MyHandler(TimerUtil activity) {
  27 + mActivity = new WeakReference<>(activity);
  28 + }
  29 +
  30 + @Override
  31 + public void handleMessage(Message msg) {
  32 + TimerUtil theActivity = mActivity.get();
  33 + switch (msg.what) {
  34 + case TIME:
  35 + if (!theActivity.isPause)
  36 + theActivity.soloveTime();
  37 + break;
  38 + case 2:
  39 + theActivity.isPause = true;
  40 + break;
  41 + default:
  42 + break;
  43 + }
  44 + }
  45 + }
  46 +
  47 +
  48 + public void setIntervalTime(long intervalTime) {
  49 + this.intervalTime = intervalTime;
  50 + }
  51 +
  52 + public void setTotalTime(long totalTime) {
  53 + this.totalTime = totalTime;
  54 + }
  55 +
  56 + public long getIntervalTime() {
  57 + return intervalTime;
  58 + }
  59 +
  60 + public long getTotalTime() {
  61 + return totalTime;
  62 + }
  63 +
  64 + public void start() {
  65 + if (totalTime <= 0 && intervalTime <= 0) {
  66 + throw new RuntimeException("you must set the totalTime > 0 or intervalTime >0");
  67 + }
  68 +
  69 + systemAddTotalTime = SystemClock.elapsedRealtime() + totalTime;
  70 +
  71 + if (null != mHandler)
  72 + mHandler.sendEmptyMessage(TIME);
  73 + }
  74 +
  75 + public void cancel() {
  76 + if (mHandler != null) {
  77 + mHandler.removeMessages(TIME);
  78 + }
  79 + }
  80 +
  81 + public void release() {
  82 + if (mHandler != null) {
  83 + mHandler.removeMessages(0);
  84 + mHandler.removeCallbacks(null);
  85 + mHandler = null;
  86 + }
  87 + }
  88 +
  89 + public void pause() {
  90 + if (mHandler != null) {
  91 + mHandler.removeMessages(TIME);
  92 + isPause = true;
  93 + curReminTime = remainTime;
  94 + }
  95 + }
  96 +
  97 + public void resume() {
  98 + if (isPause) {
  99 + isPause = false;
  100 + totalTime = curReminTime;
  101 + start();
  102 + }
  103 + }
  104 +
  105 + private MyHandler mHandler;
  106 +
  107 +
  108 + private void soloveTime() {
  109 + remainTime = systemAddTotalTime - SystemClock.elapsedRealtime();
  110 + if (remainTime <= 0) {
  111 + if (listener != null) {
  112 + listener.onFinish();
  113 + cancel();
  114 + }
  115 + } else if (remainTime < intervalTime) {
  116 + if (null != mHandler)
  117 + mHandler.sendEmptyMessageDelayed(TIME, remainTime);
  118 + } else {
  119 + long curSystemTime = SystemClock.elapsedRealtime();
  120 + if (listener != null) {
  121 + listener.onInterval(remainTime);
  122 + }
  123 +
  124 + long delay = curSystemTime + intervalTime - SystemClock.elapsedRealtime();
  125 +
  126 + while (delay < 0) delay += intervalTime;
  127 +
  128 + if (null != mHandler) {
  129 + mHandler.sendEmptyMessageDelayed(TIME, delay);
  130 + }
  131 + }
  132 + }
  133 +
  134 + public interface TimeListener {
  135 + void onFinish();
  136 +
  137 + void onInterval(long remainTime);
  138 + }
  139 +
  140 + public void setTimerLiener(TimeListener listener) {
  141 + this.listener = listener;
  142 + }
  143 +
  144 +}
cnlive/src/main/java/com/cnlive/libs/base/util/ToastUtil.java
1 package com.cnlive.libs.base.util; 1 package com.cnlive.libs.base.util;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 -import android.content.res.Resources; 4 +import android.support.annotation.IntDef;
5 import android.text.TextUtils; 5 import android.text.TextUtils;
6 import android.view.Gravity; 6 import android.view.Gravity;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.widget.TextView;
7 import android.widget.Toast; 10 import android.widget.Toast;
8 11
  12 +import java.lang.annotation.Retention;
  13 +import java.lang.annotation.RetentionPolicy;
9 14
  15 +/**
  16 + * Toast tooltip
  17 + */
10 public class ToastUtil { 18 public class ToastUtil {
11 19
12 - private static long back_pressed; 20 + @IntDef({Toast.LENGTH_LONG, Toast.LENGTH_SHORT})
  21 + @Retention(RetentionPolicy.SOURCE)
  22 + @interface TOAST_DURATION {
  23 + }
  24 +
  25 + private static final String TAG = "ToastUtil";
  26 +
  27 + private static long show_time;
13 private static String show_msg = ""; 28 private static String show_msg = "";
14 29
15 - public static int dip2px(int dpValue) {  
16 - final float scale = Resources.getSystem().getDisplayMetrics().density;  
17 - return (int) (dpValue * scale + 0.5f); 30 + private Context context;
  31 + private Build config;
  32 +
  33 + public static Build newBuild() {
  34 + return new Build();
18 } 35 }
19 36
20 - private Context mContext; 37 + public ToastUtil(Context context) {
  38 + this.context = context;
  39 + }
21 40
22 - public ToastUtil(Context context){  
23 - this.mContext = context; 41 + public ToastUtil(Context context, Build config) {
  42 + this.context = context;
  43 + this.config = config;
24 } 44 }
25 45
26 - public void showToast(String str, int duration) { 46 + /**
  47 + * Show the Toast window
  48 + *
  49 + * @param str Message
  50 + * @param duration Toast display time
  51 + */
  52 + public void showToast(String str, @TOAST_DURATION int duration) {
27 if (TextUtils.isEmpty(str)) return; 53 if (TextUtils.isEmpty(str)) return;
28 - if (back_pressed + 2000 < System.currentTimeMillis() || !show_msg.equals(str)) {  
29 - show_msg = str;  
30 -  
31 - Toast toast = Toast.makeText(mContext, str, duration); 54 + if (show_time + 2000 < System.currentTimeMillis() || !show_msg.equals(str)) {
  55 + View view = getView(show_msg = str);
32 56
33 - toast.setGravity(Gravity.BOTTOM, 0, dip2px(128)); 57 + Toast toast = Toast.makeText(context, show_msg = str, duration);
  58 + toast.setGravity(
  59 + config == null ? Gravity.NO_GRAVITY : config.gravity,
  60 + config == null ? 0 : config.xOffset,
  61 + config == null ? 0 : config.yOffset);
  62 + if (view != null) toast.setView(view);
34 toast.show(); 63 toast.show();
35 } 64 }
36 - back_pressed = System.currentTimeMillis(); 65 + show_time = System.currentTimeMillis();
37 } 66 }
38 67
39 - 68 + /**
  69 + * Show the Toast window
  70 + *
  71 + * @param str Message
  72 + */
40 public void showToast(String str) { 73 public void showToast(String str) {
41 showToast(str, Toast.LENGTH_SHORT); 74 showToast(str, Toast.LENGTH_SHORT);
42 } 75 }
43 76
  77 + private View getView(String message) {
  78 + View view = null;
  79 + try {
  80 + view = LayoutInflater
  81 + .from(context)
  82 + .inflate(config == null ? 0 : config.layoutId, null, false);
  83 + TextView textView = view.findViewById(config.viewId);
  84 + textView.setText(message);
  85 + } catch (Exception e) {
  86 + LogUtil.d(TAG, "", e);
  87 + }
  88 + return view;
  89 + }
  90 +
  91 + /**
  92 + * Toast Build
  93 + */
  94 + public static class Build {
  95 + @IntDef({Gravity.NO_GRAVITY, Gravity.CENTER, Gravity.BOTTOM, Gravity.TOP})
  96 + @Retention(RetentionPolicy.SOURCE)
  97 + @interface TOAST_GRAVITY_TYPE {
  98 + }
  99 +
  100 +
  101 + private int gravity = Gravity.NO_GRAVITY;
  102 +
  103 + private int xOffset = 0, yOffset = 0;
  104 +
  105 + private int layoutId = 0, viewId = 0;
  106 +
  107 + private Build() {
  108 + }
44 109
  110 + public int getGravity() {
  111 + return gravity;
  112 + }
  113 +
  114 + public Build setGravity(@TOAST_GRAVITY_TYPE int gravity) {
  115 + this.gravity = gravity;
  116 + return this;
  117 + }
  118 +
  119 + /**
  120 + * View alignment
  121 + *
  122 + * @param gravity gravity type
  123 + * @param xOffset X coordinate offset
  124 + * @param yOffset Y coordinate offset
  125 + * @return
  126 + */
  127 + public Build setGravity(@TOAST_GRAVITY_TYPE int gravity, int xOffset, int yOffset) {
  128 + this.gravity = gravity;
  129 + this.xOffset = xOffset;
  130 + this.yOffset = yOffset;
  131 + return this;
  132 + }
  133 +
  134 + public int getxOffset() {
  135 + return xOffset;
  136 + }
  137 +
  138 + public Build setxOffset(int xOffset) {
  139 + this.xOffset = xOffset;
  140 + return this;
  141 + }
  142 +
  143 + public int getyOffset() {
  144 + return yOffset;
  145 + }
  146 +
  147 + public Build setyOffset(int yOffset) {
  148 + this.yOffset = yOffset;
  149 + return this;
  150 + }
  151 +
  152 + public int getViewId() {
  153 + return viewId;
  154 + }
  155 +
  156 + public Build setViewId(int viewId) {
  157 + this.viewId = viewId;
  158 + return this;
  159 + }
  160 +
  161 + /**
  162 + * Set up a custom view
  163 + *
  164 + * @param layoutId Custom View Layout ID
  165 + * @param viewId Custom View TextView ID
  166 + * @return Build
  167 + */
  168 + public Build setView(int layoutId, int viewId) {
  169 + this.viewId = viewId;
  170 + this.layoutId = layoutId;
  171 + return this;
  172 + }
  173 +
  174 + public int getLayoutId() {
  175 + return layoutId;
  176 + }
  177 +
  178 + public Build setLayoutId(int layoutId) {
  179 + this.layoutId = layoutId;
  180 + return this;
  181 + }
  182 +
  183 + public ToastUtil build(Context context) {
  184 + return new ToastUtil(context, this);
  185 + }
  186 + }
45 } 187 }