| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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: |
| | | downTime = 60; |
| | | initCountTimer(); |
| | | break; |
| | | //å¦åå
¶ä»å¨ä½è®¡æ¶åæ¶ |
| | | default: |
| | | stopCountTimer(); |
| | | break; |
| | | } |
| | | return super.dispatchTouchEvent(ev); |
| | | } |
| | | |
| | | protected long downTime = 60; |
| | | |
| | | protected void initCountTimer(){ |
| | | if(!isAddCountTimer){ |
| | | return; |
| | | } |
| | | MApplication.initCountTimer(downTime*1000,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((millisUntilFinished/1000)+"s"); |
| | | } |
| | | }; |
| | | |
| | | 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(); |
| | | }*/ |
| | | } |
| | | } |