Android Open Source - E34Clock Alarm Info






From Project

Back to project page E34Clock.

License

The source code is released under:

Apache License

If you think the Android project E34Clock listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * (c) Copyright 2013 Stefan Langer/*from w  w w .j  a va 2  s . c  om*/
 *
 *    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 de.element34.e34clock;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AlarmInfo {
    private static final Pattern pattern = Pattern.compile("(\\w+)\\D+([0-9]?[0-9]:[0-9][0-9]) *(AM|PM)?");
    private static final String TAG = "e34clock.AlarmInfo";

    public List<String> extractAlarmText(String sysAlarm) {
        Matcher matcher = pattern.matcher(sysAlarm);
        List<String> nextAlarm = new ArrayList<String>();
        if (matcher.find()) {
            String weekDay = matcher.group(1);
            Log.v(TAG, "Found weekday " + weekDay);
            nextAlarm.add(weekDay);
            String timeStr = matcher.group(2);
            Log.v(TAG, "Found time " + timeStr);
            nextAlarm.add(timeStr);
            if (matcher.find(2)) {
                String amPm = matcher.group(3);
                if (amPm != null && !"".equals(amPm.trim())) {
                    Log.v(TAG, "Found time extension " + amPm);
                    nextAlarm.add(amPm);
                }
            }
        } else {
            nextAlarm.add(sysAlarm);
            Log.v(TAG, "Pattern " + pattern + " did not match!");
        }
        Log.v(TAG, "Extracted text " + nextAlarm + " from " + sysAlarm);
        return nextAlarm;
    }
}




Java Source Code List

de.element34.e34clock.AlarmInfo.java
de.element34.e34clock.BatteryInfo.java
de.element34.e34clock.ClockService.java
de.element34.e34clock.ClockSettingsActivity.java
de.element34.e34clock.ClockUtil.java
de.element34.e34clock.ClockWidget.java
de.element34.e34clock.Constants.java
de.element34.e34clock.FullClockWidget.java
de.element34.e34clock.SoloClockWidget.java
de.element34.e34clock.SoloDateWidget.java