Android Open Source - Locast-Core-Android Locast Sync Service






From Project

Back to project page Locast-Core-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Locast-Core-Android 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 edu.mit.mobile.android.locast.sync;
//www. ja v a  2  s. c o m
import android.accounts.Account;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import edu.mit.mobile.android.locast.BuildConfig;
import edu.mit.mobile.android.locast.Constants;

/**
 * <p>
 * This is a thin wrapper which routes sync requests to either {@link LocastSimpleSyncService} or
 * {@link AbsLocastAccountSyncService} depending on the constant
 * {@link Constants#USE_ACCOUNT_FRAMEWORK}. This is the primary interface to making requests for
 * synchronizing content.
 * </p>
 */
public abstract class LocastSyncService extends Service {

    private static final String TAG = LocastSyncService.class.getSimpleName();
    private static final boolean DEBUG = BuildConfig.DEBUG;
    public static final String EXTRA_ACCOUNT = "edu.mit.mobile.android.locast.EXTRA_ACCOUNT";

    final String mAuthority;

    /**
     * Convenience method to start a background sync.
     *
     * @param context
     * @param what
     *            Locast content dir or item to sync
     * @see #startSync(Account, Uri, boolean, Bundle)
     */
    public static void startSync(Context context, Uri what) {
        startSync(context, what, false);
    }

    public LocastSyncService() {
        mAuthority = getAuthority();
    }

    /**
     * Implement this to inform the superclass what authority this handles. This will only be called
     * once in the constructor, so make it count.
     *
     * @return the authority that this sync service handles.
     */
    public abstract String getAuthority();

    /**
     * Convenience method to start a sync.
     *
     * @param context
     * @param what
     *            Locast content dir or item to sync
     * @param explicitSync
     *            if the sync request was explicitly requested by the user, set this to true.
     * @see #startSync(Account, Uri, boolean, Bundle)
     */
    public static void startSync(Context context, Uri what, boolean explicitSync) {
        startSync(context, what, explicitSync, new Bundle());
    }

    public static void startExpeditedAutomaticSync(Context context, Uri what) {
        final Bundle extras = new Bundle();
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

        startSync(context, what, false, extras);
    }

    /**
     * Requests a sync of the item specified by a public URL.
     *
     * @param context
     * @param httpPubUrl
     *            an http or https URL pointing to a json array of json objects (if
     *            {@code destination} is a dir uri) or a single json object.
     * @param destination
     *            the destination local uri for the result to be stored in if it's not present
     * @param explicitSync
     *            If the sync request was explicitly requested by the user, set this to true.
     * @see #startSync(Account, Uri, boolean, Bundle)
     */
    public static void startSync(Context context, Uri httpPubUrl, Uri destination,
            boolean explicitSync) {
        final Bundle b = new Bundle();
        b.putString(SyncEngine.EXTRA_DESTINATION_URI, destination.toString());

        startSync(context, httpPubUrl, explicitSync, b);
    }

    /**
     * @param context
     * @param what
     *            Locast content dir or item to sync
     * @param explicitSync
     *            If the sync request was explicitly requested by the user, set this to true. adds
     *            {@link ContentResolver#SYNC_EXTRAS_MANUAL} and
     *            {@link ContentResolver#SYNC_EXTRAS_EXPEDITED} (unless it's already present)
     *
     * @param extras
     * @see #startSync(Account, Uri, boolean, Bundle)
     */
    public static void startSync(Context context, Uri what, boolean explicitSync, Bundle extras) {
        if (explicitSync) {
            extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            if (!extras.containsKey(ContentResolver.SYNC_EXTRAS_EXPEDITED)) {
                extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
            }
        }
        startSync(context, what, extras);
    }

    /**
     * Convenience method to request a sync.
     *
     * @param account
     * @param what
     *            Locast content dir or item to sync
     * @param explicitSync
     *            If the sync request was explicitly requested by the user, set this to true.
     * @see #startSync(Account, Uri, boolean, Bundle)
     */
    public static void startSync(Context context, Account account, Uri what) {
        final Bundle b = new Bundle();

        startSync(context, account, what, b);
    }

    /**
     * Convenience method to request a sync.
     *
     * @param account
     * @param what
     *            the uri of the item that needs to be sync'd. can be null
     * @param explicitSync
     *            if true, adds {@link ContentResolver#SYNC_EXTRAS_MANUAL} to the extras
     * @param extras
     */
    public static void startSync(Context context, Account account, Uri what, Bundle extras) {

        if (what != null) {
            extras.putString(AbsLocastAccountSyncService.EXTRA_SYNC_URI, what.toString());
        }

        if (account != null) {
            extras.putParcelable(EXTRA_ACCOUNT, account);
        }

        if (DEBUG) {
            Log.d(TAG, "requesting sync for " + account + " with extras: " + extras);
        }

        startSync(context, what, extras);
    }

    /**
     * Convenience method to request a sync.
     *
     * @param context
     * @param what
     *            the uri of the item that needs to be sync'd. can be null
     * @param extras
     */
    public static void startSync(Context context, Uri what, Bundle extras) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "startSync(" + what + ", " + extras + ")");
        }
        context.startService(new Intent(Intent.ACTION_SYNC, what).putExtras(extras));

    }
}




Java Source Code List

