Android Open Source - 24hAnalogWidget Clock Util






From Project

Back to project page 24hAnalogWidget.

License

The source code is released under:

GNU General Public License

If you think the Android project 24hAnalogWidget 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

package info.staticfree.android.twentyfourhour;
//w w  w  .  j  ava 2  s  .c  om
/*
 * Copyright (C) 2011 Steve Pomeroy <steve@staticfree.info>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class ClockUtil {

    /**
     * @param context
     * @return an intent that will show the native clock app
     * @see <a
     * href="http://stackoverflow.com/questions/3590955/intent-to-launch-the-clock-application-on-android">Stack
     * Overflow post</a>
     */
    public static final PendingIntent getClockIntent(Context context) {
        final Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(
                Intent.CATEGORY_LAUNCHER).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // Verify clock implementation
        final String clockImpls[][] = {
                {"Alarm Klock", "com.angrydoughnuts.android.alarmclock",
                        "com.angrydoughnuts.android.alarmclock.ActivityAlarmClock"},

                {"HTC Alarm Clock", "com.htc.android.worldclock",
                        "com.htc.android.worldclock.WorldClockTabControl"},

                {"Standar Alarm Clock", "com.android.deskclock",
                        "com.android.deskclock.AlarmClock"},

                {"Froyo Nexus Alarm Clock", "com.google.android.deskclock",
                        "com.android.deskclock.DeskClock"},

                {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock",
                        "com.motorola.blur.alarmclock.AlarmClock"},

                {"Samsung Galaxy S", "com.sec.android.app.clockpackage",
                        "com.sec.android.app.clockpackage.ClockPackage"}

        };

        boolean foundClockImpl = false;

        final PackageManager packageManager = context.getPackageManager();

        for (int i = 0; i < clockImpls.length; i++) {
            // final String vendor = clockImpls[i][0];
            final String packageName = clockImpls[i][1];
            final String className = clockImpls[i][2];
            try {
                final ComponentName cn = new ComponentName(packageName, className);
                packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
                alarmClockIntent.setComponent(cn);
                // debug("Found " + vendor + " --> " + packageName + "/" + className);
                foundClockImpl = true;
                break;
            } catch (final NameNotFoundException e) {
                // haven't found it yet
            }
        }

        if (foundClockImpl) {

            return PendingIntent.getActivity(context, 0, alarmClockIntent, 0);
        } else {
            return null;
        }
    }
}




Java Source Code List

info.staticfree.android.twentyfourhour.Analog24HClock.java
info.staticfree.android.twentyfourhour.AnalogClockApplication.java
info.staticfree.android.twentyfourhour.ClockUtil.java
info.staticfree.android.twentyfourhour.TwentyFourHourClockWidget3x.java
info.staticfree.android.twentyfourhour.TwentyFourHourClockWidgetResizable.java
info.staticfree.android.twentyfourhour.TwentyFourHourClockWidget.java
info.staticfree.android.twentyfourhour.WearFace.java
info.staticfree.android.twentyfourhour.WidgetDemo.java
info.staticfree.android.twentyfourhour.overlay.DateOverlay.java
info.staticfree.android.twentyfourhour.overlay.DebugOverlay.java
info.staticfree.android.twentyfourhour.overlay.DialOverlay.java
info.staticfree.android.twentyfourhour.overlay.HandsOverlay.java
info.staticfree.android.twentyfourhour.overlay.SunPositionOverlay.java
twentyfourhour.WearFaceDemoActivity.java