Android Open Source - CalWatch Watch Calendar Service

From Project

Back to project page CalWatch.


The source code is released under:

GNU General Public License

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

 * CalWatch/*w  w  w.j av a 2*/
 * Copyright (C) 2014 by Dan Wallach
 * Home page:
 * Licensing:
package org.dwallach.calwatch;

import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import java.util.Observable;
import java.util.Observer;

public class WatchCalendarService extends Service implements Observer {
    private static final String TAG = "WatchCalendarService";

    private static WatchCalendarService singletonService;
    private WearSender wearSender;
    private ClockState clockState;

    private ClockState getClockState() {
        // more on the design of this particular contraption in the comments in PhoneActivity
        if(clockState == null) {
            clockState = ClockState.getSingleton();
        return clockState;

    public WatchCalendarService() {

    public static WatchCalendarService getSingletonService() {
        return singletonService;

    // this is called when there's something new from the calendar DB
    public void sendAllToWatch() {
        if (wearSender == null) {
            Log.e(TAG, "no wear sender?!");

        // and now, send on to the wear device

    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        Log.v(TAG, "service starting!");

        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        return START_STICKY;

    private void initInternal() {
        wearSender = new WearSender(this);


    public void onCreate() {
        Log.v(TAG, "service created!");


    public void onDestroy() {
        Log.v(TAG, "service destroyed!");

        clockState = null;

    public IBinder onBind(Intent intent) {
        Log.e(TAG, "onBind: we should support this");
        throw new UnsupportedOperationException("Not yet implemented");

    public void update(Observable observable, Object data) {
        // somebody updated something in the clock state (new events, new display options, etc.)
        Log.v(TAG, "internal clock state changed: time to send all to the watch");

    public static void kickStart(Context ctx) {
        // start the calendar service, if it's not already running
        WatchCalendarService watchCalendarService = WatchCalendarService.getSingletonService();

        if(watchCalendarService == null) {
            Log.v(TAG, "launching watch calendar service");
            Intent serviceIntent = new Intent(ctx, WatchCalendarService.class);


Java Source Code List