public void onDestroy() {
    if (mTopSitesAdapter != null) {
      Cursor cursor = mTopSitesAdapter.getCursor();
      if (cursor != null && !cursor.isClosed()) cursor.close();
    }

    if (mTabsContentObserver != null) {
      mActivity.getContentResolver().unregisterContentObserver(mTabsContentObserver);
      mTabsContentObserver = null;
    }
  }
예제 #2
0
  public void onDestroy() {
    if (mAccountListener != null) {
      mAccountManager.removeOnAccountsUpdatedListener(mAccountListener);
      mAccountListener = null;
    }

    if (mTopSitesAdapter != null) {
      Cursor cursor = mTopSitesAdapter.getCursor();
      if (cursor != null && !cursor.isClosed()) cursor.close();
    }
  }
  private List<String> getTopSitesUrls() {
    List<String> urls = new ArrayList<String>();

    Cursor c = mTopSitesAdapter.getCursor();
    if (c == null || !c.moveToFirst()) return urls;

    do {
      final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
      urls.add(url);
    } while (c.moveToNext());

    return urls;
  }
예제 #4
0
  private void loadTopSites() {
    // The SyncAccounts.syncAccountsExist method should not be called on
    // UI thread as it touches disk to access a sqlite DB.
    final boolean syncIsSetup = SyncAccounts.syncAccountsExist(mActivity);

    final ContentResolver resolver = mActivity.getContentResolver();
    Cursor old = null;
    if (mTopSitesAdapter != null) {
      old = mTopSitesAdapter.getCursor();
    }
    // Swap in the new cursor.
    final Cursor oldCursor = old;
    final Cursor newCursor = BrowserDB.getTopSites(resolver, mNumberOfTopSites);

    post(
        new Runnable() {
          public void run() {
            if (mTopSitesAdapter == null) {
              mTopSitesAdapter =
                  new TopSitesCursorAdapter(
                      mActivity,
                      R.layout.abouthome_topsite_item,
                      newCursor,
                      new String[] {URLColumns.TITLE},
                      new int[] {R.id.title});

              mTopSitesGrid.setAdapter(mTopSitesAdapter);
            } else {
              mTopSitesAdapter.changeCursor(newCursor);
            }

            if (mTopSitesAdapter.getCount() > 0) loadTopSitesThumbnails(resolver);

            updateLayout(syncIsSetup);

            // Free the old Cursor in the right thread now.
            if (oldCursor != null && !oldCursor.isClosed()) oldCursor.close();

            // Even if AboutHome isn't necessarily entirely loaded if we
            // get here, for phones this is the part the user initially sees,
            // so it's the one we will care about for now.
            if (mLoadCompleteCallback != null) mLoadCompleteCallback.callback();
          }
        });
  }