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.jaspersoft.android.jaspermobile.activities.storage.fragment.SavedItemsFragment.java

@Override
public Loader<Cursor> onCreateLoader(int code, Bundle bundle) {
    StringBuilder selection = new StringBuilder("");
    ArrayList<String> selectionArgs = new ArrayList<String>();

    //Add general items (server id = -1)
    selection.append("(").append(SavedItemsTable.ACCOUNT_NAME + " =?").append("  OR ");

    selectionArgs.add(JasperSettings.RESERVED_ACCOUNT_NAME);

    //Add server profile id to WHERE params
    selection.append(SavedItemsTable.ACCOUNT_NAME + " =?");
    selectionArgs.add(mProfile.getKey());

    // Close select brackets
    selection.append(")");

    //Add filtration to WHERE params
    selection.append(" AND (");

    Iterator<String> iterator = storageResourceFilter.getCurrent().getValues().iterator();
    while (iterator.hasNext()) {
        selection.append(SavedItemsTable.FILE_FORMAT + " =?");
        selectionArgs.add(iterator.next());
        if (iterator.hasNext()) {
            selection.append(" OR ");
        }// w w w  .  ja  v  a 2s.  c  o m
    }

    selection.append(")");

    //Add sorting type to WHERE params
    String sortOrderString;
    if (sortOrder != null && sortOrder.getValue().equals(SortOrder.CREATION_DATE.getValue())) {
        sortOrderString = SavedItemsTable.CREATION_TIME + " DESC";
    } else {
        sortOrderString = SavedItemsTable.NAME + " COLLATE NOCASE ASC";
    }

    //Add search query to WHERE params
    boolean inSearchMode = searchQuery != null;
    if (inSearchMode) {
        selection.append(" AND ").append(SavedItemsTable.NAME + " LIKE ?");
        selectionArgs.add("%" + searchQuery + "%");
    }

    return new CursorLoader(getActivity(), JasperMobileDbProvider.SAVED_ITEMS_CONTENT_URI,
            SavedItemsTable.ALL_COLUMNS, selection.toString(),
            selectionArgs.toArray(new String[selectionArgs.size()]), sortOrderString);
}

From source file:com.chatwing.whitelabel.fragments.CommunicationDrawerFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    LogUtils.v("Loader running " + id);

    switch (id) {
    case LOADER_ID_COUNT_CONVERSATIONS_MESSAGES_UNREAD:
        Uri uri = ChatWingContentProvider.getConversationsUri();
        return new CursorLoader(getActivity(), uri,
                new String[] {
                        "sum(" + ConversationTable.UNREAD_COUNT + ") as " + COLUMN_NAME_SUM_UNREAD_COUNT, },
                null, null, null);/*from w w  w  .  jav a 2s .c om*/
    case LOADER_ID_CHATBOXES:
        uri = ChatWingContentProvider.getCategorizedChatBoxesUri();
        return new CursorLoader(getActivity(), uri,
                new String[] { "sum(" + ChatBoxTable.UNREAD_COUNT + ") as " + COLUMN_NAME_SUM_UNREAD_COUNT, },
                null, null, null);
    case LOADER_ID_SYNCED_BOOKMARKS:
        uri = ChatWingContentProvider.getSyncedBookmarksUri();
        return new CursorLoader(
                getActivity(), uri, new String[] { "sum(" + ChatBoxTable.TABLE_CHAT_BOX + "."
                        + ChatBoxTable.UNREAD_COUNT + ") as " + COLUMN_NAME_SUM_UNREAD_COUNT, },
                null, null, null);
    default:
        return null;
    }
}

From source file:com.katamaditya.apps.weather4u.WeatherForecastFragment.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 = WeatherUtil.getPreferredLocation(getActivity());
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting,
            System.currentTimeMillis());

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

From source file:com.gbozza.android.popularmovies.fragments.MovieGridFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    case ID_FAVOURITES_LOADER:
        Uri favouriteMoviesUri = FavouriteMovieEntry.CONTENT_URI;
        return new CursorLoader(mContext, favouriteMoviesUri, FAVOURITE_MOVIES_PROJECTION, null, null, null);
    default://from  w w  w  .ja v  a  2 s .co m
        throw new RuntimeException("Loader Not Implemented: " + id);
    }
}

From source file:com.nogago.android.tracks.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    setContentView(R.layout.track_list);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);

    getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
    metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key,
            PreferencesUtils.METRIC_UNITS_DEFAULT);
    recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);

    //    ImageButton recordImageButton = (ImageButton) findViewById(R.id.track_list_record_button);
    //    recordImageButton.setOnClickListener(new View.OnClickListener() {
    //      @Override
    //      public void onClick(View v) {
    //        updateMenuItems(true);
    //        startRecording();
    //      }/* w ww .ja v a 2 s .  c  o  m*/
    //    });

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(intent);
        }
    });
    resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);

            boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
            String name = cursor.getString(nameIndex);
            int iconId = isRecording ? R.drawable.menu_record_track
                    : TrackIconUtils.getIconDrawable(cursor.getString(iconIndex));
            String iconContentDescription = getString(
                    isRecording ? R.string.icon_recording : R.string.icon_track);
            String category = cursor.getString(categoryIndex);
            String totalTime = isRecording ? null
                    : StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = isRecording ? null
                    : StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex),
                            metricUnits);
            long startTime = cursor.getLong(startTimeIndex);
            String description = cursor.getString(descriptionIndex);
            ListItemUtils.setListItem(TrackListActivity.this, view, name, iconId, iconContentDescription,
                    category, totalTime, totalDistance, startTime, description);
        }
    };
    listView.setAdapter(resourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
            return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null, null,
                    TracksColumns._ID + " DESC");
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            resourceCursorAdapter.swapCursor(cursor);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            resourceCursorAdapter.swapCursor(null);
        }
    });
    showStartupDialogs();
}

