List of usage examples for android.app LoaderManager initLoader
public abstract <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);
From source file:com.tct.mail.ui.ConversationViewFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { LogUtils.d(LOG_TAG, "IN CVF.onActivityCreated, this=%s visible=%s", this, isUserVisible()); super.onActivityCreated(savedInstanceState); if (mActivity == null || mActivity.isFinishing()) { // Activity is finishing, just bail. return;/*ww w . ja v a2 s. c om*/ } Context context = getContext(); mTemplates = new HtmlConversationTemplates(context); final FormattedDateBuilder dateBuilder = new FormattedDateBuilder(context); mNavigationController = mActivity.getKeyboardNavigationController(); mAdapter = new ConversationViewAdapter(mActivity, this, getLoaderManager(), this, this, getContactInfoSource(), this, this, getListController(), this, mAddressCache, dateBuilder, mBidiFormatter, this); mConversationContainer.setOverlayAdapter(mAdapter); // set up snap header (the adapter usually does this with the other ones) mConversationContainer.getSnapHeader().initialize(this, mAddressCache, this, getContactInfoSource(), mActivity.getAccountController().getVeiledAddressMatcher()); final Resources resources = getResources(); mMaxAutoLoadMessages = resources.getInteger(R.integer.max_auto_load_messages); mSideMarginPx = resources.getDimensionPixelOffset(R.dimen.conversation_message_content_margin_side); mUrlToMessageIdMap = new ArrayMap<String, String>(); final InlineAttachmentViewIntentBuilderCreator creator = InlineAttachmentViewIntentBuilderCreatorHolder .getInlineAttachmentViewIntentCreator(); final WebViewContextMenu contextMenu = new WebViewContextMenu(getActivity(), creator .createInlineAttachmentViewIntentBuilder(mAccount, mConversation != null ? mConversation.id : -1)); contextMenu.setCallbacks(this); mWebView.setOnCreateContextMenuListener(contextMenu); // TS: zhaotianyong 2015-03-13 EMAIL BUGFIX-932165 ADD_S mWebView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub final int action = event.getActionMasked(); if (action == MotionEvent.ACTION_UP && webViewScaleHasChanged) { mWebView.loadUrl(String.format("javascript:setConversationHeaderSpacerHeight(%s);", mCovHeaderHeight * mWebView.getInitialScale() / mWebView.getScale())); if (mAdapter.getMessageHeaderItem() != null) { mWebView.loadUrl(String.format("javascript:setMessageHeaderSpacerHeight('%s', %s);", mTemplates.getMessageDomId(mAdapter.getMessageHeaderItem().getMessage()), mMsgHeaderHeight * mWebView.getInitialScale() / mWebView.getScale())); } mWebView.loadUrl(String.format("javascript:setConversationFooterSpacerHeight(%s);", mCovFooterHegiht * mWebView.getInitialScale() / mWebView.getScale())); webViewScaleHasChanged = false; } return mWebView.onTouchEvent(event); } }); // TS: zhaotianyong 2015-03-13 EMAIL BUGFIX-932165 ADD_E //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_S mFabButton.setAccountController(this); //Because we can't get the webview's contentHeight when onPageFinished(),so set the PictureListener //to get the contentHeight and judge if it's initialized bottom,and then do the animation. mWebView.setPictureListener(new PictureListener() { int previousHeight; @Deprecated public void onNewPicture(WebView w, Picture picture) { // TODO Auto-generated method stub int height = w.getContentHeight(); if (previousHeight == height) return; previousHeight = height; if (mWebView.isInitializedBottom()) { mWebView.animateBottom(true); } else { mWebView.animateHideFooter(); } } }); //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_E // set this up here instead of onCreateView to ensure the latest Account is loaded setupOverviewMode(); // Defer the call to initLoader with a Handler. // We want to wait until we know which fragments are present and their final visibility // states before going off and doing work. This prevents extraneous loading from occurring // as the ViewPager shifts about before the initial position is set. // // e.g. click on item #10 // ViewPager.setAdapter() actually first loads #0 and #1 under the assumption that #0 is // the initial primary item // Then CPC immediately sets the primary item to #10, which tears down #0/#1 and sets up // #9/#10/#11. getHandler().post(new FragmentRunnable("showConversation", this) { @Override public void go() { showConversation(); } }); if (mConversation != null && mConversation.conversationBaseUri != null && !Utils.isEmpty(mAccount.accountCookieQueryUri)) { // Set the cookie for this base url new SetCookieTask(getContext(), mConversation.conversationBaseUri.toString(), mAccount.accountCookieQueryUri).execute(); } // Find the height of the screen for manually scrolling the webview via keyboard. final Rect screen = new Rect(); mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(screen); mMaxScreenHeight = screen.bottom; mTopOfVisibleScreen = screen.top + mActivity.getSupportActionBar().getHeight(); //[BUGFIX]-Add-BEGIN?by?TSCD.zheng.zou,01/14/2015,887972 //[Email]It?still?display?download?remaining?when?rotate?the?screen?during?loading //note:use initLoader to reconnect with the previous loader. if (savedInstanceState != null) { mIsDownloadingRemaining = savedInstanceState.getBoolean(IS_DOWNLOADING_REMAINING); mIsPopDownloadRemain = savedInstanceState.getBoolean(IS_POP_DOWNLOAD_REMAIN); } LoaderManager lm = getLoaderManager(); if (lm.getLoader(LOADER_DOWNLOAD_REMAINING) != null) { lm.initLoader(LOADER_DOWNLOAD_REMAINING, null, mDownloadRemainCallback); } //[BUGFIX]-Add-END?by?TSCD.zheng.zou }
From source file:com.android.mail.ui.AbstractActivityController.java
/** * Load the conversation list early for the given folder. This happens when some UI element * (usually the drawer) instructs the controller that an account change or folder change is * imminent. While the UI element is animating, the controller can preload the conversation * list for the default inbox of the account provided here or to the folder provided here. * * @param nextAccount The account which the app will switch to shortly, possibly null. * @param nextFolder The folder which the app will switch to shortly, possibly null. *///from ww w . j a v a 2 s.co m protected void preloadConvList(Account nextAccount, Folder nextFolder) { // Fire off the conversation list loader for this account already with a fake // listener. final Bundle args = new Bundle(2); if (nextAccount != null) { args.putParcelable(BUNDLE_ACCOUNT_KEY, nextAccount); } else { args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); } if (nextFolder != null) { args.putParcelable(BUNDLE_FOLDER_KEY, nextFolder); } else { LogUtils.e(LOG_TAG, new Error(), "AAC.preloadConvList(): Got an empty folder"); } mFolder = null; final LoaderManager lm = mActivity.getLoaderManager(); lm.destroyLoader(LOADER_CONVERSATION_LIST); lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks); }
From source file:com.chen.mail.ui.AbstractActivityController.java
/** * Sets the current folder if it is different from the object provided here. This method does * NOT notify the folder observers that a change has happened. Observers are notified when we * get an updated folder from the loaders, which will happen as a consequence of this method * (since this method starts/restarts the loaders). * @param folder The folder to assign/* www. j a va2s .c o m*/ */ private void updateFolder(Folder folder) { if (folder == null || !folder.isInitialized()) { LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder); return; } if (folder.equals(mFolder)) { LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder); return; } final boolean wasNull = mFolder == null; LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name); final LoaderManager lm = mActivity.getLoaderManager(); // updateFolder is called from AAC.onLoadFinished() on folder changes. We need to // ensure that the folder is different from the previous folder before marking the // folder changed. setHasFolderChanged(folder); mFolder = folder; // We do not need to notify folder observers yet. Instead we start the loaders and // when the load finishes, we will get an updated folder. Then, we notify the // folderObservers in onLoadFinished. mActionBarView.setFolder(mFolder); // Only when we switch from one folder to another do we want to restart the // folder and conversation list loaders (to trigger onCreateLoader). // The first time this runs when the activity is [re-]initialized, we want to re-use the // previous loader's instance and data upon configuration change (e.g. rotation). // If there was not already an instance of the loader, init it. if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) { lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } else { lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) { // If there was an existing folder AND we have changed // folders, we want to restart the loader to get the information // for the newly selected folder lm.destroyLoader(LOADER_CONVERSATION_LIST); } final Bundle args = new Bundle(2); args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); args.putParcelable(BUNDLE_FOLDER_KEY, mFolder); lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks); }
From source file:com.android.mail.ui.AbstractActivityController.java
/** * Sets the current folder if it is different from the object provided here. This method does * NOT notify the folder observers that a change has happened. Observers are notified when we * get an updated folder from the loaders, which will happen as a consequence of this method * (since this method starts/restarts the loaders). * @param folder The folder to assign//from w ww .j ava2 s. c o m */ private void updateFolder(Folder folder) { if (folder == null || !folder.isInitialized()) { LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder); return; } if (folder.equals(mFolder)) { LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder); return; } final boolean wasNull = mFolder == null; LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name); final LoaderManager lm = mActivity.getLoaderManager(); // updateFolder is called from AAC.onLoadFinished() on folder changes. We need to // ensure that the folder is different from the previous folder before marking the // folder changed. setHasFolderChanged(folder); mFolder = folder; // We do not need to notify folder observers yet. Instead we start the loaders and // when the load finishes, we will get an updated folder. Then, we notify the // folderObservers in onLoadFinished. mActionBarController.setFolder(mFolder); // Only when we switch from one folder to another do we want to restart the // folder and conversation list loaders (to trigger onCreateLoader). // The first time this runs when the activity is [re-]initialized, we want to re-use the // previous loader's instance and data upon configuration change (e.g. rotation). // If there was not already an instance of the loader, init it. if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) { lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } else { lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) { // If there was an existing folder AND we have changed // folders, we want to restart the loader to get the information // for the newly selected folder lm.destroyLoader(LOADER_CONVERSATION_LIST); } final Bundle args = new Bundle(2); args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); args.putParcelable(BUNDLE_FOLDER_KEY, mFolder); args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, mIgnoreInitialConversationLimit); mIgnoreInitialConversationLimit = false; lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks); }
From source file:com.tct.mail.ui.AbstractActivityController.java
/** * Load conversation list when click the star toggle in actionbar. *///from w w w . j av a2s . co m private void loadConvListByStarToggle(Account nextAccount, Folder nextFolder) { final Bundle args = new Bundle(3); //TS: zheng.zou 2016-1-14 EMAIL TASK_1431225 MOD if (nextAccount != null) { args.putParcelable(BUNDLE_ACCOUNT_KEY, nextAccount); } else { args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); } if (nextFolder != null) { args.putParcelable(BUNDLE_FOLDER_KEY, nextFolder); } else { LogUtils.e(LOG_TAG, new Error(), "AAC.loadConvListByStarToggle(): Got an empty folder"); } args.putInt(BUNDLE_CONVERSATION_ORDER_KEY, SortHelper.getCurrentSort()); //TS: zheng.zou 2016-1-14 EMAIL TASK_1431225 ADD final LoaderManager lm = mActivity.getLoaderManager(); lm.destroyLoader(LOADER_CONVERSATION_LIST); lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks); }
From source file:com.tct.mail.ui.AbstractActivityController.java
/** * Sets the current folder if it is different from the object provided here. This method does * NOT notify the folder observers that a change has happened. Observers are notified when we * get an updated folder from the loaders, which will happen as a consequence of this method * (since this method starts/restarts the loaders). * @param folder The folder to assign/*from w ww . j a v a 2 s. co m*/ */ private void updateFolder(Folder folder) { if (folder == null || !folder.isInitialized()) { LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder); return; } if (folder.equals(mFolder)) { LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder); return; } final boolean wasNull = mFolder == null; LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name); final LoaderManager lm = mActivity.getLoaderManager(); // updateFolder is called from AAC.onLoadFinished() on folder changes. We need to // ensure that the folder is different from the previous folder before marking the // folder changed. setHasFolderChanged(folder); mFolder = folder; // We do not need to notify folder observers yet. Instead we start the loaders and // when the load finishes, we will get an updated folder. Then, we notify the // folderObservers in onLoadFinished. mActionBarController.setFolder(mFolder); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S mActivity.invalidateOptionsMenu(); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E // Only when we switch from one folder to another do we want to restart the // folder and conversation list loaders (to trigger onCreateLoader). // The first time this runs when the activity is [re-]initialized, we want to re-use the // previous loader's instance and data upon configuration change (e.g. rotation). // If there was not already an instance of the loader, init it. if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) { lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } else { lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) { // If there was an existing folder AND we have changed // folders, we want to restart the loader to get the information // for the newly selected folder lm.destroyLoader(LOADER_CONVERSATION_LIST); } /// TCT: Fix the empty view will always flash out here. no need show empty view when folde changing, // folders, we want to restart the loader to get the information /// cause loadConversationListData would always destroy loader,and the cursor always be empty when do this. @{ // for the newly selected folder final ConversationListFragment conversationList = getConversationListFragment(); // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_S // lm.destroyLoader(LOADER_CONVERSATION_LIST); // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_E if (conversationList != null) { conversationList.getListView().setEmptyView(null); } loadConversationListData(true); }
From source file:com.tct.mail.ui.AbstractActivityController.java
/** * TCT: Move data load code to an independent function, if we just want refresh loader data. * call this to refresh cursor data(local search or update folder) *//*ww w . j a va 2s . c om*/ private void loadConversationListData(boolean folderUpdated) { if (mFolder == null || !mFolder.isInitialized()) { LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", mFolder); return; } final LoaderManager lm = mActivity.getLoaderManager(); if (mConvListContext != null && mConvListContext.isLocalSearchExecuted()) { final Bundle args = new Bundle(4); args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); args.putParcelable(BUNDLE_FOLDER_KEY, mFolder); args.putString(SearchParams.BUNDLE_QUERY_FIELD, mConvListContext.getSearchField()); args.putString(SearchParams.BUNDLE_QUERY_TERM, mConvListContext.getSearchQuery()); LogUtils.logFeature(LogTag.SEARCH_TAG, "loadConversationListData for local search query [%s], field [%s]", mConvListContext.getSearchQuery(), mConvListContext.getSearchField()); ///TCT: Before we start the local search loader, need cancel the normal conversation list // loader to avoid no need load and wrong result display by the load finish delay.@{ if (lm.getLoader(LOADER_CONVERSATION_LIST) != null) { lm.destroyLoader(LOADER_CONVERSATION_LIST); } // @} lm.restartLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST, args, mListCursorCallbacks); } else { ///TCT: Before we start the normal search loader, need cancel the local search conversation list // loader to avoid no need load and wrong result display by the load finish delay.@{ if (lm.getLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST) != null) { lm.destroyLoader(LOADER_LOCALSEARCH_CONVERSATION_LIST); } // @} // TS: kaifeng.lu 2015-09-8 EMAIL BUGFIX-1065353 DEL_S // final ConversationCursorLoader ccl = (ConversationCursorLoader) ((Object) lm // .getLoader(LOADER_CONVERSATION_LIST)); // if (ccl != null && !ccl.getUri().equals(mFolder.conversationListUri) && folderUpdated) { // If there was an existing folder AND we have changed // folders, we want to restart the loader to get the information // for the newly selected folder // lm.destroyLoader(LOADER_CONVERSATION_LIST); // } // TS: kaifeng.lu 2015-09-8 EMAIL BUGFIX-1065353 DEL_E final Bundle args = new Bundle(2); args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount); args.putParcelable(BUNDLE_FOLDER_KEY, mFolder); args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, mIgnoreInitialConversationLimit); mIgnoreInitialConversationLimit = false; lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks); } }