BaseActivity.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.sunwin.visitorapp;
  2. import android.content.DialogInterface;
  3. import android.content.Intent;
  4. import android.content.res.Configuration;
  5. import android.content.res.Resources;
  6. import android.os.Bundle;
  7. import androidx.appcompat.app.AlertDialog;
  8. import androidx.appcompat.app.AppCompatActivity;
  9. import com.sunwin.visitorapp.activity.HomeAc;
  10. import com.sunwin.visitorapp.utils.AppManager;
  11. import com.sunwin.visitorapp.utils.Constant;
  12. import com.sunwin.visitorapp.utils.SharePrefenceUtils;
  13. import com.sunwin.visitorapp.view.LoadingDialog;
  14. public class BaseActivity extends AppCompatActivity {
  15. protected static String TAG = "";
  16. protected BaseActivity mContext;
  17. protected LoadingDialog loadingDialog;
  18. protected boolean isLogin;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. AppManager.getAppManager().addActivity(this);
  23. TAG = getClass().getSimpleName();
  24. mContext = this;
  25. loadingDialog = new LoadingDialog(this, "");
  26. isLogin = SharePrefenceUtils.getBoolean(Constant.ISharePrefence.LOGINTAG, false);
  27. }
  28. @Override
  29. protected void onResume() {
  30. super.onResume();
  31. }
  32. @Override
  33. protected void onStop() {
  34. super.onStop();
  35. }
  36. @Override
  37. protected void onDestroy() {
  38. super.onDestroy();
  39. AppManager.getAppManager().removeActivity(this);
  40. }
  41. //设置android app 的字体大小不受系统字体大小改变的影响
  42. @Override
  43. public Resources getResources() {
  44. Resources res = super.getResources();
  45. Configuration config = new Configuration();
  46. config.setToDefaults();
  47. res.updateConfiguration(config, res.getDisplayMetrics());
  48. return res;
  49. }
  50. /**
  51. * 进入应用程序
  52. */
  53. protected void openApplication() {
  54. boolean isLogin = SharePrefenceUtils.getBoolean(Constant.ISharePrefence.LOGINTAG, false);
  55. if (isLogin) {
  56. gotoMain();
  57. } else {
  58. gotoLogin();
  59. }
  60. }
  61. private void gotoMain() {
  62. Intent intent = new Intent(this, HomeAc.class);
  63. startActivity(intent);
  64. finish();
  65. }
  66. private void gotoLogin() {
  67. Intent intent = new Intent(this, LoginActivity.class);
  68. startActivity(intent);
  69. finish();
  70. }
  71. public void showBlackUserDialog() {
  72. AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
  73. builder.setTitle("提示");
  74. builder.setCancelable(false);
  75. builder.setMessage("信息异常,请联系管理员!");
  76. builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
  77. @Override
  78. public void onClick(DialogInterface dialog, int which) {
  79. finish();
  80. }
  81. });
  82. builder.show();
  83. }
  84. }