Example usage for android.database Cursor getFloat

List of usage examples for android.database Cursor getFloat

Introduction

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

Prototype

float getFloat(int columnIndex);

Source Link

Document

Returns the value of the requested column as a float.

Usage

From source file:edu.cens.loci.provider.LociDbUtils.java

/**
 * Returns an average position fix/*from   w  w w  .j av  a  2  s .com*/
 * @param start beginning time
 * @param end ending time
 * @param accuracy filter position fixes with accuracy value higher than this value
 * @return average position within the provided time interval, filtered by accuracy
 */
public LociLocation getAveragePosition(long start, long end, int accuracy) {

    LociLocation placeLoc = null;

    String[] columns = new String[] { Tracks._ID, Tracks.TIME, Tracks.LATITUDE, Tracks.LONGITUDE,
            Tracks.ALTITUDE, Tracks.SPEED, Tracks.BEARING, Tracks.ACCURACY };

    String selection = Tracks.TIME + ">=" + start + " AND " + Tracks.TIME + " <= " + end;

    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    Cursor cursor = db.query(Tables.TRACKS, columns, selection, null, null, null, null);

    ArrayList<LociLocation> track = new ArrayList<LociLocation>();

    MyLog.d(LociConfig.D.DB.UTILS, TAG,
            String.format("[DB] average position between %s-%s ==> #pos=%d (accuracy=%d)",
                    MyDateUtils.getTimeFormatLong(start), MyDateUtils.getTimeFormatLong(end), cursor.getCount(),
                    accuracy));

    if (cursor.moveToFirst()) {
        do {
            LociLocation loc = new LociLocation(LocationManager.GPS_PROVIDER);
            loc.setTime(cursor.getLong(cursor.getColumnIndex(Tracks.TIME)));
            loc.setLatitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LATITUDE)));
            loc.setLongitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LONGITUDE)));
            loc.setAltitude(cursor.getDouble(cursor.getColumnIndex(Tracks.ALTITUDE)));
            loc.setSpeed(cursor.getFloat(cursor.getColumnIndex(Tracks.SPEED)));
            loc.setBearing(cursor.getFloat(cursor.getColumnIndex(Tracks.BEARING)));
            loc.setAccuracy(cursor.getFloat(cursor.getColumnIndex(Tracks.ACCURACY)));
            track.add(loc);
        } while (cursor.moveToNext());

        placeLoc = LociLocation.averageLocation(track, accuracy);
    }
    cursor.close();
    return placeLoc;

}

From source file:com.snt.bt.recon.database.DBHandler.java

/**
 * Get all from a table and return a list
 * @return//  w  w w  . ja  v a  2  s  .c o m
 */
