| package com.doumee.keyCabinet.base; | 
|   | 
| import android.graphics.drawable.AnimationDrawable; | 
| import android.os.Build; | 
| import android.os.Bundle; | 
| import android.text.TextUtils; | 
| import android.view.MotionEvent; | 
| import android.view.View; | 
| import android.view.Window; | 
| import android.view.WindowManager; | 
| import android.widget.ImageView; | 
|   | 
| import androidx.annotation.Nullable; | 
| import androidx.databinding.ViewDataBinding; | 
|   | 
| import com.doumee.lib_coremodel.base.BaseActivity; | 
| import com.doumee.lib_coremodel.base.BaseProgressDialog; | 
| import com.doumee.lib_coremodel.base.BaseViewModel; | 
| import com.doumee.lib_coremodel.util.SpUtil; | 
| import com.doumee.keyCabinet.MApplication; | 
| import com.doumee.keyCabinet.R; | 
| import com.doumee.keyCabinet.ui.main.MainActivity; | 
| import com.doumee.keyCabinet.utils.LanguageUtil; | 
| import com.doumee.keyCabinet.utils.LogoutTool; | 
|   | 
| public abstract class MyBaseActivity<VM extends BaseViewModel,VDB extends ViewDataBinding> extends BaseActivity<VM ,VDB> { | 
|     protected boolean isAddCountTimer = true; | 
|     protected boolean isToGuild = false; | 
|     protected boolean isHideBottomUIMenu = true; | 
|   | 
|     @Override | 
|     public void onAttachedToWindow() { | 
|         super.onAttachedToWindow(); | 
|         setLanguage(); | 
|     } | 
|   | 
|     private void setLanguage() { | 
|         String language = SpUtil.getString("language"); | 
|         if(TextUtils.isEmpty(language)){ | 
|             return; | 
|         } | 
|         LanguageUtil.changeAppLanguage(this,language); | 
|     } | 
|   | 
|     @Override | 
|     protected void onCreate(@Nullable Bundle savedInstanceState) { | 
|         if(isHideBottomUIMenu) { | 
|             hideBottomUIMenu(); | 
|         } | 
|         super.onCreate(savedInstanceState); | 
|         LogoutTool.activities.add(this); | 
|     } | 
|   | 
|     @Override | 
|     protected void onResume() { | 
|         super.onResume(); | 
|         initCountTimer(); | 
|     } | 
|   | 
|     @Override | 
|     protected void onPause() { | 
|         super.onPause(); | 
|         stopCountTimer(); | 
|     } | 
|   | 
|     @Override | 
|     public boolean dispatchTouchEvent(MotionEvent ev) { | 
|         switch (ev.getAction()) { | 
|             //获取触摸动作,如果ACTION_UP,计时开始。 | 
|             case MotionEvent.ACTION_UP: | 
|                 initCountTimer(); | 
|                 break; | 
|             //否则其他动作计时取消 | 
|             default: | 
|                 stopCountTimer(); | 
|                 break; | 
|         } | 
|         return super.dispatchTouchEvent(ev); | 
|     } | 
|   | 
|     protected void initCountTimer(){ | 
|         if(!isAddCountTimer){ | 
|             return; | 
|         } | 
|         MApplication.initCountTimer(isToGuild,timerCallBack); | 
|         MApplication.startCountTimer(); | 
|     } | 
|   | 
|     private MApplication.CountTimerCallBack timerCallBack = new MApplication.CountTimerCallBack() { | 
|         @Override | 
|         public void onFinish() { | 
|             if(isFinishing()){ | 
|                 return; | 
|             } | 
|             LogoutTool.backToActivity(MainActivity.class.getSimpleName(),getContext()); | 
|         } | 
|   | 
|         @Override | 
|         public void onTick(long millisUntilFinished) { | 
|             if(isFinishing()){ | 
|                 return; | 
|             } | 
|             timeChange(String.format(getString(R.string.time_djs),millisUntilFinished/1000)); | 
|         } | 
|     }; | 
|   | 
|     protected void stopCountTimer(){ | 
|         if(!isAddCountTimer){ | 
|             return; | 
|         } | 
|         MApplication.stopCountTimer(); | 
|     } | 
|   | 
|     protected void timeChange(String djs){ | 
|   | 
|     } | 
|   | 
|     @Override | 
|     protected void onDestroy() { | 
|         super.onDestroy(); | 
|         LogoutTool.activities.remove(this); | 
|         timerCallBack = null; | 
|     } | 
|   | 
|     protected void hideBottomUIMenu() { | 
|         //隐藏虚拟按键,并且全屏 | 
|         if (Build.VERSION.SDK_INT  <=11 && Build.VERSION.SDK_INT < 19) { // lower api | 
|             View v = this.getWindow().getDecorView(); | 
|             v.setSystemUiVisibility(View.GONE); | 
|         } else if (Build.VERSION.SDK_INT  >= 19) { | 
|             Window _window = getWindow(); | 
|             WindowManager.LayoutParams params = _window.getAttributes(); | 
|             params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE; | 
|             _window.setAttributes(params); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     protected void showProgressDialog(boolean isCancel){ | 
|         showProgressDialog(R.layout.custom_progress_bar,isCancel); | 
|     } | 
|   | 
|     @Override | 
|     protected void showProgressDialog(View v, boolean isCancel){ | 
|         dismissProgressDialog(); | 
|         ImageView img = v.findViewById(R.id.loading_image); | 
|         AnimationDrawable anim = (AnimationDrawable) img.getDrawable(); | 
|         anim.start(); | 
|         mProgressDialog =  BaseProgressDialog.newInstance(getContext()); | 
|         mProgressDialog.setContentView(v); | 
|         mProgressDialog.setCanceledOnTouchOutside(isCancel); | 
|         mProgressDialog.show(); | 
|         /*try { | 
|             mProgressDialog = ProgressDialog.show(this, "", ); | 
|             mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); | 
|             mProgressDialog.setCancelable(isCancel); | 
|             mProgressDialog.show(); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|         }*/ | 
|     } | 
| } |