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.TextUtils; 23 import android.text.format.DateFormat; 24 import android.text.format.DateUtils; 25 import android.view.View; 26 import android.widget.ResourceCursorAdapter; 27 import android.widget.TextView; 28 29 public class AlertAdapter extends ResourceCursorAdapter { 30 AlertAdapter(Context context, int resource)31 public AlertAdapter(Context context, int resource) { 32 super(context, resource, null); 33 } 34 35 @Override bindView(View view, Context context, Cursor cursor)36 public void bindView(View view, Context context, Cursor cursor) { 37 TextView textView; 38 39 View stripe = view.findViewById(R.id.vertical_stripe); 40 int color = cursor.getInt(AlertActivity.INDEX_COLOR); 41 stripe.setBackgroundColor(color); 42 textView = (TextView) view.findViewById(R.id.event_title); 43 textView.setTextColor(color); 44 45 // Repeating info 46 View repeatContainer = view.findViewById(R.id.repeat_icon); 47 String rrule = cursor.getString(AlertActivity.INDEX_RRULE); 48 if (!TextUtils.isEmpty(rrule)) { 49 repeatContainer.setVisibility(View.VISIBLE); 50 } else { 51 repeatContainer.setVisibility(View.GONE); 52 } 53 54 /* 55 // Reminder 56 boolean hasAlarm = cursor.getInt(AlertActivity.INDEX_HAS_ALARM) != 0; 57 if (hasAlarm) { 58 AgendaAdapter.updateReminder(view, context, cursor.getLong(AlertActivity.INDEX_BEGIN), 59 cursor.getLong(AlertActivity.INDEX_EVENT_ID)); 60 } 61 */ 62 63 String eventName = cursor.getString(AlertActivity.INDEX_TITLE); 64 String location = cursor.getString(AlertActivity.INDEX_EVENT_LOCATION); 65 long startMillis = cursor.getLong(AlertActivity.INDEX_BEGIN); 66 long endMillis = cursor.getLong(AlertActivity.INDEX_END); 67 boolean allDay = cursor.getInt(AlertActivity.INDEX_ALL_DAY) != 0; 68 69 updateView(context, view, eventName, location, startMillis, endMillis, allDay); 70 } 71 updateView(Context context, View view, String eventName, String location, long startMillis, long endMillis, boolean allDay)72 public static void updateView(Context context, View view, String eventName, String location, 73 long startMillis, long endMillis, boolean allDay) { 74 75 Resources res = context.getResources(); 76 TextView textView; 77 78 // What 79 if (eventName == null || eventName.length() == 0) { 80 eventName = res.getString(R.string.no_title_label); 81 } 82 textView = (TextView) view.findViewById(R.id.event_title); 83 textView.setText(eventName); 84 85 // When 86 String when; 87 int flags; 88 if (allDay) { 89 flags = DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_WEEKDAY | 90 DateUtils.FORMAT_SHOW_DATE; 91 } else { 92 flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE; 93 } 94 if (DateFormat.is24HourFormat(context)) { 95 flags |= DateUtils.FORMAT_24HOUR; 96 } 97 when = Utils.formatDateRange(context, startMillis, endMillis, flags); 98 textView = (TextView) view.findViewById(R.id.when); 99 textView.setText(when); 100 101 // Where 102 textView = (TextView) view.findViewById(R.id.where); 103 if (location == null || location.length() == 0) { 104 textView.setVisibility(View.GONE); 105 } else { 106 textView.setText(location); 107 } 108 } 109 } 110