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: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  .  j av  a  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:org.openbmap.activities.CellDetailsMap.java

@Override
public final void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
    if (cursor != null && cursor.getCount() > 0) {

        final int colLat = cursor.getColumnIndex("begin_" + Schema.COL_LATITUDE);
        final int colLon = cursor.getColumnIndex("begin_" + Schema.COL_LONGITUDE);
        final int colLevel = cursor.getColumnIndex(Schema.COL_STRENGTHDBM);

        while (cursor.moveToNext()) {
            //int intensity = (int) (HEAT_AMPLIFIER * (Math.min(cursor.getInt(colLevel) + MIN_HEAT, 0)) / -10f);
            final int intensity = cursor.getInt(colLevel) / -1;
            points.add(new HeatLatLong(cursor.getDouble(colLat), cursor.getDouble(colLon), intensity));
        }//from w ww . j  a  va2 s.  c om

        if (points.size() > 0) {
            mMapView.getModel().mapViewPosition.setCenter(points.get(points.size() - 1));
        }
        mPointsLoaded = true;
        proceedAfterHeatmapCompleted();

        // update host activity
        ((CellDetailsActivity) getActivity()).setNoMeasurements(cursor.getCount());
    }
}

From source file:org.xbmc.kore.ui.TVShowOverviewFragment.java

/**
 * Display the tv show details//from   www . j  a  v  a2s  . com
 *
 * @param cursor Cursor with the data
 */
private void displayTVShowDetails(Cursor cursor) {
    LogUtils.LOGD(TAG, "displayTVShowDetails");
    cursor.moveToFirst();
    tvshowTitle = cursor.getString(TVShowDetailsQuery.TITLE);
    mediaTitle.setText(tvshowTitle);
    int numEpisodes = cursor.getInt(TVShowDetailsQuery.EPISODE),
            watchedEpisodes = cursor.getInt(TVShowDetailsQuery.WATCHEDEPISODES);
    setMediaUndertitle(numEpisodes, watchedEpisodes);

    setMediaPremiered(cursor.getString(TVShowDetailsQuery.PREMIERED),
            cursor.getString(TVShowDetailsQuery.STUDIO));

    mediaGenres.setText(cursor.getString(TVShowDetailsQuery.GENRES));

    setMediaRating(cursor.getDouble(TVShowDetailsQuery.RATING));

    mediaDescription.setText(cursor.getString(TVShowDetailsQuery.PLOT));

    //        // IMDB button
    //        imdbButton.setTag(cursor.getString(TVShowDetailsQuery.IMDBNUMBER));

    // Images
    Resources resources = getActivity().getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
    UIUtils.loadImageWithCharacterAvatar(getActivity(), getHostManager(),
            cursor.getString(TVShowDetailsQuery.THUMBNAIL), tvshowTitle, mediaPoster, posterWidth,
            posterHeight);
    int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
    UIUtils.loadImageIntoImageview(getHostManager(), cursor.getString(TVShowDetailsQuery.FANART), mediaArt,
            displayMetrics.widthPixels, artHeight);
}

From source file:com.urs.triptracks.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  om*/
    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));
    String travelBy = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_TRAVELED));
    Integer members = tripCursor.getInt(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_MEMBERS));
    Integer nonmembers = tripCursor.getInt(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_NONMEMBERS));
    Integer delays = tripCursor.getInt(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_DELAYS));
    Integer toll = tripCursor.getInt(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_PAYTOLL));
    Double tollAmt = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_PAYTOLLAMT));
    Integer payForParking = tripCursor.getInt(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_PAYPARKING));
    Double payForParkingAmt = tripCursor
            .getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_PAYPARKINGAMT));
    Double fare = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_EVERYSTOP_FARE));

    tripCursor.close();
    mDb.close();

    //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//To get local formatting use getDateInstance(), getDateTimeInstance(), or getTimeInstance(), or use new SimpleDateFormat(String template, Locale locale) with for example
    //SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale locale);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    //tripData.add(note);
    tripData.add(purpose);
    tripData.add(df.format(startTime));
    tripData.add(df.format(endTime));

    tripData.add(travelBy);
    tripData.add(members.toString());
    tripData.add(nonmembers.toString());
    tripData.add(delays.toString());
    tripData.add(toll.toString());
    tripData.add(tollAmt.toString());
    tripData.add(payForParking.toString());
    tripData.add(payForParkingAmt.toString());
    tripData.add(fare.toString());

    return tripData;
}

From source file:com.bangz.smartmute.services.LocationMuteService.java