public <T> List<T> getAll(Class<T> cl) throws InstantiationException, IllegalAccessException {
    T inst = cl.newInstance();
    List<T> list = new ArrayList<T>();

    // Select All Query
    String selectQuery;
    Cursor cursor;
    SQLiteDatabase db = this.getWritableDatabase();
    if (inst instanceof Trip) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_TRIPS;
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Trip trip = new Trip();
                trip.setSessionId(UUID.fromString(cursor.getString(0)));
                trip.setImei(cursor.getString(1));
                trip.setTransport(cursor.getString(2));

                trip.setTimestampStart(cursor.getString(3));
                trip.setTimestampEnd(cursor.getString(4));
                trip.setAppVersion(cursor.getString(5));
                trip.setUploadStatus(cursor.getString(6));
                // Adding contact to list
                list.add((T) trip);
            } while (cursor.moveToNext());
        }
        cursor.close();

    } else if (inst instanceof GPSLocation) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_LOCATIONS;
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                GPSLocation location = new GPSLocation();
                location.setLocationId(UUID.fromString(cursor.getString(0)));
                location.setSessionId(UUID.fromString(cursor.getString(1)));
                location.setTimestamp(cursor.getString(2));
                location.setLatitude(cursor.getFloat(3));
                location.setLongitude(cursor.getFloat(4));
                location.setSpeed(cursor.getFloat(5));
                location.setBearing(cursor.getFloat(6));
                location.setAltitude(cursor.getFloat(7));
                location.setAccuracy(cursor.getFloat(8));
                location.setUploadStatus(cursor.getString(9));

                // Adding contact to list
                list.add((T) location);
            } while (cursor.moveToNext());
        }
        cursor.close();

    } else if (inst instanceof BluetoothClassicEntry) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_BC;
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                BluetoothClassicEntry bc_entry = new BluetoothClassicEntry();
                bc_entry.setSessionId(UUID.fromString(cursor.getString(1)));//START FROM 1 SINCE 0 is ID
                bc_entry.setLocationId(UUID.fromString(cursor.getString(2)));
                bc_entry.setTimestamp(cursor.getString(3));
                bc_entry.setMac(cursor.getString(4));
                bc_entry.setType(cursor.getInt(5));
                bc_entry.setRssi(cursor.getInt(6));
                bc_entry.setDeviceName(cursor.getString(7));
                bc_entry.setBcClass(cursor.getString(8));
                bc_entry.setUploadStatus(cursor.getString(9));

                // Adding contact to list
                list.add((T) bc_entry);
            } while (cursor.moveToNext());
        }
        cursor.close();

    } else if (inst instanceof BluetoothLowEnergyEntry) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_BLE;
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                BluetoothLowEnergyEntry ble_entry = new BluetoothLowEnergyEntry();
                ble_entry.setSessionId(UUID.fromString(cursor.getString(1)));//START FROM 1 SINCE 0 is ID
                ble_entry.setLocationId(UUID.fromString(cursor.getString(2)));
                ble_entry.setTimestamp(cursor.getString(3));
                ble_entry.setMac(cursor.getString(4));
                ble_entry.setRssi(cursor.getInt(5));
                ble_entry.setDeviceName(cursor.getString(6));
                ble_entry.setBleAdvData(cursor.getString(7));
                ble_entry.setUploadStatus(cursor.getString(8));

                // Adding contact to list
                list.add((T) ble_entry);
            } while (cursor.moveToNext());
        }
        cursor.close();

    }

    db.close();

    // return  list
    return list;
}

From source file:org.digitalcampus.oppia.application.DbHelper.java

public QuizStats getQuizAttempt(String digest, long userId) {
    QuizStats qs = new QuizStats();
    qs.setDigest(digest);//w w  w.  j  a v a 2 s  . c o m
    qs.setAttempted(false);
    qs.setPassed(false);

    // find if attempted
    String s1 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST + "=?";
    String[] args1 = new String[] { String.valueOf(userId), digest };
    Cursor c1 = db.query(QUIZATTEMPTS_TABLE, null, s1, args1, null, null, null);
    if (c1.getCount() == 0) {
        return qs;
    }
    c1.moveToFirst();
    while (c1.isAfterLast() == false) {
        float userScore = c1.getFloat(c1.getColumnIndex(QUIZATTEMPTS_C_SCORE));
        if (userScore > qs.getUserScore()) {
            qs.setUserScore(userScore);
        }
        qs.setMaxScore(c1.getFloat(c1.getColumnIndex(QUIZATTEMPTS_C_MAXSCORE)));
        c1.moveToNext();
    }
    c1.close();
    qs.setAttempted(true);

    // find if passed
    String s2 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST + "=? AND "
            + QUIZATTEMPTS_C_PASSED + "=1";
    String[] args2 = new String[] { String.valueOf(userId), digest };
    Cursor c2 = db.query(QUIZATTEMPTS_TABLE, null, s2, args2, null, null, null);
    if (c2.getCount() > 0) {
        qs.setPassed(true);
    }
    c2.close();

    /*
    String s3 = QUIZATTEMPTS_C_USERID + "=? AND " + QUIZATTEMPTS_C_ACTIVITY_DIGEST +"=?";
    String[] args3 = new String[] { String.valueOf(userId), digest };
    Cursor c3 = db.query(QUIZATTEMPTS_TABLE, new String [] {"MAX("+  QUIZATTEMPTS_C_SCORE +") as userscore"}, s3, args3, null, null, null);
    c3.moveToFirst();
    while (c3.isAfterLast() == false) {
               
       int userScore = c3.getInt(c3.getColumnIndex("userscore"));
       if (userScore > qs.getUserScore()){
    qs.setUserScore(userScore);
       }
       Log.d(TAG, "Score: " + c3.getInt(c3.getColumnIndex("userscore")));
       Log.d(TAG, "passed: " + qs.isPassed());
       c3.moveToNext();
    }
    c3.close();
    */
    return qs;
}

