Example usage for android.support.v4.content CursorLoader CursorLoader

List of usage examples for android.support.v4.content CursorLoader CursorLoader

Introduction

In this page you can find the example usage for android.support.v4.content CursorLoader CursorLoader.

Prototype

public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) 

Source Link

Document

Creates a fully-specified CursorLoader.

Usage

From source file:com.example.android.honeypad.ui.NoteListFragment.java

public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created. This
    // sample only has one Loader, so we don't care about the ID.
    return new CursorLoader(getActivity(), NotesProvider.CONTENT_URI, NotesQuery.PROJECTION, null, null,
            NotesProvider.KEY_TITLE + " COLLATE LOCALIZED ASC");
}

From source file:com.example.android.gcncouponalert.app.DetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (null != mUri) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
        return new CursorLoader(getActivity(),
                //getContext(),
                mUri, DETAIL_COLUMNS, null, null, null);
    }//from  w  w  w . j  a v  a 2s. c  o m
    return null;
}

From source file:com.feathercoin.wallet.feathercoin.ui.AmountCalculatorFragment.java

public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    return new CursorLoader(activity, ExchangeRatesProvider.contentUri(activity.getPackageName()), null,
            ExchangeRatesProvider.KEY_CURRENCY_CODE, new String[] { exchangeCurrency }, null);
}

From source file:com.fbartnitzek.tasteemall.mainpager.DrinkPagerFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Log.v(LOG_TAG,/*from  w w  w. jav  a2s  . c om*/
            "onCreateLoader, hashCode=" + this.hashCode() + ", " + "id = [" + id + "], args = [" + args + "]");
    switch (id) {
    case DRINK_LOADER_ID:

        String pattern = ((MainActivity) getActivity()).getSearchPattern();
        String drinkType = Utils.getDrinkTypeFromSharedPrefs(getActivity(), true);

        if (jsonUri == null) {
            // private static final String DRINKS_OR_PRODUCERS_BY_NAME_AND_TYPE_SELECTION =
            //                    "(" + DA + "." + Drink.NAME + " LIKE ? OR " + PA + "." + Producer.NAME + " LIKE ?)" +
            //                            " AND " + DA + "." + Drink.TYPE + " = ?";

            // TODO: performance of static jsonObject...?

            Log.v(LOG_TAG, "onCreateLoader before jsonCreation, hashCode=" + this.hashCode() + ", " + "id = ["
                    + id + "], args = [" + args + "]");
            try {
                String encodedValue = DatabaseContract.encodeValue(pattern);
                if (jsonTextFilter == null) { //reuse it every time
                    jsonTextFilter = new JSONObject().put(Drink.ENTITY,
                            new JSONObject().put(DatabaseContract.OR,
                                    new JSONObject().put(Drink.ENTITY,
                                            new JSONObject().put(Drink.NAME, new JSONObject()).put(
                                                    Producer.ENTITY,
                                                    new JSONObject().put(Producer.NAME, new JSONObject())))));
                }

                jsonTextFilter.getJSONObject(Drink.ENTITY).getJSONObject(DatabaseContract.OR)
                        .getJSONObject(Drink.ENTITY).getJSONObject(Drink.NAME)
                        .put(DatabaseContract.Operations.CONTAINS, encodedValue);
                jsonTextFilter.getJSONObject(Drink.ENTITY).getJSONObject(DatabaseContract.OR)
                        .getJSONObject(Drink.ENTITY).getJSONObject(Producer.ENTITY).getJSONObject(Producer.NAME)
                        .put(DatabaseContract.Operations.CONTAINS, encodedValue);

                if (Drink.TYPE_ALL.equals(drinkType)) {
                    jsonTextFilter.getJSONObject(Drink.ENTITY).remove(Drink.TYPE);
                } else {
                    jsonTextFilter.getJSONObject(Drink.ENTITY).put(Drink.TYPE, new JSONObject()
                            .put(DatabaseContract.Operations.IS, DatabaseContract.encodeValue(drinkType)));
                }

                jsonUri = DatabaseContract.buildUriWithJson(jsonTextFilter);
                Log.v(LOG_TAG, "onCreateLoader after jsonCreation, hashCode=" + this.hashCode() + ", "
                        + "id = [" + id + "], args = [" + args + "]");
            } catch (JSONException | UnsupportedEncodingException e) {
                e.printStackTrace();
                Log.e(LOG_TAG, "onCreateLoader building jsonUri failed, hashCode=" + this.hashCode() + ", "
                        + "pattern= [" + pattern + "], drinkType= [" + drinkType + "]");
                throw new RuntimeException("building jsonUri failed");
            }
        }

        return new CursorLoader(getActivity(), jsonUri,
                QueryColumns.MainFragment.DrinkWithProducerQuery.COLUMNS, null, null,
                DatabaseContract.ProducerEntry.ALIAS + "." + Producer.NAME + ", "
                        + DatabaseContract.DrinkEntry.ALIAS + "." + Drink.NAME);

    default:
        throw new RuntimeException("wrong loader_id in DrinkPagerFragment...");
    }
}

