Example usage for android.database Cursor getDouble

List of usage examples for android.database Cursor getDouble

Introduction

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

Prototype

double getDouble(int columnIndex);

Source Link

Document

Returns the value of the requested column as a double.

Usage

From source file:com.money.manager.ex.reports.PayeeReportAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView txtColumn1 = (TextView) view.findViewById(R.id.textViewColumn1);
    TextView txtColumn2 = (TextView) view.findViewById(R.id.textViewColumn2);
    double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
    if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)))) {
        txtColumn1.setText(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)));
    } else {//from   w w  w. ja  v a 2s .c  om
        txtColumn1.setText(context.getString(R.string.empty_payee));
    }

    CurrencyService currencyService = new CurrencyService(mContext);

    txtColumn2.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(),
            MoneyFactory.fromDouble(total)));
    Core core = new Core(context);
    UIHelper uiHelper = new UIHelper(context);
    if (total < 0) {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_red_color_theme)));
    } else {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_green_color_theme)));
    }

    view.setBackgroundColor(core.resolveColorAttribute(
            cursor.getPosition() % 2 == 1 ? R.attr.row_dark_theme : R.attr.row_light_theme));
}

From source file:com.thedrycake.tempincity.ui.MainActivity.java

private void setTemp(Cursor cursor) {
    if (cursor != null && cursor.moveToFirst()) {
        double temp = cursor.getDouble(cursor.getColumnIndex(TemperatureEntity.Columns.TEMP));
        long tempDateInMillis = cursor.getLong(cursor.getColumnIndex(TemperatureEntity.Columns.TEMP_DATE));
        setTemp(temp);// w  ww.ja  v a  2s  . co  m
        setTempDate(tempDateInMillis);
    } else {
        setTempNotAvailable();
        setTempDateNotAvailable();
    }
}

From source file:com.money.manager.ex.reports.CategoriesReportAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView txtColumn1 = (TextView) view.findViewById(R.id.textViewColumn1);
    TextView txtColumn2 = (TextView) view.findViewById(R.id.textViewColumn2);

    double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
    String column1;/*from   w w  w . ja  v a2 s.  com*/
    String category = cursor.getString(cursor.getColumnIndex(ViewMobileData.Category));
    if (!TextUtils.isEmpty(category)) {
        column1 = "<b>" + category + "</b>";
        String subCategory = cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory));
        if (!TextUtils.isEmpty(subCategory)) {
            column1 += " : " + subCategory;
        }
    } else {
        column1 = "<i>" + context.getString(R.string.empty_category);
    }
    txtColumn1.setText(Html.fromHtml(column1));

    CurrencyService currencyService = new CurrencyService(mContext);

    txtColumn2.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(),
            MoneyFactory.fromDouble(total)));
    UIHelper uiHelper = new UIHelper(context);
    if (total < 0) {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_red_color_theme)));
    } else {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_green_color_theme)));
    }

    //view.setBackgroundColor(core.resolveColorAttribute(cursor.getPosition() % 2 == 1 ? R.attr.row_dark_theme : R.attr.row_light_theme));
}

From source file:org.fitchfamily.android.wifi_backend.ui.data.WifiDetailFragment.java

@AfterViews
protected void init() {
    container.setVisibility(View.INVISIBLE);

    getLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() {
        @Override//from   ww  w. j a v  a2 s .  c  o  m
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return new CursorLoader(getContext()).table(Database.TABLE_SAMPLES)
                    .selection(Database.COL_RFID + " = ?").selectionArgs(new String[] { rfId })
                    .columns(new String[] { Database.COL_LATITUDE, Database.COL_LONGITUDE, Database.COL_RADIUS,
                            Database.COL_SSID, Database.COL_LAT1, Database.COL_LON1, Database.COL_LAT2,
                            Database.COL_LON2, Database.COL_LAT3, Database.COL_LON3 });
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            if (cursor != null && cursor.moveToFirst()) {
                container.setVisibility(View.VISIBLE);

                lat = cursor.getDouble(0);
                lon = cursor.getDouble(1);
                acc = Math.max(Configuration.with(getContext()).accessPointAssumedAccuracy(),
                        cursor.getFloat(2));
                ssid = cursor.getString(3);
                smp = countSamples(cursor, 4);

                WifiDetailFragment.this.accuracy.setText(accuracy());
                WifiDetailFragment.this.samples.setText(samples());
            } else {
                container.setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            container.setVisibility(View.INVISIBLE);
        }
    });
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a Double out of a column in a Cursor and writes it to a ContentValues.
 * Adds nothing to the ContentValues if the column isn't present or if its value is null.
 *
 * @param cursor The cursor to read from
 * @param column The column to read/* w  ww . j a  va 2  s .  co m*/
 * @param values The {@link ContentValues} to put the value into
 */
