package com.example.jianming.myapplication;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import butterknife.Bind;
import butterknife.OnItemClick;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity {


    private static final String TAG = "MainActivity";

    @OnClick({R.id.su27, R.id.picIndexBtn})
    public void btnClicked(View v) {
        switch (v.getId()) {
            case R.id.su27:
                this.startActivity(new Intent(this, XrxActivity.class));
                break;

            case R.id.picIndexBtn:
                this.startActivity(new Intent(this, FileTrainingActivity.class));
                break;

            default:
                break;
        }
    }

    @OnItemClick(R.id.lv_left_menu)
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (position == 0) {
            startActivity(new Intent(this, SettingActivity.class));
        }
    }

    @Bind(R.id.tl_custom)
    Toolbar toolbar;

    @Bind(R.id.dl_left)
    DrawerLayout mDrawerLayout;

    @Bind(R.id.lv_left_menu)
    ListView lvLeftMenu;

    private String[] lvs = {"Settings"};

    private ArrayAdapter arrayAdapter;

    private ActionBarDrawerToggle mDrawerToggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImageLoaderConfiguration config = ImageLoaderConfiguration.createDefault(this);
        ImageLoader.getInstance().init(config);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);

        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open, R.string.close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }
            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }
        };
        mDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mDrawerToggle);



        arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, lvs);
        lvLeftMenu.setAdapter(arrayAdapter);

//        lvLeftMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                if (position == 0) {
//                    startActivity(new Intent(MainActivity.this, SettingActivity.class));
//                }
//            }
//        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        if (id == R.id.action_settings) {
            this.startActivity(new Intent(this, SettingActivity.class));
            return true;
        } else if (id == R.id.action_about) {
            this.startActivity(new Intent(this, AboutActivity.class));
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


}

@@ -97,16 +97,62 @@
 undle;%0A%0A
+import android.support.v4.view.GravityCompat;%0A
 import a
@@ -196,16 +196,16 @@
 Toggle;%0A
-
 import a
@@ -359,16 +359,45 @@
 il.Log;%0A
+import android.view.Gravity;%0A
 import a
@@ -1596,32 +1596,90 @@
 ss));%0A        %7D%0A
+        //mDrawerLayout.closeDrawer(GravityCompat.START);%0A
     %7D%0A%0A    @Bind
@@ -3097,393 +3097,8 @@
 );%0A%0A
-//        lvLeftMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() %7B%0A//            @Override%0A//            public void onItemClick(AdapterView%3C?%3E parent, View view, int position, long id) %7B%0A//                if (position == 0) %7B%0A//                    startActivity(new Intent(MainActivity.this, SettingActivity.class));%0A//                %7D%0A//            %7D%0A//        %7D);%0A
     

test close mDrawerLayout