Example usage for android.content ContentResolver addStatusChangeListener

List of usage examples for android.content ContentResolver addStatusChangeListener

Introduction

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

Prototype

public static Object addStatusChangeListener(int mask, final SyncStatusObserver callback) 

Source Link

Document

Request notifications when the different aspects of the SyncManager change.

Usage

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

@Override
protected void onResume() {
    mFirstLoadSync = true;/*from ww w . j av  a  2 s.  com*/
    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:com.alphabetbloc.accessmrs.ui.user.BaseUserActivity.java

@Override
protected void onResume() {
    mPaused = false;/*from  w  w w  .j a va2s. co  m*/
    super.onResume();
    IntentFilter filter = new IntentFilter(SyncManager.SYNC_MESSAGE);
    LocalBroadcastManager.getInstance(this).registerReceiver(onSyncNotice, filter);
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE,
            this);

    if (RefreshDataService.isSyncActive)
        updateSyncProgress();
    else {
        if (mSyncActiveDialog != null) {
            mSyncActiveDialog.dismiss();
            mSyncActiveDialog = null;
        }
    }
}

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

@Override
protected void onResume() {
    super.onResume();
    mMyLocationOverlay.enableMyLocation();
    mExpeditedSync = true;//from  ww w. j a va 2 s  . 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:com.dogar.geodesic.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    mSyncStatusObserver.onStatusChanged(0);
    // Watch for sync state changes
    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.HomeActivity.java

@Override
protected void onResume() {
    super.onResume();
    mSyncStatusObserver.onStatusChanged(0);

    // Watch for sync state changes
    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);

    // Refresh options menu.  Menu item visibility could be altered by user preferences.
    supportInvalidateOptionsMenu();/*from w ww .j  a  v a2  s .  c o  m*/
}

From source file:com.conferenceengineer.android.iosched.ui.HomeActivity.java

@Override
protected void onResume() {
    super.onResume();
    mSyncStatusObserver.onStatusChanged(0);

    // Watch for sync state changes
    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);

    // Set up conference WiFi AP if requested by user.
    WiFiUtils.installWiFiIfRequested(this);

    // Refresh options menu.  Menu item visibility could be altered by user preferences.
    supportInvalidateOptionsMenu();/*from w w w.j  a va  2 s .  com*/
}

From source file:net.abcdroid.devfest12.ui.HomeActivity.java

@Override
protected void onResume() {
    super.onResume();
    mSyncStatusObserver.onStatusChanged(0);

    // Watch for sync state changes
    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Internal constructor that only performs initial parsing.
 *//*from w w  w.java  2s  .  c  o  m*/
public AccountTypeManagerImpl(Context context) {
    mContext = context;
    mFallbackAccountType = new FallbackAccountType(context);

    mAccountManager = AccountManager.get(mContext);

    mListenerThread = new HandlerThread("AccountChangeListener");
    mListenerThread.start();
    mListenerHandler = new Handler(mListenerThread.getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MESSAGE_LOAD_DATA:
                loadAccountsInBackground();
                break;
            case MESSAGE_PROCESS_BROADCAST_INTENT:
                processBroadcastIntent((Intent) msg.obj);
                break;
            }
        }
    };

    mInvitableAccountTypeCache = new InvitableAccountTypeCache();

    // Request updates when packages or accounts change
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mBroadcastReceiver, sdFilter);

    // Request updates when locale is changed so that the order of each field will
    // be able to be changed on the locale change.
    filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiver(mBroadcastReceiver, filter);

    if (ActivityCompat.checkSelfPermission(mContext,
            Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mAccountManager.addOnAccountsUpdatedListener(this, mListenerHandler, false);

    ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this);

    mListenerHandler.sendEmptyMessage(MESSAGE_LOAD_DATA);
}

From source file:com.battlelancer.seriesguide.ui.ShowsActivity.java

@Override
protected void onResume() {
    super.onResume();

    // prefs might have changed, update menus
    supportInvalidateOptionsMenu();// w w w.  j  a v  a 2s  .c om

    if (Utils.isAmazonVersion()) {
        // update Amazon IAP
        AmazonIapManager.get().activate();
        AmazonIapManager.get().requestUserDataAndPurchaseUpdates();
        AmazonIapManager.get().validateSubscription(this);
    }

    // update next episodes
    TaskManager.getInstance(this).tryNextEpisodeUpdateTask();

    // watch for sync state changes
    mSyncStatusObserver.onStatusChanged(0);
    final int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
    mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask, mSyncStatusObserver);
}

From source file:de.sindzinski.wetter.ForecastDailyFragment.java

@Override
public void onResume() {
    super.onResume();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    sp.registerOnSharedPreferenceChangeListener(this);

    syncObserverHandle = ContentResolver.addStatusChangeListener(
            ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE,
            new MySyncStatusObserver());
}