Commit 4f62092f5b2e04342ae494db71d8181b37320053
Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/newModuleStrike
Showing
40 changed files
with
1276 additions
and
2711 deletions
Too many changes to show.
To preserve performance only 40 of 195 files are displayed.
.idea/gradle.xml
| @@ -24,7 +24,6 @@ | @@ -24,7 +24,6 @@ | ||
| 24 | <option value="$PROJECT_DIR$/core/app_qr" /> | 24 | <option value="$PROJECT_DIR$/core/app_qr" /> |
| 25 | <option value="$PROJECT_DIR$/core/base" /> | 25 | <option value="$PROJECT_DIR$/core/base" /> |
| 26 | <option value="$PROJECT_DIR$/core/database" /> | 26 | <option value="$PROJECT_DIR$/core/database" /> |
| 27 | - <option value="$PROJECT_DIR$/core/dentity_verfication" /> | ||
| 28 | <option value="$PROJECT_DIR$/core/imageload" /> | 27 | <option value="$PROJECT_DIR$/core/imageload" /> |
| 29 | <option value="$PROJECT_DIR$/core/network" /> | 28 | <option value="$PROJECT_DIR$/core/network" /> |
| 30 | <option value="$PROJECT_DIR$/library_baidumap" /> | 29 | <option value="$PROJECT_DIR$/library_baidumap" /> |
app/strike/build.gradle
| @@ -187,7 +187,6 @@ dependencies { | @@ -187,7 +187,6 @@ dependencies { | ||
| 187 | // implementation project(path: ':core:encipher') | 187 | // implementation project(path: ':core:encipher') |
| 188 | // implementation project(path: ':cloud:user') | 188 | // implementation project(path: ':cloud:user') |
| 189 | implementation project(path: ':cloud:wjj_lib') | 189 | implementation project(path: ':cloud:wjj_lib') |
| 190 | - implementation project(path: ':core:dentity_verfication') | ||
| 191 | implementation "androidx.viewpager2:viewpager2:1.0.0" | 190 | implementation "androidx.viewpager2:viewpager2:1.0.0" |
| 192 | 191 | ||
| 193 | 192 |
app/strike/src/main/AndroidManifest.xml
| @@ -17,7 +17,6 @@ | @@ -17,7 +17,6 @@ | ||
| 17 | android:roundIcon="@mipmap/ic_launcher_round" | 17 | android:roundIcon="@mipmap/ic_launcher_round" |
| 18 | android:supportsRtl="true" | 18 | android:supportsRtl="true" |
| 19 | android:theme="@style/AppTheme"> | 19 | android:theme="@style/AppTheme"> |
| 20 | - <activity android:name="com.cnlive.strike.imgutil.UgcActivity"></activity> | ||
| 21 | <activity android:name="com.cnlive.strike.imgutil.SimplePrevActivity" /> | 20 | <activity android:name="com.cnlive.strike.imgutil.SimplePrevActivity" /> |
| 22 | <activity android:name="com.cnlive.strike.demo.activity.HappyChinaActivity" /> | 21 | <activity android:name="com.cnlive.strike.demo.activity.HappyChinaActivity" /> |
| 23 | 22 |
app/strike/src/main/java/com/cnlive/strike/MainActivity.java
| @@ -10,7 +10,6 @@ import android.view.View; | @@ -10,7 +10,6 @@ import android.view.View; | ||
| 10 | import com.cnlive.cloud.R; | 10 | import com.cnlive.cloud.R; |
| 11 | import com.cnlive.strike.demo.activity.DemoMvpActivity; | 11 | import com.cnlive.strike.demo.activity.DemoMvpActivity; |
| 12 | import com.cnlive.strike.imgutil.ImgActivity; | 12 | import com.cnlive.strike.imgutil.ImgActivity; |
| 13 | -import com.cnlive.strike.imgutil.UgcActivity; | ||
| 14 | 13 | ||
| 15 | import androidx.annotation.NonNull; | 14 | import androidx.annotation.NonNull; |
| 16 | import androidx.annotation.Nullable; | 15 | import androidx.annotation.Nullable; |
| @@ -31,7 +30,6 @@ public class MainActivity extends AppCompatActivity { | @@ -31,7 +30,6 @@ public class MainActivity extends AppCompatActivity { | ||
| 31 | } | 30 | } |
| 32 | }); | 31 | }); |
| 33 | findViewById(R.id.to_img).setOnClickListener(view -> startActivity(new Intent(this, ImgActivity.class))); | 32 | findViewById(R.id.to_img).setOnClickListener(view -> startActivity(new Intent(this, ImgActivity.class))); |
| 34 | - findViewById(R.id.ugc_btn).setOnClickListener(view -> startActivity(new Intent(this, UgcActivity.class))); | ||
| 35 | } | 33 | } |
| 36 | 34 | ||
| 37 | @Nullable | 35 | @Nullable |
app/strike/src/main/java/com/cnlive/strike/imgutil/UgcActivity.java deleted
100644 → 0
| 1 | -package com.cnlive.strike.imgutil; | ||
| 2 | - | ||
| 3 | -import android.content.Intent; | ||
| 4 | -import android.os.Bundle; | ||
| 5 | - | ||
| 6 | -import com.cnlive.cloud.R; | ||
| 7 | -import com.cnlive.core.company_verfication.ui.activity.FillInCompanyDataActivity; | ||
| 8 | -import com.cnlive.core.company_verfication.ui.activity.SelectCompanyDataActivity; | ||
| 9 | -import com.cnlive.core.people_verfication.activity.CheckResultActivity; | ||
| 10 | -import com.cnlive.core.people_verfication.activity.PersonCheckActivity; | ||
| 11 | -import com.cnlive.core.people_verfication.activity.TakeIdentityPictureActivity; | ||
| 12 | - | ||
| 13 | -import androidx.appcompat.app.AppCompatActivity; | ||
| 14 | - | ||
| 15 | -public class UgcActivity extends AppCompatActivity { | ||
| 16 | - | ||
| 17 | - @Override | ||
| 18 | - protected void onCreate(Bundle savedInstanceState) { | ||
| 19 | - super.onCreate(savedInstanceState); | ||
| 20 | - setContentView(R.layout.activity_ugc); | ||
| 21 | - | ||
| 22 | - findViewById(R.id.people_denty).setOnClickListener(view -> startActivity(new Intent(this, TakeIdentityPictureActivity.class))); | ||
| 23 | - findViewById(R.id.company_denty).setOnClickListener(view -> startActivity(new Intent(this, FillInCompanyDataActivity.class))); | ||
| 24 | - findViewById(R.id.company_denty_list).setOnClickListener(view -> startActivity(new Intent(this, SelectCompanyDataActivity.class))); | ||
| 25 | - | ||
| 26 | - findViewById(R.id.btn1).setOnClickListener(view ->PersonCheckActivity.startActivity(this,"","-1")); | ||
| 27 | - findViewById(R.id.btn2).setOnClickListener(view ->PersonCheckActivity.startActivity(this,"","0")); | ||
| 28 | - findViewById(R.id.btn3).setOnClickListener(view ->PersonCheckActivity.startActivity(this,"","2")); | ||
| 29 | - findViewById(R.id.btn4).setOnClickListener(view ->PersonCheckActivity.startActivity(this,"","1")); | ||
| 30 | - | ||
| 31 | - findViewById(R.id.btn01).setOnClickListener(view -> CheckResultActivity.startActivity(this,"","person","-1")); | ||
| 32 | - findViewById(R.id.btn02).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","person","0")); | ||
| 33 | - findViewById(R.id.btn03).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","person","2")); | ||
| 34 | - findViewById(R.id.btn04).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","person","1")); | ||
| 35 | - | ||
| 36 | - findViewById(R.id.btn11).setOnClickListener(view -> CheckResultActivity.startActivity(this,"","company","-1")); | ||
| 37 | - findViewById(R.id.btn12).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","company","0")); | ||
| 38 | - findViewById(R.id.btn13).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","company","2")); | ||
| 39 | - findViewById(R.id.btn14).setOnClickListener(view ->CheckResultActivity.startActivity(this,"","company","1")); | ||
| 40 | - } | ||
| 41 | -} |
app/strike/src/main/res/layout/activity_main.xml
| @@ -21,11 +21,5 @@ | @@ -21,11 +21,5 @@ | ||
| 21 | android:layout_height="wrap_content" | 21 | android:layout_height="wrap_content" |
| 22 | android:text="图片加载测试"/> | 22 | android:text="图片加载测试"/> |
| 23 | 23 | ||
| 24 | - <Button | ||
| 25 | - android:id="@+id/ugc_btn" | ||
| 26 | - android:layout_width="wrap_content" | ||
| 27 | - android:layout_height="wrap_content" | ||
| 28 | - android:text="ugc直播认证" | ||
| 29 | - /> | ||
| 30 | </LinearLayout> | 24 | </LinearLayout> |
| 31 | </layout> | 25 | </layout> |
| 32 | \ No newline at end of file | 26 | \ No newline at end of file |
app/strike/src/main/res/layout/activity_ugc.xml deleted
100644 → 0
| 1 | -<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | -<LinearLayout 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 | - android:layout_width="match_parent" | ||
| 6 | - android:layout_height="match_parent" | ||
| 7 | - android:orientation="vertical" | ||
| 8 | - tools:context="com.cnlive.strike.imgutil.UgcActivity"> | ||
| 9 | - | ||
| 10 | - <Button | ||
| 11 | - android:id="@+id/people_denty" | ||
| 12 | - android:layout_width="match_parent" | ||
| 13 | - android:layout_height="wrap_content" | ||
| 14 | - android:layout_margin="@dimen/dp_10" | ||
| 15 | - android:text="个人认证" /> | ||
| 16 | - | ||
| 17 | - <TextView | ||
| 18 | - android:layout_width="wrap_content" | ||
| 19 | - android:layout_height="wrap_content" | ||
| 20 | - android:text="身份校验" /> | ||
| 21 | - | ||
| 22 | - <LinearLayout | ||
| 23 | - android:layout_width="match_parent" | ||
| 24 | - android:layout_height="wrap_content" | ||
| 25 | - android:orientation="horizontal"> | ||
| 26 | - | ||
| 27 | - <Button | ||
| 28 | - android:id="@+id/btn1" | ||
| 29 | - android:layout_width="wrap_content" | ||
| 30 | - android:layout_height="wrap_content" | ||
| 31 | - android:text="未校验" /> | ||
| 32 | - | ||
| 33 | - <Button | ||
| 34 | - android:id="@+id/btn2" | ||
| 35 | - android:layout_width="wrap_content" | ||
| 36 | - android:layout_height="wrap_content" | ||
| 37 | - android:text="审核中" /> | ||
| 38 | - | ||
| 39 | - <Button | ||
| 40 | - android:id="@+id/btn3" | ||
| 41 | - android:layout_width="wrap_content" | ||
| 42 | - android:layout_height="wrap_content" | ||
| 43 | - android:text="失败" /> | ||
| 44 | - | ||
| 45 | - <Button | ||
| 46 | - android:id="@+id/btn4" | ||
| 47 | - android:layout_width="wrap_content" | ||
| 48 | - android:layout_height="wrap_content" | ||
| 49 | - android:text="成功" /> | ||
| 50 | - </LinearLayout> | ||
| 51 | - | ||
| 52 | - <TextView | ||
| 53 | - android:layout_width="wrap_content" | ||
| 54 | - android:layout_height="wrap_content" | ||
| 55 | - android:text="个人认证" /> | ||
| 56 | - | ||
| 57 | - <LinearLayout | ||
| 58 | - android:layout_width="match_parent" | ||
| 59 | - android:layout_height="wrap_content" | ||
| 60 | - android:orientation="horizontal"> | ||
| 61 | - | ||
| 62 | - <Button | ||
| 63 | - android:id="@+id/btn01" | ||
| 64 | - android:layout_width="wrap_content" | ||
| 65 | - android:layout_height="wrap_content" | ||
| 66 | - android:text="未认证" /> | ||
| 67 | - | ||
| 68 | - <Button | ||
| 69 | - android:id="@+id/btn02" | ||
| 70 | - android:layout_width="wrap_content" | ||
| 71 | - android:layout_height="wrap_content" | ||
| 72 | - android:text="审核中" /> | ||
| 73 | - | ||
| 74 | - <Button | ||
| 75 | - android:id="@+id/btn03" | ||
| 76 | - android:layout_width="wrap_content" | ||
| 77 | - android:layout_height="wrap_content" | ||
| 78 | - android:text="失败" /> | ||
| 79 | - | ||
| 80 | - <Button | ||
| 81 | - android:id="@+id/btn04" | ||
| 82 | - android:layout_width="wrap_content" | ||
| 83 | - android:layout_height="wrap_content" | ||
| 84 | - android:text="成功" /> | ||
| 85 | - </LinearLayout> | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - <Button | ||
| 90 | - android:id="@+id/company_denty" | ||
| 91 | - android:layout_width="match_parent" | ||
| 92 | - android:layout_height="wrap_content" | ||
| 93 | - android:layout_margin="@dimen/dp_10" | ||
| 94 | - android:text="机构认证" /> | ||
| 95 | - | ||
| 96 | - <TextView | ||
| 97 | - android:layout_width="wrap_content" | ||
| 98 | - android:layout_height="wrap_content" | ||
| 99 | - android:text="机构认证" /> | ||
| 100 | - | ||
| 101 | - <LinearLayout | ||
| 102 | - android:layout_width="match_parent" | ||
| 103 | - android:layout_height="wrap_content" | ||
| 104 | - android:orientation="horizontal"> | ||
| 105 | - | ||
| 106 | - <Button | ||
| 107 | - android:id="@+id/btn11" | ||
| 108 | - android:layout_width="wrap_content" | ||
| 109 | - android:layout_height="wrap_content" | ||
| 110 | - android:text="未认证" /> | ||
| 111 | - | ||
| 112 | - <Button | ||
| 113 | - android:id="@+id/btn12" | ||
| 114 | - android:layout_width="wrap_content" | ||
| 115 | - android:layout_height="wrap_content" | ||
| 116 | - android:text="审核中" /> | ||
| 117 | - | ||
| 118 | - <Button | ||
| 119 | - android:id="@+id/btn13" | ||
| 120 | - android:layout_width="wrap_content" | ||
| 121 | - android:layout_height="wrap_content" | ||
| 122 | - android:text="失败" /> | ||
| 123 | - | ||
| 124 | - <Button | ||
| 125 | - android:id="@+id/btn14" | ||
| 126 | - android:layout_width="wrap_content" | ||
| 127 | - android:layout_height="wrap_content" | ||
| 128 | - android:text="成功" /> | ||
| 129 | - </LinearLayout> | ||
| 130 | - | ||
| 131 | - <Button | ||
| 132 | - android:id="@+id/company_denty_list" | ||
| 133 | - android:layout_width="match_parent" | ||
| 134 | - android:layout_height="wrap_content" | ||
| 135 | - android:layout_margin="@dimen/dp_10" | ||
| 136 | - android:text="机构认证列表" /> | ||
| 137 | -</LinearLayout> |
core/base/src/main/java/com/cnlive/core/libs/base/frame/activity/BaseActivity.java
| 1 | package com.cnlive.core.libs.base.frame.activity; | 1 | package com.cnlive.core.libs.base.frame.activity; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import android.annotation.SuppressLint; | ||
| 4 | import android.app.Activity; | 5 | import android.app.Activity; |
| 5 | import android.content.Context; | 6 | import android.content.Context; |
| 6 | -import android.content.DialogInterface; | ||
| 7 | import android.content.Intent; | 7 | import android.content.Intent; |
| 8 | import android.content.pm.ActivityInfo; | 8 | import android.content.pm.ActivityInfo; |
| 9 | import android.content.pm.PackageManager; | 9 | import android.content.pm.PackageManager; |
| 10 | import android.content.res.Configuration; | 10 | import android.content.res.Configuration; |
| 11 | import android.content.res.Resources; | 11 | import android.content.res.Resources; |
| 12 | import android.graphics.Bitmap; | 12 | import android.graphics.Bitmap; |
| 13 | -import android.graphics.Color; | 13 | +import android.graphics.drawable.Drawable; |
| 14 | import android.net.Uri; | 14 | import android.net.Uri; |
| 15 | import android.os.Build; | 15 | import android.os.Build; |
| 16 | import android.os.Bundle; | 16 | import android.os.Bundle; |
| @@ -20,42 +20,48 @@ import android.provider.Settings; | @@ -20,42 +20,48 @@ import android.provider.Settings; | ||
| 20 | import android.text.TextUtils; | 20 | import android.text.TextUtils; |
| 21 | import android.util.DisplayMetrics; | 21 | import android.util.DisplayMetrics; |
| 22 | import android.util.Log; | 22 | import android.util.Log; |
| 23 | +import android.view.Gravity; | ||
| 23 | import android.view.MotionEvent; | 24 | import android.view.MotionEvent; |
| 24 | import android.view.View; | 25 | import android.view.View; |
| 25 | import android.view.ViewGroup; | 26 | import android.view.ViewGroup; |
| 26 | -import android.view.Window; | ||
| 27 | import android.view.WindowManager; | 27 | import android.view.WindowManager; |
| 28 | import android.view.inputmethod.InputMethodManager; | 28 | import android.view.inputmethod.InputMethodManager; |
| 29 | 29 | ||
| 30 | -import androidx.annotation.ColorInt; | ||
| 31 | import androidx.annotation.ColorRes; | 30 | import androidx.annotation.ColorRes; |
| 32 | import androidx.annotation.DrawableRes; | 31 | import androidx.annotation.DrawableRes; |
| 33 | import androidx.annotation.IntRange; | 32 | import androidx.annotation.IntRange; |
| 34 | import androidx.annotation.NonNull; | 33 | import androidx.annotation.NonNull; |
| 35 | import androidx.annotation.Nullable; | 34 | import androidx.annotation.Nullable; |
| 36 | import androidx.annotation.StringRes; | 35 | import androidx.annotation.StringRes; |
| 37 | -import androidx.appcompat.app.AlertDialog; | ||
| 38 | import androidx.core.app.ActivityCompat; | 36 | import androidx.core.app.ActivityCompat; |
| 39 | import androidx.core.content.ContextCompat; | 37 | import androidx.core.content.ContextCompat; |
| 40 | import androidx.databinding.DataBindingUtil; | 38 | import androidx.databinding.DataBindingUtil; |
| 41 | import androidx.databinding.ViewDataBinding; | 39 | import androidx.databinding.ViewDataBinding; |
| 42 | import androidx.fragment.app.Fragment; | 40 | import androidx.fragment.app.Fragment; |
| 43 | 41 | ||
| 42 | +import com.alibaba.android.arouter.facade.Postcard; | ||
| 43 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 44 | import com.alibaba.android.arouter.launcher.ARouter; | 44 | import com.alibaba.android.arouter.launcher.ARouter; |
| 45 | -import com.cnlive.core.libs.base.application.AppConfig; | 45 | +import com.cnlive.cloud.base.BuildConfig; |
| 46 | +import com.cnlive.cloud.base.R; | ||
| 46 | import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | 47 | import com.cnlive.core.libs.base.frame.fragment.BaseFragment; |
| 47 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | 48 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 48 | import com.cnlive.core.libs.base.frame.view.BaseView; | 49 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 49 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | 50 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; |
| 50 | -import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 51 | +import com.cnlive.core.libs.base.listener.Callback; |
| 52 | +import com.cnlive.core.libs.base.network.manager.RxManager; | ||
| 53 | +import com.cnlive.core.libs.base.ui.widget.SelectDialog; | ||
| 54 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 51 | import com.cnlive.core.libs.base.util.AppManager; | 55 | import com.cnlive.core.libs.base.util.AppManager; |
| 56 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 57 | +import com.cnlive.core.libs.base.util.GlobalLifeCircleListener; | ||
| 58 | +import com.cnlive.core.libs.base.util.LifeCircleListener; | ||
| 52 | import com.cnlive.core.libs.base.util.ReflectUtil; | 59 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 60 | +import com.cnlive.core.libs.base.util.SharedPreferencesHelper; | ||
| 53 | import com.cnlive.core.libs.base.util.StatusBarConfig; | 61 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| 54 | import com.cnlive.core.libs.base.util.StatusBarUtil; | 62 | import com.cnlive.core.libs.base.util.StatusBarUtil; |
| 55 | -import com.cnlive.cloud.base.R; | ||
| 56 | import com.hannesdorfmann.mosby3.mvp.MvpActivity; | 63 | import com.hannesdorfmann.mosby3.mvp.MvpActivity; |
| 57 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 64 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 58 | -import com.hannesdorfmann.mosby3.mvp.delegate.ActivityMvpDelegate; | ||
| 59 | import com.me.yokeyword.fragmentation.ExtraTransaction; | 65 | import com.me.yokeyword.fragmentation.ExtraTransaction; |
| 60 | import com.me.yokeyword.fragmentation.Fragmentation; | 66 | import com.me.yokeyword.fragmentation.Fragmentation; |
| 61 | import com.me.yokeyword.fragmentation.ISupportActivity; | 67 | import com.me.yokeyword.fragmentation.ISupportActivity; |
| @@ -75,6 +81,9 @@ import java.util.List; | @@ -75,6 +81,9 @@ import java.util.List; | ||
| 75 | import java.util.Observable; | 81 | import java.util.Observable; |
| 76 | import java.util.Observer; | 82 | import java.util.Observer; |
| 77 | 83 | ||
| 84 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 85 | +import io.reactivex.disposables.Disposable; | ||
| 86 | + | ||
| 78 | 87 | ||
| 79 | /** | 88 | /** |
| 80 | * @author ys | 89 | * @author ys |
| @@ -86,8 +95,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -86,8 +95,6 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 86 | private ViewDataBinding baseBinding; | 95 | private ViewDataBinding baseBinding; |
| 87 | //获取TAG的activity名称 | 96 | //获取TAG的activity名称 |
| 88 | public final String TAG = this.getClass().getSimpleName(); | 97 | public final String TAG = this.getClass().getSimpleName(); |
| 89 | - //是否显示标题栏 | ||
| 90 | - private boolean isShowTitle = true; | ||
| 91 | //是否显示状态栏 | 98 | //是否显示状态栏 |
| 92 | private boolean isShowStatusBar = true; | 99 | private boolean isShowStatusBar = true; |
| 93 | public Context context; | 100 | public Context context; |
| @@ -110,9 +117,17 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -110,9 +117,17 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 110 | private boolean isUserClickAllowBtn = false;//用户是否点击允许按钮 | 117 | private boolean isUserClickAllowBtn = false;//用户是否点击允许按钮 |
| 111 | private boolean isShowRefuseDialog = true;//是否显示拒绝提示框 | 118 | private boolean isShowRefuseDialog = true;//是否显示拒绝提示框 |
| 112 | private String[] userSetPermission; | 119 | private String[] userSetPermission; |
| 120 | + private SelectDialog permissionTipDialog; | ||
| 113 | private Handler myActHandler; | 121 | private Handler myActHandler; |
| 114 | private List<Observable> observableList; | 122 | private List<Observable> observableList; |
| 115 | private boolean isCreateDefultEmptyView = true;//如果没有填充布局,是否设置默认布局,默认是设置的 | 123 | private boolean isCreateDefultEmptyView = true;//如果没有填充布局,是否设置默认布局,默认是设置的 |
| 124 | + private LifeCircleListener lifeCircleListener; //快速管理生命周期 | ||
| 125 | + private static GlobalLifeCircleListener globalLifeCircleListener; //全局生命周期 | ||
| 126 | + | ||
| 127 | + public boolean isActive = false; //当前Activity是否处于前台 | ||
| 128 | + public boolean isAlive = false; //当前Activity是否处于存活状态 | ||
| 129 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 130 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 116 | 131 | ||
| 117 | public final ViewDataBinding getBaseBinding() { | 132 | public final ViewDataBinding getBaseBinding() { |
| 118 | return baseBinding; | 133 | return baseBinding; |
| @@ -122,55 +137,213 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -122,55 +137,213 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 122 | @Override | 137 | @Override |
| 123 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 138 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 124 | super.onCreate(savedInstanceState); | 139 | super.onCreate(savedInstanceState); |
| 125 | - if (0 != getBindLayoutId()) { | ||
| 126 | - baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); | ||
| 127 | - } else if (0 != getViewLayoutId()) { | ||
| 128 | - setContentView(getViewLayoutId()); | ||
| 129 | - } | ||
| 130 | context = this; | 140 | context = this; |
| 131 | me = this; | 141 | me = this; |
| 142 | + isAlive = true; | ||
| 132 | this.savedInstanceState = savedInstanceState; | 143 | this.savedInstanceState = savedInstanceState; |
| 133 | -// //路由参数初始化 | ||
| 134 | -// ARouter.getInstance().inject(this); | 144 | + initRxjava(); |
| 145 | + //路由参数初始化 | ||
| 146 | + ARouter.getInstance().inject(this); | ||
| 135 | //activity管理 | 147 | //activity管理 |
| 136 | AppManager.getInstance().pushActivity(me); | 148 | AppManager.getInstance().pushActivity(me); |
| 137 | - //创建订阅映射 | ||
| 138 | - SubscriptionManager.getInstance().setCurrentDisposables(TAG); | ||
| 139 | //fragment管理 | 149 | //fragment管理 |
| 140 | mDelegate.onCreate(savedInstanceState); | 150 | mDelegate.onCreate(savedInstanceState); |
| 141 | mSwipeDelegate.onCreate(savedInstanceState); | 151 | mSwipeDelegate.onCreate(savedInstanceState); |
| 142 | init(savedInstanceState); | 152 | init(savedInstanceState); |
| 153 | +// if (!isShowTitle) { | ||
| 154 | +// requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
| 155 | +// } | ||
| 156 | + if (!isShowStatusBar) { | ||
| 157 | + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | ||
| 158 | + , WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
| 159 | + } | ||
| 160 | + if (0 != getBindLayoutId()) { | ||
| 161 | + baseBinding = DataBindingUtil.setContentView(this, getBindLayoutId()); | ||
| 162 | + } else if (0 != getViewLayoutId()) { | ||
| 163 | + setContentView(getViewLayoutId()); | ||
| 164 | + } | ||
| 143 | //两种视图都没有设置,就加载默认跟视图,用于fragment切换 | 165 | //两种视图都没有设置,就加载默认跟视图,用于fragment切换 |
| 144 | - if (isCreateDefultEmptyView) { | 166 | + else if (isCreateDefultEmptyView) { |
| 145 | if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { | 167 | if (0 == getBindLayoutId() && 0 == getViewLayoutId()) { |
| 146 | setContentView(R.layout.base_activity_main); | 168 | setContentView(R.layout.base_activity_main); |
| 147 | } | 169 | } |
| 148 | } | 170 | } |
| 149 | - if (null == observableList) { | ||
| 150 | - observableList = new ArrayList<>(); | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | //设置binding数据 | 171 | //设置binding数据 |
| 154 | if (null != baseBinding) { | 172 | if (null != baseBinding) { |
| 155 | initBindingLayoutData(baseBinding); | 173 | initBindingLayoutData(baseBinding); |
| 174 | + if (isViewAttached()) { | ||
| 175 | + getMvpView().initActBindingLayout(this, baseBinding); | ||
| 176 | + } | ||
| 156 | } | 177 | } |
| 157 | if (null != getIntent()) { | 178 | if (null != getIntent()) { |
| 158 | initParams(getIntent()); | 179 | initParams(getIntent()); |
| 159 | } | 180 | } |
| 160 | //初始化控件 | 181 | //初始化控件 |
| 161 | initView(); | 182 | initView(); |
| 162 | - if (!isShowTitle) { | ||
| 163 | - requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - if (!isShowStatusBar) { | ||
| 167 | - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | ||
| 168 | - , WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
| 169 | - } | ||
| 170 | //设置数据 | 183 | //设置数据 |
| 171 | initData(); | 184 | initData(); |
| 185 | + if (null == observableList) { | ||
| 186 | + observableList = new ArrayList<>(); | ||
| 187 | + } | ||
| 172 | //是否开启滑动返回 | 188 | //是否开启滑动返回 |
| 173 | setSwipeBackEnable(isOpenSwipBack); | 189 | setSwipeBackEnable(isOpenSwipBack); |
| 190 | + //生命周期监听 | ||
| 191 | + if (lifeCircleListener != null) { | ||
| 192 | + lifeCircleListener.onCreate(); | ||
| 193 | + } | ||
| 194 | + //全局生命周期监听 | ||
| 195 | + if (globalLifeCircleListener != null) { | ||
| 196 | + globalLifeCircleListener.onCreate(me, me.getClass().getName()); | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + private void initRxjava() { | ||
| 201 | + pauseDisposable = new CompositeDisposable(); | ||
| 202 | + destoryDisposable = new CompositeDisposable(); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + protected void init(@Nullable Bundle savedInstanceState) { | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + protected void initParams(Intent params) { | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * 获取自己的databinding | ||
| 213 | + * | ||
| 214 | + * @param baseBinding | ||
| 215 | + */ | ||
| 216 | + protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 217 | + | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + /** | ||
| 221 | + * 初始化控件 | ||
| 222 | + */ | ||
| 223 | + protected abstract void initView(); | ||
| 224 | + | ||
| 225 | + | ||
| 226 | + /** | ||
| 227 | + * 设置数据 | ||
| 228 | + */ | ||
| 229 | + protected void initData() { | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * 添加订阅 | ||
| 234 | + * Pause 销毁 | ||
| 235 | + * | ||
| 236 | + * @param disposable | ||
| 237 | + * @return | ||
| 238 | + */ | ||
| 239 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 240 | + if (null != disposable) { | ||
| 241 | + if (null != pauseDisposable) { | ||
| 242 | + pauseDisposable.add(disposable); | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + return disposable; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * 添加订阅 | ||
| 250 | + * Destory 销毁 | ||
| 251 | + * | ||
| 252 | + * @param disposable | ||
| 253 | + * @return | ||
| 254 | + */ | ||
| 255 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 256 | + if (null != disposable) { | ||
| 257 | + if (null != destoryDisposable) { | ||
| 258 | + destoryDisposable.add(disposable); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | + return disposable; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + /** | ||
| 265 | + * 实例化路由-对象 | ||
| 266 | + */ | ||
| 267 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 268 | + T obj = null; | ||
| 269 | + try { | ||
| 270 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(this); | ||
| 271 | + } catch (Exception ignored) { | ||
| 272 | + } | ||
| 273 | + return obj; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + /** | ||
| 277 | + * 获取资源颜色 | ||
| 278 | + * | ||
| 279 | + * @param colorId | ||
| 280 | + * @return | ||
| 281 | + */ | ||
| 282 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 283 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + /** | ||
| 287 | + * 获取资源字符串 | ||
| 288 | + * | ||
| 289 | + * @param stringId | ||
| 290 | + * @return | ||
| 291 | + */ | ||
| 292 | + public String getResourceStr(@StringRes int stringId) { | ||
| 293 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + /** | ||
| 297 | + * 获取资源 | ||
| 298 | + * | ||
| 299 | + * @param drawableId | ||
| 300 | + * @return | ||
| 301 | + */ | ||
| 302 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 303 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + /** | ||
| 307 | + * 用户提示 | ||
| 308 | + */ | ||
| 309 | + public void showToast(String message) { | ||
| 310 | + AlertUtil.showDeftToast(me, message); | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + /** | ||
| 314 | + * Arouter跳转 | ||
| 315 | + * | ||
| 316 | + * @param routerPath | ||
| 317 | + * @return | ||
| 318 | + */ | ||
| 319 | + public Postcard goToRouter(String routerPath) { | ||
| 320 | + return ARouter.getInstance().build(routerPath); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + /** | ||
| 324 | + * Arouter跳转无参数 | ||
| 325 | + * | ||
| 326 | + * @param routerPath | ||
| 327 | + * @return | ||
| 328 | + */ | ||
| 329 | + public void goToRouterNoParams(String routerPath) { | ||
| 330 | + ARouter.getInstance().build(routerPath).navigation(this); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + /** | ||
| 334 | + * 实例化路由-对象 (异步) | ||
| 335 | + */ | ||
| 336 | + public <T extends IProvider> void initRouterImpl(String routerPath, Callback<T> callback) { | ||
| 337 | + if (callback == null) return; | ||
| 338 | + | ||
| 339 | + T obj = null; | ||
| 340 | + try { | ||
| 341 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(this); | ||
| 342 | + } catch (Exception ignored) { | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + if (obj != null) callback.call(obj); | ||
| 346 | + else if (BuildConfig.DEBUG) AlertUtil.showDeftToast(this, "功能暂未开放"); | ||
| 174 | } | 347 | } |
| 175 | 348 | ||
| 176 | 349 | ||
| @@ -250,34 +423,37 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -250,34 +423,37 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 250 | return StatusBarUtil.getStatusBarHeight(this); | 423 | return StatusBarUtil.getStatusBarHeight(this); |
| 251 | } | 424 | } |
| 252 | 425 | ||
| 253 | - /**将标题视图自适应沉浸式状态栏 | 426 | + /** |
| 427 | + * 将标题视图自适应沉浸式状态栏 | ||
| 428 | + * | ||
| 254 | * @param view | 429 | * @param view |
| 255 | */ | 430 | */ |
| 256 | - public void setTitleViewAdjustImmersiveStatusBar(View view) { | ||
| 257 | - if (null==view){ | ||
| 258 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->view is Null"); | 431 | + public void setTitleViewAdjustImmersiveStatusBar(View view) { |
| 432 | + if (null == view) { | ||
| 433 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->view is Null"); | ||
| 259 | } | 434 | } |
| 260 | ViewGroup.LayoutParams params = view.getLayoutParams(); | 435 | ViewGroup.LayoutParams params = view.getLayoutParams(); |
| 261 | - if (null==params){ | ||
| 262 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->LayoutParams is Null 无法将标题视图自适应沉浸式状态栏!"); | 436 | + if (null == params) { |
| 437 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->LayoutParams is Null 无法将标题视图自适应沉浸式状态栏!"); | ||
| 263 | return; | 438 | return; |
| 264 | } | 439 | } |
| 265 | int oldHeight = params.height; | 440 | int oldHeight = params.height; |
| 266 | - if (oldHeight<=0){ | ||
| 267 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->无法获取标题视图高度!"); | 441 | + if (oldHeight <= 0) { |
| 442 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->无法获取标题视图高度!"); | ||
| 268 | return; | 443 | return; |
| 269 | } | 444 | } |
| 270 | - if (0==getStatusBarHeight()){ | ||
| 271 | - Log.e(TAG,"setTitleViewAdjustImmersiveStatusBar->无法获取状态栏高度!"); | 445 | + if (0 == getStatusBarHeight()) { |
| 446 | + Log.e(TAG, "setTitleViewAdjustImmersiveStatusBar->无法获取状态栏高度!"); | ||
| 272 | return; | 447 | return; |
| 273 | } | 448 | } |
| 274 | params.height = oldHeight + getStatusBarHeight(); | 449 | params.height = oldHeight + getStatusBarHeight(); |
| 275 | view.setLayoutParams(params); | 450 | view.setLayoutParams(params); |
| 276 | } | 451 | } |
| 452 | + | ||
| 277 | /** | 453 | /** |
| 278 | * 设置状态栏字体颜色 | 454 | * 设置状态栏字体颜色 |
| 279 | */ | 455 | */ |
| 280 | - // 定义适用于参数的注解,限定取值范围为{STATUS_OPEN, STATUS_CLOSE} | 456 | + // 定义适用于参数的注解,限定取值范围为{BLACK, WHITE} |
| 281 | public void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { | 457 | public void setStatusBarTextColor(@StatusBarConfig.Unit final int type) { |
| 282 | if (type == StatusBarConfig.BLACK) { | 458 | if (type == StatusBarConfig.BLACK) { |
| 283 | StatusBarUtil.setStatusBarWrite(this); | 459 | StatusBarUtil.setStatusBarWrite(this); |
| @@ -295,6 +471,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -295,6 +471,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 295 | isCreateDefultEmptyView = enable; | 471 | isCreateDefultEmptyView = enable; |
| 296 | } | 472 | } |
| 297 | 473 | ||
| 474 | + /** | ||
| 475 | + * 初始化handler | ||
| 476 | + * | ||
| 477 | + * @return | ||
| 478 | + */ | ||
| 298 | public Handler getMyActHandler() { | 479 | public Handler getMyActHandler() { |
| 299 | if (null == myActHandler) { | 480 | if (null == myActHandler) { |
| 300 | myActHandler = new Handler() { | 481 | myActHandler = new Handler() { |
| @@ -308,6 +489,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -308,6 +489,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 308 | return myActHandler; | 489 | return myActHandler; |
| 309 | } | 490 | } |
| 310 | 491 | ||
| 492 | + /** | ||
| 493 | + * 收到Activity的handler | ||
| 494 | + * | ||
| 495 | + * @param msg | ||
| 496 | + */ | ||
| 311 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 497 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| 312 | if (null != getMvpView()) { | 498 | if (null != getMvpView()) { |
| 313 | getMvpView().onReceiveActHandleMessage(msg); | 499 | getMvpView().onReceiveActHandleMessage(msg); |
| @@ -337,6 +523,12 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -337,6 +523,12 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 337 | } | 523 | } |
| 338 | } | 524 | } |
| 339 | 525 | ||
| 526 | + /** | ||
| 527 | + * 收到观察者通知 | ||
| 528 | + * | ||
| 529 | + * @param o | ||
| 530 | + * @param data | ||
| 531 | + */ | ||
| 340 | @Override | 532 | @Override |
| 341 | public void update(Observable o, Object data) { | 533 | public void update(Observable o, Object data) { |
| 342 | if (null == getMvpView()) { | 534 | if (null == getMvpView()) { |
| @@ -360,6 +552,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -360,6 +552,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 360 | /** | 552 | /** |
| 361 | * 显示竖屏 | 553 | * 显示竖屏 |
| 362 | */ | 554 | */ |
| 555 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 363 | public void showPortraitScreen() { | 556 | public void showPortraitScreen() { |
| 364 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 557 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 365 | } | 558 | } |
| @@ -367,46 +560,22 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -367,46 +560,22 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 367 | /** | 560 | /** |
| 368 | * 显示横屏 | 561 | * 显示横屏 |
| 369 | */ | 562 | */ |
| 563 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 370 | public void showLandscapeScreen() { | 564 | public void showLandscapeScreen() { |
| 371 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 565 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 372 | } | 566 | } |
| 373 | 567 | ||
| 374 | - protected void init(@Nullable Bundle savedInstanceState) { | ||
| 375 | - } | ||
| 376 | - | ||
| 377 | - protected void initParams(Intent params) { | ||
| 378 | - } | ||
| 379 | 568 | ||
| 380 | /** | 569 | /** |
| 381 | - * 初始化控件 | ||
| 382 | - */ | ||
| 383 | - protected abstract void initView(); | ||
| 384 | - | ||
| 385 | - | ||
| 386 | - /** | ||
| 387 | - * 设置数据 | 570 | + * 是否已经开启侧滑返回 |
| 571 | + * | ||
| 572 | + * @return | ||
| 388 | */ | 573 | */ |
| 389 | - protected void initData() { | ||
| 390 | - } | ||
| 391 | - | ||
| 392 | - protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 393 | - | ||
| 394 | - } | ||
| 395 | - | ||
| 396 | public boolean isOpenSwipBack() { | 574 | public boolean isOpenSwipBack() { |
| 397 | return isOpenSwipBack; | 575 | return isOpenSwipBack; |
| 398 | } | 576 | } |
| 399 | 577 | ||
| 400 | /** | 578 | /** |
| 401 | - * 设置是否显示标题栏 | ||
| 402 | - * | ||
| 403 | - * @param showTitle true or false | ||
| 404 | - */ | ||
| 405 | - public void setShowTitle(boolean showTitle) { | ||
| 406 | - isShowTitle = showTitle; | ||
| 407 | - } | ||
| 408 | - | ||
| 409 | - /** | ||
| 410 | * 设置是否显示状态栏 | 579 | * 设置是否显示状态栏 |
| 411 | * | 580 | * |
| 412 | * @param showStatusBar true or false | 581 | * @param showStatusBar true or false |
| @@ -420,6 +589,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -420,6 +589,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 420 | * 设置屏幕为横屏 | 589 | * 设置屏幕为横屏 |
| 421 | * Set the screen to landscape. | 590 | * Set the screen to landscape. |
| 422 | */ | 591 | */ |
| 592 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 423 | public void setLandscape() { | 593 | public void setLandscape() { |
| 424 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | 594 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 425 | } | 595 | } |
| @@ -428,6 +598,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -428,6 +598,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 428 | * 设置屏幕为竖屏 | 598 | * 设置屏幕为竖屏 |
| 429 | * Set the screen to portrait. | 599 | * Set the screen to portrait. |
| 430 | */ | 600 | */ |
| 601 | + @SuppressLint("SourceLockedOrientationActivity") | ||
| 431 | public void setPortrait() { | 602 | public void setPortrait() { |
| 432 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | 603 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 433 | } | 604 | } |
| @@ -551,9 +722,19 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -551,9 +722,19 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 551 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); | 722 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); |
| 552 | } | 723 | } |
| 553 | 724 | ||
| 725 | + /** | ||
| 726 | + * 获取 SharedPreferencesHelper | ||
| 727 | + */ | ||
| 728 | + protected SharedPreferencesHelper getSP() { | ||
| 729 | + return SharedPreferencesHelper.getInstance(this); | ||
| 730 | + } | ||
| 731 | + | ||
| 554 | @Override | 732 | @Override |
| 555 | protected void onResume() { | 733 | protected void onResume() { |
| 556 | super.onResume(); | 734 | super.onResume(); |
| 735 | + isActive = true; | ||
| 736 | + //创建订阅映射 | ||
| 737 | + RxManager.getInstance().setCurrentDisposables(TAG); | ||
| 557 | if (isUserClickAllowBtn) { | 738 | if (isUserClickAllowBtn) { |
| 558 | isUserClickAllowBtn = false; | 739 | isUserClickAllowBtn = false; |
| 559 | int requestCode = DEFAULT_REQUEST_CODE_PERMISSION; | 740 | int requestCode = DEFAULT_REQUEST_CODE_PERMISSION; |
| @@ -570,6 +751,35 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -570,6 +751,35 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 570 | requestPermission(requestCode, tip, isDefinePermissionCloseActivity, userSetPermission, isShowDialog, onPermissionResponseListener); | 751 | requestPermission(requestCode, tip, isDefinePermissionCloseActivity, userSetPermission, isShowDialog, onPermissionResponseListener); |
| 571 | } | 752 | } |
| 572 | } | 753 | } |
| 754 | + if (lifeCircleListener != null) { | ||
| 755 | + lifeCircleListener.onResume(); | ||
| 756 | + } | ||
| 757 | + if (globalLifeCircleListener != null) { | ||
| 758 | + globalLifeCircleListener.onResume(me, me.getClass().getName()); | ||
| 759 | + } | ||
| 760 | + AppManager.setActiveActivity(this); | ||
| 761 | + } | ||
| 762 | + | ||
| 763 | + | ||
| 764 | + @Override | ||
| 765 | + protected void onPause() { | ||
| 766 | + if (null != getPresenter()) { | ||
| 767 | + getPresenter().onPause(); | ||
| 768 | + } | ||
| 769 | + if (null != getMvpView()) { | ||
| 770 | + getMvpView().onPause(); | ||
| 771 | + } | ||
| 772 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 773 | + pauseDisposable.clear(); | ||
| 774 | + } | ||
| 775 | + isActive = false; | ||
| 776 | + if (lifeCircleListener != null) { | ||
| 777 | + lifeCircleListener.onPause(); | ||
| 778 | + } | ||
| 779 | + if (globalLifeCircleListener != null) { | ||
| 780 | + globalLifeCircleListener.onPause(me, me.getClass().getName()); | ||
| 781 | + } | ||
| 782 | + super.onPause(); | ||
| 573 | } | 783 | } |
| 574 | 784 | ||
| 575 | public void registerEventBus() { | 785 | public void registerEventBus() { |
| @@ -598,31 +808,92 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -598,31 +808,92 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 598 | @Override | 808 | @Override |
| 599 | protected void onDestroy() { | 809 | protected void onDestroy() { |
| 600 | super.onDestroy(); | 810 | super.onDestroy(); |
| 811 | + isAlive = false; | ||
| 601 | //删除观察者 | 812 | //删除观察者 |
| 602 | deleteObservable(); | 813 | deleteObservable(); |
| 603 | mDelegate.onDestroy(); | 814 | mDelegate.onDestroy(); |
| 604 | - if (null != baseBinding) { | ||
| 605 | - baseBinding.unbind(); | ||
| 606 | - } | ||
| 607 | if (null != myActHandler) { | 815 | if (null != myActHandler) { |
| 608 | myActHandler.removeCallbacksAndMessages(null); | 816 | myActHandler.removeCallbacksAndMessages(null); |
| 609 | } | 817 | } |
| 818 | + //清除当前订阅 | ||
| 819 | + RxManager.getInstance().cancel(TAG); | ||
| 820 | + //取消Rxjava订阅 | ||
| 821 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 822 | + destoryDisposable.clear(); | ||
| 823 | + } | ||
| 610 | unRegisterEventBus(); | 824 | unRegisterEventBus(); |
| 611 | onPermissionResponseListener = null; | 825 | onPermissionResponseListener = null; |
| 612 | userSetPermission = null; | 826 | userSetPermission = null; |
| 613 | userSetDefinePermissionTip = null; | 827 | userSetDefinePermissionTip = null; |
| 614 | - //activity管理 | ||
| 615 | - AppManager.getInstance().deleteActivity(me); | ||
| 616 | - //清除当前订阅 | ||
| 617 | - SubscriptionManager.getInstance().cancel(TAG); | 828 | + if (null != baseBinding) { |
| 829 | + baseBinding.unbind(); | ||
| 830 | + } | ||
| 618 | if (null != getPresenter()) { | 831 | if (null != getPresenter()) { |
| 619 | - getPresenter().onDestory(); | 832 | + getPresenter().onDestroy(); |
| 620 | } | 833 | } |
| 621 | if (null != getMvpView()) { | 834 | if (null != getMvpView()) { |
| 622 | getMvpView().onDestory(); | 835 | getMvpView().onDestory(); |
| 623 | } | 836 | } |
| 837 | + //activity管理 | ||
| 838 | + AppManager.getInstance().deleteActivity(me); | ||
| 839 | + if (lifeCircleListener != null) { | ||
| 840 | + lifeCircleListener.onDestroy(); | ||
| 841 | + } | ||
| 842 | + if (globalLifeCircleListener != null) { | ||
| 843 | + globalLifeCircleListener.onDestroy(me, me.getClass().getName()); | ||
| 844 | + } | ||
| 845 | + | ||
| 624 | } | 846 | } |
| 625 | 847 | ||
| 848 | + public void setLifeCircleListener(LifeCircleListener lifeCircleListener) { | ||
| 849 | + this.lifeCircleListener = lifeCircleListener; | ||
| 850 | + } | ||
| 851 | + | ||
| 852 | + public static GlobalLifeCircleListener getGlobalLifeCircleListener() { | ||
| 853 | + return globalLifeCircleListener; | ||
| 854 | + } | ||
| 855 | + | ||
| 856 | + public static void setGlobalLifeCircleListener(GlobalLifeCircleListener globalLifeCircleListener) { | ||
| 857 | + BaseActivity.globalLifeCircleListener = globalLifeCircleListener; | ||
| 858 | + } | ||
| 859 | + | ||
| 860 | + | ||
| 861 | + public void runOnMain(Runnable runnable) { | ||
| 862 | + runOnUiThread(new Runnable() { | ||
| 863 | + @Override | ||
| 864 | + public void run() { | ||
| 865 | + if (isAlive) { | ||
| 866 | + runnable.run(); | ||
| 867 | + } | ||
| 868 | + } | ||
| 869 | + }); | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + public void runOnMainDelayed(Runnable runnable, long time) { | ||
| 873 | + getMyActHandler().postDelayed(new Runnable() { | ||
| 874 | + @Override | ||
| 875 | + public void run() { | ||
| 876 | + runOnMain(runnable); | ||
| 877 | + } | ||
| 878 | + }, time); | ||
| 879 | + } | ||
| 880 | + | ||
| 881 | + public void runDelayed(Runnable runnable, long time) { | ||
| 882 | + getMyActHandler().postDelayed(new Runnable() { | ||
| 883 | + @Override | ||
| 884 | + public void run() { | ||
| 885 | + runnable.run(); | ||
| 886 | + } | ||
| 887 | + }, time); | ||
| 888 | + } | ||
| 889 | + | ||
| 890 | + @Override | ||
| 891 | + public void onWindowFocusChanged(boolean hasFocus) { | ||
| 892 | + super.onWindowFocusChanged(hasFocus); | ||
| 893 | + if (globalLifeCircleListener != null) { | ||
| 894 | + globalLifeCircleListener.windowFocus(me, me.getClass().getName(), hasFocus); | ||
| 895 | + } | ||
| 896 | + } | ||
| 626 | 897 | ||
| 627 | @NonNull | 898 | @NonNull |
| 628 | public final V createView() { | 899 | public final V createView() { |
| @@ -689,19 +960,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -689,19 +960,11 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 689 | /** | 960 | /** |
| 690 | * 判空 | 961 | * 判空 |
| 691 | * | 962 | * |
| 692 | - * @param o | 963 | + * @param os |
| 693 | * @return | 964 | * @return |
| 694 | */ | 965 | */ |
| 695 | - public boolean isNull(Object o) { | ||
| 696 | - if (o instanceof String) { | ||
| 697 | - String s = (String) o; | ||
| 698 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 699 | - return true; | ||
| 700 | - } | ||
| 701 | - } else if (null == o) { | ||
| 702 | - return true; | ||
| 703 | - } | ||
| 704 | - return false; | 966 | + public boolean isNull(Object... os) { |
| 967 | + return BaseHelpUtil.isNull(os); | ||
| 705 | } | 968 | } |
| 706 | 969 | ||
| 707 | @Override | 970 | @Override |
| @@ -1286,27 +1549,55 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1286,27 +1549,55 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1286 | } else { | 1549 | } else { |
| 1287 | tip = userSetDefinePermissionTip; | 1550 | tip = userSetDefinePermissionTip; |
| 1288 | } | 1551 | } |
| 1289 | - new AlertDialog.Builder(this) | ||
| 1290 | - .setTitle("温馨提示") | ||
| 1291 | - .setMessage(tip) | ||
| 1292 | - .setCancelable(false) | ||
| 1293 | - .setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1294 | - @Override | ||
| 1295 | - public void onClick(DialogInterface dialog, int which) { | ||
| 1296 | - if (isDefinePermissionCloseActivity) { | ||
| 1297 | - finish(); | ||
| 1298 | - } | ||
| 1299 | - resetPermissionConfig(); | ||
| 1300 | - } | ||
| 1301 | - }) | ||
| 1302 | - .setPositiveButton("去设置", new DialogInterface.OnClickListener() { | ||
| 1303 | - @Override | ||
| 1304 | - public void onClick(DialogInterface dialog, int which) { | ||
| 1305 | - dialog.dismiss(); | ||
| 1306 | - startAppSettings(); | ||
| 1307 | - isUserClickAllowBtn = true; | 1552 | +// new AlertDialog.Builder(this) |
| 1553 | +// .setTitle("温馨提示") | ||
| 1554 | +// .setMessage(tip) | ||
| 1555 | +// .setCancelable(false) | ||
| 1556 | +// .setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1557 | +// @Override | ||
| 1558 | +// public void onClick(DialogInterface dialog, int which) { | ||
| 1559 | +// if (isDefinePermissionCloseActivity) { | ||
| 1560 | +// finish(); | ||
| 1561 | +// } | ||
| 1562 | +// resetPermissionConfig(); | ||
| 1563 | +// } | ||
| 1564 | +// }) | ||
| 1565 | +// .setPositiveButton("去设置", new DialogInterface.OnClickListener() { | ||
| 1566 | +// @Override | ||
| 1567 | +// public void onClick(DialogInterface dialog, int which) { | ||
| 1568 | +// dialog.dismiss(); | ||
| 1569 | +// startAppSettings(); | ||
| 1570 | +// isUserClickAllowBtn = true; | ||
| 1571 | +// } | ||
| 1572 | +// }).show(); | ||
| 1573 | + if (null == permissionTipDialog) { | ||
| 1574 | + permissionTipDialog = new SelectDialog(me, tip, "取消", new SelectDialog.DialogInterface() { | ||
| 1575 | + @Override | ||
| 1576 | + public void onClick(SelectDialog dialog) { | ||
| 1577 | + dialog.dismiss(); | ||
| 1578 | + if (isDefinePermissionCloseActivity) { | ||
| 1579 | + finish(); | ||
| 1308 | } | 1580 | } |
| 1309 | - }).show(); | 1581 | + resetPermissionConfig(); |
| 1582 | + } | ||
| 1583 | + }, "去设置", new SelectDialog.DialogInterface() { | ||
| 1584 | + @Override | ||
| 1585 | + public void onClick(SelectDialog dialog) { | ||
| 1586 | + dialog.dismiss(); | ||
| 1587 | + startAppSettings(); | ||
| 1588 | + isUserClickAllowBtn = true; | ||
| 1589 | + } | ||
| 1590 | + }); | ||
| 1591 | + permissionTipDialog.setCanceledOnTouchOutside(false); | ||
| 1592 | + permissionTipDialog.setCancelable(false); | ||
| 1593 | + permissionTipDialog.setTipGravity(Gravity.LEFT); | ||
| 1594 | + permissionTipDialog.setLeftBtnColor(R.color.color_282828); | ||
| 1595 | + } else { | ||
| 1596 | + permissionTipDialog.setTipMessage(tip); | ||
| 1597 | + } | ||
| 1598 | + if (!permissionTipDialog.isShowing()) { | ||
| 1599 | + permissionTipDialog.show(); | ||
| 1600 | + } | ||
| 1310 | } | 1601 | } |
| 1311 | 1602 | ||
| 1312 | 1603 | ||
| @@ -1474,6 +1765,10 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1474,6 +1765,10 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1474 | mDelegate.loadRootFragment(R.id.root_container, toFragment, allowAnimation); | 1765 | mDelegate.loadRootFragment(R.id.root_container, toFragment, allowAnimation); |
| 1475 | } | 1766 | } |
| 1476 | 1767 | ||
| 1768 | + public final void loadRootFragment(ISupportFragment toFragment, boolean addToBackStack, boolean allowAnimation) { | ||
| 1769 | + mDelegate.loadRootFragment(R.id.root_container, toFragment, addToBackStack, allowAnimation); | ||
| 1770 | + } | ||
| 1771 | + | ||
| 1477 | /** | 1772 | /** |
| 1478 | * 加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment | 1773 | * 加载根Fragment, 即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment |
| 1479 | * | 1774 | * |
| @@ -1644,7 +1939,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | @@ -1644,7 +1939,7 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V | ||
| 1644 | Fragmentation.builder() | 1939 | Fragmentation.builder() |
| 1645 | // show stack view. Mode: BUBBLE, SHAKE, NONE | 1940 | // show stack view. Mode: BUBBLE, SHAKE, NONE |
| 1646 | .stackViewMode(Fragmentation.BUBBLE) | 1941 | .stackViewMode(Fragmentation.BUBBLE) |
| 1647 | - .debug(AppConfig.isDebug()) | 1942 | + .debug(BuildConfig.DEBUG) |
| 1648 | .install(); | 1943 | .install(); |
| 1649 | } | 1944 | } |
| 1650 | /***********************************滑动返回********************************************/ | 1945 | /***********************************滑动返回********************************************/ |
core/base/src/main/java/com/cnlive/core/libs/base/frame/fragment/BaseFragment.java
| @@ -2,6 +2,7 @@ package com.cnlive.core.libs.base.frame.fragment; | @@ -2,6 +2,7 @@ package com.cnlive.core.libs.base.frame.fragment; | ||
| 2 | 2 | ||
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | +import android.graphics.drawable.Drawable; | ||
| 5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
| 6 | import android.os.Handler; | 7 | import android.os.Handler; |
| 7 | import android.os.Message; | 8 | import android.os.Message; |
| @@ -10,8 +11,8 @@ import android.view.View; | @@ -10,8 +11,8 @@ import android.view.View; | ||
| 10 | import android.view.ViewGroup; | 11 | import android.view.ViewGroup; |
| 11 | import android.view.animation.Animation; | 12 | import android.view.animation.Animation; |
| 12 | 13 | ||
| 13 | -import androidx.annotation.ColorInt; | ||
| 14 | import androidx.annotation.ColorRes; | 14 | import androidx.annotation.ColorRes; |
| 15 | +import androidx.annotation.DrawableRes; | ||
| 15 | import androidx.annotation.FloatRange; | 16 | import androidx.annotation.FloatRange; |
| 16 | import androidx.annotation.IntRange; | 17 | import androidx.annotation.IntRange; |
| 17 | import androidx.annotation.NonNull; | 18 | import androidx.annotation.NonNull; |
| @@ -20,16 +21,20 @@ import androidx.annotation.StringRes; | @@ -20,16 +21,20 @@ import androidx.annotation.StringRes; | ||
| 20 | import androidx.databinding.DataBindingUtil; | 21 | import androidx.databinding.DataBindingUtil; |
| 21 | import androidx.databinding.ViewDataBinding; | 22 | import androidx.databinding.ViewDataBinding; |
| 22 | 23 | ||
| 24 | +import com.alibaba.android.arouter.facade.Postcard; | ||
| 25 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 23 | import com.alibaba.android.arouter.launcher.ARouter; | 26 | import com.alibaba.android.arouter.launcher.ARouter; |
| 27 | +import com.cnlive.cloud.base.R; | ||
| 24 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 28 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 25 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | 29 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 30 | +import com.cnlive.core.libs.base.frame.view.BaseView; | ||
| 26 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | 31 | import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; |
| 27 | -import com.cnlive.core.libs.base.network.manager.SubscriptionManager; | 32 | +import com.cnlive.core.libs.base.network.manager.RxManager; |
| 33 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 34 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 35 | +import com.cnlive.core.libs.base.util.LifeCircleListener; | ||
| 28 | import com.cnlive.core.libs.base.util.ReflectUtil; | 36 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 29 | -import com.cnlive.core.libs.base.frame.view.BaseView; | ||
| 30 | import com.cnlive.core.libs.base.util.StatusBarConfig; | 37 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| 31 | -import com.cnlive.cloud.base.R; | ||
| 32 | -import com.cnlive.core.libs.base.util.StatusBarUtil; | ||
| 33 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 38 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 34 | import com.me.yokeyword.fragmentation.ExtraTransaction; | 39 | import com.me.yokeyword.fragmentation.ExtraTransaction; |
| 35 | import com.me.yokeyword.fragmentation.ISupportFragment; | 40 | import com.me.yokeyword.fragmentation.ISupportFragment; |
| @@ -48,6 +53,9 @@ import java.util.List; | @@ -48,6 +53,9 @@ import java.util.List; | ||
| 48 | import java.util.Observable; | 53 | import java.util.Observable; |
| 49 | import java.util.Observer; | 54 | import java.util.Observer; |
| 50 | 55 | ||
| 56 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 57 | +import io.reactivex.disposables.Disposable; | ||
| 58 | + | ||
| 51 | /** | 59 | /** |
| 52 | * 基类fragment | 60 | * 基类fragment |
| 53 | * | 61 | * |
| @@ -69,6 +77,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -69,6 +77,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 69 | private List<Observable> observableList; | 77 | private List<Observable> observableList; |
| 70 | private Bundle savedInstanceState; | 78 | private Bundle savedInstanceState; |
| 71 | private boolean isCreateDefultEmptyView = true;//默认显示空视图 | 79 | private boolean isCreateDefultEmptyView = true;//默认显示空视图 |
| 80 | + public boolean isActive = false;//当前Fragment是否活跃 | ||
| 81 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 82 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 快速管理生命周期 | ||
| 86 | + */ | ||
| 87 | + private LifeCircleListener lifeCircleListener; | ||
| 72 | 88 | ||
| 73 | public final ViewDataBinding getBaseBinding() { | 89 | public final ViewDataBinding getBaseBinding() { |
| 74 | return baseBinding; | 90 | return baseBinding; |
| @@ -86,9 +102,9 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -86,9 +102,9 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 86 | if (null == observableList) { | 102 | if (null == observableList) { |
| 87 | observableList = new ArrayList<>(); | 103 | observableList = new ArrayList<>(); |
| 88 | } | 104 | } |
| 105 | + //初始化rxjava管理 | ||
| 106 | + initRxjava(); | ||
| 89 | this.savedInstanceState = savedInstanceState; | 107 | this.savedInstanceState = savedInstanceState; |
| 90 | - //创建订阅映射 | ||
| 91 | - SubscriptionManager.getInstance().setCurrentDisposables(TAG); | ||
| 92 | mDelegate.onCreate(savedInstanceState); | 108 | mDelegate.onCreate(savedInstanceState); |
| 93 | mSwipeDelegate.onCreate(savedInstanceState); | 109 | mSwipeDelegate.onCreate(savedInstanceState); |
| 94 | setSwipeBackEnable(me.isOpenSwipBack()); | 110 | setSwipeBackEnable(me.isOpenSwipBack()); |
| @@ -97,6 +113,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -97,6 +113,14 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 97 | if (null != getArguments()) { | 113 | if (null != getArguments()) { |
| 98 | initParams(getArguments()); | 114 | initParams(getArguments()); |
| 99 | } | 115 | } |
| 116 | + if (lifeCircleListener != null) { | ||
| 117 | + lifeCircleListener.onCreate(); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + private void initRxjava() { | ||
| 122 | + pauseDisposable = new CompositeDisposable(); | ||
| 123 | + destoryDisposable = new CompositeDisposable(); | ||
| 100 | } | 124 | } |
| 101 | 125 | ||
| 102 | @Nullable | 126 | @Nullable |
| @@ -128,15 +152,115 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -128,15 +152,115 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 128 | } | 152 | } |
| 129 | } | 153 | } |
| 130 | } | 154 | } |
| 155 | + | ||
| 131 | return super.onCreateView(inflater, container, savedInstanceState); | 156 | return super.onCreateView(inflater, container, savedInstanceState); |
| 132 | } | 157 | } |
| 133 | 158 | ||
| 159 | + public void setLifeCircleListener(LifeCircleListener lifeCircleListener) { | ||
| 160 | + this.lifeCircleListener = lifeCircleListener; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 添加订阅 | ||
| 165 | + * Pause 销毁 | ||
| 166 | + * | ||
| 167 | + * @param disposable | ||
| 168 | + * @return | ||
| 169 | + */ | ||
| 170 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 171 | + if (null != disposable) { | ||
| 172 | + if (null != pauseDisposable) { | ||
| 173 | + pauseDisposable.add(disposable); | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + return disposable; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 添加订阅 | ||
| 181 | + * Destory 销毁 | ||
| 182 | + * | ||
| 183 | + * @param disposable | ||
| 184 | + * @return | ||
| 185 | + */ | ||
| 186 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 187 | + if (null != disposable) { | ||
| 188 | + if (null != destoryDisposable) { | ||
| 189 | + destoryDisposable.add(disposable); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + return disposable; | ||
| 193 | + } | ||
| 134 | 194 | ||
| 135 | - public boolean isNull(Object o) { | 195 | + /** |
| 196 | + * 获取资源颜色 | ||
| 197 | + * | ||
| 198 | + * @param colorId | ||
| 199 | + * @return | ||
| 200 | + */ | ||
| 201 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 202 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * 获取资源字符串 | ||
| 207 | + * | ||
| 208 | + * @param stringId | ||
| 209 | + * @return | ||
| 210 | + */ | ||
| 211 | + public String getResourceStr(@StringRes int stringId) { | ||
| 212 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * 获取资源 | ||
| 217 | + * | ||
| 218 | + * @param drawableId | ||
| 219 | + * @return | ||
| 220 | + */ | ||
| 221 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 222 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 用户提示 | ||
| 227 | + */ | ||
| 228 | + public void showToast(String message) { | ||
| 229 | + AlertUtil.showDeftToast(me, message); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public boolean isNull(Object... o) { | ||
| 136 | return me.isNull(o); | 233 | return me.isNull(o); |
| 137 | } | 234 | } |
| 138 | 235 | ||
| 139 | /** | 236 | /** |
| 237 | + * 实例化路由-对象 | ||
| 238 | + */ | ||
| 239 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 240 | + return (T) me.initRouterImpl(routerPath); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 244 | + * Arouter跳转 | ||
| 245 | + * | ||
| 246 | + * @param routerPath | ||
| 247 | + * @return | ||
| 248 | + */ | ||
| 249 | + public Postcard goToRouter(String routerPath) { | ||
| 250 | + return ARouter.getInstance().build(routerPath); | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + /** | ||
| 254 | + * Arouter跳转无参数 | ||
| 255 | + * | ||
| 256 | + * @param routerPath | ||
| 257 | + * @return | ||
| 258 | + */ | ||
| 259 | + public void goToRouterNoParams(String routerPath) { | ||
| 260 | + ARouter.getInstance().build(routerPath).navigation(me); | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + /** | ||
| 140 | * 显示白色通知栏 | 264 | * 显示白色通知栏 |
| 141 | */ | 265 | */ |
| 142 | public void showDefaultWhiteStatusBar() { | 266 | public void showDefaultWhiteStatusBar() { |
| @@ -166,9 +290,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -166,9 +290,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 166 | if (null != getMvpView() && null != getPresenter()) { | 290 | if (null != getMvpView() && null != getPresenter()) { |
| 167 | if (null != baseBinding) { | 291 | if (null != baseBinding) { |
| 168 | initBindingLayoutData(baseBinding); | 292 | initBindingLayoutData(baseBinding); |
| 293 | + if (isViewAttached() && !isNull(me)) { | ||
| 294 | + getMvpView().initFragBindingLayout(me, this, baseBinding); | ||
| 295 | + } | ||
| 169 | } | 296 | } |
| 170 | if (null != baseView) { | 297 | if (null != baseView) { |
| 171 | initViewLayoutData(baseView); | 298 | initViewLayoutData(baseView); |
| 299 | + if (isViewAttached() && !isNull(me)) { | ||
| 300 | + getMvpView().initFragViewLayout(me, this, baseView); | ||
| 301 | + } | ||
| 172 | } | 302 | } |
| 173 | initView(); | 303 | initView(); |
| 174 | initData(); | 304 | initData(); |
| @@ -276,6 +406,11 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -276,6 +406,11 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 276 | EventBus.getDefault().postSticky(object); | 406 | EventBus.getDefault().postSticky(object); |
| 277 | } | 407 | } |
| 278 | 408 | ||
| 409 | + /** | ||
| 410 | + * 初始化fragment的handler | ||
| 411 | + * | ||
| 412 | + * @return | ||
| 413 | + */ | ||
| 279 | public Handler getMyFragHandler() { | 414 | public Handler getMyFragHandler() { |
| 280 | if (null == myFragHandler) { | 415 | if (null == myFragHandler) { |
| 281 | myFragHandler = new Handler() { | 416 | myFragHandler = new Handler() { |
| @@ -289,12 +424,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -289,12 +424,22 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 289 | return myFragHandler; | 424 | return myFragHandler; |
| 290 | } | 425 | } |
| 291 | 426 | ||
| 427 | + /** | ||
| 428 | + * 收到fragment对应的Activity的handler | ||
| 429 | + * | ||
| 430 | + * @param msg | ||
| 431 | + */ | ||
| 292 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 432 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| 293 | if (null != getMvpView()) { | 433 | if (null != getMvpView()) { |
| 294 | getMvpView().onReceiveActHandleMessage(msg); | 434 | getMvpView().onReceiveActHandleMessage(msg); |
| 295 | } | 435 | } |
| 296 | } | 436 | } |
| 297 | 437 | ||
| 438 | + /** | ||
| 439 | + * 收到当前fragment的handler | ||
| 440 | + * | ||
| 441 | + * @param msg | ||
| 442 | + */ | ||
| 298 | public void onReceiveFragHandleMessage(@NonNull Message msg) { | 443 | public void onReceiveFragHandleMessage(@NonNull Message msg) { |
| 299 | if (null != getMvpView()) { | 444 | if (null != getMvpView()) { |
| 300 | getMvpView().onReceiveFragHandleMessage(msg); | 445 | getMvpView().onReceiveFragHandleMessage(msg); |
| @@ -417,6 +562,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -417,6 +562,15 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 417 | } | 562 | } |
| 418 | 563 | ||
| 419 | /** | 564 | /** |
| 565 | + * 获取状态栏高度dp | ||
| 566 | + * | ||
| 567 | + * @return | ||
| 568 | + */ | ||
| 569 | + public int getStatusBarHeight() { | ||
| 570 | + return me.getStatusBarHeight(); | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + /** | ||
| 420 | * 将标题视图自适应沉浸式状态栏 | 574 | * 将标题视图自适应沉浸式状态栏 |
| 421 | * | 575 | * |
| 422 | * @param view | 576 | * @param view |
| @@ -426,37 +580,63 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -426,37 +580,63 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 426 | } | 580 | } |
| 427 | 581 | ||
| 428 | /** | 582 | /** |
| 429 | - * 获取状态栏高度 | ||
| 430 | - * | ||
| 431 | - * @return | 583 | + * 销毁 Rx Dispose |
| 432 | */ | 584 | */ |
| 433 | - public int getStatusBarHeight() { | ||
| 434 | - return me.getStatusBarHeight(); | 585 | + public void disposeRxEvent(Disposable... disposables) { |
| 586 | + if (disposables == null) return; | ||
| 587 | + for (Disposable disposable : disposables) if (disposable != null) disposable.dispose(); | ||
| 588 | + } | ||
| 589 | + | ||
| 590 | + @Override | ||
| 591 | + public void onDestroyView() { | ||
| 592 | + mDelegate.onDestroyView(); | ||
| 593 | + super.onDestroyView(); | ||
| 594 | + deleteObservable(); | ||
| 595 | + if (null != myFragHandler) { | ||
| 596 | + myFragHandler.removeCallbacksAndMessages(null); | ||
| 597 | + } | ||
| 598 | + unRegisterEventBus(); | ||
| 599 | + //清除当前订阅 | ||
| 600 | + RxManager.getInstance().cancel(TAG); | ||
| 601 | + if (null != getMvpView()) { | ||
| 602 | + getMvpView().onDestory(); | ||
| 603 | + } | ||
| 604 | + if (null != getPresenter()) { | ||
| 605 | + getPresenter().onDestroy(); | ||
| 606 | + } | ||
| 435 | } | 607 | } |
| 436 | 608 | ||
| 437 | @Override | 609 | @Override |
| 438 | public void onDestroy() { | 610 | public void onDestroy() { |
| 439 | super.onDestroy(); | 611 | super.onDestroy(); |
| 440 | deleteObservable(); | 612 | deleteObservable(); |
| 441 | - if (null != baseBinding) { | ||
| 442 | - baseBinding.unbind(); | 613 | + unRegisterEventBus(); |
| 614 | + //清除当前订阅 | ||
| 615 | + RxManager.getInstance().cancel(TAG); | ||
| 616 | + //取消Rxjava订阅 | ||
| 617 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 618 | + destoryDisposable.clear(); | ||
| 443 | } | 619 | } |
| 444 | if (null != myFragHandler) { | 620 | if (null != myFragHandler) { |
| 445 | myFragHandler.removeCallbacksAndMessages(null); | 621 | myFragHandler.removeCallbacksAndMessages(null); |
| 446 | } | 622 | } |
| 447 | - unRegisterEventBus(); | 623 | + if (null != baseBinding) { |
| 624 | + baseBinding.unbind(); | ||
| 625 | + } | ||
| 448 | mDelegate.onDestroy(); | 626 | mDelegate.onDestroy(); |
| 449 | mSwipeDelegate.onDestroyView(); | 627 | mSwipeDelegate.onDestroyView(); |
| 450 | - //清除当前订阅 | ||
| 451 | - SubscriptionManager.getInstance().cancel(TAG); | ||
| 452 | if (null != getPresenter()) { | 628 | if (null != getPresenter()) { |
| 453 | - getPresenter().onDestory(); | 629 | + getPresenter().onDestroy(); |
| 454 | } | 630 | } |
| 455 | if (null != getMvpView()) { | 631 | if (null != getMvpView()) { |
| 456 | getMvpView().onDestory(); | 632 | getMvpView().onDestory(); |
| 457 | } | 633 | } |
| 634 | + if (lifeCircleListener != null) { | ||
| 635 | + lifeCircleListener.onDestroy(); | ||
| 636 | + } | ||
| 458 | } | 637 | } |
| 459 | 638 | ||
| 639 | + | ||
| 460 | /** | 640 | /** |
| 461 | * 设置状态栏字体颜色 | 641 | * 设置状态栏字体颜色 |
| 462 | */ | 642 | */ |
| @@ -674,34 +854,37 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -674,34 +854,37 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 674 | @Override | 854 | @Override |
| 675 | public void onResume() { | 855 | public void onResume() { |
| 676 | super.onResume(); | 856 | super.onResume(); |
| 857 | + //创建订阅映射 | ||
| 858 | + RxManager.getInstance().setCurrentDisposables(TAG); | ||
| 677 | mDelegate.onResume(); | 859 | mDelegate.onResume(); |
| 678 | - } | 860 | + isActive = true; |
| 861 | + if (lifeCircleListener != null) { | ||
| 862 | + lifeCircleListener.onResume(); | ||
| 863 | + } | ||
| 679 | 864 | ||
| 680 | - @Override | ||
| 681 | - public void onPause() { | ||
| 682 | - super.onPause(); | ||
| 683 | - mDelegate.onPause(); | ||
| 684 | } | 865 | } |
| 685 | 866 | ||
| 686 | @Override | 867 | @Override |
| 687 | - public void onDestroyView() { | ||
| 688 | - mDelegate.onDestroyView(); | ||
| 689 | - super.onDestroyView(); | ||
| 690 | - deleteObservable(); | ||
| 691 | - if (null != myFragHandler) { | ||
| 692 | - myFragHandler.removeCallbacksAndMessages(null); | 868 | + public void onPause() { |
| 869 | + if (null != getPresenter()) { | ||
| 870 | + getPresenter().onPause(); | ||
| 693 | } | 871 | } |
| 694 | - unRegisterEventBus(); | ||
| 695 | - //清除当前订阅 | ||
| 696 | - SubscriptionManager.getInstance().cancel(TAG); | ||
| 697 | if (null != getMvpView()) { | 872 | if (null != getMvpView()) { |
| 698 | - getMvpView().onDestory(); | 873 | + getMvpView().onPause(); |
| 699 | } | 874 | } |
| 700 | - if (null != getPresenter()) { | ||
| 701 | - getPresenter().onDestory(); | 875 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { |
| 876 | + pauseDisposable.clear(); | ||
| 702 | } | 877 | } |
| 878 | + isActive = false; | ||
| 879 | + if (lifeCircleListener != null) { | ||
| 880 | + lifeCircleListener.onPause(); | ||
| 881 | + } | ||
| 882 | + | ||
| 883 | + super.onPause(); | ||
| 884 | + mDelegate.onPause(); | ||
| 703 | } | 885 | } |
| 704 | 886 | ||
| 887 | + | ||
| 705 | @Override | 888 | @Override |
| 706 | public void onHiddenChanged(boolean hidden) { | 889 | public void onHiddenChanged(boolean hidden) { |
| 707 | super.onHiddenChanged(hidden); | 890 | super.onHiddenChanged(hidden); |
| @@ -1131,4 +1314,16 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | @@ -1131,4 +1314,16 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V | ||
| 1131 | public void setParallaxOffset(@FloatRange(from = 0.0f, to = 1.0f) float offset) { | 1314 | public void setParallaxOffset(@FloatRange(from = 0.0f, to = 1.0f) float offset) { |
| 1132 | mSwipeDelegate.setParallaxOffset(offset); | 1315 | mSwipeDelegate.setParallaxOffset(offset); |
| 1133 | } | 1316 | } |
| 1317 | + | ||
| 1318 | + /** | ||
| 1319 | + * 设置底层view是否可点击 | ||
| 1320 | + * fragment根布局是否可点击,多用于多个fragment叠加在一个activity,是否可点击下层的fragment,默认是false可以点击下层的 | ||
| 1321 | + * | ||
| 1322 | + * @param isEnable | ||
| 1323 | + */ | ||
| 1324 | + public void setFragmentRootViewCanClickable(boolean isEnable) { | ||
| 1325 | + if (null != mDelegate) { | ||
| 1326 | + mDelegate.setFragmentRootViewCanClickable(isEnable); | ||
| 1327 | + } | ||
| 1328 | + } | ||
| 1134 | } | 1329 | } |
core/base/src/main/java/com/cnlive/core/libs/base/frame/presenter/BasePresenter.java
| 1 | package com.cnlive.core.libs.base.frame.presenter; | 1 | package com.cnlive.core.libs.base.frame.presenter; |
| 2 | 2 | ||
| 3 | +import android.app.Dialog; | ||
| 4 | +import android.content.Context; | ||
| 5 | + | ||
| 6 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 7 | +import com.alibaba.android.arouter.launcher.ARouter; | ||
| 3 | import com.cnlive.core.libs.base.frame.view.BaseView; | 8 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 9 | +import com.cnlive.core.libs.base.network.manager.RxManager; | ||
| 10 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 11 | +import com.cnlive.core.libs.base.util.SharedPreferencesHelper; | ||
| 4 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | 12 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 5 | import com.orhanobut.logger.Logger; | 13 | import com.orhanobut.logger.Logger; |
| 6 | 14 | ||
| 7 | import org.greenrobot.eventbus.EventBus; | 15 | import org.greenrobot.eventbus.EventBus; |
| 8 | 16 | ||
| 17 | +import java.util.UUID; | ||
| 18 | + | ||
| 19 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 20 | +import io.reactivex.disposables.Disposable; | ||
| 21 | + | ||
| 9 | /** | 22 | /** |
| 10 | * @param <V> | 23 | * @param <V> |
| 11 | */ | 24 | */ |
| @@ -20,21 +33,98 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | @@ -20,21 +33,98 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | ||
| 20 | EventBus.getDefault().postSticky(object); | 33 | EventBus.getDefault().postSticky(object); |
| 21 | } | 34 | } |
| 22 | 35 | ||
| 23 | - public boolean isNull(Object o) { | ||
| 24 | - if (o instanceof String) { | ||
| 25 | - String s = (String) o; | ||
| 26 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 27 | - return true; | 36 | + //用于自动取消rxjava |
| 37 | + public final String FLAG = UUID.randomUUID().toString().replaceAll("-", ""); | ||
| 38 | + | ||
| 39 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 40 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 41 | + | ||
| 42 | + public BasePresenter() { | ||
| 43 | + //创建订阅映射 | ||
| 44 | + RxManager.getInstance().setCurrentDisposables(FLAG); | ||
| 45 | + initRxjava(); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private void initRxjava() { | ||
| 49 | + pauseDisposable = new CompositeDisposable(); | ||
| 50 | + destoryDisposable = new CompositeDisposable(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 添加订阅 | ||
| 55 | + * Pause 销毁 | ||
| 56 | + * | ||
| 57 | + * @param disposable | ||
| 58 | + * @return | ||
| 59 | + */ | ||
| 60 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 61 | + if (null != disposable) { | ||
| 62 | + if (null != pauseDisposable) { | ||
| 63 | + pauseDisposable.add(disposable); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + return disposable; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 添加订阅 | ||
| 71 | + * Destory 销毁 | ||
| 72 | + * | ||
| 73 | + * @param disposable | ||
| 74 | + * @return | ||
| 75 | + */ | ||
| 76 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 77 | + if (null != disposable) { | ||
| 78 | + if (null != destoryDisposable) { | ||
| 79 | + destoryDisposable.add(disposable); | ||
| 28 | } | 80 | } |
| 29 | - } else if (null == o) { | ||
| 30 | - return true; | ||
| 31 | } | 81 | } |
| 32 | - return false; | 82 | + return disposable; |
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 实例化路由-对象 | ||
| 87 | + */ | ||
| 88 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 89 | + T obj = null; | ||
| 90 | + try { | ||
| 91 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(); | ||
| 92 | + } catch (Exception ignored) { | ||
| 93 | + } | ||
| 94 | + return obj; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 销毁 Rx Dispose | ||
| 99 | + */ | ||
| 100 | + protected void disposeRxEvent(Disposable... disposables) { | ||
| 101 | + if (disposables == null) return; | ||
| 102 | + for (Disposable disposable : disposables) { | ||
| 103 | + if (disposable == null) continue; | ||
| 104 | + if (disposable.isDisposed()) continue; | ||
| 105 | + | ||
| 106 | + disposable.dispose(); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 销毁 Dialog | ||
| 112 | + */ | ||
| 113 | + protected void disposeDialog(Dialog... dialogs) { | ||
| 114 | + if (dialogs == null) return; | ||
| 115 | + for (Dialog dialog : dialogs) if (dialog != null) dialog.dismiss(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 获取 SharedPreferencesHelper | ||
| 120 | + */ | ||
| 121 | + protected SharedPreferencesHelper getSP(Context context) { | ||
| 122 | + return SharedPreferencesHelper.getInstance(context); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public boolean isNull(Object... os) { | ||
| 126 | + return BaseHelpUtil.isNull(os); | ||
| 33 | } | 127 | } |
| 34 | - // @Override | ||
| 35 | -// public V getView() { | ||
| 36 | -// return super.getView(); | ||
| 37 | -// } | ||
| 38 | 128 | ||
| 39 | public void logError(String info) { | 129 | public void logError(String info) { |
| 40 | Logger.e(info); | 130 | Logger.e(info); |
| @@ -64,7 +154,22 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | @@ -64,7 +154,22 @@ public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { | ||
| 64 | Logger.xml(xml); | 154 | Logger.xml(xml); |
| 65 | } | 155 | } |
| 66 | 156 | ||
| 67 | - public void onDestory(){}; | 157 | + |
| 158 | + public void onPause() { | ||
| 159 | + //取消订阅 | ||
| 160 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 161 | + pauseDisposable.clear(); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public void onDestroy() { | ||
| 166 | + //取消订阅 | ||
| 167 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 168 | + destoryDisposable.clear(); | ||
| 169 | + } | ||
| 170 | + //创建订阅映射 | ||
| 171 | + RxManager.getInstance().cancel(FLAG); | ||
| 172 | + } | ||
| 68 | 173 | ||
| 69 | @Override | 174 | @Override |
| 70 | public boolean isViewAttached() { | 175 | public boolean isViewAttached() { |
core/base/src/main/java/com/cnlive/core/libs/base/frame/view/BaseView.java
| 1 | package com.cnlive.core.libs.base.frame.view; | 1 | package com.cnlive.core.libs.base.frame.view; |
| 2 | 2 | ||
| 3 | +import android.app.Dialog; | ||
| 4 | +import android.content.Context; | ||
| 5 | +import android.graphics.drawable.Drawable; | ||
| 3 | import android.os.Message; | 6 | import android.os.Message; |
| 4 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
| 8 | +import android.view.View; | ||
| 5 | 9 | ||
| 10 | +import androidx.annotation.ColorRes; | ||
| 11 | +import androidx.annotation.DrawableRes; | ||
| 6 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
| 7 | - | 13 | +import androidx.annotation.StringRes; |
| 14 | +import androidx.databinding.ViewDataBinding; | ||
| 15 | + | ||
| 16 | +import com.alibaba.android.arouter.facade.template.IProvider; | ||
| 17 | +import com.alibaba.android.arouter.launcher.ARouter; | ||
| 18 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 19 | +import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | ||
| 20 | +import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 21 | +import com.cnlive.core.libs.base.util.BaseHelpUtil; | ||
| 8 | import com.hannesdorfmann.mosby3.mvp.MvpView; | 22 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 9 | import com.orhanobut.logger.Logger; | 23 | import com.orhanobut.logger.Logger; |
| 10 | 24 | ||
| 11 | import org.greenrobot.eventbus.EventBus; | 25 | import org.greenrobot.eventbus.EventBus; |
| 12 | 26 | ||
| 27 | +import io.reactivex.disposables.CompositeDisposable; | ||
| 28 | +import io.reactivex.disposables.Disposable; | ||
| 29 | + | ||
| 13 | /** | 30 | /** |
| 14 | * @author ys | 31 | * @author ys |
| 15 | * 基类View | 32 | * 基类View |
| 16 | */ | 33 | */ |
| 17 | public class BaseView implements MvpView { | 34 | public class BaseView implements MvpView { |
| 18 | protected final String TAG = this.getClass().getSimpleName(); | 35 | protected final String TAG = this.getClass().getSimpleName(); |
| 36 | + public BaseActivity me; | ||
| 37 | + private CompositeDisposable destoryDisposable;//生命周期在destory销毁 | ||
| 38 | + private CompositeDisposable pauseDisposable;//生命周期在onPause销毁 | ||
| 19 | 39 | ||
| 20 | public final void postEvent(Object object) { | 40 | public final void postEvent(Object object) { |
| 21 | EventBus.getDefault().post(object); | 41 | EventBus.getDefault().post(object); |
| @@ -25,22 +45,92 @@ public class BaseView implements MvpView { | @@ -25,22 +45,92 @@ public class BaseView implements MvpView { | ||
| 25 | EventBus.getDefault().postSticky(object); | 45 | EventBus.getDefault().postSticky(object); |
| 26 | } | 46 | } |
| 27 | 47 | ||
| 48 | + public BaseView() { | ||
| 49 | + initRxjava(); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + private void initRxjava() { | ||
| 53 | + pauseDisposable = new CompositeDisposable(); | ||
| 54 | + destoryDisposable = new CompositeDisposable(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 添加订阅 | ||
| 59 | + * Pause 销毁 | ||
| 60 | + * | ||
| 61 | + * @param disposable | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + public Disposable addPauseDisPosable(Disposable disposable) { | ||
| 65 | + if (null != disposable) { | ||
| 66 | + if (null != pauseDisposable) { | ||
| 67 | + pauseDisposable.add(disposable); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return disposable; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 添加订阅 | ||
| 75 | + * Destory 销毁 | ||
| 76 | + * | ||
| 77 | + * @param disposable | ||
| 78 | + * @return | ||
| 79 | + */ | ||
| 80 | + public Disposable addDestoryDisPosable(Disposable disposable) { | ||
| 81 | + if (null != disposable) { | ||
| 82 | + if (null != destoryDisposable) { | ||
| 83 | + destoryDisposable.add(disposable); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return disposable; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 在Activity的View层直接重写方法获取 | ||
| 91 | + * | ||
| 92 | + * @param baseActivity | ||
| 93 | + * @param baseBinding | ||
| 94 | + */ | ||
| 95 | + public void initActBindingLayout(BaseActivity baseActivity, ViewDataBinding baseBinding) { | ||
| 96 | + this.me = baseActivity; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 在Fragment的View层直接重写方法获取 当前fragment , | ||
| 101 | + * | ||
| 102 | + * @param baseActivity | ||
| 103 | + * @param baseFragment | ||
| 104 | + * @param baseBinding | ||
| 105 | + */ | ||
| 106 | + public void initFragBindingLayout(BaseActivity baseActivity, BaseFragment baseFragment, ViewDataBinding baseBinding) { | ||
| 107 | + this.me = baseActivity; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void initFragViewLayout(BaseActivity baseActivity, BaseFragment baseFragment, View baseView) { | ||
| 111 | + this.me = baseActivity; | ||
| 112 | + } | ||
| 113 | + | ||
| 28 | public void initView() { | 114 | public void initView() { |
| 29 | } | 115 | } |
| 30 | 116 | ||
| 31 | public void initData() { | 117 | public void initData() { |
| 32 | } | 118 | } |
| 33 | 119 | ||
| 34 | - public boolean isNull(Object o) { | ||
| 35 | - if (o instanceof String) { | ||
| 36 | - String s = (String) o; | ||
| 37 | - if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | ||
| 38 | - return true; | ||
| 39 | - } | ||
| 40 | - } else if (null == o) { | ||
| 41 | - return true; | 120 | + /** |
| 121 | + * 实例化路由-对象 | ||
| 122 | + */ | ||
| 123 | + public <T extends IProvider> T initRouterImpl(String routerPath) { | ||
| 124 | + T obj = null; | ||
| 125 | + try { | ||
| 126 | + obj = (T) ARouter.getInstance().build(routerPath).navigation(); | ||
| 127 | + } catch (Exception ignored) { | ||
| 42 | } | 128 | } |
| 43 | - return false; | 129 | + return obj; |
| 130 | + } | ||
| 131 | + | ||
| 132 | + public boolean isNull(Object... os) { | ||
| 133 | + return BaseHelpUtil.isNull(os); | ||
| 44 | } | 134 | } |
| 45 | 135 | ||
| 46 | public void onReceiveActHandleMessage(@NonNull Message msg) { | 136 | public void onReceiveActHandleMessage(@NonNull Message msg) { |
| @@ -79,5 +169,85 @@ public class BaseView implements MvpView { | @@ -79,5 +169,85 @@ public class BaseView implements MvpView { | ||
| 79 | Logger.xml(xml); | 169 | Logger.xml(xml); |
| 80 | } | 170 | } |
| 81 | 171 | ||
| 82 | - public void onDestory(){}; | 172 | + |
| 173 | + public void onPause() { | ||
| 174 | + //取消订阅 | ||
| 175 | + if (null != pauseDisposable && pauseDisposable.size() > 0) { | ||
| 176 | + pauseDisposable.clear(); | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public void onDestory() { | ||
| 181 | + //取消订阅 | ||
| 182 | + if (null != destoryDisposable && destoryDisposable.size() > 0) { | ||
| 183 | + destoryDisposable.clear(); | ||
| 184 | + } | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * 获取资源颜色 | ||
| 189 | + * | ||
| 190 | + * @param colorId | ||
| 191 | + * @return | ||
| 192 | + */ | ||
| 193 | + public int getResourceColor(@ColorRes int colorId) { | ||
| 194 | + return BaseHelpUtil.getResourceColor(me, colorId); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * 获取资源字符串 | ||
| 199 | + * | ||
| 200 | + * @param stringId | ||
| 201 | + * @return | ||
| 202 | + */ | ||
| 203 | + public String getResourceStr(@StringRes int stringId) { | ||
| 204 | + return BaseHelpUtil.getResourceStr(me, stringId); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 获取资源 | ||
| 209 | + * | ||
| 210 | + * @param drawableId | ||
| 211 | + * @return | ||
| 212 | + */ | ||
| 213 | + public Drawable getResourceDrawable(@DrawableRes int drawableId) { | ||
| 214 | + return BaseHelpUtil.getResourceDrawable(me, drawableId); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 用户提示 | ||
| 219 | + */ | ||
| 220 | + public void showToast(String message) { | ||
| 221 | + AlertUtil.showDeftToast(me, message); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * 销毁 Dialog | ||
| 226 | + */ | ||
| 227 | + protected void disposeDialog(Dialog... dialogs) { | ||
| 228 | + if (dialogs == null) return; | ||
| 229 | + for (Dialog dialog : dialogs) if (dialog != null) dialog.dismiss(); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + public void onNetworkError(Context context, String errCode, String errMsg, Exception e) { | ||
| 233 | + if (!TextUtils.isEmpty(errMsg)) { | ||
| 234 | + showToast(errMsg); | ||
| 235 | + } else if (!TextUtils.isEmpty(errCode)) { | ||
| 236 | + switch (errCode) { | ||
| 237 | + case "-7001"://当前没有网络 | ||
| 238 | + showToast("请检查当前网络."); | ||
| 239 | + break; | ||
| 240 | + case "-1"://服务端错误 | ||
| 241 | + showToast("服务正在维护当中,请稍候."); | ||
| 242 | + break; | ||
| 243 | + default: | ||
| 244 | + showToast("服务正在升级当中,请稍候."); | ||
| 245 | + break; | ||
| 246 | + } | ||
| 247 | + } else if (e != null) { | ||
| 248 | + showToast("功能正在维护当中,请稍候."); | ||
| 249 | + } else { | ||
| 250 | + showToast("获取信息失败,请稍候."); | ||
| 251 | + } | ||
| 252 | + } | ||
| 83 | } | 253 | } |
core/base/src/main/java/com/cnlive/core/libs/base/listener/Callback.java
0 → 100644
core/base/src/main/java/com/cnlive/core/libs/base/network/manager/SubscriptionManager.java renamed to core/base/src/main/java/com/cnlive/core/libs/base/network/manager/RxManager.java
| @@ -4,6 +4,9 @@ package com.cnlive.core.libs.base.network.manager; | @@ -4,6 +4,9 @@ package com.cnlive.core.libs.base.network.manager; | ||
| 4 | import android.text.TextUtils; | 4 | import android.text.TextUtils; |
| 5 | import android.util.Log; | 5 | import android.util.Log; |
| 6 | 6 | ||
| 7 | + | ||
| 8 | +import com.cnlive.cloud.base.BuildConfig; | ||
| 9 | + | ||
| 7 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 8 | 11 | ||
| 9 | import io.reactivex.disposables.CompositeDisposable; | 12 | import io.reactivex.disposables.CompositeDisposable; |
| @@ -14,17 +17,18 @@ import io.reactivex.disposables.Disposable; | @@ -14,17 +17,18 @@ import io.reactivex.disposables.Disposable; | ||
| 14 | * | 17 | * |
| 15 | * @author ys | 18 | * @author ys |
| 16 | */ | 19 | */ |
| 17 | -public class SubscriptionManager { | ||
| 18 | - private static SubscriptionManager instance; | 20 | +public class RxManager { |
| 21 | + private static RxManager instance; | ||
| 19 | private HashMap<String, CompositeDisposable> hashDisposable;//所有订阅关系 | 22 | private HashMap<String, CompositeDisposable> hashDisposable;//所有订阅关系 |
| 20 | private HashMap<Integer, String> hashTag;//当前activity | 23 | private HashMap<Integer, String> hashTag;//当前activity |
| 21 | private HashMap<String, Integer> hashTagIndex;//当前activity | 24 | private HashMap<String, Integer> hashTagIndex;//当前activity |
| 22 | private String currentClassName; | 25 | private String currentClassName; |
| 26 | + private final String className = this.getClass().getName(); | ||
| 23 | 27 | ||
| 24 | /** | 28 | /** |
| 25 | * 构造函数 new CompositeDisposable对象 | 29 | * 构造函数 new CompositeDisposable对象 |
| 26 | */ | 30 | */ |
| 27 | - public SubscriptionManager() { | 31 | + public RxManager() { |
| 28 | if (null == hashDisposable) { | 32 | if (null == hashDisposable) { |
| 29 | hashDisposable = new HashMap<>(); | 33 | hashDisposable = new HashMap<>(); |
| 30 | } | 34 | } |
| @@ -41,11 +45,11 @@ public class SubscriptionManager { | @@ -41,11 +45,11 @@ public class SubscriptionManager { | ||
| 41 | * | 45 | * |
| 42 | * @return | 46 | * @return |
| 43 | */ | 47 | */ |
| 44 | - public static SubscriptionManager getInstance() { | 48 | + public synchronized static RxManager getInstance() { |
| 45 | if (instance == null) { | 49 | if (instance == null) { |
| 46 | - synchronized (SubscriptionManager.class) { | 50 | + synchronized (RxManager.class) { |
| 47 | if (instance == null) { | 51 | if (instance == null) { |
| 48 | - instance = new SubscriptionManager(); | 52 | + instance = new RxManager(); |
| 49 | } | 53 | } |
| 50 | } | 54 | } |
| 51 | } | 55 | } |
| @@ -53,79 +57,80 @@ public class SubscriptionManager { | @@ -53,79 +57,80 @@ public class SubscriptionManager { | ||
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | public synchronized void setCurrentDisposables(String TAG) { | 59 | public synchronized void setCurrentDisposables(String TAG) { |
| 60 | + currentClassName = TAG; | ||
| 56 | if (null == hashDisposable.get(TAG)) { | 61 | if (null == hashDisposable.get(TAG)) { |
| 57 | - currentClassName = TAG; | ||
| 58 | hashDisposable.put(TAG, new CompositeDisposable()); | 62 | hashDisposable.put(TAG, new CompositeDisposable()); |
| 59 | //存放当前class映射 | 63 | //存放当前class映射 |
| 60 | hashTag.put(hashDisposable.size() - 1, TAG); | 64 | hashTag.put(hashDisposable.size() - 1, TAG); |
| 61 | hashTagIndex.put(TAG, hashTag.size() - 1); | 65 | hashTagIndex.put(TAG, hashTag.size() - 1); |
| 62 | - Log.d(TAG, "初始化: "); | 66 | + logDebug(className, TAG + "初始化订阅映射"); |
| 63 | } | 67 | } |
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | /** | 70 | /** |
| 67 | * 取消订阅事件 | 71 | * 取消订阅事件 |
| 68 | */ | 72 | */ |
| 69 | - public synchronized void cancel(String TAG) { | 73 | + public synchronized void cancel(String FLAG) { |
| 70 | try { | 74 | try { |
| 71 | if (null != hashDisposable && hashDisposable.size() > 0) { | 75 | if (null != hashDisposable && hashDisposable.size() > 0) { |
| 72 | - if (null != hashDisposable.get(TAG) && hashDisposable.get(TAG).size() > 0) { | ||
| 73 | - CompositeDisposable mDisposables = hashDisposable.get(TAG); | ||
| 74 | - if (null!=mDisposables&&!mDisposables.isDisposed()) { | ||
| 75 | - Log.e(TAG, "cancel: 解除订阅"); | 76 | + if (null != hashDisposable.get(FLAG) && hashDisposable.get(FLAG).size() > 0) { |
| 77 | + CompositeDisposable mDisposables = hashDisposable.get(FLAG); | ||
| 78 | + if (null != mDisposables && !mDisposables.isDisposed()) { | ||
| 79 | + logDebug(currentClassName, FLAG + "cancel: 解除订阅"); | ||
| 76 | mDisposables.clear(); | 80 | mDisposables.clear(); |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | //移除 | 83 | //移除 |
| 80 | - hashDisposable.remove(TAG); | 84 | + hashDisposable.remove(FLAG); |
| 81 | } | 85 | } |
| 82 | - if (null != hashTagIndex.get(TAG)) { | ||
| 83 | - int currentIndex = hashTagIndex.get(TAG); | 86 | + if (null != hashTagIndex.get(FLAG)) { |
| 87 | + int currentIndex = hashTagIndex.get(FLAG); | ||
| 84 | //移除 | 88 | //移除 |
| 85 | if (null != hashTag.get(currentIndex)) { | 89 | if (null != hashTag.get(currentIndex)) { |
| 86 | - Log.e(TAG, "cancel: " + hashTag.get(currentIndex)); | 90 | + logDebug(className, FLAG + "订阅cancel: " + hashTag.get(currentIndex)); |
| 87 | hashTag.remove(currentIndex); | 91 | hashTag.remove(currentIndex); |
| 88 | } | 92 | } |
| 89 | - hashTagIndex.remove(TAG); | 93 | + hashTagIndex.remove(FLAG); |
| 90 | } | 94 | } |
| 91 | } catch (Exception e) { | 95 | } catch (Exception e) { |
| 92 | - Log.d(TAG, "cancel: " + e.getMessage()); | 96 | + logErr(className, FLAG + "订阅cancel异常: " + e.getMessage()); |
| 93 | } | 97 | } |
| 94 | } | 98 | } |
| 95 | 99 | ||
| 96 | /** | 100 | /** |
| 97 | * 订阅事件加入到CompositeDisposable容器中 | 101 | * 订阅事件加入到CompositeDisposable容器中 |
| 102 | + * 可以不写setCurrentDisposables | ||
| 98 | * | 103 | * |
| 99 | * @param disposable 订阅事件 | 104 | * @param disposable 订阅事件 |
| 100 | */ | 105 | */ |
| 101 | - public synchronized void add(Disposable disposable) { | 106 | + public synchronized void add(String FLAG, Disposable disposable) { |
| 107 | + //判断是否已经存在该订阅关系 | ||
| 108 | + if (!TextUtils.isEmpty(FLAG)) { | ||
| 109 | + setCurrentDisposables(FLAG); | ||
| 110 | + } | ||
| 111 | + String tempFlag = ""; | ||
| 112 | + if (TextUtils.isEmpty(FLAG)) { | ||
| 113 | + tempFlag = currentClassName; | ||
| 114 | + } else { | ||
| 115 | + tempFlag = FLAG; | ||
| 116 | + } | ||
| 102 | try { | 117 | try { |
| 103 | if (disposable == null) return; | 118 | if (disposable == null) return; |
| 104 | //每次去除最新的activity进行存放 | 119 | //每次去除最新的activity进行存放 |
| 105 | if (null != hashDisposable && hashDisposable.size() > 0) { | 120 | if (null != hashDisposable && hashDisposable.size() > 0) { |
| 106 | - if (!TextUtils.isEmpty(currentClassName)) { | ||
| 107 | - if (null != hashDisposable.get(currentClassName)) { | 121 | + if (!TextUtils.isEmpty(tempFlag)) { |
| 122 | + if (null != hashDisposable.get(tempFlag)) { | ||
| 108 | //存放当前activity对应的订阅 | 123 | //存放当前activity对应的订阅 |
| 109 | - hashDisposable.get(currentClassName).add(disposable); | ||
| 110 | - Log.d(currentClassName, "add: 添加订阅关系" + hashDisposable.size()); | 124 | + hashDisposable.get(tempFlag).add(disposable); |
| 125 | + logDebug(className, tempFlag + "add: 添加订阅关系" + hashDisposable.get(tempFlag).size()); | ||
| 111 | } | 126 | } |
| 112 | } | 127 | } |
| 113 | } | 128 | } |
| 114 | } catch (Exception e) { | 129 | } catch (Exception e) { |
| 115 | - Log.e("SubscriptionManager", "cancel: " + e.getMessage()); | 130 | + logErr(className, "cancel: " + e.getMessage()); |
| 116 | } | 131 | } |
| 117 | } | 132 | } |
| 118 | 133 | ||
| 119 | -// /** | ||
| 120 | -// * 取消订阅事件 | ||
| 121 | -// * | ||
| 122 | -// * @param disposable 订阅事件 | ||
| 123 | -// */ | ||
| 124 | -// public void cancel(Disposable disposable) { | ||
| 125 | -// if (disposable != null) { | ||
| 126 | -// mDisposables.delete(disposable); | ||
| 127 | -// } | ||
| 128 | -// } | ||
| 129 | 134 | ||
| 130 | /** | 135 | /** |
| 131 | * 清除容器所有 | 136 | * 清除容器所有 |
| @@ -148,7 +153,19 @@ public class SubscriptionManager { | @@ -148,7 +153,19 @@ public class SubscriptionManager { | ||
| 148 | hashTag.clear(); | 153 | hashTag.clear(); |
| 149 | hashTagIndex.clear(); | 154 | hashTagIndex.clear(); |
| 150 | } catch (Exception e) { | 155 | } catch (Exception e) { |
| 151 | - Log.e("SubscriptionManager", "cancelAll: " + e.getMessage()); | 156 | + logErr(className, "清除所有订阅cancelAll: " + e.getMessage()); |
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + private void logDebug(String tag, String msg) { | ||
| 161 | + if (BuildConfig.DEBUG) { | ||
| 162 | + Log.d(tag, msg); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + private void logErr(String tag, String msg) { | ||
| 167 | + if (BuildConfig.DEBUG) { | ||
| 168 | + Log.e(tag, msg); | ||
| 152 | } | 169 | } |
| 153 | } | 170 | } |
| 154 | } | 171 | } |
core/base/src/main/java/com/cnlive/core/libs/base/ui/widget/SelectDialog.java
| @@ -12,14 +12,16 @@ import android.widget.Button; | @@ -12,14 +12,16 @@ import android.widget.Button; | ||
| 12 | import android.widget.LinearLayout; | 12 | import android.widget.LinearLayout; |
| 13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
| 14 | 14 | ||
| 15 | +import androidx.annotation.ColorRes; | ||
| 15 | import androidx.annotation.NonNull; | 16 | import androidx.annotation.NonNull; |
| 16 | import androidx.core.content.ContextCompat; | 17 | import androidx.core.content.ContextCompat; |
| 17 | 18 | ||
| 18 | import com.cnlive.cloud.base.R; | 19 | import com.cnlive.cloud.base.R; |
| 20 | +import com.cnlive.core.libs.base.util.DensityUtils; | ||
| 19 | 21 | ||
| 20 | 22 | ||
| 21 | /** | 23 | /** |
| 22 | - * 任务编辑对话框 | 24 | + * 选择对话框 |
| 23 | * | 25 | * |
| 24 | * @author ShinnyYang | 26 | * @author ShinnyYang |
| 25 | * @date 2019/3/27 14:11 | 27 | * @date 2019/3/27 14:11 |
| @@ -51,21 +53,96 @@ public class SelectDialog extends Dialog { | @@ -51,21 +53,96 @@ public class SelectDialog extends Dialog { | ||
| 51 | 53 | ||
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | - public void setLeftBtnColor(int textColor) { | ||
| 55 | - if (null != btn_cancel && null != cancelInterface) { | 56 | + public SelectDialog(@NonNull Context context, String tipText, String btnCancelText, String btnOkText) { |
| 57 | + super(context, R.style.MyDialog); | ||
| 58 | + this.context = context; | ||
| 59 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 60 | + initView(view); | ||
| 61 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 62 | + ll_child.setLayoutParams(layoutParams); | ||
| 63 | + | ||
| 64 | + tv_dialog_tip.setText(tipText); | ||
| 65 | + btn_cancel.setText(btnCancelText); | ||
| 66 | + btn_ok.setText(btnOkText); | ||
| 67 | + | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public SelectDialog(@NonNull Context context, String tipText) { | ||
| 71 | + super(context, R.style.MyDialog); | ||
| 72 | + this.context = context; | ||
| 73 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 74 | + initView(view); | ||
| 75 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 76 | + ll_child.setLayoutParams(layoutParams); | ||
| 77 | + | ||
| 78 | + tv_dialog_tip.setText(tipText); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public SelectDialog(@NonNull Context context) { | ||
| 82 | + super(context, R.style.MyDialog); | ||
| 83 | + this.context = context; | ||
| 84 | + view = LayoutInflater.from(context).inflate(R.layout.my_dialog_select, null); | ||
| 85 | + initView(view); | ||
| 86 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT); | ||
| 87 | + ll_child.setLayoutParams(layoutParams); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void setLeftInterface(DialogInterface cancelInterface) { | ||
| 91 | + this.cancelInterface = cancelInterface; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public void setRightInterface(DialogInterface okInterface) { | ||
| 95 | + this.okInterface = okInterface; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public void setLeftText(String text) { | ||
| 99 | + if (null != btn_cancel) { | ||
| 100 | + btn_cancel.setText(text); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void setRightText(String text) { | ||
| 105 | + if (null != btn_ok) { | ||
| 106 | + btn_ok.setText(text); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public void setLeftBtnColor(@ColorRes int textColor) { | ||
| 111 | + if (null != btn_cancel) { | ||
| 56 | btn_cancel.setTextColor(ContextCompat.getColor(context, textColor)); | 112 | btn_cancel.setTextColor(ContextCompat.getColor(context, textColor)); |
| 57 | } | 113 | } |
| 58 | } | 114 | } |
| 59 | 115 | ||
| 60 | - public void setRightBtnColor(int textColor) { | ||
| 61 | - if (null != btn_ok && null != cancelInterface) { | 116 | + public void setRightBtnColor(@ColorRes int textColor) { |
| 117 | + if (null != btn_ok) { | ||
| 62 | btn_ok.setTextColor(ContextCompat.getColor(context, textColor)); | 118 | btn_ok.setTextColor(ContextCompat.getColor(context, textColor)); |
| 63 | } | 119 | } |
| 64 | } | 120 | } |
| 65 | 121 | ||
| 66 | - public void setTipTextStyle(Typeface typeface){ | 122 | + public void setTipTextStyle(Typeface typeface) { |
| 67 | tv_dialog_tip.setTypeface(typeface); | 123 | tv_dialog_tip.setTypeface(typeface); |
| 68 | } | 124 | } |
| 125 | + | ||
| 126 | + public void setTipGravity(int gravity) { | ||
| 127 | + tv_dialog_tip.setGravity(gravity); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public void setTipTextSize(float textSize) { | ||
| 131 | + tv_dialog_tip.setTextSize(textSize); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public void setTipTextPaddingLeft(float dp){ | ||
| 135 | + tv_dialog_tip.setPadding(DensityUtils.dp2px(dp),0,0,0); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setLeftTextStyle(Typeface typeface) { | ||
| 139 | + btn_cancel.setTypeface(typeface); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public void setRightTextStyle(Typeface typeface) { | ||
| 143 | + btn_ok.setTypeface(typeface); | ||
| 144 | + } | ||
| 145 | + | ||
| 69 | public void setTipMessage(String message) { | 146 | public void setTipMessage(String message) { |
| 70 | tv_dialog_tip.setText(message); | 147 | tv_dialog_tip.setText(message); |
| 71 | } | 148 | } |
| @@ -79,8 +156,6 @@ public class SelectDialog extends Dialog { | @@ -79,8 +156,6 @@ public class SelectDialog extends Dialog { | ||
| 79 | @Override | 156 | @Override |
| 80 | protected void onCreate(Bundle savedInstanceState) { | 157 | protected void onCreate(Bundle savedInstanceState) { |
| 81 | super.onCreate(savedInstanceState); | 158 | super.onCreate(savedInstanceState); |
| 82 | - | ||
| 83 | - | ||
| 84 | //显示视图 | 159 | //显示视图 |
| 85 | this.setContentView(view); | 160 | this.setContentView(view); |
| 86 | } | 161 | } |
| @@ -93,14 +168,17 @@ public class SelectDialog extends Dialog { | @@ -93,14 +168,17 @@ public class SelectDialog extends Dialog { | ||
| 93 | btn_cancel.setOnClickListener(new View.OnClickListener() { | 168 | btn_cancel.setOnClickListener(new View.OnClickListener() { |
| 94 | @Override | 169 | @Override |
| 95 | public void onClick(View view) { | 170 | public void onClick(View view) { |
| 96 | - cancelInterface.onClick(SelectDialog.this); | 171 | + if (null != cancelInterface) { |
| 172 | + cancelInterface.onClick(SelectDialog.this); | ||
| 173 | + } | ||
| 97 | } | 174 | } |
| 98 | }); | 175 | }); |
| 99 | btn_ok.setOnClickListener(new View.OnClickListener() { | 176 | btn_ok.setOnClickListener(new View.OnClickListener() { |
| 100 | @Override | 177 | @Override |
| 101 | public void onClick(View view) { | 178 | public void onClick(View view) { |
| 102 | - | ||
| 103 | - okInterface.onClick(SelectDialog.this); | 179 | + if (null != okInterface) { |
| 180 | + okInterface.onClick(SelectDialog.this); | ||
| 181 | + } | ||
| 104 | } | 182 | } |
| 105 | }); | 183 | }); |
| 106 | } | 184 | } |
core/base/src/main/java/com/cnlive/core/libs/base/util/AppManager.java
| @@ -6,6 +6,7 @@ import android.content.Context; | @@ -6,6 +6,7 @@ import android.content.Context; | ||
| 6 | 6 | ||
| 7 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; | 7 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 8 | 8 | ||
| 9 | +import java.lang.ref.WeakReference; | ||
| 9 | import java.util.Arrays; | 10 | import java.util.Arrays; |
| 10 | import java.util.Collections; | 11 | import java.util.Collections; |
| 11 | import java.util.Iterator; | 12 | import java.util.Iterator; |
| @@ -24,6 +25,7 @@ public class AppManager { | @@ -24,6 +25,7 @@ public class AppManager { | ||
| 24 | private static OnActivityStatusChangeListener onActivityStatusChangeListener; | 25 | private static OnActivityStatusChangeListener onActivityStatusChangeListener; |
| 25 | private static Stack<BaseActivity> activityStack; | 26 | private static Stack<BaseActivity> activityStack; |
| 26 | private static AppManager instance; | 27 | private static AppManager instance; |
| 28 | + private static WeakReference<BaseActivity> activeActivity; | ||
| 27 | 29 | ||
| 28 | private AppManager() { | 30 | private AppManager() { |
| 29 | } | 31 | } |
| @@ -55,6 +57,9 @@ public class AppManager { | @@ -55,6 +57,9 @@ public class AppManager { | ||
| 55 | * 获取当前Activity(堆栈中最后一个压入的) | 57 | * 获取当前Activity(堆栈中最后一个压入的) |
| 56 | */ | 58 | */ |
| 57 | public BaseActivity currentActivity() { | 59 | public BaseActivity currentActivity() { |
| 60 | + if (activityStack == null) { | ||
| 61 | + return null; | ||
| 62 | + } | ||
| 58 | BaseActivity activity = null; | 63 | BaseActivity activity = null; |
| 59 | if (!activityStack.empty()) { | 64 | if (!activityStack.empty()) { |
| 60 | activity = activityStack.lastElement(); | 65 | activity = activityStack.lastElement(); |
| @@ -63,9 +68,21 @@ public class AppManager { | @@ -63,9 +68,21 @@ public class AppManager { | ||
| 63 | } | 68 | } |
| 64 | 69 | ||
| 65 | /** | 70 | /** |
| 71 | + * 获取当前处于活动状态的Activity | ||
| 72 | + * | ||
| 73 | + * @return | ||
| 74 | + */ | ||
| 75 | + public BaseActivity getActiveActivity() { | ||
| 76 | + return activeActivity.get(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 66 | * 结束当前Activity(堆栈中最后一个压入的) | 80 | * 结束当前Activity(堆栈中最后一个压入的) |
| 67 | */ | 81 | */ |
| 68 | public void finishActivity() { | 82 | public void finishActivity() { |
| 83 | + if (activityStack == null) { | ||
| 84 | + return; | ||
| 85 | + } | ||
| 69 | BaseActivity activity = activityStack.lastElement(); | 86 | BaseActivity activity = activityStack.lastElement(); |
| 70 | killActivity(activity); | 87 | killActivity(activity); |
| 71 | } | 88 | } |
| @@ -74,7 +91,7 @@ public class AppManager { | @@ -74,7 +91,7 @@ public class AppManager { | ||
| 74 | * 结束指定的Activity | 91 | * 结束指定的Activity |
| 75 | */ | 92 | */ |
| 76 | public void killActivity(BaseActivity activity) { | 93 | public void killActivity(BaseActivity activity) { |
| 77 | - if (activity != null) { | 94 | + if (activity != null && activityStack != null) { |
| 78 | if (activity != null) { | 95 | if (activity != null) { |
| 79 | activity.finishActivity(); | 96 | activity.finishActivity(); |
| 80 | } | 97 | } |
| @@ -87,6 +104,9 @@ public class AppManager { | @@ -87,6 +104,9 @@ public class AppManager { | ||
| 87 | * 结束指定类名的Activity | 104 | * 结束指定类名的Activity |
| 88 | */ | 105 | */ |
| 89 | public void killActivity(Class<?> cls) { | 106 | public void killActivity(Class<?> cls) { |
| 107 | + if (activityStack == null) { | ||
| 108 | + return; | ||
| 109 | + } | ||
| 90 | Iterator<BaseActivity> iterator = activityStack.iterator(); | 110 | Iterator<BaseActivity> iterator = activityStack.iterator(); |
| 91 | BaseActivity temp = null; | 111 | BaseActivity temp = null; |
| 92 | while (iterator.hasNext()) { | 112 | while (iterator.hasNext()) { |
| @@ -133,14 +153,18 @@ public class AppManager { | @@ -133,14 +153,18 @@ public class AppManager { | ||
| 133 | } | 153 | } |
| 134 | 154 | ||
| 135 | public void deleteActivity(BaseActivity activity) { | 155 | public void deleteActivity(BaseActivity activity) { |
| 136 | - if (activity != null) { | ||
| 137 | - activityStack.remove(activity); | ||
| 138 | - if (onActivityStatusChangeListener != null) { | ||
| 139 | - onActivityStatusChangeListener.onActivityDestroy(activity); | ||
| 140 | - if (activityStack.isEmpty()) { | ||
| 141 | - onActivityStatusChangeListener.onAllActivityClose(); | 156 | + try { |
| 157 | + if (activity != null && activityStack != null) { | ||
| 158 | + activityStack.remove(activity); | ||
| 159 | + if (onActivityStatusChangeListener != null) { | ||
| 160 | + onActivityStatusChangeListener.onActivityDestroy(activity); | ||
| 161 | + if (activityStack.isEmpty()) { | ||
| 162 | + onActivityStatusChangeListener.onAllActivityClose(); | ||
| 163 | + } | ||
| 142 | } | 164 | } |
| 143 | } | 165 | } |
| 166 | + } catch (Exception e) { | ||
| 167 | + | ||
| 144 | } | 168 | } |
| 145 | } | 169 | } |
| 146 | 170 | ||
| @@ -174,6 +198,9 @@ public class AppManager { | @@ -174,6 +198,9 @@ public class AppManager { | ||
| 174 | * @param cls activity | 198 | * @param cls activity |
| 175 | */ | 199 | */ |
| 176 | public BaseActivity getActivityInstance(Class<?> cls) { | 200 | public BaseActivity getActivityInstance(Class<?> cls) { |
| 201 | + if (activityStack == null) { | ||
| 202 | + return null; | ||
| 203 | + } | ||
| 177 | if (!activityStack.empty()) { | 204 | if (!activityStack.empty()) { |
| 178 | Stack<BaseActivity> reverseList = new Stack<BaseActivity>(); | 205 | Stack<BaseActivity> reverseList = new Stack<BaseActivity>(); |
| 179 | reverseList.addAll(activityStack); | 206 | reverseList.addAll(activityStack); |
| @@ -216,4 +243,8 @@ public class AppManager { | @@ -216,4 +243,8 @@ public class AppManager { | ||
| 216 | 243 | ||
| 217 | void onAllActivityClose(); | 244 | void onAllActivityClose(); |
| 218 | } | 245 | } |
| 246 | + | ||
| 247 | + public static void setActiveActivity(BaseActivity activeActivity) { | ||
| 248 | + AppManager.activeActivity = new WeakReference<>(activeActivity); | ||
| 249 | + } | ||
| 219 | } | 250 | } |
core/base/src/main/java/com/cnlive/core/libs/base/util/BaseHelpUtil.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.graphics.drawable.Drawable; | ||
| 5 | +import android.text.TextUtils; | ||
| 6 | + | ||
| 7 | +import androidx.annotation.ColorRes; | ||
| 8 | +import androidx.annotation.DrawableRes; | ||
| 9 | +import androidx.annotation.StringRes; | ||
| 10 | + | ||
| 11 | +/* | ||
| 12 | + *@date:2020/4/11 12:11 | ||
| 13 | + *@author:杨帅 | ||
| 14 | + */public class BaseHelpUtil { | ||
| 15 | + /** | ||
| 16 | + * 获取资源颜色 | ||
| 17 | + * | ||
| 18 | + * @param colorId | ||
| 19 | + * @param context | ||
| 20 | + * @return | ||
| 21 | + */ | ||
| 22 | + public static int getResourceColor(Context context, @ColorRes int colorId) { | ||
| 23 | + return context.getResources().getColor(colorId); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 获取资源 | ||
| 28 | + * | ||
| 29 | + * @param drawableId | ||
| 30 | + * @param context | ||
| 31 | + * @return | ||
| 32 | + */ | ||
| 33 | + public static Drawable getResourceDrawable(Context context, @DrawableRes int drawableId) { | ||
| 34 | + return context.getResources().getDrawable(drawableId); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 获取资源字符串 | ||
| 39 | + * | ||
| 40 | + * @param stringId | ||
| 41 | + * @param context | ||
| 42 | + * @return | ||
| 43 | + */ | ||
| 44 | + public static String getResourceStr(Context context, @StringRes int stringId) { | ||
| 45 | + return context.getResources().getString(stringId); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static boolean isNull(Object... os) { | ||
| 49 | + | ||
| 50 | + if (null == os) { | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + for (Object o : os) { | ||
| 54 | + if (null == o) { | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + if (o instanceof String) { | ||
| 58 | + String s = (String) o; | ||
| 59 | + if (TextUtils.isEmpty(s) || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) | ||
| 60 | + return true; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + return false; | ||
| 64 | + } | ||
| 65 | +} |
core/base/src/main/java/com/cnlive/core/libs/base/util/GlobalLifeCircleListener.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Author: @Kongzue | ||
| 8 | + * Github: https://github.com/kongzue/ | ||
| 9 | + * Homepage: http://kongzue.com/ | ||
| 10 | + * Mail: myzcxhh@live.cn | ||
| 11 | + * CreateTime: 2018/9/1 15:44 | ||
| 12 | + */ | ||
| 13 | +public abstract class GlobalLifeCircleListener { | ||
| 14 | + | ||
| 15 | + public abstract void onCreate(BaseActivity me, String className); | ||
| 16 | + | ||
| 17 | + public abstract void onResume(BaseActivity me, String className); | ||
| 18 | + | ||
| 19 | + public abstract void onPause(BaseActivity me, String className); | ||
| 20 | + | ||
| 21 | + public abstract void onDestroy(BaseActivity me, String className); | ||
| 22 | + | ||
| 23 | + public void windowFocus(BaseActivity me, String className, boolean hasFocus) { | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | +} |
core/base/src/main/java/com/cnlive/core/libs/base/util/LifeCircleListener.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Author: @Kongzue | ||
| 5 | + * Github: https://github.com/kongzue/ | ||
| 6 | + * Homepage: http://kongzue.com/ | ||
| 7 | + * Mail: myzcxhh@live.cn | ||
| 8 | + * CreateTime: 2018/8/1 01:36 | ||
| 9 | + */ | ||
| 10 | +public interface LifeCircleListener { | ||
| 11 | + | ||
| 12 | + void onCreate(); | ||
| 13 | + | ||
| 14 | + void onResume(); | ||
| 15 | + | ||
| 16 | + void onPause(); | ||
| 17 | + | ||
| 18 | + void onDestroy(); | ||
| 19 | + | ||
| 20 | +} |
core/base/src/main/java/com/me/yokeyword/fragmentation/SupportFragmentDelegate.java
| @@ -57,7 +57,9 @@ public class SupportFragmentDelegate { | @@ -57,7 +57,9 @@ public class SupportFragmentDelegate { | ||
| 57 | private ISupportActivity mSupport; | 57 | private ISupportActivity mSupport; |
| 58 | boolean mAnimByActivity = true; | 58 | boolean mAnimByActivity = true; |
| 59 | EnterAnimListener mEnterAnimListener; | 59 | EnterAnimListener mEnterAnimListener; |
| 60 | - | 60 | + //fragment根布局是否可点击,多用于多个fragment叠加在一个activity,是否可点击下层的fragment,默认是可以点击下层的 |
| 61 | + private boolean isRootViewCanClickable = false; | ||
| 62 | + private View rootView = null; | ||
| 61 | private boolean mRootViewClickable; | 63 | private boolean mRootViewClickable; |
| 62 | 64 | ||
| 63 | public SupportFragmentDelegate(ISupportFragment support) { | 65 | public SupportFragmentDelegate(ISupportFragment support) { |
| @@ -187,11 +189,15 @@ public class SupportFragmentDelegate { | @@ -187,11 +189,15 @@ public class SupportFragmentDelegate { | ||
| 187 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { | 189 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { |
| 188 | getVisibleDelegate().onActivityCreated(savedInstanceState); | 190 | getVisibleDelegate().onActivityCreated(savedInstanceState); |
| 189 | 191 | ||
| 190 | - View view = mFragment.getView(); | ||
| 191 | - if (view != null) { | ||
| 192 | - mRootViewClickable = view.isClickable(); | ||
| 193 | - view.setClickable(true); | ||
| 194 | - setBackground(view); | 192 | + rootView = mFragment.getView(); |
| 193 | + if (rootView != null) { | ||
| 194 | + //只有设置为可点击的时候才设置 | ||
| 195 | + if (isRootViewCanClickable) { | ||
| 196 | + //解决多个fragment点击无响应的问题 | ||
| 197 | + rootView.setClickable(isRootViewCanClickable); | ||
| 198 | + } | ||
| 199 | + setBackground(rootView); | ||
| 200 | + mRootViewClickable = rootView.isClickable(); | ||
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | 203 | ||
| @@ -210,6 +216,32 @@ public class SupportFragmentDelegate { | @@ -210,6 +216,32 @@ public class SupportFragmentDelegate { | ||
| 210 | } | 216 | } |
| 211 | } | 217 | } |
| 212 | 218 | ||
| 219 | + /** | ||
| 220 | + * 获取fragment根布局是否可以点击 | ||
| 221 | + * 如设置可点击,那么,多个fragment使用时,需要注意层级叠加顺序 | ||
| 222 | + * 默认为底层不可点击 | ||
| 223 | + * | ||
| 224 | + * @return | ||
| 225 | + */ | ||
| 226 | + private boolean getRootViewCanClickable() { | ||
| 227 | + return isRootViewCanClickable; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + /** | ||
| 231 | + * 设置底层view是否可点击 | ||
| 232 | + * | ||
| 233 | + * @param isclick | ||
| 234 | + */ | ||
| 235 | + public void setFragmentRootViewCanClickable(boolean isclick) { | ||
| 236 | + isRootViewCanClickable = isclick; | ||
| 237 | + if (rootView != null) { | ||
| 238 | + mRootViewClickable = isclick; | ||
| 239 | + if (isclick) { | ||
| 240 | + rootView.setClickable(isclick); | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 213 | public void onResume() { | 245 | public void onResume() { |
| 214 | getVisibleDelegate().onResume(); | 246 | getVisibleDelegate().onResume(); |
| 215 | } | 247 | } |
| @@ -359,9 +391,9 @@ public class SupportFragmentDelegate { | @@ -359,9 +391,9 @@ public class SupportFragmentDelegate { | ||
| 359 | } | 391 | } |
| 360 | 392 | ||
| 361 | /** | 393 | /** |
| 362 | - * 类似 {@link Activity#onActivityResult(int, int, Intent)} | 394 | + * 类似 {@link Activity onActivityResult(int, int, Intent)} |
| 363 | * <p> | 395 | * <p> |
| 364 | - * Similar to {@link Activity#onActivityResult(int, int, Intent)} | 396 | + * Similar to {@link Activity onActivityResult(int, int, Intent)} |
| 365 | * | 397 | * |
| 366 | * @see #startForResult(ISupportFragment, int) | 398 | * @see #startForResult(ISupportFragment, int) |
| 367 | */ | 399 | */ |
| @@ -370,9 +402,9 @@ public class SupportFragmentDelegate { | @@ -370,9 +402,9 @@ public class SupportFragmentDelegate { | ||
| 370 | 402 | ||
| 371 | /** | 403 | /** |
| 372 | * 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法 | 404 | * 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法 |
| 373 | - * 类似 {@link Activity#onNewIntent(Intent)} | 405 | + * 类似 {@link Activity onNewIntent(Intent)} |
| 374 | * <p> | 406 | * <p> |
| 375 | - * Similar to {@link Activity#onNewIntent(Intent)} | 407 | + * Similar to {@link Activity onNewIntent(Intent)} |
| 376 | * | 408 | * |
| 377 | * @param args putNewBundle(Bundle newBundle) | 409 | * @param args putNewBundle(Bundle newBundle) |
| 378 | * @see #start(ISupportFragment, int) | 410 | * @see #start(ISupportFragment, int) |
core/dentity_verfication/.gitignore deleted
100644 → 0
| 1 | -/build |
core/dentity_verfication/build.gradle deleted
100644 → 0
| 1 | -apply plugin: 'com.android.library' | ||
| 2 | - | ||
| 3 | -android { | ||
| 4 | - | ||
| 5 | -} | ||
| 6 | - | ||
| 7 | -dependencies { | ||
| 8 | - implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
| 9 | - implementation 'androidx.appcompat:appcompat:1.0.2' | ||
| 10 | - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
| 11 | - implementation 'androidx.legacy:legacy-support-v4:1.0.0' | ||
| 12 | - testImplementation 'junit:junit:4.12' | ||
| 13 | - androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
| 14 | - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
| 15 | - implementation "com.cnlive.libs:mediapicker:$rootProject.libMediaPicker" | ||
| 16 | - implementation files('libs/license.jar') | ||
| 17 | -} |
core/dentity_verfication/consumer-rules.pro deleted
100644 → 0
core/dentity_verfication/libs/license.jar deleted
100644 → 0
No preview for this file type
core/dentity_verfication/libs/ocr-sdk.jar deleted
100644 → 0
No preview for this file type
core/dentity_verfication/proguard-rules.pro deleted
100644 → 0
| 1 | -# Add project specific ProGuard rules here. | ||
| 2 | -# You can control the set of applied configuration files using the | ||
| 3 | -# proguardFiles setting in build.gradle. | ||
| 4 | -# | ||
| 5 | -# For more details, see | ||
| 6 | -# http://developer.android.com/guide/developing/tools/proguard.html | ||
| 7 | - | ||
| 8 | -# If your project uses WebView with JS, uncomment the following | ||
| 9 | -# and specify the fully qualified class name to the JavaScript interface | ||
| 10 | -# class: | ||
| 11 | -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| 12 | -# public *; | ||
| 13 | -#} | ||
| 14 | - | ||
| 15 | -# Uncomment this to preserve the line number information for | ||
| 16 | -# debugging stack traces. | ||
| 17 | -#-keepattributes SourceFile,LineNumberTable | ||
| 18 | - | ||
| 19 | -# If you keep the line number information, uncomment this to | ||
| 20 | -# hide the original source file name. | ||
| 21 | -#-renamesourcefileattribute SourceFile |
core/dentity_verfication/src/main/AndroidManifest.xml deleted
100644 → 0
| 1 | -<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | -<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | - package="com.cnlive.core.people_verfication"> | ||
| 4 | - | ||
| 5 | - <uses-permission android:name="android.permission.CAMERA" /> | ||
| 6 | - <uses-permission android:name="android.permission.INTERNET" /> | ||
| 7 | - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
| 8 | - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
| 9 | - | ||
| 10 | - <uses-feature android:name="android.hardware.camera2.full" /> | ||
| 11 | - <uses-feature android:name="android.hardware.camera" /> | ||
| 12 | - <uses-feature android:name="android.hardware.camera.autofocus" /> | ||
| 13 | - | ||
| 14 | - <application> | ||
| 15 | - <activity android:name=".activity.PersonCheckActivity"></activity> | ||
| 16 | - <activity android:name=".activity.CheckResultActivity" /> | ||
| 17 | - <activity android:name="com.cnlive.core.company_verfication.ui.activity.FillInCompanyDataActivity"></activity> | ||
| 18 | - <activity android:name="com.cnlive.core.company_verfication.ui.activity.SelectCompanyDataActivity" /> | ||
| 19 | - <activity android:name=".activity.TakeIdentityPictureActivity" /> | ||
| 20 | - <activity | ||
| 21 | - android:name="com.cnlive.core.ocr.ui.camera.CameraActivity" | ||
| 22 | - android:configChanges="screenSize|orientation" | ||
| 23 | - android:launchMode="singleTop" | ||
| 24 | - android:screenOrientation="portrait" | ||
| 25 | - android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" /> | ||
| 26 | - </application> | ||
| 27 | - | ||
| 28 | -</manifest> | ||
| 29 | \ No newline at end of file | 0 | \ No newline at end of file |
core/dentity_verfication/src/main/assets/models/integrity_model_secret.bin deleted
100644 → 0
No preview for this file type
core/dentity_verfication/src/main/assets/models/quality_model_secret.bin deleted
100644 → 0
No preview for this file type
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/activity/FillInCompanyDataActivity.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.activity; | ||
| 2 | - | ||
| 3 | -import android.content.Context; | ||
| 4 | -import android.content.Intent; | ||
| 5 | - | ||
| 6 | -import com.cnlive.core.company_verfication.ui.fragment.FillInCompanyDataFragment; | ||
| 7 | -import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 8 | -import com.cnlive.core.people_verfication.R; | ||
| 9 | -import com.cnlive.core.people_verfication.activity.CheckResultActivity; | ||
| 10 | - | ||
| 11 | -public class FillInCompanyDataActivity extends BaseActivity { | ||
| 12 | - | ||
| 13 | - public static void startActivity(Context context, String userId){ | ||
| 14 | - Intent intent = new Intent(context, FillInCompanyDataActivity.class); | ||
| 15 | - intent.putExtra("userId",userId); | ||
| 16 | - context.startActivity(intent); | ||
| 17 | - } | ||
| 18 | - @Override | ||
| 19 | - protected void initView() { | ||
| 20 | - loadRootFragment(new FillInCompanyDataFragment()); | ||
| 21 | - } | ||
| 22 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/activity/SelectCompanyDataActivity.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.activity; | ||
| 2 | - | ||
| 3 | -import androidx.databinding.ViewDataBinding; | ||
| 4 | -import androidx.recyclerview.widget.LinearLayoutManager; | ||
| 5 | - | ||
| 6 | -import com.cnlive.core.company_verfication.ui.adapter.CompanyDataAdapter; | ||
| 7 | -import com.cnlive.core.company_verfication.ui.fragment.SelectCompanyDataFragment; | ||
| 8 | -import com.cnlive.core.libs.base.frame.activity.BaseActivity; | ||
| 9 | -import com.cnlive.core.people_verfication.R; | ||
| 10 | -import com.cnlive.core.people_verfication.databinding.FragmentFillInCompanyDataBinding; | ||
| 11 | - | ||
| 12 | -import java.util.ArrayList; | ||
| 13 | -import java.util.List; | ||
| 14 | - | ||
| 15 | -public class SelectCompanyDataActivity extends BaseActivity { | ||
| 16 | - | ||
| 17 | - @Override | ||
| 18 | - protected void initView() { | ||
| 19 | - loadRootFragment(new SelectCompanyDataFragment()); | ||
| 20 | - } | ||
| 21 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/adapter/CompanyDataAdapter.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.adapter; | ||
| 2 | - | ||
| 3 | -import android.content.Context; | ||
| 4 | -import android.view.LayoutInflater; | ||
| 5 | -import android.view.View; | ||
| 6 | -import android.view.ViewGroup; | ||
| 7 | -import android.widget.TextView; | ||
| 8 | - | ||
| 9 | -import androidx.annotation.NonNull; | ||
| 10 | -import androidx.databinding.DataBindingUtil; | ||
| 11 | -import androidx.recyclerview.widget.RecyclerView; | ||
| 12 | - | ||
| 13 | -import com.cnlive.core.people_verfication.R; | ||
| 14 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDateBinding; | ||
| 15 | - | ||
| 16 | -import java.util.List; | ||
| 17 | - | ||
| 18 | -public class CompanyDataAdapter extends RecyclerView.Adapter { | ||
| 19 | - private Context context; | ||
| 20 | - private List<String> data; | ||
| 21 | - | ||
| 22 | - public CompanyDataAdapter(Context context, List<String> data) { | ||
| 23 | - this.context = context; | ||
| 24 | - this.data = data; | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - @NonNull | ||
| 28 | - @Override | ||
| 29 | - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
| 30 | - LayoutInflater inflater = LayoutInflater.from(context); | ||
| 31 | - ItemCompanyDateBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_company_date, parent, false); | ||
| 32 | - return new MyViewHolder(binding); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - @Override | ||
| 36 | - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | ||
| 37 | - ItemCompanyDateBinding binding = ((MyViewHolder) holder).binding; | ||
| 38 | - binding.includeAccountChild.llRoot.getBaselineAlignedChildIndex(); | ||
| 39 | - binding.includeAccountChild.llChildAccountDelete.setVisibility(View.GONE); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Override | ||
| 43 | - public int getItemCount() { | ||
| 44 | - return data.size(); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - private class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 48 | - private ItemCompanyDateBinding binding; | ||
| 49 | - | ||
| 50 | - public MyViewHolder(@NonNull ItemCompanyDateBinding binding) { | ||
| 51 | - super(binding.getRoot()); | ||
| 52 | - this.binding = binding; | ||
| 53 | - binding.includeAddCircle.btnAddChildCircle.setOnClickListener(this); | ||
| 54 | - binding.includeAddChildAccount.btnAddChildAccount.setOnClickListener(this); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public void onClick(View v) { | ||
| 60 | - //添加圈子 | ||
| 61 | - if (v.getId() == R.id.btn_addChildCircle) { | ||
| 62 | - View child = LayoutInflater.from(context).inflate(R.layout.item_company_data_type_circle_child, null); | ||
| 63 | - binding.includeCircleChild.llRoot.addView(child); | ||
| 64 | - } | ||
| 65 | - //添加群组 | ||
| 66 | - else if (v.getId() == R.id.btn_addChildAccount) { | ||
| 67 | - View child = LayoutInflater.from(context).inflate(R.layout.item_company_data_type_child_account, null); | ||
| 68 | - int index=binding.includeAccountChild.llRoot.getChildCount() - 1; | ||
| 69 | - binding.includeAccountChild.llRoot.addView(child, index); | ||
| 70 | - TextView textView = child.findViewById(R.id.ll_child_account_delete); | ||
| 71 | - textView.setVisibility(View.VISIBLE); | ||
| 72 | - textView.setOnClickListener(this); | ||
| 73 | - textView.setTag(child); | ||
| 74 | -// textView.setOnClickListener(new View.OnClickListener() { | ||
| 75 | -// @Override | ||
| 76 | -// public void onClick(View v) { | ||
| 77 | -// binding.includeAccountChild.llRoot.removeView(child); | ||
| 78 | -// } | ||
| 79 | -// }); | ||
| 80 | - } else if (v.getId() == R.id.ll_child_account_delete) { | ||
| 81 | - if (null!=v&&null!=v.getTag()){ | ||
| 82 | - View child= (View) v.getTag(); | ||
| 83 | - //获取当前子类 | ||
| 84 | - binding.includeAccountChild.llRoot.removeView(child); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - } | ||
| 88 | - } | ||
| 89 | - } | ||
| 90 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/adapter/CompanyItemDataAdapter.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.adapter; | ||
| 2 | - | ||
| 3 | -import android.content.Context; | ||
| 4 | -import android.view.LayoutInflater; | ||
| 5 | -import android.view.View; | ||
| 6 | -import android.view.ViewGroup; | ||
| 7 | -import android.widget.TextView; | ||
| 8 | - | ||
| 9 | -import com.cnlive.core.company_verfication.ui.model.CompanyItemData; | ||
| 10 | -import com.cnlive.core.people_verfication.R; | ||
| 11 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeAddChildAccountBinding; | ||
| 12 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeAddCircleBinding; | ||
| 13 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeAddOrganizationBinding; | ||
| 14 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeChildAccountBinding; | ||
| 15 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeCircleChildBinding; | ||
| 16 | -import com.cnlive.core.people_verfication.databinding.ItemCompanyDataTypeOrganizationBinding; | ||
| 17 | - | ||
| 18 | -import java.util.List; | ||
| 19 | - | ||
| 20 | -import androidx.annotation.NonNull; | ||
| 21 | -import androidx.databinding.DataBindingUtil; | ||
| 22 | -import androidx.recyclerview.widget.RecyclerView; | ||
| 23 | - | ||
| 24 | -/* | ||
| 25 | - *@date:2020/4/7 16:29 | ||
| 26 | - *@author:杨帅 | ||
| 27 | - */public class CompanyItemDataAdapter extends RecyclerView.Adapter { | ||
| 28 | - private Context context; | ||
| 29 | - private List<CompanyItemData> dataList; | ||
| 30 | - private OnClickListener onClickListener; | ||
| 31 | - | ||
| 32 | - public CompanyItemDataAdapter(Context context, List<CompanyItemData> dataList) { | ||
| 33 | - this.context = context; | ||
| 34 | - this.dataList = dataList; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - public void setOnClickListener(OnClickListener onClickListener) { | ||
| 38 | - this.onClickListener = onClickListener; | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - @NonNull | ||
| 42 | - @Override | ||
| 43 | - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
| 44 | - switch (viewType) { | ||
| 45 | - case CompanyItemData.TYPE_ORGANIZATION: | ||
| 46 | - ItemCompanyDataTypeOrganizationBinding organizationBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_organization, parent, false); | ||
| 47 | - OrganizactionHolder organizactionHolder = new OrganizactionHolder(organizationBinding); | ||
| 48 | - return organizactionHolder; | ||
| 49 | - case CompanyItemData.TYPE_CIRCLE: | ||
| 50 | - ItemCompanyDataTypeCircleChildBinding circleChildBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_circle_child, parent, false); | ||
| 51 | - CircleHolder circleHolder = new CircleHolder(circleChildBinding); | ||
| 52 | - return circleHolder; | ||
| 53 | - case CompanyItemData.TYPE_ADD_CIRCLE: | ||
| 54 | - ItemCompanyDataTypeAddCircleBinding addCircleBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_add_circle, parent, false); | ||
| 55 | - AddCircleHolder addCircleHolder = new AddCircleHolder(addCircleBinding); | ||
| 56 | - return addCircleHolder; | ||
| 57 | - case CompanyItemData.TYPE_CHILD_ACCOUNT: | ||
| 58 | - ItemCompanyDataTypeChildAccountBinding childAccountBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_child_account, parent, false); | ||
| 59 | - ChildAccountHolder childAccountHolder = new ChildAccountHolder(childAccountBinding); | ||
| 60 | - return childAccountHolder; | ||
| 61 | - case CompanyItemData.TYPE_ADD_CHILD_ACCOUNT: | ||
| 62 | - ItemCompanyDataTypeAddChildAccountBinding addChildAccountBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_add_child_account, parent, false); | ||
| 63 | - AddChildAccountHolder addChildAccountHolder = new AddChildAccountHolder(addChildAccountBinding); | ||
| 64 | - return addChildAccountHolder; | ||
| 65 | - case CompanyItemData.TYPE_ADD_ORGANIZATION: | ||
| 66 | - ItemCompanyDataTypeAddOrganizationBinding addOrganizationBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_company_data_type_add_organization, parent, false); | ||
| 67 | - AddOrganizactionHolder addOrganizactionHolder = new AddOrganizactionHolder(addOrganizationBinding); | ||
| 68 | - return addOrganizactionHolder; | ||
| 69 | - } | ||
| 70 | - return null; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - @Override | ||
| 74 | - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | ||
| 75 | - switch (getItemViewType(position)) { | ||
| 76 | - case CompanyItemData.TYPE_ORGANIZATION: | ||
| 77 | - OrganizactionHolder organizactionHolder = (OrganizactionHolder) holder; | ||
| 78 | - organizactionHolder.binding.llTopLine.setVisibility(dataList.get(position).isShowTopLine() ? View.VISIBLE : View.GONE); | ||
| 79 | - organizactionHolder.binding.ivOrganizationDelete.setVisibility(dataList.get(position).isShowOrganizactionDelete() ? View.VISIBLE : View.GONE); | ||
| 80 | - | ||
| 81 | - break; | ||
| 82 | - case CompanyItemData.TYPE_CIRCLE: | ||
| 83 | - CircleHolder circleHolder = (CircleHolder) holder; | ||
| 84 | - circleHolder.binding.llCircleDelete.setVisibility(dataList.get(position).isShowDelete() ? View.VISIBLE : View.GONE); | ||
| 85 | - break; | ||
| 86 | - case CompanyItemData.TYPE_ADD_CIRCLE: | ||
| 87 | - break; | ||
| 88 | - case CompanyItemData.TYPE_CHILD_ACCOUNT: | ||
| 89 | - ChildAccountHolder childAccountHolder = (ChildAccountHolder) holder; | ||
| 90 | - childAccountHolder.binding.llChildAccountDelete.setVisibility(dataList.get(position).isShowDelete() ? View.VISIBLE : View.GONE); | ||
| 91 | - break; | ||
| 92 | - case CompanyItemData.TYPE_ADD_CHILD_ACCOUNT: | ||
| 93 | - break; | ||
| 94 | - case CompanyItemData.TYPE_ADD_ORGANIZATION: | ||
| 95 | - | ||
| 96 | - break; | ||
| 97 | - } | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | - @Override | ||
| 101 | - public int getItemCount() { | ||
| 102 | - return dataList.size(); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - @Override | ||
| 106 | - public int getItemViewType(int position) { | ||
| 107 | - return dataList.get(position).getType(); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - | ||
| 111 | - /** | ||
| 112 | - * 所属机构 | ||
| 113 | - */ | ||
| 114 | - public class OrganizactionHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 115 | - private ItemCompanyDataTypeOrganizationBinding binding; | ||
| 116 | - | ||
| 117 | - public OrganizactionHolder(@NonNull ItemCompanyDataTypeOrganizationBinding binding) { | ||
| 118 | - super(binding.getRoot()); | ||
| 119 | - this.binding = binding; | ||
| 120 | - binding.ivOrganizationDelete.setOnClickListener(this); | ||
| 121 | - binding.tvOrganization.setOnClickListener(this); | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - @Override | ||
| 125 | - public void onClick(View v) { | ||
| 126 | - //删除机构 | ||
| 127 | - if (v.getId() == R.id.iv_organization_delete) { | ||
| 128 | - //获取当前所在逻辑位置 | ||
| 129 | - int logicPosition = dataList.get(getLayoutPosition()).getLogicPosition(); | ||
| 130 | - deleteLogicItem(logicPosition); | ||
| 131 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_ADD_ORGANIZATION, dataList.get(dataList.size() - 1).getLogicPosition())); | ||
| 132 | - notifyDataSetChanged(); | ||
| 133 | - } | ||
| 134 | - //选中机构 | ||
| 135 | - else if (v.getId() == R.id.tv_organization) { | ||
| 136 | - if (null != onClickListener) { | ||
| 137 | - onClickListener.onClick(binding.tvOrganization); | ||
| 138 | - } | ||
| 139 | - } | ||
| 140 | - } | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - private void deleteLogicItem(int logicPosition) { | ||
| 144 | - if (dataList.size() == 0) { | ||
| 145 | - return; | ||
| 146 | - } | ||
| 147 | - for (int i = dataList.size() - 1; i >= 0; i--) { | ||
| 148 | - if (dataList.get(i).getLogicPosition() == logicPosition) { | ||
| 149 | - dataList.remove(i); | ||
| 150 | - } | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - /** | ||
| 155 | - * 所属机构圈子 | ||
| 156 | - */ | ||
| 157 | - public class CircleHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 158 | - private ItemCompanyDataTypeCircleChildBinding binding; | ||
| 159 | - | ||
| 160 | - public CircleHolder(@NonNull ItemCompanyDataTypeCircleChildBinding binding) { | ||
| 161 | - super(binding.getRoot()); | ||
| 162 | - this.binding = binding; | ||
| 163 | - binding.llCircleDelete.setOnClickListener(this); | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - @Override | ||
| 167 | - public void onClick(View v) { | ||
| 168 | - if (v.getId() == R.id.ll_circle_delete) { | ||
| 169 | - int removeIndex = getLayoutPosition(); | ||
| 170 | - dataList.remove(removeIndex); | ||
| 171 | - notifyItemRemoved(removeIndex); | ||
| 172 | - } | ||
| 173 | - } | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - /** | ||
| 177 | - * 添加圈子 | ||
| 178 | - */ | ||
| 179 | - public class AddCircleHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 180 | - private ItemCompanyDataTypeAddCircleBinding binding; | ||
| 181 | - | ||
| 182 | - public AddCircleHolder(@NonNull ItemCompanyDataTypeAddCircleBinding binding) { | ||
| 183 | - super(binding.getRoot()); | ||
| 184 | - this.binding = binding; | ||
| 185 | - binding.btnAddChildCircle.setOnClickListener(this); | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - @Override | ||
| 189 | - public void onClick(View v) { | ||
| 190 | - if (v.getId() == R.id.btn_addChildCircle) { | ||
| 191 | - //获取当前逻辑上的数量 | ||
| 192 | - int logicSize = dataList.get(getLayoutPosition()).getLogicPosition(); | ||
| 193 | - dataList.add(getLayoutPosition(), new CompanyItemData(CompanyItemData.TYPE_CIRCLE, logicSize, true)); | ||
| 194 | - notifyItemInserted(getLayoutPosition() + 1); | ||
| 195 | - } | ||
| 196 | - } | ||
| 197 | - } | ||
| 198 | - | ||
| 199 | - /** | ||
| 200 | - * 所属子账号 | ||
| 201 | - */ | ||
| 202 | - public class ChildAccountHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 203 | - private ItemCompanyDataTypeChildAccountBinding binding; | ||
| 204 | - | ||
| 205 | - public ChildAccountHolder(@NonNull ItemCompanyDataTypeChildAccountBinding binding) { | ||
| 206 | - super(binding.getRoot()); | ||
| 207 | - this.binding = binding; | ||
| 208 | - binding.llChildAccountDelete.setOnClickListener(this); | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - @Override | ||
| 212 | - public void onClick(View v) { | ||
| 213 | - if (v.getId() == R.id.ll_child_account_delete) { | ||
| 214 | - int removeIndex = getLayoutPosition(); | ||
| 215 | - dataList.remove(removeIndex); | ||
| 216 | - notifyItemRemoved(removeIndex); | ||
| 217 | - | ||
| 218 | - } | ||
| 219 | - } | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | - /** | ||
| 223 | - * 添加子账号 | ||
| 224 | - */ | ||
| 225 | - public class AddChildAccountHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 226 | - private ItemCompanyDataTypeAddChildAccountBinding binding; | ||
| 227 | - | ||
| 228 | - public AddChildAccountHolder(@NonNull ItemCompanyDataTypeAddChildAccountBinding binding) { | ||
| 229 | - super(binding.getRoot()); | ||
| 230 | - this.binding = binding; | ||
| 231 | - binding.btnAddChildAccount.setOnClickListener(this); | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - @Override | ||
| 235 | - public void onClick(View v) { | ||
| 236 | - if (v.getId() == R.id.btn_addChildAccount) { | ||
| 237 | - //获取当前逻辑上的数量 | ||
| 238 | - int logicSize = dataList.get(getLayoutPosition()).getLogicPosition(); | ||
| 239 | - dataList.add(getAdapterPosition(), new CompanyItemData(CompanyItemData.TYPE_CHILD_ACCOUNT, logicSize, true)); | ||
| 240 | - notifyItemInserted(getLayoutPosition() + 1); | ||
| 241 | - | ||
| 242 | - } | ||
| 243 | - } | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - /** | ||
| 247 | - * 添加机构 | ||
| 248 | - */ | ||
| 249 | - public class AddOrganizactionHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
| 250 | - private ItemCompanyDataTypeAddOrganizationBinding binding; | ||
| 251 | - | ||
| 252 | - public AddOrganizactionHolder(@NonNull ItemCompanyDataTypeAddOrganizationBinding binding) { | ||
| 253 | - super(binding.getRoot()); | ||
| 254 | - this.binding = binding; | ||
| 255 | - binding.btnAddOrganization.setOnClickListener(this); | ||
| 256 | - } | ||
| 257 | - | ||
| 258 | - @Override | ||
| 259 | - public void onClick(View v) { | ||
| 260 | - if (v.getId() == R.id.btn_addOrganization) { | ||
| 261 | - //获取当前逻辑上的数量 | ||
| 262 | - int logicSize = dataList.get(getLayoutPosition()).getLogicPosition(); | ||
| 263 | - int selectIndex = getLayoutPosition(); | ||
| 264 | - dataList.remove(dataList.size() - 1); | ||
| 265 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_ORGANIZATION, logicSize + 1, true, true)); | ||
| 266 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_CIRCLE, logicSize + 1)); | ||
| 267 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_ADD_CIRCLE, logicSize + 1)); | ||
| 268 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_CHILD_ACCOUNT, logicSize + 1)); | ||
| 269 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_ADD_CHILD_ACCOUNT, logicSize + 1)); | ||
| 270 | - dataList.add(new CompanyItemData(CompanyItemData.TYPE_ADD_ORGANIZATION, logicSize + 1)); | ||
| 271 | - notifyItemInserted(selectIndex); | ||
| 272 | - } | ||
| 273 | - } | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | - public interface OnClickListener { | ||
| 277 | - void onClick(TextView textView); | ||
| 278 | - } | ||
| 279 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/fragment/BottomSheetDialog.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.fragment; | ||
| 2 | - | ||
| 3 | -import android.os.Bundle; | ||
| 4 | -import android.view.LayoutInflater; | ||
| 5 | -import android.view.View; | ||
| 6 | -import android.view.ViewGroup; | ||
| 7 | - | ||
| 8 | -import androidx.annotation.NonNull; | ||
| 9 | -import androidx.annotation.Nullable; | ||
| 10 | - | ||
| 11 | -import com.cnlive.core.people_verfication.R; | ||
| 12 | -import com.google.android.material.bottomsheet.BottomSheetDialogFragment; | ||
| 13 | - | ||
| 14 | -public class BottomSheetDialog extends BottomSheetDialogFragment { | ||
| 15 | - @Nullable | ||
| 16 | - @Override | ||
| 17 | - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| 18 | - | ||
| 19 | - return inflater.inflate(R.layout.fragment_bottom, container, false); | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - @Override | ||
| 23 | - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
| 24 | - super.onViewCreated(view, savedInstanceState); | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - } | ||
| 28 | -} | ||
| 29 | \ No newline at end of file | 0 | \ No newline at end of file |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/fragment/FillInCompanyDataFragment.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.fragment; | ||
| 2 | - | ||
| 3 | -import android.os.Bundle; | ||
| 4 | -import android.view.View; | ||
| 5 | - | ||
| 6 | -import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | ||
| 7 | -import com.cnlive.core.people_verfication.R; | ||
| 8 | -import com.cnlive.core.people_verfication.databinding.FragmentFillInCompanyDataBinding; | ||
| 9 | - | ||
| 10 | -import androidx.databinding.ViewDataBinding; | ||
| 11 | - | ||
| 12 | -/* | ||
| 13 | - *@date:2020/4/7 14:50 | ||
| 14 | - *@author:杨帅 | ||
| 15 | - */public class FillInCompanyDataFragment extends BaseFragment { | ||
| 16 | - private FragmentFillInCompanyDataBinding binding; | ||
| 17 | - | ||
| 18 | - public static FillInCompanyDataFragment newInstance(String userId) { | ||
| 19 | - FillInCompanyDataFragment fragment = new FillInCompanyDataFragment(); | ||
| 20 | - Bundle args = new Bundle(); | ||
| 21 | - args.putString("userId", userId); | ||
| 22 | - fragment.setArguments(args); | ||
| 23 | - return fragment; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - @Override | ||
| 27 | - protected int getBindLayoutId() { | ||
| 28 | - return R.layout.fragment_fill_in_company_data; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - @Override | ||
| 32 | - protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 33 | - super.initBindingLayoutData(baseBinding); | ||
| 34 | - binding = (FragmentFillInCompanyDataBinding) baseBinding; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - @Override | ||
| 38 | - protected void initView() { | ||
| 39 | - showDefaultWhiteStatusBar(); | ||
| 40 | - binding.topbar.setTitle("填写公司信息"); | ||
| 41 | - binding.topbar.addLeftImageButton(R.drawable.icon_verficat_back,R.id.back_btn).setOnClickListener(new View.OnClickListener() { | ||
| 42 | - @Override | ||
| 43 | - public void onClick(View v) { | ||
| 44 | - me.finish(); | ||
| 45 | - } | ||
| 46 | - }); | ||
| 47 | - } | ||
| 48 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/fragment/SelectCompanyDataFragment.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.fragment; | ||
| 2 | - | ||
| 3 | -import android.os.Bundle; | ||
| 4 | -import android.view.View; | ||
| 5 | -import android.widget.TextView; | ||
| 6 | - | ||
| 7 | -import com.cnlive.core.company_verfication.ui.adapter.CompanyItemDataAdapter; | ||
| 8 | -import com.cnlive.core.company_verfication.ui.model.CompanyItemData; | ||
| 9 | -import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | ||
| 10 | -import com.cnlive.core.libs.base.util.StatusBarConfig; | ||
| 11 | -import com.cnlive.core.libs.base.util.StatusBarUtil; | ||
| 12 | -import com.cnlive.core.people_verfication.R; | ||
| 13 | -import com.cnlive.core.people_verfication.databinding.FragmentSelectInCompanyDataBinding; | ||
| 14 | -import com.google.android.material.bottomsheet.BottomSheetBehavior; | ||
| 15 | - | ||
| 16 | -import java.util.ArrayList; | ||
| 17 | -import java.util.List; | ||
| 18 | - | ||
| 19 | -import androidx.annotation.NonNull; | ||
| 20 | -import androidx.databinding.ViewDataBinding; | ||
| 21 | -import androidx.recyclerview.widget.LinearLayoutManager; | ||
| 22 | - | ||
| 23 | -/* | ||
| 24 | - *@date:2020/4/7 14:54 | ||
| 25 | - *@author:杨帅 | ||
| 26 | - */public class SelectCompanyDataFragment extends BaseFragment { | ||
| 27 | - private List<String> data = new ArrayList<>(); | ||
| 28 | - private FragmentSelectInCompanyDataBinding binding; | ||
| 29 | - private CompanyItemDataAdapter itemDataAdapter; | ||
| 30 | - private BottomSheetBehavior behavior; | ||
| 31 | - | ||
| 32 | - public static SelectCompanyDataFragment newInstance(String userId) { | ||
| 33 | - SelectCompanyDataFragment fragment = new SelectCompanyDataFragment(); | ||
| 34 | - Bundle args = new Bundle(); | ||
| 35 | - args.putString("userId", userId); | ||
| 36 | - fragment.setArguments(args); | ||
| 37 | - return fragment; | ||
| 38 | - } | ||
| 39 | - @Override | ||
| 40 | - protected int getBindLayoutId() { | ||
| 41 | - return R.layout.fragment_select_in_company_data; | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - @Override | ||
| 45 | - protected void initBindingLayoutData(ViewDataBinding baseBinding) { | ||
| 46 | - super.initBindingLayoutData(baseBinding); | ||
| 47 | - binding = (FragmentSelectInCompanyDataBinding) baseBinding; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - protected void initView() { | ||
| 52 | - //设置沉浸式状态栏 | ||
| 53 | - showImmersiveStatusBar(); | ||
| 54 | - //设置状态栏提示文字颜色 | ||
| 55 | - setStatusBarTextColor(StatusBarConfig.BLACK); | ||
| 56 | - initTopBar(); | ||
| 57 | - List<CompanyItemData> list = new ArrayList<>(); | ||
| 58 | - list.add(new CompanyItemData(CompanyItemData.TYPE_ORGANIZATION, 0)); | ||
| 59 | - list.add(new CompanyItemData(CompanyItemData.TYPE_CIRCLE, 0)); | ||
| 60 | - list.add(new CompanyItemData(CompanyItemData.TYPE_ADD_CIRCLE, 0)); | ||
| 61 | - list.add(new CompanyItemData(CompanyItemData.TYPE_CHILD_ACCOUNT, 0)); | ||
| 62 | - list.add(new CompanyItemData(CompanyItemData.TYPE_ADD_CHILD_ACCOUNT, 0)); | ||
| 63 | - list.add(new CompanyItemData(CompanyItemData.TYPE_ADD_ORGANIZATION, 0)); | ||
| 64 | - itemDataAdapter = new CompanyItemDataAdapter(me, list); | ||
| 65 | - binding.recyclerView.setLayoutManager(new LinearLayoutManager(me)); | ||
| 66 | - binding.recyclerView.setAdapter(itemDataAdapter); | ||
| 67 | - binding.viewMask.setVisibility(View.GONE); | ||
| 68 | - behavior = BottomSheetBehavior.from(binding.llBottom); | ||
| 69 | - behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | ||
| 70 | - @Override | ||
| 71 | - public void onStateChanged(@NonNull View bottomSheet, @BottomSheetBehavior.State int newState) { | ||
| 72 | - String state = "null"; | ||
| 73 | - switch (newState) { | ||
| 74 | - case 1: | ||
| 75 | - state = "STATE_DRAGGING";//过渡状态此时用户正在向上或者向下拖动bottom sheet | ||
| 76 | - break; | ||
| 77 | - case 2: | ||
| 78 | - state = "STATE_SETTLING"; // 视图从脱离手指自由滑动到最终停下的这一小段时间 | ||
| 79 | - break; | ||
| 80 | - case 3: | ||
| 81 | - state = "STATE_EXPANDED"; //处于完全展开的状态 | ||
| 82 | - | ||
| 83 | - break; | ||
| 84 | - case 4: | ||
| 85 | - state = "STATE_COLLAPSED"; //默认的折叠状态 | ||
| 86 | - binding.viewMask.setVisibility(View.GONE); | ||
| 87 | - break; | ||
| 88 | - case 5: | ||
| 89 | - state = "STATE_HIDDEN"; //下滑动完全隐藏 bottom sheet | ||
| 90 | - binding.viewMask.setVisibility(View.GONE); | ||
| 91 | - break; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - @Override | ||
| 97 | - public void onSlide(@NonNull View view, float v) { | ||
| 98 | - | ||
| 99 | - } | ||
| 100 | - }); | ||
| 101 | - //蒙版点击 | ||
| 102 | - binding.viewMask.setOnClickListener(new View.OnClickListener() { | ||
| 103 | - @Override | ||
| 104 | - public void onClick(View v) { | ||
| 105 | - if (!isNull(behavior)) { | ||
| 106 | - binding.viewMask.setVisibility(View.GONE); | ||
| 107 | - behavior.setState(BottomSheetBehavior.STATE_HIDDEN); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - }); | ||
| 111 | - | ||
| 112 | - itemDataAdapter.setOnClickListener(new CompanyItemDataAdapter.OnClickListener() { | ||
| 113 | - @Override | ||
| 114 | - public void onClick(TextView textView) { | ||
| 115 | - if (!isNull(behavior)) { | ||
| 116 | - binding.viewMask.setVisibility(View.VISIBLE); | ||
| 117 | - behavior.setState(BottomSheetBehavior.STATE_EXPANDED); | ||
| 118 | - } | ||
| 119 | -// BottomSheetDialog bottomSheetDialog=new BottomSheetDialog(); | ||
| 120 | -// bottomSheetDialog.show(getFragmentManager(),TAG); | ||
| 121 | - } | ||
| 122 | - }); | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - private void initTopBar() { | ||
| 126 | - // 设置标题栏的内容在状态栏之下 | ||
| 127 | - binding.topbar.setTitle("填写公司信息"); | ||
| 128 | - // 设置标题栏 + 状态栏的高度 | ||
| 129 | - setTitleViewAdjustImmersiveStatusBar(binding.llTop); | ||
| 130 | - binding.topbar.addLeftImageButton(R.drawable.icon_verficat_back, R.id.back_btn).setOnClickListener(new View.OnClickListener() { | ||
| 131 | - @Override | ||
| 132 | - public void onClick(View v) { | ||
| 133 | - me.finish(); | ||
| 134 | - } | ||
| 135 | - }); | ||
| 136 | - } | ||
| 137 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/company_verfication/ui/model/CompanyItemData.java deleted
100644 → 0
| 1 | -package com.cnlive.core.company_verfication.ui.model; | ||
| 2 | - | ||
| 3 | -/*机构数据 | ||
| 4 | - *@date:2020/4/7 16:24 | ||
| 5 | - *@author:杨帅 | ||
| 6 | - */public class CompanyItemData { | ||
| 7 | - public static final int TYPE_ORGANIZATION = 0;//所属机构 | ||
| 8 | - public static final int TYPE_CIRCLE = 1;//您的圈子 | ||
| 9 | - public static final int TYPE_ADD_CIRCLE = 2;//添加圈子 | ||
| 10 | - public static final int TYPE_CHILD_ACCOUNT = 3;//相关账号 | ||
| 11 | - public static final int TYPE_ADD_CHILD_ACCOUNT = 4;//添加子账号 | ||
| 12 | - public static final int TYPE_ADD_ORGANIZATION = 5;//添加机构 | ||
| 13 | - | ||
| 14 | - private int type; | ||
| 15 | - private boolean showDelete; | ||
| 16 | - private int logicPosition;//逻辑上数量 | ||
| 17 | - private boolean showTopLine; | ||
| 18 | - private boolean showOrganizactionDelete; | ||
| 19 | - | ||
| 20 | - public int getType() { | ||
| 21 | - return type; | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | - public void setType(int type) { | ||
| 25 | - this.type = type; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - public boolean isShowDelete() { | ||
| 29 | - return showDelete; | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public void setShowDelete(boolean showDelete) { | ||
| 33 | - this.showDelete = showDelete; | ||
| 34 | - } | ||
| 35 | - public CompanyItemData(int type, int logicPosition) { | ||
| 36 | - this.type = type; | ||
| 37 | - this.logicPosition = logicPosition; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - public CompanyItemData(int type, int logicPosition, boolean showTopLine, boolean showOrganizactionDelete) { | ||
| 41 | - this.type = type; | ||
| 42 | - this.logicPosition = logicPosition; | ||
| 43 | - this.showTopLine = showTopLine; | ||
| 44 | - this.showOrganizactionDelete = showOrganizactionDelete; | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - public CompanyItemData(int type, int logicPosition, boolean showDelete) { | ||
| 48 | - this.type = type; | ||
| 49 | - this.logicPosition = logicPosition; | ||
| 50 | - this.showDelete = showDelete; | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - public boolean isShowTopLine() { | ||
| 54 | - return showTopLine; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - public void setShowTopLine(boolean showTopLine) { | ||
| 58 | - this.showTopLine = showTopLine; | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - public int getLogicPosition() { | ||
| 62 | - return logicPosition; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - public void setLogicPosition(int logicPosition) { | ||
| 66 | - this.logicPosition = logicPosition; | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - public boolean isShowOrganizactionDelete() { | ||
| 70 | - return showOrganizactionDelete; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - public void setShowOrganizactionDelete(boolean showOrganizactionDelete) { | ||
| 74 | - this.showOrganizactionDelete = showOrganizactionDelete; | ||
| 75 | - } | ||
| 76 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/ocr/RecognizeService.java deleted
100644 → 0
| 1 | -package com.cnlive.core.ocr; | ||
| 2 | - | ||
| 3 | -import android.content.Context; | ||
| 4 | -import android.util.Log; | ||
| 5 | - | ||
| 6 | -import com.baidu.ocr.sdk.OCR; | ||
| 7 | -import com.baidu.ocr.sdk.OnResultListener; | ||
| 8 | -import com.baidu.ocr.sdk.exception.OCRError; | ||
| 9 | -import com.baidu.ocr.sdk.model.AccessToken; | ||
| 10 | -import com.baidu.ocr.sdk.model.BankCardParams; | ||
| 11 | -import com.baidu.ocr.sdk.model.BankCardResult; | ||
| 12 | -import com.baidu.ocr.sdk.model.IDCardParams; | ||
| 13 | -import com.baidu.ocr.sdk.model.IDCardResult; | ||
| 14 | - | ||
| 15 | -import java.io.File; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * @author Lynn | ||
| 19 | - * @date 2018/1/4 | ||
| 20 | - */ | ||
| 21 | - | ||
| 22 | -public class RecognizeService { | ||
| 23 | - | ||
| 24 | - /** | ||
| 25 | - * 识别银行卡 | ||
| 26 | - * | ||
| 27 | - * @param filePath 文件路径 | ||
| 28 | - * @param listener 回调 | ||
| 29 | - */ | ||
| 30 | - public static void recBankCard(String filePath, OnResultListener<BankCardResult> listener) { | ||
| 31 | - BankCardParams params = new BankCardParams(); | ||
| 32 | - params.setImageFile(new File(filePath)); | ||
| 33 | - OCR.getInstance().recognizeBankCard(params, listener); | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * 识别身份证 | ||
| 38 | - * | ||
| 39 | - * @param idCardSide 身份证正反面 | ||
| 40 | - * @param filePath 文件路径 | ||
| 41 | - * @param listener 回调 | ||
| 42 | - */ | ||
| 43 | - public static void recIDCard(String idCardSide, String filePath, OnResultListener<IDCardResult> listener) { | ||
| 44 | - IDCardParams param = new IDCardParams(); | ||
| 45 | - param.setImageFile(new File(filePath)); | ||
| 46 | - // 设置身份证正反面 | ||
| 47 | - param.setIdCardSide(idCardSide); | ||
| 48 | - // 设置方向检测 | ||
| 49 | - param.setDetectDirection(true); | ||
| 50 | - // 设置图像参数压缩质量0-100, 越大图像质量越好但是请求时间越长。 不设置则默认值为20 | ||
| 51 | - param.setImageQuality(20); | ||
| 52 | - OCR.getInstance().recognizeIDCard(param, listener); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * 初始化 with AK & SK | ||
| 57 | - * | ||
| 58 | - * @param context context | ||
| 59 | - */ | ||
| 60 | - public static void initAccessTokenWithAkSk(final Context context) { | ||
| 61 | - OCR.getInstance().initAccessTokenWithAkSk(new OnResultListener<AccessToken>() { | ||
| 62 | - @Override | ||
| 63 | - public void onResult(AccessToken result) { | ||
| 64 | - String token = result.getAccessToken(); | ||
| 65 | - Log.e("LynnTest", result.toString()); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - public void onError(OCRError error) { | ||
| 70 | - error.printStackTrace(); | ||
| 71 | - Log.e("LynnTest", error.getMessage()); | ||
| 72 | - } | ||
| 73 | - }, context, "YIGsVzdh35y3GCaNUDsxM3cC", "neAe1orXgeTaiHkAbygrgCevKe1fPrG1"); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - /** | ||
| 77 | - * 初始化 授权文件(安全模式) | ||
| 78 | - * | ||
| 79 | - * @param context | ||
| 80 | - */ | ||
| 81 | - public static void initAccessToken(Context context) { | ||
| 82 | - OCR.getInstance().initAccessToken(new OnResultListener<AccessToken>() { | ||
| 83 | - @Override | ||
| 84 | - public void onResult(AccessToken accessToken) { | ||
| 85 | - String token = accessToken.getAccessToken(); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @Override | ||
| 89 | - public void onError(OCRError ocrError) { | ||
| 90 | - | ||
| 91 | - } | ||
| 92 | - }, context); | ||
| 93 | - } | ||
| 94 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/ocr/idcardquality/IDcardQualityProcess.java deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. | ||
| 3 | - */ | ||
| 4 | -package com.cnlive.core.ocr.idcardquality; | ||
| 5 | - | ||
| 6 | -import android.content.res.AssetManager; | ||
| 7 | -import android.graphics.Bitmap; | ||
| 8 | - | ||
| 9 | -import com.baidu.idl.authority.AlgorithmOnMainThreadException; | ||
| 10 | -import com.baidu.idl.authority.IDLAuthorityException; | ||
| 11 | -import com.baidu.idl.license.License; | ||
| 12 | -import com.baidu.idl.util.UIThread; | ||
| 13 | - | ||
| 14 | - | ||
| 15 | -public class IDcardQualityProcess { | ||
| 16 | - | ||
| 17 | - private static IDcardQualityProcess mInstance; | ||
| 18 | - private static String tokenString; | ||
| 19 | - private static int mAuthorityStatus; | ||
| 20 | - private static Throwable loadNativeException = null; | ||
| 21 | - private static volatile boolean hasReleased; | ||
| 22 | - | ||
| 23 | - public IDcardQualityProcess() { | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - public static synchronized IDcardQualityProcess getInstance() { | ||
| 27 | - if (null == mInstance) { | ||
| 28 | - mInstance = new IDcardQualityProcess(); | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - return mInstance; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - public native byte[] convertRGBImage(int[] colors, int width, int height); | ||
| 35 | - | ||
| 36 | - public native int idcardQualityModelInit(AssetManager var1, String var2); | ||
| 37 | - | ||
| 38 | - public native int idcardQualityCaptchaRelease(); | ||
| 39 | - | ||
| 40 | - public native int idcardQualityProcess(byte[] var1, int var2, int var3, boolean var4, int var5); | ||
| 41 | - | ||
| 42 | - public static synchronized int init(String token) throws AlgorithmOnMainThreadException, IDLAuthorityException { | ||
| 43 | - if (UIThread.isUITread()) { | ||
| 44 | - throw new AlgorithmOnMainThreadException(); | ||
| 45 | - } else { | ||
| 46 | - tokenString = token; | ||
| 47 | - | ||
| 48 | - try { | ||
| 49 | - mAuthorityStatus = License.getInstance().init(tokenString); | ||
| 50 | - } catch (Exception var2) { | ||
| 51 | - if (var2!=null) | ||
| 52 | - var2.printStackTrace(); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - return mAuthorityStatus; | ||
| 56 | - } | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - public int idcardQualityInit(AssetManager assetManager, String modelPath) { | ||
| 60 | - if (mAuthorityStatus == 0) { | ||
| 61 | - hasReleased = false; | ||
| 62 | - return this.idcardQualityModelInit(assetManager, modelPath); | ||
| 63 | - } else { | ||
| 64 | - return mAuthorityStatus; | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - public int idcardQualityRelease() { | ||
| 69 | - if (mAuthorityStatus == 0) { | ||
| 70 | - hasReleased = true; | ||
| 71 | - this.idcardQualityCaptchaRelease(); | ||
| 72 | - return 0; | ||
| 73 | - } else { | ||
| 74 | - return mAuthorityStatus; | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - public int idcardQualityDetectionImg(Bitmap img, boolean isfont) { | ||
| 79 | - if (mAuthorityStatus == 0) { | ||
| 80 | - if (hasReleased) { | ||
| 81 | - return -1; | ||
| 82 | - } | ||
| 83 | - int imgHeight = img.getHeight(); | ||
| 84 | - int imgWidth = img.getWidth(); | ||
| 85 | - byte[] imageData = this.getRGBImageData(img); | ||
| 86 | - return this.idcardQualityProcess(imageData, imgHeight, imgWidth, isfont, 3); | ||
| 87 | - } else { | ||
| 88 | - return mAuthorityStatus; | ||
| 89 | - } | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - public static Throwable getLoadSoException() { | ||
| 93 | - return loadNativeException; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - public byte[] getRGBImageData(Bitmap img) { | ||
| 97 | - int imgWidth = img.getWidth(); | ||
| 98 | - int imgHeight = img.getHeight(); | ||
| 99 | - int[] pixels = new int[imgWidth * imgHeight]; | ||
| 100 | - img.getPixels(pixels, 0, imgWidth, 0, 0, imgWidth, imgHeight); | ||
| 101 | - byte[] imageData = convertRGBImage(pixels, imgWidth, imgHeight); | ||
| 102 | - return imageData; | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - public void releaseModel() { | ||
| 106 | - this.idcardQualityRelease(); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - static { | ||
| 110 | - try { | ||
| 111 | - System.loadLibrary("idl_license"); | ||
| 112 | - System.loadLibrary("idcard_quality.1.1.1"); | ||
| 113 | - } catch (Throwable e) { | ||
| 114 | - loadNativeException = e; | ||
| 115 | - } | ||
| 116 | - mInstance = null; | ||
| 117 | - mAuthorityStatus = 256; | ||
| 118 | - } | ||
| 119 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/ocr/ui/camera/Camera1Control.java deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. | ||
| 3 | - */ | ||
| 4 | -package com.cnlive.core.ocr.ui.camera; | ||
| 5 | - | ||
| 6 | -import android.Manifest; | ||
| 7 | -import android.content.Context; | ||
| 8 | -import android.content.pm.FeatureInfo; | ||
| 9 | -import android.content.pm.PackageManager; | ||
| 10 | -import android.graphics.ImageFormat; | ||
| 11 | -import android.graphics.Rect; | ||
| 12 | -import android.graphics.SurfaceTexture; | ||
| 13 | -import android.graphics.YuvImage; | ||
| 14 | -import android.hardware.Camera; | ||
| 15 | -import android.os.Build; | ||
| 16 | -import android.util.Log; | ||
| 17 | -import android.view.TextureView; | ||
| 18 | -import android.view.View; | ||
| 19 | -import android.widget.FrameLayout; | ||
| 20 | - | ||
| 21 | -import com.cnlive.core.libs.base.util.AlertUtil; | ||
| 22 | - | ||
| 23 | -import java.io.ByteArrayOutputStream; | ||
| 24 | -import java.io.IOException; | ||
| 25 | -import java.util.ArrayList; | ||
| 26 | -import java.util.Collections; | ||
| 27 | -import java.util.Comparator; | ||
| 28 | -import java.util.List; | ||
| 29 | -import java.util.concurrent.atomic.AtomicBoolean; | ||
| 30 | - | ||
| 31 | -import androidx.core.app.ActivityCompat; | ||
| 32 | - | ||
| 33 | -/** | ||
| 34 | - * 5.0以下相机API的封装。 | ||
| 35 | - */ | ||
| 36 | -@SuppressWarnings("deprecation") | ||
| 37 | -public class Camera1Control implements ICameraControl { | ||
| 38 | - | ||
| 39 | - private int displayOrientation = 0; | ||
| 40 | - private int cameraId = 0; | ||
| 41 | - private int flashMode; | ||
| 42 | - private AtomicBoolean takingPicture = new AtomicBoolean(false); | ||
| 43 | - private AtomicBoolean abortingScan = new AtomicBoolean(false); | ||
| 44 | - private Context context; | ||
| 45 | - private Camera camera; | ||
| 46 | - | ||
| 47 | - private Camera.Parameters parameters; | ||
| 48 | - private PermissionCallback permissionCallback; | ||
| 49 | - private Rect previewFrame = new Rect(); | ||
| 50 | - | ||
| 51 | - private PreviewView previewView; | ||
| 52 | - private View displayView; | ||
| 53 | - private int rotation = 0; | ||
| 54 | - private OnDetectPictureCallback detectCallback; | ||
| 55 | - private int previewFrameCount = 0; | ||
| 56 | - private Camera.Size optSize; | ||
| 57 | - | ||
| 58 | - /* | ||
| 59 | - * 非扫描模式 | ||
| 60 | - */ | ||
| 61 | - private final int MODEL_NOSCAN = 0; | ||
| 62 | - | ||
| 63 | - /* | ||
| 64 | - * 本地质量控制扫描模式 | ||
| 65 | - */ | ||
| 66 | - private final int MODEL_SCAN = 1; | ||
| 67 | - | ||
| 68 | - private int detectType = MODEL_NOSCAN; | ||
| 69 | - | ||
| 70 | - public int getCameraRotation() { | ||
| 71 | - return rotation; | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - public AtomicBoolean getAbortingScan() { | ||
| 75 | - return abortingScan; | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - @Override | ||
| 79 | - public void setDetectCallback(OnDetectPictureCallback callback) { | ||
| 80 | - detectType = MODEL_SCAN; | ||
| 81 | - detectCallback = callback; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - private void onRequestDetect(byte[] data) { | ||
| 85 | - // 相机已经关闭 | ||
| 86 | - if (camera == null || data == null) { | ||
| 87 | - return; | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - YuvImage img = new YuvImage(data, ImageFormat.NV21, optSize.width, optSize.height, null); | ||
| 91 | - ByteArrayOutputStream os = null; | ||
| 92 | - try { | ||
| 93 | - os = new ByteArrayOutputStream(data.length); | ||
| 94 | - img.compressToJpeg(new Rect(0, 0, optSize.width, optSize.height), 80, os); | ||
| 95 | - byte[] jpeg = os.toByteArray(); | ||
| 96 | - int status = detectCallback.onDetect(jpeg, getCameraRotation()); | ||
| 97 | - | ||
| 98 | - if (status == 0) { | ||
| 99 | - clearPreviewCallback(); | ||
| 100 | - } | ||
| 101 | - } catch (OutOfMemoryError e) { | ||
| 102 | - // 内存溢出则取消当次操作 | ||
| 103 | - } finally { | ||
| 104 | - try { | ||
| 105 | - os.close(); | ||
| 106 | - } catch (Throwable e) { | ||
| 107 | - e.printStackTrace(); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - @Override | ||
| 114 | - public void setDisplayOrientation(@CameraView.Orientation int displayOrientation) { | ||
| 115 | - this.displayOrientation = displayOrientation; | ||
| 116 | - switch (displayOrientation) { | ||
| 117 | - case CameraView.ORIENTATION_PORTRAIT: | ||
| 118 | - rotation = 90; | ||
| 119 | - break; | ||
| 120 | - case CameraView.ORIENTATION_HORIZONTAL: | ||
| 121 | - rotation = 0; | ||
| 122 | - break; | ||
| 123 | - case CameraView.ORIENTATION_INVERT: | ||
| 124 | - rotation = 180; | ||
| 125 | - break; | ||
| 126 | - default: | ||
| 127 | - rotation = 0; | ||
| 128 | - } | ||
| 129 | - previewView.requestLayout(); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - /** | ||
| 133 | - * {@inheritDoc} | ||
| 134 | - */ | ||
| 135 | - @Override | ||
| 136 | - public void refreshPermission() { | ||
| 137 | - startPreview(true); | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - /** | ||
| 141 | - * {@inheritDoc} | ||
| 142 | - */ | ||
| 143 | - @Override | ||
| 144 | - public void setFlashMode(@FlashMode int flashMode) { | ||
| 145 | - if (this.flashMode == flashMode) { | ||
| 146 | - return; | ||
| 147 | - } | ||
| 148 | - this.flashMode = flashMode; | ||
| 149 | - updateFlashMode(flashMode); | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - @Override | ||
| 153 | - public int getFlashMode() { | ||
| 154 | - return flashMode; | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - @Override | ||
| 158 | - public void start() { | ||
| 159 | - | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - @Override | ||
| 163 | - public void stop() { | ||
| 164 | - if (camera != null) { | ||
| 165 | - camera.setPreviewCallback(null); | ||
| 166 | - stopPreview(); | ||
| 167 | - // 避免同步代码,为了先设置null后release | ||
| 168 | - Camera tempC = camera; | ||
| 169 | - camera = null; | ||
| 170 | - tempC.release(); | ||
| 171 | - camera = null; | ||
| 172 | - buffer = null; | ||
| 173 | - } | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - private void stopPreview() { | ||
| 177 | - if (camera != null) { | ||
| 178 | - camera.stopPreview(); | ||
| 179 | - } | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - @Override | ||
| 183 | - public void pause() { | ||
| 184 | - if (camera != null) { | ||
| 185 | - stopPreview(); | ||
| 186 | - } | ||
| 187 | - setFlashMode(FLASH_MODE_OFF); | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - @Override | ||
| 191 | - public void resume() { | ||
| 192 | - takingPicture.set(false); | ||
| 193 | - if (camera == null) { | ||
| 194 | - openCamera(); | ||
| 195 | - } else { | ||
| 196 | - previewView.textureView.setSurfaceTextureListener(surfaceTextureListener); | ||
| 197 | - if (previewView.textureView.isAvailable()) { | ||
| 198 | - startPreview(false); | ||
| 199 | - } | ||
| 200 | - } | ||
| 201 | - } | ||
| 202 | - | ||
| 203 | - @Override | ||
| 204 | - public View getDisplayView() { | ||
| 205 | - return displayView; | ||
| 206 | - } | ||
| 207 | - | ||
| 208 | - @Override | ||
| 209 | - public void takePicture(final OnTakePictureCallback onTakePictureCallback) { | ||
| 210 | - if (takingPicture.get()) { | ||
| 211 | - return; | ||
| 212 | - } | ||
| 213 | - try { | ||
| 214 | - switch (displayOrientation) { | ||
| 215 | - case CameraView.ORIENTATION_PORTRAIT: | ||
| 216 | - parameters.setRotation(90); | ||
| 217 | - break; | ||
| 218 | - case CameraView.ORIENTATION_HORIZONTAL: | ||
| 219 | - parameters.setRotation(0); | ||
| 220 | - break; | ||
| 221 | - case CameraView.ORIENTATION_INVERT: | ||
| 222 | - parameters.setRotation(180); | ||
| 223 | - break; | ||
| 224 | - } | ||
| 225 | - Camera.Size picSize = getOptimalSize(camera.getParameters().getSupportedPictureSizes()); | ||
| 226 | - parameters.setPictureSize(picSize.width, picSize.height); | ||
| 227 | - camera.setParameters(parameters); | ||
| 228 | - takingPicture.set(true); | ||
| 229 | - | ||
| 230 | - camera.takePicture(null, null, new Camera.PictureCallback() { | ||
| 231 | - @Override | ||
| 232 | - public void onPictureTaken(byte[] data, Camera camera) { | ||
| 233 | - startPreview(false); | ||
| 234 | - takingPicture.set(false); | ||
| 235 | - if (onTakePictureCallback != null) { | ||
| 236 | - onTakePictureCallback.onPictureTaken(data); | ||
| 237 | - } | ||
| 238 | - } | ||
| 239 | - }); | ||
| 240 | - } catch (RuntimeException e) { | ||
| 241 | - e.printStackTrace(); | ||
| 242 | - startPreview(false); | ||
| 243 | - ; | ||
| 244 | - takingPicture.set(false); | ||
| 245 | - } | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - @Override | ||
| 249 | - public void setPermissionCallback(PermissionCallback callback) { | ||
| 250 | - this.permissionCallback = callback; | ||
| 251 | - } | ||
| 252 | - | ||
| 253 | - public Camera1Control(Context context) { | ||
| 254 | - this.context = context; | ||
| 255 | - previewView = new PreviewView(context); | ||
| 256 | - openCamera(); | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - private void openCamera() { | ||
| 260 | - setupDisplayView(); | ||
| 261 | - } | ||
| 262 | - | ||
| 263 | - private void setupDisplayView() { | ||
| 264 | - final TextureView textureView = new TextureView(context); | ||
| 265 | - previewView.textureView = textureView; | ||
| 266 | - previewView.setTextureView(textureView); | ||
| 267 | - displayView = previewView; | ||
| 268 | - textureView.setSurfaceTextureListener(surfaceTextureListener); | ||
| 269 | - } | ||
| 270 | - | ||
| 271 | - private SurfaceTexture surfaceCache; | ||
| 272 | - | ||
| 273 | - private byte[] buffer = null; | ||
| 274 | - | ||
| 275 | - private void setPreviewCallbackImpl() { | ||
| 276 | - if (buffer == null) { | ||
| 277 | - buffer = new byte[displayView.getWidth() | ||
| 278 | - * displayView.getHeight() * ImageFormat.getBitsPerPixel(ImageFormat.NV21) / 8]; | ||
| 279 | - } | ||
| 280 | - if (camera != null && detectType == MODEL_SCAN) { | ||
| 281 | - camera.addCallbackBuffer(buffer); | ||
| 282 | - camera.setPreviewCallback(previewCallback); | ||
| 283 | - } | ||
| 284 | - } | ||
| 285 | - | ||
| 286 | - private void clearPreviewCallback() { | ||
| 287 | - if (camera != null && detectType == MODEL_SCAN) { | ||
| 288 | - camera.setPreviewCallback(null); | ||
| 289 | - stopPreview(); | ||
| 290 | - } | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | - Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() { | ||
| 294 | - @Override | ||
| 295 | - public void onPreviewFrame(final byte[] data, Camera camera) { | ||
| 296 | - // 扫描成功阻止打开新线程处理 | ||
| 297 | - if (abortingScan.get()) { | ||
| 298 | - return; | ||
| 299 | - } | ||
| 300 | - // 节流 | ||
| 301 | - if (previewFrameCount++ % 5 != 0) { | ||
| 302 | - return; | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - // 在某些机型和某项项目中,某些帧的data的数据不符合nv21的格式,需要过滤,否则后续处理会导致crash | ||
| 306 | - if (data.length != parameters.getPreviewSize().width * parameters.getPreviewSize().height * 1.5) { | ||
| 307 | - return; | ||
| 308 | - } | ||
| 309 | - | ||
| 310 | - camera.addCallbackBuffer(buffer); | ||
| 311 | - | ||
| 312 | - CameraThreadPool.execute(new Runnable() { | ||
| 313 | - @Override | ||
| 314 | - public void run() { | ||
| 315 | - Camera1Control.this.onRequestDetect(data); | ||
| 316 | - } | ||
| 317 | - }); | ||
| 318 | - } | ||
| 319 | - }; | ||
| 320 | - | ||
| 321 | - | ||
| 322 | - private void initCamera() { | ||
| 323 | - try { | ||
| 324 | - if (camera == null) { | ||
| 325 | - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); | ||
| 326 | - for (int i = 0; i < Camera.getNumberOfCameras(); i++) { | ||
| 327 | - Camera.getCameraInfo(i, cameraInfo); | ||
| 328 | - if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { | ||
| 329 | - cameraId = i; | ||
| 330 | - } | ||
| 331 | - } | ||
| 332 | - try { | ||
| 333 | - camera = Camera.open(cameraId); | ||
| 334 | - } catch (Throwable e) { | ||
| 335 | - e.printStackTrace(); | ||
| 336 | - startPreview(true); | ||
| 337 | - return; | ||
| 338 | - } | ||
| 339 | - | ||
| 340 | - } | ||
| 341 | - if (parameters == null) { | ||
| 342 | - parameters = camera.getParameters(); | ||
| 343 | - parameters.setPreviewFormat(ImageFormat.NV21); | ||
| 344 | - } | ||
| 345 | - opPreviewSize(previewView.getWidth(), previewView.getHeight()); | ||
| 346 | - camera.setPreviewTexture(surfaceCache); | ||
| 347 | - setPreviewCallbackImpl(); | ||
| 348 | - startPreview(false); | ||
| 349 | - } catch (IOException e) { | ||
| 350 | - e.printStackTrace(); | ||
| 351 | - } | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - private TextureView.SurfaceTextureListener surfaceTextureListener = new TextureView.SurfaceTextureListener() { | ||
| 355 | - @Override | ||
| 356 | - public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { | ||
| 357 | - surfaceCache = surface; | ||
| 358 | - initCamera(); | ||
| 359 | - } | ||
| 360 | - | ||
| 361 | - @Override | ||
| 362 | - public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { | ||
| 363 | - opPreviewSize(previewView.getWidth(), previewView.getHeight()); | ||
| 364 | - setPreviewCallbackImpl(); | ||
| 365 | - } | ||
| 366 | - | ||
| 367 | - @Override | ||
| 368 | - public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { | ||
| 369 | - return false; | ||
| 370 | - } | ||
| 371 | - | ||
| 372 | - @Override | ||
| 373 | - public void onSurfaceTextureUpdated(SurfaceTexture surface) { | ||
| 374 | - setPreviewCallbackImpl(); | ||
| 375 | - } | ||
| 376 | - }; | ||
| 377 | - | ||
| 378 | - // 开启预览 | ||
| 379 | - private void startPreview(boolean checkPermission) { | ||
| 380 | - if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) | ||
| 381 | - != PackageManager.PERMISSION_GRANTED) { | ||
| 382 | - if (checkPermission && permissionCallback != null) { | ||
| 383 | - permissionCallback.onRequestPermission(); | ||
| 384 | - } | ||
| 385 | - return; | ||
| 386 | - } | ||
| 387 | - if (camera == null) { | ||
| 388 | - initCamera(); | ||
| 389 | - } else { | ||
| 390 | - try { | ||
| 391 | - camera.startPreview(); | ||
| 392 | - CameraThreadPool.createAutoFocusTimerTask(new Runnable() { | ||
| 393 | - @Override | ||
| 394 | - public void run() { | ||
| 395 | - synchronized (Camera1Control.this) { | ||
| 396 | - if (camera != null && !takingPicture.get()) { | ||
| 397 | - try { | ||
| 398 | - camera.autoFocus(new Camera.AutoFocusCallback() { | ||
| 399 | - @Override | ||
| 400 | - public void onAutoFocus(boolean success, Camera camera) { | ||
| 401 | - } | ||
| 402 | - }); | ||
| 403 | - } catch (Throwable e) { | ||
| 404 | - // startPreview是异步实现,可能在某些机器上前几次调用会autofocus failß | ||
| 405 | - } | ||
| 406 | - } | ||
| 407 | - } | ||
| 408 | - } | ||
| 409 | - }); | ||
| 410 | - } catch (Exception e) { | ||
| 411 | - Log.e("ocr_ui startPreview", "startPreview: " + (e == null ? "" : e.getMessage())); | ||
| 412 | - } | ||
| 413 | - } | ||
| 414 | - } | ||
| 415 | - | ||
| 416 | - private void opPreviewSize(int width, @SuppressWarnings("unused") int height) { | ||
| 417 | - | ||
| 418 | - if (parameters != null && camera != null && width > 0) { | ||
| 419 | - try { | ||
| 420 | - optSize = getOptimalSize(camera.getParameters().getSupportedPreviewSizes()); | ||
| 421 | - }catch (Exception e){ | ||
| 422 | - e.printStackTrace(); | ||
| 423 | - } | ||
| 424 | - optSize = getOptimalSize(camera.getParameters().getSupportedPreviewSizes()); | ||
| 425 | - parameters.setPreviewSize(optSize.width, optSize.height); | ||
| 426 | - previewView.setRatio(1.0f * optSize.width / optSize.height); | ||
| 427 | - | ||
| 428 | - camera.setDisplayOrientation(getSurfaceOrientation()); | ||
| 429 | - stopPreview(); | ||
| 430 | - try { | ||
| 431 | - camera.setParameters(parameters); | ||
| 432 | - } catch (RuntimeException e) { | ||
| 433 | - e.printStackTrace(); | ||
| 434 | - | ||
| 435 | - } | ||
| 436 | - startPreview(false); | ||
| 437 | - } | ||
| 438 | - } | ||
| 439 | - | ||
| 440 | - private Camera.Size getOptimalSize(List<Camera.Size> sizes) { | ||
| 441 | - int width = previewView.textureView.getWidth(); | ||
| 442 | - int height = previewView.textureView.getHeight(); | ||
| 443 | - Camera.Size pictureSize = sizes.get(0); | ||
| 444 | - | ||
| 445 | - List<Camera.Size> candidates = new ArrayList<>(); | ||
| 446 | - | ||
| 447 | - for (Camera.Size size : sizes) { | ||
| 448 | - if (size.width >= width && size.height >= height && size.width * height == size.height * width) { | ||
| 449 | - // 比例相同 | ||
| 450 | - candidates.add(size); | ||
| 451 | - } else if (size.height >= width && size.width >= height && size.width * width == size.height * height) { | ||
| 452 | - // 反比例 | ||
| 453 | - candidates.add(size); | ||
| 454 | - } | ||
| 455 | - } | ||
| 456 | - if (!candidates.isEmpty()) { | ||
| 457 | - return Collections.min(candidates, sizeComparator); | ||
| 458 | - } | ||
| 459 | - | ||
| 460 | - for (Camera.Size size : sizes) { | ||
| 461 | - if (size.width > width && size.height > height) { | ||
| 462 | - return size; | ||
| 463 | - } | ||
| 464 | - } | ||
| 465 | - | ||
| 466 | - return pictureSize; | ||
| 467 | - } | ||
| 468 | - | ||
| 469 | - private Comparator<Camera.Size> sizeComparator = new Comparator<Camera.Size>() { | ||
| 470 | - @Override | ||
| 471 | - public int compare(Camera.Size lhs, Camera.Size rhs) { | ||
| 472 | - return Long.signum((long) lhs.width * lhs.height - (long) rhs.width * rhs.height); | ||
| 473 | - } | ||
| 474 | - }; | ||
| 475 | - | ||
| 476 | - private void updateFlashMode(int flashMode) { | ||
| 477 | - switch (flashMode) { | ||
| 478 | - case FLASH_MODE_TORCH: | ||
| 479 | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| 480 | - try { | ||
| 481 | - parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); | ||
| 482 | - } catch (Exception e) { | ||
| 483 | - e.printStackTrace(); | ||
| 484 | - } | ||
| 485 | - }else { | ||
| 486 | - boolean isUse = false; | ||
| 487 | - PackageManager packageManager = context.getPackageManager(); | ||
| 488 | - FeatureInfo[] features = packageManager.getSystemAvailableFeatures(); | ||
| 489 | - for (FeatureInfo featureInfo : features) { | ||
| 490 | - if (PackageManager.FEATURE_CAMERA_FLASH.equals(featureInfo.name)) { // 断设备是否支持闪光灯 | ||
| 491 | - try { | ||
| 492 | - parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); | ||
| 493 | - isUse = true; | ||
| 494 | - } catch (Exception e) { | ||
| 495 | - e.printStackTrace(); | ||
| 496 | - } | ||
| 497 | - } | ||
| 498 | - } | ||
| 499 | - if(!isUse) AlertUtil.showDeftToast(context,"该设备不支持闪光灯"); | ||
| 500 | - } | ||
| 501 | - break; | ||
| 502 | - case FLASH_MODE_OFF: | ||
| 503 | - parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); | ||
| 504 | - break; | ||
| 505 | - case ICameraControl.FLASH_MODE_AUTO: | ||
| 506 | - parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); | ||
| 507 | - break; | ||
| 508 | - default: | ||
| 509 | - parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); | ||
| 510 | - break; | ||
| 511 | - } | ||
| 512 | - if (parameters == null || camera == null) | ||
| 513 | - return; | ||
| 514 | - camera.setParameters(parameters); | ||
| 515 | - } | ||
| 516 | - | ||
| 517 | - private int getSurfaceOrientation() { | ||
| 518 | - @CameraView.Orientation | ||
| 519 | - int orientation = displayOrientation; | ||
| 520 | - switch (orientation) { | ||
| 521 | - case CameraView.ORIENTATION_PORTRAIT: | ||
| 522 | - return 90; | ||
| 523 | - case CameraView.ORIENTATION_HORIZONTAL: | ||
| 524 | - return 0; | ||
| 525 | - case CameraView.ORIENTATION_INVERT: | ||
| 526 | - return 180; | ||
| 527 | - default: | ||
| 528 | - return 90; | ||
| 529 | - } | ||
| 530 | - } | ||
| 531 | - | ||
| 532 | - /** | ||
| 533 | - * 有些相机匹配不到完美的比例。比如。我们的layout是4:3的。预览只有16:9 | ||
| 534 | - * 的,如果直接显示图片会拉伸,变形。缩放的话,又有黑边。所以我们采取的策略 | ||
| 535 | - * 是,等比例放大。这样预览的有一部分会超出屏幕。拍照后再进行裁剪处理。 | ||
| 536 | - */ | ||
| 537 | - private class PreviewView extends FrameLayout { | ||
| 538 | - | ||
| 539 | - private TextureView textureView; | ||
| 540 | - | ||
| 541 | - private float ratio = 0.75f; | ||
| 542 | - | ||
| 543 | - void setTextureView(TextureView textureView) { | ||
| 544 | - this.textureView = textureView; | ||
| 545 | - removeAllViews(); | ||
| 546 | - addView(textureView); | ||
| 547 | - } | ||
| 548 | - | ||
| 549 | - void setRatio(float ratio) { | ||
| 550 | - this.ratio = ratio; | ||
| 551 | - requestLayout(); | ||
| 552 | - relayout(getWidth(), getHeight()); | ||
| 553 | - } | ||
| 554 | - | ||
| 555 | - public PreviewView(Context context) { | ||
| 556 | - super(context); | ||
| 557 | - } | ||
| 558 | - | ||
| 559 | - @Override | ||
| 560 | - protected void onSizeChanged(int w, int h, int oldw, int oldh) { | ||
| 561 | - super.onSizeChanged(w, h, oldw, oldh); | ||
| 562 | - relayout(w, h); | ||
| 563 | - } | ||
| 564 | - | ||
| 565 | - private void relayout(int w, int h) { | ||
| 566 | - int width = w; | ||
| 567 | - int height = h; | ||
| 568 | - if (w < h) { | ||
| 569 | - // 垂直模式,高度固定。 | ||
| 570 | - height = (int) (width * ratio); | ||
| 571 | - } else { | ||
| 572 | - // 水平模式,宽度固定。 | ||
| 573 | - width = (int) (height * ratio); | ||
| 574 | - } | ||
| 575 | - | ||
| 576 | - int l = (getWidth() - width) / 2; | ||
| 577 | - int t = (getHeight() - height) / 2; | ||
| 578 | - | ||
| 579 | - previewFrame.left = l; | ||
| 580 | - previewFrame.top = t; | ||
| 581 | - previewFrame.right = l + width; | ||
| 582 | - previewFrame.bottom = t + height; | ||
| 583 | - } | ||
| 584 | - | ||
| 585 | - @Override | ||
| 586 | - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | ||
| 587 | - super.onLayout(changed, left, top, right, bottom); | ||
| 588 | - textureView.layout(previewFrame.left, previewFrame.top, previewFrame.right, previewFrame.bottom); | ||
| 589 | - } | ||
| 590 | - } | ||
| 591 | - | ||
| 592 | - @Override | ||
| 593 | - public Rect getPreviewFrame() { | ||
| 594 | - return previewFrame; | ||
| 595 | - } | ||
| 596 | -} |
core/dentity_verfication/src/main/java/com/cnlive/core/ocr/ui/camera/Camera2Control.java deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. | ||
| 3 | - */ | ||
| 4 | - | ||
| 5 | -package com.cnlive.core.ocr.ui.camera; | ||
| 6 | - | ||
| 7 | -import android.Manifest; | ||
| 8 | -import android.annotation.SuppressLint; | ||
| 9 | -import android.annotation.TargetApi; | ||
| 10 | -import android.content.Context; | ||
| 11 | -import android.content.pm.PackageManager; | ||
| 12 | -import android.graphics.ImageFormat; | ||
| 13 | -import android.graphics.Matrix; | ||
| 14 | -import android.graphics.Point; | ||
| 15 | -import android.graphics.Rect; | ||
| 16 | -import android.graphics.RectF; | ||
| 17 | -import android.graphics.SurfaceTexture; | ||
| 18 | -import android.hardware.camera2.CameraAccessException; | ||
| 19 | -import android.hardware.camera2.CameraCaptureSession; | ||
| 20 | -import android.hardware.camera2.CameraCharacteristics; | ||
| 21 | -import android.hardware.camera2.CameraDevice; | ||
| 22 | -import android.hardware.camera2.CameraManager; | ||
| 23 | -import android.hardware.camera2.CameraMetadata; | ||
| 24 | -import android.hardware.camera2.CaptureFailure; | ||
| 25 | -import android.hardware.camera2.CaptureRequest; | ||
| 26 | -import android.hardware.camera2.CaptureResult; | ||
| 27 | -import android.hardware.camera2.TotalCaptureResult; | ||
| 28 | -import android.hardware.camera2.params.StreamConfigurationMap; | ||
| 29 | -import android.media.Image; | ||
| 30 | -import android.media.ImageReader; | ||
| 31 | -import android.os.Build; | ||
| 32 | -import android.os.Handler; | ||
| 33 | -import android.os.HandlerThread; | ||
| 34 | -import android.util.Size; | ||
| 35 | -import android.util.SparseIntArray; | ||
| 36 | -import android.view.Surface; | ||
| 37 | -import android.view.TextureView; | ||
| 38 | -import android.view.View; | ||
| 39 | -import android.view.WindowManager; | ||
| 40 | - | ||
| 41 | -import java.nio.ByteBuffer; | ||
| 42 | -import java.util.ArrayList; | ||
| 43 | -import java.util.Arrays; | ||
| 44 | -import java.util.Collections; | ||
| 45 | -import java.util.Comparator; | ||
| 46 | -import java.util.List; | ||
| 47 | -import java.util.concurrent.Semaphore; | ||
| 48 | -import java.util.concurrent.TimeUnit; | ||
| 49 | -import java.util.concurrent.atomic.AtomicBoolean; | ||
| 50 | - | ||
| 51 | -import androidx.annotation.NonNull; | ||
| 52 | -import androidx.core.content.ContextCompat; | ||
| 53 | - | ||
| 54 | -@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
| 55 | -public class Camera2Control implements ICameraControl { | ||
| 56 | - @Override | ||
| 57 | - public void setDetectCallback(OnDetectPictureCallback callback) { | ||
| 58 | - // TODO 暂时只用camera | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Override | ||
| 62 | - public AtomicBoolean getAbortingScan() { | ||
| 63 | - // TODO 暂时只用camera | ||
| 64 | - return null; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - /** | ||
| 68 | - * Conversion from screen rotation to JPEG orientation. | ||
| 69 | - */ | ||
| 70 | - private static final SparseIntArray ORIENTATIONS = new SparseIntArray(); | ||
| 71 | - private static final int MAX_PREVIEW_SIZE = 2048; | ||
| 72 | - | ||
| 73 | - static { | ||
| 74 | - ORIENTATIONS.append(Surface.ROTATION_0, 90); | ||
| 75 | - ORIENTATIONS.append(Surface.ROTATION_90, 0); | ||
| 76 | - ORIENTATIONS.append(Surface.ROTATION_180, 270); | ||
| 77 | - ORIENTATIONS.append(Surface.ROTATION_270, 180); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - private static final int STATE_PREVIEW = 0; | ||
| 81 | - private static final int STATE_WAITING_FOR_LOCK = 1; | ||
| 82 | - private static final int STATE_WAITING_FOR_CAPTURE = 2; | ||
| 83 | - private static final int STATE_CAPTURING = 3; | ||
| 84 | - private static final int STATE_PICTURE_TAKEN = 4; | ||
| 85 | - | ||
| 86 | - private static final int MAX_PREVIEW_WIDTH = 1920; | ||
| 87 | - private static final int MAX_PREVIEW_HEIGHT = 1080; | ||
| 88 | - | ||
| 89 | - private int flashMode; | ||
| 90 | - private int orientation = 0; | ||
| 91 | - private int state = STATE_PREVIEW; | ||
| 92 | - | ||
| 93 | - private Context context; | ||
| 94 | - private OnTakePictureCallback onTakePictureCallback; | ||
| 95 | - private PermissionCallback permissionCallback; | ||
| 96 | - | ||
| 97 | - private String cameraId; | ||
| 98 | - private TextureView textureView; | ||
| 99 | - private Size previewSize; | ||
| 100 | - private Rect previewFrame = new Rect(); | ||
| 101 | - | ||
| 102 | - private HandlerThread backgroundThread; | ||
| 103 | - private Handler backgroundHandler; | ||
| 104 | - private ImageReader imageReader; | ||
| 105 | - private CameraCaptureSession captureSession; | ||
| 106 | - private CameraDevice cameraDevice; | ||
| 107 | - | ||
| 108 | - private CaptureRequest.Builder previewRequestBuilder; | ||
| 109 | - private CaptureRequest previewRequest; | ||
| 110 | - | ||
| 111 | - private Semaphore cameraLock = new Semaphore(1); | ||
| 112 | - private int sensorOrientation; | ||
| 113 | - | ||
| 114 | - @Override | ||
| 115 | - public void start() { | ||
| 116 | - startBackgroundThread(); | ||
| 117 | - if (textureView.isAvailable()) { | ||
| 118 | - openCamera(textureView.getWidth(), textureView.getHeight()); | ||
| 119 | - textureView.setSurfaceTextureListener(surfaceTextureListener); | ||
| 120 | - } else { | ||
| 121 | - textureView.setSurfaceTextureListener(surfaceTextureListener); | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - @Override | ||
| 126 | - public void stop() { | ||
| 127 | - textureView.setSurfaceTextureListener(null); | ||
| 128 | - closeCamera(); | ||
| 129 | - stopBackgroundThread(); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - @Override | ||
| 133 | - public void pause() { | ||
| 134 | - setFlashMode(FLASH_MODE_OFF); | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - @Override | ||
| 138 | - public void resume() { | ||
| 139 | - state = STATE_PREVIEW; | ||
| 140 | - } | ||
| 141 | - | ||
| 142 | - @Override | ||
| 143 | - public View getDisplayView() { | ||
| 144 | - return textureView; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - @Override | ||
| 148 | - public Rect getPreviewFrame() { | ||
| 149 | - return previewFrame; | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - @Override | ||
| 153 | - public void takePicture(OnTakePictureCallback callback) { | ||
| 154 | - this.onTakePictureCallback = callback; | ||
| 155 | - // 拍照第一步,对焦 | ||
| 156 | - lockFocus(); | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - @Override | ||
| 160 | - public void setPermissionCallback(PermissionCallback callback) { | ||
| 161 | - this.permissionCallback = callback; | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | - @Override | ||
| 165 | - public void setDisplayOrientation(@CameraView.Orientation int displayOrientation) { | ||
| 166 | - this.orientation = displayOrientation / 90; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - @Override | ||
| 170 | - public void refreshPermission() { | ||
| 171 | - openCamera(textureView.getWidth(), textureView.getHeight()); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - @Override | ||
| 175 | - public void setFlashMode(@FlashMode int flashMode) { | ||
| 176 | - if (this.flashMode == flashMode) { | ||
| 177 | - return; | ||
| 178 | - } | ||
| 179 | - this.flashMode = flashMode; | ||
| 180 | - try { | ||
| 181 | - previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, | ||
| 182 | - CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); | ||
| 183 | - updateFlashMode(flashMode, previewRequestBuilder); | ||
| 184 | - previewRequest = previewRequestBuilder.build(); | ||
| 185 | - captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler); | ||
| 186 | - } catch (Exception e) { | ||
| 187 | - if (e!=null) | ||
| 188 | - e.printStackTrace(); | ||
| 189 | - } | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - @Override | ||
| 193 | - public int getFlashMode() { | ||
| 194 | - return flashMode; | ||
| 195 | - } | ||
| 196 | - | ||
| 197 | - public Camera2Control(Context activity) { | ||
| 198 | - this.context = activity; | ||
| 199 | - textureView = new TextureView(activity); | ||
| 200 | - } | ||
| 201 | - | ||
| 202 | - private final TextureView.SurfaceTextureListener surfaceTextureListener = | ||
| 203 | - new TextureView.SurfaceTextureListener() { | ||
| 204 | - @Override | ||
| 205 | - public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { | ||
| 206 | - openCamera(width, height); | ||
| 207 | - } | ||
| 208 | - | ||
| 209 | - @Override | ||
| 210 | - public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { | ||
| 211 | - configureTransform(width, height); | ||
| 212 | - previewFrame.left = 0; | ||
| 213 | - previewFrame.top = 0; | ||
| 214 | - previewFrame.right = width; | ||
| 215 | - previewFrame.bottom = height; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - @Override | ||
| 219 | - public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) { | ||
| 220 | - stop(); | ||
| 221 | - return true; | ||
| 222 | - } | ||
| 223 | - | ||
| 224 | - @Override | ||
| 225 | - public void onSurfaceTextureUpdated(SurfaceTexture texture) { | ||
| 226 | - } | ||
| 227 | - }; | ||
| 228 | - | ||
| 229 | - @SuppressLint("MissingPermission") | ||
| 230 | - private void openCamera(int width, int height) { | ||
| 231 | - // 6.0+的系统需要检查系统权限 。 | ||
| 232 | - if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) | ||
| 233 | - != PackageManager.PERMISSION_GRANTED) { | ||
| 234 | - requestCameraPermission(); | ||
| 235 | - return; | ||
| 236 | - } | ||
| 237 | - setUpCameraOutputs(width, height); | ||
| 238 | - configureTransform(width, height); | ||
| 239 | - CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); | ||
| 240 | - try { | ||
| 241 | - if (!cameraLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { | ||
| 242 | - throw new RuntimeException("Time out waiting to lock camera opening."); | ||
| 243 | - } | ||
| 244 | - manager.openCamera(cameraId, deviceStateCallback, backgroundHandler); | ||
| 245 | - } catch (CameraAccessException e) { | ||
| 246 | - if (e!=null) | ||
| 247 | - e.printStackTrace(); | ||
| 248 | - } catch (InterruptedException e) { | ||
| 249 | - if (e!=null) | ||
| 250 | - throw new RuntimeException("Interrupted while trying to lock camera opening.", e); | ||
| 251 | - } | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | - private final CameraDevice.StateCallback deviceStateCallback = new CameraDevice.StateCallback() { | ||
| 255 | - @Override | ||
| 256 | - public void onOpened(@NonNull CameraDevice cameraDevice) { | ||
| 257 | - cameraLock.release(); | ||
| 258 | - Camera2Control.this.cameraDevice = cameraDevice; | ||
| 259 | - createCameraPreviewSession(); | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | - @Override | ||
| 263 | - public void onDisconnected(@NonNull CameraDevice cameraDevice) { | ||
| 264 | - cameraLock.release(); | ||
| 265 | - cameraDevice.close(); | ||
| 266 | - Camera2Control.this.cameraDevice = null; | ||
| 267 | - } | ||
| 268 | - | ||
| 269 | - @Override | ||
| 270 | - public void onError(@NonNull CameraDevice cameraDevice, int error) { | ||
| 271 | - cameraLock.release(); | ||
| 272 | - cameraDevice.close(); | ||
| 273 | - Camera2Control.this.cameraDevice = null; | ||
| 274 | - } | ||
| 275 | - }; | ||
| 276 | - | ||
| 277 | - private void createCameraPreviewSession() { | ||
| 278 | - try { | ||
| 279 | - SurfaceTexture texture = textureView.getSurfaceTexture(); | ||
| 280 | - assert texture != null; | ||
| 281 | - texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); | ||
| 282 | - Surface surface = new Surface(texture); | ||
| 283 | - previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); | ||
| 284 | - previewRequestBuilder.addTarget(surface); | ||
| 285 | - updateFlashMode(this.flashMode, previewRequestBuilder); | ||
| 286 | - cameraDevice.createCaptureSession(Arrays.asList(surface, imageReader.getSurface()), | ||
| 287 | - new CameraCaptureSession.StateCallback() { | ||
| 288 | - | ||
| 289 | - @Override | ||
| 290 | - public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { | ||
| 291 | - // The camera is already closed | ||
| 292 | - if (null == cameraDevice) { | ||
| 293 | - return; | ||
| 294 | - } | ||
| 295 | - captureSession = cameraCaptureSession; | ||
| 296 | - try { | ||
| 297 | - previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, | ||
| 298 | - CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); | ||
| 299 | - previewRequest = previewRequestBuilder.build(); | ||
| 300 | - captureSession.setRepeatingRequest(previewRequest, | ||
| 301 | - captureCallback, backgroundHandler); | ||
| 302 | - } catch (CameraAccessException e) { | ||
| 303 | - if (e!=null) | ||
| 304 | - e.printStackTrace(); | ||
| 305 | - } | ||
| 306 | - } | ||
| 307 | - | ||
| 308 | - @Override | ||
| 309 | - public void onConfigureFailed( | ||
| 310 | - @NonNull CameraCaptureSession cameraCaptureSession) { | ||
| 311 | - // TODO | ||
| 312 | - } | ||
| 313 | - }, null | ||
| 314 | - ); | ||
| 315 | - } catch (CameraAccessException e) { | ||
| 316 | - if (e!=null) | ||
| 317 | - e.printStackTrace(); | ||
| 318 | - } | ||
| 319 | - } | ||
| 320 | - | ||
| 321 | - private final ImageReader.OnImageAvailableListener onImageAvailableListener = | ||
| 322 | - new ImageReader.OnImageAvailableListener() { | ||
| 323 | - @Override | ||
| 324 | - public void onImageAvailable(ImageReader reader) { | ||
| 325 | - if (onTakePictureCallback != null) { | ||
| 326 | - Image image = reader.acquireNextImage(); | ||
| 327 | - ByteBuffer buffer = image.getPlanes()[0].getBuffer(); | ||
| 328 | - byte[] bytes = new byte[buffer.remaining()]; | ||
| 329 | - buffer.get(bytes); | ||
| 330 | - | ||
| 331 | - image.close(); | ||
| 332 | - onTakePictureCallback.onPictureTaken(bytes); | ||
| 333 | - } | ||
| 334 | - } | ||
| 335 | - }; | ||
| 336 | - | ||
| 337 | - private CameraCaptureSession.CaptureCallback captureCallback = | ||
| 338 | - new CameraCaptureSession.CaptureCallback() { | ||
| 339 | - private void process(CaptureResult result) { | ||
| 340 | - switch (state) { | ||
| 341 | - case STATE_PREVIEW: { | ||
| 342 | - break; | ||
| 343 | - } | ||
| 344 | - case STATE_WAITING_FOR_LOCK: { | ||
| 345 | - Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); | ||
| 346 | - if (afState == null) { | ||
| 347 | - captureStillPicture(); | ||
| 348 | - return; | ||
| 349 | - } | ||
| 350 | - switch (afState) { | ||
| 351 | - case CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED: | ||
| 352 | - case CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: | ||
| 353 | - case CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED: { | ||
| 354 | - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); | ||
| 355 | - if (aeState == null | ||
| 356 | - || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { | ||
| 357 | - captureStillPicture(); | ||
| 358 | - } else { | ||
| 359 | - runPreCaptureSequence(); | ||
| 360 | - } | ||
| 361 | - break; | ||
| 362 | - } | ||
| 363 | - default: | ||
| 364 | - captureStillPicture(); | ||
| 365 | - } | ||
| 366 | - break; | ||
| 367 | - } | ||
| 368 | - case STATE_WAITING_FOR_CAPTURE: { | ||
| 369 | - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); | ||
| 370 | - if (aeState == null | ||
| 371 | - || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE | ||
| 372 | - || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { | ||
| 373 | - state = STATE_CAPTURING; | ||
| 374 | - } else { | ||
| 375 | - if (aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { | ||
| 376 | - captureStillPicture(); | ||
| 377 | - } | ||
| 378 | - } | ||
| 379 | - break; | ||
| 380 | - } | ||
| 381 | - case STATE_CAPTURING: { | ||
| 382 | - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); | ||
| 383 | - if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { | ||
| 384 | - captureStillPicture(); | ||
| 385 | - } | ||
| 386 | - break; | ||
| 387 | - } | ||
| 388 | - default: | ||
| 389 | - break; | ||
| 390 | - } | ||
| 391 | - } | ||
| 392 | - | ||
| 393 | - @Override | ||
| 394 | - public void onCaptureProgressed(@NonNull CameraCaptureSession session, | ||
| 395 | - @NonNull CaptureRequest request, | ||
| 396 | - @NonNull CaptureResult partialResult) { | ||
| 397 | - process(partialResult); | ||
| 398 | - } | ||
| 399 | - | ||
| 400 | - @Override | ||
| 401 | - public void onCaptureCompleted(@NonNull CameraCaptureSession session, | ||
| 402 | - @NonNull CaptureRequest request, | ||
| 403 | - @NonNull TotalCaptureResult result) { | ||
| 404 | - process(result); | ||
| 405 | - } | ||
| 406 | - | ||
| 407 | - }; | ||
| 408 | - | ||
| 409 | - private Size getOptimalSize(Size[] choices, int textureViewWidth, | ||
| 410 | - int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { | ||
| 411 | - List<Size> bigEnough = new ArrayList<>(); | ||
| 412 | - List<Size> notBigEnough = new ArrayList<>(); | ||
| 413 | - int w = aspectRatio.getWidth(); | ||
| 414 | - int h = aspectRatio.getHeight(); | ||
| 415 | - for (Size option : choices) { | ||
| 416 | - if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight | ||
| 417 | - && option.getHeight() == option.getWidth() * h / w) { | ||
| 418 | - if (option.getWidth() >= textureViewWidth | ||
| 419 | - && option.getHeight() >= textureViewHeight) { | ||
| 420 | - bigEnough.add(option); | ||
| 421 | - } else { | ||
| 422 | - notBigEnough.add(option); | ||
| 423 | - } | ||
| 424 | - } | ||
| 425 | - } | ||
| 426 | - | ||
| 427 | - // Pick the smallest of those big enough. If there is no one big enough, pick the | ||
| 428 | - // largest of those not big enough. | ||
| 429 | - if (bigEnough.size() > 0) { | ||
| 430 | - return Collections.min(bigEnough, sizeComparator); | ||
| 431 | - } | ||
| 432 | - | ||
| 433 | - for (Size option : choices) { | ||
| 434 | - if (option.getWidth() >= maxWidth && option.getHeight() >= maxHeight) { | ||
| 435 | - return option; | ||
| 436 | - } | ||
| 437 | - } | ||
| 438 | - | ||
| 439 | - if (notBigEnough.size() > 0) { | ||
| 440 | - return Collections.max(notBigEnough, sizeComparator); | ||
| 441 | - } | ||
| 442 | - | ||
| 443 | - return choices[0]; | ||
| 444 | - } | ||
| 445 | - | ||
| 446 | - private Comparator<Size> sizeComparator = new Comparator<Size>() { | ||
| 447 | - @Override | ||
| 448 | - public int compare(Size lhs, Size rhs) { | ||
| 449 | - return Long.signum((long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight()); | ||
| 450 | - } | ||
| 451 | - }; | ||
| 452 | - | ||
| 453 | - private void requestCameraPermission() { | ||
| 454 | - if (permissionCallback != null) { | ||
| 455 | - permissionCallback.onRequestPermission(); | ||
| 456 | - } | ||
| 457 | - } | ||
| 458 | - | ||
| 459 | - @SuppressWarnings("SuspiciousNameCombination") | ||
| 460 | - private void setUpCameraOutputs(int width, int height) { | ||
| 461 | - CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); | ||
| 462 | - try { | ||
| 463 | - for (String cameraId : manager.getCameraIdList()) { | ||
| 464 | - CameraCharacteristics characteristics = | ||
| 465 | - manager.getCameraCharacteristics(cameraId); | ||
| 466 | - | ||
| 467 | - Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); | ||
| 468 | - if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { | ||
| 469 | - continue; | ||
| 470 | - } | ||
| 471 | - | ||
| 472 | - StreamConfigurationMap map = characteristics.get( | ||
| 473 | - CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); | ||
| 474 | - if (map == null) { | ||
| 475 | - continue; | ||
| 476 | - } | ||
| 477 | - | ||
| 478 | - // int preferredPictureSize = (int) (Math.max(textureView.getWidth(), textureView | ||
| 479 | - // .getHeight()) * 1.5); | ||
| 480 | - // preferredPictureSize = Math.min(preferredPictureSize, 2560); | ||
| 481 | - | ||
| 482 | - WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); | ||
| 483 | - Point screenSize = new Point(); | ||
| 484 | - windowManager.getDefaultDisplay().getSize(screenSize); | ||
| 485 | - int maxImageSize = Math.max(MAX_PREVIEW_SIZE, screenSize.y * 3 / 2); | ||
| 486 | - | ||
| 487 | - Size size = getOptimalSize(map.getOutputSizes(ImageFormat.JPEG), textureView.getWidth(), | ||
| 488 | - textureView.getHeight(), maxImageSize, maxImageSize, new Size(4, 3)); | ||
| 489 | - | ||
| 490 | - imageReader = ImageReader.newInstance(size.getWidth(), size.getHeight(), | ||
| 491 | - ImageFormat.JPEG, 1); | ||
| 492 | - imageReader.setOnImageAvailableListener( | ||
| 493 | - onImageAvailableListener, backgroundHandler); | ||
| 494 | - | ||
| 495 | - int displayRotation = orientation; | ||
| 496 | - // noinspection ConstantConditions | ||
| 497 | - sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); | ||
| 498 | - boolean swappedDimensions = false; | ||
| 499 | - switch (displayRotation) { | ||
| 500 | - case Surface.ROTATION_0: | ||
| 501 | - case Surface.ROTATION_180: | ||
| 502 | - if (sensorOrientation == 90 || sensorOrientation == 270) { | ||
| 503 | - swappedDimensions = true; | ||
| 504 | - } | ||
| 505 | - break; | ||
| 506 | - case Surface.ROTATION_90: | ||
| 507 | - case Surface.ROTATION_270: | ||
| 508 | - if (sensorOrientation == 0 || sensorOrientation == 180) { | ||
| 509 | - swappedDimensions = true; | ||
| 510 | - } | ||
| 511 | - break; | ||
| 512 | - default: | ||
| 513 | - } | ||
| 514 | - | ||
| 515 | - int rotatedPreviewWidth = width; | ||
| 516 | - int rotatedPreviewHeight = height; | ||
| 517 | - int maxPreviewWidth = screenSize.x; | ||
| 518 | - int maxPreviewHeight = screenSize.y; | ||
| 519 | - | ||
| 520 | - if (swappedDimensions) { | ||
| 521 | - rotatedPreviewWidth = height; | ||
| 522 | - rotatedPreviewHeight = width; | ||
| 523 | - maxPreviewWidth = screenSize.y; | ||
| 524 | - maxPreviewHeight = screenSize.x; | ||
| 525 | - } | ||
| 526 | - | ||
| 527 | - maxPreviewWidth = Math.min(maxPreviewWidth, MAX_PREVIEW_WIDTH); | ||
| 528 | - maxPreviewHeight = Math.min(maxPreviewHeight, MAX_PREVIEW_HEIGHT); | ||
| 529 | - | ||
| 530 | - previewSize = getOptimalSize(map.getOutputSizes(SurfaceTexture.class), | ||
| 531 | - rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, | ||
| 532 | - maxPreviewHeight, size); | ||
| 533 | - this.cameraId = cameraId; | ||
| 534 | - return; | ||
| 535 | - } | ||
| 536 | - } catch (CameraAccessException | NullPointerException e) { | ||
| 537 | - if (e!=null) | ||
| 538 | - e.printStackTrace(); | ||
| 539 | - } | ||
| 540 | - } | ||
| 541 | - | ||
| 542 | - private void closeCamera() { | ||
| 543 | - try { | ||
| 544 | - cameraLock.acquire(); | ||
| 545 | - if (null != captureSession) { | ||
| 546 | - captureSession.close(); | ||
| 547 | - captureSession = null; | ||
| 548 | - } | ||
| 549 | - if (null != cameraDevice) { | ||
| 550 | - cameraDevice.close(); | ||
| 551 | - cameraDevice = null; | ||
| 552 | - } | ||
| 553 | - if (null != imageReader) { | ||
| 554 | - imageReader.close(); | ||
| 555 | - imageReader = null; | ||
| 556 | - } | ||
| 557 | - } catch (InterruptedException e) { | ||
| 558 | - throw new RuntimeException("Interrupted while trying to lock camera closing.", e); | ||
| 559 | - } finally { | ||
| 560 | - cameraLock.release(); | ||
| 561 | - } | ||
| 562 | - } | ||
| 563 | - | ||
| 564 | - private void startBackgroundThread() { | ||
| 565 | - backgroundThread = new HandlerThread("ocr_camera"); | ||
| 566 | - backgroundThread.start(); | ||
| 567 | - backgroundHandler = new Handler(backgroundThread.getLooper()); | ||
| 568 | - } | ||
| 569 | - | ||
| 570 | - private void stopBackgroundThread() { | ||
| 571 | - if (backgroundThread != null) { | ||
| 572 | - backgroundThread.quitSafely(); | ||
| 573 | - backgroundThread = null; | ||
| 574 | - backgroundHandler = null; | ||
| 575 | - } | ||
| 576 | - } | ||
| 577 | - | ||
| 578 | - private void configureTransform(int viewWidth, int viewHeight) { | ||
| 579 | - if (null == textureView || null == previewSize || null == context) { | ||
| 580 | - return; | ||
| 581 | - } | ||
| 582 | - int rotation = orientation; | ||
| 583 | - Matrix matrix = new Matrix(); | ||
| 584 | - RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); | ||
| 585 | - RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); | ||
| 586 | - float centerX = viewRect.centerX(); | ||
| 587 | - float centerY = viewRect.centerY(); | ||
| 588 | - if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { | ||
| 589 | - bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); | ||
| 590 | - matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); | ||
| 591 | - float scale = Math.max( | ||
| 592 | - (float) viewHeight / previewSize.getHeight(), | ||
| 593 | - (float) viewWidth / previewSize.getWidth()); | ||
| 594 | - matrix.postScale(scale, scale, centerX, centerY); | ||
| 595 | - matrix.postRotate(90 * (rotation - 2), centerX, centerY); | ||
| 596 | - } else if (Surface.ROTATION_180 == rotation) { | ||
| 597 | - matrix.postRotate(180, centerX, centerY); | ||
| 598 | - } | ||
| 599 | - textureView.setTransform(matrix); | ||
| 600 | - } | ||
| 601 | - | ||
| 602 | - // 拍照前,先对焦 | ||
| 603 | - private void lockFocus() { | ||
| 604 | - if (captureSession != null && state == STATE_PREVIEW) { | ||
| 605 | - try { | ||
| 606 | - previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, | ||
| 607 | - CameraMetadata.CONTROL_AF_TRIGGER_START); | ||
| 608 | - state = STATE_WAITING_FOR_LOCK; | ||
| 609 | - captureSession.capture(previewRequestBuilder.build(), captureCallback, | ||
| 610 | - backgroundHandler); | ||
| 611 | - } catch (CameraAccessException e) { | ||
| 612 | - if (e!=null) | ||
| 613 | - e.printStackTrace(); | ||
| 614 | - } | ||
| 615 | - } | ||
| 616 | - } | ||
| 617 | - | ||
| 618 | - private void runPreCaptureSequence() { | ||
| 619 | - try { | ||
| 620 | - previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, | ||
| 621 | - CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START); | ||
| 622 | - state = STATE_WAITING_FOR_CAPTURE; | ||
| 623 | - captureSession.capture(previewRequestBuilder.build(), captureCallback, | ||
| 624 | - backgroundHandler); | ||
| 625 | - } catch (CameraAccessException e) { | ||
| 626 | - if (e!=null) | ||
| 627 | - e.printStackTrace(); | ||
| 628 | - } | ||
| 629 | - } | ||
| 630 | - | ||
| 631 | - // 拍照session | ||
| 632 | - private void captureStillPicture() { | ||
| 633 | - try { | ||
| 634 | - if (null == context || null == cameraDevice) { | ||
| 635 | - return; | ||
| 636 | - } | ||
| 637 | - final CaptureRequest.Builder captureBuilder = | ||
| 638 | - cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); | ||
| 639 | - captureBuilder.addTarget(imageReader.getSurface()); | ||
| 640 | - captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, | ||
| 641 | - CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); | ||
| 642 | - | ||
| 643 | - captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(orientation)); | ||
| 644 | - updateFlashMode(this.flashMode, captureBuilder); | ||
| 645 | - CameraCaptureSession.CaptureCallback captureCallback = | ||
| 646 | - new CameraCaptureSession.CaptureCallback() { | ||
| 647 | - @Override | ||
| 648 | - public void onCaptureCompleted(@NonNull CameraCaptureSession session, | ||
| 649 | - @NonNull CaptureRequest request, | ||
| 650 | - @NonNull TotalCaptureResult result) { | ||
| 651 | - unlockFocus(); | ||
| 652 | - } | ||
| 653 | - | ||
| 654 | - @Override | ||
| 655 | - public void onCaptureFailed(@NonNull CameraCaptureSession session, | ||
| 656 | - @NonNull CaptureRequest request, | ||
| 657 | - @NonNull CaptureFailure failure) { | ||
| 658 | - super.onCaptureFailed(session, request, failure); | ||
| 659 | - } | ||
| 660 | - }; | ||
| 661 | - | ||
| 662 | - // 停止预览 | ||
| 663 | - captureSession.stopRepeating(); | ||
| 664 | - captureSession.capture(captureBuilder.build(), captureCallback, backgroundHandler); | ||
| 665 | - state = STATE_PICTURE_TAKEN; | ||
| 666 | - // unlockFocus(); | ||
| 667 | - } catch (CameraAccessException e) { | ||
| 668 | - if (e!=null) | ||
| 669 | - e.printStackTrace(); | ||
| 670 | - } | ||
| 671 | - } | ||
| 672 | - | ||
| 673 | - private int getOrientation(int rotation) { | ||
| 674 | - return (ORIENTATIONS.get(rotation) + sensorOrientation + 270) % 360; | ||
| 675 | - } | ||
| 676 | - | ||
| 677 | - // 停止对焦 | ||
| 678 | - private void unlockFocus() { | ||
| 679 | - try { | ||
| 680 | - previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, | ||
| 681 | - CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); | ||
| 682 | - captureSession.capture(previewRequestBuilder.build(), captureCallback, | ||
| 683 | - backgroundHandler); | ||
| 684 | - state = STATE_PREVIEW; | ||
| 685 | - // 预览 | ||
| 686 | - captureSession.setRepeatingRequest(previewRequest, captureCallback, | ||
| 687 | - backgroundHandler); | ||
| 688 | - textureView.setSurfaceTextureListener(surfaceTextureListener); | ||
| 689 | - } catch (CameraAccessException e) { | ||
| 690 | - if (e!=null) | ||
| 691 | - e.printStackTrace(); | ||
| 692 | - } | ||
| 693 | - } | ||
| 694 | - | ||
| 695 | - private void updateFlashMode(@FlashMode int flashMode, CaptureRequest.Builder builder) { | ||
| 696 | - switch (flashMode) { | ||
| 697 | - case FLASH_MODE_TORCH: | ||
| 698 | - builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); | ||
| 699 | - break; | ||
| 700 | - case FLASH_MODE_OFF: | ||
| 701 | - builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF); | ||
| 702 | - break; | ||
| 703 | - case ICameraControl.FLASH_MODE_AUTO: | ||
| 704 | - default: | ||
| 705 | - builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE); | ||
| 706 | - break; | ||
| 707 | - } | ||
| 708 | - } | ||
| 709 | -} |