Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

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

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:cm.aptoide.ptdev.ScheduledDownloadsActivity.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor c) {
    scheduledDownloadsHashMap.clear();//  ww w. jav  a 2 s .  c  om
    if (c.getCount() == 0) {
        findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    } else {
        findViewById(android.R.id.empty).setVisibility(View.GONE);
    }
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        ScheduledDownload scheduledDownload = new ScheduledDownload(c.getLong(c.getColumnIndex("_id")), true);

        scheduledDownload.setApkid(c.getString(c.getColumnIndex("package_name")));
        scheduledDownload.setMd5(c.getString(c.getColumnIndex("md5")));
        scheduledDownload.setName(c.getString(c.getColumnIndex("name")));
        scheduledDownload.setVername(c.getString(c.getColumnIndex("version_name")));
        scheduledDownload.setRepoName(c.getString(c.getColumnIndex("repo_name")));
        scheduledDownload.setIconPath(c.getString(c.getColumnIndex("icon")));

        scheduledDownloadsHashMap.put(c.getLong(c.getColumnIndex("_id")), scheduledDownload);
    }
    adapter.swapCursor(c);
}

From source file:com.rs.TCOfflineStatementCollection.java

/**
 * return a list of all local statements from db
 * @return List of LocalStatementsItem/*from  w  ww.  ja v  a  2  s .co  m*/
 */
public List<LocalStatementsItem> getCachedStatements() {
    List<LocalStatementsItem> statementArray = new ArrayList<LocalStatementsItem>();

    Cursor cursor;
    SQLiteDatabase database;
    TCLocalStorageDatabaseOpenHelper dbHelper;
    dbHelper = new TCLocalStorageDatabaseOpenHelper(appContext);
    database = dbHelper.getWritableDatabase();
    cursor = database.query(TCOfflineDataManager.LOCAL_STATEMENT_TABLE_NAME, null, null, null, null, null,
            LocalStatements.CREATE_DATE + " DESC"); //query for all the statements

    cursor.moveToFirst(); //go to the beginning of the query and then loop through all the packages, adding them to the return List
    while (!cursor.isAfterLast()) {
        LocalStatementsItem thisPackage = new LocalStatementsItem();
        thisPackage.id = cursor.getInt(0);
        thisPackage.statementId = cursor.getString(cursor.getColumnIndex("statementId"));
        thisPackage.statementJson = cursor.getString(cursor.getColumnIndex("statementJson"));
        thisPackage.createDate = cursor.getLong(cursor.getColumnIndex("createDate"));
        thisPackage.postedDate = cursor.getLong(cursor.getColumnIndex("postedDate"));
        thisPackage.querystring = cursor.getString(cursor.getColumnIndex("querystring"));

        statementArray.add(thisPackage);
        cursor.moveToNext();
    }

    cursor.close();
    database.close();

    return statementArray;
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

public static void updateSubscribedFeeds(ContentResolver cr, String account) {
    Set<String> feedsToSync = Sets.newHashSet();
    feedsToSync.add(getGroupsFeedForAccount(account));
    addContactsFeedsToSync(cr, account, feedsToSync);

    Cursor c = SubscribedFeeds.Feeds.query(cr, sSubscriptionProjection,
            SubscribedFeeds.Feeds.AUTHORITY + "=? AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?",
            new String[] { Contacts.AUTHORITY, account }, null);
    try {//from  w w  w.j  av a  2s . co  m
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "scanning over subscriptions with authority " + Contacts.AUTHORITY + " and account "
                    + account);
        }
        c.moveToNext();
        while (!c.isAfterLast()) {
            String feedInCursor = c.getString(1);
            if (feedsToSync.contains(feedInCursor)) {
                feedsToSync.remove(feedInCursor);
                c.moveToNext();
            } else {
                c.deleteRow();
            }
        }
        c.commitUpdates();
    } finally {
        c.close();
    }

    // any feeds remaining in feedsToSync need a subscription
    for (String feed : feedsToSync) {
        SubscribedFeeds.addFeed(cr, feed, account, Contacts.AUTHORITY, ContactsClient.SERVICE);

        // request a sync of this feed
        Bundle extras = new Bundle();
        extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, account);
        extras.putString("feed", feed);
        cr.startSync(Contacts.CONTENT_URI, extras);
    }
}

From source file:liqui.droid.activity.LiquiDroid.java

