Back to project page DashClockWidget.
The source code is released under:
Apache License
If you think the Android project DashClockWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright 2013 Google Inc./*from w ww. j a v a 2 s. com*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.apps.dashclock.nextalarm; import com.google.android.apps.dashclock.LogUtils; import com.google.android.apps.dashclock.Utils; import com.google.android.apps.dashclock.api.DashClockExtension; import com.google.android.apps.dashclock.api.ExtensionData; import com.google.android.apps.dashclock.configuration.AppChooserPreference; import net.nurik.roman.dashclock.R; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.preference.PreferenceManager; import android.provider.Settings; import android.text.TextUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Next alarm extension. */ public class NextAlarmExtension extends DashClockExtension { private static final String TAG = LogUtils.makeLogTag(NextAlarmExtension.class); public static final String PREF_ALARM_SHORTCUT = "pref_alarm_shortcut"; private static Pattern sDigitPattern = Pattern.compile("\\s[0-9]"); @Override protected void onInitialize(boolean isReconnect) { super.onInitialize(isReconnect); if (!isReconnect) { addWatchContentUris(new String[]{ Settings.System.getUriFor(Settings.System.NEXT_ALARM_FORMATTED).toString() }); } } @Override protected void onUpdateData(int reason) { String nextAlarm = Settings.System.getString(getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED); if (!TextUtils.isEmpty(nextAlarm)) { Matcher m = sDigitPattern.matcher(nextAlarm); if (m.find() && m.start() > 0) { nextAlarm = nextAlarm.substring(0, m.start()) + "\n" + nextAlarm.substring(m.start() + 1); // +1 to skip whitespace } } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); Intent alarmIntent = AppChooserPreference.getIntentValue( sp.getString(PREF_ALARM_SHORTCUT, null), null); if (alarmIntent == null) { alarmIntent = Utils.getDefaultAlarmsIntent(this); } publishUpdate(new ExtensionData() .visible(!TextUtils.isEmpty(nextAlarm)) .icon(R.drawable.ic_extension_next_alarm) .status(nextAlarm) .clickIntent(alarmIntent)); } }