package com.max.tang.demokiller.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import butterknife.ButterKnife;
import com.max.tang.demokiller.R;
import com.max.tang.demokiller.fragment.DemoListFragment;
import com.max.tang.demokiller.fragment.OnFragmentInteractionListener;
import com.max.tang.demokiller.fragment.PlusOneFragment;
import com.max.tang.demokiller.utils.log.Logger;

public class NavigationActivity extends BaseActivity
        implements NavigationView.OnNavigationItemSelectedListener,
        PlusOneFragment.OnFragmentInteractionListener,
        OnFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme_NoActionBar);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //navigationView.getMenu().getItem(0).setChecked(true);
        navigationView.setCheckedItem(R.id.demo_list);
        if (savedInstanceState == null) {
            navigationView.getMenu().performIdentifierAction(R.id.demo_list, 0);
        }

        ButterKnife.bind(this);
        Logger.d("onCreate");

    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.navigation, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        Fragment fragment;
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        Logger.d("Navigation Item Clicked: " + item.getItemId() );

        if (id == R.id.demo_list) {
            fragment = DemoListFragment.newInstance("","");
            ft.replace(R.id.content_navigation, fragment);
        } else if (id == R.id.plus_one) {
            fragment = PlusOneFragment.newInstance("","");
            ft.replace(R.id.content_navigation, fragment);

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }
        ft.commit();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onFragmentInteraction(Uri uri) {
        Logger.d("onFragmentInteraction: " + uri.getHost());
    }

    @Override
    public void startDemo(Class className) {
        Intent intent = new Intent(this, className);
        startActivity(intent);
        overridePendingTransition(android.R.anim.slide_in_left, R.anim.slide_out_left);
    }
}

@@ -1223,24 +1223,215 @@
 nceState) %7B%0A
+        /**%0A         * https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd%0A         * replacing that custom theme with the standard theme before calling super.onCreate()%0A         */%0A
         setT
@@ -1462,24 +1462,33 @@
 ActionBar);%0A
+        %0A
         supe

add comments