// Path: chapter08/WoodworkingTools/app/src/main/java/com/auidbook/woodworkingtools/Tool.java
// public class Tool implements Parcelable {
// 
//     private static final int DETAILS_COUNT = 3;
// 
//     private final String mName;
//     private final String mPrice;
//     private final String[] mDetails;
//     private final String mDescription;
//     private final int mImageResourceId;
//     private final int mThumbnailResourceId;
// 
//     public Tool(String name, String price, String[] details, String description, @DrawableRes int imageResourceId, @DrawableRes int thumbnailResourceId) {
//         mName = name;
//         mPrice = price;
//         mDetails = new String[DETAILS_COUNT];
//         if (details != null) {
//             System.arraycopy(details, 0, mDetails, 0, details.length);
//         }
//         mDescription = description;
//         mImageResourceId = imageResourceId;
//         mThumbnailResourceId = thumbnailResourceId;
//     }
// 
//     public String getDescription() {
//         return mDescription;
//     }
// 
//     public String[] getDetails() {
//         return mDetails;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public String getPrice() {
//         return mPrice;
//     }
// 
//     public int getImageResourceId() {
//         return mImageResourceId;
//     }
// 
//     public int getThumbnailResourceId() {
//         return mThumbnailResourceId;
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(mName);
//         dest.writeString(mPrice);
//         dest.writeStringArray(mDetails);
//         dest.writeString(mDescription);
//         dest.writeInt(mImageResourceId);
//         dest.writeInt(mThumbnailResourceId);
//     }
// 
//     private Tool(Parcel in) {
//         mName = in.readString();
//         mPrice = in.readString();
//         mDetails = in.createStringArray();
//         mDescription = in.readString();
//         mImageResourceId = in.readInt();
//         mThumbnailResourceId = in.readInt();
//     }
// 
//     public static final Parcelable.Creator<Tool> CREATOR = new Parcelable.Creator<Tool>() {
//         public Tool createFromParcel(Parcel source) {
//             return new Tool(source);
//         }
// 
//         public Tool[] newArray(int size) {
//             return new Tool[size];
//         }
//     };
// }
// 
// Path: chapter08/WoodworkingTools/app/src/main/java/com/auidbook/woodworkingtools/tooldetails/ToolDetailActivity.java
// public class ToolDetailActivity extends AppCompatActivity {
// 
//     private static final String EXTRA_TOOL = "com.auidbook.woodworkingtools.TOOL";
// 
//     public static void startActivity(Context context, Tool tool) {
//         final Intent intent = new Intent(context, ToolDetailActivity.class);
//         intent.putExtra(EXTRA_TOOL, tool);
//         context.startActivity(intent);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_tool_detail);
// 
//         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
//         getSupportActionBar().setDisplayShowTitleEnabled(false);
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// 
//         final Tool tool = getIntent().getParcelableExtra(EXTRA_TOOL);
//         if (tool == null) {
//             throw new IllegalStateException("Tool not available as extra; use startActivity when creating an activity instance");
//         }
// 
//         final CaptionedImageView captionedImageView = (CaptionedImageView) findViewById(R.id.hero_image);
//         captionedImageView.getImageView().setSquare(false);
//         captionedImageView.getTextView().setText(tool.getName());
//         captionedImageView.setImageResource(tool.getImageResourceId());
// 
//         findAndSetTextView(R.id.price, tool.getPrice());
//         findAndSetTextView(R.id.detail_0, tool.getDetails()[0]);
//         findAndSetTextView(R.id.detail_1, tool.getDetails()[1]);
//         findAndSetTextView(R.id.detail_2, tool.getDetails()[2]);
//         findAndSetTextView(R.id.description, tool.getDescription());
//     }
// 
//     private void findAndSetTextView(int id, String text) {
//         final TextView textView = (TextView) findViewById(id);
//         textView.setText(text);
//     }
// }


import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.AdapterView;
import com.auidbook.woodworkingtools.Tool;
import com.auidbook.woodworkingtools.tooldetails.ToolDetailActivity;
import java.util.List;
package com.auidbook.woodworkingtools.toollist;





/**
 * A placeholder fragment containing a simple view.
 */
public class ToolListFragment extends ListFragment implements AdapterView.OnItemClickListener {


    private static final String ARG_TOOL_TAB = "toolTab";

    private ToolTab mToolTab;
    private ToolArrayAdapter mToolArrayAdapter;

    public static ToolListFragment newInstance(ToolTab toolTab) {
        final ToolListFragment fragment = new ToolListFragment();
        final Bundle args = new Bundle();
        args.putParcelable(ARG_TOOL_TAB, toolTab);
        fragment.setArguments(args);
        return fragment;
    }

    public ToolListFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args == null) {
            throw new IllegalStateException("No arguments set; use newInstance when constructing!");
        }
        mToolTab = args.getParcelable(ARG_TOOL_TAB);
