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:nz.co.wholemeal.christchurchmetro.Stop.java

public Stop(String platformTag, String platformNumber, Context context) throws InvalidPlatformNumberException {

    String queryBase = "SELECT platform_tag, platform_number, name, road_name, latitude, longitude FROM platforms ";
    String whereClause;//ww  w . ja  va2  s  . c om
    String whereParameter;

    if (platformTag == null) {
        whereClause = "WHERE platform_number = ?";
        whereParameter = platformNumber;
    } else {
        whereClause = "WHERE platform_tag = ?";
        whereParameter = platformTag;
    }

    DatabaseHelper databaseHelper = new DatabaseHelper(context);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();

    Cursor cursor = database.rawQuery(queryBase + whereClause, new String[] { whereParameter });

    if (cursor.moveToFirst()) {
        this.platformTag = cursor.getString(0);
        this.platformNumber = cursor.getString(1);
        this.name = cursor.getString(2);
        this.roadName = cursor.getString(3);
        this.latitude = cursor.getDouble(4);
        this.longitude = cursor.getDouble(5);
        cursor.close();
        database.close();
    } else {
        cursor.close();
        database.close();
        throw new InvalidPlatformNumberException("Invalid platform");
    }
}

From source file:com.Sunshine.MainActivity.java

/**
 * Called when a Loader has finished loading its data.
 *
 * NOTE: There is one small bug in this code. If no data is present in the cursor do to an
 * initial load being performed with no access to internet, the loading indicator will show
 * indefinitely, until data is present from the ContentProvider. This will be fixed in a
 * future version of the course.// www  . j  ava2 s. c o  m
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 */
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    mForecastAdapter.swapCursor(data);
    if (mPosition == RecyclerView.NO_POSITION)
        mPosition = 0;
    mRecyclerView.smoothScrollToPosition(mPosition);
    if (data.getCount() != 0)
        showWeatherDataView();

    data.moveToPosition(1);
    int high = (int) data.getDouble(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP));
    int low = (int) data.getDouble(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));
    int id = data.getInt(data.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID));
    Intent i = new Intent(MainActivity.this, WearableDataSync.class);
    i.putExtra("high", high);
    i.putExtra("low", low);
    i.putExtra("w_id", id);
    startService(i);
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    super.onLoadFinished(loader, data);
    switch (loader.getId()) {
    case ID_LOADER:
        if (data == null)
            return;

        //parse cursor for calculate total
        double totalAmount = 0;
        while (data.moveToNext()) {
            totalAmount += data.getDouble(data.getColumnIndex("TOTAL"));
        }/*from w w w  .  jav  a 2 s.  c om*/

        CurrencyService currencyService = new CurrencyService(getContext());

        TextView txtColumn2 = (TextView) mFooterListView.findViewById(R.id.textViewColumn2);
        txtColumn2.setText(currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(totalAmount)));

        // solve bug chart
        if (data.getCount() > 0) {
            getListView().removeFooterView(mFooterListView);
            getListView().addFooterView(mFooterListView);
        }
        // handler to show chart
        if (((PayeesReportActivity) getActivity()).mIsDualPanel) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    showChart();
                }
            }, 1 * 1000);
        }
    }
}

From source file:org.aquabase.DetailsFragment.java

public void setData(Cursor cursor, Vector<Pair<String, Integer>> columns) {
    mLabelIds.clear();/*from   w w  w  .ja  va  2s.  co m*/
    mValues.clear();

    for (Pair<String, Integer> pair : columns) {
        String columnName = pair.first;
        String value = new String();

        int columnIndex = cursor.getColumnIndexOrThrow(columnName);
        switch (cursor.getType(columnIndex)) {
        case Cursor.FIELD_TYPE_STRING:
            value = cursor.getString(columnIndex);
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            value = Double.toString(cursor.getDouble(columnIndex));
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            value = Integer.toString(cursor.getInt(columnIndex));
            break;
        default:
        }

        mLabelIds.add(pair.second);
        mValues.add(value);
    }
}