From source file:com.gbozza.android.stockhawk.ui.StockFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(mContext, Contract.Quote.URI, Contract.Quote.QUOTE_COLUMNS.toArray(new String[] {}),
            null, null, Contract.Quote.COLUMN_SYMBOL);
}

From source file:com.alboteanu.android.sunshine.app.DetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (null != mUri) {
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
        return new CursorLoader(getActivity(), mUri, DETAIL_COLUMNS, null, null, null);
    }/* w ww  .java  2 s  . c o m*/
    ViewParent vp = getView().getParent();
    if (vp instanceof CardView) {
        ((View) vp).setVisibility(View.INVISIBLE);
    }
    return null;
}

From source file:com.adkdevelopment.earthquakesurvival.ui.RecentFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    int sort = Utilities.getSortingPreference(getContext());
    String sortingPreference = EarthquakeColumns.TIME;

    String sortOrder = " DESC";
    switch (sort) {
    case EarthquakeObject.SORT_MAGNITUDE:
        sortingPreference = EarthquakeColumns.MAG;
        break;/*from  ww  w.  ja  v a 2  s. com*/
    case EarthquakeObject.SORT_TIME:
        sortingPreference = EarthquakeColumns.TIME;
        break;
    case EarthquakeObject.SORT_DISTANCE:
        sortingPreference = EarthquakeColumns.DISTANCE;
        sortOrder = " ASC";
        break;
    }

    return new CursorLoader(getActivity(), EarthquakeColumns.CONTENT_URI, null, EarthquakeColumns.MAG + " >= ?",
            new String[] { String.valueOf(Utilities.getMagnitudePrefs(getContext())) },
            sortingPreference + sortOrder);
}

From source file:com.dustinmreed.openwifi.DetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (null != mUri) {
        Log.e(LOG_TAG, mUri.toString());
        // Now create and return a CursorLoader that will take care of
        // creating a Cursor for the data being displayed.
        return new CursorLoader(getActivity(), mUri, DETAIL_COLUMNS, null, null, null);
    }/*from www.j  av a2  s.com*/
    return null;
}

From source file:ca.qc.bdeb.info.horus.ForecastFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    // This is called when a new Loader needs to be created.  This
    // fragment only uses one loader, so we don't care about checking the id.

    // To only show current and future dates, filter the query to return weather only for
    // dates after or including today.

    // Sort order:  Ascending, by date.
    String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";

    String locationSetting = Utility.getPreferredLocation(getActivity());
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting,
            System.currentTimeMillis());

    return new CursorLoader(getActivity(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder);
}

From source file:com.g11x.checklistapp.ChecklistItemActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (checklistContentObserver != null) {
        getContentResolver().unregisterContentObserver(checklistContentObserver);
    }/*w w  w  .  j a  va  2s . c  om*/
    checklistContentObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistItemActivity.this);
            super.onChange(selfChange);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistItemActivity.this);
            super.onChange(selfChange, uri);
        }
    };
    getContentResolver().registerContentObserver(Database.ChecklistItem.CONTENT_URI, true,
            checklistContentObserver);

    return new CursorLoader(ChecklistItemActivity.this, Database.ChecklistItem.CONTENT_URI,
            ChecklistItem.PROJECTION, null, null, null);
}