package com.example.conami.dokidoki_memorial;

import android.content.Context;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import android.view.inputmethod.InputMethodManager;

public class MainActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    private SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//        toolbar.setTitle("タイトル");

        /*
        toolbar.setNavigationIcon(R.drawable.frustration);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // ナビゲーションアイコンクリック時の処理
                Log.d("toolbar_frustration","Click!!");
            }
        });
        */

//        toolbar.inflateMenu(R.menu.menu_main);
//        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
//            @Override
//            public boolean onMenuItemClick(MenuItem item) {
//                switch (item.getItemId()) {
//                    case R.id.menu_home:
//                        Log.d("Frustration","Click!");
//                        mViewPager.setCurrentItem(0);
//                        return true;
//                    case R.id.menu_memorial:
//                        Log.d("Frustration","Click!");
//                        mViewPager.setCurrentItem(1);
//                        return true;
//                    case R.id.menu_frustration_message:
//                        Log.d("Frustration","Click!");
//                        mViewPager.setCurrentItem(2);
//                        return true;
//                }
//                return true;
//            }
//        });
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        //
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                final InputMethodManager imm = (InputMethodManager)getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

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

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, 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);
    }





    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            switch (position){
                case 0:
                    return HomeFragment.newInstance(position);
                case 1:
                    return FrustrationListFragment.newInstance(position);
                case 2:
                    return MessageSendingFragment.newInstance(position);
                default:
                    return null;
            }
            //return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "SECTION 1";
                case 1:
                    return "SECTION 2";
                case 2:
                    return "SECTION 3";
            }
            return null;
        }
    }
}

@@ -230,50 +230,8 @@
 ity;
-%0Aimport android.support.v7.widget.Toolbar;
 %0A%0Aim
@@ -1379,1445 +1379,8 @@
 );%0A%0A
-//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);%0A//        setSupportActionBar(toolbar);%0A//        toolbar.setTitle(%22%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB%22);%0A%0A        /*%0A        toolbar.setNavigationIcon(R.drawable.frustration);%0A        toolbar.setNavigationOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View view) %7B%0A                // %E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86%0A                Log.d(%22toolbar_frustration%22,%22Click!!%22);%0A            %7D%0A        %7D);%0A        */%0A%0A//        toolbar.inflateMenu(R.menu.menu_main);%0A//        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() %7B%0A//            @Override%0A//            public boolean onMenuItemClick(MenuItem item) %7B%0A//                switch (item.getItemId()) %7B%0A//                    case R.id.menu_home:%0A//                        Log.d(%22Frustration%22,%22Click!%22);%0A//                        mViewPager.setCurrentItem(0);%0A//                        return true;%0A//                    case R.id.menu_memorial:%0A//                        Log.d(%22Frustration%22,%22Click!%22);%0A//                        mViewPager.setCurrentItem(1);%0A//                        return true;%0A//                    case R.id.menu_frustration_message:%0A//                        Log.d(%22Frustration%22,%22Click!%22);%0A//                        mViewPager.setCurrentItem(2);%0A//                        return true;%0A//                %7D%0A//                return true;%0A//            %7D%0A//        %7D);
 %0A   

delete Toolbar