Example #1
0
 public Cursor swapCursor(Cursor newCursor) {
   if (newCursor == this.mCursor) {
     return null;
   }
   Cursor oldCursor = this.mCursor;
   if (oldCursor != null) {
     if (this.mChangeObserver != null) {
       oldCursor.unregisterContentObserver(this.mChangeObserver);
     }
     if (this.mDataSetObserver != null) {
       oldCursor.unregisterDataSetObserver(this.mDataSetObserver);
     }
   }
   this.mCursor = newCursor;
   if (newCursor != null) {
     if (this.mChangeObserver != null) {
       newCursor.registerContentObserver(this.mChangeObserver);
     }
     if (this.mDataSetObserver != null) {
       newCursor.registerDataSetObserver(this.mDataSetObserver);
     }
     this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
     this.mDataValid = true;
     notifyDataSetChanged();
     return oldCursor;
   }
   this.mRowIDColumn = -1;
   this.mDataValid = false;
   notifyDataSetInvalidated();
   return oldCursor;
 }
  public void changeCursor(Cursor cursor) {
    if (cursor == mCursor) {
      return;
    }

    if (mCursor != null) {
      mCursor.unregisterContentObserver(mChangeObserver);
      mCursor.unregisterDataSetObserver(mDataSetObserver);
      mCursor.close();
    }
    mCursor = cursor;
    resetCache();
    findGroups();
    if (cursor != null) {
      cursor.registerContentObserver(mChangeObserver);
      cursor.registerDataSetObserver(mDataSetObserver);
      mRowIdColumnIndex = cursor.getColumnIndexOrThrow("_id");
      mDataValid = true;
      notifyDataSetChanged();
    } else {
      mRowIdColumnIndex = -1;
      mDataValid = false;
      // notify the observers about the lack of a data set
      notifyDataSetInvalidated();
    }
  }
 /**
  * Swap in a new Cursor, returning the old Cursor. Unlike {@link #changeCursor(Cursor)}, the
  * returned old Cursor is <em>not</em> closed.
  *
  * @param newCursor The new cursor to be used.
  * @return Returns the previously set Cursor, or null if there wasa not one. If the given new
  *     Cursor is the same instance is the previously set Cursor, null is also returned.
  */
 public Cursor swapCursor(Cursor newCursor) {
   if (newCursor == mCursor) {
     return null;
   }
   Cursor oldCursor = mCursor;
   if (oldCursor != null) {
     if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
     if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
   }
   mCursor = newCursor;
   if (newCursor != null) {
     if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
     if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
     mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
     mDataValid = true;
     // notify the observers about the new cursor
     notifyDataSetChanged();
   } else {
     mRowIDColumn = -1;
     mDataValid = false;
     // notify the observers about the lack of a data set
     // notifyDataSetInvalidated();
     notifyItemRangeRemoved(0, getItemCount());
   }
   return oldCursor;
 }
 /**
  * Swap in a new Cursor, returning the old Cursor. Unlike {@link #changeCursor(Cursor)}, the
  * returned old Cursor is <em>not</em> closed.
  *
  * @param newCursor The new cursor to be used.
  * @return Returns the previously set Cursor, or null if there wasa not one. If the given new
  *     Cursor is the same instance is the previously set Cursor, null is also returned.
  */
 public Cursor swapCursor(Cursor newCursor) {
   if (newCursor == mCursor) {
     return null;
   }
   Cursor oldCursor = mCursor;
   if (oldCursor != null) {
     if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
     if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
   }
   mCursor = newCursor;
   if (newCursor != null) {
     if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
     if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
     mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
     mDataValid = true;
     // notify the observers about the new cursor
     notifyDataSetChanged();
   } else {
     mRowIDColumn = -1;
     mDataValid = false;
     // notify the observers about the lack of a data set
     // There is no notifyDataSetInvalidated() method in RecyclerView.Adapter
     notifyDataSetChanged();
   }
   return oldCursor;
 }