com.beoui.geocell.GeocellLogger.java
com.beoui.geocell.GeocellQueryEngine.java
com.beoui.geocell.GeocellUtils.java
com.beoui.geocell.annotations.Geocells.java
com.beoui.geocell.annotations.Latitude.java
com.beoui.geocell.annotations.Longitude.java
com.beoui.geocell.comparator.DoubleTupleComparator.java
com.beoui.geocell.comparator.LocationComparableTuple.java
com.beoui.geocell.model.BoundingBox.java
com.beoui.geocell.model.CostFunction.java
com.beoui.geocell.model.DefaultCostFunction.java
com.beoui.geocell.model.GeocellQuery.java
com.beoui.geocell.model.LocationCapable.java
com.beoui.geocell.model.Point.java
com.beoui.geocell.model.Tuple.java
com.stackoverflow.ArrayUtils.java
com.stackoverflow.CollectionUtils.java
com.stackoverflow.MediaUtils.java
com.stackoverflow.Predicate.java
edu.mit.mobile.android.MelAndroid.java
edu.mit.mobile.android.json.JSONArrayAdapter.java
edu.mit.mobile.android.locast.Constants.java
edu.mit.mobile.android.locast.accounts.AbsAccountChangeReceiver.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticationService.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java
edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticator.java
edu.mit.mobile.android.locast.accounts.AbsRegisterActivity.java
edu.mit.mobile.android.locast.accounts.LogoutFragment.java
edu.mit.mobile.android.locast.app.LocastApplication.java
edu.mit.mobile.android.locast.data.AbsComment.java
edu.mit.mobile.android.locast.data.AbsResourcesSync.java
edu.mit.mobile.android.locast.data.CastMedia.java
edu.mit.mobile.android.locast.data.ImageContent.java
edu.mit.mobile.android.locast.data.JSONSyncableIdenticalChildFinder.java
edu.mit.mobile.android.locast.data.JsonSyncableItem.java
edu.mit.mobile.android.locast.data.MediaProcessingException.java
edu.mit.mobile.android.locast.data.NoPublicPath.java
edu.mit.mobile.android.locast.data.OrderedList.java
edu.mit.mobile.android.locast.data.ResourcesSync.java
edu.mit.mobile.android.locast.data.SyncException.java
edu.mit.mobile.android.locast.data.SyncItemDeletedException.java
edu.mit.mobile.android.locast.data.SyncMapException.java
edu.mit.mobile.android.locast.data.SyncMap.java
edu.mit.mobile.android.locast.data.VideoContent.java
edu.mit.mobile.android.locast.data.interfaces.AuthorableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Authorable.java
edu.mit.mobile.android.locast.data.interfaces.CommentableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Commentable.java
edu.mit.mobile.android.locast.data.interfaces.FavoritableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Favoritable.java
edu.mit.mobile.android.locast.data.interfaces.LocatableUtils.java
edu.mit.mobile.android.locast.data.interfaces.Locatable.java
edu.mit.mobile.android.locast.data.interfaces.PrivatelyAuthorableUtils.java
edu.mit.mobile.android.locast.data.interfaces.PrivatelyAuthorable.java
edu.mit.mobile.android.locast.data.interfaces.TitledUtils.java
edu.mit.mobile.android.locast.data.interfaces.Titled.java
edu.mit.mobile.android.locast.data.tags.IdenticalTagFinder.java
edu.mit.mobile.android.locast.data.tags.TagSyncField.java
edu.mit.mobile.android.locast.data.tags.Tag.java
edu.mit.mobile.android.locast.data.tags.TaggableUtils.java
edu.mit.mobile.android.locast.data.tags.TaggableWrapper.java
edu.mit.mobile.android.locast.data.tags.Taggable.java
edu.mit.mobile.android.locast.net.ClientResponseException.java
edu.mit.mobile.android.locast.net.LocastApplicationCallbacks.java
edu.mit.mobile.android.locast.net.NetworkClient.java
edu.mit.mobile.android.locast.net.NetworkProtocolException.java
edu.mit.mobile.android.locast.sync.AbsLocastAccountSyncService.java
edu.mit.mobile.android.locast.sync.AbsMediaSync.java
edu.mit.mobile.android.locast.sync.LocastSimpleSyncService.java
edu.mit.mobile.android.locast.sync.LocastSyncService.java
edu.mit.mobile.android.locast.sync.LocastSyncStatusObserver.java
edu.mit.mobile.android.locast.sync.NotificationProgressListener.java
edu.mit.mobile.android.locast.sync.SyncColumns.java
edu.mit.mobile.android.locast.sync.SyncEngine.java
edu.mit.mobile.android.locast.sync.SyncableProvider.java
edu.mit.mobile.android.locast.sync.SyncableSimpleContentProvider.java
edu.mit.mobile.android.locast.sync.Syncable.java
edu.mit.mobile.android.locast.widget.RemoteTagsAdapter.java
edu.mit.mobile.android.locast.widget.TagButton.java
edu.mit.mobile.android.locast.widget.TagListView.java
edu.mit.mobile.android.locast.widget.TagList.java
edu.mit.mobile.android.locast.widget.TagsLoaderCallbacks.java
edu.mit.mobile.android.location.IncrementalLocator.java
se.fnord.android.layout.PredicateLayout.java