Android Open Source - UniversalLoader U L Fragment Impl






From Project

Back to project page UniversalLoader.

License

The source code is released under:

Apache License

If you think the Android project UniversalLoader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.michaelflisar.universalloader;
/*from  www .j a v a2 s.  c o  m*/
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.michaelflisar.universalloader.data.fragments.ULFragmentLoaderData.ULLoaderType;
import com.michaelflisar.universalloader.data.fragments.ULFragmentLoaders;
import com.michaelflisar.universalloader.data.main.ULFragmentKey;
import com.michaelflisar.universalloader.data.main.ULKey;
import com.michaelflisar.universalloader.data.main.ULResult;
import com.michaelflisar.universalloader.helper.ULDebugger;
import com.michaelflisar.universalloader.helper.ULDebugger.DebugMode;
import com.michaelflisar.universalloader.interfaces.IFragmentImplParent;
import com.michaelflisar.universalloader.interfaces.IUniversalLoaderListener;
import com.michaelflisar.universalloader.interfaces.IUniversalLoaderProvider;
import com.michaelflisar.universalloaderfragment.R;

public class ULFragmentImpl implements IUniversalLoaderListener
{
    private IFragmentImplParent mParent = null;
    private ULFragmentKey mFKey = null;
    private IUniversalLoaderProvider mProvider = null;

    private ViewGroup mMainView = null;
    private View mLoadingView = null;

    private boolean mAutomaticLoadingOverlayEnabled = true;

    public ULFragmentImpl(IFragmentImplParent parent)
    {
        mParent = parent;
        mFKey = mParent.createFragmentKey();
    }

    // -----------------------------
    // handling fragment functions
    // ordered by lifecycle
    // -----------------------------

    public void onAttach()
    {

    }

    public void onCreate()
    {

    }

    public ViewGroup onCreateView(LayoutInflater inflater, ViewGroup container, View userView)
    {
        mMainView = (ViewGroup) inflater.inflate(R.layout.loader_fragment, container, false);
        mLoadingView = mMainView.findViewById(R.id.loading_overlay);
        mMainView.addView(userView, 0);
        return mMainView;
    }

    public void onActivityCreated(IUniversalLoaderProvider provider, ULFragmentLoaders loaders)
    {
        mProvider = provider;
        mProvider.getUniversalLoader().putLoaderData(mFKey, loaders);
        mProvider.getUniversalLoader().register(this, true, ULLoaderType.OnViewCreated);
        mProvider.getUniversalLoader().deliverAlreadyLoadedData(this, ULLoaderType.OnViewCreated);
        mProvider.getUniversalLoader().startAllLoadersAutomatically(mFKey, ULLoaderType.OnViewCreated);
    }

    public void onStart()
    {
        mProvider.getUniversalLoader().deliverAlreadyLoadedData(this, ULLoaderType.OnStart);
        mProvider.getUniversalLoader().startAllLoadersAutomatically(mFKey, ULLoaderType.OnStart);
    }

    public void onResume()
    {
        if (mAutomaticLoadingOverlayEnabled && mProvider.getUniversalLoader().isAllDataLoaded(mFKey))
            setLoadingState(false);
    }

    public void onPause()
    {

    }

    public void onStop()
    {

    }

    public void onDestroyView()
    {
        mProvider.getUniversalLoader().unregister(this);
        mMainView = null;
        mLoadingView = null;
    }

    public void onDestroy()
    {
        mParent = null;
        mProvider = null;
    }

    public void onDetach()
    {

    }

    // -----------------------------
    // functions
    // -----------------------------

    public void disableAutomaticLoadingOverlay()
    {
        mAutomaticLoadingOverlayEnabled = false;
    }

    public void setLoadingState(boolean enabled)
    {
        if (mLoadingView != null)
            mLoadingView.setVisibility(enabled ? View.VISIBLE : View.GONE);
    }

    // ------------------
    // IUniversalLoader callbacks
    // ------------------

    @Override
    public ULFragmentKey getFragmentKey()
    {
        return mFKey;
    }

    @Override
    public void onLoaderStarted()
    {
        if (mAutomaticLoadingOverlayEnabled)
            setLoadingState(true);
        if (mParent != null)
            mParent.onLoaderStarted();
    }

    @Override
    public void onDataReceived(ULKey key, ULResult result)
    {
        ULDebugger.debug(DebugMode.SIMPLE, getClass(), "onDataReceived: " + key);
        mParent.onDataReceived(key, result);
        if (mAutomaticLoadingOverlayEnabled && mProvider != null)
        {
            // check if ALL loaders have loaded their data
            if (mProvider.getUniversalLoader().isAllDataLoaded(mFKey))
                setLoadingState(false);
        }
    }
}




Java Source Code List

com.michaelflisar.universalloader.ULActivity.java
com.michaelflisar.universalloader.ULFragmentImpl.java
com.michaelflisar.universalloader.UniversalLoader.java
com.michaelflisar.universalloader.data.fragments.ULFragmentLoaderData.java
com.michaelflisar.universalloader.data.fragments.ULFragmentLoaders.java
com.michaelflisar.universalloader.data.main.ULFragmentKey.java
com.michaelflisar.universalloader.data.main.ULKey.java
com.michaelflisar.universalloader.data.main.ULLoaderDataManager.java
com.michaelflisar.universalloader.data.main.ULResultManager.java
com.michaelflisar.universalloader.data.main.ULResult.java
com.michaelflisar.universalloader.data.main.ULTaskManager.java
com.michaelflisar.universalloader.data.main.ULTask.java
com.michaelflisar.universalloader.demo.Helper.java
com.michaelflisar.universalloader.demo.TestActivity.java
com.michaelflisar.universalloader.demo.TestLoaderFragment.java
com.michaelflisar.universalloader.fragments.ULDialogFragment.java
com.michaelflisar.universalloader.fragments.ULFragment.java
com.michaelflisar.universalloader.helper.ULDebugger.java
com.michaelflisar.universalloader.helper.ULHelper.java
com.michaelflisar.universalloader.interfaces.IFragmentImplParent.java
com.michaelflisar.universalloader.interfaces.IUniversalLoaderListener.java
com.michaelflisar.universalloader.interfaces.IUniversalLoaderProvider.java