Example usage for android.database Cursor getPosition

List of usage examples for android.database Cursor getPosition

Introduction

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

Prototype

int getPosition();

Source Link

Document

Returns the current position of the cursor in the row set.

Usage

From source file:com.google.android.apps.iosched.ui.gtv.GoogleTVSessionLivestreamActivity.java

/**
 * Locates which item should be selected in the action bar drop-down spinner based on the
 * current active session uri//from  www. j a v a2  s  .  c  o  m
 */
private int locateSelectedItem(Cursor data) {
    int selected = 0;
    if (data != null && mSessionId != null) {
        while (data.moveToNext()) {
            if (mSessionId.equals(data.getString(SessionsQuery.SESSION_ID))) {
                selected = data.getPosition();
            }
        }
    }
    return selected;
}

From source file:tw.idv.palatis.danboorugallery.PostDetailActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (mPosition != -1) {
        // tries to find the position in the new cursor
        Cursor oldCursor = mPagerAdapter.getCursor(mPosition);
        if (oldCursor != null) {
            int post_id = oldCursor.getInt(PostsTable.INDEX_POST_POST_ID);
            cursor.moveToPosition(-1);//w w  w  .  j  a  v  a  2  s.co m
            while (cursor.moveToNext())
                if (cursor.getInt(PostsTable.INDEX_POST_POST_ID) == post_id) {
                    mPosition = cursor.getPosition();
                    break;
                }
        }
    }

    mPagerAdapter.swapCursor(cursor);
    mViewPager.setCurrentItem(mPosition, false);
    cursor.moveToPosition(mPosition);
    Host host = SiteSession.getHostById(cursor.getInt(PostsTable.INDEX_POST_HOST_ID));
    Post post = Post.fromCursor(host, cursor, null);
    mInfoText.setText(post.describeContent(PostDetailActivity.this));
}

From source file:org.xbmc.kore.ui.TVShowEpisodeListFragment.java

private void setState(Cursor cursor) {
    if (cursor.getCount() == 1) {
        seasonsEpisodesListView.expandGroup(0);
    } else if (cursor.getCount() > 0) {
        cursor.moveToFirst();//ww w  . jav a  2s  . co m
        do {
            int position = cursor.getPosition();

            // Expand the first season that has unseen episodes
            int unwatched = cursor.getInt(SeasonsListQuery.EPISODE)
                    - cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);
            if (groupsExpanded.isEmpty() && (unwatched > 0)) {
                seasonsEpisodesListView.expandGroup(position);
                groupsExpanded.put(position, true);
                break;
            }

            if (groupsExpanded.get(position) != null) {
                seasonsEpisodesListView.expandGroup(position);
            }
        } while (cursor.moveToNext());
    }
}

From source file:com.digipom.manteresting.android.adapter.NailCursorAdapter.java

