package com.bxj.activity;

import android.os.Bundle;
import android.widget.Toast;

import com.bxj.App;
import com.bxj.R;
import com.bxj.common.BaseActivity;
import com.bxj.fragment.ContentBXJFragment;
import com.bxj.fragment.SlidingMenuLeft;
import com.bxj.fragment.SlidingMenuRight;
import com.bxj.manager.StorageManager;
import com.bxj.utils.StatServiceUtil;
import com.bxj.utils.SystemUtils;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnClosedListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenedListener;

public class MainActivity extends BaseActivity implements
		SlidingMenuLeft.Callbacks {
	private ContentBXJFragment contentFragment;
	public static String CONTENT_FRAGMENT = "content_fragment";
	public static String LEFT_FRAGMENT = "slidingmenu_left";
	public static String RIGHT_FRAGMENT = "slidingmenu_right";
	private long exitTime = 0;
	private SlidingMenu slidingmenu;
	private boolean isSecondaryOpen;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// set the Above View
		if (savedInstanceState != null)
			contentFragment = (ContentBXJFragment) getSupportFragmentManager()
					.getFragment(savedInstanceState, "mContent");
		if (contentFragment == null) {
			contentFragment = new ContentBXJFragment();
		}
		setContentView(R.layout.activity_main);
		setAllowSwipeFinsh(false);

		// 没有内存卡就弹窗退出
		if (!StorageManager.getInstance().existSDcard()) {
			SystemUtils.checkSDcardDlg(this);
		}

		slidingmenu = new SlidingMenu(this);
		slidingmenu.setMode(SlidingMenu.LEFT_RIGHT);
		slidingmenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		slidingmenu.setBehindOffset(getWindowManager().getDefaultDisplay()
				.getWidth() / 3);
		slidingmenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		slidingmenu.setMenu(R.layout.layout_menu_left);
		slidingmenu.setSecondaryMenu(R.layout.layout_menu_right);

		// set the Above View

		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.content_container, contentFragment,
						CONTENT_FRAGMENT).commit();
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.slidingmenu_left, new SlidingMenuLeft(),
						LEFT_FRAGMENT).commit();
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.slidingmenu_right, new SlidingMenuRight(),
						RIGHT_FRAGMENT).commit();
		slidingmenu.setOnClosedListener(new OnClosedListener() {

			@Override
			public void onClosed() {
				contentFragment.settingChanged();
			}
		});
		slidingmenu.setOnOpenedListener(new OnOpenedListener() {

			@Override
			public void onOpened() {
				if (isSecondaryOpen) {
					isSecondaryOpen = false;
				} else {
					StatServiceUtil.trackEvent("打开左菜单");
				}
			}
		});

		slidingmenu.setSecondaryOnOpenListner(new OnOpenListener() {

			@Override
			public void onOpen() {
				isSecondaryOpen = true;
				StatServiceUtil.trackEvent("打开右菜单");
			}
		});

		slidingmenu.post(new Runnable() {

			@Override
			public void run() {
				appInit();
			}
		});

	}

	private void appInit() {
		App.getApp().appinit();
	}

	@Override
	public void onItemSelected(String id) {

	}

	@Override
	public void onBackPressed() {
		if (contentFragment != null && contentFragment.onBackPressed()) {
			// 如果事件 被消费掉 return
			return;
		}

		if ((System.currentTimeMillis() - exitTime) > 2000) {
			Toast.makeText(getApplicationContext(), R.string.exit_notiy,
					Toast.LENGTH_SHORT).show();
			exitTime = System.currentTimeMillis();
		} else {
			exitApp();
		}
	}

	/**
	 * 退出应用
	 */
	private void exitApp() {
		finish();
		System.exit(0);
	}

	public SlidingMenu getSlidingmenu() {
		return slidingmenu;
	}

	public void setSlidingmenu(SlidingMenu slidingmenu) {
		this.slidingmenu = slidingmenu;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

}

@@ -447,225 +447,8 @@
 enu;
-%0Aimport com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnClosedListener;%0Aimport com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener;%0Aimport com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenedListener;
 %0A%0Apu
@@ -2321,79 +2321,14 @@
 ner(
-new OnClosedListener() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void onClosed() %7B%0A%09%09%09%09
+() -%3E 
 cont
@@ -2355,26 +2355,16 @@
 hanged()
-;%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09%09sli
@@ -2396,79 +2396,28 @@
 ner(
-new OnOpenedListener() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void onOpened() %7B%0A%09%09%09%09
+() -%3E %7B%0A            
 if (
@@ -2435,21 +2435,32 @@
 Open) %7B%0A
-%09%09%09%09%09
+                
 isSecond
@@ -2480,26 +2480,45 @@
 se;%0A
-%09%09%09%09%7D else %7B%0A%09%09%09%09%09
+            %7D else %7B%0A                
 Stat
@@ -2554,21 +2554,30 @@
 %22);%0A
-%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09
+            %7D%0A        
 %7D);%0A
@@ -2621,75 +2621,28 @@
 ner(
-new OnOpenListener() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void onOpen() %7B%0A%09%09%09%09
+() -%3E %7B%0A            
 isSe
@@ -2661,20 +2661,28 @@
 = true;%0A
-%09%09%09%09
+            
 StatServ
@@ -2710,23 +2710,24 @@
 %E5%BC%80%E5%8F%B3%E8%8F%9C%E5%8D%95%22);%0A
-%09%09%09%7D%0A%09%09
+        
 %7D);%0A%0A%09%09s
@@ -2746,85 +2746,23 @@
 ost(
-new Runnable() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09appInit();%0A%09%09%09%7D%0A%09%09%7D
+() -%3E appInit()
 );%0A%0A

use lambda