Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:de.escoand.readdaily.DownloadHandler.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    final Database db = Database.getInstance(context);
    final Cursor downloads = db.getDownloads();

    LogHandler.log(Log.WARN, "receive starting");

    while (downloads.moveToNext()) {
        final long id = downloads.getLong(downloads.getColumnIndex(Database.COLUMN_ID));
        final String name = downloads.getString(downloads.getColumnIndex(Database.COLUMN_SUBSCRIPTION));
        final String mime = downloads.getString(downloads.getColumnIndex(Database.COLUMN_TYPE));
        final Cursor download = manager.query(new DownloadManager.Query().setFilterById(id));

        // download exists
        if (!download.moveToFirst())
            continue;

        // download finished
        if (download.getInt(
                download.getColumnIndex(DownloadManager.COLUMN_STATUS)) != DownloadManager.STATUS_SUCCESSFUL)
            continue;

        // import file in background
        new Thread(new Runnable() {
            @Override//from  w  w w  .j  ava 2  s  . c o m
            public void run() {
                try {
                    LogHandler.log(Log.WARN, "import starting of " + name);

                    final FileInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(
                            manager.openDownloadedFile(id));
                    final String mimeServer = manager.getMimeTypeForDownloadedFile(id);

                    LogHandler.log(Log.INFO, "id: " + String.valueOf(id));
                    LogHandler.log(Log.INFO, "manager: " + manager.toString());
                    LogHandler.log(Log.INFO, "stream: " + stream.toString());
                    LogHandler.log(Log.INFO, "mime: " + mime);
                    LogHandler.log(Log.INFO, "mimeServer: " + mimeServer);

                    switch (mime != null ? mime : (mimeServer != null ? mimeServer : "")) {

                    // register feedback
                    case "application/json":
                        final byte[] buf = new byte[256];
                        final int len = stream.read(buf);
                        LogHandler.log(Log.WARN, "register feedback: " + new String(buf, 0, len));
                        break;

                    // csv data
                    case "text/plain":
                        db.importCSV(name, stream);
                        break;

                    // xml data
                    case "application/xml":
                    case "text/xml":
                        db.importXML(name, stream);
                        break;

                    // zipped data
                    case "application/zip":
                        db.importZIP(name, stream);
                        break;

                    // do nothing
                    default:
                        LogHandler.log(new IntentFilter.MalformedMimeTypeException());
                        break;
                    }

                    stream.close();
                    LogHandler.log(Log.WARN, "import finished (" + name + ")");
                }

                // file error
                catch (FileNotFoundException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_open);
                }

                // stream error
                catch (IOException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_read);
                }

                // xml error
                catch (XmlPullParserException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_xml);
                }

                // clean
                finally {
                    manager.remove(id);
                    db.removeDownload(id);
                    LogHandler.log(Log.WARN, "clean finished");
                }
            }
        }).start();
    }

    downloads.close();
    LogHandler.log(Log.WARN, "receiving done");
}

From source file:github.popeen.dsub.util.SongDBHandler.java