From source file:org.fitchfamily.android.wifi_backend.database.Database.java

@Nullable
public SimpleLocation getLocation(String rfId) {
    final long entryTime = System.currentTimeMillis();
    final String canonicalBSSID = AccessPoint.bssid(rfId);

    Cursor c = getReadableDatabase().query(TABLE_SAMPLES,
            new String[] { COL_LATITUDE, COL_LONGITUDE, COL_RADIUS, COL_LAT1, COL_LON1, COL_LAT2, COL_LON2,
                    COL_LAT3, COL_LON3 },
            COL_RFID + "=? AND " + COL_MOVED_GUARD + "=0", new String[] { canonicalBSSID }, null, null, null);

    try {//from   w  w  w .  ja va  2s.co  m
        if (c != null && c.moveToFirst()) {
            // We only want to return location data for APs that we have received at least
            // three samples.
            Integer sampleCount = 0;
            if (c.getDouble(3) != 0.d || c.getDouble(4) != 0.d)
                sampleCount++;
            if (c.getDouble(5) != 0.d || c.getDouble(6) != 0.d)
                sampleCount++;
            if (c.getDouble(7) != 0.d || c.getDouble(8) != 0.d)
                sampleCount++;
            if (sampleCount == 3) {

                // radius is our observed coverage but it can be quite small, as little as
                // zero if we have only one sample. We want to report an accuracy value that
                // is likely to actually contain the AP's real location and no matter how
                // many samples we have collected systemic/sampling errors will mean we dont
                // know the actual coverage radius.
                //
                // Web search indicates that 40m coverage on older WiFi protocols and 100m
                // coverage on newer APs (both ranges for outdoor conditions).
                //
                // So we will take the greater value (assumed max range) or actual measured
                // range as our assumed accuracy.

                SimpleLocation result = SimpleLocation.builder().latitude(c.getDouble(0))
                        .longitude(c.getDouble(1)).radius(Math
                                .max(Configuration.with(context).accessPointAssumedAccuracy(), c.getFloat(2)))
                        .changed(false).build();

                if (DEBUG) {
                    Log.i(TAG, rfId + " at " + result.toString());
                }

                if (DEBUG) {
                    Log.i(TAG, "getLocation time: " + (System.currentTimeMillis() - entryTime) + "ms");
                }
                c.close();
                c = null;
                return result;
            } else {
                if (DEBUG) {
                    Log.i(TAG, "getLocation(): Insufficient samples (" + sampleCount + ")");
                    Log.i(TAG, "getLocation time: " + (System.currentTimeMillis() - entryTime) + "ms");
                }
            }
        }
        c.close();
        c = null;
        return null;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:com.odoo.orm.OModel.java

/**
 * Creates the record row.//from ww  w.  j a v  a2 s .c  om
 * 
 * @param column
 *            the column
 * @param cr
 *            the cr
 * @return the object
 */
public Object createRecordRow(OColumn column, Cursor cr) {
    Object value = false;
    if (column.getDefaultValue() != null) {
        value = column.getDefaultValue();
    }
    int index = cr.getColumnIndex(column.getName());
    switch (cr.getType(index)) {
    case Cursor.FIELD_TYPE_NULL:
        value = false;
        break;
    case Cursor.FIELD_TYPE_STRING:
        value = cr.getString(index);
        break;
    case Cursor.FIELD_TYPE_INTEGER:
        value = cr.getInt(index);
        break;
    case Cursor.FIELD_TYPE_FLOAT:
        value = cr.getFloat(index);
        break;
    case Cursor.FIELD_TYPE_BLOB:
        value = cr.getBlob(index);
        break;
    }
    return value;
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Handle activity menu/*from w w w  .j  av  a  2s. c o  m*/
 */
@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    final long waypointId = waypointsArrayAdapter.getItem((int) info.id).getId();

    Cursor tmpCursor;
    String sql;

    switch (item.getItemId()) {

    case 0:

        // update waypoint in db
        updateWaypoint(waypointId);

        return true;

    case 1:

        deleteWaypoint(waypointId);

        return true;

    case 2:

        // email waypoint data using default email client

        String elevationUnit = app.getPreferences().getString("elevation_units", "m");
        String elevationUnitLocalized = Utils.getLocalizedElevationUnit(this, elevationUnit);

        sql = "SELECT * FROM waypoints WHERE _id=" + waypointId + ";";
        tmpCursor = app.getDatabase().rawQuery(sql, null);
        tmpCursor.moveToFirst();

        double lat1 = tmpCursor.getDouble(tmpCursor.getColumnIndex("lat")) / 1E6;
        double lng1 = tmpCursor.getDouble(tmpCursor.getColumnIndex("lng")) / 1E6;

        String messageBody = getString(R.string.title) + ": "
                + tmpCursor.getString(tmpCursor.getColumnIndex("title")) + "\n\n" + getString(R.string.lat)
                + ": " + Utils.formatLat(lat1, 0) + "\n" + getString(R.string.lng) + ": "
                + Utils.formatLng(lng1, 0) + "\n" + getString(R.string.elevation) + ": "
                + Utils.formatElevation(tmpCursor.getFloat(tmpCursor.getColumnIndex("elevation")),
                        elevationUnit)
                + elevationUnitLocalized + "\n\n" + "http://maps.google.com/?ll=" + lat1 + "," + lng1 + "&z=10";

        tmpCursor.close();

        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                getResources().getString(R.string.email_subject_waypoint));
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageBody);

        this.startActivity(Intent.createChooser(emailIntent, getString(R.string.sending_email)));

        return true;

    case 3:

        this.showOnMap(waypointId);

        return true;

    case 4:

        // TODO: use a thread for online sync

        // sync one waypoint data with remote server

        // create temp waypoint from current record
        Waypoint wp = Waypoints.get(app.getDatabase(), waypointId);

        try {

            // preparing query string for calling web service
            String lat = Location.convert(wp.getLocation().getLatitude(), 0);
            String lng = Location.convert(wp.getLocation().getLongitude(), 0);
            String title = URLEncoder.encode(wp.getTitle());

            String userName = app.getPreferences().getString("user_name", "");
            String userPassword = app.getPreferences().getString("user_password", "");
            String sessionValue = userName + "@" + Utils.md5("aripuca_session" + userPassword);

            if (userName.equals("") || userPassword.equals("")) {
                Toast.makeText(WaypointsListActivity.this, R.string.username_or_password_required,
                        Toast.LENGTH_SHORT).show();
                return false;
            }

            String queryString = "?do=ajax_map_handler&aripuca_session=" + sessionValue
                    + "&action=add_point&lat=" + lat + "&lng=" + lng + "&z=16&n=" + title + "&d=AndroidSync";

            // http connection
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpGet httpGet = new HttpGet(
                    app.getPreferences().getString("online_sync_url", "http://tracker.aripuca.com")
                            + queryString);
            HttpResponse response = httpClient.execute(httpGet, localContext);

            ByteArrayOutputStream outstream = new ByteArrayOutputStream();
            response.getEntity().writeTo(outstream);

            // parsing JSON return
            JSONObject jsonObject = new JSONObject(outstream.toString());

            Toast.makeText(WaypointsListActivity.this, jsonObject.getString("message").toString(),
                    Toast.LENGTH_SHORT).show();

        } catch (ClientProtocolException e) {
            Toast.makeText(WaypointsListActivity.this, "ClientProtocolException: " + e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            Toast.makeText(WaypointsListActivity.this, "IOException " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        } catch (JSONException e) {
            Toast.makeText(WaypointsListActivity.this, "JSONException " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }

        return true;

    default:
        return super.onContextItemSelected(item);
    }

}

From source file:com.snt.bt.recon.database.DBHandler.java

/**
 * Compose JSON out of SQLite records//from  w ww. j  ava2 s .  c o  m
 * @return
 */
public <T> String composeJSONfromSQLite(Class<T> cl) throws InstantiationException, IllegalAccessException {
    T inst = cl.newInstance();
    List<T> list = new ArrayList<T>();

    // Select All Query
    String selectQuery;
    Cursor cursor;
    SQLiteDatabase db = this.getWritableDatabase();
    if (inst instanceof Trip) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_TRIPS + " where " + KEY_UPLOAD_STATUS + " = '" + "no" + "' or "
                + KEY_UPLOAD_STATUS + " = '" + "partial" + "'";
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Trip trip = new Trip();
                trip.setSessionId(UUID.fromString(cursor.getString(0)));
                trip.setImei(cursor.getString(1));
                trip.setTransport(cursor.getString(2));

                trip.setTimestampStart(cursor.getString(3));
                trip.setTimestampEnd(cursor.getString(4));
                trip.setAppVersion(cursor.getString(5));

                // Adding contact to list
                list.add((T) trip);
            } while (cursor.moveToNext());
        }
        cursor.close();

    } else if (inst instanceof GPSLocation) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_LOCATIONS + " where " + KEY_UPLOAD_STATUS + " = '" + "no" + "'";
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                GPSLocation location = new GPSLocation();
                location.setLocationId(UUID.fromString(cursor.getString(0)));
                location.setSessionId(UUID.fromString(cursor.getString(1)));
                location.setTimestamp(cursor.getString(2));
                location.setLatitude(cursor.getFloat(3));
                location.setLongitude(cursor.getFloat(4));
                location.setSpeed(cursor.getFloat(5));
                location.setBearing(cursor.getFloat(6));
                location.setAltitude(cursor.getFloat(7));
                location.setAccuracy(cursor.getFloat(8));

                // Adding contact to list
                list.add((T) location);
            } while (cursor.moveToNext());
        }
        cursor.close();

    }

    else if (inst instanceof BluetoothClassicEntry) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_BC + " where " + KEY_UPLOAD_STATUS + " = '" + "no" + "'";
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                BluetoothClassicEntry bc_entry = new BluetoothClassicEntry();
                bc_entry.setId(cursor.getInt(0));
                bc_entry.setSessionId(UUID.fromString(cursor.getString(1)));
                bc_entry.setLocationId(UUID.fromString(cursor.getString(2)));
                bc_entry.setTimestamp(cursor.getString(3));
                bc_entry.setMac(cursor.getString(4));
                bc_entry.setType(cursor.getInt(5));
                bc_entry.setRssi(cursor.getInt(6));
                bc_entry.setDeviceName(cursor.getString(7));
                bc_entry.setBcClass(cursor.getString(8));

                // Adding contact to list
                list.add((T) bc_entry);
            } while (cursor.moveToNext());
        }
        cursor.close();

    }

    else if (inst instanceof BluetoothLowEnergyEntry) {
        // Select All Query
        selectQuery = "SELECT * FROM " + TABLE_BLE + " where " + KEY_UPLOAD_STATUS + " = '" + "no" + "'";
        cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                BluetoothLowEnergyEntry ble_entry = new BluetoothLowEnergyEntry();
                ble_entry.setId(cursor.getInt(0));
                ble_entry.setSessionId(UUID.fromString(cursor.getString(1)));
                ble_entry.setLocationId(UUID.fromString(cursor.getString(2)));
                ble_entry.setTimestamp(cursor.getString(3));
                ble_entry.setMac(cursor.getString(4));
                ble_entry.setRssi(cursor.getInt(5));
                ble_entry.setDeviceName(cursor.getString(6));
                ble_entry.setBleAdvData(cursor.getString(7));

                // Adding contact to list
                list.add((T) ble_entry);
            } while (cursor.moveToNext());
        }
        cursor.close();
    }

    db.close();

    // return contact list
    Gson gson = new GsonBuilder().create();
    //Use GSON to serialize Array List to JSON
    Log.d("DatabaseTest", "composeJSONfromSQLite " + cl.getName() + " " + gson.toJson(list));

    return gson.toJson(list);
}

