Example usage for android.app LoaderManager initLoader

List of usage examples for android.app LoaderManager initLoader

Introduction

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

Prototype

public abstract <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);

Source Link

Document

Ensures a loader is initialized and active.

Usage

From source file:ph.devcon.android.profile.service.ProfileServiceImpl.java

@Override
public void populateFromCache(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Profile>>() {
                @Override// ww  w  .j av  a 2 s.co  m
                public android.support.v4.content.Loader<List<Profile>> onCreateLoader(int id, Bundle args) {
                    try {
                        return new OrmliteListLoaderSupport<Profile, Integer>(context, profileDao,
                                profileDao.queryBuilder().prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Profile>> loader,
                        List<Profile> data) {
                    if ((data != null) && (data.size() > 0)) {
                        eventBus.post(new FetchedProfileEvent(data.get(0)));
                    } else {
                        eventBus.post(new FetchedProfileFailedEvent("Cache was empty.."));
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Profile>> loader) {
                }
            });
}

From source file:ph.devcon.android.attendee.service.AttendeeServiceImpl.java

@Override
public void populateFromIdList(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState,
        final List<Integer> idList) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Attendee>>() {
                @Override//from  w w w.  j a  va  2 s. c  o  m
                public android.support.v4.content.Loader<List<Attendee>> onCreateLoader(int id, Bundle args) {
                    try {
                        return new OrmliteListLoaderSupport(context, attendeeDao,
                                attendeeDao.queryBuilder().where().in("id", idList).prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Attendee>> loader,
                        List<Attendee> data) {
                    if (data != null) {
                        eventBus.post(new FetchedAttendeeListEvent(data));
                    } else {
                        eventBus.post(new FetchedAttendeeListFailedEvent());
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Attendee>> loader) {
                }
            });
}

From source file:ph.devcon.android.speaker.service.SpeakerServiceImpl.java

public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<Speaker>>() {
        @Override//  w  ww.ja v a 2 s . com
        public Loader<List<Speaker>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, speakerDao, speakerDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public void onLoadFinished(Loader<List<Speaker>> loader, List<Speaker> data) {
            if (data != null) {
                eventBus.postSticky(new FetchedSpeakerListEvent(data));
            } else {
                eventBus.postSticky(new FetchedSpeakerListFailedEvent());
            }
        }

        @Override
        public void onLoaderReset(Loader<List<Speaker>> loader) {
        }
    });
}

From source file:ph.devcon.android.speaker.service.SpeakerServiceImpl.java

@Override
public void getAll(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Speaker>>() {
                @Override/*from  w w w  .  j  ava 2  s  . c o m*/
                public android.support.v4.content.Loader<List<Speaker>> onCreateLoader(int i, Bundle bundle) {
                    try {
                        return new OrmliteListLoaderSupport(context, speakerDao, speakerDao.getAll());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Speaker>> loader,
                        List<Speaker> data) {
                    if (data != null) {
                        eventBus.postSticky(new FetchedAllSpeakerListEvent(data));
                    } else {
                        eventBus.postSticky(new FetchedSpeakerListFailedEvent());
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Speaker>> objectLoader) {
                }
            });
}

From source file:ph.devcon.android.speaker.service.SpeakerServiceImpl.java

@Override
public void getSpeakers(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Speaker>>() {
                @Override/*ww  w . jav a2 s  .  c o  m*/
                public android.support.v4.content.Loader<List<Speaker>> onCreateLoader(int i, Bundle bundle) {
                    try {
                        return new OrmliteListLoaderSupport(context, speakerDao, speakerDao.getSpeakers());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Speaker>> loader,
                        List<Speaker> data) {
                    if (data != null) {
                        eventBus.postSticky(new FetchedSpeakerListEvent(data));
                    } else {
                        eventBus.postSticky(new FetchedSpeakerListFailedEvent());
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Speaker>> objectLoader) {
                }
            });
}

From source file:ph.devcon.android.speaker.service.SpeakerServiceImpl.java

@Override
public void getPanels(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Speaker>>() {
                @Override/*from   w  w  w. ja  v  a  2 s . c  o  m*/
                public android.support.v4.content.Loader<List<Speaker>> onCreateLoader(int i, Bundle bundle) {
                    try {
                        return new OrmliteListLoaderSupport(context, speakerDao, speakerDao.getPanels());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Speaker>> loader,
                        List<Speaker> data) {
                    if (data != null) {
                        eventBus.postSticky(new FetchedPanelSpeakerListEvent(data));
                    } else {
                        eventBus.postSticky(new FetchedSpeakerListFailedEvent());
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Speaker>> objectLoader) {
                }
            });
}

From source file:ph.devcon.android.speaker.service.SpeakerServiceImpl.java

/**
 * to slowly move to supporting older versions
 *
 * @param loaderManager/* w ww.j  a va  2 s  .co  m*/
 * @param savedInstanceState
 */
@Override
public void populateFromCache(android.support.v4.app.LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState,
            new android.support.v4.app.LoaderManager.LoaderCallbacks<List<Speaker>>() {
                @Override
                public android.support.v4.content.Loader<List<Speaker>> onCreateLoader(int i, Bundle bundle) {
                    try {
                        return new OrmliteListLoaderSupport(context, speakerDao,
                                speakerDao.queryBuilder().prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                public void onLoadFinished(android.support.v4.content.Loader<List<Speaker>> loader,
                        List<Speaker> data) {
                    if (data != null) {
                        eventBus.postSticky(new FetchedSpeakerListEvent(data));
                    } else {
                        eventBus.postSticky(new FetchedSpeakerListFailedEvent());
                    }
                }

                @Override
                public void onLoaderReset(android.support.v4.content.Loader<List<Speaker>> objectLoader) {
                }
            });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_activity);
    setupViews();/*w ww  . jav  a  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.gumgoose.app.quakebuddy.EarthquakeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.earthquake_activity);

    // Monitor upgrades in QuakeBuddy and trigger the changes dialog
    detectVersionChange();/*from  ww w  .  java 2  s .c om*/

    // Find a reference to the ListView in the layout
    ListView earthquakeListView = (ListView) findViewById(R.id.list);

    // Find a reference to the loading indicator in the layout
    mLoadingIndicator = findViewById(R.id.loading_indicator);

    // Find a reference to the empty list View placeholder
    mEmptyStateView = findViewById(R.id.empty_view);

    // Find a reference to the empty list TextView placeholder
    mEmptyTextView = (TextView) findViewById(R.id.empty_message);

    // Set the empty state View to display when the ListView is empty
    earthquakeListView.setEmptyView(mEmptyStateView);

    // Make a new adapter and enable it on the earthquake ListView
    mAdapter = new QuakeAdapter(this, new ArrayList<Quake>());
    earthquakeListView.setAdapter(mAdapter);

    // Find a reference to the swipe to refresh feature
    swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);
    swipe.setOnRefreshListener(EarthquakeActivity.this);
    swipe.setColorSchemeColors(getResources().getColor(R.color.colorAccent));

    // Set an OnItemClick listener on the ListView
    earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // Fetch the USGS earthquake URL and check whether the URL is valid
            String quakeUrl = mAdapter.getItem(position).getQuakeURL();

            if (URLUtil.isValidUrl(quakeUrl)) {
                // URL is valid, start WebViewActivity with URL intent
                Intent websiteIntent = new Intent(EarthquakeActivity.this, WebViewActivity.class);
                websiteIntent.putExtra("url", quakeUrl);
                startActivity(websiteIntent);
            } else {
                // Inform the user by Toast message and exit gracefully
                Toast.makeText(EarthquakeActivity.this, R.string.error_invalid_url, Toast.LENGTH_LONG).show();
            }
        }
    });

    // Connect to the ConnectivityManager system service
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    // Check whether there is an active network connection
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        // Network detected, initialize the Loader
        LoaderManager loaderManager = getLoaderManager();
        loaderManager.initLoader(EARTHQUAKE_LOADER_ID, null, this);
    } else {
        // Display the empty View on ListView with no internet message
        mLoadingIndicator.setVisibility(View.GONE);
        swipe.setRefreshing(false);
        mEmptyTextView.setText(R.string.no_internet_connection);
        mEmptyStateView.setVisibility(View.VISIBLE);
    }
}

From source file:com.sintef_energy.ubisolar.fragments.UsageFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mDevices = new LinkedHashMap<>();

    if (savedInstanceState != null && mSavedState == null)
        mSavedState = savedInstanceState.getBundle("mSavedState");

    LoaderManager loaderManager = getLoaderManager();

    //Get devices
    if (mSavedState != null) {
        mDeviceUsageList = mSavedState.getParcelableArrayList("mDeviceUsageList");
        loaderManager.restartLoader(LOADER_DEVICES, null, this);
    } else {//from  ww w.j a  v  a2s  . co m
        mDeviceUsageList = new ArrayList<>();
        loaderManager.initLoader(LOADER_DEVICES, null, this);
    }

    mPreferenceManager.setNavDrawerUsage(0);
    Intent i = new Intent(Global.BROADCAST_NAV_DRAWER);
    i.putExtra(Global.DATA_B_NAV_DRAWER_USAGE, 0);
    LocalBroadcastManager.getInstance(this.getActivity().getApplicationContext()).sendBroadcast(i);
}