@SuppressWarnings("deprecation")
@Override/*from   ww  w. j ava 2 s  .co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.action_login_sync))) {
        // we create a new account
    } else {
        Cursor c = getContentResolver().query(ACCOUNT_CONTENT_URI, null, "last_active = 1", null, null);

        c.moveToFirst();

        if (!c.isAfterLast()) {
            mApiName = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_NAME));
            mApiUrl = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_URL));
            mMemberId = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_MEMBER_ID));
            mSessionKey = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_SESSION_KEY));

            Log.d("XXX", "loading old session: " + mMemberId + "@" + mApiName);
        }

        c.close();
    }

    if (isAuthenticated()) {
        Intent intent = new Intent().setClass(LiquiDroid.this, MemberActivity.class);

        Bundle extras = new Bundle();
        extras.putString(Constants.Account.API_NAME, getAPIName());
        extras.putString(Constants.Account.API_URL, getAPIUrl());
        extras.putString(Constants.Account.MEMBER_ID, getMemberId());
        extras.putString(Constants.Account.SESSION_KEY, getSessionKey());
        intent.putExtras(extras);

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

        finish();
        return;
    }

    setContentView(R.layout.act_main);

    /*
    ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
            
    actionBar.addAction(new IntentAction(this, new Intent(getApplicationContext(),
        Search.class), R.drawable.ic_search));
                
        */

    mSpinnerLQFBs = (Spinner) findViewById(R.id.sp_lqfb_instance);

    mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null,
            new String[] { DBSystem.Instance.COLUMN_NAME, DBSystem.Instance.COLUMN_ID },
            new int[] { android.R.id.text1 });

    mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mSpinnerLQFBs.setAdapter(mAdapter);
    mSpinnerLQFBs.setOnItemSelectedListener(this);

    mEditTextApiKey = (EditText) findViewById(R.id.et_api_token);
    mEditTextApiKey.addTextChangedListener(mPasswortTextWatcher);

    mButtonLogin = (Button) findViewById(R.id.btn_login);
    mButtonLogin.setEnabled(false);
    mButtonLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Cursor c = (Cursor) mSpinnerLQFBs.getSelectedItem();

            if (c == null)
                return;

            mApiUrl = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_URL));
            mApiName = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_NAME));

            hideKeyboard(mButtonLogin.getWindowToken());

            String key = mEditTextApiKey.getText().toString().trim();
            new LoginTask(LiquiDroid.this).execute(getAPIName(), getAPIUrl(), key);
        }
    });

    TextView tvExplore = (TextView) findViewById(R.id.tv_explore);
    tvExplore.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent().setClass(LiquiDroid.this, Explore.class);

            Bundle extras = new Bundle();
            extras.putString(Constants.Account.API_NAME, mApiName);
            extras.putString(Constants.Account.API_URL, mApiUrl);
            extras.putString(Constants.Account.MEMBER_ID, mMemberId);
            extras.putString(Constants.Account.SESSION_KEY, mSessionKey);
            intent.putExtras(extras);

            startActivity(intent);
        }
    });

    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.action_login_sync))) {
        // we create a new account

        LinearLayout llExplore = (LinearLayout) findViewById(R.id.ll_explore);
        llExplore.setVisibility(View.GONE);
    }

    getSupportLoaderManager().initLoader(0, null, this);
}

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

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    mCursor = data;/*from   w ww .j  a v a  2s .co  m*/
    mAdapter.swapCursor(data);

    final SparseBooleanArray checked = new SparseBooleanArray();
    data.moveToFirst();
    //if (mSelectedIds.size() == 0) {
    while (!data.isAfterLast()) {
        final boolean is_activated = data.getInt(data.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1;
        final long user_id = data.getLong(data.getColumnIndexOrThrow(Accounts.USER_ID));
        //if (is_activated) {
        //mSelectedIds.add(user_id);
        //}

        //View v = (View) getListView().getItemAtPosition(data.getPosition());
        //CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
        //cb.setChecked(is_activated);
        //mAdapter.setItemChecked(data.getPosition(), is_activated);
        data.moveToNext();
    }
    /*} else {
    while (!cursor.isAfterLast()) {
    final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID));
    if (mSelectedIds.contains(user_id)) {
       checked.put(cursor.getPosition(), true);
       mAdapter.setItemChecked(cursor.getPosition(), true);
    }
    cursor.moveToNext();
    }
    }*/
}

From source file:de.elanev.studip.android.app.widget.UserListFragment.java

/**
 * Creating floating context menu/*from www . ja v  a 2s.co  m*/
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    Cursor listItemCursor = (Cursor) mListView.getAdapter().getItem(info.position);

    final String[] projection = new String[] {
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_NAME,
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_ID,
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_ID };
    final String contactId = listItemCursor
            .getString(listItemCursor.getColumnIndex(UsersContract.Columns.USER_ID));

    CursorLoader loader = new CursorLoader(getActivity(),
            ContactsContract.CONTENT_URI_CONTACTS.buildUpon().appendPath(contactId).build(), projection, null,
            null, ContactsContract.Columns.ContactGroups.GROUP_NAME + " ASC");

    final Cursor c = loader.loadInBackground();

    if (c.getCount() <= 0) {
        inflater.inflate(R.menu.user_add_context_menu, menu);
    } else {
        inflater.inflate(R.menu.user_context_menu, menu);
        c.moveToFirst();
        while (!c.isAfterLast()) {
            String currGroupName = c
                    .getString(c.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_NAME));
            if (TextUtils.equals(currGroupName, getString(R.string.studip_app_contacts_favorites))) {
                menu.removeItem(R.id.add_to_favorites);
                menu.findItem(R.id.remove_from_favorites).setVisible(true);
            }

            c.moveToNext();
        }

    }
    c.close();
}