From source file:piuk.blockchain.android.ui.ExchangeRatesFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

    setEmptyText(getString(R.string.exchange_rates_fragment_empty_text));

    adapter = new SimpleCursorAdapter(getActivity(), R.layout.exchange_rate_row, null,
            new String[] { ExchangeRatesProvider.KEY_CURRENCY_CODE, ExchangeRatesProvider.KEY_EXCHANGE_RATE_15M,
                    ExchangeRatesProvider.KEY_EXCHANGE_RATE_24H,
                    ExchangeRatesProvider.KEY_EXCHANGE_RATE_SYMBOL },
            new int[] { R.id.exchange_rate_currency_code, R.id.exchange_rate_value, R.id.exchange_up_down,
                    R.id.exchange_rate_symbol },
            0);//  w w w .ja v a2  s.co  m

    adapter.setViewBinder(new ViewBinder() {
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {

            String columnName = cursor.getColumnName(columnIndex);

            if (columnName.equals(ExchangeRatesProvider.KEY_CURRENCY_CODE)) {
                return false;
            } else if (columnName.equals(ExchangeRatesProvider.KEY_EXCHANGE_RATE_15M)) {
                final TextView valueView = (TextView) view;

                final double _15m = cursor.getDouble(columnIndex);

                valueView.setText(format.format(_15m));

                return true;
            } else if (columnName.equals(ExchangeRatesProvider.KEY_EXCHANGE_RATE_15M)) {
                final TextView valueView = (TextView) view;

                final String symbol = cursor.getString(columnIndex);

                valueView.setText(symbol);

                return true;
            } else if (columnName.equals(ExchangeRatesProvider.KEY_EXCHANGE_RATE_24H)) {
                final ImageView image = (ImageView) view;

                double _15MValue = cursor
                        .getDouble(cursor.getColumnIndex(ExchangeRatesProvider.KEY_EXCHANGE_RATE_15M));
                double _24HValue = cursor.getDouble(columnIndex);

                if (_15MValue > _24HValue) {
                    image.setImageResource(R.drawable.icon_up_green);
                } else if (_15MValue < _24HValue) {
                    image.setImageResource(R.drawable.icon_down_red);
                } else {
                    image.setImageResource(R.drawable.icon_right_black);
                }

                return true;
            }

            return false;
        }
    });

    setListAdapter(adapter);

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

From source file:nintao.com.android.study.sunshine.ForecastAdapter.java

private String convertCursorRowToUXFormat(Cursor cursor) {

    //        // get row indices for our cursor
    //        int idx_max_temp = cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP);
    //        int idx_min_temp = cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP);
    //        int idx_date = cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_DATE);
    //        int idx_short_desc = cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC);

    String highAndLow = formatHighLows(cursor.getDouble(COL_WEATHER_MAX_TEMP),
            cursor.getDouble(COL_WEATHER_MIN_TEMP));

    return Utility.formatDate(cursor.getLong(COL_WEATHER_DATE)) + " - " + cursor.getString(COL_WEATHER_DESC)
            + " - " + highAndLow;
}

From source file:org.voidsink.anewjkuapp.fragment.MapFragment.java

private void finishSearch(Uri uri) {
    Log.i(TAG, "finish search: " + uri.toString());

    // jump to point with given Uri
    ContentResolver cr = getActivity().getContentResolver();

    Cursor c = cr.query(uri, ImportPoiTask.POI_PROJECTION, null, null, null);
    if (c.moveToNext()) {
        String name = c.getString(ImportPoiTask.COLUMN_POI_NAME);
        double lon = c.getDouble(ImportPoiTask.COLUMN_POI_LON);
        double lat = c.getDouble(ImportPoiTask.COLUMN_POI_LAT);

        setNewGoal(new LatLong(lat, lon), name);
    }/* w ww.ja  v  a  2s  . c o m*/
    if (mSearchView != null) {
        mSearchView.setQuery("", false);
    }
}

From source file:export.format.FacebookCourse.java

