package com.insidesecure.drm.android.reference;


import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.insidesecure.drm.android.reference.xoplayer.R;
import java.util.ArrayList;


public class CustomSpinnerAdapter extends ArrayAdapter
{
    private Context           context;
    private ArrayList<String> rowsData;


    public CustomSpinnerAdapter(Context           context,
                                ArrayList<String> rowsData)
    {

        super(context, -1, rowsData);

        this.context = context;
        this.rowsData = rowsData;

        setDropDownViewResource(android.R.layout.simple_spinner_item);
    }


    public int getCount()
    {

        return rowsData.size();
    }


    public Object getItem(int position)
    {

        return rowsData.get(position);
    }


    public View getView(int       position,
                        View      convertView,
                        ViewGroup parent)
    {
        View view;

        if (convertView == null)
        {
            view = new TextView(context);
            ((TextView) view).setTextColor(Color.WHITE);
            ((TextView) view).setGravity(Gravity.LEFT);
            view.setBackgroundResource(R.drawable.spinner_item_selector);
            view.setPadding(0, 0, 7, 0);
        }
        else
        {
            view = convertView;
        }

        ((TextView) view).setText((String) getItem(position));

        return view;
    }


    public View getDropDownView(int       position,
                                View      convertView,
                                ViewGroup parent)
    {
        View view;

        if (convertView == null)
        {
            view = new TextView(context);
            ((TextView) view).setTextColor(Color.WHITE);
            ((TextView) view).setTextSize(16.0f);
            ((TextView) view).setGravity(Gravity.LEFT);
            view.setBackgroundResource(R.drawable.spinner_item_selector);
            view.setPadding(5, 5, 0, 5);
        }
        else
        {
            view = convertView;
        }

        if (position == 0)
        {
            ((TextView) view).setMaxLines(0);
            view.setVisibility(View.GONE);
        }
        else
        {
            ((TextView) view).setMaxLines(1);
            view.setVisibility(View.VISIBLE);
        }

        ((TextView) view).setText((String) getItem(position));

        return view;
    }
}