List of usage examples for android.database ContentObserver ContentObserver
public ContentObserver(Handler handler)
From source file:systems.obscure.client.ContactsListActivity.java
private void initializeContactUpdatesReceiver() { observer = new ContentObserver(null) { @Override//from w w w . j a v a 2 s .c om public void onChange(boolean selfChange) { super.onChange(selfChange); Log.w("ConversationListActivity", "detected android contact data changed, refreshing cache"); // TODO only clear updated recipients from cache // RecipientFactory.clearCache(); // ContactsListActivity.this.runOnUiThread(new Runnable() { // @Override // public void run() { // ((ContactsListFragment)fragment.getListAdapter()).notifyDataSetChanged(); // } // }); } }; getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, observer); }
From source file:org.mariotaku.twidere.fragment.CursorStatusesFragment.java
@Override public void onStart() { super.onStart(); final ContentResolver cr = getContentResolver(); mContentObserver = new ContentObserver(new Handler()) { @Override// w w w . j a v a 2 s. com public void onChange(boolean selfChange) { reloadStatuses(); } }; cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver); cr.registerContentObserver(Filters.CONTENT_URI, true, mContentObserver); updateRefreshState(); reloadStatuses(); }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
public NavigationBarView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context;// ww w .j a va 2s . c o m mHidden = false; mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE)); final Resources res = mContext.getResources(); mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size); mVertical = false; mShowMenu = false; mDelegateHelper = new DelegateViewHelper(this); mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back); mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land); mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime); mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime); mContext.getContentResolver().registerContentObserver( Settings.System.getUriFor(Settings.System.NAV_BAR_COLOR), false, new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { updateColor(false); } }); }
From source file:com.tingtingapps.securesms.ConversationListActivity.java
private void initializeContactUpdatesReceiver() { observer = new ContentObserver(null) { @Override// www . ja v a 2 s .c om public void onChange(boolean selfChange) { super.onChange(selfChange); Log.w(TAG, "Detected android contact data changed, refreshing cache"); RecipientFactory.clearCache(); ConversationListActivity.this.runOnUiThread(new Runnable() { @Override public void run() { fragment.getListAdapter().notifyDataSetChanged(); } }); } }; getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, observer); }
From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); mObserver = new ContentObserver(new Handler(mActivity.getMainLooper())) { @Override// w w w . j a v a 2 s . co m public void onChange(boolean selfChange) { if (mObjects == null || mObjects.getCursor() == null || !isAdded()) { return; } // XXX Move this to WizardStepHandler-- register a content observer // there only when required. if (WizardStepHandler.isCurrentTask(mActivity, WizardStepHandler.TASK_EDIT_PICTURE)) { Cursor c = mObjects.getCursor(); ObjectManager om = new ObjectManager(App.getDatabaseSource(mActivity)); AppManager am = new AppManager(App.getDatabaseSource(mActivity)); if (c.moveToFirst()) { while (!c.isAfterLast()) { long objId = c.getLong(c.getColumnIndexOrThrow(MObject.COL_ID)); MObject obj = om.getObjectForId(objId); if (obj != null && am.getAppIdentifier(obj.appId_).startsWith("musubi.sketch")) { WizardStepHandler.accomplishTask(mActivity, WizardStepHandler.TASK_EDIT_PICTURE); break; } c.moveToNext(); } } } if (DBG) Log.d(TAG, "-- contentObserver observed change"); getLoaderManager().restartLoader(0, getLoaderArgs(mTotal), FeedViewFragment.this); } }; if (savedInstanceState != null) { mTotal = savedInstanceState.getInt(EXTRA_NUM_ITEMS); Log.d(TAG, "setting total from instance: " + mTotal); } else { Log.d(TAG, "using total " + mTotal); } if (DBG) Log.d(TAG, "-- onCreated"); getLoaderManager().initLoader(0, getLoaderArgs(mTotal), this); }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
protected void createContentObserver() { Activity ctx = this.cordova.getActivity(); this.mObserver = new ContentObserver(new Handler()) { public void onChange(boolean selfChange) { this.onChange(selfChange, null); }/*from w ww .ja va 2s. c o m*/ public void onChange(boolean selfChange, Uri uri) { ContentResolver resolver = cordova.getActivity().getContentResolver(); Log.d(LOGTAG, ("onChange, selfChange: " + selfChange + ", uri: " + (Object) uri)); int id = -1; String str; if (uri != null && (str = uri.toString()).startsWith(SMS_URI_ALL)) { try { id = Integer.parseInt(str.substring(SMS_URI_ALL.length())); Log.d(LOGTAG, ("sms id: " + id)); } catch (NumberFormatException var6_6) { // empty catch block } } if (id == -1) { uri = Uri.parse(SMS_URI_INBOX); } Cursor cur = resolver.query(uri, null, null, null, "_id desc"); if (cur != null) { int n = cur.getCount(); Log.d(LOGTAG, ("n = " + n)); if (n > 0 && cur.moveToFirst()) { JSONObject json; if ((json = SMSPlugin.this.getJsonFromCursor(cur)) != null) { onSMSArrive(json); } else { Log.d(LOGTAG, "fetch record return null"); } } cur.close(); } } }; ctx.getContentResolver().registerContentObserver(Uri.parse(SMS_URI_INBOX), true, this.mObserver); Log.d(LOGTAG, "sms inbox observer registered"); }
From source file:com.appsimobile.appsii.module.calls.CallLogLoader.java
/** * Handles a request to start the Loader. *//*from w w w .j av a 2 s .c om*/ @Override protected void onStartLoading() { AppInjector.inject(this); if (mCallLogEntries != null) { // If we currently have a result available, deliver it // immediately. deliverResult(mCallLogEntries); } // Start watching for changes in the app data. if (mCallLogObserver == null) { mCallLogObserver = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { onChange(selfChange, null); } @Override public void onChange(boolean selfChange, Uri uri) { onContentChanged(); } }; getContext().getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI, true, mCallLogObserver); } mPermissionGrantedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int req = intent.getIntExtra(PermissionUtils.EXTRA_REQUEST_CODE, 0); if (req == PermissionUtils.REQUEST_CODE_PERMISSION_READ_CALL_LOG) { onContentChanged(); } } }; IntentFilter filter2 = new IntentFilter(PermissionUtils.ACTION_PERMISSION_RESULT); getContext().registerReceiver(mPermissionGrantedReceiver, filter2); // Has something interesting in the configuration changed since we // last built the app list? if (takeContentChanged() || mCallLogEntries == null) { // If the data has changed since the last time it was loaded // or is not currently available, start a load. forceLoad(); } }
From source file:com.android.contacts.model.AccountTypeManager.java
/** * Internal constructor that only performs initial parsing. *///from w w w . j a v a2 s. co m public AccountTypeManagerImpl(Context context) { mContext = context; mLocalAccountLocator = DeviceLocalAccountLocator.create(context); mTypeProvider = new AccountTypeProvider(context); mFallbackAccountType = new FallbackAccountType(context); mAccountManager = AccountManager.get(mContext); mExecutor = ContactsExecutors.getDefaultThreadPoolExecutor(); mMainThreadExecutor = ContactsExecutors.newHandlerExecutor(mMainThreadHandler); // 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); mAccountManager.addOnAccountsUpdatedListener(this, mMainThreadHandler, false); ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this); if (Flags.getInstance().getBoolean(Experiments.CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) { // Observe changes to RAW_CONTACTS so that we will update the list of "Device" accounts // if a new device contact is added. mContext.getContentResolver().registerContentObserver(ContactsContract.RawContacts.CONTENT_URI, /* notifyDescendents */ true, new ContentObserver(mMainThreadHandler) { @Override public boolean deliverSelfNotifications() { return true; } @Override public void onChange(boolean selfChange) { reloadLocalAccounts(); } @Override public void onChange(boolean selfChange, Uri uri) { reloadLocalAccounts(); } }); } loadAccountTypes(); }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
protected void createContentObserver() { Context ctx = this.cordova.getActivity(); this.mObserver = new ContentObserver(new Handler()) { public void onChange(boolean selfChange) { onChange(selfChange, null);//from ww w . j av a 2 s .c om } public void onChange(boolean selfChange, Uri uri) { Log.d("SMSPlugin", "onChange, selfChange: " + selfChange + ", uri: " + uri); int id = -1; if (uri != null) { String str = uri.toString(); if (str.startsWith("content://sms/")) { String box_or_id = str.substring("content://sms/".length()); try { id = Integer.parseInt(str); Log.d("SMSPlugin", "sms id: " + id); } catch (NumberFormatException localNumberFormatException) { } } } if (id == -1) { uri = Uri.parse("content://sms/inbox"); } ContentResolver resolver = SMSPlugin.this.cordova.getActivity().getContentResolver(); Cursor cur = resolver.query(uri, null, null, null, "_id desc"); if (cur != null) { int n = cur.getCount(); Log.d("SMSPlugin", "n = " + n); if ((n > 0) && (cur.moveToFirst())) { JSONObject json = SMSPlugin.this.getJsonFromCursor(cur); if (json != null) { SMSPlugin.this.onSMSArrive(json); } else { Log.d("SMSPlugin", "fetch record return null"); } } cur.close(); } } }; ctx.getContentResolver().registerContentObserver(Uri.parse("content://sms/inbox"), true, this.mObserver); Log.d("SMSPlugin", "sms inbox observer registered"); }
From source file:com.android.email.activity.MessageView.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.message_view); mHandler = new MessageViewHandler(); mControllerCallback = new ControllerResults(); mSubjectView = (TextView) findViewById(R.id.subject); mFromView = (TextView) findViewById(R.id.from); mToView = (TextView) findViewById(R.id.to); mCcView = (TextView) findViewById(R.id.cc); mCcContainerView = findViewById(R.id.cc_container); mDateView = (TextView) findViewById(R.id.date); mTimeView = (TextView) findViewById(R.id.time); mMessageContentView = (WebView) findViewById(R.id.message_content); mAttachments = (LinearLayout) findViewById(R.id.attachments); mAttachmentIcon = (ImageView) findViewById(R.id.attachment); mFavoriteIcon = (ImageView) findViewById(R.id.favorite); mShowPicturesSection = findViewById(R.id.show_pictures_section); mInviteSection = findViewById(R.id.invite_section); mSenderPresenceView = (ImageView) findViewById(R.id.presence); mMoveToNewer = findViewById(R.id.moveToNewer); mMoveToOlder = findViewById(R.id.moveToOlder); mScrollView = findViewById(R.id.scrollview); mMoveToNewer.setOnClickListener(this); mMoveToOlder.setOnClickListener(this); mFromView.setOnClickListener(this); mSenderPresenceView.setOnClickListener(this); mFavoriteIcon.setOnClickListener(this); findViewById(R.id.reply).setOnClickListener(this); findViewById(R.id.reply_all).setOnClickListener(this); findViewById(R.id.delete).setOnClickListener(this); findViewById(R.id.show_pictures).setOnClickListener(this); mMeetingYes = (TextView) findViewById(R.id.accept); mMeetingMaybe = (TextView) findViewById(R.id.maybe); mMeetingNo = (TextView) findViewById(R.id.decline); mMeetingYes.setOnClickListener(this); mMeetingMaybe.setOnClickListener(this); mMeetingNo.setOnClickListener(this); findViewById(R.id.invite_link).setOnClickListener(this); mMessageContentView.setVerticalScrollBarEnabled(false); mMessageContentView.getSettings().setBlockNetworkLoads(true); mMessageContentView.getSettings().setSupportZoom(false); mMessageContentView.setWebViewClient(new CustomWebViewClient()); mProgressDialog = new ProgressDialog(this); mProgressDialog.setIndeterminate(true); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); mDateFormat = android.text.format.DateFormat.getDateFormat(this); // short format mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format mFavoriteIconOn = getResources().getDrawable(R.drawable.btn_star_big_buttonless_on); mFavoriteIconOff = getResources().getDrawable(R.drawable.btn_star_big_buttonless_off); initFromIntent();/*from w ww. j a v a2 s .com*/ if (icicle != null) { mMessageId = icicle.getLong(STATE_MESSAGE_ID, mMessageId); } mController = Controller.getInstance(getApplication()); // This observer is used to watch for external changes to the message list mCursorObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { // get a new message list cursor, but only if we already had one // (otherwise it's "too soon" and other pathways will cause it to be loaded) if (mLoadMessageListTask == null && mMessageListCursor != null) { mLoadMessageListTask = new LoadMessageListTask(mMailboxId); mLoadMessageListTask.execute(); } } }; messageChanged(); }