Example usage for android.content ContentResolver isSyncActive

List of usage examples for android.content ContentResolver isSyncActive

Introduction

In this page you can find the example usage for android.content ContentResolver isSyncActive.

Prototype

public static boolean isSyncActive(Account account, String authority) 

Source Link

Document

Returns true if there is currently a sync operation for the given account or authority actively being processed.

Usage

From source file:edu.mit.mobile.android.locast.ver2.itineraries.ItineraryDetail.java

@Override
protected void onResume() {
    mFirstLoadSync = true;//ww w .j ava 2s. co m
    super.onResume();
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override
        public void onStatusChanged(int which) {
            final Account a = Authenticator.getFirstAccount(ItineraryDetail.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress
    final Account a = Authenticator.getFirstAccount(ItineraryDetail.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }
}

From source file:eu.masconsult.bgbanking.activity.HomeActivity.java

boolean isSyncActive() {
    for (Bank bank : Bank.values()) {
        for (Account account : accountManager.getAccountsByType(bank.getAccountType(this))) {
            if (ContentResolver.isSyncActive(account, BankingContract.AUTHORITY)) {
                Log.v(TAG, bank + " is syncing");
                return true;
            }/*from   www  .  j a  v  a  2 s .  com*/
        }
    }
    Log.v(TAG, "nothing is syncing");
    return false;
}

From source file:edu.mit.mobile.android.locast.ver2.casts.LocatableListWithMap.java

@Override
protected void onResume() {
    super.onResume();
    mMyLocationOverlay.enableMyLocation();
    mExpeditedSync = true;/*from  w  w w .ja  va  2s  .  c o  m*/
    mSyncHandle = ContentResolver.addStatusChangeListener(0xff, new SyncStatusObserver() {

        @Override
        public void onStatusChanged(int which) {
            Account a = Authenticator.getFirstAccount(LocatableListWithMap.this);
            if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
                    && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
                Log.d(TAG, "Sync finished, should refresh naw!!");
                mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);

            } else {
                Log.d(TAG, "Sync Active or Pending!!");
                mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
            }
        }
    });
    //check if synch is in progress 
    Account a = Authenticator.getFirstAccount(LocatableListWithMap.this);
    if (!ContentResolver.isSyncActive(a, MediaProvider.AUTHORITY)
            && !ContentResolver.isSyncPending(a, MediaProvider.AUTHORITY)) {
        Log.d(TAG, "Sync finished, should refresh naw!!");
        mHandler.sendEmptyMessage(MSG_SET_NOT_REFRESHING);
    } else {
        Log.d(TAG, "Sync Active or Pending!!");
        mHandler.sendEmptyMessage(MSG_SET_REFRESHING);
    }
}

From source file:de.stkl.gbgvertretungsplan.fragments.MainFragment.java

public void actionRefresh() {
    // only if neither pending nor active
    if (!ContentResolver.isSyncActive(((MainActivity) getActivity()).mDefaultAccount,
            getString(Account.CONTENT_AUTHORITY))
            && !ContentResolver.isSyncPending(((MainActivity) getActivity()).mDefaultAccount,
                    getString(Account.CONTENT_AUTHORITY))) {
        Bundle settingsBundle = new Bundle();
        settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); // this is a manual sync
        settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); // start immediately
        ContentResolver.requestSync(Authenticator.getDefaultAccount(getActivity()),
                getString(Account.CONTENT_AUTHORITY), settingsBundle);
    }/*from ww w .  j a v  a 2s  .  c om*/
}

From source file:org.alfresco.mobile.android.application.fragments.sync.SyncFragment.java

private boolean isSyncActive() {
    try {/*from w  ww  .  j  a v  a  2  s . c  o  m*/
        return ContentResolver.isSyncActive(AlfrescoAccountManager.getInstance(getActivity()).getAndroidAccount(
                SessionUtils.getAccount(getActivity()).getId()), SyncContentProvider.AUTHORITY);
    } catch (Exception e) {
        return false;
    }
}

From source file:com.odoo.MainActivity.java

/**
 * Sets the auto sync./*  w w w . j av  a 2  s  . c o m*/
 * 
 * @param authority
 *            the authority
 * @param isON
 *            the is on
 */
public void setAutoSync(String authority, boolean isON) {
    try {
        Account account = OdooAccountManager.getAccount(this, OUser.current(mContext).getAndroidName());
        if (!ContentResolver.isSyncActive(account, authority)) {
            ContentResolver.setSyncAutomatically(account, authority, isON);
        }
    } catch (NullPointerException eNull) {

    }
}

From source file:com.openerp.MainActivity.java

/**
 * Sets the auto sync./*from  ww  w .  ja va2 s  .  c o m*/
 * 
 * @param authority
 *            the authority
 * @param isON
 *            the is on
 */
public void setAutoSync(String authority, boolean isON) {
    try {
        Account account = OpenERPAccountManager.getAccount(this, OEUser.current(mContext).getAndroidName());
        if (!ContentResolver.isSyncActive(account, authority)) {
            ContentResolver.setSyncAutomatically(account, authority, isON);
        }
    } catch (NullPointerException eNull) {

    }
}

From source file:org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.java

/**
 * Is a sync currently in progress?/*from w w  w.  j a v a2  s .  c  o  m*/
 *
 * @return true if Android is currently syncing the underlying Android Account.
 */
public boolean isCurrentlySyncing() {
    boolean active = false;
    for (String authority : AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.keySet()) {
        active |= ContentResolver.isSyncActive(account, authority);
    }
    return active;
}

From source file:com.nononsenseapps.notepad.MainActivity.java

private void requestSync(String accountName) {
    if (accountName != null && !"".equals(accountName)) {
        Account account = SyncPrefs.getAccount(AccountManager.get(this), accountName);
        // Don't start a new sync if one is already going
        if (!ContentResolver.isSyncActive(account, NotePad.AUTHORITY)) {
            Bundle options = new Bundle();
            // This will force a sync regardless of what the setting is
            // in accounts manager. Only use it here where the user has
            // manually desired a sync to happen NOW.
            options.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            ContentResolver.requestSync(account, NotePad.AUTHORITY, options);
        }//from   www .j  a  v  a  2 s.c  o  m
    }
}