List of usage examples for android.database MergeCursor registerContentObserver
@Override public void registerContentObserver(ContentObserver observer)
From source file:com.abcvoipsip.ui.favorites.FavLoader.java
@Override public Cursor loadInBackground() { // First of all, get all active accounts ArrayList<SipProfile> accounts = SipProfile.getAllProfiles(getContext(), true); Cursor[] cursorsToMerge = new Cursor[2 * accounts.size()]; int i = 0;//from w w w.j av a 2 s.c o m for (SipProfile acc : accounts) { cursorsToMerge[i++] = createHeaderCursorFor(acc); cursorsToMerge[i++] = createContentCursorFor(acc); } getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver); if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); return mg; } else { return null; } }
From source file:com.csipsimple.ui.favorites.FavLoader.java
@Override public Cursor loadInBackground() { // First of all, get all active accounts ArrayList<SipProfile> accounts = SipProfile.getAllProfiles(getContext(), true, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD, SipProfile.FIELD_PRIORITY, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED, SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY }); Cursor[] cursorsToMerge = new Cursor[2 * accounts.size()]; int i = 0;/* ww w .j av a2s . c o m*/ for (SipProfile acc : accounts) { cursorsToMerge[i++] = createHeaderCursorFor(acc); cursorsToMerge[i++] = createContentCursorFor(acc); } getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver); if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); return mg; } else { return null; } }
From source file:com.csipsimple.ui.account.AccountsLoader.java
@Override public Cursor loadInBackground() { // First register for status updates if (loadStatus) { getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver);/*from w w w .ja v a 2s.co m*/ } ArrayList<FilteredProfile> prefinalAccounts = new ArrayList<FilteredProfile>(); // Get all sip profiles ArrayList<SipProfile> accounts; PreferencesProviderWrapper prefsWrapper = new PreferencesProviderWrapper(getContext()); if (onlyActive && !prefsWrapper.isValidConnectionForOutgoing()) { accounts = new ArrayList<SipProfile>(); } else { accounts = SipProfile.getAllProfiles(getContext(), onlyActive, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD }); } // And all external call handlers Map<String, String> externalHandlers; if (loadCallHandlerPlugins) { externalHandlers = CallHandlerPlugin.getAvailableCallHandlers(getContext()); } else { externalHandlers = new HashMap<String, String>(); } if (TextUtils.isEmpty(numberToCall)) { // In case of empty number to call, just add everything without any other question for (SipProfile acc : accounts) { prefinalAccounts.add(new FilteredProfile(acc, false)); } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), false)); } } else { // If there is a number to call, add only those callable, and flag must call entries // Note that we keep processing all call handlers voluntarily cause we may encounter a sip account that doesn't register // But is in force call mode for (SipProfile acc : accounts) { if (Filter.isCallableNumber(getContext(), acc.id, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), acc.id, numberToCall); prefinalAccounts.add(new FilteredProfile(acc, forceCall)); } } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { long accId = CallHandlerPlugin.getAccountIdForCallHandler(getContext(), extEnt.getKey()); if (Filter.isCallableNumber(getContext(), accId, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), accId, numberToCall); prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), forceCall)); if (forceCall) { break; } } } } // Build final cursor based on final filtered accounts Cursor[] cursorsToMerge = new Cursor[prefinalAccounts.size()]; int i = 0; for (FilteredProfile acc : prefinalAccounts) { cursorsToMerge[i++] = createCursorForAccount(acc); } if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); finalAccounts = prefinalAccounts; return mg; } else { finalAccounts = prefinalAccounts; return null; } }
From source file:com.fututel.ui.account.AccountsLoader.java
@Override public Cursor loadInBackground() { // First register for status updates if (loadStatus) { getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver);//from w w w . ja v a 2 s .c om } ArrayList<FilteredProfile> prefinalAccounts = new ArrayList<FilteredProfile>(); // Get all sip profiles ArrayList<SipProfile> accounts; PreferencesProviderWrapper prefsWrapper = new PreferencesProviderWrapper(getContext()); if (onlyActive && !prefsWrapper.isValidConnectionForOutgoing()) { accounts = new ArrayList<SipProfile>(); } else { accounts = SipProfile.getAllProfiles(getContext(), onlyActive, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD }); } // And all external call handlers Map<String, String> externalHandlers; if (loadCallHandlerPlugins) { externalHandlers = CallHandlerPlugin.getAvailableCallHandlers(getContext()); } else { externalHandlers = new HashMap<String, String>(); } if (TextUtils.isEmpty(numberToCall)) { // In case of empty number to call, just add everything without any other question for (SipProfile acc : accounts) { prefinalAccounts.add(new FilteredProfile(acc, false)); } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), false)); } } else { // If there is a number to call, add only those callable, and flag must call entries // If one must call entry is found per group, just stop looping, and don't add other from the group. // Note that we keep processing external call handlers voluntarily cause we may encounter a sip account that doesn't register // But is in force call mode for (SipProfile acc : accounts) { if (Filter.isCallableNumber(getContext(), acc.id, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), acc.id, numberToCall); prefinalAccounts.add(new FilteredProfile(acc, forceCall)); if (forceCall) { break; } } } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { long accId = CallHandlerPlugin.getAccountIdForCallHandler(getContext(), extEnt.getKey()); if (Filter.isCallableNumber(getContext(), accId, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), accId, numberToCall); prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), forceCall)); if (forceCall) { break; } } } } // Build final cursor based on final filtered accounts Cursor[] cursorsToMerge = new Cursor[prefinalAccounts.size()]; int i = 0; for (FilteredProfile acc : prefinalAccounts) { cursorsToMerge[i++] = createCursorForAccount(acc); } if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); finalAccounts = prefinalAccounts; return mg; } else { finalAccounts = prefinalAccounts; return null; } }