private List<Geofence> fillGeofences(Cursor cursor) {

    List<Geofence> geofences = new ArrayList<Geofence>();
    long id;//from   w  w w  .  j a  va 2 s  .com
    double latitude, longitude;
    float radius;

    int idxLatitude = cursor.getColumnIndex(RulesColumns.LATITUDE);
    int idxLongitude = cursor.getColumnIndex(RulesColumns.LONGITUDE);
    int idxRadius = cursor.getColumnIndex(RulesColumns.RADIUS);
    int idxId = cursor.getColumnIndex(RulesColumns._ID);

    while (cursor.moveToNext()) {

        id = cursor.getLong(idxId);
        latitude = cursor.getDouble(idxLatitude);
        longitude = cursor.getDouble(idxLongitude);
        radius = cursor.getFloat(idxRadius);
        String strcondition = cursor.getString(cursor.getColumnIndex(RulesColumns.CONDITION));
        LocationCondition condition = new LocationCondition(strcondition);

        Geofence.Builder gb = new Geofence.Builder().setRequestId(String.valueOf(id))
                .setTransitionTypes(
                        condition.getTriggerCondition().getTransitionType() | Geofence.GEOFENCE_TRANSITION_EXIT)
                .setCircularRegion(latitude, longitude, radius).setExpirationDuration(Geofence.NEVER_EXPIRE);
        if (condition.getTriggerCondition().getTransitionType() == Geofence.GEOFENCE_TRANSITION_DWELL)
            gb.setLoiteringDelay(condition.getTriggerCondition().getLoiteringDelay());

        gb.setNotificationResponsiveness(condition.getTriggerCondition().getNotificationDelay());

        Geofence geofence = gb.build();

        geofences.add(geofence);
    }

    return geofences;
}

From source file:com.mk4droid.IMC_Services.DatabaseHandler.java

/**
 * Getting all issues./*from w  w w . j  a  va 2 s. c  o m*/
 * 
 * @return
 */
public ArrayList<Issue> getAllIssues() {
    ArrayList<Issue> mIssueL = new ArrayList<Issue>();
    // Select All Query
    String selectQuery = "SELECT * FROM " + TABLE_Issues + " ORDER BY " + KEY_IssueID + " DESC";

    if (!db.isOpen())
        db = this.getWritableDatabase();

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

    if (cursor.moveToFirst()) {
        do {
            Issue mIssue = new Issue(cursor.getInt(0), cursor.getString(1), cursor.getInt(2),
                    cursor.getDouble(3), cursor.getDouble(4), cursor.getString(5), cursor.getString(6),
                    cursor.getString(7), cursor.getInt(8), cursor.getInt(9), cursor.getString(10),
                    cursor.getString(11), cursor.getString(12), cursor.getInt(13), cursor.getInt(14),
                    cursor.getString(15), cursor.getInt(16), cursor.getString(17), cursor.getInt(18),
                    cursor.getString(19));

            mIssueL.add(mIssue);
        } while (cursor.moveToNext());
    }

    cursor.close();
    return mIssueL;
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case ID_LOADER_SUMMARY:
        if (data != null && data.moveToFirst()) {
            String balance = Double.toString(data.getDouble(data.getColumnIndex(QueryAccountBills.TOTAL)));
            mAccountBalance = MoneyFactory.fromString(balance);
            String reconciled = Double
                    .toString(data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILED)));
            mAccountReconciled = MoneyFactory.fromString(reconciled);
        } else {//w  w w  . j  ava2  s  . c  om
            mAccountBalance = MoneyFactory.fromString("0");
            mAccountReconciled = MoneyFactory.fromString("0");
        }
        // show balance values
        setTextViewBalance();
        break;

    case AllDataListFragment.ID_LOADER_ALL_DATA_DETAIL:
        // Notification received from AllDataListFragment.
        // Once the transactions are loaded, load the summary data.
        getLoaderManager().restartLoader(ID_LOADER_SUMMARY, null, this);
        // load/reset running balance
        populateRunningBalance();

        break;
    }
}

From source file:com.wildplot.android.ankistats.WeeklyBreakdown.java

