Java Code Examples for android.content.ContentResolver#addStatusChangeListener()

The following examples show how to use android.content.ContentResolver#addStatusChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactListFragment.java    From haxsync with GNU General Public License v2.0 6 votes vote down vote up
@Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      
      setEmptyText(getActivity().getString(R.string.no_contacts));
      setHasOptionsMenu(true);


String[] columns = new String[] {RawContacts.DISPLAY_NAME_PRIMARY};
int[] to = new int[] { android.R.id.text1 };
mAdapter = new ContactsCursorAdapter(
        getActivity(),
        android.R.layout.simple_list_item_activated_1, 
        null,
        columns,
        to,
        0);
setListAdapter(mAdapter);
showSyncIndicator();
   mContentProviderHandle = ContentResolver.addStatusChangeListener(
             ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, this);

  }
 
Example 2
Source File: SyncTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public void setListening(boolean listening) {
    if (listening && mEnabled) {
        mSyncHandle = ContentResolver.addStatusChangeListener(
            ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, mSyncObserver);
        getSyncState();
        if (DEBUG) log(getKey() + ": sync status listener registered");
    } else if (mSyncHandle != null){
        ContentResolver.removeStatusChangeListener(mSyncHandle);
        mSyncHandle = null;
        if (DEBUG) log(getKey() + ": sync status listener unregistered");
    }
}
 
Example 3
Source File: BaseFragment.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (OUser.current(getActivity()) == null)
        return;
    if (mSyncStatusObserverListener != null) {
        mSyncStatusObserver.onStatusChanged(0);
        int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING
                | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
        mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask,
                mSyncStatusObserver);
    }
    parent().registerReceiver(syncFinishReceiver,
            new IntentFilter(ISyncFinishReceiver.SYNC_FINISH));
}
 
Example 4
Source File: EntryListFragment.java    From android-BasicSyncAdapter with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: BaseFragment.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (OUser.current(getActivity()) == null)
        return;
    if (mSyncStatusObserverListener != null) {
        mSyncStatusObserver.onStatusChanged(0);
        int mask = ContentResolver.SYNC_OBSERVER_TYPE_PENDING
                | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE;
        mSyncObserverHandle = ContentResolver.addStatusChangeListener(mask,
                mSyncStatusObserver);
    }
    parent().registerReceiver(syncFinishReceiver,
            new IntentFilter(ISyncFinishReceiver.SYNC_FINISH));
}
 
