content: package com.github.airsaid.accountbook.base;
  
  import android.app.Activity;
  import android.content.pm.ActivityInfo;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v7.app.ActionBar;
  import android.support.v7.widget.Toolbar;
  import android.text.TextUtils;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowManager;
  import android.view.inputmethod.InputMethodManager;
  
  import com.github.airsaid.accountbook.R;
  import com.github.airsaid.accountbook.util.ActivityManager;
  import com.github.airsaid.accountbook.util.ThemeManager;
  import com.github.airsaid.accountbook.widget.slideback.SlideBackActivity;
  
  import butterknife.ButterKnife;
  
  
  /**
   * Created by zhouyou on 2016/6/23.
   * Class desc: activity base class
   */
  public abstract class BaseActivity extends SlideBackActivity {
  
      protected static String TAG;
      protected Activity mContext;
      private Toolbar mToolbar;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          // 设置 Activity 屏幕方向
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
          // 设置不自动弹出软键盘
          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
          // 隐藏 ActionBar
          supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
          // 设置 TAG
          TAG = this.getClass().getSimpleName();
  
          super.onCreate(savedInstanceState);
          this.mContext = this;
  
          // 设置主题色
          ThemeManager.getInstance().init(this);
  
          // 设置布局
          setContentView(getView());
  
          // 绑定依赖注入框架
          ButterKnife.bind(this);
  
          onCreateActivity(savedInstanceState);
          // 将当前 Activity 推入栈中
          ActivityManager.getInstance().pushActivity(this);
      }
      
      private View getView(){
          return getLayoutInflater().inflate(getLayoutRes(), null, true);
      }
  
      @Override
      protected void onStart() {
          super.onStart();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
      }
  
      @Override
      protected void onResume() {
          super.onResume();
      }
  
      /**
       * 初始化标题栏
       */
      public Toolbar initToolbar(String title) {
          mToolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(mToolbar);
          ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.setDisplayShowTitleEnabled(false);
              actionBar.setDisplayHomeAsUpEnabled(true);
              actionBar.setDisplayShowHomeEnabled(true);
          }
          // 设置标题
          if(!TextUtils.isEmpty(title)){
              mToolbar.setTitle(title);
          }
  
          // 设置左侧图标
          mToolbar.setNavigationIcon(R.mipmap.ic_back);
          mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onBack();
              }
          });
          return mToolbar;
      }
  
      /**
       * 设置标题栏标题
       */
      public void setTitle(String title){
          if(mToolbar != null){
              mToolbar.setTitle(title);
          }
      }
  
      /**
       * 设置标题栏标题颜色
       */
      public void setTitleTextColor(int id) {
          if (mToolbar != null) {
              mToolbar.setTitleTextColor(id);
          }
      }
  
      /**
       * 返回
       */
      protected void onBack() {
          finish();
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          if(null != this.getCurrentFocus()){
              // 点击空白位置 隐藏软键盘
              InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
              return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
          }
          return super.onTouchEvent(event);
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          ActivityManager.getInstance().popActivity(this);
      }
  
      /**
       * 获取布局
       */
      public abstract int getLayoutRes();
  
      public abstract void onCreateActivity(@Nullable Bundle savedInstanceState);
  }
  