public boolean calculateBreakdown(int type) {
    mTitle = R.string.stats_weekly_breakdown;
    mAxisTitles = new int[] { R.string.stats_day_of_week, R.string.stats_percentage_correct,
            R.string.stats_reviews };/*  w ww  .  j av a2  s .c  o  m*/

    mValueLabels = new int[] { R.string.stats_percentage_correct, R.string.stats_answers };
    mColors = new int[] { R.color.stats_counts, R.color.stats_hours };

    mType = type;
    String lim = _revlogLimitWholeOnly().replaceAll("[\\[\\]]", "");

    if (lim.length() > 0) {
        lim = " and " + lim;
    }

    Calendar sd = GregorianCalendar.getInstance();
    sd.setTimeInMillis(mCollectionData.getDayCutoff() * 1000);

    int pd = _periodDays();
    if (pd > 0) {
        lim += " and id > " + ((mCollectionData.getDayCutoff() - (86400 * pd)) * 1000);
    }

    long cutoff = mCollectionData.getDayCutoff();
    long cut = cutoff - sd.get(Calendar.HOUR_OF_DAY) * 3600;

    ArrayList<double[]> list = new ArrayList<double[]>();
    Cursor cur = null;
    String query = "SELECT strftime('%w',datetime( cast(id/ 1000  -" + sd.get(Calendar.HOUR_OF_DAY) * 3600
            + " as int), 'unixepoch')) as wd, " + "sum(case when ease = 1 then 0 else 1 end) / "
            + "cast(count() as float) * 100, " + "count() " + "from revlog " + "where type in (0,1,2) " + lim
            + " " + "group by wd " + "order by wd";
    Log.d(AnkiStatsApplication.TAG,
            sd.get(Calendar.HOUR_OF_DAY) + " : " + cutoff + " weekly breakdown query: " + query);
    try {
        cur = mAnkiDb.getDatabase().rawQuery(query, null);
        while (cur.moveToNext()) {
            list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2) });
        }

    } finally {
        if (cur != null && !cur.isClosed()) {
            cur.close();
        }
    }

    //TODO adjust for breakdown, for now only copied from intervals
    // small adjustment for a proper chartbuilding with achartengine
    //        if (list.size() == 0 || list.get(0)[0] > 0) {
    //            list.add(0, new double[] { 0, 0, 0 });
    //        }
    //        if (num == -1 && list.size() < 2) {
    //            num = 31;
    //        }
    //        if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) {
    //            list.add(new double[] { num, 0, 0 });
    //        } else if (type == Utils.TYPE_LIFE && list.size() < 2) {
    //            list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0, 0 });
    //        }

    mSeriesList = new double[4][list.size()];
    mPeak = 0.0;
    mMcount = 0.0;
    double minHour = Double.MAX_VALUE;
    double maxHour = 0;
    for (int i = 0; i < list.size(); i++) {
        double[] data = list.get(i);
        int hour = (int) data[0];

        //double hour = data[0];
        if (hour < minHour)
            minHour = hour;

        if (hour > maxHour)
            maxHour = hour;

        double pct = data[1];
        if (pct > mPeak)
            mPeak = pct;

        mSeriesList[0][i] = hour;
        mSeriesList[1][i] = pct;
        mSeriesList[2][i] = data[2];
        if (i == 0) {
            mSeriesList[3][i] = pct;
        } else {
            double prev = mSeriesList[3][i - 1];
            double diff = pct - prev;
            diff /= 3.0;
            diff = Math.round(diff * 10.0) / 10.0;

            mSeriesList[3][i] = prev + diff;
        }

        if (data[2] > mMcount)
            mMcount = data[2];
        if (mSeriesList[1][i] > mMaxCards)
            mMaxCards = (int) mSeriesList[1][i];
    }

    mMaxElements = (int) (maxHour - minHour);
    return list.size() > 0;
}

From source file:com.money.manager.ex.notifications.RepeatingTransactionNotifications.java

