Example usage for android.app LoaderManager getLoader

List of usage examples for android.app LoaderManager getLoader

Introduction

In this page you can find the example usage for android.app LoaderManager getLoader.

Prototype

public abstract <D> Loader<D> getLoader(int id);

Source Link

Document

Return the Loader with the given id or null if no matching Loader is found.

Usage

From source file:com.amgems.uwschedule.ui.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);
    setupViews();//from   w  w w  . j a  va  2  s . com

    getContentResolver().delete(ScheduleContract.Courses.CONTENT_URI, null, null);
    getContentResolver().delete(ScheduleContract.Meetings.CONTENT_URI, null, null);

    // Initialize inbound data
    mUsername = getIntent().getStringExtra(EXTRAS_HOME_USERNAME);
    mCookieStore = CookieStore.getInstance(getApplicationContext());

    // Set up navigation drawer items
    mDrawerLayoutRoot.setDrawerListener(mDrawerToggle);
    List<DrawerListAdapter.Group> drawerGroups = new ArrayList<DrawerListAdapter.Group>();
    drawerGroups.add(new DrawerListAdapter.Group(R.string.drawer_group_home, R.drawable.ic_nav_home));
    drawerGroups.add(new DrawerListAdapter.Group(R.string.drawer_group_friends, R.drawable.ic_nav_friends));
    drawerGroups.add(new DrawerListAdapter.Group(R.string.drawer_group_favorites, R.drawable.ic_nav_favorites));
    mDrawerListView.setAdapter(new DrawerListAdapter(this, drawerGroups));
    mCoursesViewPager.setAdapter(new CoursesFragmentPagerAdapter(getSupportFragmentManager()));

    mDrawerEmailTextView.setText(mUsername + USER_EMAIL_POSTFIX);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    WebService.init();
    mAsyncDataHandler = new AsyncDataHandler(new AsyncQueryHandler(this.getContentResolver()) {
    });
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(GET_SLN_LOADER_ID) == null) {
        manager.initLoader(GET_SLN_LOADER_ID, null, this);
    }

    mPublisher = new Publisher<String>() {
        private List<Subscriber<? super String>> mSubscriberList = new ArrayList<Subscriber<? super String>>();
        private String mData;

        @Override
        public void register(Subscriber<? super String> dataSubscriber) {
            mSubscriberList.add(dataSubscriber);
            dataSubscriber.update(mData);
        }

        @Override
        public void publish(String data) {
            mData = data;
            for (Subscriber<? super String> subscriber : mSubscriberList) {
                subscriber.update(data);
            }
        }
    };
}

From source file:com.android.browser.BookmarksPageCallbacks.java

/**
 * @param uri/*from  w w w  .  java 2s .com*/
 */
private void loadFolder(int groupPosition, Uri uri) {
    LoaderManager manager = getLoaderManager();
    // This assumes groups are ordered the same as loaders
    BookmarksLoader loader = (BookmarksLoader) ((Loader<?>) manager
            .getLoader(LOADER_BOOKMARKS + groupPosition));
    loader.setUri(uri);
    loader.forceLoad();
}

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;//  w w  w .ja  va 2 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.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/*  w  ww .  ja va 2s. 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  w  w .  ja  va 2 s.  c  om*/
 */
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

/**
 * 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)
 *///w w  w  .  j  av a  2 s . c  o  m
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);
    }
}

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//  ww w  .  j a v  a 2s  .  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);
    //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);
}