Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

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

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruAPI.java

@Override
public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) {
    String[] tags;/*from   w w  w. jav a  2 s  . c  o m*/
    if (tags_cursor != null) {
        tags_cursor.moveToPosition(-1);
        tags = new String[tags_cursor.getCount()];
        while (tags_cursor.moveToNext())
            tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME);
    } else
        tags = new String[0];
    return new DanbooruPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID),
            post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH),
            post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT),
            new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)),
            new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)),
            post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE),
            post_cursor.getString(PostsTable.INDEX_POST_FILE_URL),
            post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL),
            post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags,
            post_cursor.getString(PostsTable.INDEX_POST_RATING),
            post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO));
}

From source file:info.guardianproject.otr.app.im.app.AddContactActivity.java

private int searchInitListPos(Cursor c, String listName) {
    if (TextUtils.isEmpty(listName)) {
        return 0;
    }//from w  w w. ja v a  2 s .c o m
    c.moveToPosition(-1);
    while (c.moveToNext()) {
        if (listName.equals(c.getString(CONTACT_LIST_NAME_COLUMN))) {
            return c.getPosition();
        }
    }
    return 0;
}

From source file:org.mariotaku.twidere.fragment.DraftsFragment.java

@Override
public void onItemClick(final AdapterView<?> view, final View child, final int position, final long id) {
    final Cursor c = mAdapter.getCursor();
    if (c == null || c.isClosed() || !c.moveToPosition(position))
        return;/*from ww w  . j av  a 2  s. co  m*/
    final Draft item = DraftCursorIndices.fromCursor(c);
    if (TextUtils.isEmpty(item.action_type)) {
        editDraft(item);
        return;
    }
    switch (item.action_type) {
    case "0":
    case "1":
    case Draft.Action.UPDATE_STATUS:
    case Draft.Action.REPLY:
    case Draft.Action.QUOTE: {
        editDraft(item);
        break;
    }
    }
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Cursor cursor = getCursor();
    cursor.moveToPosition(position);
    if (convertView == null) {
        convertView = newView(parent);/* ww w.j  a  va 2 s .c o  m*/
    }
    if (cursor.getLong(Queries.Query.DATA_ID) == mCurrentId) {
        mCheckedItemPosition = position;
        if (mCheckedItemChangedListener != null) {
            mCheckedItemChangedListener.onCheckedItemChanged(mCheckedItemPosition);
        }
    }
    bindView(convertView, convertView.getContext(), cursor);
    return convertView;
}

From source file:org.ohmage.fragments.HomeFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    ArrayList<Item> items = new ArrayList<Item>();
    boolean pivot = true;
    data.moveToPosition(-1);
    while (data.moveToNext()) {
        if (items.isEmpty() && data.getLong(4) != Reminders.NOT_PENDING) {
            pivot = false;//w  w  w .j a v  a2s  .c o m
            items.add(new Item("Pending"));
        } else if (!items.isEmpty() && data.getLong(4) == Reminders.NOT_PENDING && !pivot) {
            pivot = true;
            items.add(new Item("Surveys"));
        }
        items.add(new Item(data, 0));
    }

    SurveyAdapter adapter = getListAdapter();
    if (adapter == null) {
        adapter = new SurveyAdapter(getActivity(), items);
        setListAdapter(adapter);
    } else {
        adapter.setData(items);
    }

    setGridShown(true);
}

From source file:com.nomapp.nomapp_beta.RecipePreview.FillGapBaseActivity.java

private void setUpTitle() {
    Cursor cursor = Database.getDatabase().getGeneralDb().query(Database.getRecipesTableName(),
            new String[] { Database.getRecipesName() }, null, null, null, null, null);

    Intent data = getIntent();//from  w ww. j  a  v  a  2  s . c o m
    cursor.moveToPosition(data.getIntExtra("numberOfRecipe", 0) - 1);

    ((TextView) findViewById(R.id.title)).setText(cursor.getString(0));
    cursor.close();

    setTitle(null);
}

From source file:com.gigathinking.simpleapplock.AppLaunchDetectorService.java

