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.crankworks.cycletracks.TripUploader.java

private Vector<String> getTripData(long tripId) {
    Vector<String> tripData = new Vector<String>();
    mDb.openReadOnly();/*from ww  w  .ja  v  a 2 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");
    tripData.add(note);
    tripData.add(purpose);
    tripData.add(df.format(startTime));
    tripData.add(df.format(endTime));

    return tripData;
}

From source file:src.com.nustats.pacelogger.TripUploader.java

private Vector<String> getTripData(long tripId) {
    Vector<String> tripData = new Vector<String>();
    mDb.openReadOnly();//w w w .j  a v a2s.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");
    tripData.add(note);
    tripData.add(purpose);
    tripData.add(df.format(startTime));
    tripData.add(df.format(endTime));

    return tripData;
}

From source file:com.money.manager.ex.fragment.AccountFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case ID_LOADER_SUMMARY:
        if (data != null && data.moveToFirst()) {
            mAccountBalance = data.getDouble(data.getColumnIndex(QueryAccountBills.TOTAL));
            mAccountReconciled = data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILED));
        } else {//from w w w .j av a  2s .c om
            mAccountBalance = 0;
            mAccountReconciled = 0;
        }
        // show balance values
        setTextViewBalance();
        // set titles
        getSherlockActivity().getSupportActionBar().setSubtitle(mAccountName);

        break;
    }
}

From source file:com.samknows.measurement.storage.TestResultDataSource.java

public List<AggregateTestResult> getAverageResults(long starttime, long endtime) {
    List<AggregateTestResult> ret = new ArrayList<AggregateTestResult>();
    String selection = String.format("dtime BETWEEN %d AND %d AND success <> 0", starttime, endtime);
    String averageColumn = String.format("AVG(%s)", SKSQLiteHelper.TR_COLUMN_RESULT);

    String[] columns = { SKSQLiteHelper.TR_COLUMN_TYPE, averageColumn, "COUNT(*)" };
    String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE;
    Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null,
            null);/*from   w  w w  .  j a  va 2  s.  c  om*/
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        AggregateTestResult curr = new AggregateTestResult();
        curr.testType = cursor.getString(0);
        curr.aggregateFunction = "average";
        curr.value = cursor.getDouble(1);
        curr.numberOfResults = cursor.getInt(2);
        ret.add(curr);
    }
    cursor.close();
    return ret;
}

From source file:gov.wa.wsdot.android.wsdot.ui.HighImpactAlertsFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    alertItems.clear();//w  w w. j  av a  2 s .  c  o m

    if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
            HighwayAlertsItem item = new HighwayAlertsItem();
            item.setAlertId(cursor.getString(0));
            item.setStartLatitude(cursor.getDouble(1));
            item.setStartLongitude(cursor.getDouble(2));
            item.setEventCategory(cursor.getString(3));
            item.setExtendedDescription(cursor.getString(4));
            item.setLastUpdatedTime(cursor.getString(6));
            alertItems.add(item);

            cursor.moveToNext();
        }

    } else {
        HighwayAlertsItem item = new HighwayAlertsItem();
        item.setEventCategory("empty");
        alertItems.add(item);
    }

    mLoadingSpinner.setVisibility(View.GONE);
    mPager.setVisibility(View.VISIBLE);
    mIndicator.setVisibility(View.VISIBLE);
    mAdapter = new ViewPagerAdapter(getActivity(), alertItems);
    mPager.setAdapter(mAdapter);
    mIndicator.setViewPager(mPager);
}

