package com.neivin.materialcolorpalette;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;

public class ColorDetailActivity extends AppCompatActivity {

    String mColorName;
    ArrayList<ColorValue> mColorList;

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

        // Obtain the name of the color
        mColorName = getIntent().getStringExtra("COLOR_NAME");

        // Fill out the values neeeded to list out the color values
        populateColorList();

        // Set title of the Activity to hte chosen color
        if (getActionBar()!= null)
            getActionBar().setTitle(mColorName);
        if(getSupportActionBar() != null)
            getSupportActionBar().setTitle(mColorName);

        ColorListAdapter listAdapter = new ColorListAdapter(this, mColorList);

        ListView colorList = (ListView) findViewById(R.id.color_list);
        colorList.setAdapter(listAdapter);
    }

    private void populateColorList(){
        String resourceName = mColorName.toLowerCase().replace(' ', '_') + "_color_values";

        String[] colorHexValues  = getResources().getStringArray(getResources().getIdentifier(resourceName,"array","com.neivin.materialcolorpalette"));

        ArrayList<String> colorGrades = new ArrayList<>(Arrays.asList("50","100","200","300","400","500","600","700","800","900"));

        if(!mColorName.equals("Brown") && !mColorName.equals("Grey") && !mColorName.equals("Blue Grey")){
            colorGrades.add("A100");
            colorGrades.add("A200");
            colorGrades.add("A400");
            colorGrades.add("A700");
        }

        mColorList = new ArrayList<>();
        // Add to color List to send to adapter
        for(int i = 0; i<colorHexValues.length; i++){
            mColorList.add(new ColorValue(colorGrades.get(i), colorHexValues[i]));
        }
    }
}

@@ -54,66 +54,201 @@
 oid.
-os.Bundle;%0Aimport android.support.v7.app.AppCompatActivity
+content.ClipData;%0Aimport android.content.ClipboardManager;%0Aimport android.os.Bundle;%0Aimport android.support.v7.app.AppCompatActivity;%0Aimport android.view.View;%0Aimport android.widget.AdapterView
 ;%0Aim
@@ -276,16 +276,45 @@
 istView;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -483,16 +483,48 @@
 lorList;
+%0A    ClipboardManager clipboard;
 %0A%0A    @O
@@ -685,24 +685,152 @@
 r_detail);%0A%0A
+        // Set up Clipboard for copying color vals%0A        clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);%0A%0A
         // O
@@ -1453,16 +1453,717 @@
 apter);%0A
+        colorList.setOnItemClickListener(new AdapterView.OnItemClickListener() %7B%0A            @Override%0A            public void onItemClick(AdapterView%3C?%3E parent, View view, int position, long id) %7B%0A                String hexValue = mColorList.get(position).getHexCode();%0A                String colorGrade = mColorList.get(position).getColorGrade();%0A%0A                ClipData clip = ClipData.newPlainText(mColorName + %22 %22 + colorGrade, hexValue);%0A                clipboard.setPrimaryClip(clip);%0A                %0A                Toast.makeText(ColorDetailActivity.this,%0A                        mColorName + %22 %22 + colorGrade +%22 copied to clipboard%22, Toast.LENGTH_SHORT).show();%0A            %7D%0A        %7D);%0A
     %7D%0A%0A 

Copy color hex value to clipboard