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:com.example.android.newsapp.NewsActivity.java

public void updateUi() {
    ListView newsListView = (ListView) findViewById(R.id.list);

    mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
    newsListView.setEmptyView(mEmptyStateTextView);

    mAdapter = new NewsAdapter(this, new ArrayList<NewsEvent>());

    newsListView.setAdapter(mAdapter);/*  ww w  .  j a v a 2 s  .c o m*/

    newsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            NewsEvent currentNewsEvent = mAdapter.getItem(position);

            Uri currentNewsEventUri = Uri.parse(currentNewsEvent.getUrl());

            Intent websiteIntent = new Intent(Intent.ACTION_VIEW, currentNewsEventUri);

            startActivity(websiteIntent);
        }
    });

    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        LoaderManager loaderManager = getLoaderManager();
        loaderManager.initLoader(NEWS_LOADER_ID, null, this);
    } else {
        View loadingIndicator = findViewById(R.id.loading_indicator);
        loadingIndicator.setVisibility(View.GONE);

        mEmptyStateTextView.setText(R.string.no_internet_connection);
    }
}

From source file:ph.devcon.android.news.service.NewsServiceImpl.java

@Override
public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<News>>() {
        @Override/*from  w w w.j  a  v a2s .  c  o  m*/
        public Loader<List<News>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, newsDao, newsDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public void onLoadFinished(Loader<List<News>> loader, List<News> data) {
            if (data != null) {
                eventBus.post(new FetchedNewsListEvent(data));
            } else {
                eventBus.post(new FetchedNewsListFailedEvent());
            }
        }

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

From source file:ph.devcon.android.program.service.ProgramServiceImpl.java

public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<Program>>() {
        @Override//w ww.  j  av a2  s  .c  om
        public Loader<List<Program>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, programDao, programDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public void onLoadFinished(Loader<List<Program>> loader, List<Program> data) {
            if (data != null) {
                eventBus.post(new FetchedProgramListEvent(data));
            } else {
                eventBus.post(new FetchedProgramListFailedEvent());
            }
        }

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

From source file:ph.devcon.android.sponsor.service.SponsorServiceImpl.java

public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<Sponsor>>() {
        @Override//  w w w.java2 s .c  o m
        public Loader<List<Sponsor>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, sponsorDao, sponsorDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

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

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

From source file:ph.devcon.android.news.service.NewsServiceImpl.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<News>>() {
                @Override//from www .ja  va  2  s  .  c  o  m
                public android.support.v4.content.Loader<List<News>> onCreateLoader(int id, Bundle args) {
                    try {
                        return new OrmliteListLoaderSupport<News, Integer>(context, newsDao,
                                newsDao.queryBuilder().prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

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

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

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

public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<Attendee>>() {
        @Override//from   w w  w.j ava  2 s.co m
        public Loader<List<Attendee>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, attendeeDao, attendeeDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

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

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

From source file:ph.devcon.android.program.service.ProgramServiceImpl.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<Program>>() {
                @Override//ww  w  .  j ava2 s. c  om
                public android.support.v4.content.Loader<List<Program>> onCreateLoader(int id, Bundle args) {
                    try {
                        return new OrmliteListLoaderSupport<Program, Integer>(context, programDao,
                                programDao.queryBuilder().prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

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

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

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

public void populateFromCache(LoaderManager loaderManager, Bundle savedInstanceState) {
    loaderManager.initLoader(0, savedInstanceState, new LoaderManager.LoaderCallbacks<List<Profile>>() {
        @Override//from   w ww  .  j a  va 2 s  .c  om
        public Loader<List<Profile>> onCreateLoader(int id, Bundle args) {
            try {
                return new OrmliteListLoader(context, profileDao, profileDao.queryBuilder().prepare());
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public void onLoadFinished(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(Loader<List<Profile>> loader) {
        }
    });
}

From source file:ph.devcon.android.sponsor.service.SponsorServiceImpl.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<Sponsor>>() {
                @Override//w w w. ja  va  2  s .c o  m
                public android.support.v4.content.Loader<List<Sponsor>> onCreateLoader(int id, Bundle args) {
                    try {
                        return new OrmliteListLoaderSupport<Sponsor, Integer>(context, sponsorDao,
                                sponsorDao.queryBuilder().prepare());
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

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

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

From source file:ph.devcon.android.attendee.service.AttendeeServiceImpl.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<Attendee>>() {
                @Override//ww  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().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) {
                }
            });
}