From source file:com.example.amit.tellymoviebuzzz.PopularSeriesFragment.java

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    // String locationSetting = Utility.getPreferredLocation(getActivity());
    String movie = Utility.getPreferredMovie(getActivity());
    // Sort order:  Ascending, by date.
    // String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    // Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
    //       locationSetting, System.currentTimeMillis());

    Uri movieForMovieIdUri = MovieContract.MovieNumberEntry.buildMovieType(movie);
    String sortOrder = null;/*from  www  . j a v a 2s .c  o m*/

    String sSeriesID = MovieContract.SeriesNumberEntry.TABLE_NAME + "."
            + MovieContract.SeriesNumberEntry.COLUMN_SERIES_CATEGORY + " = ? ";

    /*   Cursor locationCursor1 = mContext.getContentResolver().query(
        MovieContract.SeriesNumberEntry.CONTENT_URI,
        new String[]{MovieContract.SeriesNumberEntry.COLUMN_SERIES_FOLLOWING},
        sSeriesID,
        new String[]{"popular"},
        null);
            
            
       int count = locationCursor1.getCount();
            
       arr = new boolean[count];
            
       if (locationCursor1.moveToFirst()) {
            
    while (locationCursor1.isAfterLast() == false) {
        String following = locationCursor1.getString(locationCursor1
                .getColumnIndex(MovieContract.SeriesNumberEntry.COLUMN_SERIES_FOLLOWING));
            
        if(following=="yes")
            arr[locationCursor1.getPosition()] = true;
        else
            arr[locationCursor1.getPosition()] = false;
            
    }
            
    locationCursor1.moveToNext();
       }
            
    */
    String sSeriesTypeWithSeriesID = MovieContract.SeriesNumberEntry.TABLE_NAME + "."
            + MovieContract.SeriesNumberEntry.COLUMN_SERIES_CATEGORY + " = ? ";

    return new CursorLoader(getActivity(), MovieContract.SeriesNumberEntry.CONTENT_URI, FORECAST_SERIES_COLUMNS,
            sSeriesTypeWithSeriesID, new String[] { "popular" }, sortOrder);
}

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

public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    final Uri uri = AddressBookProvider.contentUri(activity.getPackageName());
    return new CursorLoader(activity, uri, null, AddressBookProvider.SELECTION_NOTIN,
            new String[] { walletAddressesSelection != null ? walletAddressesSelection : "" },
            AddressBookProvider.KEY_LABEL + " COLLATE LOCALIZED ASC");
}

From source file:com.orangelabs.rcs.ri.messaging.chat.single.SingleChatView.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    /* Create a new CursorLoader with the following query parameters. */
    return new CursorLoader(this, mUriHistoryProvider, PROJ_CHAT_MSG, WHERE_CLAUSE,
            new String[] { mContact.toString() }, ORDER_CHAT_MSG);
}

From source file:com.dwdesign.tweetings.fragment.DMConversationFragment.java

@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    if (args == null || !args.containsKey(INTENT_KEY_ACCOUNT_ID))
        return new CursorLoader(getActivity(), TweetStore.NULL_CONTENT_URI, null, null, null, null);
    final String[] cols = DirectMessages.COLUMNS;
    final long account_id = args != null ? args.getLong(INTENT_KEY_ACCOUNT_ID, -1) : -1;
    final long conversation_id = args != null ? args.getLong(INTENT_KEY_CONVERSATION_ID, -1) : -1;
    final String screen_name = args != null ? args.getString(INTENT_KEY_SCREEN_NAME) : null;
    final Uri uri = buildDirectMessageConversationUri(account_id, conversation_id, screen_name);
    mConversationContainer.setVisibility(
            account_id <= 0 || conversation_id <= 0 && screen_name == null ? View.GONE : View.VISIBLE);
    mScreenNameContainer.setVisibility(/* ww w  .j  a v  a2s.co  m*/
            account_id <= 0 || conversation_id <= 0 && screen_name == null ? View.VISIBLE : View.GONE);
    return new CursorLoader(getActivity(), uri, cols, null, null,
            DirectMessages.Conversation.DEFAULT_SORT_ORDER);
}

From source file:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.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.
    Uri rateUri = ForexContract.RateEntry.buildStartCurrencyWithDate(mMainCurrency.getId(),
            Utility.getForexSyncDate(mContext));

    return new CursorLoader(getActivity(), rateUri, ForexContract.RATE_CURRENCY_COLUMNS, null, null, null);
}