Example #5
0
  /*
     This test uses the provider to insert and then update the data. Uncomment this test to
     see if your update location is functioning correctly.
  */
  public void testUpdateLocation() {
    // Create a new map of values, where column names are the keys
    ContentValues values = TestUtilities.createNorthPoleLocationValues();

    Uri locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, values);
    long locationRowId = ContentUris.parseId(locationUri);

    // Verify we got a row back.
    assertTrue(locationRowId != -1);
    Log.d(LOG_TAG, "New row id: " + locationRowId);

    ContentValues updatedValues = new ContentValues(values);
    updatedValues.put(LocationEntry._ID, locationRowId);
    updatedValues.put(LocationEntry.CITY_NAME, "Santa's Village");

    // Create a cursor with observer to make sure that the content provider is notifying
    // the observers as expected
    Cursor locationCursor =
        mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null);

    TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
    locationCursor.registerContentObserver(tco);

    int count =
        mContext
            .getContentResolver()
            .update(
                LocationEntry.CONTENT_URI,
                updatedValues,
                LocationEntry._ID + "= ?",
                new String[] {Long.toString(locationRowId)});
    assertEquals(count, 1);

    // Test to make sure our observer is called.  If not, we throw an assertion.
    //
    // Students: If your code is failing here, it means that your content provider
    // isn't calling getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();

    locationCursor.unregisterContentObserver(tco);
    // locationCursor.close();

    // A cursor is your primary interface to the query results.
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                LocationEntry.CONTENT_URI,
                null, // projection
                LocationEntry._ID + " = " + locationRowId,
                null, // Values for the "where" clause
                null // sort order
                );

    TestUtilities.validateCursor(
        "testUpdateLocation.  Error validating location entry update.", cursor, updatedValues);

    // cursor.close();
  }
Example #6
0
 public synchronized void unIni() {
   if (mCursor != null) {
     mCursor.unregisterContentObserver(mChangeObserver);
     mCursor.close();
     mCursor = null;
     mApnWrapper = null;
   }
 }
 @Override
 protected void onPause() {
   super.onPause();
   if (haveCursors()) {
     mDateSortedCursor.unregisterContentObserver(mContentObserver);
     mDateSortedCursor.unregisterDataSetObserver(mDataSetObserver);
   }
 }
  @Override
  protected void onDestroy() {
    super.onDestroy();

    try {
      downloadCursor.unregisterContentObserver(mDownloadObserver);
    } catch (Exception ne) {
    }
  }
Example #9
0
  /** Stop address book monitoring */
  public void stop() {
    if (sLogger.isActivated()) {
      sLogger.info("Stop address book monitoring");
    }
    /* Remove the messages that may still be scheduled */
    mCheckHandler.removeMessages(CHECK_MESSAGE);

    /* Unregister content observer */
    if (mObserverIsRegistered) {
      mContactsContractCursor.unregisterContentObserver(mContactsContractObserver);
      mObserverIsRegistered = false;
      mContactsContractCursor.close();
    }

    mCleanupExecutor.shutdownNow();
  }
 @Override
 public void onDestroy() {
   cursor.unregisterContentObserver(observer);
   cursor.close();
 } //
Example #11
0
 public void onGetTimeLineComplete(String paramString1, int paramInt1, String paramString2, int paramInt2, int paramInt3, boolean paramBoolean1, ArrayList<VinePost> paramArrayList, String paramString3, int paramInt4, int paramInt5, int paramInt6, long paramLong, boolean paramBoolean2, int paramInt7, String paramString4)
 {
   PendingRequest localPendingRequest = ProfileFragment.this.removeRequest(paramString1);
   int i;
   ArrayList localArrayList2;
   int j;
   label228: Object localObject;
   if (localPendingRequest != null)
   {
     if ((paramInt2 != 2) && (paramInt2 != 10))
       break label401;
     i = 1;
     if ((i != 0) && (paramInt1 == 200))
     {
       ProfileFragment.this.mProfileHeaderAdapter.updatePostsCount(paramInt7);
       ProfileFragment.this.mProfileHeaderAdapter.notifyDataSetChanged();
     }
     if ((paramBoolean1) && (paramInt1 == 200))
     {
       if (((paramInt2 == 3) && (ProfileFragment.this.mCurrentTab == 2)) || ((i != 0) && (ProfileFragment.this.mCurrentTab == 1)))
       {
         Cursor localCursor1 = ProfileFragment.this.mCursorAdapter.getCursor();
         ArrayList localArrayList1 = null;
         if (localCursor1 != null)
         {
           int k = localCursor1.getCount();
           localArrayList1 = null;
           if (k > 0)
           {
             Bundle localBundle = new Bundle();
             localBundle.putBoolean("include_list", true);
             localCursor1.respond(localBundle);
             localArrayList1 = localCursor1.getExtras().getParcelableArrayList("extra_posts");
           }
         }
         localArrayList2 = HybridPostCursor.mergePosts(localArrayList1, paramArrayList, VineComparatorFactory.get(paramInt2), false);
         if (localArrayList2 != null)
         {
           if (ProfileFragment.this.mCurrentTab != 1)
             break label407;
           j = ProfileFragment.this.mCursorQuerySizePosts;
           if (!BuildUtil.isOldDeviceOrLowEndDevice(ProfileFragment.this.getActivity()))
             break label419;
           localObject = new HybridPostCursorExplore(localArrayList2, j);
           label254: if (paramInt5 <= 0)
             ((HybridPostCursor)localObject).markLast();
           if (ProfileFragment.this.mChangeObserver == null)
             break label435;
           Cursor localCursor2 = ProfileFragment.this.mCursorAdapter.swapCursor((Cursor)localObject);
           if (localCursor2 != null)
             localCursor2.unregisterContentObserver(ProfileFragment.this.mChangeObserver);
           ((HybridPostCursor)localObject).registerContentObserver(ProfileFragment.this.mChangeObserver);
           label319: ProfileFragment.this.mCursorAdapter.notifyDataSetChanged();
         }
       }
       if (i == 0)
         break label451;
       ProfileFragment.this.mCursorQuerySizePosts = ProfileFragment.this.mCursorAdapter.getCount();
     }
   }
   while (true)
   {
     ProfileFragment.this.mAppController.saveLoadedPosts(paramArrayList, paramInt2, paramString3, paramInt4, paramInt5, paramInt6, paramLong, false);
     if ((i != 0) || (paramInt2 == 3))
       ProfileFragment.this.hideProgress(localPendingRequest.fetchType);
     return;
     label401: i = 0;
     break;
     label407: j = ProfileFragment.this.mCursorQuerySizeLikes;
     break label228;
     label419: localObject = new HybridPostCursor(localArrayList2, j);
     break label254;
     label435: CrashUtil.logException(new VineException("Invalid observer"));
     break label319;
     label451: if (paramInt2 == 3)
       ProfileFragment.this.mCursorQuerySizeLikes = ProfileFragment.this.mCursorAdapter.getCount();
   }
 }
