package com.example.projectweek;


import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Created by svirch_n on 29/01/14.
 * nicolas.svirchevsky@epitech.eu
 */

public class FragmentCategorie extends Fragment {

    private Typeface mTypeface = null;

    private String[] mColor = {
            "#F8B194",
            "#EF997B",
            "#F67281",
            "#C16E87",
            "#706684",
            "#73587D",
            "#355C7C"
    };

    private String[] mArray = {
            "RESTAURANT",
            "HOTEL",
            "MODE",
            "SERVICE",
            "CULTUREL",
            "SORTIE",
            "ELECTRONIQUE"
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);


        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
        View view = inflater.inflate(R.layout.fragment_categorie, container, false);
        View newView;
        ViewGroup viewGroup;
        if (view != null) {
            viewGroup = (ViewGroup) view.findViewById(R.id.linear);
            for (int i = 0; i < mArray.length; i++) {
                newView = inflater.inflate(R.layout.item_categorie, null);
                ((TextView)newView.findViewById(R.id.text)).setText(mArray[i]);
                ((TextView)newView.findViewById(R.id.text)).setTypeface(mTypeface);
                newView.setBackgroundColor(Color.parseColor(mColor[i]));
                viewGroup.addView(newView, param);
            }

        }
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();

        mTypeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Bold.ttf");
    }

//    @Override
//    public void onListItemClick(ListView l, View v, int position, long id) {
//        super.onListItemClick(l, v, position, id);
//
//        Intent intent = new Intent(getActivity(), EventActivity.class);
//        String message = mColor[position];
//        intent.putExtra(MyActivity.EXTRA_MESSAGE, message);
//        startActivity(intent);
//    }
//

    public class MyAdapter extends ArrayAdapter<String> {

        public MyAdapter() {
            super(getActivity(), R.layout.item_categorie, mArray);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view = convertView;
            if (view == null)
                view = getActivity().getLayoutInflater().inflate(R.layout.item_categorie, null);
            if (view != null) {
                ((TextView) view.findViewById(R.id.text)).setText(mArray[position]);
                ((TextView) view.findViewById(R.id.text)).setTypeface(mTypeface);
                view.findViewById(R.id.linear).setBackgroundColor(Color.parseColor(mColor[position]));
            }
            return view;
        }
    }

}
@@ -623,16 +623,48 @@
 ragment 
+implements View.OnClickListener 
 %7B%0A%0A    p
@@ -1975,32 +1975,33 @@
      ((TextView)
+ 
 newView.findView
@@ -2064,16 +2064,17 @@
 extView)
+ 
 newView.
@@ -2191,24 +2191,74 @@
 Color%5Bi%5D));%0A
+                newView.setOnClickListener(this);%0A
             
@@ -2419,16 +2419,16 @@
 ume();%0A%0A
-
         
@@ -2524,16 +2524,320 @@
 %0A    %7D%0A%0A
+    @Override%0A    public void onClick(View view) %7B%0A        Intent intent = new Intent(getActivity(), EventActivity.class);%0A        String message = mColor%5B((ViewGroup)view.getParent()).indexOfChild(view)%5D;%0A        intent.putExtra(MyActivity.EXTRA_MESSAGE, message);%0A        startActivity(intent);%0A    %7D%0A%0A
 //    @O

Index of Categories done