From source file:org.wheelmap.android.model.POIsListCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    POIsListItemView pliv = (POIsListItemView) view;
    SupportManager manager = WheelmapApp.getSupportManager();
    if (manager == null) {
        Log.d(TAG, "SupportManager is null - how can that be?");
        return;/*from  w w w.  j a  va2s . c om*/
    }

    String name = POIHelper.getName(cursor);
    WheelchairState state = POIHelper.getWheelchair(cursor);
    int index = cursor.getColumnIndex(POIsCursorWrapper.LOCATION_COLUMN_NAME);
    double distance = cursor.getDouble(index);
    int categoryId = POIHelper.getCategoryId(cursor);
    int nodeTypeId = POIHelper.getNodeTypeId(cursor);
    NodeType nodeType = manager.lookupNodeType(nodeTypeId);

    if (name.length() > 0)
        pliv.setName(name);
    else {
        pliv.setName(nodeType.localizedName);
    }
    String category = manager.lookupCategory(categoryId).localizedName;
    pliv.setCategory(category);
    pliv.setNodeType(nodeType.localizedName);

    pliv.setDistance(mDistanceFormatter.format(distance));
    Drawable marker = manager.lookupWheelDrawable(state.getId());
    pliv.setIcon(marker);
}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * Reads the database for all chatrooms.
 * @return A list of all chatrooms./*from  w w w  . j a va 2s .  co  m*/
 */
public List<Chatroom> getAllChatrooms() {
    List<Chatroom> chatroomList = new ArrayList<Chatroom>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_CHATROOMS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            Chatroom chatroom = new Chatroom();
            chatroom.setName(cursor.getString(0));
            chatroom.setLatitude(cursor.getDouble(2));
            chatroom.setLongitude(cursor.getDouble(StringLiterals.THREE));
            chatroom.setRadius(cursor.getFloat(StringLiterals.FOUR));
            // Adding chatroom to list
            chatroomList.add(chatroom);
        } while (cursor.moveToNext());
    }

    // return contact list
    return chatroomList;
}

From source file:com.example.kylelehman.sunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);/*w w  w. j a v  a2 s. c om*/

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .putExtra(DetailActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE));
                startActivity(intent);
            }
        }
    });

    return rootView;
}