// Path: chapter08/WoodworkingTools/app/src/main/java/com/auidbook/woodworkingtools/Tool.java
// public class Tool implements Parcelable {
// 
//     private static final int DETAILS_COUNT = 3;
// 
//     private final String mName;
//     private final String mPrice;
//     private final String[] mDetails;
//     private final String mDescription;
//     private final int mImageResourceId;
//     private final int mThumbnailResourceId;
// 
//     public Tool(String name, String price, String[] details, String description, @DrawableRes int imageResourceId, @DrawableRes int thumbnailResourceId) {
//         mName = name;
//         mPrice = price;
//         mDetails = new String[DETAILS_COUNT];
//         if (details != null) {
//             System.arraycopy(details, 0, mDetails, 0, details.length);
//         }
//         mDescription = description;
//         mImageResourceId = imageResourceId;
//         mThumbnailResourceId = thumbnailResourceId;
//     }
// 
//     public String getDescription() {
//         return mDescription;
//     }
// 
//     public String[] getDetails() {
//         return mDetails;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public String getPrice() {
//         return mPrice;
//     }
// 
//     public int getImageResourceId() {
//         return mImageResourceId;
//     }
// 
//     public int getThumbnailResourceId() {
//         return mThumbnailResourceId;
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(mName);
//         dest.writeString(mPrice);
//         dest.writeStringArray(mDetails);
//         dest.writeString(mDescription);
//         dest.writeInt(mImageResourceId);
//         dest.writeInt(mThumbnailResourceId);
//     }
// 
//     private Tool(Parcel in) {
//         mName = in.readString();
//         mPrice = in.readString();
//         mDetails = in.createStringArray();
//         mDescription = in.readString();
//         mImageResourceId = in.readInt();
//         mThumbnailResourceId = in.readInt();
//     }
// 
//     public static final Parcelable.Creator<Tool> CREATOR = new Parcelable.Creator<Tool>() {
//         public Tool createFromParcel(Parcel source) {
//             return new Tool(source);
//         }
// 
//         public Tool[] newArray(int size) {
//             return new Tool[size];
//         }
//     };
// }
// 
// Path: chapter08/WoodworkingTools/app/src/main/java/com/auidbook/woodworkingtools/tooldetails/ToolDetailActivity.java
// public class ToolDetailActivity extends AppCompatActivity {
// 
//     private static final String EXTRA_TOOL = "com.auidbook.woodworkingtools.TOOL";
// 
//     public static void startActivity(Context context, Tool tool) {
//         final Intent intent = new Intent(context, ToolDetailActivity.class);
//         intent.putExtra(EXTRA_TOOL, tool);
//         context.startActivity(intent);
//     }
// 
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_tool_detail);
// 
//         final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//         setSupportActionBar(toolbar);
//         getSupportActionBar().setDisplayShowTitleEnabled(false);
//         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// 
//         final Tool tool = getIntent().getParcelableExtra(EXTRA_TOOL);
//         if (tool == null) {
//             throw new IllegalStateException("Tool not available as extra; use startActivity when creating an activity instance");
//         }
// 
//         final CaptionedImageView captionedImageView = (CaptionedImageView) findViewById(R.id.hero_image);
//         captionedImageView.getImageView().setSquare(false);
//         captionedImageView.getTextView().setText(tool.getName());
//         captionedImageView.setImageResource(tool.getImageResourceId());
// 
//         findAndSetTextView(R.id.price, tool.getPrice());
//         findAndSetTextView(R.id.detail_0, tool.getDetails()[0]);
//         findAndSetTextView(R.id.detail_1, tool.getDetails()[1]);
//         findAndSetTextView(R.id.detail_2, tool.getDetails()[2]);
//         findAndSetTextView(R.id.description, tool.getDescription());
//     }
// 
//     private void findAndSetTextView(int id, String text) {
//         final TextView textView = (TextView) findViewById(id);
//         textView.setText(text);
//     }
// }


// Path: chapter08/WoodworkingTools/app/src/main/java/com/auidbook/woodworkingtools/toollist/ToolListFragment.java
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.AdapterView;
import com.auidbook.woodworkingtools.Tool;
import com.auidbook.woodworkingtools.tooldetails.ToolDetailActivity;
import java.util.List;

package com.auidbook.woodworkingtools.toollist;





/**
 * A placeholder fragment containing a simple view.
 */
public class ToolListFragment extends ListFragment implements AdapterView.OnItemClickListener {


    private static final String ARG_TOOL_TAB = "toolTab";

    private ToolTab mToolTab;
    private ToolArrayAdapter mToolArrayAdapter;

    public static ToolListFragment newInstance(ToolTab toolTab) {
        final ToolListFragment fragment = new ToolListFragment();
        final Bundle args = new Bundle();
        args.putParcelable(ARG_TOOL_TAB, toolTab);
        fragment.setArguments(args);
        return fragment;
    }

    public ToolListFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args == null) {
            throw new IllegalStateException("No arguments set; use newInstance when constructing!");
        }
        mToolTab = args.getParcelable(ARG_TOOL_TAB);
        final List<Tool> tools = ToolListGenerator.getTools(mToolTab);