Commit 9ee528fa64d3e881c0d095095c7998a16034f27b
1 parent
7b7d619e
基类新增权限申请,侧滑返回功能
Showing
39 changed files
with
2719 additions
and
178 deletions
Too many changes to show.
To preserve performance only 39 of 179 files are displayed.
app/strike/src/main/AndroidManifest.xml
| ... | ... | @@ -4,6 +4,8 @@ |
| 4 | 4 | |
| 5 | 5 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| 6 | 6 | <uses-permission android:name="android.permission.INTERNET" /> |
| 7 | + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | |
| 8 | + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |
| 7 | 9 | |
| 8 | 10 | <application |
| 9 | 11 | android:name=".MyApp" | ... | ... |
app/strike/src/main/java/com/cnlive/strike/MainActivity.java
| 1 | 1 | package com.cnlive.strike; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import android.Manifest; | |
| 4 | 5 | import android.content.Intent; |
| 6 | +import android.util.Log; | |
| 5 | 7 | import android.view.View; |
| 6 | 8 | |
| 7 | 9 | import com.cnlive.core.libs.base.frame.activity.BaseActivity; |
| 10 | +import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | |
| 8 | 11 | import com.cnlive.strike.user.ui.activity.LoginActivity; |
| 9 | 12 | |
| 10 | 13 | public class MainActivity extends BaseActivity { |
| ... | ... | @@ -21,11 +24,43 @@ public class MainActivity extends BaseActivity { |
| 21 | 24 | findViewById(R.id.go_to).setOnClickListener(new View.OnClickListener() { |
| 22 | 25 | @Override |
| 23 | 26 | public void onClick(View v) { |
| 24 | - startActivity(new Intent(MainActivity.this, LoginActivity.class)); | |
| 25 | -// LoginActivity.start(MainActivity.this); | |
| 27 | +// startActivity(new Intent(MainActivity.this, MyActivity.class)); | |
| 28 | + LoginActivity.start(MainActivity.this); | |
| 26 | 29 | |
| 27 | 30 | } |
| 28 | 31 | }); |
| 32 | + findViewById(R.id.go_to1).setOnClickListener(new View.OnClickListener() { | |
| 33 | + @Override | |
| 34 | + public void onClick(View v) { | |
| 35 | + requestPermission(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, new OnPermissionResponseListener() { | |
| 36 | + @Override | |
| 37 | + public void onSuccess(String[] permissions) { | |
| 38 | + Log.e(TAG, "onSuccess: "); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void onFail() { | |
| 43 | + Log.e(TAG, "onFail: "); | |
| 44 | + } | |
| 45 | + }); | |
| 46 | + } | |
| 47 | + }); | |
| 48 | + findViewById(R.id.go_to2).setOnClickListener(new View.OnClickListener() { | |
| 49 | + @Override | |
| 50 | + public void onClick(View v) { | |
| 51 | + requestPermission(10010, "拒绝我了", new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, new OnPermissionResponseListener() { | |
| 52 | + @Override | |
| 53 | + public void onSuccess(String[] permissions) { | |
| 54 | + Log.e(TAG, "onSuccess: "); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + public void onFail() { | |
| 59 | + Log.e(TAG, "onFail: "); | |
| 60 | + } | |
| 61 | + }); | |
| 62 | + } | |
| 63 | + }); | |
| 29 | 64 | } |
| 30 | 65 | |
| 31 | 66 | ... | ... |
app/strike/src/main/java/com/cnlive/strike/MyActivity.java
| ... | ... | @@ -13,6 +13,7 @@ public class MyActivity extends BaseActivity { |
| 13 | 13 | |
| 14 | 14 | @Override |
| 15 | 15 | protected void initView() { |
| 16 | + setOpenSwipBack(true); | |
| 16 | 17 | getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyFragment()).commitAllowingStateLoss(); |
| 17 | 18 | } |
| 18 | 19 | ... | ... |
app/strike/src/main/java/com/cnlive/strike/MyFragment.java
| 1 | 1 | package com.cnlive.strike; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import android.Manifest; | |
| 4 | 5 | import android.os.Bundle; |
| 5 | 6 | import android.util.Log; |
| 6 | 7 | import android.view.LayoutInflater; |
| ... | ... | @@ -9,6 +10,7 @@ import android.view.ViewGroup; |
| 9 | 10 | import android.widget.TextView; |
| 10 | 11 | |
| 11 | 12 | import com.cnlive.core.libs.base.frame.fragment.BaseFragment; |
| 13 | +import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | |
| 12 | 14 | import com.cnlive.core.network.BaseResult; |
| 13 | 15 | import com.cnlive.core.network.HttpConn; |
| 14 | 16 | import com.cnlive.core.network.NetCallBack; |
| ... | ... | @@ -45,6 +47,38 @@ public class MyFragment extends BaseFragment<MyFragmentView, MyPresenter> { |
| 45 | 47 | super.initView(); |
| 46 | 48 | setStatusBarColor(R.color.green, 0); |
| 47 | 49 | setStatusBarTextColor(StatusBarConfig.BLACK); |
| 50 | + view.findViewById(R.id.btn_test2).setOnClickListener(new View.OnClickListener() { | |
| 51 | + @Override | |
| 52 | + public void onClick(View v) { | |
| 53 | + requestPermission(010001, "测试", new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, new OnPermissionResponseListener() { | |
| 54 | + @Override | |
| 55 | + public void onSuccess(String[] permissions) { | |
| 56 | + Log.e(TAG, "onSuccess: "); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public void onFail() { | |
| 61 | + Log.e(TAG, "onFail: "); | |
| 62 | + } | |
| 63 | + }); | |
| 64 | + } | |
| 65 | + }); | |
| 66 | + view.findViewById(R.id.btn_test1).setOnClickListener(new View.OnClickListener() { | |
| 67 | + @Override | |
| 68 | + public void onClick(View v) { | |
| 69 | + requestPermission(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, new OnPermissionResponseListener() { | |
| 70 | + @Override | |
| 71 | + public void onSuccess(String[] permissions) { | |
| 72 | + Log.e(TAG, "onSuccess: "); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public void onFail() { | |
| 77 | + Log.e(TAG, "onFail: "); | |
| 78 | + } | |
| 79 | + }); | |
| 80 | + } | |
| 81 | + }); | |
| 48 | 82 | view.findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() { |
| 49 | 83 | @Override |
| 50 | 84 | public void onClick(View v) { | ... | ... |
app/strike/src/main/res/layout/activity_main.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | <layout> |
| 3 | - <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + | |
| 4 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 4 | 5 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 5 | 6 | xmlns:tools="http://schemas.android.com/tools" |
| 6 | 7 | android:layout_width="match_parent" |
| ... | ... | @@ -8,11 +9,23 @@ |
| 8 | 9 | android:orientation="vertical" |
| 9 | 10 | tools:context=".ui.activity.AllDeviceActivity"> |
| 10 | 11 | |
| 11 | - <Button | |
| 12 | - android:id="@+id/go_to" | |
| 13 | - android:layout_width="wrap_content" | |
| 14 | - android:layout_height="wrap_content" | |
| 15 | - android:text="跳转"/> | |
| 12 | + <Button | |
| 13 | + android:id="@+id/go_to" | |
| 14 | + android:layout_width="wrap_content" | |
| 15 | + android:layout_height="wrap_content" | |
| 16 | + android:text="跳转" /> | |
| 17 | + | |
| 18 | + <Button | |
| 19 | + android:id="@+id/go_to1" | |
| 20 | + android:layout_width="wrap_content" | |
| 21 | + android:layout_height="wrap_content" | |
| 22 | + android:text="请求权限默认提示语" /> | |
| 23 | + | |
| 24 | + <Button | |
| 25 | + android:id="@+id/go_to2" | |
| 26 | + android:layout_width="wrap_content" | |
| 27 | + android:layout_height="wrap_content" | |
| 28 | + android:text="请求权限自定义提示语" /> | |
| 16 | 29 | |
| 17 | - </RelativeLayout> | |
| 30 | + </LinearLayout> | |
| 18 | 31 | </layout> |
| 19 | 32 | \ No newline at end of file | ... | ... |
app/strike/src/main/res/layout/activity_main1.xml
| ... | ... | @@ -20,5 +20,17 @@ |
| 20 | 20 | android:layout_width="wrap_content" |
| 21 | 21 | android:layout_height="wrap_content" |
| 22 | 22 | android:text="测试view" /> |
| 23 | + | |
| 24 | + <Button | |
| 25 | + android:id="@+id/btn_test1" | |
| 26 | + android:layout_width="wrap_content" | |
| 27 | + android:layout_height="wrap_content" | |
| 28 | + android:text="权限申请" /> | |
| 29 | + | |
| 30 | + <Button | |
| 31 | + android:id="@+id/btn_test2" | |
| 32 | + android:layout_width="wrap_content" | |
| 33 | + android:layout_height="wrap_content" | |
| 34 | + android:text="自定义提示语权限申请" /> | |
| 23 | 35 | </LinearLayout> |
| 24 | 36 | </layout> |
| 25 | 37 | \ No newline at end of file | ... | ... |
build.gradle
| ... | ... | @@ -10,11 +10,11 @@ buildscript { |
| 10 | 10 | repositories { |
| 11 | 11 | google() |
| 12 | 12 | jcenter() |
| 13 | - | |
| 13 | + | |
| 14 | 14 | } |
| 15 | 15 | dependencies { |
| 16 | 16 | classpath 'com.android.tools.build:gradle:3.5.1' |
| 17 | - | |
| 17 | + | |
| 18 | 18 | // NOTE: Do not place your application dependencies here; they belong |
| 19 | 19 | // in the individual module build.gradle files |
| 20 | 20 | classpath "com.alibaba:arouter-register:1.0.2" |
| ... | ... | @@ -26,9 +26,25 @@ allprojects { |
| 26 | 26 | repositories { |
| 27 | 27 | google() |
| 28 | 28 | jcenter() |
| 29 | - | |
| 29 | + | |
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | + | |
| 33 | +////配置全局变量 | |
| 34 | +//ext { | |
| 35 | +// def versionMajor = 1 | |
| 36 | +// def versionMinor = 5 | |
| 37 | +// def versionPatch = 6 | |
| 38 | +// def versionBuild = 0 | |
| 39 | +// // module依赖库公共版本号 | |
| 40 | +// versionCode = versionMajor * 1000 + versionMinor * 100 + versionPatch * 10 + versionBuild | |
| 41 | +// versionName = "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}" | |
| 42 | +// | |
| 43 | +// compileSdkVersion = 29 | |
| 44 | +// buildToolsVersion = "29.0.2" | |
| 45 | +// minSdkVersion = 19 | |
| 46 | +// targetSdkVersion = 29 | |
| 47 | +//} | |
| 32 | 48 | allprojects { |
| 33 | 49 | afterEvaluate { |
| 34 | 50 | if (project.parent == null || project.parent == rootProject) return |
| ... | ... | @@ -37,7 +53,7 @@ allprojects { |
| 37 | 53 | compileSdkVersion 29 |
| 38 | 54 | buildToolsVersion "29.0.0" |
| 39 | 55 | defaultConfig { |
| 40 | - if (minSdkVersion == null) minSdkVersion 16 | |
| 56 | + if (minSdkVersion == null) minSdkVersion 21 | |
| 41 | 57 | if (targetSdkVersion == null) targetSdkVersion 29 |
| 42 | 58 | if (versionCode == null) versionCode 1 |
| 43 | 59 | if (versionName == null) versionName "1.2" |
| ... | ... | @@ -93,7 +109,7 @@ allprojects { |
| 93 | 109 | imput("implementation", project, moudle.core_base) |
| 94 | 110 | |
| 95 | 111 | //Tripartite Base |
| 96 | - for (String moudle : base_librarys) imput('implementation', project, moudle) | |
| 112 | + for (String moudle : base_librarys) imput('implementation', project, moudle) | |
| 97 | 113 | for (String moudle : base_compilers) imput('annotationProcessor', project, moudle) |
| 98 | 114 | |
| 99 | 115 | } | ... | ... |
cloud/user/build.gradle
| 1 | 1 | apply plugin: 'com.android.library' |
| 2 | 2 | |
| 3 | 3 | android { |
| 4 | - compileSdkVersion 29 | |
| 5 | - buildToolsVersion "29.0.2" | |
| 6 | - | |
| 7 | - | |
| 8 | - defaultConfig { | |
| 9 | - minSdkVersion 21 | |
| 10 | - targetSdkVersion 29 | |
| 11 | - versionCode 1 | |
| 12 | - versionName "1.0" | |
| 13 | - | |
| 14 | - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |
| 15 | - consumerProguardFiles 'consumer-rules.pro' | |
| 16 | - } | |
| 4 | +// compileSdkVersion 29 | |
| 5 | +// buildToolsVersion "29.0.2" | |
| 6 | +// | |
| 7 | +// | |
| 8 | +// defaultConfig { | |
| 9 | +// minSdkVersion 21 | |
| 10 | +// targetSdkVersion 29 | |
| 11 | +// versionCode 1 | |
| 12 | +// versionName "1.0" | |
| 13 | +// | |
| 14 | +// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |
| 15 | +// consumerProguardFiles 'consumer-rules.pro' | |
| 16 | +// } | |
| 17 | 17 | |
| 18 | 18 | buildTypes { |
| 19 | 19 | debug { | ... | ... |
cloud/user/src/main/AndroidManifest.xml
| ... | ... | @@ -57,7 +57,7 @@ |
| 57 | 57 | android:launchMode="singleTop" |
| 58 | 58 | android:screenOrientation="portrait" /> |
| 59 | 59 | <activity |
| 60 | - android:name="com.cnlive.strike.moudle.user.ui.activity.FirstLoginActivity" | |
| 60 | + android:name=".ui.activity.FirstLoginActivity" | |
| 61 | 61 | android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation" |
| 62 | 62 | android:launchMode="singleTop" |
| 63 | 63 | android:screenOrientation="portrait" /> | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/UserUtilAction.java
| ... | ... | @@ -2,9 +2,11 @@ package com.cnlive.strike.user; |
| 2 | 2 | |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.os.Environment; |
| 5 | +import android.text.TextUtils; | |
| 5 | 6 | |
| 6 | 7 | import com.cnlive.core.libs.base.application.AppConfig; |
| 7 | 8 | import com.cnlive.core.network.BaseResult; |
| 9 | +import com.cnlive.core.network.HttpConn; | |
| 8 | 10 | import com.cnlive.strike.user.network.api.ApiBaseServiceOpen; |
| 9 | 11 | import com.cnlive.strike.user.network.api.BaseRequest; |
| 10 | 12 | import com.cnlive.strike.user.network.model.TokenData; |
| ... | ... | @@ -19,13 +21,12 @@ import okhttp3.MediaType; |
| 19 | 21 | import okhttp3.RequestBody; |
| 20 | 22 | |
| 21 | 23 | |
| 22 | - | |
| 23 | 24 | /** |
| 24 | 25 | * Created by Lynn on 2018/10/15. |
| 25 | 26 | */ |
| 26 | 27 | |
| 27 | 28 | public class UserUtilAction { |
| 28 | - public static int TOKEN_ERROR_CODE = -900001; | |
| 29 | + public static final String TOKEN_ERROR_CODE = "-900001"; | |
| 29 | 30 | public static String TOKEN_ERROR_MSG = "用户token为空"; |
| 30 | 31 | |
| 31 | 32 | /** |
| ... | ... | @@ -103,9 +104,9 @@ public class UserUtilAction { |
| 103 | 104 | map.put("srcUid", srcUid); |
| 104 | 105 | map.put("clientPlat", "a"); |
| 105 | 106 | map.put("token", token); |
| 106 | -// if (TextUtils.isEmpty(token)) { | |
| 107 | -// callback.callback(TOKEN_ERROR_CODE, TOKEN_ERROR_MSG, null); | |
| 108 | -// } | |
| 107 | + if (TextUtils.isEmpty(token)) { | |
| 108 | + HttpConn.error(UserUtilAction.TOKEN_ERROR_CODE, TOKEN_ERROR_MSG); | |
| 109 | + } | |
| 109 | 110 | return BaseRequest.init().service(ApiBaseServiceOpen.class).queryUserInfo(map); |
| 110 | 111 | |
| 111 | 112 | } |
| ... | ... | @@ -126,9 +127,9 @@ public class UserUtilAction { |
| 126 | 127 | map.put("extInfo", extInfo); |
| 127 | 128 | map.put("token", token); |
| 128 | 129 | map.put("clientPlat", "a"); |
| 129 | -// if (TextUtils.isEmpty(token)) { | |
| 130 | -// callback.callback(TOKEN_ERROR_CODE, TOKEN_ERROR_MSG, null); | |
| 131 | -// } | |
| 130 | + if (TextUtils.isEmpty(token)) { | |
| 131 | + HttpConn.error(UserUtilAction.TOKEN_ERROR_CODE, TOKEN_ERROR_MSG); | |
| 132 | + } | |
| 132 | 133 | return BaseRequest.init().service(ApiBaseServiceOpen.class).updateUserExtInfo(map); |
| 133 | 134 | |
| 134 | 135 | } |
| ... | ... | @@ -153,9 +154,9 @@ public class UserUtilAction { |
| 153 | 154 | map.put("value", value); |
| 154 | 155 | map.put("clientPlat", "a"); |
| 155 | 156 | map.put("token", token); |
| 156 | -// if (TextUtils.isEmpty(token)) { | |
| 157 | -// callback.callback(TOKEN_ERROR_CODE, TOKEN_ERROR_MSG, null); | |
| 158 | -// } | |
| 157 | + if (TextUtils.isEmpty(token)) { | |
| 158 | + HttpConn.error(UserUtilAction.TOKEN_ERROR_CODE, TOKEN_ERROR_MSG); | |
| 159 | + } | |
| 159 | 160 | return BaseRequest.init().service(ApiBaseServiceOpen.class).modifyUserInfo(map); |
| 160 | 161 | |
| 161 | 162 | } |
| ... | ... | @@ -195,9 +196,9 @@ public class UserUtilAction { |
| 195 | 196 | map.put("clientPlat", "a"); |
| 196 | 197 | map.put("countryCode", countryCode); |
| 197 | 198 | map.put("token", token); |
| 198 | -// if (TextUtils.isEmpty(token)) { | |
| 199 | -// callback.callback(TOKEN_ERROR_CODE, TOKEN_ERROR_MSG, null); | |
| 200 | -// } | |
| 199 | + if (TextUtils.isEmpty(token)) { | |
| 200 | + HttpConn.error(UserUtilAction.TOKEN_ERROR_CODE, TOKEN_ERROR_MSG); | |
| 201 | + } | |
| 201 | 202 | return BaseRequest.init().service(ApiBaseServiceOpen.class).updateMobile(map); |
| 202 | 203 | |
| 203 | 204 | } |
| ... | ... | @@ -212,16 +213,16 @@ public class UserUtilAction { |
| 212 | 213 | * @return |
| 213 | 214 | */ |
| 214 | 215 | public static Observable<BaseResult<UserData>> register(Context context, String userName, String pwd, String verificationCode) { |
| 215 | - Map<String, String> map = new HashMap<>(); | |
| 216 | - map.put("appId", AppConfig.getAppId()); | |
| 217 | - map.put("userName", userName); | |
| 218 | - map.put("pwd", pwd); | |
| 219 | - map.put("verificationCode", verificationCode); | |
| 220 | - map.put("invitationCode", ""); | |
| 221 | - map.put("uuid", AppConfig.getAppUUID()); | |
| 222 | - map.put("frmId", ""); | |
| 223 | - map.put("clientPlat", "a"); | |
| 224 | - return BaseRequest.init().service(ApiBaseServiceOpen.class).register(map); | |
| 216 | + Map<String, String> map = new HashMap<>(); | |
| 217 | + map.put("appId", AppConfig.getAppId()); | |
| 218 | + map.put("userName", userName); | |
| 219 | + map.put("pwd", pwd); | |
| 220 | + map.put("verificationCode", verificationCode); | |
| 221 | + map.put("invitationCode", ""); | |
| 222 | + map.put("uuid", AppConfig.getAppUUID()); | |
| 223 | + map.put("frmId", ""); | |
| 224 | + map.put("clientPlat", "a"); | |
| 225 | + return BaseRequest.init().service(ApiBaseServiceOpen.class).register(map); | |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | |
| ... | ... | @@ -232,10 +233,10 @@ public class UserUtilAction { |
| 232 | 233 | * @return |
| 233 | 234 | */ |
| 234 | 235 | public static Observable<BaseResult<TokenData>> accessToken(Context context) { |
| 235 | - Map<String, String> map = new HashMap<>(); | |
| 236 | - map.put("appId", AppConfig.getAppId()); | |
| 237 | - map.put("secret", AppConfig.getAppSceret()); | |
| 238 | - return BaseRequest.init().service(ApiBaseServiceOpen.class).accessToken(map); | |
| 236 | + Map<String, String> map = new HashMap<>(); | |
| 237 | + map.put("appId", AppConfig.getAppId()); | |
| 238 | + map.put("secret", AppConfig.getAppSceret()); | |
| 239 | + return BaseRequest.init().service(ApiBaseServiceOpen.class).accessToken(map); | |
| 239 | 240 | } |
| 240 | 241 | |
| 241 | 242 | // /** | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/frame/presenter/FirstLoginPresenter.java
0 → 100644
| 1 | +package com.cnlive.strike.user.frame.presenter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.text.TextUtils; | |
| 5 | + | |
| 6 | +import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | |
| 7 | +import com.cnlive.core.network.BaseResult; | |
| 8 | +import com.cnlive.core.network.HttpConn; | |
| 9 | +import com.cnlive.core.network.NetCallBack; | |
| 10 | +import com.cnlive.strike.user.R; | |
| 11 | +import com.cnlive.strike.user.UserUtilAction; | |
| 12 | +import com.cnlive.strike.user.auth.UserService; | |
| 13 | +import com.cnlive.strike.user.frame.view.FirstLoginView; | |
| 14 | +import com.cnlive.strike.user.network.model.UserData; | |
| 15 | + | |
| 16 | +import java.io.File; | |
| 17 | + | |
| 18 | +import io.reactivex.ObservableSource; | |
| 19 | +import io.reactivex.functions.Function; | |
| 20 | + | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * Created by xiansong on 2018/1/19. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +public class FirstLoginPresenter extends BasePresenter<FirstLoginView> { | |
| 27 | + | |
| 28 | + public void loadUserInfo(Context context) { | |
| 29 | + UserService userService = UserService.getInstance(context); | |
| 30 | + if (userService != null && userService.getAppAccount() != null) { | |
| 31 | + String sid = UserService.getUid(context); | |
| 32 | + String token = userService.getAppAccount().getToken(); | |
| 33 | + HttpConn.action( | |
| 34 | + UserUtilAction.queryUserInfo(context, sid, sid, token) | |
| 35 | + , new NetCallBack<BaseResult<UserData>>() { | |
| 36 | + @Override | |
| 37 | + public void onRequestState(int state) { | |
| 38 | + | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void onSuccess(BaseResult<UserData> data) { | |
| 43 | + userService.setUserInfo(data.getData()); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void onFailure(String errCode, String errMsg) { | |
| 48 | + | |
| 49 | + } | |
| 50 | + } | |
| 51 | + ); | |
| 52 | + } | |
| 53 | + } | |
| 54 | + | |
| 55 | + public void uploadName(Context context, String nickName) { | |
| 56 | + if (TextUtils.isEmpty(nickName)) { | |
| 57 | + if (getView() != null) | |
| 58 | + getView().showToast(context.getString(R.string.user_toast_edit_nickname_empty)); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + if (nickName.trim().length() == 0) { | |
| 62 | + if (getView() != null) | |
| 63 | + getView().showToast(context.getString(R.string.user_toast_edit_nickname_only_space)); | |
| 64 | + return; | |
| 65 | + } | |
| 66 | +// 请输入昵称(不支持表情符号) | |
| 67 | + UserService userService = UserService.getInstance(context); | |
| 68 | + String sid = UserService.getUid(context); | |
| 69 | + String token = userService.getAppAccount().getToken(); | |
| 70 | + HttpConn.action( | |
| 71 | + UserUtilAction.modifyUserInfo(context, sid, "nickName", nickName.trim().replaceAll("[\r\n]", ""), token) | |
| 72 | + .concatMap(new Function<BaseResult, ObservableSource<BaseResult<UserData>>>() { | |
| 73 | + @Override | |
| 74 | + public ObservableSource<BaseResult<UserData>> apply(BaseResult baseResult) throws Exception { | |
| 75 | + if (baseResult.isSuccess()) { | |
| 76 | + return UserUtilAction.queryUserInfo(context, sid, sid, token); | |
| 77 | + } | |
| 78 | + return HttpConn.error(baseResult); | |
| 79 | + } | |
| 80 | + }) | |
| 81 | + , new NetCallBack<BaseResult<UserData>>() { | |
| 82 | + @Override | |
| 83 | + public void onRequestState(int state) { | |
| 84 | + if (state == HttpConn.ON_START) { | |
| 85 | + ifViewAttached(view -> view.showProgress(R.string.upload_nickname_dialog)); | |
| 86 | + } else if (state == HttpConn.ON_END) { | |
| 87 | + ifViewAttached(view -> view.hideProgress()); | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Override | |
| 92 | + public void onSuccess(BaseResult<UserData> data) { | |
| 93 | + userService.setUserInfo(data.getData()); | |
| 94 | + | |
| 95 | +// HelperUtil.modifyUserName(context, nickName); | |
| 96 | + userService.setUserNickName(nickName); | |
| 97 | + ifViewAttached(view -> view.showMainPage()); | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public void onFailure(String errCode, String errMsg) { | |
| 102 | + if ("8".equals(errCode) || "9".equals(errCode)) { | |
| 103 | +// UserOfflineUtil.userInvalid(context); | |
| 104 | +// HelperUtil.userInvalid(context); | |
| 105 | + } else if (errCode.equals(UserUtilAction.TOKEN_ERROR_CODE)) { | |
| 106 | + ifViewAttached(view -> view.showTokenErrorDialog()); | |
| 107 | + } else { | |
| 108 | + ifViewAttached(view -> view.showToast(errMsg)); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + } | |
| 112 | + ); | |
| 113 | + } | |
| 114 | + | |
| 115 | +// public void uploadFile(Context context, String filePath) { | |
| 116 | +// if (updateFaceEvent != null) updateFaceEvent.cencel(); | |
| 117 | +// if (getView() == null) return; | |
| 118 | +// getView().showProgress(R.string.upload_image_dialog); | |
| 119 | +// File file = new File(filePath); | |
| 120 | +// UserService userService = UserService.getInstance(context); | |
| 121 | +// if (file.exists()) { | |
| 122 | +// | |
| 123 | +// updateFaceEvent = Logic.create() | |
| 124 | +// .action(UserUtilAction.accessToken(context)) | |
| 125 | +// .action((BaseInfo<TokenData> data, DataCallback<BaseInfo<FaceData>> callback) -> { | |
| 126 | +// UserUtilAction.updateUserFace(context, UserService.getUid(context), file, userService.getAppAccount().getToken(), data.getData().getAccess_token(), callback); | |
| 127 | +// return null; | |
| 128 | +// }) | |
| 129 | +// .<BaseInfo<FaceData>>event() | |
| 130 | +// .setStateCallback(state -> { | |
| 131 | +// if (getView() == null) return; | |
| 132 | +// if (state == STATE_LOAD) { | |
| 133 | +// | |
| 134 | +// } else if (state == STATE_IDLE) { | |
| 135 | +// getView().hideProgress(); | |
| 136 | +// } | |
| 137 | +// }) | |
| 138 | +// .setFailureCallback((state, message) -> { | |
| 139 | +// if (getView() == null) return; | |
| 140 | +// if (state == 8 || state == 9) { | |
| 141 | +//// UserOfflineUtil.userInvalid(context); | |
| 142 | +// HelperUtil.userInvalid(context); | |
| 143 | +// } else if (state == UserUtilAction.TOKEN_ERROR_CODE) { | |
| 144 | +// getView().showTokenErrorDialog(); | |
| 145 | +// } else { | |
| 146 | +// getView().showToast(message); | |
| 147 | +// } | |
| 148 | +// }) | |
| 149 | +// .setSuccessCallback(data -> { | |
| 150 | +// HelperUtil.modifyUserImage(context, data.getData().getFaceUrl()); | |
| 151 | +//// LoginManager.modifyUserImage( UserService.getUid(context), data.getData().getFaceUrl()); | |
| 152 | +// userService.setUserFaceUrl(data.getData().getFaceUrl(), data.getData().getBigFaceUrl()); | |
| 153 | +// if (getView() == null) return; | |
| 154 | +// getView().photoChange(data.getData().getFaceUrl()); | |
| 155 | +// }) | |
| 156 | +// .start(); | |
| 157 | +// } else { | |
| 158 | +// if (getView() != null) getView().showToast("文件不存在"); | |
| 159 | +// } | |
| 160 | +// } | |
| 161 | + | |
| 162 | +} | |
| 163 | + | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/frame/presenter/QuickLoginPresenter.java
| ... | ... | @@ -19,6 +19,7 @@ import com.cnlive.strike.user.frame.data.QuickLoginData; |
| 19 | 19 | import com.cnlive.strike.user.frame.view.QuickLoginView; |
| 20 | 20 | import com.cnlive.strike.user.model.CNLiveUserInfo; |
| 21 | 21 | import com.cnlive.strike.user.router.user.UserAction; |
| 22 | +import com.cnlive.strike.user.ui.activity.FirstLoginActivity; | |
| 22 | 23 | import com.cnlive.strike.user.ui.fragment.QuickLoginFragment; |
| 23 | 24 | import com.cnlive.strike.user.util.RegexUtils; |
| 24 | 25 | import com.cnlive.strike.user.util.TimeEvent; |
| ... | ... | @@ -169,7 +170,9 @@ public class QuickLoginPresenter extends BasePresenter<QuickLoginView> { |
| 169 | 170 | } else { |
| 170 | 171 | //友盟账号登录统计,暂时只有平台登录,后续对接三方登录 |
| 171 | 172 | // MobclickAgent.onProfileSignIn("CNLive", user.getUid()); |
| 172 | - ifViewAttached(view -> view.showMainView(false, false)); | |
| 173 | +// ifViewAttached(view -> view.showMainView(false, false)); | |
| 174 | + //todo 测试首次用户 | |
| 175 | + ifViewAttached(view -> view.showEditView(false)); | |
| 173 | 176 | } |
| 174 | 177 | AppConfig.setCountryCode(""); |
| 175 | 178 | AppConfig.setVerificationCode(""); | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/frame/view/FirstLoginView.java
0 → 100644
| 1 | +package com.cnlive.strike.user.frame.view; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.content.Intent; | |
| 6 | +import android.text.TextUtils; | |
| 7 | + | |
| 8 | +import com.cnlive.core.libs.base.frame.view.BaseView; | |
| 9 | +import com.cnlive.core.libs.base.util.AlertUtil; | |
| 10 | +import com.cnlive.core.libs.base.util.GlideUtil; | |
| 11 | +import com.cnlive.strike.user.R; | |
| 12 | +import com.cnlive.strike.user.model.LoginSuccessInfo; | |
| 13 | +import com.cnlive.strike.user.model.msg.UserEventMsg; | |
| 14 | +import com.cnlive.strike.user.ui.activity.FirstLoginActivity; | |
| 15 | +import com.cnlive.strike.user.ui.fragment.FirstLoginFragment; | |
| 16 | +import com.cnlive.strike.user.ui.widget.TokenErrorDialog; | |
| 17 | + | |
| 18 | +import org.greenrobot.eventbus.EventBus; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Created by xiansong on 2018/1/19. | |
| 22 | + */ | |
| 23 | + | |
| 24 | +public class FirstLoginView extends BaseView { | |
| 25 | + private FirstLoginFragment fragment; | |
| 26 | + | |
| 27 | + public FirstLoginView(FirstLoginFragment fragment) { | |
| 28 | + this.fragment = fragment; | |
| 29 | + } | |
| 30 | + | |
| 31 | + private Activity getContext() { | |
| 32 | + return fragment.getActivity(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void showToast(String msg) { | |
| 36 | + if (getContext() == null) return; | |
| 37 | + Context context = getContext(); | |
| 38 | + AlertUtil.showDeftToast(context, msg); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void showProgress(int stringId) { | |
| 42 | + if (!fragment.mProgressDialog.isShowing()) { | |
| 43 | + String tag = getContext().getString(stringId); | |
| 44 | + fragment.mProgressDialog.setMessage(tag); | |
| 45 | + fragment.mProgressDialog.show(); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void hideProgress() { | |
| 50 | + if (fragment.mProgressDialog.isShowing()) fragment.mProgressDialog.dismiss(); | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void photoChange(String faceUrl) { | |
| 54 | + if (getContext() == null) return; | |
| 55 | + GlideUtil.init(fragment, faceUrl).error(R.drawable.touxiang_circle).circleCrop().into(fragment.binding.ivUserIcon); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void showMainPage() { | |
| 59 | + if (getContext() == null) return; | |
| 60 | + //设置跳转信息 | |
| 61 | + LoginSuccessInfo successInfo = new LoginSuccessInfo(); | |
| 62 | + successInfo.setClickAd(fragment.clickAd); | |
| 63 | + successInfo.setTagMsg(fragment.tagMsg); | |
| 64 | + EventBus.getDefault().post(new UserEventMsg(UserEventMsg.LOGIN_SUCCESS, successInfo)); | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | +// Intent intent = new Intent(getContext(), MainTestActivity.class); | |
| 69 | +// if (!TextUtils.isEmpty(fragment.tagMsg)) | |
| 70 | +// intent.putExtra("classifyTagMsg", fragment.tagMsg); | |
| 71 | +// | |
| 72 | +// intent.putExtra(FirstLoginActivity.TAG_CLICK_AD, fragment.clickAd); | |
| 73 | +// getContext().startActivity(intent); | |
| 74 | +// getContext().finish(); | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void showTokenErrorDialog() { | |
| 78 | + if (fragment.tokenErrorDialog != null) | |
| 79 | + fragment.tokenErrorDialog.dismiss(); | |
| 80 | + fragment.tokenErrorDialog = TokenErrorDialog.showTokenErrorDialog(fragment.getActivity()); | |
| 81 | + } | |
| 82 | + | |
| 83 | + | |
| 84 | +} | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/frame/view/QuickLoginView.java
| ... | ... | @@ -3,6 +3,7 @@ package com.cnlive.strike.user.frame.view; |
| 3 | 3 | import android.accounts.Account; |
| 4 | 4 | import android.app.Activity; |
| 5 | 5 | import android.content.Context; |
| 6 | +import android.content.Intent; | |
| 6 | 7 | import android.text.Editable; |
| 7 | 8 | import android.text.Spannable; |
| 8 | 9 | import android.text.SpannableStringBuilder; |
| ... | ... | @@ -24,6 +25,8 @@ import com.cnlive.strike.user.frame.data.OtherUserInfo; |
| 24 | 25 | import com.cnlive.strike.user.model.LoginSuccessInfo; |
| 25 | 26 | import com.cnlive.strike.user.sms.OnSmsCatchListener; |
| 26 | 27 | import com.cnlive.strike.user.sms.SmsVerifyCatcher; |
| 28 | +import com.cnlive.strike.user.ui.activity.FirstLoginActivity; | |
| 29 | +import com.cnlive.strike.user.ui.activity.LoginActivity; | |
| 27 | 30 | import com.cnlive.strike.user.ui.fragment.QuickLoginFragment; |
| 28 | 31 | |
| 29 | 32 | import java.util.regex.Matcher; |
| ... | ... | @@ -180,16 +183,16 @@ public class QuickLoginView extends BaseView { |
| 180 | 183 | public void showEditView(boolean isHasOtherUserInfo) { |
| 181 | 184 | if (getContext() == null) return; |
| 182 | 185 | //设置跳转信息 |
| 183 | - LoginSuccessInfo successInfo = new LoginSuccessInfo(); | |
| 184 | - successInfo.setTagMsg(TextUtils.isEmpty(fragment.tagMsg) ? "" : fragment.tagMsg); | |
| 185 | - successInfo.setClickAd(fragment.clickAd); | |
| 186 | +// LoginSuccessInfo successInfo = new LoginSuccessInfo(); | |
| 187 | +// successInfo.setTagMsg(TextUtils.isEmpty(fragment.tagMsg) ? "" : fragment.tagMsg); | |
| 188 | +// successInfo.setClickAd(fragment.clickAd); | |
| 186 | 189 | // HelperUtil.isNewUser(fragment.getActivity(), successInfo, isHasOtherUserInfo); |
| 187 | 190 | |
| 188 | -// Intent intent = new Intent(getContext(), FirstLoginActivity.class); | |
| 189 | -// intent.putExtra(LoginActivity.TAG_MSG, TextUtils.isEmpty(fragment.tagMsg) ? "" : fragment.tagMsg); | |
| 190 | -// intent.putExtra(LoginActivity.TAG_CLICK_AD, fragment.clickAd); | |
| 191 | -// getContext().startActivity(intent); | |
| 192 | -// getContext().finish(); | |
| 191 | + Intent intent = new Intent(getContext(), FirstLoginActivity.class); | |
| 192 | + intent.putExtra(LoginActivity.TAG_MSG, TextUtils.isEmpty(fragment.tagMsg) ? "" : fragment.tagMsg); | |
| 193 | + intent.putExtra(LoginActivity.TAG_CLICK_AD, fragment.clickAd); | |
| 194 | + getContext().startActivity(intent); | |
| 195 | + getContext().finish(); | |
| 193 | 196 | } |
| 194 | 197 | |
| 195 | 198 | public void showMainView(boolean isNewUser, boolean isHasOtherUserInfo) { | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/router/user/UserOfflineUtil.java
| 1 | 1 | package com.cnlive.strike.user.router.user; |
| 2 | 2 | |
| 3 | +import android.app.Activity; | |
| 3 | 4 | import android.content.Context; |
| 4 | 5 | |
| 6 | +import androidx.appcompat.app.AppCompatActivity; | |
| 7 | + | |
| 5 | 8 | import com.cnlive.core.libs.base.util.AlertUtil; |
| 6 | 9 | import com.cnlive.strike.user.auth.UserService; |
| 10 | +import com.kongzue.dialog.interfaces.OnMenuItemClickListener; | |
| 11 | +import com.kongzue.dialog.v3.BottomMenu; | |
| 7 | 12 | |
| 8 | 13 | import org.greenrobot.eventbus.EventBus; |
| 9 | 14 | |
| ... | ... | @@ -38,6 +43,13 @@ public class UserOfflineUtil { |
| 38 | 43 | |
| 39 | 44 | //todo BottomSheet |
| 40 | 45 | public static void logout(Context context) { |
| 46 | + | |
| 47 | + BottomMenu.show((AppCompatActivity) context, new String[]{"菜单1", "菜单2", "菜单3"}, new OnMenuItemClickListener() { | |
| 48 | + @Override | |
| 49 | + public void onClick(String text, int index) { | |
| 50 | + //返回参数 text 即菜单名称,index 即菜单索引 | |
| 51 | + } | |
| 52 | + }); | |
| 41 | 53 | // new BottomSheet.BottomListSheetBuilder(context) |
| 42 | 54 | // .addItem("退出登录", "", true) |
| 43 | 55 | // .addItem("取消") | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/ui/activity/FirstLoginActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.user.ui.activity; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.text.TextUtils; | |
| 6 | + | |
| 7 | +import androidx.annotation.NonNull; | |
| 8 | +import androidx.fragment.app.FragmentManager; | |
| 9 | + | |
| 10 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | |
| 11 | +import com.cnlive.core.libs.base.util.AlertUtil; | |
| 12 | +import com.cnlive.core.libs.base.util.DoublePressed; | |
| 13 | +import com.cnlive.core.libs.base.util.FragmentUtil; | |
| 14 | +import com.cnlive.strike.user.R; | |
| 15 | +import com.cnlive.strike.user.ui.fragment.FirstLoginFragment; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * @author Lynn | |
| 19 | + * @date 2017/12/22 | |
| 20 | + */ | |
| 21 | + | |
| 22 | +public class FirstLoginActivity extends BaseActivity { | |
| 23 | + private FirstLoginFragment firstLoginFragment; | |
| 24 | + private String tagMsg; | |
| 25 | + public static String TAG_CLICK_AD = "clickAd"; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + protected int getViewLayoutId() { | |
| 29 | + return R.layout.activity_login; | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + protected void initParam() { | |
| 34 | + super.initParam(); | |
| 35 | + tagMsg = getIntent().getStringExtra(LoginActivity.TAG_MSG); | |
| 36 | + boolean clickAd = getIntent().getBooleanExtra(TAG_CLICK_AD, false); | |
| 37 | + firstLoginFragment = new FirstLoginFragment(); | |
| 38 | + Bundle args = new Bundle(); | |
| 39 | + args.putString(LoginActivity.TAG_MSG, TextUtils.isEmpty(tagMsg) ? "" : tagMsg); | |
| 40 | + args.putBoolean(TAG_CLICK_AD, clickAd); | |
| 41 | + firstLoginFragment.setArguments(args); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + protected void initView() { | |
| 46 | + super.initView(); | |
| 47 | + FragmentManager fragmentManager = getSupportFragmentManager(); | |
| 48 | + FragmentUtil fragmentUtil = new FragmentUtil(R.id.loginContent); | |
| 49 | + fragmentUtil.initFragment(firstLoginFragment, fragmentManager); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + protected void onDestroy() { | |
| 54 | + super.onDestroy(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| 59 | + super.onActivityResult(requestCode, resultCode, data); | |
| 60 | + firstLoginFragment.onActivityResult(requestCode, resultCode, data); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
| 65 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| 66 | + if (firstLoginFragment != null) | |
| 67 | + firstLoginFragment.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public void onBackPressed() { | |
| 72 | + if (DoublePressed.onDoublePressed()) { | |
| 73 | + super.onBackPressed(); | |
| 74 | + } else { | |
| 75 | + AlertUtil.showDeftToast(this, getString(R.string.msg_exit)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | +} | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/ui/activity/LoginActivity.java
| ... | ... | @@ -24,21 +24,13 @@ public class LoginActivity extends BaseActivity { |
| 24 | 24 | public static String FROM_TOKEN_ERROR = "from_token_error"; |
| 25 | 25 | public static String TAG_MSG = "tagMsg"; |
| 26 | 26 | public static String TAG_SHARE = "tagValue"; |
| 27 | - public static String TAG_CLICK_AD= "clickAd"; | |
| 27 | + public static String TAG_CLICK_AD = "clickAd"; | |
| 28 | 28 | private Fragment quickLoginFragment; |
| 29 | 29 | private boolean fromTokenError; |
| 30 | 30 | private String tagMsg; |
| 31 | 31 | private String shareType; |
| 32 | 32 | private boolean clickAd; |
| 33 | 33 | |
| 34 | - // @Override | |
| 35 | -// public Resources getResources() { | |
| 36 | -// Resources res = super.getResources(); | |
| 37 | -// Configuration config = new Configuration(); | |
| 38 | -// config.setToDefaults(); | |
| 39 | -// res.updateConfiguration(config, res.getDisplayMetrics()); | |
| 40 | -// return res; | |
| 41 | -// } | |
| 42 | 34 | public static void start(Context context) { |
| 43 | 35 | Intent intent = new Intent(context, LoginActivity.class); |
| 44 | 36 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); |
| ... | ... | @@ -86,7 +78,7 @@ public class LoginActivity extends BaseActivity { |
| 86 | 78 | fromTokenError = getIntent().getBooleanExtra(FROM_TOKEN_ERROR, false); |
| 87 | 79 | tagMsg = getIntent().getStringExtra(TAG_MSG) == null ? "" : getIntent().getStringExtra(TAG_MSG); |
| 88 | 80 | shareType = getIntent().getStringExtra(TAG_SHARE); |
| 89 | - clickAd = getIntent().getBooleanExtra(TAG_CLICK_AD,false); | |
| 81 | + clickAd = getIntent().getBooleanExtra(TAG_CLICK_AD, false); | |
| 90 | 82 | addFragment(); |
| 91 | 83 | } |
| 92 | 84 | |
| ... | ... | @@ -106,15 +98,15 @@ public class LoginActivity extends BaseActivity { |
| 106 | 98 | protected void onNewIntent(Intent intent) { |
| 107 | 99 | super.onNewIntent(intent); |
| 108 | 100 | tagMsg = intent.getStringExtra(TAG_MSG) == null ? "" : intent.getStringExtra(TAG_MSG); |
| 109 | - clickAd = getIntent().getBooleanExtra(TAG_CLICK_AD,false); | |
| 101 | + clickAd = getIntent().getBooleanExtra(TAG_CLICK_AD, false); | |
| 110 | 102 | addFragment(); |
| 111 | 103 | } |
| 112 | 104 | |
| 113 | - private void addFragment() { | |
| 105 | + private void addFragment() { | |
| 114 | 106 | if ("shareIM".equals(shareType) || "shareMom".equals(shareType)) { |
| 115 | - quickLoginFragment = QuickLoginFragment.newInstance(fromTokenError, tagMsg, shareType,clickAd); | |
| 107 | + quickLoginFragment = QuickLoginFragment.newInstance(fromTokenError, tagMsg, shareType, clickAd); | |
| 116 | 108 | } else { |
| 117 | - quickLoginFragment = QuickLoginFragment.newInstance(fromTokenError, tagMsg,clickAd); | |
| 109 | + quickLoginFragment = QuickLoginFragment.newInstance(fromTokenError, tagMsg, clickAd); | |
| 118 | 110 | } |
| 119 | 111 | |
| 120 | 112 | FragmentManager fragmentManager = getSupportFragmentManager(); | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/ui/fragment/FirstLoginFragment.java
0 → 100644
| 1 | +package com.cnlive.strike.user.ui.fragment; | |
| 2 | + | |
| 3 | +import android.Manifest; | |
| 4 | +import android.app.Activity; | |
| 5 | +import android.app.Dialog; | |
| 6 | +import android.app.ProgressDialog; | |
| 7 | +import android.content.Intent; | |
| 8 | +import android.text.Editable; | |
| 9 | +import android.text.TextUtils; | |
| 10 | +import android.text.TextWatcher; | |
| 11 | +import android.view.View; | |
| 12 | + | |
| 13 | +import androidx.annotation.NonNull; | |
| 14 | +import androidx.appcompat.app.AppCompatActivity; | |
| 15 | + | |
| 16 | +import com.cnlive.core.libs.base.frame.fragment.BaseFragment; | |
| 17 | +import com.cnlive.core.libs.base.util.AlertUtil; | |
| 18 | +import com.cnlive.core.libs.base.util.GlideUtil; | |
| 19 | +import com.cnlive.core.libs.base.util.StatusBarConfig; | |
| 20 | +import com.cnlive.strike.user.R; | |
| 21 | +import com.cnlive.strike.user.auth.UserService; | |
| 22 | +import com.cnlive.strike.user.databinding.FragmentFirstLoginBinding; | |
| 23 | +import com.cnlive.strike.user.frame.data.FirstLoginData; | |
| 24 | +import com.cnlive.strike.user.frame.presenter.FirstLoginPresenter; | |
| 25 | +import com.cnlive.strike.user.frame.view.FirstLoginView; | |
| 26 | +import com.cnlive.strike.user.model.CNLiveUserInfo; | |
| 27 | +import com.cnlive.strike.user.router.user.UserOfflineUtil; | |
| 28 | +import com.cnlive.strike.user.ui.activity.FirstLoginActivity; | |
| 29 | +import com.cnlive.strike.user.ui.activity.LoginActivity; | |
| 30 | + | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Created by xiansong on 2018/1/19. | |
| 34 | + */ | |
| 35 | + | |
| 36 | +public class FirstLoginFragment extends BaseFragment<FirstLoginView, FirstLoginPresenter> { | |
| 37 | + | |
| 38 | + public ProgressDialog mProgressDialog = null; | |
| 39 | + public Dialog tokenErrorDialog; | |
| 40 | + public String tagMsg; | |
| 41 | + public boolean clickAd; | |
| 42 | + public FragmentFirstLoginBinding binding; | |
| 43 | + public FirstLoginData data; | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + protected void initFragmentStyle() { | |
| 47 | + super.initFragmentStyle(); | |
| 48 | + setStatusBarTextColor(StatusBarConfig.WHITE); | |
| 49 | + setStatusBarColor(R.color.color_fff, 0); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + protected int getBindLayoutId() { | |
| 54 | + return R.layout.fragment_first_login; | |
| 55 | + } | |
| 56 | + | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + protected void initParams() { | |
| 60 | + super.initParams(); | |
| 61 | + if (getArguments() != null) { | |
| 62 | + tagMsg = getArguments().getString(LoginActivity.TAG_MSG); | |
| 63 | + clickAd = getArguments().getBoolean(FirstLoginActivity.TAG_CLICK_AD); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + protected void initBindingData() { | |
| 69 | + super.initBindingData(); | |
| 70 | + binding = (FragmentFirstLoginBinding) baseBinding; | |
| 71 | + if (null == data) { | |
| 72 | + data = new FirstLoginData(); | |
| 73 | + } | |
| 74 | + binding.setData(data); | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + protected void initView() { | |
| 79 | + super.initView(); | |
| 80 | + mProgressDialog = new ProgressDialog(getActivity()); | |
| 81 | + mProgressDialog.setOnCancelListener(dialog -> getMvpView().hideProgress()); | |
| 82 | + CNLiveUserInfo userInfo = UserService.getInstance(getActivity()).getAppAccount(); | |
| 83 | + if (userInfo != null) { | |
| 84 | + data.setImage(userInfo.getFaceUrl()); | |
| 85 | + data.setName(userInfo.getNickName()); | |
| 86 | + } | |
| 87 | + | |
| 88 | + if (!TextUtils.isEmpty(data.getImage())) { | |
| 89 | + GlideUtil.init(getActivity(), data.getImage()).error(R.drawable.touxiang_circle).circleCrop().into(binding.ivUserIcon); | |
| 90 | + | |
| 91 | + } | |
| 92 | + binding.setClick(v -> { | |
| 93 | + if (v.getId() == R.id.login) getPresenter().uploadName(getActivity(), data.getName()); | |
| 94 | + if (v.getId() == R.id.backLogout) UserOfflineUtil.logout(getActivity()); | |
| 95 | + }); | |
| 96 | + binding.setImageClick(v -> selectPhoto(false)); | |
| 97 | + | |
| 98 | + binding.ivDelete.setOnClickListener(v -> binding.etNickName.setText("")); | |
| 99 | + binding.etNickName.addTextChangedListener(new TextWatcher() { | |
| 100 | + @Override | |
| 101 | + public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| 102 | + | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Override | |
| 106 | + public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| 107 | + | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public void afterTextChanged(Editable s) { | |
| 112 | + if (s.length() > 0 && s.length() <= 15) { | |
| 113 | + binding.ivDelete.setVisibility(View.VISIBLE); | |
| 114 | + if (s.length() == 15) { | |
| 115 | + AlertUtil.showDeftToast(getActivity(), "昵称最长15个字"); | |
| 116 | + } | |
| 117 | + } else { | |
| 118 | + binding.ivDelete.setVisibility(View.INVISIBLE); | |
| 119 | + } | |
| 120 | + | |
| 121 | + } | |
| 122 | + }); | |
| 123 | + } | |
| 124 | + | |
| 125 | + | |
| 126 | + private static final String[] PERMISSION = new String[]{ | |
| 127 | + Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}; | |
| 128 | + | |
| 129 | + | |
| 130 | + public void selectPhoto(boolean fromResult) { | |
| 131 | +// boolean hasPermission = fromResult ? AppUtil.checkPermissions(getActivity(), PERMISSION) : PermissionChecker.checkPermissions(getActivity() | |
| 132 | +// , PERMISSION, REQUEST_CODE_PERMISSION_CAMERA, com.cnlive.media.picker.R.string.dialog_imagepicker_permission_sdcard_message); | |
| 133 | +// | |
| 134 | +// if (hasPermission) { | |
| 135 | +// ImagePicker imagePicker = new ImagePicker.Builder() | |
| 136 | +// //最大选择图片数目,默认40张 | |
| 137 | +// .maxNum(1) | |
| 138 | +// .setSelectGif(false) | |
| 139 | +// //是否需要相机(默认false) | |
| 140 | +// .needCamera(true) | |
| 141 | +// //选择模式(默认PICKER_IMAGE_VIDEO) PICKER_IMAGE-->图片 PICKER_VIDEO-->视频 PICKER_IMAGE_VIDEO-->图片&视频 | |
| 142 | +// .selectMode(PickerConfig.PICKER_IMAGE) | |
| 143 | +// //拍照或录像存储位置 默认Environment.getExternalStorageDirectory().getPath() + File.separator + "JCamera" | |
| 144 | +// .cachePath(Environment.getExternalStorageDirectory() + "/strike/file/") | |
| 145 | +// //是否为发朋友圈模式(默认false) true-->图片与视频不能同时选择 | |
| 146 | +// .isFriendCircle(false) | |
| 147 | +// //裁剪 只有在单选模式下才可以使用 | |
| 148 | +// .doCrop(1, 1, 300, 300) | |
| 149 | +// //是否开启单选模式(默认false) | |
| 150 | +// .isSinglePick(true) | |
| 151 | +// .builder(); | |
| 152 | +// | |
| 153 | +// //跳转到图片选择页面 activity 请求码 结果码 | |
| 154 | +// imagePicker.start(getActivity(), PickerConfig.PICKER_IMAGE, PickerConfig.DEFAULT_RESULT_CODE); | |
| 155 | +// } | |
| 156 | + | |
| 157 | + } | |
| 158 | + | |
| 159 | + @Override | |
| 160 | + public void onPause() { | |
| 161 | + super.onPause(); | |
| 162 | + getMvpView().hideProgress(); | |
| 163 | + if (tokenErrorDialog != null) tokenErrorDialog.dismiss(); | |
| 164 | + } | |
| 165 | + | |
| 166 | + @Override | |
| 167 | + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
| 168 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| 169 | + Activity activity = getActivity(); | |
| 170 | + if (activity == null) return; | |
| 171 | +// if (requestCode == REQUEST_CODE_PERMISSION_CAMERA) { | |
| 172 | +// boolean hasPermission = PermissionChecker.onRequestPermissionsResult( | |
| 173 | +// activity, requestCode, permissions, grantResults, false, | |
| 174 | +// com.cnlive.media.picker.R.string.dialog_imagepicker_permission_sdcard_message)[0]; | |
| 175 | +// if (hasPermission) { | |
| 176 | +// selectPhoto(true); | |
| 177 | +// } | |
| 178 | +// } | |
| 179 | + } | |
| 180 | + | |
| 181 | + @Override | |
| 182 | + public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| 183 | + super.onActivityResult(requestCode, resultCode, data); | |
| 184 | +// if (resultCode == PickerConfig.DEFAULT_RESULT_CODE) { | |
| 185 | +// List<Media> list = data.getParcelableArrayListExtra(PickerConfig.EXTRA_RESULT); | |
| 186 | +// if (list == null) return; | |
| 187 | +// if (getPresenter() == null) return; | |
| 188 | +// if (list.size() > 0 && list.get(0) != null && !TextUtils.isEmpty(list.get(0).path)) | |
| 189 | +// getPresenter().uploadFile(FirstLoginFragment.this.getActivity(), list.get(0).path); | |
| 190 | +// | |
| 191 | +// } | |
| 192 | + } | |
| 193 | +} | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/ui/fragment/QuickLoginFragment.java
| ... | ... | @@ -51,11 +51,9 @@ public class QuickLoginFragment extends BaseFragment<QuickLoginView, QuickLoginP |
| 51 | 51 | public FragmentQuickLoginBinding binding; |
| 52 | 52 | public QuickLoginData data; |
| 53 | 53 | |
| 54 | - @Nullable | |
| 55 | 54 | @Override |
| 56 | - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
| 57 | - binding = DataBindingUtil.inflate(inflater, R.layout.fragment_quick_login, container, false); | |
| 58 | - return binding.getRoot(); | |
| 55 | + protected int getBindLayoutId() { | |
| 56 | + return R.layout.fragment_quick_login; | |
| 59 | 57 | } |
| 60 | 58 | |
| 61 | 59 | public static QuickLoginFragment newInstance(boolean fromTokenError, String tagMsg, boolean clickAd) { |
| ... | ... | @@ -80,9 +78,15 @@ public class QuickLoginFragment extends BaseFragment<QuickLoginView, QuickLoginP |
| 80 | 78 | } |
| 81 | 79 | |
| 82 | 80 | @Override |
| 83 | - public void onCreate(Bundle savedInstanceState) { | |
| 84 | - super.onCreate(savedInstanceState); | |
| 85 | - if (getActivity() == null) return; | |
| 81 | + protected void initFragmentStyle() { | |
| 82 | + super.initFragmentStyle(); | |
| 83 | + setStatusBarColor(R.color.color_fff, 0); | |
| 84 | + setStatusBarTextColor(StatusBarConfig.BLACK); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + protected void initParams() { | |
| 89 | + super.initParams(); | |
| 86 | 90 | if (getArguments() != null) { |
| 87 | 91 | fromTokenError = getArguments().getBoolean(LoginActivity.FROM_TOKEN_ERROR, false); |
| 88 | 92 | tagMsg = getArguments().getString(LoginActivity.TAG_MSG); |
| ... | ... | @@ -90,8 +94,19 @@ public class QuickLoginFragment extends BaseFragment<QuickLoginView, QuickLoginP |
| 90 | 94 | clickAd = getArguments().getBoolean(LoginActivity.TAG_CLICK_AD); |
| 91 | 95 | } |
| 92 | 96 | uri = UserAction.getUri(getActivity()); |
| 93 | - setStatusBarColor(R.color.color_fff, 0); | |
| 94 | - setStatusBarTextColor(StatusBarConfig.BLACK); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + protected void initBindingData() { | |
| 101 | + super.initBindingData(); | |
| 102 | + binding= (FragmentQuickLoginBinding) baseBinding; | |
| 103 | + data = new QuickLoginData(); | |
| 104 | + binding.setData(data); | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + protected void initView() { | |
| 109 | + super.initView(); | |
| 95 | 110 | adapter = new UserListAdapter(getActivity(), 0); |
| 96 | 111 | adapter.setClickListener((name) -> getMvpView().onUploadLoginUser(name)); |
| 97 | 112 | adapter.setDeleteListener((name) -> getMvpView().onDeleteLoginUser(name)); |
| ... | ... | @@ -101,9 +116,13 @@ public class QuickLoginFragment extends BaseFragment<QuickLoginView, QuickLoginP |
| 101 | 116 | mProgressDialog.setOnCancelListener(dialog -> { |
| 102 | 117 | // getPresenter().cancelLoad(); |
| 103 | 118 | }); |
| 119 | + getMvpView().setAgreementText(); | |
| 120 | + binding.setClickListener(v -> onClick(v.getId())); | |
| 121 | + binding.setAdapter(adapter); | |
| 122 | + getPresenter().init(getContext()); | |
| 123 | + if (getMvpView() != null) getMvpView().initView(); | |
| 104 | 124 | } |
| 105 | 125 | |
| 106 | - | |
| 107 | 126 | @Override |
| 108 | 127 | public void onStart() { |
| 109 | 128 | super.onStart(); |
| ... | ... | @@ -116,22 +135,6 @@ public class QuickLoginFragment extends BaseFragment<QuickLoginView, QuickLoginP |
| 116 | 135 | if (smsVerifyCatcher != null) smsVerifyCatcher.onStop(); |
| 117 | 136 | } |
| 118 | 137 | |
| 119 | - @Override | |
| 120 | - protected void initBindingData() { | |
| 121 | - super.initBindingData(); | |
| 122 | - data = new QuickLoginData(); | |
| 123 | - binding.setData(data); | |
| 124 | - } | |
| 125 | - | |
| 126 | - @Override | |
| 127 | - protected void initView() { | |
| 128 | - super.initView(); | |
| 129 | - getMvpView().setAgreementText(); | |
| 130 | - binding.setClickListener(v -> onClick(v.getId())); | |
| 131 | - binding.setAdapter(adapter); | |
| 132 | - getPresenter().init(getContext()); | |
| 133 | - if (getMvpView() != null) getMvpView().initView(); | |
| 134 | - } | |
| 135 | 138 | |
| 136 | 139 | /** |
| 137 | 140 | * 点击事件 | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/ui/widget/TokenErrorDialog.java
0 → 100644
| 1 | +package com.cnlive.strike.user.ui.widget; | |
| 2 | + | |
| 3 | +import android.app.Dialog; | |
| 4 | +import android.content.Context; | |
| 5 | + | |
| 6 | +import com.cnlive.strike.user.R; | |
| 7 | +import com.cnlive.strike.user.ui.activity.LoginActivity; | |
| 8 | +import com.cnlive.strike.user.util.AlertDialogUtils; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Created by Lynn on 2019/1/19. | |
| 12 | + */ | |
| 13 | + | |
| 14 | +public class TokenErrorDialog { | |
| 15 | + public static Dialog showTokenErrorDialog(Context context) { | |
| 16 | + return AlertDialogUtils.showTwoButtonDialog(context, | |
| 17 | + "取消", | |
| 18 | + "重新登录", | |
| 19 | + "修改个人信息", | |
| 20 | + R.color.color_dialog_btn, | |
| 21 | + R.color.color_ffa300, | |
| 22 | + new AlertDialogUtils.DialogTwoListener() { | |
| 23 | + @Override | |
| 24 | + public void onClickLeft(Dialog dialog) { | |
| 25 | + dialog.dismiss(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public void onClickRight(Dialog dialog) { | |
| 30 | + dialog.dismiss(); | |
| 31 | + LoginActivity.start(context, true); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + ); | |
| 35 | + } | |
| 36 | +} | ... | ... |
cloud/user/src/main/java/com/cnlive/strike/user/util/AlertDialogUtils.java
0 → 100644
| 1 | +package com.cnlive.strike.user.util; | |
| 2 | + | |
| 3 | +import android.app.Dialog; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.view.LayoutInflater; | |
| 6 | +import android.view.View; | |
| 7 | +import android.view.ViewGroup; | |
| 8 | +import android.widget.TextView; | |
| 9 | + | |
| 10 | +import com.cnlive.core.libs.base.util.DensityUtils; | |
| 11 | +import com.cnlive.core.libs.base.util.ScreenUtil; | |
| 12 | +import com.cnlive.strike.user.R; | |
| 13 | + | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by Lynn on 2018/3/27. | |
| 17 | + */ | |
| 18 | + | |
| 19 | +public class AlertDialogUtils { | |
| 20 | + | |
| 21 | + public static Dialog showTwoButtonDialog(Context context, String leftString, String rightString, String content, int leftTextColor, int rightTextColor, final DialogTwoListener l) { | |
| 22 | + final Dialog dialog = new Dialog(context, R.style.CustomDialogStyleMediaPicker); | |
| 23 | + View view = LayoutInflater.from(context).inflate(R.layout.layout_alert_dialog_2_btn, null); | |
| 24 | + ((TextView) (view.findViewById(R.id.content))).setText(content); | |
| 25 | + ((TextView) (view.findViewById(R.id.btn_left))).setText(leftString); | |
| 26 | + ((TextView) (view.findViewById(R.id.btn_left))).setTextColor(context.getResources().getColor(leftTextColor)); | |
| 27 | + ((TextView) (view.findViewById(R.id.btn_right))).setText(rightString); | |
| 28 | + ((TextView) (view.findViewById(R.id.btn_right))).setTextColor(context.getResources().getColor(rightTextColor)); | |
| 29 | + ViewGroup.LayoutParams vl = new ViewGroup.LayoutParams(ScreenUtil.getScreenWidth(context) - DensityUtils.dp2px(context, 146), ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 30 | + view.findViewById(R.id.btn_left).setOnClickListener(new View.OnClickListener() { | |
| 31 | + @Override | |
| 32 | + public void onClick(View v) { | |
| 33 | + if (l == null) { | |
| 34 | + dialog.dismiss(); | |
| 35 | + } else { | |
| 36 | + l.onClickLeft(dialog); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + }); | |
| 40 | + view.findViewById(R.id.btn_right).setOnClickListener(new View.OnClickListener() { | |
| 41 | + @Override | |
| 42 | + public void onClick(View v) { | |
| 43 | + if (l == null) { | |
| 44 | + dialog.dismiss(); | |
| 45 | + } else { | |
| 46 | + l.onClickRight(dialog); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + }); | |
| 50 | + dialog.setCanceledOnTouchOutside(false); | |
| 51 | + dialog.setCancelable(false); | |
| 52 | + dialog.addContentView(view, vl); | |
| 53 | + dialog.show(); | |
| 54 | + return dialog; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public interface DialogTwoListener { | |
| 58 | + void onClickLeft(Dialog dialog); | |
| 59 | + | |
| 60 | + void onClickRight(Dialog dialog); | |
| 61 | + } | |
| 62 | +} | ... | ... |
config.gradle
| ... | ... | @@ -20,12 +20,12 @@ ext { |
| 20 | 20 | //用户 |
| 21 | 21 | // cloud_user: project(':cloud:user'), |
| 22 | 22 | //基础库 |
| 23 | - core_base : project(':core:base') | |
| 23 | + core_base: project(':core:base') | |
| 24 | 24 | |
| 25 | 25 | ] |
| 26 | 26 | |
| 27 | 27 | androidx = [ |
| 28 | - appcompat : "androidx.appcompat:appcompat:1.0.2", | |
| 28 | + appcompat : "androidx.appcompat:appcompat:1.1.0+", | |
| 29 | 29 | constraintlayout: "androidx.constraintlayout:constraintlayout:1.1.3", |
| 30 | 30 | multidex : "androidx.multidex:multidex:2.0.1" |
| 31 | 31 | ] |
| ... | ... | @@ -47,6 +47,8 @@ ext { |
| 47 | 47 | ] |
| 48 | 48 | |
| 49 | 49 | library = [ |
| 50 | +// //空祖对话框 https://github.com/kongzue/DialogV3 | |
| 51 | +// kongzueDailog : 'com.kongzue.dialog_v3x:dialog:3.1.6', | |
| 50 | 52 | //视讯云加密 |
| 51 | 53 | libCnencipher : 'com.cnlive:lib-cnencipher:1.1.1', |
| 52 | 54 | //视频库 |
| ... | ... | @@ -98,6 +100,8 @@ ext { |
| 98 | 100 | // ] |
| 99 | 101 | //基础三方库 |
| 100 | 102 | base_librarys = [ |
| 103 | + //对话框 | |
| 104 | +// library.kongzueDailog, | |
| 101 | 105 | //视讯云加密库 |
| 102 | 106 | library.libCnencipher, |
| 103 | 107 | //视频库 | ... | ... |
core/base/build.gradle
| 1 | 1 | apply plugin: 'com.android.library' |
| 2 | 2 | |
| 3 | 3 | android { |
| 4 | - compileSdkVersion 29 | |
| 5 | - buildToolsVersion "29.0.2" | |
| 6 | - | |
| 4 | +// compileSdkVersion 29 | |
| 5 | +// buildToolsVersion "29.0.2" | |
| 6 | +// | |
| 7 | 7 | defaultConfig { |
| 8 | - minSdkVersion 16 | |
| 9 | - targetSdkVersion 29 | |
| 10 | - versionCode 1 | |
| 11 | - versionName "1.0" | |
| 12 | - } | |
| 13 | - | |
| 14 | - buildTypes { | |
| 15 | - release { | |
| 16 | - minifyEnabled false | |
| 17 | - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
| 18 | - } | |
| 8 | +// minSdkVersion 16 | |
| 9 | +// targetSdkVersion 29 | |
| 10 | +// versionCode 1 | |
| 11 | +// versionName "1.0" | |
| 12 | + renderscriptTargetApi 17 | |
| 13 | + renderscriptSupportModeEnabled true | |
| 19 | 14 | } |
| 15 | +// | |
| 16 | +// buildTypes { | |
| 17 | +// release { | |
| 18 | +// minifyEnabled false | |
| 19 | +// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
| 20 | +// } | |
| 21 | +// } | |
| 20 | 22 | dataBinding { |
| 21 | 23 | enabled true |
| 22 | 24 | } |
| ... | ... | @@ -26,4 +28,5 @@ dependencies { |
| 26 | 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
| 27 | 29 | api files('libs/pinyin4j-2.5.0.jar') |
| 28 | 30 | |
| 31 | + implementation 'androidx.legacy:legacy-support-v4:1.0.0' | |
| 29 | 32 | } | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/frame/activity/BaseActivity.java
| 1 | 1 | package com.cnlive.core.libs.base.frame.activity; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -import android.annotation.SuppressLint; | |
| 5 | 4 | import android.content.Context; |
| 5 | +import android.content.DialogInterface; | |
| 6 | +import android.content.Intent; | |
| 6 | 7 | import android.content.pm.ActivityInfo; |
| 8 | +import android.content.pm.PackageManager; | |
| 9 | +import android.graphics.Point; | |
| 10 | +import android.net.Uri; | |
| 11 | +import android.os.Build; | |
| 7 | 12 | import android.os.Bundle; |
| 8 | -import android.os.Looper; | |
| 13 | +import android.provider.Settings; | |
| 14 | +import android.text.TextUtils; | |
| 15 | +import android.util.DisplayMetrics; | |
| 16 | +import android.view.Display; | |
| 9 | 17 | import android.view.View; |
| 10 | 18 | import android.view.Window; |
| 11 | 19 | import android.view.WindowManager; |
| 12 | 20 | import android.view.inputmethod.InputMethodManager; |
| 13 | -import android.widget.Toast; | |
| 14 | 21 | |
| 15 | 22 | import androidx.annotation.ColorRes; |
| 16 | 23 | import androidx.annotation.IntRange; |
| 17 | 24 | import androidx.annotation.NonNull; |
| 18 | 25 | import androidx.annotation.Nullable; |
| 26 | +import androidx.appcompat.app.AlertDialog; | |
| 27 | +import androidx.core.app.ActivityCompat; | |
| 19 | 28 | import androidx.core.content.ContextCompat; |
| 20 | 29 | import androidx.databinding.DataBindingUtil; |
| 21 | 30 | import androidx.databinding.ViewDataBinding; |
| 22 | 31 | |
| 23 | 32 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 24 | 33 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 34 | +import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | |
| 25 | 35 | import com.cnlive.core.libs.base.network.manager.SubscriptionManager; |
| 36 | +import com.cnlive.core.libs.base.util.AppManager; | |
| 26 | 37 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 27 | 38 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| 28 | 39 | import com.cnlive.core.libs.base.util.StatusBarUtil; |
| 29 | -import com.cnlive.core.libs.base.util.ActivityCollector; | |
| 40 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackActivityBase; | |
| 41 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackActivityHelper; | |
| 42 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackLayout; | |
| 43 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackUtil; | |
| 30 | 44 | import com.hannesdorfmann.mosby3.mvp.MvpActivity; |
| 31 | 45 | |
| 46 | +import java.lang.reflect.Field; | |
| 47 | +import java.util.ArrayList; | |
| 48 | +import java.util.List; | |
| 49 | + | |
| 32 | 50 | /** |
| 33 | 51 | * @author ys |
| 34 | 52 | * 基类 activity |
| 35 | 53 | */ |
| 36 | -public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V>> extends MvpActivity<V, P> { | |
| 54 | +public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V>> extends MvpActivity<V, P> implements SwipeBackActivityBase { | |
| 37 | 55 | private V view; |
| 38 | 56 | private P presenter; |
| 39 | 57 | public ViewDataBinding baseBinding; |
| ... | ... | @@ -46,8 +64,17 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 46 | 64 | //是否允许旋转屏幕 |
| 47 | 65 | private boolean isAllowScreenRoate = true; |
| 48 | 66 | public Context context; |
| 49 | - private int stateBarColor = -1; | |
| 50 | - | |
| 67 | + /*******************************************/ | |
| 68 | + private int stateBarColor = -1;//状态栏颜色 | |
| 69 | + public BaseActivity me;//本类 | |
| 70 | + private Bundle savedInstanceState; | |
| 71 | + private OnPermissionResponseListener onPermissionResponseListener; //权限申请回调 | |
| 72 | + private int DEFAULT_REQUEST_CODE_PERMISSION = 0x00099;//默认权限请求码 | |
| 73 | + private int USER_SET_REQUEST_CODE_PERMISSION = -0x00099;//用户设置的权限请求码 | |
| 74 | + private String defaultDefinePermissionTip = "需要必要的权限才可以正常使用该功能,您已拒绝获得该权限。\n如果需要重新授权,您可以点击“允许”按钮进入系统设置进行授权";//默认拒绝的权限提示语 | |
| 75 | + private String userSetDefinePermissionTip = "";//用户设置的权限提示语 | |
| 76 | + private SwipeBackActivityHelper mHelper;//侧滑返回 | |
| 77 | + private boolean isOpenSwipBack = false; | |
| 51 | 78 | |
| 52 | 79 | @Override |
| 53 | 80 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| ... | ... | @@ -58,8 +85,10 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 58 | 85 | setContentView(getViewLayoutId()); |
| 59 | 86 | } |
| 60 | 87 | context = this; |
| 88 | + me = this; | |
| 89 | + this.savedInstanceState = savedInstanceState; | |
| 61 | 90 | //activity管理 |
| 62 | - ActivityCollector.addActivity(this); | |
| 91 | + AppManager.getInstance().pushActivity(me); | |
| 63 | 92 | //创建订阅映射 |
| 64 | 93 | SubscriptionManager.getInstance().setCurrentDisposables(TAG); |
| 65 | 94 | if (!isShowTitle) { |
| ... | ... | @@ -78,12 +107,26 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 78 | 107 | } |
| 79 | 108 | //设置binding数据 |
| 80 | 109 | initBindingData(); |
| 110 | + initParam(); | |
| 81 | 111 | //初始化控件 |
| 82 | 112 | initView(); |
| 83 | 113 | //设置数据 |
| 84 | 114 | initData(); |
| 115 | + //是否开启滑动返回 | |
| 116 | + if (isOpenSwipBack) { | |
| 117 | + mHelper = new SwipeBackActivityHelper(this); | |
| 118 | + mHelper.onActivityCreate(); | |
| 119 | + } | |
| 120 | + | |
| 85 | 121 | } |
| 86 | 122 | |
| 123 | + protected void setOpenSwipBack(boolean isOpen) { | |
| 124 | + isOpenSwipBack = isOpen; | |
| 125 | + } | |
| 126 | + | |
| 127 | + | |
| 128 | + protected void initParam() { | |
| 129 | + } | |
| 87 | 130 | |
| 88 | 131 | /** |
| 89 | 132 | * 初始化控件 |
| ... | ... | @@ -190,11 +233,12 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 190 | 233 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); |
| 191 | 234 | } |
| 192 | 235 | |
| 236 | + | |
| 193 | 237 | @Override |
| 194 | 238 | protected void onDestroy() { |
| 195 | 239 | super.onDestroy(); |
| 196 | 240 | //activity管理 |
| 197 | - ActivityCollector.removeActivity(this); | |
| 241 | + AppManager.getInstance().deleteActivity(me); | |
| 198 | 242 | //清除所有订阅 |
| 199 | 243 | SubscriptionManager.getInstance().cancel(TAG); |
| 200 | 244 | } |
| ... | ... | @@ -205,7 +249,8 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 205 | 249 | * @param color |
| 206 | 250 | * @param statusBarAlpha |
| 207 | 251 | */ |
| 208 | - protected void setStatusBarColor(@ColorRes int color, @IntRange(from = 0, to = 255) int statusBarAlpha) { | |
| 252 | + protected void setStatusBarColor(@ColorRes int color, | |
| 253 | + @IntRange(from = 0, to = 255) int statusBarAlpha) { | |
| 209 | 254 | StatusBarUtil.setColor(this, ContextCompat.getColor(this, color), statusBarAlpha); |
| 210 | 255 | } |
| 211 | 256 | |
| ... | ... | @@ -247,4 +292,322 @@ public abstract class BaseActivity<V extends BaseView, P extends BasePresenter<V |
| 247 | 292 | protected int getViewLayoutId() { |
| 248 | 293 | return 0; |
| 249 | 294 | } |
| 295 | + | |
| 296 | + | |
| 297 | + /********************************************************/ | |
| 298 | + //用于进行dip和px转换 | |
| 299 | + public int dp2px(float dpValue) { | |
| 300 | + final float scale = getResources().getDisplayMetrics().density; | |
| 301 | + return (int) (dpValue * scale + 0.5f); | |
| 302 | + } | |
| 303 | + | |
| 304 | + //用于进行px和dip转换 | |
| 305 | + public int px2dp(float pxValue) { | |
| 306 | + final float scale = getResources().getDisplayMetrics().density; | |
| 307 | + return (int) (pxValue / scale + 0.5f); | |
| 308 | + } | |
| 309 | + | |
| 310 | + //获取状态栏的高度 | |
| 311 | + public int getStatusBarHeight() { | |
| 312 | + try { | |
| 313 | + Class<?> c = Class.forName("com.android.internal.R$dimen"); | |
| 314 | + Object obj = c.newInstance(); | |
| 315 | + Field field = c.getField("status_bar_height"); | |
| 316 | + int x = Integer.parseInt(field.get(obj).toString()); | |
| 317 | + return getResources().getDimensionPixelSize(x); | |
| 318 | + } catch (Exception e) { | |
| 319 | + e.printStackTrace(); | |
| 320 | + } | |
| 321 | + return 0; | |
| 322 | + } | |
| 323 | + | |
| 324 | + //获取屏幕宽度 | |
| 325 | + public int getDisplayWidth() { | |
| 326 | + Display disp = getWindowManager().getDefaultDisplay(); | |
| 327 | + Point outP = new Point(); | |
| 328 | + disp.getSize(outP); | |
| 329 | + return outP.x; | |
| 330 | + } | |
| 331 | + | |
| 332 | + //获取屏幕可用部分高度(屏幕高度-状态栏高度-屏幕底栏高度) | |
| 333 | + public int getDisplayHeight() { | |
| 334 | + Display disp = getWindowManager().getDefaultDisplay(); | |
| 335 | + Point outP = new Point(); | |
| 336 | + disp.getSize(outP); | |
| 337 | + return outP.y; | |
| 338 | + } | |
| 339 | + | |
| 340 | + //获取真实的屏幕高度,注意判断非0 | |
| 341 | + public int getRootHeight() { | |
| 342 | + int diaplayHeight = 0; | |
| 343 | + Display display = getWindowManager().getDefaultDisplay(); | |
| 344 | + Point point = new Point(); | |
| 345 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
| 346 | + display.getRealSize(point); | |
| 347 | + diaplayHeight = point.y; | |
| 348 | + } else { | |
| 349 | + DisplayMetrics dm = new DisplayMetrics(); | |
| 350 | + getWindowManager().getDefaultDisplay().getMetrics(dm); | |
| 351 | + diaplayHeight = dm.heightPixels; //得到高度``` | |
| 352 | + } | |
| 353 | + return diaplayHeight; | |
| 354 | + } | |
| 355 | + | |
| 356 | + //网络传输文本判空规则 | |
| 357 | + public static boolean isNull(String s) { | |
| 358 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | |
| 359 | + return true; | |
| 360 | + } | |
| 361 | + return false; | |
| 362 | + } | |
| 363 | + | |
| 364 | + @Override | |
| 365 | + public void finish() { | |
| 366 | + AppManager.getInstance().killActivity(me); | |
| 367 | + } | |
| 368 | + | |
| 369 | + public void finishActivity() { | |
| 370 | + super.finish(); | |
| 371 | + } | |
| 372 | + | |
| 373 | + public Bundle getSavedInstanceState() { | |
| 374 | + return savedInstanceState; | |
| 375 | + } | |
| 376 | + | |
| 377 | + | |
| 378 | + /** | |
| 379 | + * 请求权限 | |
| 380 | + * <p> | |
| 381 | + * 警告:此处除了用户拒绝外,唯一可能出现无法获取权限或失败的情况是在AndroidManifest.xml中未声明权限信息 | |
| 382 | + * Android6.0+即便需要动态请求权限(重点)但不代表着不需要在AndroidManifest.xml中进行声明。 | |
| 383 | + * | |
| 384 | + * @param permissions 请求的权限 | |
| 385 | + * @param onPermissionResponseListener 回调监听器 | |
| 386 | + */ | |
| 387 | + public void requestPermission(String[] permissions, OnPermissionResponseListener | |
| 388 | + onPermissionResponseListener) { | |
| 389 | + this.onPermissionResponseListener = onPermissionResponseListener; | |
| 390 | + if (checkPermissions(permissions)) { | |
| 391 | + if (onPermissionResponseListener != null) { | |
| 392 | + onPermissionResponseListener.onSuccess(permissions); | |
| 393 | + } | |
| 394 | + } else { | |
| 395 | + List<String> needPermissions = getDeniedPermissions(permissions); | |
| 396 | + ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), DEFAULT_REQUEST_CODE_PERMISSION); | |
| 397 | + } | |
| 398 | + } | |
| 399 | + | |
| 400 | + /** | |
| 401 | + * 自定义权限申请码 | |
| 402 | + * | |
| 403 | + * @param requestCode | |
| 404 | + * @param permissions | |
| 405 | + * @param onPermissionResponseListener | |
| 406 | + */ | |
| 407 | + public void requestPermission(int requestCode, String[] | |
| 408 | + permissions, OnPermissionResponseListener onPermissionResponseListener) { | |
| 409 | + this.onPermissionResponseListener = onPermissionResponseListener; | |
| 410 | + this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | |
| 411 | + if (checkPermissions(permissions)) { | |
| 412 | + if (onPermissionResponseListener != null) { | |
| 413 | + onPermissionResponseListener.onSuccess(permissions); | |
| 414 | + } | |
| 415 | + } else { | |
| 416 | + List<String> needPermissions = getDeniedPermissions(permissions); | |
| 417 | + ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), USER_SET_REQUEST_CODE_PERMISSION); | |
| 418 | + } | |
| 419 | + } | |
| 420 | + | |
| 421 | + /** | |
| 422 | + * 自定义权限申请码和提示信息 | |
| 423 | + * | |
| 424 | + * @param requestCode | |
| 425 | + * @param permissions | |
| 426 | + * @param onPermissionResponseListener | |
| 427 | + */ | |
| 428 | + public void requestPermission(int requestCode, String defineTip, String[] | |
| 429 | + permissions, OnPermissionResponseListener onPermissionResponseListener) { | |
| 430 | + this.onPermissionResponseListener = onPermissionResponseListener; | |
| 431 | + this.USER_SET_REQUEST_CODE_PERMISSION = requestCode; | |
| 432 | + this.userSetDefinePermissionTip = defineTip; | |
| 433 | + if (checkPermissions(permissions)) { | |
| 434 | + if (onPermissionResponseListener != null) { | |
| 435 | + onPermissionResponseListener.onSuccess(permissions); | |
| 436 | + } | |
| 437 | + } else { | |
| 438 | + List<String> needPermissions = getDeniedPermissions(permissions); | |
| 439 | + ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), USER_SET_REQUEST_CODE_PERMISSION); | |
| 440 | + } | |
| 441 | + } | |
| 442 | + | |
| 443 | + /** | |
| 444 | + * 获取权限集中需要申请权限的列表 | |
| 445 | + * | |
| 446 | + * @param permissions | |
| 447 | + * @return | |
| 448 | + */ | |
| 449 | + private List<String> getDeniedPermissions(String[] permissions) { | |
| 450 | + List<String> needRequestPermissionList = new ArrayList<>(); | |
| 451 | + for (String permission : permissions) { | |
| 452 | + if (ContextCompat.checkSelfPermission(this, permission) != | |
| 453 | + PackageManager.PERMISSION_GRANTED || | |
| 454 | + ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { | |
| 455 | + needRequestPermissionList.add(permission); | |
| 456 | + } | |
| 457 | + } | |
| 458 | + return needRequestPermissionList; | |
| 459 | + } | |
| 460 | + | |
| 461 | + /** | |
| 462 | + * 系统请求权限回调 | |
| 463 | + * | |
| 464 | + * @param requestCode | |
| 465 | + * @param permissions | |
| 466 | + * @param grantResults | |
| 467 | + */ | |
| 468 | + @Override | |
| 469 | + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |
| 470 | + @NonNull int[] grantResults) { | |
| 471 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| 472 | + //默认权限申请码 | |
| 473 | + if (requestCode == DEFAULT_REQUEST_CODE_PERMISSION) { | |
| 474 | + if (verifyPermissions(grantResults)) { | |
| 475 | + if (onPermissionResponseListener != null) { | |
| 476 | + onPermissionResponseListener.onSuccess(permissions); | |
| 477 | + } | |
| 478 | + } else { | |
| 479 | + if (onPermissionResponseListener != null) { | |
| 480 | + onPermissionResponseListener.onFail(); | |
| 481 | + } | |
| 482 | + showTipsDialog(""); | |
| 483 | + } | |
| 484 | + } | |
| 485 | + //用户自定义权限申请码 | |
| 486 | + else if (requestCode == USER_SET_REQUEST_CODE_PERMISSION) { | |
| 487 | + if (verifyPermissions(grantResults)) { | |
| 488 | + if (onPermissionResponseListener != null) { | |
| 489 | + onPermissionResponseListener.onSuccess(permissions); | |
| 490 | + } | |
| 491 | + } else { | |
| 492 | + if (onPermissionResponseListener != null) { | |
| 493 | + onPermissionResponseListener.onFail(); | |
| 494 | + } | |
| 495 | + showTipsDialog(userSetDefinePermissionTip); | |
| 496 | + } | |
| 497 | + //重置用户提示语 | |
| 498 | + userSetDefinePermissionTip = ""; | |
| 499 | + } | |
| 500 | + } | |
| 501 | + | |
| 502 | + /** | |
| 503 | + * 检测所有的权限是否都已授权 | |
| 504 | + * | |
| 505 | + * @param permissions | |
| 506 | + * @return | |
| 507 | + */ | |
| 508 | + public boolean checkPermissions(String[] permissions) { | |
| 509 | + boolean isAllow = true; | |
| 510 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
| 511 | + return true; | |
| 512 | + } | |
| 513 | + for (String permission : permissions) { | |
| 514 | + if (ContextCompat.checkSelfPermission(this, permission) != | |
| 515 | + PackageManager.PERMISSION_GRANTED) { | |
| 516 | + isAllow = false; | |
| 517 | + break; | |
| 518 | + } | |
| 519 | + } | |
| 520 | + return isAllow; | |
| 521 | + } | |
| 522 | + | |
| 523 | + //单权限检查 | |
| 524 | + public boolean checkPermissions(String permission) { | |
| 525 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
| 526 | + return true; | |
| 527 | + } | |
| 528 | + if (ContextCompat.checkSelfPermission(this, permission) != | |
| 529 | + PackageManager.PERMISSION_GRANTED) { | |
| 530 | + return false; | |
| 531 | + } | |
| 532 | + return true; | |
| 533 | + } | |
| 534 | + | |
| 535 | + /** | |
| 536 | + * 确认所有的权限是否都已授权 | |
| 537 | + * | |
| 538 | + * @param grantResults | |
| 539 | + * @return | |
| 540 | + */ | |
| 541 | + private boolean verifyPermissions(int[] grantResults) { | |
| 542 | + for (int grantResult : grantResults) { | |
| 543 | + if (grantResult != PackageManager.PERMISSION_GRANTED) { | |
| 544 | + return false; | |
| 545 | + } | |
| 546 | + } | |
| 547 | + return true; | |
| 548 | + } | |
| 549 | + | |
| 550 | + /** | |
| 551 | + * 显示提示对话框 | |
| 552 | + */ | |
| 553 | + private void showTipsDialog(String msg) { | |
| 554 | + String tip = ""; | |
| 555 | + if (TextUtils.isEmpty(msg)) { | |
| 556 | + tip = defaultDefinePermissionTip; | |
| 557 | + } else { | |
| 558 | + tip = msg; | |
| 559 | + } | |
| 560 | + new AlertDialog.Builder(this) | |
| 561 | + .setTitle("温馨提示") | |
| 562 | + .setMessage(tip) | |
| 563 | + .setNegativeButton("取消", new DialogInterface.OnClickListener() { | |
| 564 | + @Override | |
| 565 | + public void onClick(DialogInterface dialog, int which) { | |
| 566 | + } | |
| 567 | + }) | |
| 568 | + .setPositiveButton("确定", new DialogInterface.OnClickListener() { | |
| 569 | + @Override | |
| 570 | + public void onClick(DialogInterface dialog, int which) { | |
| 571 | + startAppSettings(); | |
| 572 | + } | |
| 573 | + }).show(); | |
| 574 | + } | |
| 575 | + | |
| 576 | + //启动当前应用设置页面 | |
| 577 | + public void startAppSettings() { | |
| 578 | + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | |
| 579 | + intent.setData(Uri.parse("package:" + getPackageName())); | |
| 580 | + startActivity(intent); | |
| 581 | + } | |
| 582 | + | |
| 583 | + @Override | |
| 584 | + protected void onPostCreate(Bundle savedInstanceState) { | |
| 585 | + super.onPostCreate(savedInstanceState); | |
| 586 | + if (null != mHelper) { | |
| 587 | + mHelper.onPostCreate(); | |
| 588 | + } | |
| 589 | + } | |
| 590 | + | |
| 591 | + @Override | |
| 592 | + public SwipeBackLayout getSwipeBackLayout() { | |
| 593 | + if (null != mHelper) { | |
| 594 | + return mHelper.getSwipeBackLayout(); | |
| 595 | + } | |
| 596 | + return null; | |
| 597 | + } | |
| 598 | + | |
| 599 | + @Override | |
| 600 | + public void setSwipeBackEnable(boolean enable) { | |
| 601 | + if (null != getSwipeBackLayout()) { | |
| 602 | + getSwipeBackLayout().setEnableGesture(enable); | |
| 603 | + } | |
| 604 | + } | |
| 605 | + | |
| 606 | + @Override | |
| 607 | + public void scrollToFinishActivity() { | |
| 608 | + if (null != mHelper) { | |
| 609 | + SwipeBackUtil.convertActivityToTranslucent(this); | |
| 610 | + getSwipeBackLayout().scrollToFinishActivity(); | |
| 611 | + } | |
| 612 | + } | |
| 250 | 613 | } |
| 251 | 614 | \ No newline at end of file | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/frame/fragment/BaseFragment.java
| ... | ... | @@ -14,7 +14,10 @@ import androidx.core.content.ContextCompat; |
| 14 | 14 | import androidx.databinding.DataBindingUtil; |
| 15 | 15 | import androidx.databinding.ViewDataBinding; |
| 16 | 16 | |
| 17 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | |
| 17 | 18 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 19 | +import com.cnlive.core.libs.base.interfaces.OnPermissionResponseListener; | |
| 20 | +import com.cnlive.core.libs.base.util.ParameterCache; | |
| 18 | 21 | import com.cnlive.core.libs.base.util.ReflectUtil; |
| 19 | 22 | import com.cnlive.core.libs.base.frame.view.BaseView; |
| 20 | 23 | import com.cnlive.core.libs.base.util.StatusBarConfig; |
| ... | ... | @@ -35,6 +38,16 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V |
| 35 | 38 | protected final String TAG = this.getClass().getSimpleName(); |
| 36 | 39 | public ViewDataBinding baseBinding; |
| 37 | 40 | public View baseView; |
| 41 | + public BaseActivity me; | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void onCreate(Bundle savedInstanceState) { | |
| 45 | + super.onCreate(savedInstanceState); | |
| 46 | + if (getActivity() == null) return; | |
| 47 | + me = (BaseActivity) getActivity(); | |
| 48 | + initFragmentStyle(); | |
| 49 | + initParams(); | |
| 50 | + } | |
| 38 | 51 | |
| 39 | 52 | @Nullable |
| 40 | 53 | @Override |
| ... | ... | @@ -44,6 +57,7 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V |
| 44 | 57 | return baseBinding.getRoot(); |
| 45 | 58 | } else if (0 != getViewLayoutId()) { |
| 46 | 59 | baseView = inflater.inflate(getViewLayoutId(), container, false); |
| 60 | + return baseView; | |
| 47 | 61 | } |
| 48 | 62 | return super.onCreateView(inflater, container, savedInstanceState); |
| 49 | 63 | } |
| ... | ... | @@ -77,21 +91,53 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V |
| 77 | 91 | return view; |
| 78 | 92 | } |
| 79 | 93 | |
| 94 | + /** | |
| 95 | + * 初始化fragment样式 | |
| 96 | + */ | |
| 97 | + protected void initFragmentStyle() { | |
| 98 | + | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * 在初始化视图之前做的事 | |
| 103 | + */ | |
| 104 | + protected void initParams() { | |
| 105 | + | |
| 106 | + } | |
| 80 | 107 | |
| 108 | + /** | |
| 109 | + * 初始化视图 | |
| 110 | + */ | |
| 81 | 111 | protected void initView() { |
| 82 | 112 | } |
| 83 | 113 | |
| 84 | 114 | |
| 115 | + /** | |
| 116 | + * 初始化视图数据 | |
| 117 | + */ | |
| 85 | 118 | protected void initData() { |
| 86 | 119 | } |
| 87 | 120 | |
| 121 | + /** | |
| 122 | + * 初始化databinding数据 | |
| 123 | + */ | |
| 88 | 124 | protected void initBindingData() { |
| 89 | 125 | } |
| 90 | 126 | |
| 127 | + /** | |
| 128 | + * 设置binding视图 | |
| 129 | + * | |
| 130 | + * @return | |
| 131 | + */ | |
| 91 | 132 | protected int getBindLayoutId() { |
| 92 | 133 | return 0; |
| 93 | 134 | } |
| 94 | 135 | |
| 136 | + /** | |
| 137 | + * 设置普通view视图 | |
| 138 | + * | |
| 139 | + * @return | |
| 140 | + */ | |
| 95 | 141 | protected int getViewLayoutId() { |
| 96 | 142 | return 0; |
| 97 | 143 | } |
| ... | ... | @@ -147,8 +193,41 @@ public abstract class BaseFragment<V extends BaseView, P extends BasePresenter<V |
| 147 | 193 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); |
| 148 | 194 | } |
| 149 | 195 | |
| 150 | - @Override | |
| 151 | - public void onDestroy() { | |
| 152 | - super.onDestroy(); | |
| 196 | + | |
| 197 | + /*********************************************************/ | |
| 198 | + //用于进行dip和px转换 | |
| 199 | + public int dp2px(float dpValue) { | |
| 200 | + return me.dp2px(dpValue); | |
| 201 | + } | |
| 202 | + | |
| 203 | + //用于进行px和dip转换 | |
| 204 | + public int px2dp(float pxValue) { | |
| 205 | + return me.px2dp(pxValue); | |
| 206 | + } | |
| 207 | + | |
| 208 | + //权限申请 | |
| 209 | + public void requestPermission(String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | |
| 210 | + me.requestPermission(permissions, onPermissionResponseListener); | |
| 153 | 211 | } |
| 212 | + | |
| 213 | + //权限申请 | |
| 214 | + public void requestPermission(int requestCode, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | |
| 215 | + me.requestPermission(requestCode, permissions, onPermissionResponseListener); | |
| 216 | + } | |
| 217 | + | |
| 218 | + //权限申请 | |
| 219 | + public void requestPermission(int requestCode, String defineTip, String[] permissions, OnPermissionResponseListener onPermissionResponseListener) { | |
| 220 | + me.requestPermission(requestCode, defineTip, permissions, onPermissionResponseListener); | |
| 221 | + } | |
| 222 | + | |
| 223 | + //多权限检查 | |
| 224 | + public boolean checkPermissions(String[] permissions) { | |
| 225 | + return me.checkPermissions(permissions); | |
| 226 | + } | |
| 227 | + | |
| 228 | + //单权限检查 | |
| 229 | + public boolean checkPermissions(String permission) { | |
| 230 | + return me.checkPermissions(permission); | |
| 231 | + } | |
| 232 | + | |
| 154 | 233 | } | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/frame/presenter/BasePresenter.java
| ... | ... | @@ -6,6 +6,13 @@ import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 6 | 6 | public class BasePresenter<V extends BaseView> extends MvpBasePresenter<V> { |
| 7 | 7 | protected final String TAG = this.getClass().getSimpleName(); |
| 8 | 8 | |
| 9 | + //网络传输文本判空规则 | |
| 10 | + public static boolean isNull(String s) { | |
| 11 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | |
| 12 | + return true; | |
| 13 | + } | |
| 14 | + return false; | |
| 15 | + } | |
| 9 | 16 | // @Override |
| 10 | 17 | // public V getView() { |
| 11 | 18 | // return super.getView(); | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/frame/view/BaseView.java
| ... | ... | @@ -14,4 +14,12 @@ public class BaseView implements MvpView { |
| 14 | 14 | |
| 15 | 15 | public void initData() { |
| 16 | 16 | } |
| 17 | + | |
| 18 | + //网络传输文本判空规则 | |
| 19 | + public static boolean isNull(String s) { | |
| 20 | + if (s == null || s.trim().isEmpty() || "null".equals(s) || "(null)".equals(s)) { | |
| 21 | + return true; | |
| 22 | + } | |
| 23 | + return false; | |
| 24 | + } | |
| 17 | 25 | } | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/interfaces/OnPermissionResponseListener.java
0 → 100644
core/base/src/main/java/com/cnlive/core/libs/base/util/ActivityCollector.java deleted
100644 → 0
| 1 | -package com.cnlive.core.libs.base.util; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | - | |
| 5 | -import java.util.ArrayList; | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 8 | -public class ActivityCollector { | |
| 9 | - public static List<Activity> activitys = new ArrayList<Activity>(); | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * 向List中添加一个活动 | |
| 13 | - * | |
| 14 | - * @param activity 活动 | |
| 15 | - */ | |
| 16 | - public static void addActivity(Activity activity) { | |
| 17 | - | |
| 18 | - activitys.add(activity); | |
| 19 | - } | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 从List中移除活动 | |
| 23 | - * | |
| 24 | - * @param activity 活动 | |
| 25 | - */ | |
| 26 | - public static void removeActivity(Activity activity) { | |
| 27 | - | |
| 28 | - activitys.remove(activity); | |
| 29 | - } | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 将List中存储的活动全部销毁掉 | |
| 33 | - */ | |
| 34 | - public static void finishAll() { | |
| 35 | - | |
| 36 | - for (Activity activity : activitys) { | |
| 37 | - | |
| 38 | - if (!activity.isFinishing()) { | |
| 39 | - | |
| 40 | - activity.finish(); | |
| 41 | - } | |
| 42 | - } | |
| 43 | - } | |
| 44 | -} |
core/base/src/main/java/com/cnlive/core/libs/base/util/AppManager.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | |
| 2 | + | |
| 3 | +import android.annotation.SuppressLint; | |
| 4 | +import android.app.Activity; | |
| 5 | +import android.content.Context; | |
| 6 | + | |
| 7 | +import com.cnlive.core.libs.base.frame.activity.BaseActivity; | |
| 8 | + | |
| 9 | +import java.util.Arrays; | |
| 10 | +import java.util.Collections; | |
| 11 | +import java.util.Iterator; | |
| 12 | +import java.util.List; | |
| 13 | +import java.util.Stack; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * @author xiaohaibin | |
| 17 | + * @link https://xiaohaibin.github.io/ | |
| 18 | + * @email: xhb_199409@163.com | |
| 19 | + * @github: https://github.com/xiaohaibin | |
| 20 | + * @describe: Activity管理工具类 | |
| 21 | + */ | |
| 22 | +public class AppManager { | |
| 23 | + | |
| 24 | + private static OnActivityStatusChangeListener onActivityStatusChangeListener; | |
| 25 | + private static Stack<BaseActivity> activityStack; | |
| 26 | + private static AppManager instance; | |
| 27 | + | |
| 28 | + private AppManager() { | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @return 获取activity管理实例 | |
| 33 | + */ | |
| 34 | + public static AppManager getInstance() { | |
| 35 | + if (instance == null) { | |
| 36 | + instance = new AppManager(); | |
| 37 | + } | |
| 38 | + return instance; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 添加Activity到堆栈 | |
| 43 | + */ | |
| 44 | + public void pushActivity(BaseActivity activity) { | |
| 45 | + if (activityStack == null) { | |
| 46 | + activityStack = new Stack<BaseActivity>(); | |
| 47 | + } | |
| 48 | + activityStack.add(activity); | |
| 49 | + if (onActivityStatusChangeListener != null) { | |
| 50 | + onActivityStatusChangeListener.onActivityCreate(activity); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 获取当前Activity(堆栈中最后一个压入的) | |
| 56 | + */ | |
| 57 | + public BaseActivity currentActivity() { | |
| 58 | + BaseActivity activity = null; | |
| 59 | + if (!activityStack.empty()) { | |
| 60 | + activity = activityStack.lastElement(); | |
| 61 | + } | |
| 62 | + return activity; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * 结束当前Activity(堆栈中最后一个压入的) | |
| 67 | + */ | |
| 68 | + public void finishActivity() { | |
| 69 | + BaseActivity activity = activityStack.lastElement(); | |
| 70 | + killActivity(activity); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * 结束指定的Activity | |
| 75 | + */ | |
| 76 | + public void killActivity(BaseActivity activity) { | |
| 77 | + if (activity != null) { | |
| 78 | + if (activity != null) { | |
| 79 | + activity.finishActivity(); | |
| 80 | + } | |
| 81 | + activityStack.remove(activity); | |
| 82 | + activity = null; | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * 结束指定类名的Activity | |
| 88 | + */ | |
| 89 | + public void killActivity(Class<?> cls) { | |
| 90 | + Iterator<BaseActivity> iterator = activityStack.iterator(); | |
| 91 | + BaseActivity temp = null; | |
| 92 | + while (iterator.hasNext()) { | |
| 93 | + BaseActivity activity = iterator.next(); | |
| 94 | + if (activity != null && activity.getClass().equals(cls)) { | |
| 95 | + temp = activity; | |
| 96 | + } | |
| 97 | + } | |
| 98 | + if (temp != null) { | |
| 99 | + temp.finish(); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * 结束所有Activity | |
| 105 | + */ | |
| 106 | + public void killAllActivity() { | |
| 107 | + if (activityStack != null) { | |
| 108 | + while (!activityStack.empty()) { | |
| 109 | + BaseActivity activity = currentActivity(); | |
| 110 | + killActivity(activity); | |
| 111 | + } | |
| 112 | + activityStack.clear(); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * 退出应用程序 | |
| 118 | + */ | |
| 119 | + @SuppressLint("MissingPermission") | |
| 120 | + public void exit(Context context) { | |
| 121 | + try { | |
| 122 | + killAllActivity(); | |
| 123 | + android.app.ActivityManager activityMgr = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |
| 124 | + activityMgr.killBackgroundProcesses(context.getPackageName()); | |
| 125 | + System.exit(0); | |
| 126 | + } catch (Exception e) { | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + @Deprecated | |
| 131 | + public void AppExit(Context context) { | |
| 132 | + exit(context); | |
| 133 | + } | |
| 134 | + | |
| 135 | + 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(); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * 关闭所有 {@link Activity},排除指定的 {@link Activity} | |
| 149 | + * | |
| 150 | + * @param cls activity | |
| 151 | + */ | |
| 152 | + public void killOtherActivityExclude(Class<?>... cls) { | |
| 153 | + List<Class<?>> excludeList = Arrays.asList(cls); | |
| 154 | + if (activityStack != null) { | |
| 155 | + Stack<BaseActivity> activityStackCache = new Stack<>(); | |
| 156 | + activityStackCache.addAll(activityStack); | |
| 157 | + Iterator<BaseActivity> iterator = activityStackCache.iterator(); | |
| 158 | + while (iterator.hasNext()) { | |
| 159 | + BaseActivity activity = iterator.next(); | |
| 160 | + if (activity != null && excludeList.contains(activity.getClass())) { | |
| 161 | + continue; | |
| 162 | + } | |
| 163 | + iterator.remove(); | |
| 164 | + if (activity != null) { | |
| 165 | + activity.finish(); | |
| 166 | + } | |
| 167 | + } | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * 根据类名获取堆栈中最后一个 activity 实例 | |
| 173 | + * | |
| 174 | + * @param cls activity | |
| 175 | + */ | |
| 176 | + public BaseActivity getActivityInstance(Class<?> cls) { | |
| 177 | + if (!activityStack.empty()) { | |
| 178 | + Stack<BaseActivity> reverseList = new Stack<BaseActivity>(); | |
| 179 | + reverseList.addAll(activityStack); | |
| 180 | + Collections.reverse(reverseList); | |
| 181 | + Iterator<BaseActivity> iterator = reverseList.iterator(); | |
| 182 | + BaseActivity temp = null; | |
| 183 | + while (iterator.hasNext()) { | |
| 184 | + BaseActivity activity = iterator.next(); | |
| 185 | + if (activity != null && activity.getClass().equals(cls)) { | |
| 186 | + temp = activity; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + if (temp != null) { | |
| 190 | + return temp; | |
| 191 | + } | |
| 192 | + } | |
| 193 | + return null; | |
| 194 | + } | |
| 195 | + | |
| 196 | + public void onDestroy() { | |
| 197 | + activityStack = new Stack<>(); | |
| 198 | + } | |
| 199 | + | |
| 200 | + public static Stack<BaseActivity> getActivityStack() { | |
| 201 | + return activityStack; | |
| 202 | + } | |
| 203 | + | |
| 204 | + public static OnActivityStatusChangeListener getOnActivityStatusChangeListener() { | |
| 205 | + return onActivityStatusChangeListener; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public static void setOnActivityStatusChangeListener(OnActivityStatusChangeListener onActivityStatusChangeListener) { | |
| 209 | + AppManager.onActivityStatusChangeListener = onActivityStatusChangeListener; | |
| 210 | + } | |
| 211 | + | |
| 212 | + public interface OnActivityStatusChangeListener { | |
| 213 | + void onActivityCreate(BaseActivity activity); | |
| 214 | + | |
| 215 | + void onActivityDestroy(BaseActivity activity); | |
| 216 | + | |
| 217 | + void onAllActivityClose(); | |
| 218 | + } | |
| 219 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/JumpParameter.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | |
| 2 | + | |
| 3 | +import java.util.HashMap; | |
| 4 | +import java.util.Map; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * @Version: 6.7.0 | |
| 8 | + * @Author: Kongzue | |
| 9 | + * @github: https://github.com/kongzue/BaseFramework | |
| 10 | + * @link: http://kongzue.com/ | |
| 11 | + * @describe: 自动化代码流水线作业,以及对原生安卓、MIUI、flyme的透明状态栏显示灰色图标文字的支持,同时提供一些小工具简化开发难度,详细说明文档:https://github.com/kongzue/BaseFramework | |
| 12 | + */ | |
| 13 | + | |
| 14 | +public class JumpParameter { | |
| 15 | + | |
| 16 | + private Map<String, Object> datas; | |
| 17 | + | |
| 18 | + public JumpParameter put(String key, Object value) { | |
| 19 | + if (datas == null) { | |
| 20 | + datas = new HashMap<>(); | |
| 21 | + } | |
| 22 | + datas.put(key, value); | |
| 23 | + return this; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public JumpParameter cleanAll() { | |
| 27 | + datas = new HashMap<>(); | |
| 28 | + return this; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public Object get(String key) { | |
| 32 | + if (datas == null) { | |
| 33 | + return null; | |
| 34 | + } | |
| 35 | + return datas.get(key); | |
| 36 | + } | |
| 37 | + | |
| 38 | + public boolean getBoolean(String key) { | |
| 39 | + if (datas == null || datas.get(key) == null) { | |
| 40 | + return false; | |
| 41 | + } | |
| 42 | + return (boolean) datas.get(key); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public boolean getBoolean(String key, boolean defaultValue) { | |
| 46 | + if (datas == null || datas.get(key) == null) { | |
| 47 | + return defaultValue; | |
| 48 | + } | |
| 49 | + return (boolean) datas.get(key); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public int getInt(String key) { | |
| 53 | + if (datas == null || datas.get(key) == null) { | |
| 54 | + return 0; | |
| 55 | + } | |
| 56 | + return (int) datas.get(key); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public int getInt(String key, int defaultValue) { | |
| 60 | + if (datas == null || datas.get(key) == null) { | |
| 61 | + return defaultValue; | |
| 62 | + } | |
| 63 | + return (int) datas.get(key); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public String getString(String key) { | |
| 67 | + if (datas == null || datas.get(key) == null) { | |
| 68 | + return ""; | |
| 69 | + } | |
| 70 | + return (String) datas.get(key); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public String getString(String key, String defaultValue) { | |
| 74 | + if (datas == null || datas.get(key) == null) { | |
| 75 | + return defaultValue; | |
| 76 | + } | |
| 77 | + return (String) datas.get(key); | |
| 78 | + } | |
| 79 | + | |
| 80 | + public double getDouble(String key) { | |
| 81 | + if (datas == null || datas.get(key) == null) { | |
| 82 | + return 0; | |
| 83 | + } | |
| 84 | + return (double) datas.get(key); | |
| 85 | + } | |
| 86 | + | |
| 87 | + public double getDouble(String key, double defaultValue) { | |
| 88 | + if (datas == null || datas.get(key) == null) { | |
| 89 | + return defaultValue; | |
| 90 | + } | |
| 91 | + return (double) datas.get(key); | |
| 92 | + } | |
| 93 | + | |
| 94 | + public long getLong(String key) { | |
| 95 | + if (datas == null || datas.get(key) == null) { | |
| 96 | + return 0; | |
| 97 | + } | |
| 98 | + return (long) datas.get(key); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public long getLong(String key, long defaultValue) { | |
| 102 | + if (datas == null || datas.get(key) == null) { | |
| 103 | + return defaultValue; | |
| 104 | + } | |
| 105 | + return (long) datas.get(key); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public short getShort(String key) { | |
| 109 | + if (datas == null || datas.get(key) == null) { | |
| 110 | + return 0; | |
| 111 | + } | |
| 112 | + return (short) datas.get(key); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public short getShort(String key, short defaultValue) { | |
| 116 | + if (datas == null || datas.get(key) == null) { | |
| 117 | + return defaultValue; | |
| 118 | + } | |
| 119 | + return (short) datas.get(key); | |
| 120 | + } | |
| 121 | + | |
| 122 | + public float getFloat(String key) { | |
| 123 | + if (datas == null || datas.get(key) == null) { | |
| 124 | + return 0; | |
| 125 | + } | |
| 126 | + return (float) datas.get(key); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public float getFloat(String key, float defaultValue) { | |
| 130 | + if (datas == null || datas.get(key) == null) { | |
| 131 | + return defaultValue; | |
| 132 | + } | |
| 133 | + return (float) datas.get(key); | |
| 134 | + } | |
| 135 | + | |
| 136 | + public Map<String, Object> getAll() { | |
| 137 | + return datas; | |
| 138 | + } | |
| 139 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/ParameterCache.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util; | |
| 2 | + | |
| 3 | +import java.util.HashMap; | |
| 4 | +import java.util.Map; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 数据传递的中间人 | |
| 8 | + * 本类负责缓存数据,承担 BaseActivity、BaseFragment 之间数据传输的缓存角色 | |
| 9 | + */ | |
| 10 | +public class ParameterCache { | |
| 11 | + | |
| 12 | + private static ParameterCache parameterCache; | |
| 13 | + | |
| 14 | + private ParameterCache() { | |
| 15 | + } | |
| 16 | + | |
| 17 | + public static ParameterCache getInstance() { | |
| 18 | + if (parameterCache == null) { | |
| 19 | + synchronized (ParameterCache.class) { | |
| 20 | + if (parameterCache == null) { | |
| 21 | + parameterCache = new ParameterCache(); | |
| 22 | + } | |
| 23 | + } | |
| 24 | + } | |
| 25 | + return parameterCache; | |
| 26 | + } | |
| 27 | + | |
| 28 | + private Map<String, JumpParameter> parameterList; | |
| 29 | + | |
| 30 | + public JumpParameter get(String className) { | |
| 31 | + if (parameterList == null) { | |
| 32 | + return null; | |
| 33 | + } | |
| 34 | + return parameterList.get(className); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void set(String className, JumpParameter jumpParameter) { | |
| 38 | + if (parameterList == null) { | |
| 39 | + parameterList = new HashMap<>(); | |
| 40 | + } | |
| 41 | + parameterList.put(className, jumpParameter); | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | + private Map<String, JumpParameter> parameterResponseList; | |
| 46 | + | |
| 47 | + public JumpParameter getResponse(String className) { | |
| 48 | + if (parameterResponseList == null) { | |
| 49 | + return null; | |
| 50 | + } | |
| 51 | + return parameterResponseList.get(className); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setResponse(String className, JumpParameter jumpParameter) { | |
| 55 | + if (parameterResponseList == null) { | |
| 56 | + parameterResponseList = new HashMap<>(); | |
| 57 | + } | |
| 58 | + parameterResponseList.put(className, jumpParameter); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void cleanResponse(String className) { | |
| 62 | + if (parameterResponseList == null) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + parameterResponseList.put(className, null); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void cleanParameter(String className) { | |
| 69 | + if (parameterList == null) { | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + parameterList.put(className, null); | |
| 73 | + } | |
| 74 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/SwipeBackActivity.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import androidx.appcompat.app.AppCompatActivity; | |
| 5 | + | |
| 6 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackActivityBase; | |
| 7 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackActivityHelper; | |
| 8 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackLayout; | |
| 9 | +import com.cnlive.core.libs.base.util.swipeback.util.SwipeBackUtil; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Author: @Isaac Wang | |
| 13 | + * Github: https://github.com/ikew0ng/SwipeBackLayout | |
| 14 | + * License: Apache License | |
| 15 | + */ | |
| 16 | +public class SwipeBackActivity extends AppCompatActivity implements SwipeBackActivityBase { | |
| 17 | + private SwipeBackActivityHelper mHelper; | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + protected void onCreate(Bundle savedInstanceState) { | |
| 21 | + super.onCreate(savedInstanceState); | |
| 22 | + mHelper = new SwipeBackActivityHelper(this); | |
| 23 | + mHelper.onActivityCreate(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + protected void onPostCreate(Bundle savedInstanceState) { | |
| 28 | + super.onPostCreate(savedInstanceState); | |
| 29 | + mHelper.onPostCreate(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public SwipeBackLayout getSwipeBackLayout() { | |
| 34 | + return mHelper.getSwipeBackLayout(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public void setSwipeBackEnable(boolean enable) { | |
| 39 | + getSwipeBackLayout().setEnableGesture(enable); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public void scrollToFinishActivity() { | |
| 44 | + SwipeBackUtil.convertActivityToTranslucent(this); | |
| 45 | + getSwipeBackLayout().scrollToFinishActivity(); | |
| 46 | + } | |
| 47 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackActivityBase.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author Yrom | |
| 5 | + */ | |
| 6 | +public interface SwipeBackActivityBase { | |
| 7 | + /** | |
| 8 | + * @return the SwipeBackLayout associated with this activity. | |
| 9 | + */ | |
| 10 | + public abstract SwipeBackLayout getSwipeBackLayout(); | |
| 11 | + | |
| 12 | + public abstract void setSwipeBackEnable(boolean enable); | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * Scroll out contentView and finish the activity | |
| 16 | + */ | |
| 17 | + public abstract void scrollToFinishActivity(); | |
| 18 | + | |
| 19 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackActivityHelper.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.graphics.Color; | |
| 5 | +import android.graphics.drawable.ColorDrawable; | |
| 6 | +import android.view.LayoutInflater; | |
| 7 | +import android.view.View; | |
| 8 | + | |
| 9 | +import com.cnlive.strike.base.R; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * @author Yrom | |
| 13 | + */ | |
| 14 | +public class SwipeBackActivityHelper { | |
| 15 | + private Activity mActivity; | |
| 16 | + | |
| 17 | + private SwipeBackLayout mSwipeBackLayout; | |
| 18 | + | |
| 19 | + public SwipeBackActivityHelper(Activity activity) { | |
| 20 | + mActivity = activity; | |
| 21 | + } | |
| 22 | + | |
| 23 | + @SuppressWarnings("deprecation") | |
| 24 | + public void onActivityCreate() { | |
| 25 | + mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | |
| 26 | + mActivity.getWindow().getDecorView().setBackgroundDrawable(null); | |
| 27 | + mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate( | |
| 28 | + R.layout.swipeback_layout, null); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public void onPostCreate() { | |
| 32 | + mSwipeBackLayout.attachToActivity(mActivity); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public View findViewById(int id) { | |
| 36 | + if (mSwipeBackLayout != null) { | |
| 37 | + return mSwipeBackLayout.findViewById(id); | |
| 38 | + } | |
| 39 | + return null; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public SwipeBackLayout getSwipeBackLayout() { | |
| 43 | + return mSwipeBackLayout; | |
| 44 | + } | |
| 45 | +} | |
| 0 | 46 | \ No newline at end of file | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackLayout.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.content.res.TypedArray; | |
| 6 | +import android.graphics.Canvas; | |
| 7 | +import android.graphics.Rect; | |
| 8 | +import android.graphics.drawable.Drawable; | |
| 9 | +import android.util.AttributeSet; | |
| 10 | +import android.view.MotionEvent; | |
| 11 | +import android.view.View; | |
| 12 | +import android.view.ViewGroup; | |
| 13 | +import android.widget.FrameLayout; | |
| 14 | + | |
| 15 | + | |
| 16 | +import androidx.core.view.ViewCompat; | |
| 17 | + | |
| 18 | +import com.cnlive.strike.base.R; | |
| 19 | + | |
| 20 | +import java.util.ArrayList; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Author: @Isaac Wang | |
| 25 | + * Github: https://github.com/ikew0ng/SwipeBackLayout | |
| 26 | + * License: Apache License | |
| 27 | + */ | |
| 28 | + | |
| 29 | +public class SwipeBackLayout extends FrameLayout { | |
| 30 | + /** | |
| 31 | + * Minimum velocity that will be detected as a fling | |
| 32 | + */ | |
| 33 | + private static final int MIN_FLING_VELOCITY = 400; // dips per second | |
| 34 | + | |
| 35 | + private static final int DEFAULT_SCRIM_COLOR = 0x99000000; | |
| 36 | + | |
| 37 | + private static final int FULL_ALPHA = 255; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Edge flag indicating that the left edge should be affected. | |
| 41 | + */ | |
| 42 | + public static final int EDGE_LEFT = ViewDragHelper.EDGE_LEFT; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Edge flag indicating that the right edge should be affected. | |
| 46 | + */ | |
| 47 | + public static final int EDGE_RIGHT = ViewDragHelper.EDGE_RIGHT; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Edge flag indicating that the bottom edge should be affected. | |
| 51 | + */ | |
| 52 | + public static final int EDGE_BOTTOM = ViewDragHelper.EDGE_BOTTOM; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Edge flag set indicating all edges should be affected. | |
| 56 | + */ | |
| 57 | + public static final int EDGE_ALL = EDGE_LEFT | EDGE_RIGHT | EDGE_BOTTOM; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * A view is not currently being dragged or animating as a result of a | |
| 61 | + * fling/snap. | |
| 62 | + */ | |
| 63 | + public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * A view is currently being dragged. The position is currently changing as | |
| 67 | + * a result of user input or simulated user input. | |
| 68 | + */ | |
| 69 | + public static final int STATE_DRAGGING = ViewDragHelper.STATE_DRAGGING; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * A view is currently settling into place as a result of a fling or | |
| 73 | + * predefined non-interactive motion. | |
| 74 | + */ | |
| 75 | + public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING; | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Default threshold of scroll | |
| 79 | + */ | |
| 80 | + private static final float DEFAULT_SCROLL_THRESHOLD = 0.3f; | |
| 81 | + | |
| 82 | + private static final int OVERSCROLL_DISTANCE = 10; | |
| 83 | + | |
| 84 | + private static final int[] EDGE_FLAGS = { | |
| 85 | + EDGE_LEFT, EDGE_RIGHT, EDGE_BOTTOM, EDGE_ALL | |
| 86 | + }; | |
| 87 | + | |
| 88 | + private int mEdgeFlag; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Threshold of scroll, we will close the activity, when scrollPercent over | |
| 92 | + * this value; | |
| 93 | + */ | |
| 94 | + private float mScrollThreshold = DEFAULT_SCROLL_THRESHOLD; | |
| 95 | + | |
| 96 | + private Activity mActivity; | |
| 97 | + | |
| 98 | + private boolean mEnable = true; | |
| 99 | + | |
| 100 | + private View mContentView; | |
| 101 | + | |
| 102 | + private ViewDragHelper mDragHelper; | |
| 103 | + | |
| 104 | + private float mScrollPercent; | |
| 105 | + | |
| 106 | + private int mContentLeft; | |
| 107 | + | |
| 108 | + private int mContentTop; | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * The set of listeners to be sent events through. | |
| 112 | + */ | |
| 113 | + private List<SwipeListener> mListeners; | |
| 114 | + | |
| 115 | + private Drawable mShadowLeft; | |
| 116 | + | |
| 117 | + private Drawable mShadowRight; | |
| 118 | + | |
| 119 | + private Drawable mShadowBottom; | |
| 120 | + | |
| 121 | + private float mScrimOpacity; | |
| 122 | + | |
| 123 | + private int mScrimColor = DEFAULT_SCRIM_COLOR; | |
| 124 | + | |
| 125 | + private boolean mInLayout; | |
| 126 | + | |
| 127 | + private Rect mTmpRect = new Rect(); | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * Edge being dragged | |
| 131 | + */ | |
| 132 | + private int mTrackingEdge; | |
| 133 | + | |
| 134 | + public SwipeBackLayout(Context context) { | |
| 135 | + this(context, null); | |
| 136 | + } | |
| 137 | + | |
| 138 | + public SwipeBackLayout(Context context, AttributeSet attrs) { | |
| 139 | + this(context, attrs, R.attr.SwipeBackLayoutStyle); | |
| 140 | + } | |
| 141 | + | |
| 142 | + public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { | |
| 143 | + super(context, attrs); | |
| 144 | + mDragHelper = ViewDragHelper.create(this, new ViewDragCallback()); | |
| 145 | + | |
| 146 | + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle, | |
| 147 | + R.style.SwipeBackLayout); | |
| 148 | + | |
| 149 | + int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1); | |
| 150 | + if (edgeSize > 0) { | |
| 151 | + setEdgeSize(edgeSize); | |
| 152 | + } | |
| 153 | + int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)]; | |
| 154 | + setEdgeTrackingEnabled(mode); | |
| 155 | + | |
| 156 | + int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, | |
| 157 | + R.drawable.shadow_left); | |
| 158 | + int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, | |
| 159 | + R.drawable.shadow_right); | |
| 160 | + int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, | |
| 161 | + R.drawable.shadow_bottom); | |
| 162 | + setShadow(shadowLeft, EDGE_LEFT); | |
| 163 | + setShadow(shadowRight, EDGE_RIGHT); | |
| 164 | + setShadow(shadowBottom, EDGE_BOTTOM); | |
| 165 | + a.recycle(); | |
| 166 | + final float density = getResources().getDisplayMetrics().density; | |
| 167 | + final float minVel = MIN_FLING_VELOCITY * density; | |
| 168 | + mDragHelper.setMinVelocity(minVel); | |
| 169 | + mDragHelper.setMaxVelocity(minVel * 2f); | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * Sets the sensitivity of the NavigationLayout. | |
| 174 | + * | |
| 175 | + * @param context The application context. | |
| 176 | + * @param sensitivity value between 0 and 1, the final value for touchSlop = | |
| 177 | + * ViewConfiguration.getScaledTouchSlop * (1 / s); | |
| 178 | + */ | |
| 179 | + public void setSensitivity(Context context, float sensitivity) { | |
| 180 | + mDragHelper.setSensitivity(context, sensitivity); | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * Set up contentView which will be moved by user gesture | |
| 185 | + * | |
| 186 | + * @param view | |
| 187 | + */ | |
| 188 | + public void setContentView(View view) { | |
| 189 | + mContentView = view; | |
| 190 | + } | |
| 191 | + | |
| 192 | + public void setEnableGesture(boolean enable) { | |
| 193 | + mEnable = enable; | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * Enable edge tracking for the selected edges of the parent view. The | |
| 198 | + * callback's | |
| 199 | + * and | |
| 200 | + * methods will only be invoked for edges for which edge tracking has been | |
| 201 | + * enabled. | |
| 202 | + * | |
| 203 | + * @param edgeFlags Combination of edge flags describing the edges to watch | |
| 204 | + * @see #EDGE_LEFT | |
| 205 | + * @see #EDGE_RIGHT | |
| 206 | + * @see #EDGE_BOTTOM | |
| 207 | + */ | |
| 208 | + public void setEdgeTrackingEnabled(int edgeFlags) { | |
| 209 | + mEdgeFlag = edgeFlags; | |
| 210 | + mDragHelper.setEdgeTrackingEnabled(mEdgeFlag); | |
| 211 | + } | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * Set a color to use for the scrim that obscures primary content while a | |
| 215 | + * drawer is open. | |
| 216 | + * | |
| 217 | + * @param color Color to use in 0xAARRGGBB format. | |
| 218 | + */ | |
| 219 | + public void setScrimColor(int color) { | |
| 220 | + mScrimColor = color; | |
| 221 | + invalidate(); | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * Set the size of an edge. This is the range in pixels along the edges of | |
| 226 | + * this view that will actively detect edge touches or drags if edge | |
| 227 | + * tracking is enabled. | |
| 228 | + * | |
| 229 | + * @param size The size of an edge in pixels | |
| 230 | + */ | |
| 231 | + public void setEdgeSize(int size) { | |
| 232 | + mDragHelper.setEdgeSize(size); | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Register a callback to be invoked when a swipe event is sent to this | |
| 237 | + * view. | |
| 238 | + * | |
| 239 | + * @param listener the swipe listener to attach to this view | |
| 240 | + * @deprecated use {@link #addSwipeListener} instead | |
| 241 | + */ | |
| 242 | + @Deprecated | |
| 243 | + public void setSwipeListener(SwipeListener listener) { | |
| 244 | + addSwipeListener(listener); | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** | |
| 248 | + * Add a callback to be invoked when a swipe event is sent to this view. | |
| 249 | + * | |
| 250 | + * @param listener the swipe listener to attach to this view | |
| 251 | + */ | |
| 252 | + public void addSwipeListener(SwipeListener listener) { | |
| 253 | + if (mListeners == null) { | |
| 254 | + mListeners = new ArrayList<SwipeListener>(); | |
| 255 | + } | |
| 256 | + mListeners.add(listener); | |
| 257 | + } | |
| 258 | + | |
| 259 | + /** | |
| 260 | + * Removes a listener from the set of listeners | |
| 261 | + * | |
| 262 | + * @param listener | |
| 263 | + */ | |
| 264 | + public void removeSwipeListener(SwipeListener listener) { | |
| 265 | + if (mListeners == null) { | |
| 266 | + return; | |
| 267 | + } | |
| 268 | + mListeners.remove(listener); | |
| 269 | + } | |
| 270 | + | |
| 271 | + public static interface SwipeListener { | |
| 272 | + /** | |
| 273 | + * Invoke when state or scrollPercent changed | |
| 274 | + * | |
| 275 | + * @param state flag to describe scroll state | |
| 276 | + * @param scrollPercent scroll percent of this view | |
| 277 | + * @see #STATE_IDLE | |
| 278 | + * @see #STATE_DRAGGING | |
| 279 | + * @see #STATE_SETTLING | |
| 280 | + */ | |
| 281 | + public void onScrollStateChange(int state, float scrollPercent); | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * Invoke when edge touched | |
| 285 | + * | |
| 286 | + * @param edgeFlag edge flag describing the edge being touched | |
| 287 | + * @see #EDGE_LEFT | |
| 288 | + * @see #EDGE_RIGHT | |
| 289 | + * @see #EDGE_BOTTOM | |
| 290 | + */ | |
| 291 | + public void onEdgeTouch(int edgeFlag); | |
| 292 | + | |
| 293 | + /** | |
| 294 | + * Invoke when scroll percent over the threshold for the first time | |
| 295 | + */ | |
| 296 | + public void onScrollOverThreshold(); | |
| 297 | + } | |
| 298 | + | |
| 299 | + public interface SwipeListenerEx extends SwipeListener { | |
| 300 | + void onContentViewSwipedBack(); | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * Set scroll threshold, we will close the activity, when scrollPercent over | |
| 305 | + * this value | |
| 306 | + * | |
| 307 | + * @param threshold | |
| 308 | + */ | |
| 309 | + public void setScrollThresHold(float threshold) { | |
| 310 | + if (threshold >= 1.0f || threshold <= 0) { | |
| 311 | + throw new IllegalArgumentException("Threshold value should be between 0 and 1.0"); | |
| 312 | + } | |
| 313 | + mScrollThreshold = threshold; | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * Set a drawable used for edge shadow. | |
| 318 | + * | |
| 319 | + * @param shadow Drawable to use | |
| 320 | + * @param edgeFlag Combination of edge flags describing the edge to set | |
| 321 | + * @see #EDGE_LEFT | |
| 322 | + * @see #EDGE_RIGHT | |
| 323 | + * @see #EDGE_BOTTOM | |
| 324 | + */ | |
| 325 | + public void setShadow(Drawable shadow, int edgeFlag) { | |
| 326 | + if ((edgeFlag & EDGE_LEFT) != 0) { | |
| 327 | + mShadowLeft = shadow; | |
| 328 | + } else if ((edgeFlag & EDGE_RIGHT) != 0) { | |
| 329 | + mShadowRight = shadow; | |
| 330 | + } else if ((edgeFlag & EDGE_BOTTOM) != 0) { | |
| 331 | + mShadowBottom = shadow; | |
| 332 | + } | |
| 333 | + invalidate(); | |
| 334 | + } | |
| 335 | + | |
| 336 | + /** | |
| 337 | + * Set a drawable used for edge shadow. | |
| 338 | + * | |
| 339 | + * @param resId Resource of drawable to use | |
| 340 | + * @param edgeFlag Combination of edge flags describing the edge to set | |
| 341 | + * @see #EDGE_LEFT | |
| 342 | + * @see #EDGE_RIGHT | |
| 343 | + * @see #EDGE_BOTTOM | |
| 344 | + */ | |
| 345 | + public void setShadow(int resId, int edgeFlag) { | |
| 346 | + setShadow(getResources().getDrawable(resId), edgeFlag); | |
| 347 | + } | |
| 348 | + | |
| 349 | + /** | |
| 350 | + * Scroll out contentView and finish the activity | |
| 351 | + */ | |
| 352 | + public void scrollToFinishActivity() { | |
| 353 | + final int childWidth = mContentView.getWidth(); | |
| 354 | + final int childHeight = mContentView.getHeight(); | |
| 355 | + | |
| 356 | + int left = 0, top = 0; | |
| 357 | + if ((mEdgeFlag & EDGE_LEFT) != 0) { | |
| 358 | + left = childWidth + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE; | |
| 359 | + mTrackingEdge = EDGE_LEFT; | |
| 360 | + } else if ((mEdgeFlag & EDGE_RIGHT) != 0) { | |
| 361 | + left = -childWidth - mShadowRight.getIntrinsicWidth() - OVERSCROLL_DISTANCE; | |
| 362 | + mTrackingEdge = EDGE_RIGHT; | |
| 363 | + } else if ((mEdgeFlag & EDGE_BOTTOM) != 0) { | |
| 364 | + top = -childHeight - mShadowBottom.getIntrinsicHeight() - OVERSCROLL_DISTANCE; | |
| 365 | + mTrackingEdge = EDGE_BOTTOM; | |
| 366 | + } | |
| 367 | + | |
| 368 | + mDragHelper.smoothSlideViewTo(mContentView, left, top); | |
| 369 | + invalidate(); | |
| 370 | + } | |
| 371 | + | |
| 372 | + @Override | |
| 373 | + public boolean onInterceptTouchEvent(MotionEvent event) { | |
| 374 | + if (!mEnable) { | |
| 375 | + return false; | |
| 376 | + } | |
| 377 | + try { | |
| 378 | + return mDragHelper.shouldInterceptTouchEvent(event); | |
| 379 | + } catch (ArrayIndexOutOfBoundsException e) { | |
| 380 | + // FIXME: handle exception | |
| 381 | + // issues #9 | |
| 382 | + return false; | |
| 383 | + } | |
| 384 | + } | |
| 385 | + | |
| 386 | + @Override | |
| 387 | + public boolean onTouchEvent(MotionEvent event) { | |
| 388 | + if (!mEnable) { | |
| 389 | + return false; | |
| 390 | + } | |
| 391 | + mDragHelper.processTouchEvent(event); | |
| 392 | + return true; | |
| 393 | + } | |
| 394 | + | |
| 395 | + @Override | |
| 396 | + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | |
| 397 | + mInLayout = true; | |
| 398 | + if (mContentView != null) { | |
| 399 | + mContentView.layout(mContentLeft, mContentTop, | |
| 400 | + mContentLeft + mContentView.getMeasuredWidth(), | |
| 401 | + mContentTop + mContentView.getMeasuredHeight()); | |
| 402 | + } | |
| 403 | + mInLayout = false; | |
| 404 | + } | |
| 405 | + | |
| 406 | + @Override | |
| 407 | + public void requestLayout() { | |
| 408 | + if (!mInLayout) { | |
| 409 | + super.requestLayout(); | |
| 410 | + } | |
| 411 | + } | |
| 412 | + | |
| 413 | + @Override | |
| 414 | + protected boolean drawChild(Canvas canvas, View child, long drawingTime) { | |
| 415 | + final boolean drawContent = child == mContentView; | |
| 416 | + | |
| 417 | + boolean ret = super.drawChild(canvas, child, drawingTime); | |
| 418 | + if (mScrimOpacity > 0 && drawContent | |
| 419 | + && mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) { | |
| 420 | + drawShadow(canvas, child); | |
| 421 | + drawScrim(canvas, child); | |
| 422 | + } | |
| 423 | + return ret; | |
| 424 | + } | |
| 425 | + | |
| 426 | + private void drawScrim(Canvas canvas, View child) { | |
| 427 | + final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; | |
| 428 | + final int alpha = (int) (baseAlpha * mScrimOpacity); | |
| 429 | + final int color = alpha << 24 | (mScrimColor & 0xffffff); | |
| 430 | + | |
| 431 | + if ((mTrackingEdge & EDGE_LEFT) != 0) { | |
| 432 | + canvas.clipRect(0, 0, child.getLeft(), getHeight()); | |
| 433 | + } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { | |
| 434 | + canvas.clipRect(child.getRight(), 0, getRight(), getHeight()); | |
| 435 | + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { | |
| 436 | + canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight()); | |
| 437 | + } | |
| 438 | + canvas.drawColor(color); | |
| 439 | + } | |
| 440 | + | |
| 441 | + private void drawShadow(Canvas canvas, View child) { | |
| 442 | + final Rect childRect = mTmpRect; | |
| 443 | + child.getHitRect(childRect); | |
| 444 | + | |
| 445 | + if ((mEdgeFlag & EDGE_LEFT) != 0) { | |
| 446 | + mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, | |
| 447 | + childRect.left, childRect.bottom); | |
| 448 | + mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); | |
| 449 | + mShadowLeft.draw(canvas); | |
| 450 | + } | |
| 451 | + | |
| 452 | + if ((mEdgeFlag & EDGE_RIGHT) != 0) { | |
| 453 | + mShadowRight.setBounds(childRect.right, childRect.top, | |
| 454 | + childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom); | |
| 455 | + mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); | |
| 456 | + mShadowRight.draw(canvas); | |
| 457 | + } | |
| 458 | + | |
| 459 | + if ((mEdgeFlag & EDGE_BOTTOM) != 0) { | |
| 460 | + mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, | |
| 461 | + childRect.bottom + mShadowBottom.getIntrinsicHeight()); | |
| 462 | + mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); | |
| 463 | + mShadowBottom.draw(canvas); | |
| 464 | + } | |
| 465 | + } | |
| 466 | + | |
| 467 | + public void attachToActivity(Activity activity) { | |
| 468 | + mActivity = activity; | |
| 469 | + TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{ | |
| 470 | + android.R.attr.windowBackground | |
| 471 | + }); | |
| 472 | + int background = a.getResourceId(0, 0); | |
| 473 | + a.recycle(); | |
| 474 | + | |
| 475 | + ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); | |
| 476 | + ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); | |
| 477 | + decorChild.setBackgroundResource(background); | |
| 478 | + decor.removeView(decorChild); | |
| 479 | + addView(decorChild); | |
| 480 | + setContentView(decorChild); | |
| 481 | + addSwipeListener(new SwipeBackListenerActivityAdapter(activity)); | |
| 482 | + decor.addView(this); | |
| 483 | + } | |
| 484 | + | |
| 485 | + @Override | |
| 486 | + public void computeScroll() { | |
| 487 | + mScrimOpacity = 1 - mScrollPercent; | |
| 488 | + if (mDragHelper.continueSettling(true)) { | |
| 489 | + ViewCompat.postInvalidateOnAnimation(this); | |
| 490 | + } | |
| 491 | + } | |
| 492 | + | |
| 493 | + private class ViewDragCallback extends ViewDragHelper.Callback { | |
| 494 | + private boolean mIsScrollOverValid; | |
| 495 | + | |
| 496 | + @Override | |
| 497 | + public boolean tryCaptureView(View view, int i) { | |
| 498 | + boolean ret = mDragHelper.isEdgeTouched(mEdgeFlag, i); | |
| 499 | + if (ret) { | |
| 500 | + if (mDragHelper.isEdgeTouched(EDGE_LEFT, i)) { | |
| 501 | + mTrackingEdge = EDGE_LEFT; | |
| 502 | + } else if (mDragHelper.isEdgeTouched(EDGE_RIGHT, i)) { | |
| 503 | + mTrackingEdge = EDGE_RIGHT; | |
| 504 | + } else if (mDragHelper.isEdgeTouched(EDGE_BOTTOM, i)) { | |
| 505 | + mTrackingEdge = EDGE_BOTTOM; | |
| 506 | + } | |
| 507 | + if (mListeners != null && !mListeners.isEmpty()) { | |
| 508 | + for (SwipeListener listener : mListeners) { | |
| 509 | + listener.onEdgeTouch(mTrackingEdge); | |
| 510 | + } | |
| 511 | + } | |
| 512 | + mIsScrollOverValid = true; | |
| 513 | + } | |
| 514 | + boolean directionCheck = false; | |
| 515 | + if (mEdgeFlag == EDGE_LEFT || mEdgeFlag == EDGE_RIGHT) { | |
| 516 | + directionCheck = !mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL, i); | |
| 517 | + } else if (mEdgeFlag == EDGE_BOTTOM) { | |
| 518 | + directionCheck = !mDragHelper | |
| 519 | + .checkTouchSlop(ViewDragHelper.DIRECTION_HORIZONTAL, i); | |
| 520 | + } else if (mEdgeFlag == EDGE_ALL) { | |
| 521 | + directionCheck = true; | |
| 522 | + } | |
| 523 | + return ret & directionCheck; | |
| 524 | + } | |
| 525 | + | |
| 526 | + @Override | |
| 527 | + public int getViewHorizontalDragRange(View child) { | |
| 528 | + return mEdgeFlag & (EDGE_LEFT | EDGE_RIGHT); | |
| 529 | + } | |
| 530 | + | |
| 531 | + @Override | |
| 532 | + public int getViewVerticalDragRange(View child) { | |
| 533 | + return mEdgeFlag & EDGE_BOTTOM; | |
| 534 | + } | |
| 535 | + | |
| 536 | + @Override | |
| 537 | + public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { | |
| 538 | + super.onViewPositionChanged(changedView, left, top, dx, dy); | |
| 539 | + if ((mTrackingEdge & EDGE_LEFT) != 0) { | |
| 540 | + mScrollPercent = Math.abs((float) left | |
| 541 | + / (mContentView.getWidth() + mShadowLeft.getIntrinsicWidth())); | |
| 542 | + } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { | |
| 543 | + mScrollPercent = Math.abs((float) left | |
| 544 | + / (mContentView.getWidth() + mShadowRight.getIntrinsicWidth())); | |
| 545 | + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { | |
| 546 | + mScrollPercent = Math.abs((float) top | |
| 547 | + / (mContentView.getHeight() + mShadowBottom.getIntrinsicHeight())); | |
| 548 | + } | |
| 549 | + mContentLeft = left; | |
| 550 | + mContentTop = top; | |
| 551 | + invalidate(); | |
| 552 | + if (mScrollPercent < mScrollThreshold && !mIsScrollOverValid) { | |
| 553 | + mIsScrollOverValid = true; | |
| 554 | + } | |
| 555 | + | |
| 556 | + if (mListeners != null && !mListeners.isEmpty()) { | |
| 557 | + for (SwipeListener listener : mListeners) { | |
| 558 | + listener.onScrollStateChange(mDragHelper.getViewDragState(), mScrollPercent); | |
| 559 | + } | |
| 560 | + } | |
| 561 | + | |
| 562 | + if (mListeners != null && !mListeners.isEmpty() | |
| 563 | + && mDragHelper.getViewDragState() == STATE_DRAGGING | |
| 564 | + && mScrollPercent >= mScrollThreshold && mIsScrollOverValid) { | |
| 565 | + mIsScrollOverValid = false; | |
| 566 | + for (SwipeListener listener : mListeners) { | |
| 567 | + listener.onScrollOverThreshold(); | |
| 568 | + } | |
| 569 | + } | |
| 570 | + | |
| 571 | + if (mScrollPercent >= 1) { | |
| 572 | + if (null != mListeners && !mListeners.isEmpty()) { | |
| 573 | + for (SwipeListener listener : mListeners) { | |
| 574 | + if (listener instanceof SwipeListenerEx) { | |
| 575 | + ((SwipeListenerEx) listener).onContentViewSwipedBack(); | |
| 576 | + } | |
| 577 | + } | |
| 578 | + } | |
| 579 | + } | |
| 580 | + } | |
| 581 | + | |
| 582 | + @Override | |
| 583 | + public void onViewReleased(View releasedChild, float xvel, float yvel) { | |
| 584 | + final int childWidth = releasedChild.getWidth(); | |
| 585 | + final int childHeight = releasedChild.getHeight(); | |
| 586 | + | |
| 587 | + int left = 0, top = 0; | |
| 588 | + if ((mTrackingEdge & EDGE_LEFT) != 0) { | |
| 589 | + left = xvel > 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? childWidth | |
| 590 | + + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE : 0; | |
| 591 | + } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { | |
| 592 | + left = xvel < 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? -(childWidth | |
| 593 | + + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE) : 0; | |
| 594 | + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { | |
| 595 | + top = yvel < 0 || yvel == 0 && mScrollPercent > mScrollThreshold ? -(childHeight | |
| 596 | + + mShadowBottom.getIntrinsicHeight() + OVERSCROLL_DISTANCE) : 0; | |
| 597 | + } | |
| 598 | + | |
| 599 | + mDragHelper.settleCapturedViewAt(left, top); | |
| 600 | + invalidate(); | |
| 601 | + } | |
| 602 | + | |
| 603 | + @Override | |
| 604 | + public int clampViewPositionHorizontal(View child, int left, int dx) { | |
| 605 | + int ret = 0; | |
| 606 | + if ((mTrackingEdge & EDGE_LEFT) != 0) { | |
| 607 | + ret = Math.min(child.getWidth(), Math.max(left, 0)); | |
| 608 | + } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { | |
| 609 | + ret = Math.min(0, Math.max(left, -child.getWidth())); | |
| 610 | + } | |
| 611 | + return ret; | |
| 612 | + } | |
| 613 | + | |
| 614 | + @Override | |
| 615 | + public int clampViewPositionVertical(View child, int top, int dy) { | |
| 616 | + int ret = 0; | |
| 617 | + if ((mTrackingEdge & EDGE_BOTTOM) != 0) { | |
| 618 | + ret = Math.min(0, Math.max(top, -child.getHeight())); | |
| 619 | + } | |
| 620 | + return ret; | |
| 621 | + } | |
| 622 | + | |
| 623 | + @Override | |
| 624 | + public void onViewDragStateChanged(int state) { | |
| 625 | + super.onViewDragStateChanged(state); | |
| 626 | + if (mListeners != null && !mListeners.isEmpty()) { | |
| 627 | + for (SwipeListener listener : mListeners) { | |
| 628 | + listener.onScrollStateChange(state, mScrollPercent); | |
| 629 | + } | |
| 630 | + } | |
| 631 | + } | |
| 632 | + } | |
| 633 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackListenerActivityAdapter.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | + | |
| 5 | +import androidx.annotation.NonNull; | |
| 6 | + | |
| 7 | +import java.lang.ref.WeakReference; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Created by laysionqet on 2018/4/24. | |
| 11 | + */ | |
| 12 | +public class SwipeBackListenerActivityAdapter implements SwipeBackLayout.SwipeListenerEx { | |
| 13 | + private final WeakReference<Activity> mActivity; | |
| 14 | + | |
| 15 | + public SwipeBackListenerActivityAdapter(@NonNull Activity activity) { | |
| 16 | + mActivity = new WeakReference<>(activity); | |
| 17 | + } | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public void onScrollStateChange(int state, float scrollPercent) { | |
| 21 | + | |
| 22 | + } | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public void onEdgeTouch(int edgeFlag) { | |
| 26 | + Activity activity = mActivity.get(); | |
| 27 | + if (null != activity) { | |
| 28 | + SwipeBackUtil.convertActivityToTranslucent(activity); | |
| 29 | + } | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void onScrollOverThreshold() { | |
| 34 | + | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public void onContentViewSwipedBack() { | |
| 39 | + Activity activity = mActivity.get(); | |
| 40 | + if (null != activity && !activity.isFinishing()) { | |
| 41 | + activity.finish(); | |
| 42 | + activity.overridePendingTransition(0, 0); | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} | |
| 0 | 46 | \ No newline at end of file | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackPreferenceActivity.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.preference.PreferenceActivity; | |
| 5 | +import android.view.View; | |
| 6 | + | |
| 7 | +public class SwipeBackPreferenceActivity extends PreferenceActivity implements SwipeBackActivityBase { | |
| 8 | + private SwipeBackActivityHelper mHelper; | |
| 9 | + | |
| 10 | + @Override | |
| 11 | + protected void onCreate(Bundle savedInstanceState) { | |
| 12 | + super.onCreate(savedInstanceState); | |
| 13 | + mHelper = new SwipeBackActivityHelper(this); | |
| 14 | + mHelper.onActivityCreate(); | |
| 15 | + } | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + protected void onPostCreate(Bundle savedInstanceState) { | |
| 19 | + super.onPostCreate(savedInstanceState); | |
| 20 | + mHelper.onPostCreate(); | |
| 21 | + } | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + public View findViewById(int id) { | |
| 25 | + View v = super.findViewById(id); | |
| 26 | + if (v == null && mHelper != null) { | |
| 27 | + return mHelper.findViewById(id); | |
| 28 | + } | |
| 29 | + return v; | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public SwipeBackLayout getSwipeBackLayout() { | |
| 34 | + return mHelper.getSwipeBackLayout(); | |
| 35 | + } | |
| 36 | + @Override | |
| 37 | + public void setSwipeBackEnable(boolean enable) { | |
| 38 | + getSwipeBackLayout().setEnableGesture(enable); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void scrollToFinishActivity() { | |
| 43 | + getSwipeBackLayout().scrollToFinishActivity(); | |
| 44 | + } | |
| 45 | +} | ... | ... |
core/base/src/main/java/com/cnlive/core/libs/base/util/swipeback/util/SwipeBackUtil.java
0 → 100644
| 1 | +package com.cnlive.core.libs.base.util.swipeback.util; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.app.ActivityOptions; | |
| 5 | +import android.os.Build; | |
| 6 | + | |
| 7 | +import java.lang.reflect.Method; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Created by Chaojun Wang on 6/9/14. | |
| 11 | + */ | |
| 12 | +public class SwipeBackUtil { | |
| 13 | + private SwipeBackUtil() { | |
| 14 | + } | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Convert a translucent themed Activity | |
| 18 | + * {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque | |
| 19 | + * Activity. | |
| 20 | + * <p> | |
| 21 | + * Call this whenever the background of a translucent Activity has changed | |
| 22 | + * to become opaque. Doing so will allow the {@link android.view.Surface} of | |
| 23 | + * the Activity behind to be released. | |
| 24 | + * <p> | |
| 25 | + * This call has no effect on non-translucent activities or on activities | |
| 26 | + * with the {@link android.R.attr#windowIsFloating} attribute. | |
| 27 | + */ | |
| 28 | + public static void convertActivityFromTranslucent(Activity activity) { | |
| 29 | + try { | |
| 30 | + Method method = Activity.class.getDeclaredMethod("convertFromTranslucent"); | |
| 31 | + method.setAccessible(true); | |
| 32 | + method.invoke(activity); | |
| 33 | + } catch (Throwable t) { | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Convert a translucent themed Activity | |
| 39 | + * {@link android.R.attr#windowIsTranslucent} back from opaque to | |
| 40 | + * translucent following a call to | |
| 41 | + * {@link #convertActivityFromTranslucent(android.app.Activity)} . | |
| 42 | + * <p> | |
| 43 | + * Calling this allows the Activity behind this one to be seen again. Once | |
| 44 | + * all such Activities have been redrawn | |
| 45 | + * <p> | |
| 46 | + * This call has no effect on non-translucent activities or on activities | |
| 47 | + * with the {@link android.R.attr#windowIsFloating} attribute. | |
| 48 | + */ | |
| 49 | + public static void convertActivityToTranslucent(Activity activity) { | |
| 50 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| 51 | + convertActivityToTranslucentAfterL(activity); | |
| 52 | + } else { | |
| 53 | + convertActivityToTranslucentBeforeL(activity); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Calling the convertToTranslucent method on platforms before Android 5.0 | |
| 59 | + */ | |
| 60 | + public static void convertActivityToTranslucentBeforeL(Activity activity) { | |
| 61 | + try { | |
| 62 | + Class<?>[] classes = Activity.class.getDeclaredClasses(); | |
| 63 | + Class<?> translucentConversionListenerClazz = null; | |
| 64 | + for (Class clazz : classes) { | |
| 65 | + if (clazz.getSimpleName().contains("TranslucentConversionListener")) { | |
| 66 | + translucentConversionListenerClazz = clazz; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + Method method = Activity.class.getDeclaredMethod( | |
| 70 | + "convertToTranslucent", | |
| 71 | + translucentConversionListenerClazz | |
| 72 | + ); | |
| 73 | + method.setAccessible(true); | |
| 74 | + method.invoke(activity, new Object[]{ | |
| 75 | + null | |
| 76 | + }); | |
| 77 | + } catch (Throwable t) { | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Calling the convertToTranslucent method on platforms after Android 5.0 | |
| 83 | + */ | |
| 84 | + private static void convertActivityToTranslucentAfterL(Activity activity) { | |
| 85 | + try { | |
| 86 | + Method getActivityOptions = Activity.class.getDeclaredMethod("getActivityOptions"); | |
| 87 | + getActivityOptions.setAccessible(true); | |
| 88 | + Object options = getActivityOptions.invoke(activity); | |
| 89 | + | |
| 90 | + Class<?>[] classes = Activity.class.getDeclaredClasses(); | |
| 91 | + Class<?> translucentConversionListenerClazz = null; | |
| 92 | + for (Class clazz : classes) { | |
| 93 | + if (clazz.getSimpleName().contains("TranslucentConversionListener")) { | |
| 94 | + translucentConversionListenerClazz = clazz; | |
| 95 | + } | |
| 96 | + } | |
| 97 | + Method convertToTranslucent = Activity.class.getDeclaredMethod("convertToTranslucent", | |
| 98 | + translucentConversionListenerClazz, ActivityOptions.class | |
| 99 | + ); | |
| 100 | + convertToTranslucent.setAccessible(true); | |
| 101 | + convertToTranslucent.invoke(activity, null, options); | |
| 102 | + } catch (Throwable t) { | |
| 103 | + } | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | ... | ... |