1 /* 2 * Copyright (C) 2012 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.deskclock; 18 19 import android.app.Fragment; 20 import android.app.FragmentManager; 21 import android.app.FragmentTransaction; 22 import android.content.Context; 23 import android.widget.Toast; 24 25 /** 26 * Static utility methods for Alarms. 27 */ 28 public class AlarmUtils { 29 30 public static void showTimeEditDialog(FragmentManager manager, final Alarm alarm) { 31 final FragmentTransaction ft = manager.beginTransaction(); 32 final Fragment prev = manager.findFragmentByTag("time_dialog"); 33 if (prev != null) { 34 ft.remove(prev); 35 } 36 ft.addToBackStack(null); 37 38 final AlarmTimePickerDialogFragment fragment = AlarmTimePickerDialogFragment.newInstance( 39 alarm); 40 fragment.show(ft, "time_dialog"); 41 } 42 43 public static void popAlarmSetToast(Context context, long timeInMillis) { 44 String toastText = SetAlarm.formatToast(context, timeInMillis); 45 Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG); 46 ToastMaster.setToast(toast); 47 toast.show(); 48 } 49 50 /** 51 * Display a toast that tells the user how long until the alarm 52 * goes off. This helps prevent "am/pm" mistakes. 53 */ 54 public static void popAlarmSetToast(Context context, int hour, int minute, 55 Alarm.DaysOfWeek daysOfWeek) { 56 popAlarmSetToast(context, 57 Alarms.calculateAlarm(hour, minute, daysOfWeek) 58 .getTimeInMillis()); 59 } 60 } 61