package com.library.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;

import com.library.event.AppExitEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by CaoPengfei on 17/5/24.
 */

public class BaseActivity extends AppCompatActivity {
    private static final String TAG = "BaseActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(AppExitEvent event) {
        Log.i(TAG,"onMessageEvent:" + event);
        finish();
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() != KeyEvent.ACTION_UP) {
            return super.dispatchKeyEvent(event);
        }
        int keyCode = event.getKeyCode();
        if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE){
            EventBus.getDefault().post(new AppExitEvent());
        }
        return super.dispatchKeyEvent(event);
    }

}

@@ -1114,32 +1114,34 @@
 ent);%0A        %7D%0A
+//
         int keyC
@@ -1162,24 +1162,26 @@
 tKeyCode();%0A
+//
         if (
@@ -1253,16 +1253,18 @@
 SCAPE)%7B%0A
+//
         
@@ -1315,16 +1315,18 @@
 ent());%0A
+//
         

fix dispatch