Example usage for android.database Cursor getColumnIndex

List of usage examples for android.database Cursor getColumnIndex

Introduction

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

Prototype

int getColumnIndex(String columnName);

Source Link

Document

Returns the zero-based index for the given column name, or -1 if the column doesn't exist.

Usage

From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java

private Vector<String> getTripData(long tripId) {
    Vector<String> tripData = new Vector<String>();
    mDb.openReadOnly();/*from w  ww.j  ava2  s.c o  m*/
    Cursor tripCursor = mDb.fetchTrip(tripId);

    String note = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_NOTE));
    String purpose = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_PURP));
    Double startTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_START));
    Double endTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_END));
    tripCursor.close();
    mDb.close();

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    tripData.add(note);
    tripData.add(purpose);
    tripData.add(df.format(startTime));
    tripData.add(df.format(endTime));

    return tripData;
}

From source file:com.taxicop.sync.SyncAdapter.java

public String queryUser(ContentProviderClient provider) {
    Cursor c = null;
    String usr = null;/*w w w . j a  va 2 s  .  com*/
    try {
        c = provider.query(PlateContentProvider.URI_USERS, null, null, null, null);
        if (c.moveToFirst()) {
            usr = c.getString(c.getColumnIndex(Fields.ID_USR));
        }
    } catch (Exception e) {
        Log.e(TAG, "queryuser= " + e.getMessage());
    }
    c.close();
    return usr;
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java

@Override
public void onPositiveButtonClicked(int position) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);/*from   www . j  ava2s  . c o  m*/
    long id = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID));
    if (mServerProfileId == id) {
        Toast.makeText(getActivity(), "Can`t delete active profile", Toast.LENGTH_SHORT).show();
        return;
    }
    Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SERVER_PROFILES_CONTENT_URI, String.valueOf(id));
    int deleteCount = getActivity().getContentResolver().delete(uri, null, null);
    if (deleteCount > 0) {
        Toast.makeText(getActivity(), R.string.spm_profile_deleted_toast, Toast.LENGTH_SHORT).show();
    }
    mAdapter.finishActionMode();
}

From source file:com.googlecode.android_scripting.facade.ContactsFacade.java

@Rpc(description = "Returns a List of all contacts.", returns = "a List of contacts as Maps")
public List<JSONObject> contactsGet(@RpcParameter(name = "attributes") @RpcOptional JSONArray attributes)
        throws JSONException {
    List<JSONObject> result = new ArrayList<JSONObject>();
    String[] columns;//from   www.  j a  v  a 2s .c  o m
    if (attributes == null || attributes.length() == 0) {
        // In case no attributes are specified we set the default ones.
        columns = new String[] { "_id", "name", "primary_phone", "primary_email", "type" };
    } else {
        // Convert selected attributes list into usable string list.
        columns = new String[attributes.length()];
        for (int i = 0; i < attributes.length(); i++) {
            columns[i] = attributes.getString(i);
        }
    }
    List<String> queryList = new ArrayList<String>();
    for (String s : columns) {
        queryList.add(s);
    }
    if (!queryList.contains("_id")) {
        queryList.add("_id");
    }

    String[] query = queryList.toArray(new String[queryList.size()]);
    Cursor cursor = mContentResolver.query(CONTACTS_URI, query, null, null, null);
    if (cursor != null) {
        int idIndex = cursor.getColumnIndex("_id");
        while (cursor.moveToNext()) {
            String id = cursor.getString(idIndex);
            JSONObject message = new JSONObject();
            for (int i = 0; i < columns.length; i++) {
                String key = columns[i];
                String value = cursor.getString(cursor.getColumnIndex(key));
                if (mPhoneNumber != null) {
                    if (key.equals("primary_phone")) {
                        value = findPhone(id);
                    }
                }
                message.put(key, value);
            }
            result.add(message);
        }
        cursor.close();
    }
    return result;
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java

@Override
public void onEdit(int position) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);/*from w ww.  j  a v  a  2 s . c o  m*/

    long profileId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID));

    ServerProfileActivity_.intent(getActivity()).profileId(profileId).start();
    mAdapter.finishActionMode();
}

