Android Open Source - Multi-Mania-app Sync Adapter






From Project

Back to project page Multi-Mania-app.

License

The source code is released under:

MIT License

If you think the Android project Multi-Mania-app 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 be.ana.nmct.multimania.service;
//from w  w  w .  j  a  v  a2  s. c o m
import android.accounts.Account;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
import android.util.Log;

import be.ana.nmct.multimania.ui.MainActivity;
import be.ana.nmct.multimania.utils.SettingsUtil;
import be.ana.nmct.multimania.utils.SyncUtils;

/**
 * Created by Astrid on 16/11/2014.
 */
public class SyncAdapter extends AbstractThreadedSyncAdapter {

    public static final String SYNC_READY_BROADCAST = "be.ana.nmct.multimania.sync_ready";
    private static final String TAG = SyncAdapter.class.getSimpleName();
    public static final java.lang.String FORCE_DOWNLOAD_FAVORITES = "force_download_favorites";
    // Global variables
    // Define a variable to contain a content resolver instance
    private ContentResolver mContentResolver;

    /**
     * Set up the sync adapter
     */
    public SyncAdapter(Context context, boolean autoInitialize) {
        super(context, autoInitialize);
        /*
         * If your app uses a content resolver, get an instance of it
         * from the incoming Context
         */
        mContentResolver = context.getContentResolver();

    }
    /**
     * Set up the sync adapter. This form of the
     * constructor maintains compatibility with Android 3.0
     * and later platform versions
     */
    public SyncAdapter(
            Context context,
            boolean autoInitialize,
            boolean allowParallelSyncs) {
        super(context, autoInitialize, allowParallelSyncs);
        /*
         * If your app uses a content resolver, get an instance of it
         * from the incoming Context
         */
        mContentResolver = context.getContentResolver();
    }

    @Override
    public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
        SettingsUtil accountSettings = new SettingsUtil(getContext().getApplicationContext(), MainActivity.PREFERENCE_NAME);
        getContext().getApplicationInfo().loadDescription(getContext().getPackageManager());
        boolean forceDownloadFavorites = extras.getBoolean(FORCE_DOWNLOAD_FAVORITES,false);
        SyncUtils utils = new SyncUtils(getContext());
        String startSync = "Sync starts for ";
        String endSync = "Sync end for ";
        try{
            Log.d(TAG,startSync + "rooms");
            utils.syncRooms(provider);
            Log.d(TAG,endSync + "rooms");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "tags");
            utils.syncTags(provider);
            Log.d(TAG, endSync + "tags");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "speakers");
            utils.syncSpeakers(provider);
            Log.d(TAG, endSync + "speakers");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "talks");
            String id = accountSettings.getStringPreference(MainActivity.PREFERENCE_ACCOUNT);
            Log.d(TAG,"User id:"+id);
            utils.syncTalks(provider,id, forceDownloadFavorites);
            Log.d(TAG, endSync + "talks");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "talkTags");
            utils.syncTalkTags(provider);
            Log.d(TAG, endSync + "talkTags");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "talkSpeakers");
            utils.syncTalkSpeakers(provider);
            Log.d(TAG, endSync + "talkSpeakers");
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            Log.d(TAG,startSync + "news");
            utils.syncNews(provider);
            Log.d(TAG, endSync + "news");
        }catch(Exception e){
            e.printStackTrace();
        }

        /*Intent intent = new Intent(getContext(), MainActivity.class);
        intent.setAction(MainActivity.LOAD_SYNC);
        getContext().startActivity(intent);*/

        Intent intent = new Intent();
        intent.setAction(SYNC_READY_BROADCAST);
        //LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
        getContext().sendBroadcast(intent);
        Log.d(TAG,"Sync ready in adapter");
    }
}




Java Source Code List

be.ana.nmct.multimania.ApiTest.java
be.ana.nmct.multimania.ApplicationTest.java
be.ana.nmct.multimania.CalendarTest.java
be.ana.nmct.multimania.DbTest.java
be.ana.nmct.multimania.Import.java
be.ana.nmct.multimania.NotificationImport.java
be.ana.nmct.multimania.ProviderTest.java
be.ana.nmct.multimania.SyncTest.java
be.ana.nmct.multimania.data.ApiActions.java
be.ana.nmct.multimania.data.DbHelper.java
be.ana.nmct.multimania.data.GsonLoader.java
be.ana.nmct.multimania.data.MultimaniaContract.java
be.ana.nmct.multimania.data.MultimaniaProvider.java
be.ana.nmct.multimania.data.NewsItemLoader.java
be.ana.nmct.multimania.data.RoomLoader.java
be.ana.nmct.multimania.data.TagLoader.java
be.ana.nmct.multimania.data.TalkLoader.java
be.ana.nmct.multimania.model.IData.java
be.ana.nmct.multimania.model.NewsItem.java
be.ana.nmct.multimania.model.Room.java
be.ana.nmct.multimania.model.Speaker.java
be.ana.nmct.multimania.model.Tag.java
be.ana.nmct.multimania.model.TalkSpeaker.java
be.ana.nmct.multimania.model.TalkTag.java
be.ana.nmct.multimania.model.Talk.java
be.ana.nmct.multimania.model.User.java
be.ana.nmct.multimania.service.AuthenticatorService.java
be.ana.nmct.multimania.service.Authenticator.java
be.ana.nmct.multimania.service.BootListener.java
be.ana.nmct.multimania.service.NotificationReceiver.java
be.ana.nmct.multimania.service.NotificationSender.java
be.ana.nmct.multimania.service.SyncAdapter.java
be.ana.nmct.multimania.service.SyncService.java
be.ana.nmct.multimania.ui.AboutFragment.java
be.ana.nmct.multimania.ui.LoadActivity.java
be.ana.nmct.multimania.ui.MainActivity.java
be.ana.nmct.multimania.ui.MapFragment.java
be.ana.nmct.multimania.ui.MyScheduleFragment.java
be.ana.nmct.multimania.ui.MySchedulesFragment.java
be.ana.nmct.multimania.ui.NavigationDrawerFragment.java
be.ana.nmct.multimania.ui.NewsFragment.java
be.ana.nmct.multimania.ui.NewsItemActivity.java
be.ana.nmct.multimania.ui.NewsItemFragment.java
be.ana.nmct.multimania.ui.ScheduleFragment.java
be.ana.nmct.multimania.ui.SchedulesFragment.java
be.ana.nmct.multimania.ui.SettingsFragment.java
be.ana.nmct.multimania.ui.SuggestionFragment.java
be.ana.nmct.multimania.ui.TalkActivity.java
be.ana.nmct.multimania.ui.TalkFragment.java
be.ana.nmct.multimania.utils.GoogleCalUtil.java
be.ana.nmct.multimania.utils.SettingsHelper.java
be.ana.nmct.multimania.utils.SettingsUtil.java
be.ana.nmct.multimania.utils.SyncUtils.java
be.ana.nmct.multimania.utils.Utility.java
be.ana.nmct.multimania.vm.NavigationItem.java
be.ana.nmct.multimania.vm.ScheduleTalkVm.java
be.ana.nmct.multimania.widget.StaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.BulletStaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.HeaderFooterListAdapter.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompatIcs.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompat.java