From source file:net.simonvt.cathode.ui.fragment.ShowFragment.java

private void updateShowView(final Cursor cursor) {
    if (cursor == null || !cursor.moveToFirst())
        return;/*from w  w w  . ja  va  2 s. c om*/

    String title = cursor.getString(cursor.getColumnIndex(ShowColumns.TITLE));
    if (!TextUtils.equals(title, showTitle)) {
        showTitle = title;
        updateTitle();
    }
    final String airTime = cursor.getString(cursor.getColumnIndex(ShowColumns.AIR_TIME));
    final String airDay = cursor.getString(cursor.getColumnIndex(ShowColumns.AIR_DAY));
    final String network = cursor.getString(cursor.getColumnIndex(ShowColumns.NETWORK));
    final String certification = cursor.getString(cursor.getColumnIndex(ShowColumns.CERTIFICATION));
    final String posterUrl = cursor.getString(cursor.getColumnIndex(ShowColumns.POSTER));
    if (posterUrl != null) {
        poster.setImage(posterUrl);
    }
    final String fanartUrl = cursor.getString(cursor.getColumnIndex(ShowColumns.FANART));
    if (fanartUrl != null) {
        fanart.setImage(fanartUrl);
    }
    final String overview = cursor.getString(cursor.getColumnIndex(ShowColumns.OVERVIEW));
    inWatchlist = cursor.getInt(cursor.getColumnIndex(ShowColumns.IN_WATCHLIST)) == 1;
    final int inCollectionCount = cursor.getInt(cursor.getColumnIndex(ShowColumns.IN_COLLECTION_COUNT));
    final int watchedCount = cursor.getInt(cursor.getColumnIndex(ShowColumns.WATCHED_COUNT));
    isHidden = cursor.getInt(cursor.getColumnIndex(ShowColumns.HIDDEN)) == 1;

    currentRating = cursor.getInt(cursor.getColumnIndex(ShowColumns.USER_RATING));
    final float ratingAll = cursor.getFloat(cursor.getColumnIndex(ShowColumns.RATING));
    rating.setValue(ratingAll);

    watched.setVisibility(watchedCount > 0 ? View.VISIBLE : View.GONE);
    collection.setVisibility(inCollectionCount > 0 ? View.VISIBLE : View.GONE);
    watchlist.setVisibility(inWatchlist ? View.VISIBLE : View.GONE);

    String airTimeString = null;
    if (airDay != null && airTime != null) {
        airTimeString = airDay + " " + airTime;
    }
    if (network != null) {
        if (airTimeString != null) {
            airTimeString += ", " + network;
        } else {
            airTimeString = network;
        }
    }

    this.airTime.setText(airTimeString);
    this.certification.setText(certification);
    this.overview.setText(overview);

    setContentVisible(true);
    invalidateMenu();
}

