Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

In this page you can find the example usage for android.database Cursor moveToNext.

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

From source file:heartware.com.heartware_master.DBAdapter.java

public HashMap<String, String> getMeetupInfo(final String note, final String userId) {
    HashMap<String, String> workoutMap = new HashMap<String, String>();
    SQLiteDatabase database = this.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + MEETUPS_TABLE + " WHERE " + NOTE + "='" + note + "'" + " AND "
            + USER_ID + " = " + userId;
    Cursor cursor = database.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {//from w ww.  j  ava  2s .com
            workoutMap.put(USER_ID, cursor.getString(0));
            workoutMap.put(NOTE, cursor.getString(1));
            workoutMap.put(EXERCISE, cursor.getString(2));
            workoutMap.put(LOCATION, cursor.getString(3));
            workoutMap.put(DATE, cursor.getString(4));
            workoutMap.put(PEOPLE, cursor.getString(5));
        } while (cursor.moveToNext());
    }
    return workoutMap;
}

From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java

/**
 * Upload any outstanding classifications.
 *
 * @return Return true if we know for sure that no further uploading is currently necessary.
 *///from  w w w . j av  a2s  .c o m
private boolean uploadOutstandingClassifications() {
    //To keep things simple, don't do this while it is already happening.
    //This only ever happens on this thread so there should be no need for a lock here.
    if (mUploadsInProgress > 0)
        return false;

    // TODO: Request re-authentication when the server says we have used the wrong name + api_key.
    // What does the server reply in that case?
    // See https://github.com/zooniverse/Galaxy-Zoo/issues/184
    final LoginUtils.LoginDetails loginDetails = LoginUtils.getAccountLoginDetails(getContext());

    // query the database for any item whose classification is not yet uploaded.
    final ContentResolver resolver = getContentResolver();

    final String[] projection = { Item.Columns._ID, Item.Columns.SUBJECT_ID };
    final String whereClause = "(" + Item.Columns.DONE + " == 1) AND " + "(" + Item.Columns.UPLOADED + " != 1)";
    final Cursor c = resolver.query(Item.ITEMS_URI, projection, whereClause, new String[] {}, null); //TODO: Order by?

    if (c.getCount() == 0) {
        c.close();
        return true; //Tell the caller that no action was necessary.
    }

    while (c.moveToNext()) {
        final String itemId = c.getString(0);
        final String subjectId = c.getString(1);

        mUploadsInProgress++;
        final UploadTask task = new UploadTask(itemId, subjectId, loginDetails.name, loginDetails.authApiKey);
        final Thread thread = new Thread(task);
        thread.start();
    }

    c.close();
    return false;
}

From source file:net.fred.feedex.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_feed_edit);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w ww  . j av  a2  s . com
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    setResult(RESULT_CANCELED);

    Intent intent = getIntent();

    mTabHost = (TabHost) findViewById(R.id.tabHost);
    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View tabWidget = findViewById(android.R.id.tabs);

    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title))
            .setContent(R.id.feed_tab));
    mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title))
            .setContent(R.id.filters_tab));

    mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String s) {
            invalidateOptionsMenu();
        }
    });

    if (savedInstanceState != null) {
        mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB));
    }

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        tabWidget.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }
    } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
        setTitle(R.string.new_feed_title);

        tabWidget.setVisibility(View.GONE);
        mUrlEditText.setText(intent.getDataString());
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, Constants.EMPTY_CURSOR);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startSupportActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (savedInstanceState == null) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor != null && cursor.moveToNext()) {
                mNameEditText.setText(cursor.getString(0));
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                if (cursor.getInt(3) == 1) { // if it's a group, we cannot edit it
                    finish();
                }
            } else {
                UiUtils.showMessage(EditFeedActivity.this, R.string.error);
                finish();
            }

            if (cursor != null) {
                cursor.close();
            }
        }
    }
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private void syncCheckins(ContentProviderClient provider, String cookie) {
    Cursor cursor = null;
    try {/*from ww w . j ava  2  s  . co  m*/
        cursor = provider.query(Table.ATTENDEE.getBaseUri(),
                new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, },
                Table.Attendee.CHECKIN_MODIFIED, null, null);
        if (0 == cursor.getCount()) {
            Log.d(TAG, "No checkin to sync.");
            return;
        }
        int syncCount = 0;
        while (cursor.moveToNext()) {
            String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID));
            String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID));
            long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN));
            long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie);
            if (serverCheckin >= 0) {
                ContentValues values = new ContentValues();
                values.put(Table.Attendee.CHECKIN_MODIFIED, false);
                if (0 == serverCheckin) {
                    values.putNull(Table.Attendee.CHECKIN);
                } else {
                    values.put(Table.Attendee.CHECKIN, serverCheckin);
                }
                provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null);
                ++syncCount;
            }
        }
        Log.d(TAG, syncCount + " checkin(s) synced.");
    } catch (RemoteException e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.citrus.sdk.database.DBHandler.java

public List<OptionDetails> getSavedOptions() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor current_cursor;
    String[] columNames = { MMID, SCHEME, EXPDATE, NAME, OWNER, BANK, NUMBER, TYPE, IMPS_REGISTERED, TOKEN_ID,
            DEFAULT_OPTION };//  www .j  av a 2 s  .  c o  m
    String orderBy = DEFAULT_OPTION + " DESC";
    List<OptionDetails> savedOptions = new ArrayList<OptionDetails>();
    current_cursor = db.query(PAYOPTION_TABLE, columNames, null, null, null, null, orderBy);
    if (current_cursor.moveToFirst()) {
        do {
            OptionDetails currentOption = new OptionDetails(current_cursor);
            savedOptions.add(currentOption);
        } while (current_cursor.moveToNext());
    }
    return savedOptions;
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getBookmarksInBook(BibleBook book) {
    Log.d(TAG, "about to getBookmarksInPassage:" + book.getOSIS());
    List<BookmarkDto> bookmarkList = new ArrayList<BookmarkDto>();
    //av11n TODO may need to map between different versifications here
    Cursor c = db.query(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS, BookmarkColumn.KEY + " LIKE ?",
            new String[] { String.valueOf(book.getOSIS() + ".%") }, null, null, null);
    try {/*from w  w w .j a  va 2 s .  co  m*/
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                bookmarkList.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    Log.d(TAG, "bookmarksInPassage set to " + bookmarkList.size() + " item long list");
    return bookmarkList;
}

From source file:com.carlrice.reader.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_feed_edit);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  ww w  .  ja  va 2 s .  c  o m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    setResult(RESULT_CANCELED);

    Intent intent = getIntent();

    mTabHost = (TabHost) findViewById(R.id.tabHost);
    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View tabWidget = findViewById(android.R.id.tabs);
    View buttonLayout = findViewById(R.id.button_layout);

    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title))
            .setContent(R.id.feed_tab));
    mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title))
            .setContent(R.id.filters_tab));

    mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String s) {
            invalidateOptionsMenu();
        }
    });

    if (savedInstanceState != null) {
        mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB));
    }

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        tabWidget.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        buttonLayout.setVisibility(View.GONE);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, Constants.EMPTY_CURSOR);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startSupportActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (savedInstanceState == null) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor.moveToNext()) {
                mNameEditText.setText(cursor.getString(0));
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                cursor.close();
            } else {
                cursor.close();
                Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }
}

