// Path: wear/src/main/java/ooo/oxo/apps/earth/provider/EarthsContract.java
// public class EarthsContract {
// 
//     public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".earths";
// 
//     public static final Uri CONTENT_URI = new Uri.Builder()
//             .scheme(ContentResolver.SCHEME_CONTENT)
//             .authority(AUTHORITY)
//             .path("earths")
//             .build();
// 
//     public static final Uri LATEST_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "latest");
// 
//     public static final String CONTENT_TYPE_DIR
//             = "vnd.android.cursor.dir/vnd." + BuildConfig.APPLICATION_ID + ".earths";
// 
//     public static final String CONTENT_TYPE_ITEM
//             = "vnd.android.cursor.item/vnd." + BuildConfig.APPLICATION_ID + ".earths";
// 
//     static final String TABLE = "earths";
// 
//     public static class Columns implements BaseColumns {
//         public static final String FILE = "file";
//         public static final String FETCHED_AT = "fetched_at";
//     }
// 
// }


import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable;
import com.umeng.analytics.MobclickAgent;
import java.util.concurrent.atomic.AtomicInteger;
import ooo.oxo.apps.earth.provider.EarthsContract;
import android.app.Service;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
/*
 * Mantou Earth - Live your wallpaper with live earth
 * Copyright (C) 2015-2019 XiNGRZ <xxx@oxo.ooo>
 *
 * 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/>.
 */

package ooo.oxo.apps.earth;






/**
 * 用于观察地球变化并触发 {@link WatchTransferService} 同步到手表
 */
public class WatchSyncService extends Service implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        NodeApi.NodeListener {

    private static final String TAG = "WatchSyncService";

    private final AtomicInteger connected = new AtomicInteger();

    private final ContentObserver observer = new ContentObserver(null) {
        @Override
        public void onChange(boolean selfChange) {
            Log.d(TAG, "new earth ready, triggering watch sync...");
            sync();
        }
    };

    private GoogleApiClient client;

    @Override
    public void onCreate() {
        super.onCreate();

        client = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

// Path: wear/src/main/java/ooo/oxo/apps/earth/provider/EarthsContract.java
// public class EarthsContract {
// 
//     public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".earths";
// 
//     public static final Uri CONTENT_URI = new Uri.Builder()
//             .scheme(ContentResolver.SCHEME_CONTENT)
//             .authority(AUTHORITY)
//             .path("earths")
//             .build();
// 
//     public static final Uri LATEST_CONTENT_URI = Uri.withAppendedPath(CONTENT_URI, "latest");
// 
//     public static final String CONTENT_TYPE_DIR
//             = "vnd.android.cursor.dir/vnd." + BuildConfig.APPLICATION_ID + ".earths";
// 
//     public static final String CONTENT_TYPE_ITEM
//             = "vnd.android.cursor.item/vnd." + BuildConfig.APPLICATION_ID + ".earths";
// 
//     static final String TABLE = "earths";
// 
//     public static class Columns implements BaseColumns {
//         public static final String FILE = "file";
//         public static final String FETCHED_AT = "fetched_at";
//     }
// 
// }


// Path: app/src/main/java/ooo/oxo/apps/earth/WatchSyncService.java
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable;
import com.umeng.analytics.MobclickAgent;
import java.util.concurrent.atomic.AtomicInteger;
import ooo.oxo.apps.earth.provider.EarthsContract;
import android.app.Service;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;

/*
 * Mantou Earth - Live your wallpaper with live earth
 * Copyright (C) 2015-2019 XiNGRZ <xxx@oxo.ooo>
 *
 * 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/>.
 */

package ooo.oxo.apps.earth;






/**
 * 用于观察地球变化并触发 {@link WatchTransferService} 同步到手表
 */
public class WatchSyncService extends Service implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        NodeApi.NodeListener {

    private static final String TAG = "WatchSyncService";

    private final AtomicInteger connected = new AtomicInteger();

    private final ContentObserver observer = new ContentObserver(null) {
        @Override
        public void onChange(boolean selfChange) {
            Log.d(TAG, "new earth ready, triggering watch sync...");
            sync();
        }
    };

    private GoogleApiClient client;

    @Override
    public void onCreate() {
        super.onCreate();

        client = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        getContentResolver().registerContentObserver(EarthsContract.LATEST_CONTENT_URI, false, observer);