public synchronized Pair<Integer, String> getIdFromPath(String path) {
    SQLiteDatabase db = this.getReadableDatabase();

    String[] columns = { SONGS_SERVER_KEY, SONGS_SERVER_ID };
    Cursor cursor = db.query(TABLE_SONGS, columns, SONGS_COMPLETE_PATH + " = ?", new String[] { path }, null,
            null, SONGS_LAST_PLAYED + " DESC", null);

    try {//from   www .  j  a v a  2  s.c  om
        cursor.moveToFirst();
        return new Pair(cursor.getInt(0), cursor.getString(1));
    } catch (Exception e) {
        return null;
    } finally {
        db.close();
    }
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void logSentMessage(String msgId, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    /* Check first that the number of logged messages for this group is not greater than the 
    * limit impossed per group, because if it's greater we must delete number-limit older logs
    * until the table only has the limit. This is done this way because on the MessageList a set
    * is built with the post messages from that group, and then every loaded message's msgId is checked 
    * to see if it's in the set (to check for replies to our messages), so allowing it to grow too much
    * could make the MessageView slow/* ww  w .j  av a 2  s.c o  m*/
    */

    Cursor c = dbwrite.rawQuery(
            "SELECT _id FROM sent_posts_log WHERE subscribed_group_id=" + groupid + " ORDER BY _id", null);
    int count = c.getCount();
    int toKill = count - UsenetConstants.SENT_POSTS_LOG_LIMIT_PER_GROUP;
    int kennyId;

    if (toKill > 0) {
        // Delete some more than needed so we don't have to do this on every post sent
        toKill += UsenetConstants.SENT_POST_KILL_ADITIONAL;
        c.moveToFirst();

        for (int i = 0; i < toKill; i++) {
            kennyId = c.getInt(0);
            dbwrite.execSQL("DELETE FROM sent_posts_log WHERE _id=" + kennyId);
            c.moveToNext();
        }
    }
    c.close();

    // Now we have room for sure, insert the log
    ContentValues cv = new ContentValues(2);
    cv.put("server_article_id", msgId);
    cv.put("subscribed_group_id", groupid);
    dbwrite.insert("sent_posts_log", null, cv);

    dbwrite.close();
    db.close();
}

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
    // + ";";//ww w . j a v a2s . 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:com.android.providers.contacts.ContactsSyncAdapter.java

private static void cursorToContactsElement(ContactsElement element, Cursor c, HashMap<Integer, Byte> map) {
    final int typeIndex = c.getColumnIndexOrThrow("type");
    final int labelIndex = c.getColumnIndexOrThrow("label");
    final int isPrimaryIndex = c.getColumnIndexOrThrow("isprimary");

    element.setLabel(c.getString(labelIndex));
    element.setType(map.get(c.getInt(typeIndex)));
    element.setIsPrimary(c.getInt(isPrimaryIndex) != 0);
}

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

boolean isSigningIn(Cursor cursor) {
    int connectionStatus = cursor.getInt(ACCOUNT_CONNECTION_STATUS);
    return connectionStatus == Imps.ConnectionStatus.CONNECTING;
}

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

private boolean isSignedIn(Cursor cursor) {
    int connectionStatus = cursor.getInt(ACCOUNT_CONNECTION_STATUS);

    return connectionStatus == Imps.ConnectionStatus.ONLINE;
}

From source file:com.github.gfx.android.orma.migration.SchemaDiffMigration.java

@NonNull
private Pair<Integer, String> fetchSchemaVersions(Database db) {
    ensureHistoryTableExists(db);//  w ww .  j  av  a  2 s .com
    Cursor cursor = db.query(MIGRATION_STEPS_TABLE, new String[] { kDbVersion, kSchemaHash }, null, null, null,
            null, kId + " DESC", "1");
    try {
        if (cursor.moveToFirst()) {
            return new Pair<>(cursor.getInt(0), cursor.getString(1));
        } else {
            return new Pair<>(0, "");
        }
    } finally {
        cursor.close();
    }
}

From source file:jen.jobs.application.UpdateJobSeeking.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_update_job_seeking);
    setTitle(getText(R.string.update_job_seeking));

    sharedPref = this.getSharedPreferences(MainActivity.JENJOBS_SHARED_PREFERENCE, Context.MODE_PRIVATE);
    profileId = sharedPref.getInt("js_profile_id", 0);
    isOnline = Jenjobs.isOnline(getApplicationContext());

    selectedMalaysiaState = (TextView) findViewById(R.id.selectedMalaysiaState);
    selectedCountry = (TextView) findViewById(R.id.selectedCountry);
    selectedJobSeekingStatus = (TextView) findViewById(R.id.selectedJobSeekingStatus);
    selectedJobNotice = (TextView) findViewById(R.id.selectedJobNotice);
    TextView licenseLabel = (TextView) findViewById(R.id.licenseLabel);
    TextView ownTransportLabel = (TextView) findViewById(R.id.ownTransportLabel);
    cbLicense = (CheckBox) findViewById(R.id.license);
    cbTransport = (CheckBox) findViewById(R.id.own_transport);

    LinearLayout selectJobSeekingStatus = (LinearLayout) findViewById(R.id.selectJobSeekingStatus);
    LinearLayout selectCountry = (LinearLayout) findViewById(R.id.selectCountry);
    selectMalaysiaState = (LinearLayout) findViewById(R.id.selectMalaysiaState);
    selectMalaysiaStateSibling = findViewById(R.id.selectMalaysiaStateSibling);
    LinearLayout selectJobNotice = (LinearLayout) findViewById(R.id.selectJobNotice);

    // TODO - read default values from db
    tableProfile = new TableProfile(getApplicationContext());
    tableAddress = new TableAddress(getApplicationContext());
    Profile profile = tableProfile.getProfile();

    Cursor c = tableAddress.getAddress();
    if (c.moveToFirst()) {
        int _country_id = c.getInt(8);
        String _country_name = c.getString(11);
        int _state_id = c.getInt(6);
        String _state_name = c.getString(7);

        //Log.e("country_id", ""+_country_id);
        //Log.e("country_name", _country_name);

        if (_country_id > 0 && _country_name.length() > 0) {
            selectedCountry.setText(_country_name);
            selectedCountryValues = new Country(_country_id, _country_name);
        }// w  w w .  ja v  a2s  . com

        if (_state_id > 0 && _state_name.length() > 0) {
            selectedMalaysiaStateValues = new State(_state_id, _state_name);
            selectedMalaysiaState.setText(_state_name);
        }
    }
    c.close();

    if (profile.js_jobseek_status_id > 0) {
        HashMap jobseekStatus = Jenjobs.getJobSeekingStatus();
        String _jssValue = (String) jobseekStatus.get(profile.js_jobseek_status_id);
        selectedJobSeekingStatusValues = new JobSeekingStatus(profile.js_jobseek_status_id, _jssValue);
        selectedJobSeekingStatus.setText(_jssValue);
    }

    if (profile.availability > 0 && profile.availability_unit.length() > 0) {
        selectedAvailability = String.valueOf(profile.availability);

        String[] _av = getResources().getStringArray(R.array.availability_unit);
        for (String a_av : _av) {
            if (a_av.substring(0, 1).equals(profile.availability_unit)) {
                selectedAvailabilityUnit = a_av;
            }
        }

        String a = selectedAvailability + " " + selectedAvailabilityUnit;
        selectedJobNotice.setText(a);
    }

    if (profile.driving_license) {
        cbLicense.setChecked(true);
    }

    if (profile.transport) {
        cbTransport.setChecked(true);
    }

    licenseLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cbLicense.setChecked(!cbLicense.isChecked());
        }
    });

    ownTransportLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cbTransport.setChecked(!cbTransport.isChecked());
        }
    });

    selectJobSeekingStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectJobSeekingStatus.class);
            if (selectedJobSeekingStatusValues != null) {
                intent.putExtra("jobseekingstatus", selectedJobSeekingStatusValues);
            }
            startActivityForResult(intent, SELECT_JOB_SEEKING_STATUS);
        }
    });

    selectCountry.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectCountry.class);
            intent.putExtra("single", true);
            startActivityForResult(intent, SELECT_COUNTRY);
        }
    });

    selectMalaysiaState.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectState.class);
            intent.putExtra("single", true);
            startActivityForResult(intent, SELECT_STATE);
        }
    });

    selectJobNotice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), UpdateNoticePeriod.class);
            // TODO - set saved period
            startActivityForResult(intent, SELECT_JOB_NOTICE);
        }
    });

    Button update = (Button) findViewById(R.id.save_jobseeking_information);
    update.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    Button cancelButton = (Button) findViewById(R.id.cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
}

From source file:com.tcm.sunshine.app.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city// w  w  w.j  a v a  2s . c om
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI

    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cursor = contentResolver.query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID },
            LocationEntry.COLUMN_CITY_NAME + " = ?", new String[] { cityName }, null);
    try {
        if (cursor.moveToFirst()) {
            return cursor.getInt(cursor.getColumnIndex(LocationEntry._ID));
        }
    } finally {
        cursor.close();
    }

    ContentValues contentValues = new ContentValues();
    contentValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
    contentValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
    contentValues.put(LocationEntry.COLUMN_COORD_LAT, lat);
    contentValues.put(LocationEntry.COLUMN_COORD_LONG, lon);
    Uri insertUri = contentResolver.insert(LocationEntry.CONTENT_URI, contentValues);

    return ContentUris.parseId(insertUri);
}