From source file:cm.aptoide.pt.ScheduledDownloads.java

public void onLoadFinished(Loader<Cursor> arg0, Cursor c) {
    scheduledDownloadsHashMap.clear();/*from w  ww.j a  v  a 2 s.  c  o m*/
    if (c.getCount() == 0) {
        findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    } else {
        findViewById(android.R.id.empty).setVisibility(View.GONE);
    }
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        ScheduledDownload scheduledDownload = new ScheduledDownload(c.getString(1), true);

        scheduledDownload.setApkid(c.getString(2));
        scheduledDownload.setVercode(Integer.parseInt(c.getString(3)));

        scheduledDownload.setVername(c.getString(4));
        scheduledDownload.setRepoName(c.getString(5));
        scheduledDownload.setIconPath(c.getString(6));

        scheduledDownloadsHashMap.put(c.getString(0), scheduledDownload);
    }
    adapter.swapCursor(c);

}

From source file:com.example.android.tvleanback.ui.MainFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        final int loaderId = loader.getId();

        if (loaderId == CATEGORY_LOADER) {

            // Every time we have to re-get the category loader, we must re-create the sidebar.
            mCategoryRowAdapter.clear();

            // Iterate through each category entry and add it to the ArrayAdapter.
            while (!data.isAfterLast()) {

                int categoryIndex = data.getColumnIndex(VideoContract.VideoEntry.COLUMN_CATEGORY);
                String category = data.getString(categoryIndex);

                // Create header for this category.
                HeaderItem header = new HeaderItem(category);

                int videoLoaderId = category.hashCode(); // Create unique int from category.
                CursorObjectAdapter existingAdapter = mVideoCursorAdapters.get(videoLoaderId);
                if (existingAdapter == null) {

                    // Map video results from the database to Video objects.
                    CursorObjectAdapter videoCursorAdapter = new CursorObjectAdapter(new CardPresenter());
                    videoCursorAdapter.setMapper(new VideoCursorMapper());
                    mVideoCursorAdapters.put(videoLoaderId, videoCursorAdapter);

                    ListRow row = new ListRow(header, videoCursorAdapter);
                    mCategoryRowAdapter.add(row);

                    // Start loading the videos from the database for a particular category.
                    Bundle args = new Bundle();
                    args.putString(VideoContract.VideoEntry.COLUMN_CATEGORY, category);
                    getLoaderManager().initLoader(videoLoaderId, args, this);
                } else {
                    ListRow row = new ListRow(header, existingAdapter);
                    mCategoryRowAdapter.add(row);
                }// ww  w  .  j  a v  a2s. c  o m

                data.moveToNext();
            }

            // Create a row for this special case with more samples.
            HeaderItem gridHeader = new HeaderItem(getString(R.string.more_samples));
            GridItemPresenter gridPresenter = new GridItemPresenter(this);
            ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(gridPresenter);
            gridRowAdapter.add(getString(R.string.grid_view));
            gridRowAdapter.add(getString(R.string.guidedstep_first_title));
            gridRowAdapter.add(getString(R.string.error_fragment));
            gridRowAdapter.add(getString(R.string.personal_settings));
            ListRow row = new ListRow(gridHeader, gridRowAdapter);
            mCategoryRowAdapter.add(row);

            startEntranceTransition(); // TODO: Move startEntranceTransition to after all
            // cursors have loaded.
        } else {
            // The CursorAdapter contains a Cursor pointing to all videos.
            mVideoCursorAdapters.get(loaderId).changeCursor(data);
        }
    } else {
        // Start an Intent to fetch the videos.
        Intent serviceIntent = new Intent(getActivity(), FetchVideoService.class);
        getActivity().startService(serviceIntent);
    }
}

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

public boolean[] values() {

    boolean[] arr;
    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];
    // this.checkBoxState = 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//from w w  w  .j a  va2  s  .  c  o m
                arr[locationCursor1.getPosition()] = false;

        }

        locationCursor1.moveToNext();
    }

    return arr;
}

From source file:com.soundcloud.android.crop.support.ImagesFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.gallery, null);

    Toolbar toolbar = (Toolbar) v.findViewById(R.id.toolbar);
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from www .ja v a 2 s . c  om*/
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME,
                    MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE,
                    MediaStore.Images.Media._ID },
            MediaStore.Images.Media.BUCKET_ID + " = ?",
            new String[] { String.valueOf(getArguments().getInt("bucket")) },
            MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> images = new ArrayList<GridItem>(cur.getCount());

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        "" + cur.getString(4));
                images.add(new GridItem(cur.getString(1), cur.getString(0), cur.getString(2), cur.getLong(3),
                        uri));
                cur.moveToNext();
            }
        }
        cur.close();
    }

    GridView grid = (GridView) v.findViewById(R.id.grid);
    grid.setAdapter(new GalleryAdapter(getActivity(), images));
    grid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((SelectPictureActivity) getActivity()).imageSelected(images.get(position).path,
                    images.get(position).imageTaken, images.get(position).imageSize, images.get(position).uri);
        }
    });
    return v;
}