FileDocCategorySizeDatePackage
SelectCalendarsAdapter.javaAPI DocAndroid 1.5 API4983Wed May 06 22:42:42 BST 2009com.android.calendar

SelectCalendarsAdapter

public class SelectCalendarsAdapter extends android.widget.CursorAdapter

Fields Summary
private static final int
CLEAR_ALPHA_MASK
private static final int
HIGH_ALPHA
private static final int
MED_ALPHA
private static final int
LOW_ALPHA
private static final float[]
CORNERS
private static final String
TAG
private final android.view.LayoutInflater
mInflater
private final android.content.ContentResolver
mResolver
private final android.content.ContentValues
mValues
Constructors Summary
public SelectCalendarsAdapter(android.content.Context context, android.database.Cursor cursor)

        super(context, cursor);
        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mResolver = context.getContentResolver();
    
Methods Summary
public voidbindView(android.view.View view, android.content.Context context, android.database.Cursor cursor)

        int idColumn = cursor.getColumnIndexOrThrow(Calendars._ID);
        int nameColumn = cursor.getColumnIndexOrThrow(Calendars.DISPLAY_NAME);
        int selectedColumn = cursor.getColumnIndexOrThrow(Calendars.SELECTED);
        int colorColumn = cursor.getColumnIndexOrThrow(Calendars.COLOR);
        view.findViewById(R.id.color).setBackgroundDrawable(getColorChip(cursor.getInt(colorColumn)));
        setText(view, R.id.calendar, cursor.getString(nameColumn));
        CheckBox box = (CheckBox) view.findViewById(R.id.checkbox);
        long id = cursor.getLong(idColumn);
        boolean checked = cursor.getInt(selectedColumn) != 0;
        box.setOnCheckedChangeListener(null);
        box.setChecked(checked);
        box.setOnCheckedChangeListener(new CheckBoxListener(id));
    
private android.graphics.drawable.DrawablegetColorChip(int color)

        
        /*
         * We want the color chip to have a nice gradient using
         * the color of the calendar. To do this we use a GradientDrawable.
         * The color supplied has an alpha of FF so we first do:
         * color & 0x00FFFFFF
         * to clear the alpha. Then we add our alpha to it.
         * We use 3 colors to get a step effect where it starts off very
         * light and quickly becomes dark and then a slow transition to
         * be even darker.
         */
        color &= CLEAR_ALPHA_MASK;
        int startColor = color | HIGH_ALPHA;
        int middleColor = color | MED_ALPHA;
        int endColor = color | LOW_ALPHA;
        int[] colors = new int[] {startColor, middleColor, endColor};
        GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
        d.setCornerRadii(CORNERS);
        return d;
    
public android.view.ViewnewView(android.content.Context context, android.database.Cursor cursor, android.view.ViewGroup parent)

        return mInflater.inflate(R.layout.calendar_item, parent, false);
    
private static voidsetText(android.view.View view, int id, java.lang.String text)

        if (TextUtils.isEmpty(text)) {
            return;
        }
        TextView textView = (TextView) view.findViewById(id);
        textView.setText(text);