AlarmUtils.java revision 9a39d368cab0c21a3a721d2df86a44eba4e3121c
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
17package com.android.deskclock;
18
19import android.app.Fragment;
20import android.app.FragmentManager;
21import android.app.FragmentTransaction;
22import android.content.Context;
23import android.widget.Toast;
24
25/**
26 * Static utility methods for Alarms.
27 */
28public 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        final AlarmTimePickerDialogFragment fragment = AlarmTimePickerDialogFragment.newInstance(
37                alarm);
38        fragment.show(ft, "time_dialog");
39    }
40
41    public static void popAlarmSetToast(Context context, long timeInMillis) {
42        String toastText = SetAlarm.formatToast(context, timeInMillis);
43        Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG);
44        ToastMaster.setToast(toast);
45        toast.show();
46    }
47
48    /**
49     * Display a toast that tells the user how long until the alarm
50     * goes off.  This helps prevent "am/pm" mistakes.
51     */
52    public static void popAlarmSetToast(Context context, int hour, int minute,
53                                 Alarm.DaysOfWeek daysOfWeek) {
54        popAlarmSetToast(context,
55                Alarms.calculateAlarm(hour, minute, daysOfWeek)
56                        .getTimeInMillis());
57    }
58}
59