Example #12
0
 public void onLoadFinished(Loader<Cursor> paramLoader, Cursor paramCursor)
 {
   int i = 1;
   Cursor localCursor = this.mFeedAdapter.getCursor();
   switch (paramLoader.getId())
   {
   default:
   case 1:
   case 2:
     label224: label226: 
     do
     {
       while (true)
       {
         return;
         if (this.mCurrentTab == i)
         {
           if (localCursor != null)
             localCursor.unregisterContentObserver(this.mChangeObserver);
           if (paramCursor != null)
             paramCursor.registerContentObserver(this.mChangeObserver);
           this.mFeedAdapter.swapCursor(paramCursor);
           if ((this.mFeedAdapter.isEmpty()) && ((0x2 & this.mFetchFlags) == 0))
             fetchContent(3, i);
           while (true)
           {
             if ((this.mFeedAdapter.isEmpty()) || (this.mLastFetchType != 7))
               break label224;
             hideProgress(7);
             if (this.mFeedAdapter.getCursor() == null)
               break label226;
             if (this.mFeedAdapter.getCursor().getCount() > this.mCursorPreviousPosts)
               break;
             fetchContent(i, i);
             return;
             if (this.mRepostsToggled)
             {
               fetchContent(3, false);
               this.mRepostsToggled = false;
             }
             else
             {
               hideProgress(3);
               if (!this.mFeedAdapter.isEmpty())
                 showSadface(false);
               else
                 showSadface(false);
             }
           }
         }
       }
       CrashUtil.logException(new VineException(), "Possible null cursor after swap.", new Object[0]);
       return;
     }
     while (this.mCurrentTab != 2);
     if (localCursor != null)
       localCursor.unregisterContentObserver(this.mChangeObserver);
     if (paramCursor != null)
       paramCursor.registerContentObserver(this.mChangeObserver);
     this.mFeedAdapter.swapCursor(paramCursor);
     if ((this.mFeedAdapter.isEmpty()) && ((0x4 & this.mFetchFlags) == 0))
       fetchContent(3, i);
     while ((!this.mFeedAdapter.isEmpty()) && (this.mLastFetchType == 7))
     {
       if (this.mFeedAdapter.getCursor().getCount() <= this.mCursorPreviousLikes)
         fetchContent(i, i);
       hideProgress(7);
       return;
       hideProgress(3);
       if (!this.mFeedAdapter.isEmpty())
         showSadface(false);
       else
         showSadface(false);
     }
   case 3:
   }
   if ((paramCursor != null) && (paramCursor.moveToFirst()))
     if (paramCursor.getInt(0) <= 0);
   for (this.mHideProfileReposts = i; ; this.mHideProfileReposts = false)
   {
     this.mSectionAdapter = null;
     setup();
     initProfile();
     return;
     int j = 0;
     break;
   }
 }
 public void unregisterContentObserver(ContentObserver observer) {
   mDatabaseCursor.unregisterContentObserver(observer);
 }