From source file:th.in.ffc.person.PersonDetailViewFragment.java

private void doShowRegularData(Cursor c) {
    addTitle(getString(R.string.personal_data));

    addContentArrayFormat(getString(R.string.sex), c.getString(c.getColumnIndex(Person.SEX)), R.array.sex);

    addContent(R.string.nickname, c.getString(c.getColumnIndex(Person.NICKNAME)));

    String birth = c.getString(c.getColumnIndex(Person.BIRTH));
    mBorn = Date.newInstance(birth);
    addContent(R.string.birthday, DateTime.getFullFormatThai(getActivity(), mBorn));

    Date current = Date.newInstance(DateTime.getCurrentDate());
    if (mBorn != null) {
        AgeCalculator cal = new AgeCalculator(current, mBorn);
        Date age = cal.calulate();
        mDeath = addContent(R.string.age, AgeCalculator.toAgeFormat(this.getFFCActivity(), age));
        getActivity().getSupportLoaderManager().initLoader(LOAD_DEATH, null, this);
    }/*w  w w  .j ava  2  s.  co m*/

    addContent(R.string.blood, PersonUtils.getBlood(c.getString(c.getColumnIndex(Person.BLOOD_GROUP)),
            c.getString(c.getColumnIndex(Person.BLOOD_RH))));

    addContent(R.string.allergic, c.getString(c.getColumnIndex(Person.ALLERGIC)));

    String nation = c.getString(c.getColumnIndex(Person.NATION));
    if (!TextUtils.isEmpty(nation))
        addContentQuery(R.string.nation, Nation.NAME, Uri.withAppendedPath(Nation.CONTENT_URI, nation), null);

    String origin = c.getString(c.getColumnIndex(Person.ORIGIN));
    if (!TextUtils.isEmpty(origin))
        addContentQuery(R.string.origin, Nation.NAME, Uri.withAppendedPath(Nation.CONTENT_URI, origin), null);

    addContentArrayFormat(getString(R.string.religion), c.getString(c.getColumnIndex(Person.RELIGION)),
            R.array.religion);

    addContentArrayFormat(getString(R.string.education), c.getString(c.getColumnIndex(Person.EDUCATION)),
            R.array.education);

    String occupa = c.getString(c.getColumnIndex(Person.OCCUPA));
    if (!TextUtils.isEmpty(occupa))
        addContentQuery(R.string.occupa, Occupation.NAME, Uri.withAppendedPath(Occupation.CONTENT_URI, occupa),
                null);

    addContent(R.string.income,
            PersonUtils.getIncome(this.getActivity(), c.getFloat(c.getColumnIndex(Person.INCOME))));
    addContent(R.string.tel, c.getString(c.getColumnIndex(Person.TEL)));

}

