/** Reinflates and updates all components of this view. */ public void refresh() { if (mTopSitesAdapter != null) mTopSitesAdapter.notifyDataSetChanged(); removeAllViews(); // We must remove the currently inflated view to allow for reinflation. inflate(); mTopSitesGrid.setAdapter( mTopSitesAdapter); // mTopSitesGrid is a new instance (from loadTopSites()). update(AboutHomeContent.UpdateFlags.ALL); // Refresh all elements. }
private void updateLayout(boolean syncIsSetup) { boolean hasTopSites = mTopSitesAdapter.getCount() > 0; setTopSitesVisibility(hasTopSites); AboutHomePromoBox.Type type = mPrelimPromoBoxType; if (syncIsSetup && type == AboutHomePromoBox.Type.SYNC) type = AboutHomePromoBox.Type.APPS; mPromoBox.show(type); }
private void clearThumbnailsWithUrl(final String url) { for (int i = 0; i < mTopSitesAdapter.getCount(); i++) { final View view = mTopSitesGrid.getChildAt(i); final TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag(); if (holder.getUrl().equals(url)) { clearThumbnail(holder); } } }
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; } }
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; }
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(); } }); }
private void updateTopSitesThumbnails(Map<String, Bitmap> thumbnails) { for (int i = 0; i < mTopSitesAdapter.getCount(); i++) { final View view = mTopSitesGrid.getChildAt(i); // The grid view might get temporarily out of sync with the // adapter refreshes (e.g. on device rotation) if (view == null) continue; TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag(); final String url = holder.getUrl(); if (TextUtils.isEmpty(url)) { holder.thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_add); holder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { displayThumbnail(view, thumbnails.get(url)); } } mTopSitesGrid.invalidate(); }
private void updateLayout() { boolean hasTopSites = mTopSitesAdapter.getCount() > 0; setTopSitesVisibility(hasTopSites); mPromoBox.showRandomPromo(); }