public static void cursorDoubleToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) {
    final int index = cursor.getColumnIndexOrThrow(column);
    if (!cursor.isNull(index)) {
        values.put(column, cursor.getDouble(index));
    }
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a Double out of a field in a Cursor and writes it to a Map.
 *
 * @param cursor The cursor to read from
 * @param field The REAL field to read//  www  .  j av  a 2s  . c  o m
 * @param values The {@link ContentValues} to put the value into
 * @param key The key to store the value with in the map
 */
public static void cursorDoubleToContentValues(Cursor cursor, String field, ContentValues values, String key) {
    int colIndex = cursor.getColumnIndex(field);
    if (!cursor.isNull(colIndex)) {
        values.put(key, cursor.getDouble(colIndex));
    } else {
        values.put(key, (Double) null);
    }
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

private void showOnMap(ListView l, int position) {
    // Get the cursor and fetch the stop ID from that.
    SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
    Cursor c = cursorAdapter.getCursor();
    c.moveToPosition(position - l.getHeaderViewsCount());
    final String stopId = c.getString(COL_ID);
    final double lat = c.getDouble(COL_LATITUDE);
    final double lon = c.getDouble(COL_LONGITUDE);

    HomeActivity.start(getActivity(), stopId, lat, lon);
}

From source file:com.kobi.metalsexchange.app.DetailFragment.java

private String getRateForCurrency(Cursor data, String currencyId) {
    double rateRaw = data.getDouble(Utility.getPreferredCurrencyColumnId(currencyId));
    String rate = Utility.getFormattedCurrency(rateRaw, currencyId, getActivity(), true);
    return rate;//from   w ww  .  j av a 2 s  .  co m
}

From source file:com.android.unit_tests.CheckinProviderTest.java

@MediumTest
public void testStatsUpdate() {
    ContentResolver r = getContext().getContentResolver();

    // First, delete any existing data associated with the TEST tag.
    Uri uri = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 0, 0);
    assertNotNull(uri);//  w w w  .  j av  a2 s .  co m
    assertEquals(1, r.delete(uri, null, null));
    assertFalse(r.query(uri, null, null, null, null).moveToNext());

    // Now, add a known quantity to the TEST tag.
    Uri u2 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 1, 0.5);
    assertFalse(uri.equals(u2));

    Cursor c = r.query(u2, null, null, null, null);
    assertTrue(c.moveToNext());
    assertEquals(1, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT)));
    assertEquals(0.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM)));
    assertFalse(c.moveToNext()); // Only one.

    // Add another known quantity to TEST (should sum with the first).
    Uri u3 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 2, 1.0);
    assertEquals(u2, u3);
    c.requery();
    assertTrue(c.moveToNext());
    assertEquals(3, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT)));
    assertEquals(1.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM)));
    assertFalse(c.moveToNext()); // Only one.

    // Now subtract the values; the whole row should disappear.
    Uri u4 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, -3, -1.5);
    assertNull(u4);
    c.requery();
    assertFalse(c.moveToNext()); // Row has been deleted.
    c.close();
}

From source file:ca.mudar.mtlaucasou.BaseListFragment.java

/**
 * When item is selected, send geocoordinates to the listener which is
 * implemented by the Activity. The Activity deals with the MapFragment.
 *///w w  w. j ava 2s  .  com
@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    Cursor cursor = (Cursor) getListAdapter().getItem(position);

    double geoLat = cursor.getDouble(cursor.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LAT));
    double geoLng = cursor.getDouble(cursor.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LNG));

    GeoPoint geoPoint = new GeoPoint((int) (geoLat * 1E6), (int) (geoLng * 1E6));

    if (mListener != null) {
        mListener.onPlacemarkSelected(geoPoint);
    }
}