// Path: chapter10/WoodworkingTools/app/src/main/java/com/iangclifton/woodworkingtools/toollist/ToolListActivity.java
// public class ToolListActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
// 
//     private static final String EXTRA_TOOL_TYPE = "com.iangclifton.woodworkingtools.TOOL_TYPE";
// 
//     private ToolType mToolType;
//     private ViewPager mViewPager;
// 
//     public static void startActivity(Activity activity, ToolType toolType, Bundle activityOptions) {
//         final Intent intent = new Intent(activity, ToolListActivity.class);
//         intent.putExtra(EXTRA_TOOL_TYPE, toolType);
//         ActivityCompat.startActivity(activity, intent, activityOptions);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_tool_list);
// 
//         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// 
//         mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
//         if (mToolType == null) {
//             throw new IllegalStateException("ToolType not available as extra; use startActivity");
//         }
//         setTitle(mToolType.getToolNameResourceId());
// 
//         // Set up tabs
//         mViewPager = (ViewPager) findViewById(R.id.viewpager);
//         final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
//         final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
//         tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
//         mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
//         mViewPager.setAdapter(toolPagerAdapter);
//         tabLayout.setOnTabSelectedListener(this);
// 
//         // Handle animation from previous activity
//         postponeEnterTransition();
//         mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
//             @Override
//             public boolean onPreDraw() {
//                 mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
//                 startPostponedEnterTransition();
//                 return true;
//             }
//         });
// 
//         setEnterSharedElementCallback(new SharedElementCallback() {
//             @Override
//             public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
//                 if (mViewPager.getCurrentItem() != 0) {
//                     // Not displaying the about page, which has the hero image
//                     names.clear();
//                     sharedElements.clear();
//                 }
//             }
//         });
// 
// 
//     }
// 
// 
//     @Override
//     public void onTabSelected(TabLayout.Tab tab) {
//         mViewPager.setCurrentItem(tab.getPosition());
//     }
// 
//     @Override
//     public void onTabUnselected(TabLayout.Tab tab) {
// 
//     }
// 
//     @Override
//     public void onTabReselected(TabLayout.Tab tab) {
// 
//     }
// }


import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import com.iangclifton.woodworkingtools.toollist.ToolListActivity;
package com.iangclifton.woodworkingtools;




/**
 * Fragment displaying a GridView of tool types.
 *
 * @author Ian G. Clifton
 */
public class ToolGridFragment extends Fragment implements AdapterView.OnItemClickListener {

    private ToolGridAdapter mToolGridAdapter;

    public ToolGridFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_tool_grid, container, false);
        final GridView gridView = (GridView) rootView.findViewById(R.id.gridview);
        mToolGridAdapter = new ToolGridAdapter(getActivity());
        gridView.setAdapter(mToolGridAdapter);
        gridView.setOnItemClickListener(this);
        return rootView;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
        final CaptionedImageView captionedImageView = (CaptionedImageView) view;
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                getActivity(),
                new Pair<View, String>(captionedImageView.getImageView(), getString(R.string.transition_image_view)),
                new Pair<View, String>(captionedImageView.getTextView(), getString(R.string.transition_text_view))
        );
// Path: chapter10/WoodworkingTools/app/src/main/java/com/iangclifton/woodworkingtools/toollist/ToolListActivity.java
// public class ToolListActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
// 
//     private static final String EXTRA_TOOL_TYPE = "com.iangclifton.woodworkingtools.TOOL_TYPE";
// 
//     private ToolType mToolType;
//     private ViewPager mViewPager;
// 
//     public static void startActivity(Activity activity, ToolType toolType, Bundle activityOptions) {
//         final Intent intent = new Intent(activity, ToolListActivity.class);
//         intent.putExtra(EXTRA_TOOL_TYPE, toolType);
//         ActivityCompat.startActivity(activity, intent, activityOptions);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_tool_list);
// 
//         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// 
//         mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
//         if (mToolType == null) {
//             throw new IllegalStateException("ToolType not available as extra; use startActivity");
//         }
//         setTitle(mToolType.getToolNameResourceId());
// 
//         // Set up tabs
//         mViewPager = (ViewPager) findViewById(R.id.viewpager);
//         final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
//         final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
//         tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
//         mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
//         mViewPager.setAdapter(toolPagerAdapter);
//         tabLayout.setOnTabSelectedListener(this);
// 
//         // Handle animation from previous activity
//         postponeEnterTransition();
//         mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
//             @Override
//             public boolean onPreDraw() {
//                 mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
//                 startPostponedEnterTransition();
//                 return true;
//             }
//         });
// 
//         setEnterSharedElementCallback(new SharedElementCallback() {
//             @Override
//             public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
//                 if (mViewPager.getCurrentItem() != 0) {
//                     // Not displaying the about page, which has the hero image
//                     names.clear();
//                     sharedElements.clear();
//                 }
//             }
//         });
// 
// 
//     }
// 
// 
//     @Override
//     public void onTabSelected(TabLayout.Tab tab) {
//         mViewPager.setCurrentItem(tab.getPosition());
//     }
// 
//     @Override
//     public void onTabUnselected(TabLayout.Tab tab) {
// 
//     }
// 
//     @Override
//     public void onTabReselected(TabLayout.Tab tab) {
// 
//     }
// }


// Path: chapter10/WoodworkingTools/app/src/main/java/com/iangclifton/woodworkingtools/ToolGridFragment.java
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import com.iangclifton.woodworkingtools.toollist.ToolListActivity;

package com.iangclifton.woodworkingtools;




/**
 * Fragment displaying a GridView of tool types.
 *
 * @author Ian G. Clifton
 */
public class ToolGridFragment extends Fragment implements AdapterView.OnItemClickListener {

    private ToolGridAdapter mToolGridAdapter;

    public ToolGridFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_tool_grid, container, false);
        final GridView gridView = (GridView) rootView.findViewById(R.id.gridview);
        mToolGridAdapter = new ToolGridAdapter(getActivity());
        gridView.setAdapter(mToolGridAdapter);
        gridView.setOnItemClickListener(this);
        return rootView;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
        final CaptionedImageView captionedImageView = (CaptionedImageView) view;
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                getActivity(),
                new Pair<View, String>(captionedImageView.getImageView(), getString(R.string.transition_image_view)),
                new Pair<View, String>(captionedImageView.getTextView(), getString(R.string.transition_text_view))
        );
        ToolListActivity.startActivity(getActivity(), mToolGridAdapter.getItem(position), activityOptions.toBundle());