当前位置: 首页>>代码示例>>Java>>正文


Java Cursor.getPosition方法代码示例

本文整理汇总了Java中android.database.Cursor.getPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.getPosition方法的具体用法?Java Cursor.getPosition怎么用?Java Cursor.getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.Cursor的用法示例。


在下文中一共展示了Cursor.getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExplainQueryPlan

import android.database.Cursor; //导入方法依赖的package包/类
private String[] getExplainQueryPlan() {
    Cursor cursor = db.rawQuery("EXPLAIN QUERY PLAN " + query, queryArgs);
    String[] plan = new String[cursor.getCount()];
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        // The docs at https://sqlite.org/eqp.html talk about how the output format of
        // EXPLAIN QUERY PLAN can change between SQLite versions. This has been observed
        // between the sqlite versions on Android 2.3.3 and Android 5.0. However, it seems
        // that the last column is always the one with the interesting details that we wish
        // to log. If this fails for some reason, then hey, it is only for debug builds, right?
        if (cursor.getColumnCount() > 0) {
            int index = cursor.getColumnCount() - 1;
            plan[cursor.getPosition()] = cursor.getString(index);
        }
        cursor.moveToNext();
    }
    cursor.close();
    return plan;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:20,代码来源:LoggingQuery.java

示例2: FilteringCursorWrapper

import android.database.Cursor; //导入方法依赖的package包/类
public FilteringCursorWrapper(
        Cursor cursor, String[] acceptMimes, String[] rejectMimes, long rejectBefore) {
    mCursor = cursor;

    final int count = cursor.getCount();
    mPosition = new int[count];

    cursor.moveToPosition(-1);
    while (cursor.moveToNext() && mCount < count) {
        final String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
        final String name = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME);
        final long lastModified = getCursorLong(cursor, Document.COLUMN_LAST_MODIFIED);
        if (rejectMimes != null && MimePredicate.mimeMatches(rejectMimes, mimeType)) {
            continue;
        }
        if (lastModified < rejectBefore) {
            continue;
        }

        if (MimePredicate.mimeMatches(acceptMimes, mimeType)) {
            mPosition[mCount++] = cursor.getPosition();
        }
    }

    Log.d(TAG, "Before filtering " + cursor.getCount() + ", after " + mCount);
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:27,代码来源:FilteringCursorWrapper.java

示例3: exportTable

import android.database.Cursor; //导入方法依赖的package包/类
private JSONArray exportTable(String tableName) throws JSONException {

        // get everything from the table
        String sql = "select * from " + tableName;
        Cursor cur = mDatabase.rawQuery(sql, new String[0]);
        int numCols = cur.getColumnCount();
        JSONArray resultSet = new JSONArray();
        cur.moveToFirst();

        // move through the table, creating rows
        // and adding each column with name and value
        // to the row
        while (cur.getPosition() < cur.getCount()) {
            JSONObject rowObject = new JSONObject();
            for (int idx = 0; idx < numCols; idx++) {
                rowObject.put(cur.getColumnName(idx), cur.getString(idx));
            }

            resultSet.put(rowObject);
            cur.moveToNext();
        }

        cur.close();
        return resultSet;
    }
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:26,代码来源:DatabaseDump.java

示例4: checkCursorPosition

