170 lines
4.5 KiB
Java
170 lines
4.5 KiB
Java
|
package com.safemobile.adapters;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
import com.safemobile.lib.R;
|
||
|
import com.safemobile.lib.radio.ZoneChannel;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.content.Context;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.ArrayAdapter;
|
||
|
import android.widget.ImageView;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
public class ZoneChannelComboBoxAdapter extends ArrayAdapter<ZoneChannel>{
|
||
|
|
||
|
private static final int TYPE_ZONE = 0;
|
||
|
private static final int TYPE_CHANNEL = 1;
|
||
|
private static final int TYPE_MAX_COUNT = 2;
|
||
|
|
||
|
|
||
|
private Context context;
|
||
|
int layoutResourceId;
|
||
|
private ArrayList<ZoneChannel> listValues;
|
||
|
|
||
|
public ZoneChannelComboBoxAdapter(Context context, int textViewResourceId, ArrayList<ZoneChannel> listValues) {
|
||
|
super(context, textViewResourceId, listValues);
|
||
|
this.context = context;
|
||
|
this.layoutResourceId = textViewResourceId;
|
||
|
this.listValues = listValues;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||
|
return getCustomView(position, convertView, parent);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
return getCustomView(position, convertView, parent);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getItemViewType(int position) {
|
||
|
return listValues.get(position).isSection() ? TYPE_ZONE : TYPE_CHANNEL;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getViewTypeCount() {
|
||
|
return TYPE_MAX_COUNT;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getCount() {
|
||
|
return listValues.size();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ZoneChannel getItem(int position) {
|
||
|
return listValues.get(position);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public long getItemId(int position) {
|
||
|
return position;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isEnabled(int position) {
|
||
|
if(getItemViewType(position) == TYPE_ZONE)
|
||
|
return false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||
|
ImagesSpinnerHolder holder = null;
|
||
|
int type = getItemViewType(position);
|
||
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||
|
|
||
|
if(convertView == null) {
|
||
|
holder = new ImagesSpinnerHolder();
|
||
|
|
||
|
switch (type) {
|
||
|
case TYPE_ZONE:
|
||
|
convertView = inflater.inflate(R.layout.combobox_section_header, parent, false);
|
||
|
holder.title = (TextView) convertView.findViewById(R.id.txtHeader);
|
||
|
break;
|
||
|
|
||
|
case TYPE_CHANNEL:
|
||
|
convertView = inflater.inflate(R.layout.combobox_row, parent, false);
|
||
|
holder.textSpinner = (TextView)convertView.findViewById(R.id.text);
|
||
|
holder.imgSpinner = (ImageView)convertView.findViewById(R.id.icon);
|
||
|
holder.imgSpinner.setVisibility(View.GONE);
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
|
||
|
convertView.setTag(holder);
|
||
|
}
|
||
|
else
|
||
|
holder = (ImagesSpinnerHolder) convertView.getTag();
|
||
|
|
||
|
switch(type) {
|
||
|
case TYPE_ZONE:
|
||
|
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||
|
|
||
|
break;
|
||
|
|
||
|
case TYPE_CHANNEL:
|
||
|
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||
|
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
|
||
|
|
||
|
View row = convertView;
|
||
|
|
||
|
|
||
|
if(row == null) {
|
||
|
// check if section header -> isSection will return true
|
||
|
if(sectionList.get(position))
|
||
|
{
|
||
|
row = inflater.inflate(R.layout.spinner_header, parent, false);
|
||
|
holder.title = (TextView) row.findViewById(R.id.txtHeader);
|
||
|
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
row = inflater.inflate(R.layout.spinner, parent, false);
|
||
|
holder.textSpinner = (TextView)row.findViewById(R.id.language);
|
||
|
holder.imgSpinner = (ImageView)row.findViewById(R.id.icon);
|
||
|
holder.imgSpinner.setVisibility(View.INVISIBLE);
|
||
|
|
||
|
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||
|
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||
|
}
|
||
|
|
||
|
row.setTag(holder);
|
||
|
}
|
||
|
else {
|
||
|
|
||
|
holder = (ImagesSpinnerHolder)row.getTag();
|
||
|
if(sectionList.get(position)){
|
||
|
if(holder.title!= null)
|
||
|
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||
|
}
|
||
|
else {
|
||
|
if(holder.textSpinner!=null)
|
||
|
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||
|
if(holder.imgSpinner != null)
|
||
|
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||
|
}
|
||
|
}
|
||
|
*/
|
||
|
return convertView;
|
||
|
}
|
||
|
|
||
|
private class ImagesSpinnerHolder {
|
||
|
ImageView imgSpinner;
|
||
|
TextView textSpinner;
|
||
|
TextView title;
|
||
|
}
|
||
|
|
||
|
}
|