@Override
public void onCreate() {
    super.onCreate();
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mAppListData = new AppListData(getApplicationContext());
    mAppListData.init();/* w  w w  .j a va  2s. c om*/
    updateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (!mList.isEmpty()) {
                mList.clear();
            }
            if (!mAppMap.isEmpty()) {
                mAppMap.clear();
            }
            Cursor cursor = mAppListData.getAppListInfo();
            int count = cursor.getCount();
            for (int i = 0; i < count; ++i) {
                cursor.moveToPosition(i);
                mList.add(cursor.getString(2));
                mAppMap.put(cursor.getString(2), Boolean.valueOf(cursor.getString(3)));
                mLastOpen.put(cursor.getString(2), cursor.getInt(4));
            }
        }
    };
    mList = new ArrayList<String>();
    mAppMap = new HashMap<String, Boolean>();
    mLastOpen = new HashMap<String, Integer>();
    Cursor cursor = mAppListData.getAppListInfo();
    int count = cursor.getCount();
    for (int i = 0; i < count; ++i) {
        cursor.moveToPosition(i);
        mList.add(cursor.getString(2));
        mAppMap.put(cursor.getString(2), Boolean.valueOf(cursor.getString(3)));
        mLastOpen.put(cursor.getString(2), cursor.getInt(4));
    }
    cursor.close();
    LocalBroadcastManager.getInstance(this).registerReceiver(updateReceiver,
            new IntentFilter(AppLockApplication.UPDATE_LIST));
    new DetectAppLaunch().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:ph.devcon.android.attendee.AttendeesFragment.java

public ArrayList<Integer> getIds() {
    ArrayList<Integer> ids = new ArrayList<Integer>();
    Cursor c = attendeeAdapter.getCursor();
    if (Optional.fromNullable(c).isPresent()) {
        Integer ID_INDEX = c.getColumnIndex(FTSAttendee.COL_ID);
        for (int i = 0; i < c.getCount(); i++) {
            c.moveToPosition(i);
            Integer id = Integer.valueOf(c.getString(ID_INDEX));
            ids.add(id);//from  w w w  . j av  a 2s .co m
        }
    }
    return ids;
}

From source file:com.mobicage.rogerthat.plugins.history.HistoryListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    T.UI();/*from   w ww  .  java  2 s .  co  m*/

    final View view;

    if (convertView == null) {
        view = mLayoutInflater.inflate(R.layout.activity_list_row, parent, false);
    } else {
        view = convertView;
    }

    final Cursor cursor = getCursor();
    if (!cursor.moveToPosition(position)) {
        throw new IllegalStateException("couldn't move cursor to position " + position);
    }
    final HistoryItem item = mStore.getCurrentHistoryItem(cursor);

    final StringTuple historyText = createHistoryText(item);

    final TextView tv1 = (TextView) view.findViewById(R.id.activity_list_row_text1);
    tv1.setText(historyText.s1);
    tv1.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.primary_text_light));

    final TextView tv2 = (TextView) view.findViewById(R.id.activity_list_row_text2);
    if (historyText.s2 == null)
        tv2.setVisibility(View.GONE);
    else {
        tv2.setText(historyText.s2);
        tv2.setVisibility(View.VISIBLE);
        tv2.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.secondary_text_light));
    }

    final TextView tv3 = (TextView) view.findViewById(R.id.activity_list_row_text3);
    if (historyText.s3 == null)
        tv3.setVisibility(View.GONE);
    else {
        tv3.setText(historyText.s3);
        tv3.setVisibility(View.VISIBLE);
        tv3.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.secondary_text_light));
    }

    updateDividerLine(view, item);

    final int image = getImage(item);
    final ImageView iv = (ImageView) view.findViewById(R.id.activity_list_row_icon);
    if (image != -1) {
        iv.setImageResource(image);
    } else {
        iv.setImageResource(0);
    }

    final TextView timestampTextView = (TextView) view.findViewById(R.id.timestamp);
    timestampTextView.setText(TimeUtils.getHumanTime(mContext, item.timestampMillis, false));

    view.setTag(item);
    return view;
}

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

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor c = mForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);//from  w  ww  .  j  a  v  a  2s .com
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}