From source file:com.glandorf1.joe.wsprnetviewer.app.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read wspr SNR from cursor, display it and use it to select icon
        double rxSnr = data.getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_RX_SNR));
        mIconView.setImageResource(Utility.getIconResourceForWsprCondition((double) (rxSnr)));
        mRxSnrView.setText(Utility.formatSnr(getActivity(), rxSnr));
        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(Double.toString(rxSnr) + " dBm");

        // Read timestamp from cursor and update views for day of week and timestamp
        String timestamp = data//w  w  w .  j a va 2  s .c o m
                .getString(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT));
        String timeAgoText = Utility.getTimeAgo(getActivity(), timestamp);
        String timestampText = Utility.getFormattedTimestamp(timestamp, Utility.TIMESTAMP_FORMAT_HOURS_MINUTES);
        mTimeAgoView.setText(timeAgoText);
        mTimestampView.setText(timestampText);

        boolean isMetric = Utility.isMetric(getActivity());

        // Read TX power, RX drift from cursor and update view
        double txpower = data.getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_TX_POWER));
        String txpowerString = Utility.formatPower(getActivity(), txpower);
        mTxPowerView.setText(txpowerString);
        double rxDrift = data.getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_RX_DRIFT));
        String rxDriftString = Utility.formatRxDrift(getActivity(), rxDrift);
        mRxDriftView.setText(rxDriftString);

        // Read TX frequency from cursor and update view
        double txMhz = data
                .getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_TX_FREQ_MHZ));
        String txMhzString = Utility.formatFrequency(getActivity(), txMhz, true); // TODO: option to display wavelength
        mTxFreqMhzView.setText(txMhzString);

        // Read callsigns from cursor and update view
        // TODO: decide if callsigns need any special formatting
        String txCallsign = data
                .getString(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_TX_CALLSIGN))
                .replace(Utility.NBSP, ' ').trim();
        mTxCallsignView.setText(Utility.formatCallsign(getActivity(), txCallsign, true));
        String rxCallsign = data
                .getString(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_RX_CALLSIGN))
                .replace(Utility.NBSP, ' ').trim();
        mRxCallsignView.setText(Utility.formatCallsign(getActivity(), rxCallsign, false));

        // Read km distance and azimuth from cursor and update view.
        // If the 'units' preference changes, this auto-magically gets updated.
        double km = data.getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_DISTANCE));
        mDistanceView.setText(Utility.formatDistance(getActivity(), km, isMetric));
        if (!Utility.isMetric(getActivity())) {
            mDistanceLabelView.setText(getString(R.string._units_english_distance));
        }
        double degrees = data.getDouble(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_AZIMUTH));
        degrees = degrees < 0 ? 0 : degrees;
        mAzimuthView.setText(Utility.formatAzimuth(getActivity(), degrees));

        // Read gridsquares from cursor and update view
        mRxGridsquare = data
                .getString(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_RX_GRIDSQUARE));
        String gridsquare = Utility.formatGridsquare(getActivity(), mRxGridsquare, false);
        mRxGridsquareView.setText(gridsquare);
        mTxGridsquare = data
                .getString(data.getColumnIndex(WsprNetContract.SignalReportEntry.COLUMN_TX_GRIDSQUARE));
        gridsquare = Utility.formatGridsquare(getActivity(), mTxGridsquare, true);
        mTxGridsquareView.setText(gridsquare);
        // Update lat/long/azimuth for the map
        mDetailMap.setLatLongAzimuth(Utility.gridsquareToLatitude(mTxGridsquare),
                Utility.gridsquareToLongitude(mTxGridsquare), Utility.gridsquareToLatitude(mRxGridsquare),
                Utility.gridsquareToLongitude(mRxGridsquare), degrees);

        // These are for testing:
        //            mDetailMap.setLatLongAzimuth(
        //                    Utility.gridsquareToLatitude("AA"),
        //                    Utility.gridsquareToLongitude("AA"),
        //                    Utility.gridsquareToLatitude("KK"),
        //                    Utility.gridsquareToLongitude("KK"),
        //                    degrees);

        // These are for testing:
        //            Double lat, lon;
        //            lat = Utility.gridsquareToLatitude("AA00");
        //            lon = Utility.gridsquareToLongitude("AA00");
        //            Log.v(LOG_TAG, "lat/long(AA00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("GG");
        //            lon = Utility.gridsquareToLongitude("GG");
        //            Log.v(LOG_TAG, "lat/long(GG00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("II");
        //            lon = Utility.gridsquareToLongitude("II");
        //            Log.v(LOG_TAG, "lat/long(II00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("RR");
        //            lon = Utility.gridsquareToLongitude("RR");
        //            Log.v(LOG_TAG, "lat/long(RR00)= " + lat.toString() + ", " + lon.toString() );
        //
        //            lat = Utility.gridsquareToLatitude("DD");
        //            lon = Utility.gridsquareToLongitude("DD");
        //            Log.v(LOG_TAG, "lat/long(DD00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("OD");
        //            lon = Utility.gridsquareToLongitude("OD");
        //            Log.v(LOG_TAG, "lat/long(OD00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("OO");
        //            lon = Utility.gridsquareToLongitude("OO");
        //            Log.v(LOG_TAG, "lat/long(OO00)= " + lat.toString() + ", " + lon.toString() );
        //            lat = Utility.gridsquareToLatitude("DO");
        //            lon = Utility.gridsquareToLongitude("DO");
        //            Log.v(LOG_TAG, "lat/long(DO00)= " + lat.toString() + ", " + lon.toString() );

        // Set up a string for a "share intent":
        mWspr = String.format(
                "WSPR @%s UTC: %s MHz/%s dBm SNR\n" + " tx/rx grid: %s/%s\n" + " tx/rx call: %s/%s",
                timestampText, txMhzString, rxSnr, mTxGridsquare, mRxGridsquare, txCallsign, rxCallsign);

        // If onCreateOptionsMenu has already happened, update the share intent.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareWsprIntent());
        }
    }
}

From source file:alberthsu.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);//from   w  ww.  j a  v  a2  s. c  om

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {

                Intent intent = new Intent(getActivity(), detailedActivity.class)
                        .putExtra(detailedActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE));
                startActivity(intent);
            }
        }
    });

    return rootView;
}