/** * Creates an instance of {@link EnhancedBookmarkManager}. It also initializes resources, bookmark * models and jni bridges. * * @param activity The activity context to use. */ public EnhancedBookmarkManager(Activity activity) { mActivity = activity; mEnhancedBookmarksModel = new EnhancedBookmarksModel(); mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.eb_main, null); mDrawer = (DrawerLayout) mMainView.findViewById(R.id.eb_drawer_layout); mDrawerListView = (EnhancedBookmarkDrawerListView) mMainView.findViewById(R.id.eb_drawer_list); mContentView = (EnhancedBookmarkContentView) mMainView.findViewById(R.id.eb_content_view); mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.eb_view_switcher); mUndoController = new EnhancedBookmarkUndoController( activity, mEnhancedBookmarksModel, ((SnackbarManageable) activity).getSnackbarManager()); mSearchView = (EnhancedBookmarkSearchView) getView().findViewById(R.id.eb_search_view); mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver); initializeIfBookmarkModelLoaded(); // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup // code, but that might be executed much later. Especially on L, showing loading // progress bar blocks that so it won't be loaded. http://crbug.com/429383 PartnerBookmarksShim.kickOffReading(activity); mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile()); ActivityManager activityManager = ((ActivityManager) ApplicationStatus.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE)); int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024, FAVICON_MAX_CACHE_SIZE_BYTES); mLargeIconBridge.createCache(maxSize); }
/** Destroys and cleans up itself. This must be called after done using this class. */ public void destroy() { for (EnhancedBookmarkUIObserver observer : mUIObservers) { observer.onDestroy(); } assert mUIObservers.size() == 0; if (mUndoController != null) { mUndoController.destroy(); mUndoController = null; } mEnhancedBookmarksModel.removeObserver(mBookmarkModelObserver); mEnhancedBookmarksModel.destroy(); mEnhancedBookmarksModel = null; mLargeIconBridge.destroy(); mLargeIconBridge = null; }