import android.database.Cursor; //导入方法依赖的package包/类
void checkCursorPosition(Cursor cursor) throws IllegalArgumentException {
    if (cursor.getPosition() == -1) {
        throw new IllegalArgumentException(
            "Cursor position is -1. " +
            "Did you forget to moveToFirst() or move() before passing to the value object?");
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:8,代码来源:ValueObject.java

示例5: migrateDatabase

import android.database.Cursor; //导入方法依赖的package包/类
public static void migrateDatabase(Context context,
                                     MasterSecret masterSecret,
                                     SmsMigrationProgressListener listener)
  {
//    if (context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).getBoolean("migrated", false))
//      return;

    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    Cursor cursor                 = null;

    try {
      Uri threadListUri = Uri.parse("content://mms-sms/conversations?simple=true");
      cursor            = context.getContentResolver().query(threadListUri, null, null, null, "date ASC");

      while (cursor != null && cursor.moveToNext()) {
        long   theirThreadId         = cursor.getLong(cursor.getColumnIndexOrThrow("_id"));
        String theirRecipients       = cursor.getString(cursor.getColumnIndexOrThrow("recipient_ids"));
        Recipients ourRecipients     = getOurRecipients(context, theirRecipients);
        ProgressDescription progress = new ProgressDescription(cursor.getCount(), cursor.getPosition(), 100, 0);

        if (ourRecipients != null) {
          long ourThreadId = threadDatabase.getThreadIdFor(ourRecipients);
          migrateConversation(context, masterSecret,
                              listener, progress,
                              theirThreadId, ourThreadId);
        }

        progress.incrementPrimaryComplete();
        listener.progressUpdate(progress);
      }
    } finally {
      if (cursor != null)
        cursor.close();
    }

    context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).edit()
      .putBoolean("migrated", true).apply();
  }
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:39,代码来源:SmsMigrator.java

示例6: getType

import android.database.Cursor; //导入方法依赖的package包/类
private static int getType(Cursor cursor, int columnIndex) throws Exception
{

    if (Build.VERSION.SDK_INT >= 11)
    {
        return cursor.getType(columnIndex);
    }

    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    int type = -1;
    if (cursorWindow.isNull(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_NULL;
    } else if (cursorWindow.isLong(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_INTEGER;
    } else if (cursorWindow.isFloat(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_FLOAT;
    } else if (cursorWindow.isString(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_STRING;
    } else if (cursorWindow.isBlob(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_BLOB;
    }

    return type;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:32,代码来源:TypeUtil.java

示例7: getCallTypes

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Returns the call types for the given number of items in the cursor.
 * <p>
 * It uses the next {@code count} rows in the cursor to extract the types.
 * <p>
 * It position in the cursor is unchanged by this function.
 */
private int[] getCallTypes(Cursor cursor, int count) {
    int position = cursor.getPosition();
    int[] callTypes = new int[count];
    for (int index = 0; index < count; ++index) {
        callTypes[index] = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
        cursor.moveToNext();
    }
    cursor.moveToPosition(position);
    return callTypes;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:18,代码来源:CallLogAdapter.java

示例8: getCallIds

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * Returns the call ids for the given number of items in the cursor.
 * <p>
 * It uses the next {@code count} rows in the cursor to extract the types.
 * <p>
 * It position in the cursor is unchanged by this function.
 */
private long[] getCallIds(Cursor cursor, int count) {
    int position = cursor.getPosition();
    long[] callIds = new long[count];
    for (int index = 0; index < count; ++index) {
        if(!cursor.isAfterLast()) {
            callIds[index] = cursor.getLong(cursor.getColumnIndex(CallLog.Calls._ID));
        }
        cursor.moveToNext();
    }
    cursor.moveToPosition(position);
    return callIds;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:20,代码来源:CallLogAdapter.java

示例9: createIntentFromSuggestion

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * When a particular suggestion has been selected, perform the various lookups required
 * to use the suggestion.  This includes checking the cursor for suggestion-specific data,
 * and/or falling back to the XML for defaults;  It also creates REST style Uri data when
 * the suggestion includes a data id.
 *
 * @param c The suggestions cursor, moved to the row of the user's selection
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied, or fixed default
        String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e ) {
        int rowNum;
        try {                       // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2 ) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum +
                        " returned exception.", e);
        return null;
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:56,代码来源:SearchView.java

示例10: makeSortedCursor

import android.database.Cursor; //导入方法依赖的package包/类
@Nullable
private static SortedLongCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor, final int idColumn) {
    if (cursor != null && cursor.moveToFirst()) {
        // create the list of ids to select against
        StringBuilder selection = new StringBuilder();
        selection.append(BaseColumns._ID);
        selection.append(" IN (");

        // this tracks the order of the ids
        long[] order = new long[cursor.getCount()];

        long id = cursor.getLong(idColumn);
        selection.append(id);
        order[cursor.getPosition()] = id;

        while (cursor.moveToNext()) {
            selection.append(",");

            id = cursor.getLong(idColumn);
            order[cursor.getPosition()] = id;
            selection.append(String.valueOf(id));
        }

        selection.append(")");

        // get a list of songs with the data given the selection statement
        Cursor songCursor = SongLoader.makeSongCursor(context, selection.toString(), null);
        if (songCursor != null) {
            // now return the wrapped TopTracksCursor to handle sorting given order
            return new SortedLongCursor(songCursor, order, BaseColumns._ID);
        }
    }

    return null;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:36,代码来源:TopAndRecentlyPlayedTracksLoader.java

示例11: moveCursor

import android.database.Cursor; //导入方法依赖的package包/类
public static int moveCursor(Cursor cursor, String idColumnName, long id) {
       int pos = cursor.getColumnIndexOrThrow(idColumnName);
       if (cursor.moveToFirst()) {
           do {
               if (cursor.getLong(pos) == id) {
                   return cursor.getPosition();
               }
           } while(cursor.moveToNext());
       }
	return -1;
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:12,代码来源:Utils.java

示例12: makeSortedCursor

import android.database.Cursor; //导入方法依赖的package包/类
/**
 * 根据包含song id的cursor,获取排序好的song cursor
 *
 * @param context
 * @param cursor
 * @param idColumn
 * @return
 */
public static SortedCursor makeSortedCursor(final Context context, final Cursor cursor,
                                            final int idColumn) {
    if (cursor != null && cursor.moveToFirst()) {

        StringBuilder selection = new StringBuilder();
        selection.append(BaseColumns._ID);
        selection.append(" IN (");

        long[] order = new long[cursor.getCount()];

        long id = cursor.getLong(idColumn);
        selection.append(id);
        order[cursor.getPosition()] = id;

        while (cursor.moveToNext()) {
            selection.append(",");

            id = cursor.getLong(idColumn);
            order[cursor.getPosition()] = id;
            selection.append(String.valueOf(id));
        }

        selection.append(")");

        Cursor songCursor = makeSongCursor(context, selection.toString(), null);
        if (songCursor != null) {
            return new SortedCursor(songCursor, order, BaseColumns._ID, null);
        }
    }

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

    return null;
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:45,代码来源:SongsPresenter.java

示例13: initConversationView

import android.database.Cursor; //导入方法依赖的package包/类
void initConversationView(final Context context, Cursor cursor, final InboxConversationView conversationView, Conversation conversation, boolean isExpanded) {
    conversationView.setAppId(conversation.getLastMessage().getAppId());
    conversationView.setAppSpecificSenderId(conversation.getSender().getAppSpecificUserId());
    conversationView.setFrom(conversation.getSender().getDisplayName());
    conversationView.setMessagePreview(conversation.getLastMessage().getBody());
    conversationView.setTimestamp(conversation.getLastMessage().getTimestamp());
    conversationView.setNumUnreadMessages(conversation.getNumUnreadMessages());
    App app = this.appManager.getAppById(conversation.getLastMessage().getAppId());
    Drawable icon = app.getAppIcon();
    ProfilePhoto profilePhoto = app.getProfilePhotoForMessage(conversation.getLastMessage());
    conversationView.setProfilePhoto(context, profilePhoto);
    if (profilePhoto == null) {
        ((ProfilePhotoManager) GuiceModule.get().getInstance(ProfilePhotoManager.class)).loadProfilePhoto(conversation.getSender().getAppId(), conversation.getSender().getAppSpecificUserId(), conversation.getSender().getDisplayName(), new ProfilePhotoManager.OnProfilePhotoLoadedListener() {
            public void onProfilePhotoLoaded(String appId, String senderId, String senderName, ProfilePhoto photo) {
                if (InboxCursorAdapter.this.areStringsEqual(appId, conversationView.getAppId()) && InboxCursorAdapter.this.areStringsEqual(senderId, conversationView.getAppSpecificSenderId()) && InboxCursorAdapter.this.areStringsEqual(senderName, conversationView.getFrom())) {
                    conversationView.setProfilePhoto(context, photo);
                }
            }
        });
    }
    conversationView.setIcon(icon);
    int index = cursor.getPosition();
    boolean showAllMessagesDivider = false;
    if (index == 0 && conversation.getNumUnreadMessages() <= 0) {
        this.firstReadConversation = conversation.getLastMessage().getTimestamp();
    } else if (index > 0 && conversation.getNumUnreadMessages() <= 0 && conversation.getLastMessage().getTimestamp() >= this.firstReadConversation) {
        this.firstReadConversation = conversation.getLastMessage().getTimestamp();
        showAllMessagesDivider = true;
    }
    conversationView.showAllMessagesDivider(showAllMessagesDivider);
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:32,代码来源:InboxCursorAdapter.java

示例14: makeSortedCursor

import android.database.Cursor; //导入方法依赖的package包/类
@Nullable
private static SortedLongCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor, final int idColumn) {

    if (cursor != null && cursor.moveToFirst()) {
        // create the list of ids to select against
        StringBuilder selection = new StringBuilder();
        selection.append(BaseColumns._ID);
        selection.append(" IN (");

        // this tracks the order of the ids
        long[] order = new long[cursor.getCount()];

        long id = cursor.getLong(idColumn);
        selection.append(id);
        order[cursor.getPosition()] = id;

        while (cursor.moveToNext()) {
            selection.append(",");

            id = cursor.getLong(idColumn);
            order[cursor.getPosition()] = id;
            selection.append(String.valueOf(id));
        }

        selection.append(")");

        // get a list of songs with the data given the selection statement
        Cursor songCursor = SongLoader.makeSongCursor(context, selection.toString(), null);
        if (songCursor != null) {
            // now return the wrapped TopTracksCursor to handle sorting given order
            return new SortedLongCursor(songCursor, order, BaseColumns._ID);
        }
    }

    return null;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:37,代码来源:TopAndRecentlyPlayedTracksLoader.java

示例15: getItemPosition

import android.database.Cursor; //导入方法依赖的package包/类
public int getItemPosition(final long id) {
	final Cursor cursor = getCursor();
	if (cursor == null)
		return 1;

	if (cursor.moveToFirst())
		do {
			if (cursor.getLong(0 /* _ID */) == id)
				return cursor.getPosition() + 1;
		} while (cursor.moveToNext());
	return 1; // should never happen
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:13,代码来源:UARTConfigurationsAdapter.java


注:本文中的android.database.Cursor.getPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。