From source file:com.ruuhkis.cookies.CookieSQLSource.java

private int[] getPorts(long cookieId) {
    List<Integer> ports = new ArrayList<Integer>();

    Cursor cursor = db.query(CookieSQLHelper.PORT_TABLE_NAME, null, CookieSQLHelper.COLUMN_COOKIE_ID + "=?",
            new String[] { Long.toString(cookieId) }, null, null, null, null);
    cursor.moveToFirst();//from  www. j a  va  2 s.  co m

    while (!cursor.isAfterLast()) {
        ports.add(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PORT)));
        cursor.moveToNext();
    }

    cursor.close();

    int[] arrayPorts = new int[ports.size()];
    for (int i = 0; i < ports.size(); i++) {
        arrayPorts[i] = ports.get(i);
    }

    return arrayPorts;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java

public ArrayList<TrafficData> getAllTrafficFromDate(String date, int typeID) {
    ArrayList<TrafficData> list = new ArrayList<TrafficData>();
    String q = "SELECT * FROM " + LocalTransformationDB.TABLE_TRAFFIC_MON
    // + ";";//w  w w . jav a 2s  .  co m
            + " where( " + LocalTransformationDB.COLUMN_DATE_TEXT + " like '" + date + "%' AND "
            + LocalTransformationDB.COLUMN_TYPE + " = " + typeID + ")" + " ORDER BY "
            + LocalTransformationDB.COLUMN_ID + ";";
    Cursor cursor = database.rawQuery(q, null);
    if (cursor.moveToFirst()) {
        do {
            TrafficData trafficData = new TrafficData(
                    cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_DATE_TEXT)),
                    cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_TYPE)),
                    cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_X_AXIS)),
                    cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_Y_AXIS)));
            list.add(trafficData);
        } while (cursor.moveToNext());
    }
    cursor.close();
    return list;
}

From source file:it.ms.theing.loquitur.functions.PhoneDir.java

private String getEmail(String ID) {
    Cursor emails = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
            ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + ID, null, null);
    String s = "";
    if (emails.moveToNext()) {
        s = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
    }//from   ww w  .  j  a v a  2s.com
    emails.close();
    return s;
}

From source file:it.ms.theing.loquitur.functions.PhoneDir.java

private String getPhone(String ID) {
    Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + ID, null, null);
    String s = "";
    if (phones.moveToNext()) {
        s = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    }/* w  ww .j  a  va  2s. c o  m*/
    phones.close();
    return s;
}

From source file:com.newtifry.android.database.NewtifrySource.java

@Override
protected NewtifrySource inflate(Context context, Cursor cursor) {
    NewtifrySource source = new NewtifrySource();
    source.setAccountName(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_ACCOUNT_NAME)));
    source.setId(cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_ID)));
    source.setServerEnabled(/*from   www.j a  v  a 2s . c  om*/
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SERVER_ENABLED)) == 0 ? false
                    : true);
    source.setLocalEnabled(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_LOCAL_ENABLED)) == 0 ? false
                    : true);
    source.setServerId(cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SERVER_ID)));
    source.setTitle(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_TITLE)));
    source.setChangeTimestamp(
            cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_CHANGE_TIMESTAMP)));
    source.setSourceKey(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SOURCE_KEY)));
    source.setSourceColor(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SOURCE_COLOR)));

    source.setUseGlobalNotification(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_USE_GLOBAL_NOTIFICATION)) == 0
                    ? false
                    : true);
    source.setNotification(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_NOTIFICATION)) == 0 ? false
                    : true);
    source.setVibrate(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_VIBRATE)) == 0 ? false : true);
    source.setNotifierPro(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_NOTIFIERPRO)) == 0 ? false : true);
    source.setLedFlash(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_LED_FLASH)) == 0 ? false : true);
    source.setRingtone(cursor.getString(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_CUSTOM_RINGTONE)));
    source.setSpeakMessage(
            cursor.getLong(cursor.getColumnIndex(NewtifryDatabaseAdapter.KEY_SPEAK_MESSAGE)) == 0 ? false
                    : true);

    return source;
}