1/* 2 * Copyright (C) 2015 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 */ 16package com.android.deskclock.widget.selector; 17 18import android.content.Context; 19import android.view.LayoutInflater; 20import android.view.View; 21import android.view.ViewGroup; 22import android.widget.ArrayAdapter; 23import android.widget.TextView; 24 25import com.android.deskclock.R; 26import com.android.deskclock.provider.Alarm; 27import com.android.deskclock.widget.TextTime; 28 29import java.util.List; 30 31public class AlarmSelectionAdapter extends ArrayAdapter<AlarmSelection> { 32 33 public AlarmSelectionAdapter(Context context, int id, List<AlarmSelection> alarms) { 34 super(context, id, alarms); 35 } 36 37 @Override 38 public View getView(int position, View convertView, ViewGroup parent) { 39 final Context context = getContext(); 40 View row = convertView; 41 if (row == null) { 42 final LayoutInflater inflater = LayoutInflater.from(context); 43 row = inflater.inflate(R.layout.alarm_row, parent, false); 44 } 45 46 final AlarmSelection selection = getItem(position); 47 final Alarm alarm = selection.getAlarm(); 48 49 final TextTime alarmTime = (TextTime) row.findViewById(R.id.digital_clock); 50 alarmTime.setFormat(context, 51 context.getResources().getDimensionPixelSize(R.dimen.alarm_label_size)); 52 alarmTime.setTime(alarm.hour, alarm.minutes); 53 54 final TextView alarmLabel = (TextView) row.findViewById(R.id.label); 55 alarmLabel.setText(alarm.label); 56 57 // find days when alarm is firing 58 final String daysOfWeek; 59 if (!alarm.daysOfWeek.isRepeating()) { 60 daysOfWeek = Alarm.isTomorrow(alarm) ? 61 context.getResources().getString(R.string.alarm_tomorrow) : 62 context.getResources().getString(R.string.alarm_today); 63 } else { 64 daysOfWeek = alarm.daysOfWeek.toString(context, 0); 65 } 66 67 final TextView daysOfWeekView = (TextView) row.findViewById(R.id.daysOfWeek); 68 daysOfWeekView.setText(daysOfWeek); 69 70 return row; 71 } 72}