Example 6
Source File: RunConditionMonitor.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
public RunConditionMonitor(Context context, OnRunConditionChangedListener listener) {
    Log.v(TAG, "Created new instance");
    ((SyncthingApp) context.getApplicationContext()).component().inject(this);
    mContext = context;
    mOnRunConditionChangedListener = listener;

    /**
     * Register broadcast receivers.
     */
    // NetworkReceiver
    ReceiverManager.registerReceiver(mContext, new NetworkReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    // BatteryReceiver
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    ReceiverManager.registerReceiver(mContext, new BatteryReceiver(), filter);

    // PowerSaveModeChangedReceiver
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ReceiverManager.registerReceiver(mContext,
                new PowerSaveModeChangedReceiver(),
                new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
    }

    // SyncStatusObserver to monitor android's "AutoSync" quick toggle.
    mSyncStatusObserverHandle = ContentResolver.addStatusChangeListener(
            ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, mSyncStatusObserver);

    // Initially determine if syncthing should run under current circumstances.
    updateShouldRunDecision();
}
 
Example 7
Source File: ContactListFragment.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onResume() {
     super.onResume();
     //hideIfSyncing();
     mContentProviderHandle = ContentResolver.addStatusChangeListener(
         ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, this);
   }
 
Example 8
Source File: AccountSnippet.java    From mobly-bundled-snippets with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a Google account to the device.
 *
 * @param username Username of the account to add (including @gmail.com).
 * @param password Password of the account to add.
 */
@Rpc(
        description =
                "Add a Google (GMail) account to the device, with account data sync disabled.")
public void addAccount(String username, String password)
        throws AccountSnippetException, AccountsException, IOException {
    // Check for existing account. If we try to re-add an existing account, Android throws an
    // exception that says "Account does not exist or not visible. Maybe change pwd?" which is
    // a little hard to understand.
    if (listAccounts().contains(username)) {
        throw new AccountSnippetException(
                "Account " + username + " already exists on the device");
    }
    Bundle addAccountOptions = new Bundle();
    addAccountOptions.putString("username", username);
    addAccountOptions.putString("password", password);
    AccountManagerFuture<Bundle> future =
            mAccountManager.addAccount(
                    GOOGLE_ACCOUNT_TYPE,
                    AUTH_TOKEN_TYPE,
                    null /* requiredFeatures */,
                    addAccountOptions,
                    null /* activity */,
                    null /* authCallback */,
                    null /* handler */);
    Bundle result = future.getResult();
    if (result.containsKey(AccountManager.KEY_ERROR_CODE)) {
        throw new AccountSnippetException(
                String.format(
                        Locale.US,
                        "Failed to add account due to code %d: %s",
                        result.getInt(AccountManager.KEY_ERROR_CODE),
                        result.getString(AccountManager.KEY_ERROR_MESSAGE)));
    }

    // Disable sync to avoid test flakiness as accounts fetch additional data.
    // It takes a while for all sync adapters to be populated, so register for broadcasts when
    // sync is starting and disable them there.
    // NOTE: this listener is NOT unregistered because several sync requests for the new account
    // will come in over time.
    Account account = new Account(username, GOOGLE_ACCOUNT_TYPE);
    Object handle =
            ContentResolver.addStatusChangeListener(
                    ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE
                            | ContentResolver.SYNC_OBSERVER_TYPE_PENDING,
                    which -> {
                        for (SyncAdapterType adapter : ContentResolver.getSyncAdapterTypes()) {
                            // Ignore non-Google account types.
                            if (!adapter.accountType.equals(GOOGLE_ACCOUNT_TYPE)) {
                                continue;
                            }
                            // If a content provider is not whitelisted, then disable it.
                            // Because startSync and stopSync synchronously update the whitelist
                            // and sync settings, writelock both the whitelist check and the
                            // call to sync together.
                            mLock.writeLock().lock();
                            try {
                                if (!isAdapterWhitelisted(username, adapter.authority)) {
                                    updateSync(account, adapter.authority, false /* sync */);
                                }
                            } finally {
                                mLock.writeLock().unlock();
                            }
                        }
                    });
    mSyncStatusObserverHandles.add(handle);
}
 
Example 9
Source File: SystemSyncContentResolverDelegate.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public Object addStatusChangeListener(int mask, SyncStatusObserver callback) {
    return ContentResolver.addStatusChangeListener(mask, callback);
}
 
Example 10
Source File: InternalApplicationBootstrapper.java    From android-sdk with MIT License 4 votes vote down vote up
public InternalApplicationBootstrapper(Transport transport, ServiceScheduler scheduler, HandlerManager handlerManager,
                                       Clock clk, BluetoothPlatform btPlatform, ResolverConfiguration resolverConfiguration) {
    super(scheduler);
    SensorbergSdk.getComponent().inject(this);

    geofenceAvailable = (geofenceManager != null);

    this.transport = transport;
    transport.setProximityUUIDUpdateHandler(this);

    if (geofenceAvailable) {
        geofenceManager.addListener(this);
    }

    settingsManager.setSettingsUpdateCallback(settingsUpdateCallbackListener);
    settingsManager.setMessageDelayWindowLengthListener((MessageDelayWindowLengthListener) scheduler);
    clock = clk;
    bluetoothPlatform = btPlatform;

    attributes = loadAttributes();

    beaconActionHistoryPublisher.setResolverListener(resolverListener);

    scanner = new Scanner(settingsManager, settingsManager.isShouldRestoreBeaconStates(), clock, fileManager, scheduler, handlerManager,
            btPlatform);
    resolver = new Resolver(resolverConfiguration, handlerManager, transport, attributes);
    resolver.setListener(resolverListener);

    scanner.addScannerListener(this);


    serviceScheduler.restorePendingIntents();

    ScannerBroadcastReceiver.setManifestReceiverEnabled(true, context);
    GenericBroadcastReceiver.setManifestReceiverEnabled(true, context);

    setUpAlarmsForSettings();
    setUpAlarmForBeaconActionHistoryPublisher();
    updateAlarmsForActionLayoutFetch();

    //cache the current network state
    NetworkInfoBroadcastReceiver.triggerListenerWithCurrentState(context);
    ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this);
}
 
Example 11
Source File: SystemSyncContentResolverDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Object addStatusChangeListener(int mask, SyncStatusObserver callback) {
    return ContentResolver.addStatusChangeListener(mask, callback);
}
 
Example 12
Source File: SystemSyncContentResolverDelegate.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Object addStatusChangeListener(int mask, SyncStatusObserver callback) {
    return ContentResolver.addStatusChangeListener(mask, callback);
}