/**
 * BindView will also be called after newView. See {@link CursorAdapter}
 *//*from   ww  w.  j  a v a 2  s.c o  m*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
    try {
        // 84, or 0.825, comes from the margins/paddings around the
        // image. This will need to be changed if the margins/paddings are
        // changed or multi-column mode is used.
        final int approxImageWidthInPixels = (int) (context.getResources().getDisplayMetrics().widthPixels
                * 0.825f);

        // Request a load of the bitmaps on either side, to avoid
        // problems when scrolling up and down.
        final int cursorPosition = cursor.getPosition();

        if (cursorPosition > 0) {
            cursor.moveToPrevious();
            if (cursor.getString(nailObjectColumnIndex) != null) {
                cacheDataAndGet(context, cursor, approxImageWidthInPixels);
            }
            cursor.moveToNext();
        }

        if (cursorPosition < cursor.getCount() - 1) {
            cursor.moveToNext();
            if (cursor.getString(nailObjectColumnIndex) != null) {
                cacheDataAndGet(context, cursor, approxImageWidthInPixels);
            }
            cursor.moveToPrevious();
        }

        final ViewHolder viewHolder = (ViewHolder) view.getTag();

        final CachedData cachedDataForThisNailItem = cacheDataAndGet(context, cursor, approxImageWidthInPixels);

        viewHolder.nailDescription.setText(cachedDataForThisNailItem.nailDescription);
        viewHolder.nailUserAndCategory.setText(cachedDataForThisNailItem.styledUserAndCategory);

        if (failedDownloads.contains(cachedDataForThisNailItem.originalImageUriString)) {
            // This image has failed. The user will have to select to
            // retry this image. INVISIBLE and not GONE so that the view
            // doesn't jump in sizes for couldNotLoadImageIndicator.
            viewHolder.imageLoadingIndicator.setVisibility(View.INVISIBLE);
            viewHolder.couldNotLoadImageIndicator.setVisibility(View.VISIBLE);
            viewHolder.loadedImage.setVisibility(View.GONE);
        } else {
            // Should default to WRAP_CONTENT
            viewHolder.loadedImage.getLayoutParams().height = LayoutParams.WRAP_CONTENT;

            Bitmap bitmap = null;

            if (serviceConnector.getService() != null) {
                bitmap = serviceConnector.getService().getOrLoadLifoAsync(
                        cachedDataForThisNailItem.originalImageUriString, approxImageWidthInPixels,
                        bitmapCompleteReceiver);
            }

            if (bitmap == null) {
                viewHolder.imageLoadingIndicator.setVisibility(View.VISIBLE);
                viewHolder.couldNotLoadImageIndicator.setVisibility(View.INVISIBLE);
                viewHolder.loadedImage.setVisibility(View.GONE);
            } else {
                viewHolder.imageLoadingIndicator.setVisibility(View.GONE);
                viewHolder.couldNotLoadImageIndicator.setVisibility(View.GONE);
                viewHolder.loadedImage.setVisibility(View.VISIBLE);

                viewHolder.loadedImage.setImageBitmap(bitmap);
            }
        }
    } catch (JSONException e) {
        if (LoggerConfig.canLog(Log.ERROR)) {
            Log.e(TAG, "Could not load JSON object from database.", e);
        }
    } catch (Exception e) {
        if (LoggerConfig.canLog(Log.ERROR)) {
            Log.e(TAG, "Error binding view.", e);
        }
    }
}

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final LayoutInflater li = LayoutInflater.from(context);
    final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo));
    View v;//from  ww  w . j  a  v a2 s .c  o  m
    final ViewHolder h = new ViewHolder();
    if (cursor.getLong(iId) == mActiveId) {
        final int position = cursor.getPosition();
        v = li.inflate(R.layout.item_ticket_active, parent, false);
        h.vValidTo = (TextView) v.findViewById(R.id.ticket_valid_to);
        h.vValidFrom = (TextView) v.findViewById(R.id.ticket_valid_from);
        h.vCode = (TextView) v.findViewById(R.id.ticket_code);
        h.vValidToLabel = (TextView) v.findViewById(R.id.ticket_valid_to_label);
        h.vValidFromLabel = (TextView) v.findViewById(R.id.ticket_valid_from_label);
        h.vCodeLabel = (TextView) v.findViewById(R.id.ticket_code_label);
        h.vDelete = (ImageButton) v.findViewById(R.id.delete_button);
        h.vCollapse = (ImageButton) v.findViewById(R.id.collapse_button);
        h.vShowSms = (Button) v.findViewById(R.id.sms_button);
        h.vSeparator1 = v.findViewById(R.id.separator1);
        h.vSeparator2 = v.findViewById(R.id.separator2);
        h.vSeparator3 = v.findViewById(R.id.separator3);
        h.vTopInfo = v.findViewById(R.id.top_info);
        //listeners
        h.vCollapse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.collapseUncollapseTicket(mActiveId, mShowSms);
            }
        });
        h.vTopInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.collapseUncollapseTicket(mActiveId, mShowSms);
            }
        });
        h.vShowSms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSms(position);
            }
        });
        if (mShowSms) {
            showSms(position);
            mShowSms = false;
        }
    } else {
        v = li.inflate(R.layout.item_ticket, parent, false);
        h.vWhenExpired = (TextView) v.findViewById(R.id.ticket_when_expired);
    }
    h.vIndicator = (ImageView) v.findViewById(R.id.ticket_indicator);
    h.vStatus = (TextView) v.findViewById(R.id.ticket_status);
    h.vCity = (TextView) v.findViewById(R.id.ticket_city);
    h.vTicket = v.findViewById(R.id.ticket);
    h.animator = ObjectAnimator.ofFloat(h.vIndicator, "rotationX", 0, 360);
    v.setTag(h);

    return v;
}

From source file:com.ubundude.timesheet.MainUIFragment.java

private void displayDialog() {
    /** Open the database table for reading and writing */
    db = dbHelp.getReadableDatabase();/*  w  w  w.  j a  va2s . co m*/

    /** Select statement to get data needed for the list view */
    String getProjects = "select _id, name from projects";

    /** Open a cursor and store the return of the query */
    Cursor cu = db.rawQuery(getProjects, null);

    /** Arrays to store the project names and ID's in */
    CharSequence[] projects = new CharSequence[cu.getCount()];
    final int[] IDs = new int[cu.getCount()];

    /** Make sure cursor is not null */
    if (cu != null && cu.getCount() > 0) {
        cu.moveToFirst();

        /** While there is a cursor row, store the contents of that row in an array */
        do {
            projects[cu.getPosition()] = cu.getString(1);
            IDs[cu.getPosition()] = cu.getInt(0);
        } while (cu.moveToNext());

    }
    /** Create a new list dialog to allow the user to select a project */
    AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
    build.setTitle("Choose Project");
    Log.d("Display Dialog", "Title Set");
    build.setItems(projects, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            proId = IDs[which];

            /** If the project ID is 1, start the project editor activity */
            if (proId == 1) {
                Intent intent = new Intent(getActivity(), ProjectEditorActivity.class);
                intent.putExtra(ProjectEditorActivity.PRO_KEY, proId);
                startActivity(intent);
            } else {
                quickAddHandler(proId);
            }

        }
    });

    /** Create and show the dialog */
    AlertDialog diag = build.create();
    diag.show();

    /** Close the cursor and database */
    cu.close();
    db.close();
}

