|
|
@@ -2,6 +2,7 @@ package com.core.base;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.content.res.Configuration;
|
|
|
@@ -26,9 +27,9 @@ import com.common.preferences.PreferenceUtils;
|
|
|
import com.core.app.ActionBackActivity;
|
|
|
import com.core.app.Constants;
|
|
|
import com.core.app.MyApplication;
|
|
|
-import com.core.model.Approval;
|
|
|
import com.core.net.volley.FastVolley;
|
|
|
import com.core.utils.NotifyUtils;
|
|
|
+import com.core.utils.ToastUtil;
|
|
|
import com.core.widget.CustomProgressDialog;
|
|
|
import com.core.widget.crouton.Crouton;
|
|
|
import com.umeng.analytics.MobclickAgent;
|
|
|
@@ -42,276 +43,345 @@ import java.util.Locale;
|
|
|
* @author Dean Tao
|
|
|
*/
|
|
|
public abstract class BaseActivity extends ActionBackActivity {
|
|
|
- private FastVolley mFastVolley;
|
|
|
- private String HASHCODE;
|
|
|
- public CustomProgressDialog progressDialog;
|
|
|
- public Context ct;
|
|
|
- public Activity activity;
|
|
|
-
|
|
|
- public void preOnCreacte() {
|
|
|
- }
|
|
|
-
|
|
|
- public BaseActivity() {
|
|
|
- super();
|
|
|
- HASHCODE = Integer.toHexString(this.hashCode()) + "@";// 加上@符号,将拼在一起的两个HashCode分开
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
- MobclickAgent.onResume(this);
|
|
|
- // getRootView().setFitsSystemWindows(true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- super.onPause();
|
|
|
- MobclickAgent.onPause(this);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- initStyle();
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- if (android.os.Build.VERSION.SDK_INT > 108) {
|
|
|
- Window window = getWindow();
|
|
|
- window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
|
|
- WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
- window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
|
|
|
- WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
|
|
- //设置根布局的内边距
|
|
|
+ private FastVolley mFastVolley;
|
|
|
+ private String HASHCODE;
|
|
|
+ public CustomProgressDialog progressDialog;
|
|
|
+ public Context ct;
|
|
|
+ public Activity activity;
|
|
|
+
|
|
|
+ public void preOnCreacte() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseActivity() {
|
|
|
+ super();
|
|
|
+ HASHCODE = Integer.toHexString(this.hashCode()) + "@";// 加上@符号,将拼在一起的两个HashCode分开
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ MobclickAgent.onResume(this);
|
|
|
+ // getRootView().setFitsSystemWindows(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ MobclickAgent.onPause(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ initStyle();
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ if (android.os.Build.VERSION.SDK_INT > 108) {
|
|
|
+ Window window = getWindow();
|
|
|
+ window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
|
|
+ WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
+ window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
|
|
|
+ WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
|
|
+ //设置根布局的内边距
|
|
|
// RelativeLayout relativeLayout = (RelativeLayout)
|
|
|
// findViewById(R.id.layout);
|
|
|
// relativeLayout.setPadding(0, getActionBarHeight() + getStatusBarHeight(), 0,
|
|
|
// 0);
|
|
|
- }
|
|
|
- preOnCreacte();
|
|
|
- ct = this;
|
|
|
- activity = this;
|
|
|
- setNotTouchEvent(true);
|
|
|
- mFastVolley = MyApplication.getInstance().getFastVolley();
|
|
|
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
|
|
|
- progressDialog = CustomProgressDialog.createDialog(this);
|
|
|
-
|
|
|
- //重启之后恢复到之前的语言
|
|
|
- switchLanguage(PreferenceUtils.getString(this, "language", "rCN"));
|
|
|
-
|
|
|
- // SystemUtil.setSystemBarTint(this);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void initStyle() {
|
|
|
- if (getIntent() == null || getIntent().getIntExtra("style", -1) == -1) return;
|
|
|
- try {
|
|
|
- int theme = getSharedPreferences("cons", MODE_PRIVATE).
|
|
|
- getInt("theme", getIntent().getIntExtra("style", -1));
|
|
|
- setTheme(theme);
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public View getRootView() {
|
|
|
- return ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public int getStatusBarHeight() {
|
|
|
- Class c = null;
|
|
|
- Object obj = null;
|
|
|
- Field field = null;
|
|
|
- int x = 0, statusBarHeight = 0;
|
|
|
- try {
|
|
|
- c = Class.forName("com.android.internal.R$dimen");
|
|
|
- obj = c.newInstance();
|
|
|
- field = c.getField("status_bar_height");
|
|
|
- x = Integer.parseInt(field.get(obj).toString());
|
|
|
- statusBarHeight = getResources().getDimensionPixelSize(x);
|
|
|
- } catch (Exception e1) {
|
|
|
- e1.printStackTrace();
|
|
|
- }
|
|
|
- return statusBarHeight;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取ActionBar的高度
|
|
|
- public int getActionBarHeight() {
|
|
|
- TypedValue tv = new TypedValue();
|
|
|
- int actionBarHeight = 0;
|
|
|
- if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))// 如果资源是存在的、有效的
|
|
|
- {
|
|
|
- actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
|
|
|
- }
|
|
|
- return actionBarHeight;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTouch(boolean b) {
|
|
|
- setNotTouchEvent(b);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- // 取消所有HASHCODE包含该类名的request
|
|
|
- mFastVolley.cancelAll(HASHCODE);
|
|
|
-
|
|
|
- Crouton.cancelAllCroutons();
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onStop() {
|
|
|
- super.onStop();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onStart() {
|
|
|
- super.onStart();
|
|
|
- PreferenceUtils.putBoolean(this, Constants.IS_NOTIFICATION, false);//不进行通知
|
|
|
- }
|
|
|
-
|
|
|
- public void addDefaultRequest(Request<?> request) {
|
|
|
- mFastVolley.addDefaultRequest(HASHCODE, request);
|
|
|
- }
|
|
|
-
|
|
|
- public void addShortRequest(Request<?> request) {
|
|
|
- mFastVolley.addShortRequest(HASHCODE, request);
|
|
|
- }
|
|
|
-
|
|
|
- public void addRequest(Request<?> request, RetryPolicy retryPolicy) {
|
|
|
- mFastVolley.addRequest(HASHCODE, request, retryPolicy);
|
|
|
- }
|
|
|
-
|
|
|
- public void cancelAll(Object tag) {
|
|
|
- mFastVolley.cancelAll(HASHCODE, tag);
|
|
|
- }
|
|
|
-
|
|
|
- public void cancelAll() {
|
|
|
- mFastVolley.cancelAll(HASHCODE);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isNetworkActive() {
|
|
|
- return MyApplication.getInstance().isNetworkActive();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void ToastMessage(String message) {
|
|
|
- NotifyUtils.ToastMessage(this, message);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc:切换语言
|
|
|
- * @author:Arison on 2017/5/18
|
|
|
- */
|
|
|
- protected void switchLanguage(String language) {
|
|
|
- Resources resources = getResources();
|
|
|
- Configuration config = resources.getConfiguration();
|
|
|
- DisplayMetrics dm = resources.getDisplayMetrics();
|
|
|
- if (language.equals("en")) {
|
|
|
- config.locale = Locale.ENGLISH;
|
|
|
- } else if (language.equals("rCN")) {
|
|
|
- config.locale = Locale.SIMPLIFIED_CHINESE;
|
|
|
- } else if (language.equals("rTW")) {
|
|
|
- config.locale = Locale.TRADITIONAL_CHINESE;
|
|
|
- } else if (language.equals("sys")) {
|
|
|
- config.locale = Locale.getDefault();
|
|
|
- }
|
|
|
- LogUtil.d("MainActivity" + "当前语言版本模式:" + language);
|
|
|
- resources.updateConfiguration(config, dm);
|
|
|
- PreferenceUtils.putString("language", language);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /*处理权限问题*/
|
|
|
- private SparseArray<Runnable> allowablePermissionRunnables;
|
|
|
- private SparseArray<Runnable> disallowablePermissionRunnables;
|
|
|
- private int permissionItem = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断是否缺少权限
|
|
|
- *
|
|
|
- * @param permission
|
|
|
- * @return true 缺少 false 以获取
|
|
|
- */
|
|
|
- protected boolean lacksPermission(String permission) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
- return ContextCompat.checkSelfPermission(ct, permission) != PackageManager.PERMISSION_GRANTED;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 请求权限,先判断,如果没有权限就去请求
|
|
|
- * 尽量不将权限请求放在onResume 中,会出现不断循环请求
|
|
|
- *
|
|
|
- * @param permission 权限
|
|
|
- * @param allowableRunnable 当取得权限后执行操作,主线程
|
|
|
- * @param disallowableRunnable 当用户拒绝权限后执行操作,主线程
|
|
|
- */
|
|
|
- public void requestPermission(String permission, Runnable allowableRunnable, Runnable disallowableRunnable) {
|
|
|
- permissionItem++;
|
|
|
- LogUtil.i("requestPermission");
|
|
|
- if (allowableRunnable != null) {
|
|
|
- if (allowablePermissionRunnables == null) {
|
|
|
- allowablePermissionRunnables = new SparseArray<>();
|
|
|
- }
|
|
|
- allowablePermissionRunnables.put(permissionItem, allowableRunnable);
|
|
|
- }
|
|
|
- if (disallowableRunnable != null) {
|
|
|
- if (disallowablePermissionRunnables == null) {
|
|
|
- disallowablePermissionRunnables = new SparseArray<>();
|
|
|
- }
|
|
|
- disallowablePermissionRunnables.put(permissionItem, disallowableRunnable);
|
|
|
- }
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
- //减少是否拥有权限
|
|
|
- int checkCallPhonePermission = ContextCompat.checkSelfPermission(getApplicationContext(), permission);
|
|
|
- if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {//没有获取到权限
|
|
|
+ }
|
|
|
+ preOnCreacte();
|
|
|
+ ct = this;
|
|
|
+ activity = this;
|
|
|
+ setNotTouchEvent(true);
|
|
|
+ mFastVolley = MyApplication.getInstance().getFastVolley();
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
|
|
|
+ progressDialog = CustomProgressDialog.createDialog(this);
|
|
|
+
|
|
|
+ //重启之后恢复到之前的语言
|
|
|
+ switchLanguage(PreferenceUtils.getString(this, "language", "rCN"));
|
|
|
+
|
|
|
+ // SystemUtil.setSystemBarTint(this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initStyle() {
|
|
|
+ if (getIntent() == null || getIntent().getIntExtra("style", -1) == -1) return;
|
|
|
+ try {
|
|
|
+ int theme = getSharedPreferences("cons", MODE_PRIVATE).
|
|
|
+ getInt("theme", getIntent().getIntExtra("style", -1));
|
|
|
+ setTheme(theme);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public View getRootView() {
|
|
|
+ return ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int getStatusBarHeight() {
|
|
|
+ Class c = null;
|
|
|
+ Object obj = null;
|
|
|
+ Field field = null;
|
|
|
+ int x = 0, statusBarHeight = 0;
|
|
|
+ try {
|
|
|
+ c = Class.forName("com.android.internal.R$dimen");
|
|
|
+ obj = c.newInstance();
|
|
|
+ field = c.getField("status_bar_height");
|
|
|
+ x = Integer.parseInt(field.get(obj).toString());
|
|
|
+ statusBarHeight = getResources().getDimensionPixelSize(x);
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ return statusBarHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取ActionBar的高度
|
|
|
+ public int getActionBarHeight() {
|
|
|
+ TypedValue tv = new TypedValue();
|
|
|
+ int actionBarHeight = 0;
|
|
|
+ if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))// 如果资源是存在的、有效的
|
|
|
+ {
|
|
|
+ actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
|
|
|
+ }
|
|
|
+ return actionBarHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTouch(boolean b) {
|
|
|
+ setNotTouchEvent(b);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ // 取消所有HASHCODE包含该类名的request
|
|
|
+ mFastVolley.cancelAll(HASHCODE);
|
|
|
+
|
|
|
+ Crouton.cancelAllCroutons();
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onStop() {
|
|
|
+ super.onStop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onStart() {
|
|
|
+ super.onStart();
|
|
|
+ PreferenceUtils.putBoolean(this, Constants.IS_NOTIFICATION, false);//不进行通知
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addDefaultRequest(Request<?> request) {
|
|
|
+ mFastVolley.addDefaultRequest(HASHCODE, request);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addShortRequest(Request<?> request) {
|
|
|
+ mFastVolley.addShortRequest(HASHCODE, request);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addRequest(Request<?> request, RetryPolicy retryPolicy) {
|
|
|
+ mFastVolley.addRequest(HASHCODE, request, retryPolicy);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void cancelAll(Object tag) {
|
|
|
+ mFastVolley.cancelAll(HASHCODE, tag);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void cancelAll() {
|
|
|
+ mFastVolley.cancelAll(HASHCODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isNetworkActive() {
|
|
|
+ return MyApplication.getInstance().isNetworkActive();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void ToastMessage(String message) {
|
|
|
+ NotifyUtils.ToastMessage(this, message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc:切换语言
|
|
|
+ * @author:Arison on 2017/5/18
|
|
|
+ */
|
|
|
+ protected void switchLanguage(String language) {
|
|
|
+ Resources resources = getResources();
|
|
|
+ Configuration config = resources.getConfiguration();
|
|
|
+ DisplayMetrics dm = resources.getDisplayMetrics();
|
|
|
+ if (language.equals("en")) {
|
|
|
+ config.locale = Locale.ENGLISH;
|
|
|
+ } else if (language.equals("rCN")) {
|
|
|
+ config.locale = Locale.SIMPLIFIED_CHINESE;
|
|
|
+ } else if (language.equals("rTW")) {
|
|
|
+ config.locale = Locale.TRADITIONAL_CHINESE;
|
|
|
+ } else if (language.equals("sys")) {
|
|
|
+ config.locale = Locale.getDefault();
|
|
|
+ }
|
|
|
+ LogUtil.d("MainActivity" + "当前语言版本模式:" + language);
|
|
|
+ resources.updateConfiguration(config, dm);
|
|
|
+ PreferenceUtils.putString("language", language);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*处理权限问题*/
|
|
|
+ private SparseArray<Runnable> allowablePermissionRunnables;
|
|
|
+ private SparseArray<Runnable> disallowablePermissionRunnables;
|
|
|
+ private int permissionItem = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否缺少权限
|
|
|
+ *
|
|
|
+ * @param permission
|
|
|
+ * @return true 缺少 false 以获取
|
|
|
+ */
|
|
|
+ protected boolean lacksPermission(String permission) {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ return ContextCompat.checkSelfPermission(ct, permission) != PackageManager.PERMISSION_GRANTED;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求权限,先判断,如果没有权限就去请求
|
|
|
+ * 尽量不将权限请求放在onResume 中,会出现不断循环请求
|
|
|
+ *
|
|
|
+ * @param permission 权限
|
|
|
+ * @param allowableRunnable 当取得权限后执行操作,主线程
|
|
|
+ * @param disallowableRunnable 当用户拒绝权限后执行操作,主线程
|
|
|
+ */
|
|
|
+ public void requestPermission(String permission, Runnable allowableRunnable, Runnable disallowableRunnable) {
|
|
|
+ permissionItem++;
|
|
|
+ LogUtil.i("requestPermission");
|
|
|
+ if (allowableRunnable != null) {
|
|
|
+ if (allowablePermissionRunnables == null) {
|
|
|
+ allowablePermissionRunnables = new SparseArray<>();
|
|
|
+ }
|
|
|
+ allowablePermissionRunnables.put(permissionItem, allowableRunnable);
|
|
|
+ }
|
|
|
+ if (disallowableRunnable != null) {
|
|
|
+ if (disallowablePermissionRunnables == null) {
|
|
|
+ disallowablePermissionRunnables = new SparseArray<>();
|
|
|
+ }
|
|
|
+ disallowablePermissionRunnables.put(permissionItem, disallowableRunnable);
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ //减少是否拥有权限
|
|
|
+ int checkCallPhonePermission = ContextCompat.checkSelfPermission(getApplicationContext(), permission);
|
|
|
+ if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {//没有获取到权限
|
|
|
// if (!shouldShowRequestPermissionRationale(permission)) {
|
|
|
- //弹出对话框接收权限
|
|
|
- LogUtil.i("ActivityCompat.requestPermissions=" + permission);
|
|
|
- ActivityCompat.requestPermissions(BaseActivity.this, new String[]{permission}, permissionItem);
|
|
|
+ //弹出对话框接收权限
|
|
|
+ LogUtil.i("ActivityCompat.requestPermissions=" + permission);
|
|
|
+ ActivityCompat.requestPermissions(BaseActivity.this, new String[]{permission}, permissionItem);
|
|
|
// } else {
|
|
|
// ToastUtil.showToast(ct, R.string.not_camera_permission);
|
|
|
// }
|
|
|
- } else {
|
|
|
- if (allowableRunnable != null) {
|
|
|
- allowableRunnable.run();
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (allowableRunnable != null) {
|
|
|
- allowableRunnable.run();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
- if (permissions != null) {
|
|
|
- for (String p : permissions) {
|
|
|
- LogUtil.i("permission=" + p);
|
|
|
- }
|
|
|
- }
|
|
|
- if (grantResults != null && grantResults.length > 0) {
|
|
|
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
- if (allowablePermissionRunnables != null) {
|
|
|
- Runnable allowRun = allowablePermissionRunnables.get(requestCode);
|
|
|
- if (allowRun != null) {
|
|
|
- allowRun.run();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (disallowablePermissionRunnables != null) {
|
|
|
- Runnable disallowRun = disallowablePermissionRunnables.get(requestCode);
|
|
|
- if (disallowRun != null) {
|
|
|
- disallowRun.run();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ } else {
|
|
|
+ if (allowableRunnable != null) {
|
|
|
+ allowableRunnable.run();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (allowableRunnable != null) {
|
|
|
+ allowableRunnable.run();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
+ if (permissions != null) {
|
|
|
+ for (String p : permissions) {
|
|
|
+ LogUtil.i("permission=" + p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (grantResults != null && grantResults.length > 0) {
|
|
|
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
+ if (allowablePermissionRunnables != null) {
|
|
|
+ Runnable allowRun = allowablePermissionRunnables.get(requestCode);
|
|
|
+ if (allowRun != null) {
|
|
|
+ allowRun.run();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (disallowablePermissionRunnables != null) {
|
|
|
+ Runnable disallowRun = disallowablePermissionRunnables.get(requestCode);
|
|
|
+ if (disallowRun != null) {
|
|
|
+ disallowRun.run();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public <T extends View> T $(int resId) {
|
|
|
+ return (T) super.findViewById(resId);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void toast(String text) {
|
|
|
+ ToastUtil.showToast(this, text);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void toast(int resId) {
|
|
|
+ try {
|
|
|
+ ToastUtil.showToast(this, resId);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void toast(String text, ViewGroup viewGroup) {
|
|
|
+ ToastUtil.showToast(this, text, viewGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void toast(int resId, ViewGroup viewGroup) {
|
|
|
+ try {
|
|
|
+ ToastUtil.showToast(this, resId, viewGroup);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * [页面跳转]
|
|
|
+ *
|
|
|
+ * @param clz
|
|
|
+ */
|
|
|
+ public void startActivity(Class<?> clz) {
|
|
|
+ startActivity(clz, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * [携带数据的页面跳转]
|
|
|
+ *
|
|
|
+ * @param clz
|
|
|
+ * @param bundle
|
|
|
+ */
|
|
|
+ public void startActivity(Class<?> clz, Bundle bundle) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(this, clz);
|
|
|
+ if (bundle != null) {
|
|
|
+ intent.putExtras(bundle);
|
|
|
+ }
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * [含有Bundle通过Class打开编辑界面]
|
|
|
+ *
|
|
|
+ * @param cls
|
|
|
+ * @param bundle
|
|
|
+ * @param requestCode
|
|
|
+ */
|
|
|
+ public void startActivityForResult(Class<?> cls, Bundle bundle,
|
|
|
+ int requestCode) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(this, cls);
|
|
|
+ if (bundle != null) {
|
|
|
+ intent.putExtras(bundle);
|
|
|
+ }
|
|
|
+ startActivityForResult(intent, requestCode);
|
|
|
+ }
|
|
|
}
|