From source file:com.navjagpal.fileshare.WebServer.java

private void sendPlaylist(DefaultHttpServerConnection serverConnection, RequestLine requestLine)
        throws IOException, HttpException {
    HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 200, "OK");

    Cursor c = mContext.getContentResolver().query(FileSharingProvider.Files.CONTENT_URI, new String[] {
            FileSharingProvider.Files.Columns._ID, FileSharingProvider.Files.Columns.DISPLAY_NAME }, null, null,
            null);/*from  w w w  .  j a  va 2 s .  c  o m*/
    String playlist = "";
    while (c.moveToNext()) {
        long id = c.getLong(c.getColumnIndex(FileSharingProvider.Files.Columns._ID));
        String name = c.getString(c.getColumnIndex(FileSharingProvider.Files.Columns.DISPLAY_NAME));
        if (name.endsWith(".mp3")) {
            playlist += SharedFileBrowser.getShareURL(id, mContext) + "\n";
        }
    }
    c.close();
    response.addHeader("Content-Type", "audio/x-mpegurl");
    response.addHeader("Content-Length", "" + playlist.length());
    response.setEntity(new StringEntity(playlist));
    serverConnection.sendResponseHeader(response);
    serverConnection.sendResponseEntity(response);
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    if (data.moveToNext()) {
        /*//  w w w . ja v  a 2s  .c om
         * Here we have to check the column indexes by name as we have requested for all. The order may be different.
         */
        final String fileName = data
                .getString(data.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)/* 0 DISPLAY_NAME */);
        final int fileSize = data.getInt(data.getColumnIndex(MediaStore.MediaColumns.SIZE) /* 1 SIZE */);
        String filePath = null;
        final int dataIndex = data.getColumnIndex(MediaStore.MediaColumns.DATA);
        if (dataIndex != -1)
            filePath = data.getString(dataIndex /*2 DATA */);
        if (!TextUtils.isEmpty(filePath))
            mFilePath = filePath;

        mFileNameView.setText(fileName);
        mFileSizeView.setText(getString(R.string.dfu_file_size_text, fileSize));
        final boolean isHexFile = mStatusOk = MimeTypeMap.getFileExtensionFromUrl(fileName)
                .equalsIgnoreCase("HEX");
        mFileStatusView.setText(isHexFile ? R.string.dfu_file_status_ok : R.string.dfu_file_status_invalid);
        mUploadButton.setEnabled(mSelectedDevice != null && isHexFile);
    }
}

From source file:com.app.uafeed.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.activity_feed_edit);
    setResult(RESULT_CANCELED);/*from w w  w .ja va 2 s . c o m*/

    Intent intent = getIntent();

    mTabHost = (TabHost) findViewById(R.id.tabHost);
    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View tabWidget = findViewById(android.R.id.tabs);
    View buttonLayout = findViewById(R.id.button_layout);

    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title))
            .setContent(R.id.feed_tab));
    mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title))
            .setContent(R.id.filters_tab));

    mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String s) {
            invalidateOptionsMenu();
        }
    });

    if (savedInstanceState != null) {
        mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB));
    }

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        tabWidget.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        buttonLayout.setVisibility(View.GONE);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, null);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (savedInstanceState == null) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor.moveToNext()) {
                mPreviousName = cursor.getString(0);
                mNameEditText.setText(mPreviousName);
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                cursor.close();
            } else {
                cursor.close();
                Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }
}