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 */ 16 package com.android.deskclock.widget.selector; 17 18 import android.content.Context; 19 import android.view.LayoutInflater; 20 import android.view.View; 21 import android.view.ViewGroup; 22 import android.widget.ArrayAdapter; 23 import android.widget.TextView; 24 25 import com.android.deskclock.R; 26 import com.android.deskclock.provider.Alarm; 27 import com.android.deskclock.widget.TextTime; 28 29 import java.util.Calendar; 30 import java.util.List; 31 32 public class AlarmSelectionAdapter extends ArrayAdapter<AlarmSelection> { 33 AlarmSelectionAdapter(Context context, int id, List<AlarmSelection> alarms)34 public AlarmSelectionAdapter(Context context, int id, List<AlarmSelection> alarms) { 35 super(context, id, alarms); 36 } 37 38 @Override getView(int position, View convertView, ViewGroup parent)39 public View getView(int position, View convertView, ViewGroup parent) { 40 final Context context = getContext(); 41 View row = convertView; 42 if (row == null) { 43 final LayoutInflater inflater = LayoutInflater.from(context); 44 row = inflater.inflate(R.layout.alarm_row, parent, false); 45 } 46 47 final AlarmSelection selection = getItem(position); 48 final Alarm alarm = selection.getAlarm(); 49 50 final TextTime alarmTime = (TextTime) row.findViewById(R.id.digital_clock); 51 alarmTime.setFormat(context); 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, Calendar.getInstance()) ? 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 }