public JSONObject export(long activityId, boolean showTrail, JSONObject runObj)
        throws IOException, JSONException {

    final String[] aColumns = { DB.ACTIVITY.NAME, DB.ACTIVITY.COMMENT, DB.ACTIVITY.START_TIME,
            DB.ACTIVITY.DISTANCE, DB.ACTIVITY.TIME, DB.ACTIVITY.SPORT };
    Cursor cursor = mDB.query(DB.ACTIVITY.TABLE, aColumns, "_id = " + activityId, null, null, null, null);
    cursor.moveToFirst();//from   w  w w .ja v a 2  s.c  o m

    if (runObj != null) {
        runObj.put("sport", cursor.getInt(5));
        runObj.put("startTime", cursor.getLong(2));
        runObj.put("endTime", cursor.getLong(2) + cursor.getLong(4));
        if (!cursor.isNull(1))
            runObj.put("comment", cursor.getString(1));
    }

    JSONObject obj = new JSONObject();
    double distance = cursor.getDouble(3);
    long duration = cursor.getLong(4);
    cursor.close();

    double unitMeters = formatter.getUnitMeters();
    if (distance < unitMeters) {
        obj.put("distance", new JSONObject().put("value", distance).put("units", "m"));
    } else {
        final int decimals = 1;
        double base = distance / unitMeters;
        double val = Formatter.round(base, decimals);
        obj.put("distance", new JSONObject().put("value", val).put("units", formatter.getUnitString()));
    }

    obj.put("duration", new JSONObject().put("value", duration).put("units", "s"));
    if (distance != 0) {
        obj.put("pace", pace(distance, duration));
    }

    if (showTrail) {
        JSONArray trail = trail(activityId);
        if (trail != null)
            obj.put("metrics", trail);
    }

    return obj;
}

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

public void showChart() {
    PayeeReportAdapter adapter = (PayeeReportAdapter) getListAdapter();
    if (adapter == null)
        return;//from  w w  w . j  a  v a  2s.c  o  m
    Cursor cursor = adapter.getCursor();
    if (cursor == null)
        return;
    if (!cursor.moveToFirst())
        return;

    ArrayList<ValuePieEntry> arrayList = new ArrayList<ValuePieEntry>();
    while (!cursor.isAfterLast()) {
        ValuePieEntry item = new ValuePieEntry();
        // total
        double total = Math.abs(cursor.getDouble(cursor.getColumnIndex("TOTAL")));
        if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)))) {
            item.setText(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)));
        } else {
            item.setText(getString(R.string.empty_payee));
        }
        item.setValue(total);
        CurrencyService currencyService = new CurrencyService(getContext());
        item.setValueFormatted(currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(total)));
        // add element
        arrayList.add(item);
        // move to next record
        cursor.moveToNext();
    }

    Bundle args = new Bundle();
    args.putSerializable(PieChartFragment.KEY_CATEGORIES_VALUES, arrayList);
    //get fragment manager
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    if (fragmentManager != null) {
        PieChartFragment fragment;
        fragment = (PieChartFragment) fragmentManager
                .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName());
        if (fragment == null) {
            fragment = new PieChartFragment();
        }
        fragment.setChartArguments(args);
        fragment.setDisplayHomeAsUpEnabled(true);

        if (fragment.isVisible())
            fragment.onResume();

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (((PayeesReportActivity) getActivity()).mIsDualPanel) {
            fragmentTransaction.replace(R.id.fragmentChart, fragment, PieChartFragment.class.getSimpleName());
        } else {
            fragmentTransaction.replace(R.id.fragmentMain, fragment, PieChartFragment.class.getSimpleName());
            fragmentTransaction.addToBackStack(null);
        }
        try {
            fragmentTransaction.commit();
        } catch (IllegalStateException e) {
            Timber.e(e, "adding fragment");
        }
    }
}

From source file:planets.position.Planets.java

/**
 * Loads the device location from the DB, or shows the location alert dialog
 * box./*from  w  ww  .ja  v a2s.c o m*/
 */
private void loadLocation() {
    if (checkLocation()) {
        Cursor locCur = cr.query(Uri.withAppendedPath(PlanetsDbProvider.LOCATION_URI, String.valueOf(0)),
                projection, null, null, null);
        locCur.moveToFirst();
        latitude = locCur.getDouble(locCur.getColumnIndexOrThrow("lat"));
        longitude = locCur.getDouble(locCur.getColumnIndexOrThrow("lng"));
        offset = locCur.getDouble(locCur.getColumnIndexOrThrow("offset"));
        elevation = locCur.getDouble(locCur.getColumnIndexOrThrow("elevation"));
    } else {
        // showLocationDataAlert();
        locationDialog = LocationDialog.newInstance();
        locationDialog.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
        locationDialog.show(getSupportFragmentManager(), "locDialogMain");
    }
}