From source file:com.abcvoipsip.ui.messages.ConverstationsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);

    final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag();
    String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));

    //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE));

    tagView.fromFull = fromFull;//ww w. j  a  va  2s.  c om
    tagView.to = to_number;
    tagView.from = nbr;
    tagView.position = cursor.getPosition();

    /*
    Drawable background = (read == 0)?
        context.getResources().getDrawable(R.drawable.conversation_item_background_unread) :
        context.getResources().getDrawable(R.drawable.conversation_item_background_read);
            
    view.setBackgroundDrawable(background);
     */
    String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number);

    /*
    final Uri lookupUri = info.contactContentUri;
    final String name = info.name;
    final int ntype = info.numberType;
    final String label = info.phoneLabel;
    CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false);
    */

    // Photo
    tagView.quickContactView.assignContactUri(info.contactContentUri);
    ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(),
            info, SipHome.USE_LIGHT_THEME ? R.drawable.ic_contact_picture_holo_light
                    : R.drawable.ic_contact_picture_holo_dark);

    // From
    tagView.fromView.setText(formatMessage(cursor));

    //Date
    // Set the date/time field by mixing relative and absolute times.
    int flags = DateUtils.FORMAT_ABBREV_RELATIVE;
    tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(),
            DateUtils.MINUTE_IN_MILLIS, flags));
}

From source file:com.csipsimple.ui.messages.ConversationsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);

    final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag();
    String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));

    //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE));

    tagView.fromFull = fromFull;//from  ww w  . j  a  v  a  2 s.co m
    tagView.to = to_number;
    tagView.from = nbr;
    tagView.position = cursor.getPosition();

    /*
    Drawable background = (read == 0)?
        context.getResources().getDrawable(R.drawable.conversation_item_background_unread) :
        context.getResources().getDrawable(R.drawable.conversation_item_background_read);
            
    view.setBackgroundDrawable(background);
     */
    String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number);

    /*
    final Uri lookupUri = info.contactContentUri;
    final String name = info.name;
    final int ntype = info.numberType;
    final String label = info.phoneLabel;
    CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false);
    */

    // Photo
    tagView.quickContactView.assignContactUri(info.contactContentUri);
    ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(),
            info, R.drawable.ic_contact_picture_holo_dark);

    // From
    tagView.fromView.setText(formatMessage(cursor));

    //Date
    // Set the date/time field by mixing relative and absolute times.
    int flags = DateUtils.FORMAT_ABBREV_RELATIVE;
    tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(),
            DateUtils.MINUTE_IN_MILLIS, flags));
}

From source file:com.fututel.ui.messages.ConversationsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);

    final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag();
    String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));

    //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE));

    tagView.fromFull = fromFull;// w w w .ja  v a  2s  .co m
    tagView.to = to_number;
    tagView.from = nbr;
    tagView.position = cursor.getPosition();

    /*
    Drawable background = (read == 0)?
        context.getResources().getDrawable(R.drawable.conversation_item_background_unread) :
        context.getResources().getDrawable(R.drawable.conversation_item_background_read);
            
    view.setBackgroundDrawable(background);
     */
    String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number);

    /*
    final Uri lookupUri = info.contactContentUri;
    final String name = info.name;
    final int ntype = info.numberType;
    final String label = info.phoneLabel;
    CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false);
    */

    // Photo
    tagView.quickContactView.assignContactUri(info.contactContentUri);
    ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(),
            info, R.drawable.ic_contact_picture_holo_light);

    // From
    tagView.fromView.setText(formatMessage(cursor));

    //Date
    // Set the date/time field by mixing relative and absolute times.
    int flags = DateUtils.FORMAT_ABBREV_RELATIVE;
    tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(),
            DateUtils.MINUTE_IN_MILLIS, flags));
}

From source file:org.akvo.flow.service.DataSyncService.java

private void exportSurveys() {
    long[] surveyInstanceIds = new long[0];// Avoid null cases
    Cursor cursor = mDatabase.getUnexportedSurveyInstances();
    if (cursor != null) {
        surveyInstanceIds = new long[cursor.getCount()];
        if (cursor.moveToFirst()) {
            do {//www  .  j  a  v  a  2  s . c o  m
                surveyInstanceIds[cursor.getPosition()] = cursor
                        .getLong(cursor.getColumnIndexOrThrow(SurveyInstanceColumns._ID));
            } while (cursor.moveToNext());
        }
        cursor.close();
    }

    for (long id : surveyInstanceIds) {
        ZipFileData zipFileData = formZip(id);
        if (zipFileData != null) {
            displayExportNotification(getDestName(zipFileData.filename));

            // Create new entries in the transmission queue
            mDatabase.createTransmission(id, zipFileData.filename);
            updateSurveyStatus(id, SurveyInstanceStatus.EXPORTED);

            for (String image : zipFileData.imagePaths) {
                mDatabase.createTransmission(id, image);
            }
        }
    }
}