1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.calendar; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.database.Cursor; 22 import android.text.format.DateFormat; 23 import android.text.format.DateUtils; 24 import android.view.View; 25 import android.widget.ResourceCursorAdapter; 26 import android.widget.TextView; 27 28 public class AlertAdapter extends ResourceCursorAdapter { 29 30 public AlertAdapter(Context context, int resource) { 31 super(context, resource, null); 32 } 33 34 @Override 35 public void bindView(View view, Context context, Cursor cursor) { 36 TextView textView; 37 38 View stripe = view.findViewById(R.id.vertical_stripe); 39 int color = cursor.getInt(AlertActivity.INDEX_COLOR); 40 stripe.setBackgroundColor(color); 41 textView = (TextView) view.findViewById(R.id.event_title); 42 textView.setTextColor(color); 43 44 // Repeating info 45 View repeatContainer = view.findViewById(R.id.repeat_icon); 46 String rrule = cursor.getString(AlertActivity.INDEX_RRULE); 47 if (rrule != null) { 48 repeatContainer.setVisibility(View.VISIBLE); 49 } else { 50 repeatContainer.setVisibility(View.GONE); 51 } 52 53 /* 54 // Reminder 55 boolean hasAlarm = cursor.getInt(AlertActivity.INDEX_HAS_ALARM) != 0; 56 if (hasAlarm) { 57 AgendaAdapter.updateReminder(view, context, cursor.getLong(AlertActivity.INDEX_BEGIN), 58 cursor.getLong(AlertActivity.INDEX_EVENT_ID)); 59 } 60 */ 61 62 String eventName = cursor.getString(AlertActivity.INDEX_TITLE); 63 String location = cursor.getString(AlertActivity.INDEX_EVENT_LOCATION); 64 long startMillis = cursor.getLong(AlertActivity.INDEX_BEGIN); 65 long endMillis = cursor.getLong(AlertActivity.INDEX_END); 66 boolean allDay = cursor.getInt(AlertActivity.INDEX_ALL_DAY) != 0; 67 68 updateView(context, view, eventName, location, startMillis, endMillis, allDay); 69 } 70 71 public static void updateView(Context context, View view, String eventName, String location, 72 long startMillis, long endMillis, boolean allDay) { 73 74 Resources res = context.getResources(); 75 TextView textView; 76 77 // What 78 if (eventName == null || eventName.length() == 0) { 79 eventName = res.getString(R.string.no_title_label); 80 } 81 textView = (TextView) view.findViewById(R.id.event_title); 82 textView.setText(eventName); 83 84 // When 85 String when; 86 int flags; 87 if (allDay) { 88 flags = DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_WEEKDAY | 89 DateUtils.FORMAT_SHOW_DATE; 90 } else { 91 flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE; 92 } 93 if (DateFormat.is24HourFormat(context)) { 94 flags |= DateUtils.FORMAT_24HOUR; 95 } 96 when = DateUtils.formatDateRange(context, startMillis, endMillis, flags); 97 textView = (TextView) view.findViewById(R.id.when); 98 textView.setText(when); 99 100 // Where 101 textView = (TextView) view.findViewById(R.id.where); 102 if (location == null || location.length() == 0) { 103 textView.setVisibility(View.GONE); 104 } else { 105 textView.setText(location); 106 } 107 } 108 } 109