List of usage examples for android.content ContentResolver notifyChange
public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer)
From source file:mobisocial.musubi.service.AppUpdaterService.java
@Override public void onCreate() { mDatabaseSource = App.getDatabaseSource(this); mThread = new HandlerThread("AppManifests"); mThread.setPriority(Thread.MIN_PRIORITY); mThread.start();/*from w w w.j ava 2 s . c om*/ mAppManager = new AppManager(mDatabaseSource); mUpdateHandler = new Handler(mThread.getLooper()); ContentResolver resolver = getContentResolver(); resolver.registerContentObserver(MusubiService.UPDATE_APP_MANIFESTS, false, new UpdateApps(mUpdateHandler)); //kick it off once per boot resolver.notifyChange(MusubiService.UPDATE_APP_MANIFESTS, null); Log.w(TAG, "service is now running"); }
From source file:com.actinarium.nagbox.service.NagboxService.java
/** * Unset "not seen" flag from the task with provided ID or all unseen tasks (depending on whether a summary * notification or an individual one from the stack was dismissed) * * @param id ID of the task that's "seen". Pass {@link Task#NO_ID} to "see" all tasks *//*from ww w . j av a 2 s. com*/ private void handleOnNotificationDismissed(long id) { Task[] tasksToDismiss = NagboxDbOps.getTasksToDismiss(mDatabase, id); if (tasksToDismiss.length == 0) { // Well, nothing to do. Maybe the user has deactivated the tasks before dismissing the notification return; } NagboxDbOps.Transaction transaction = NagboxDbOps.startTransaction(mDatabase); for (Task task : tasksToDismiss) { task.setIsSeen(true); transaction.updateTaskStatus(task); } boolean isSuccess = transaction.commit(); if (!isSuccess) { Log.e(TAG, "Couldn't unset the 'not seen' flag from tasks"); } else { // Notify all affected task items final ContentResolver contentResolver = getContentResolver(); for (Task task : tasksToDismiss) { contentResolver.notifyChange(TasksTable.getUriForItem(task.id), null); } } }
From source file:com.actinarium.nagbox.service.NagboxService.java
private void handleOnAlarmFired() { final long now = System.currentTimeMillis(); Task[] tasksToRemind = NagboxDbOps.getTasksToRemind(mDatabase, now); if (tasksToRemind.length == 0) { Log.i(TAG, "Alarm fired/check requested, but there was nothing to remind about"); return;// ww w . java2 s. c o m } NotificationHelper.fireNotification(this, tasksToRemind); // Update the status and the time of the next fire where needed. List<Task> tasksToUpdate = new ArrayList<>(tasksToRemind.length); for (Task task : tasksToRemind) { boolean isModified = false; if (task.isSeen()) { task.setIsSeen(false); isModified = true; } // Using the loop because the alarm might've fired long ago (e.g. before system reboot), // so we need to make sure that nextFireAt is indeed in the future while (task.nextFireAt <= now) { task.nextFireAt += task.interval * DateUtils.MINUTE_IN_MILLIS; isModified = true; } if (isModified) { tasksToUpdate.add(task); } } final int updateSize = tasksToUpdate.size(); if (updateSize == 0) { Log.w(TAG, "Strangely enough, there was nothing to update when alarm fired"); rescheduleAlarm(); return; } // Otherwise update the tasks that need it NagboxDbOps.Transaction transaction = NagboxDbOps.startTransaction(mDatabase); for (int i = 0; i < updateSize; i++) { final Task task = tasksToUpdate.get(i); transaction.updateTaskStatus(task); } boolean isSuccess = transaction.commit(); if (!isSuccess) { Log.e(TAG, "Couldn't update status of the tasks when alarm fired"); } else { // Notify all affected task items final ContentResolver contentResolver = getContentResolver(); for (int i = 0; i < updateSize; i++) { contentResolver.notifyChange(TasksTable.getUriForItem(tasksToUpdate.get(i).id), null); } } // Finally, schedule the alarm to fire the next time it's ought to fire rescheduleAlarm(); }
From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java
/** * Adds an account to the local database. Must not be called on the main thread. */// w ww . java 2s. com public static MMyAccount addAccountToDatabase(Activity activity, AccountDetails accountDetails) { SQLiteOpenHelper databaseSource = App.getDatabaseSource(activity); IdentitiesManager im = new IdentitiesManager(databaseSource); MyAccountManager am = new MyAccountManager(databaseSource); DeviceManager dm = new DeviceManager(databaseSource); FeedManager fm = new FeedManager(databaseSource); String accountType = accountDetails.accountType; String accountName = accountDetails.accountName; String principal = accountDetails.principal; boolean owned = accountDetails.owned; IBIdentity ibid; if (accountType.equals(ACCOUNT_TYPE_GOOGLE)) { ibid = new IBIdentity(Authority.Email, principal, 0); } else if (accountType.equals(ACCOUNT_TYPE_FACEBOOK)) { ibid = new IBIdentity(Authority.Facebook, principal, 0); } else if (accountType.equals(ACCOUNT_TYPE_PHONE)) { ibid = new IBIdentity(Authority.PhoneNumber, principal, 0); } else { throw new RuntimeException("Unsupported account type " + accountType); } SQLiteDatabase db = databaseSource.getWritableDatabase(); db.beginTransaction(); try { // Ensure identity in the database MIdentity id = im.getIdentityForIBHashedIdentity(ibid); //don't repeatedly add profile broadcast groups or do any //of this processing if the account is already owned. if (id != null && id.owned_) { return null; } MIdentity original = im.getOwnedIdentities().get(0); //if this identity wasnt already in the contact book, we need to update it if (id == null) { id = new MIdentity(); populateMyNewIdentity(activity, principal, im, ibid, id, original, owned); im.insertIdentity(id); } else { populateMyNewIdentity(activity, principal, im, ibid, id, original, owned); im.updateIdentity(id); } im.updateMyProfileName(activity, id.musubiName_, false); im.updateMyProfileThumbnail(activity, id.musubiThumbnail_, false); // Ensure account entry exists MMyAccount account = am.lookupAccount(accountName, accountType); if (account == null) { //create the account account = new MMyAccount(); account.accountName_ = accountName; account.accountType_ = accountType; account.identityId_ = id.id_; am.insertAccount(account); } else { account.identityId_ = id.id_; am.updateAccount(account); } // For accounts linked to identities that are not yet owned, // skip further initialization if (owned) { MDevice dev = dm.getDeviceForName(id.id_, dm.getLocalDeviceName()); // Ensure device exists if (dev == null) { dev = new MDevice(); dev.deviceName_ = dm.getLocalDeviceName(); dev.identityId_ = id.id_; dm.insertDevice(dev); } //this feed will contain all members who should receive //a profile for the account because of a friend introduction MFeed provisional = new MFeed(); provisional.name_ = MFeed.PROVISONAL_WHITELIST_FEED_NAME; provisional.type_ = MFeed.FeedType.ASYMMETRIC; fm.insertFeed(provisional); //XXX //TODO: in other places in the code, we should be pruning the //provisional whitelist feed as people become whitelisted.. //these get inserted for owned identities to allow profile //broadcasts to go out MMyAccount provAccount = new MMyAccount(); provAccount.accountName_ = MMyAccount.PROVISIONAL_WHITELIST_ACCOUNT; provAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE; provAccount.identityId_ = id.id_; provAccount.feedId_ = provisional.id_; am.insertAccount(provAccount); //this feed will contain all members who should receive //a profile for the account because they are whitelisted //and contacted you on one of your accounts. MFeed accountBroadcastFeed = new MFeed(); accountBroadcastFeed.name_ = MFeed.LOCAL_WHITELIST_FEED_NAME; accountBroadcastFeed.type_ = MFeed.FeedType.ASYMMETRIC; fm.insertFeed(accountBroadcastFeed); MMyAccount localAccount = new MMyAccount(); localAccount.accountName_ = MMyAccount.LOCAL_WHITELIST_ACCOUNT; localAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE; localAccount.identityId_ = id.id_; localAccount.feedId_ = accountBroadcastFeed.id_; am.insertAccount(localAccount); db.setTransactionSuccessful(); ContentResolver resolver = activity.getContentResolver(); // Notify interested services (identity available makes AMQP wake up for example) resolver.notifyChange(MusubiService.OWNED_IDENTITY_AVAILABLE, null); resolver.notifyChange(MusubiService.MY_PROFILE_UPDATED, null); // Makes key update wake up resolver.notifyChange(MusubiService.AUTH_TOKEN_REFRESH, null); WizardStepHandler.accomplishTask(activity, WizardStepHandler.TASK_LINK_ACCOUNT); App.getUsageMetrics(activity).report(MusubiMetrics.ACCOUNT_CONNECTED, account.accountType_); } else { db.setTransactionSuccessful(); } return account; } finally { db.endTransaction(); } }
From source file:com.akop.bach.parser.PsnParser.java
public void createAccount(BasicAccount account, ContentValues cv) { // Add profile to database ContentResolver cr = mContext.getContentResolver(); cr.insert(Profiles.CONTENT_URI, cv); cr.notifyChange(Profiles.CONTENT_URI, null); PsnAccount psnAccount = (PsnAccount) account; // Save changes to preferences psnAccount.setOnlineId(cv.getAsString(Profiles.ONLINE_ID)); psnAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL)); psnAccount.setLastSummaryUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); }
From source file:com.chatwing.whitelabel.managers.CommunicationModeManager.java
protected boolean updateChatBoxUnreadCountInDB(int chatBoxId, int unreadCount) { Uri uri = ChatWingContentProvider.getChatBoxWithIdUri(chatBoxId); ContentValues contentValues = new ContentValues(); contentValues.put(ChatBoxTable.UNREAD_COUNT, unreadCount); ContentResolver contentResolver = mActivityDelegate.getActivity().getContentResolver(); int updated = contentResolver.update(uri, contentValues, null, null); if (updated == 1) { mBus.post(new ChatBoxUnreadCountChangedEvent(chatBoxId)); contentResolver.notifyChange(ChatWingContentProvider.getSyncedBookmarksUri(), null); contentResolver.notifyChange(ChatWingContentProvider.getAggregatedCategoriesUri(), null); contentResolver.notifyChange(ChatWingContentProvider.getCategorizedChatBoxesUri(), null); return true; } else {/*from w ww . j ava2 s.c o m*/ LogUtils.e("Failed to update unread count."); return false; } }
From source file:com.chatwingsdk.managers.CommunicationModeManager.java
protected boolean updateChatBoxUnreadCountInDB(int chatBoxId, int unreadCount) { Uri uri = ChatWingContentProvider.getChatBoxWithIdUri(chatBoxId); ContentValues contentValues = new ContentValues(); contentValues.put(ChatBoxTable.UNREAD_COUNT, unreadCount); ContentResolver contentResolver = mActivityDelegate.getActivity().getContentResolver(); int updated = contentResolver.update(uri, contentValues, null, null); if (updated == 1) { LogUtils.v("Update unread count. New Unread count: " + unreadCount); mBus.post(new ChatBoxUnreadCountChangedEvent(chatBoxId)); contentResolver.notifyChange(ChatWingContentProvider.getAggregatedCategoriesUri(), null); return true; } else {/*from ww w.j a v a2s .co m*/ LogUtils.e("Failed to update unread count."); return false; } }
From source file:co.nerdart.ourss.fragment.FeedsListFragment.java
private void moveItem(boolean fromIsGroup, boolean toIsGroup, boolean fromIsFeedWithoutGroup, long packedPosTo, int packedGroupPosTo, int flatPosFrom) { ContentValues values = new ContentValues(); ContentResolver cr = getActivity().getContentResolver(); if (fromIsGroup && toIsGroup) { values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } else if (!fromIsGroup && toIsGroup) { values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1); values.putNull(FeedColumns.GROUP_ID); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } else if ((!fromIsGroup && !toIsGroup) || (fromIsFeedWithoutGroup && !toIsGroup)) { int groupPrio = ExpandableListView.getPackedPositionChild(packedPosTo) + 1; values.put(FeedColumns.PRIORITY, groupPrio); int flatGroupPosTo = mListView .getFlatListPosition(ExpandableListView.getPackedPositionForGroup(packedGroupPosTo)); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatGroupPosTo)); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); }/* w ww . j a v a 2 s.c om*/ }
From source file:co.nerdart.ourss.fragment.FeedsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.feed_list_fragment, container, false); mListView = (DragNDropExpandableListView) rootView.findViewById(android.R.id.list); mListAdapter.setExpandableListView(mListView); mListView.setFastScrollEnabled(true); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override/*w w w.j av a2 s. com*/ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { String title = ((TextView) view.findViewById(android.R.id.text1)).getText().toString(); Matcher m = Pattern.compile("(.*) \\([0-9]+\\)$").matcher(title); if (m.matches()) { title = m.group(1); } long feedId = mListView.getItemIdAtPosition(position); ActionMode actionMode; if (view.findViewById(R.id.indicator).getVisibility() == View.VISIBLE) { // This is a group actionMode = getActivity().startActionMode(mGroupActionModeCallback); } else { // This is a feed actionMode = getActivity().startActionMode(mFeedActionModeCallback); } actionMode.setTag(new Pair<Long, String>(feedId, title)); mListAdapter.setSelectedFeed(feedId); return true; } }); mListView.setAdapter(mListAdapter); mListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { mListAdapter.startFeedActivity(id); return false; } }); mListView.setDragNDropListener(new DragNDropListener() { boolean fromHasGroupIndicator = false; @Override public void onStopDrag(View itemView) { } @Override public void onStartDrag(View itemView) { fromHasGroupIndicator = itemView.findViewById(R.id.indicator).getVisibility() == View.VISIBLE; } @Override public void onDrop(final int flatPosFrom, final int flatPosTo) { final boolean fromIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosFrom)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean toIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosTo)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean fromIsFeedWithoutGroup = fromIsGroup && !fromHasGroupIndicator; View toView = mListView.getChildAt(flatPosTo - mListView.getFirstVisiblePosition()); boolean toIsFeedWithoutGroup = toIsGroup && toView.findViewById(R.id.indicator).getVisibility() != View.VISIBLE; final long packedPosTo = mListView.getExpandableListPosition(flatPosTo); final int packedGroupPosTo = ExpandableListView.getPackedPositionGroup(packedPosTo); if ((fromIsFeedWithoutGroup || !fromIsGroup) && toIsGroup && !toIsFeedWithoutGroup) { new AlertDialog.Builder(getActivity()) // .setTitle(R.string.to_group_title) // .setMessage(R.string.to_group_message) // .setPositiveButton(R.string.to_group_into, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ContentValues values = new ContentValues(); values.put(FeedColumns.PRIORITY, 1); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatPosTo)); ContentResolver cr = getActivity().getContentResolver(); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } }).setNegativeButton(R.string.to_group_above, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } }).show(); } else { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } } @Override public void onDrag(int x, int y, ListView listView) { } }); return rootView; }
From source file:net.etuldan.sparss.fragment.EditFeedsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_edit_feed_list, container, false); mListView = (DragNDropExpandableListView) rootView.findViewById(android.R.id.list); mListView.setFastScrollEnabled(true); mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override/* www . j ava2 s . c o m*/ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } }); mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (v.findViewById(R.id.indicator).getVisibility() != View.VISIBLE) { // This is no a real group startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } return false; } }); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ActionBarActivity activity = (ActionBarActivity) getActivity(); if (activity != null) { String title = ((TextView) view.findViewById(android.R.id.text1)).getText().toString(); Matcher m = Pattern.compile("(.*) \\([0-9]+\\)$").matcher(title); if (m.matches()) { title = m.group(1); } long feedId = mListView.getItemIdAtPosition(position); ActionMode actionMode; if (view.findViewById(R.id.indicator).getVisibility() == View.VISIBLE) { // This is a group actionMode = activity.startSupportActionMode(mGroupActionModeCallback); } else { // This is a feed actionMode = activity.startSupportActionMode(mFeedActionModeCallback); } actionMode.setTag(new Pair<>(feedId, title)); mListView.setItemChecked(position, true); } return true; } }); mListView.setAdapter(new FeedsCursorAdapter(getActivity(), FeedColumns.GROUPS_CONTENT_URI)); mListView.setDragNDropListener(new DragNDropListener() { boolean fromHasGroupIndicator = false; @Override public void onStopDrag(View itemView) { } @Override public void onStartDrag(View itemView) { fromHasGroupIndicator = itemView.findViewById(R.id.indicator).getVisibility() == View.VISIBLE; } @Override public void onDrop(final int flatPosFrom, final int flatPosTo) { final boolean fromIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosFrom)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean toIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosTo)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean fromIsFeedWithoutGroup = fromIsGroup && !fromHasGroupIndicator; View toView = mListView.getChildAt(flatPosTo - mListView.getFirstVisiblePosition()); boolean toIsFeedWithoutGroup = toIsGroup && toView.findViewById(R.id.indicator).getVisibility() != View.VISIBLE; final long packedPosTo = mListView.getExpandableListPosition(flatPosTo); final int packedGroupPosTo = ExpandableListView.getPackedPositionGroup(packedPosTo); if ((fromIsFeedWithoutGroup || !fromIsGroup) && toIsGroup && !toIsFeedWithoutGroup) { new AlertDialog.Builder(getActivity()) // .setTitle(R.string.to_group_title) // .setMessage(R.string.to_group_message) // .setPositiveButton(R.string.to_group_into, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ContentValues values = new ContentValues(); values.put(FeedColumns.PRIORITY, 1); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatPosTo)); ContentResolver cr = getActivity().getContentResolver(); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } }).setNegativeButton(R.string.to_group_above, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } }).show(); } else { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } } @Override public void onDrag(int x, int y, ListView listView) { } }); return rootView; }