public void notifyRepeatingTransaction() {
    // create application
    CurrencyUtils currencyUtils = new CurrencyUtils(context);
    // init currencies
    if (!currencyUtils.isInit())
        currencyUtils.init();/* www .  j  av a 2  s.com*/

    // select data
    QueryBillDeposits billDeposits = new QueryBillDeposits(context);
    MoneyManagerOpenHelper databaseHelper = new MoneyManagerOpenHelper(context);

    if (databaseHelper != null) {
        Cursor cursor = databaseHelper.getReadableDatabase().rawQuery(billDeposits.getSource() + " AND "
                + QueryBillDeposits.DAYSLEFT + "<=0 ORDER BY " + QueryBillDeposits.NEXTOCCURRENCEDATE, null);
        if (cursor != null) {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                while (!cursor.isAfterLast()) {
                    String line = cursor
                            .getString(cursor.getColumnIndex(QueryBillDeposits.USERNEXTOCCURRENCEDATE)) + " "
                            + cursor.getString(cursor.getColumnIndex(QueryBillDeposits.PAYEENAME)) + ": <b>"
                            + currencyUtils.getCurrencyFormatted(
                                    cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.CURRENCYID)),
                                    cursor.getDouble(cursor.getColumnIndex(QueryBillDeposits.AMOUNT)))
                            + "</b>";
                    // add line
                    inboxStyle.addLine(Html.fromHtml("<small>" + line + "</small>"));
                    // move to next row
                    cursor.moveToNext();
                }

                NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                // create pendig intent
                Intent intent = new Intent(context, RepeatingTransactionListActivity.class);
                // set launch from notification // check pin code
                intent.putExtra(RepeatingTransactionListActivity.INTENT_EXTRA_LAUNCH_NOTIFICATION, true);

                PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
                // create notification
                Notification notification = null;
                try {
                    notification = new NotificationCompat.Builder(context).setAutoCancel(true)
                            .setContentIntent(pendingIntent)
                            .setContentTitle(context.getString(R.string.application_name))
                            .setContentText(
                                    context.getString(R.string.notification_repeating_transaction_expired))
                            .setSubText(context
                                    .getString(R.string.notification_click_to_check_repeating_transaction))
                            .setSmallIcon(R.drawable.ic_stat_notification)
                            .setTicker(context.getString(R.string.notification_repeating_transaction_expired))
                            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND
                                    | Notification.DEFAULT_LIGHTS)
                            .setNumber(cursor.getCount()).setStyle(inboxStyle).build();
                    // notify 
                    notificationManager.cancel(ID_NOTIFICATION);
                    notificationManager.notify(ID_NOTIFICATION, notification);
                } catch (Exception e) {
                    Log.e(LOGCAT, e.getMessage());
                }
            }
            // close cursor
            cursor.close();
        }
        // close database helper
        //databaseHelper.close();
    }
}

From source file:com.money.manager.ex.notifications.RecurringTransactionNotifications.java

private void showNotification(Cursor cursor) {
    CurrencyService currencyService = new CurrencyService(mContext);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    while (cursor.moveToNext()) {
        String payeeName = cursor.getString(cursor.getColumnIndex(QueryBillDeposits.PAYEENAME));
        // check if payee name is null, then put toAccountName
        if (TextUtils.isEmpty(payeeName))
            payeeName = cursor.getString(cursor.getColumnIndex(QueryBillDeposits.TOACCOUNTNAME));
        // compose text
        String line = cursor.getString(cursor.getColumnIndex(QueryBillDeposits.USERNEXTOCCURRENCEDATE)) + " "
                + payeeName + ": <b>"
                + currencyService.getCurrencyFormatted(
                        cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.CURRENCYID)),
                        MoneyFactory/*from  ww w.  j  a v a 2s.  c  o m*/
                                .fromDouble(cursor.getDouble(cursor.getColumnIndex(QueryBillDeposits.AMOUNT))))
                + "</b>";
        // add line
        inboxStyle.addLine(Html.fromHtml("<small>" + line + "</small>"));
    }

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // create pending intent
    Intent intent = new Intent(getContext(), RecurringTransactionListActivity.class);
    // set launch from notification // check pin code
    intent.putExtra(RecurringTransactionListActivity.INTENT_EXTRA_LAUNCH_NOTIFICATION, true);

    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, 0);

    // todo: Actions
    //        Intent skipIntent = new Intent(intent);
    //        //skipIntent.setAction(Intent.)
    //        PendingIntent skipPending = PendingIntent.getActivity(getContext(), 0, skipIntent, 0);
    //        Intent enterIntent = new Intent(getContext(), RecurringTransactionEditActivity.class);
    //        PendingIntent enterPending = PendingIntent.getActivity(getContext(), 0, enterIntent, 0);

    // create notification
    try {
        Notification notification = new NotificationCompat.Builder(getContext()).setAutoCancel(true)
                .setContentIntent(pendingIntent).setContentTitle(mContext.getString(R.string.application_name))
                .setContentText(mContext.getString(R.string.notification_repeating_transaction_expired))
                .setSubText(mContext.getString(R.string.notification_click_to_check_repeating_transaction))
                .setSmallIcon(R.drawable.ic_stat_notification)
                .setTicker(mContext.getString(R.string.notification_repeating_transaction_expired))
                .setDefaults(
                        Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
                .setNumber(cursor.getCount()).setStyle(inboxStyle)
                .setColor(mContext.getResources().getColor(R.color.md_primary))
                //                    .addAction(R.drawable.ic_action_content_clear_dark, getContext().getString(R.string.skip), skipPending)
                //                    .addAction(R.drawable.ic_action_done_dark, getContext().getString(R.string.enter), enterPending)
                .build();
        // notify
        notificationManager.cancel(ID_NOTIFICATION);
        notificationManager.notify(ID_NOTIFICATION, notification);
    } catch (Exception e) {
        Timber.e(e, "showing notification for recurring transaction");
    }
}