From source file:org.digitalcampus.oppia.application.DbHelper.java

public void getCourseQuizResults(ArrayList<QuizStats> stats, int courseId, long userId) {

    String quizResultsWhereClause = QUIZATTEMPTS_C_COURSEID + " =? AND " + QUIZATTEMPTS_C_USERID + "=?";
    String[] quizResultsArgs = new String[] { String.valueOf(courseId), String.valueOf(userId) };
    String[] quizResultsColumns = new String[] { QUIZATTEMPTS_C_ACTIVITY_DIGEST, QUIZATTEMPTS_C_PASSED,
            QUIZATTEMPTS_C_MAXSCORE, QUIZATTEMPTS_C_SCORE };

    //We get the attempts made by the user for this course's quizzes
    Cursor c = db.query(QUIZATTEMPTS_TABLE, quizResultsColumns, quizResultsWhereClause, quizResultsArgs, null,
            null, null);/*w w w.j  a v  a 2s. co  m*/
    if (c.getCount() <= 0)
        return; //we return the empty array

    if (stats == null)
        stats = new ArrayList<QuizStats>();

    c.moveToFirst();
    while (!c.isAfterLast()) {
        String quizDigest = c.getString(c.getColumnIndex(QUIZATTEMPTS_C_ACTIVITY_DIGEST));
        int score = (int) (c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_SCORE)) * 100);
        int maxScore = (int) (c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_MAXSCORE)) * 100);
        boolean passed = c.getInt(c.getColumnIndex(QUIZATTEMPTS_C_PASSED)) > 0;

        boolean alreadyInserted = false;
        for (QuizStats quiz : stats) {
            if (quiz.getDigest().equals(quizDigest)) {
                if (quiz.getUserScore() < score)
                    quiz.setUserScore(score);
                if (quiz.getMaxScore() < maxScore)
                    quiz.setMaxScore(maxScore);
                quiz.setAttempted(true);
                quiz.setPassed(passed);
                Log.d(TAG, "quiz score: " + quiz.getUserScore());
                Log.d(TAG, "quiz passed: " + quiz.isPassed());
                alreadyInserted = true;
                break;
            }
        }
        if (!alreadyInserted) {
            QuizStats quiz = new QuizStats();
            quiz.setAttempted(true);
            quiz.setDigest(quizDigest);
            quiz.setUserScore(score);
            quiz.setMaxScore(maxScore);
            quiz.setPassed(passed);
            stats.add(quiz);
        }

        c.moveToNext();
    }
    c.close();

}