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:org.droidparts.persist.sql.EntityManager.java

protected Object readFromCursor(Cursor cursor, int columnIndex, Class<?> valType, Class<?> arrCollItemType)
        throws IllegalArgumentException {
    if (cursor.isNull(columnIndex)) {
        return null;
    } else if (isBoolean(valType)) {
        return cursor.getInt(columnIndex) == 1;
    } else if (isByte(valType)) {
        return Byte.valueOf(cursor.getString(columnIndex));
    } else if (isByteArray(valType)) {
        return cursor.getBlob(columnIndex);
    } else if (isDouble(valType)) {
        return cursor.getDouble(columnIndex);
    } else if (isFloat(valType)) {
        return cursor.getFloat(columnIndex);
    } else if (isInteger(valType)) {
        return cursor.getInt(columnIndex);
    } else if (isLong(valType)) {
        return cursor.getLong(columnIndex);
    } else if (isShort(valType)) {
        return cursor.getShort(columnIndex);
    } else if (isString(valType)) {
        return cursor.getString(columnIndex);
    } else if (isUUID(valType)) {
        return UUID.fromString(cursor.getString(columnIndex));
    } else if (isDate(valType)) {
        return new Date(cursor.getLong(columnIndex));
    } else if (isBitmap(valType)) {
        byte[] arr = cursor.getBlob(columnIndex);
        return BitmapFactory.decodeByteArray(arr, 0, arr.length);
    } else if (isJsonObject(valType) || isJsonArray(valType)) {
        String str = cursor.getString(columnIndex);
        try {//from w  w w.j a  v  a  2  s .  c o  m
            return isJsonObject(valType) ? new JSONObject(str) : new JSONArray(str);
        } catch (JSONException e) {
            throw new IllegalArgumentException(e);
        }
    } else if (isEnum(valType)) {
        return instantiateEnum(valType, cursor.getString(columnIndex));
    } else if (isEntity(valType)) {
        long id = cursor.getLong(columnIndex);
        @SuppressWarnings("unchecked")
        Entity entity = instantiate((Class<Entity>) valType);
        entity.id = id;
        return entity;
    } else if (isArray(valType) || isCollection(valType)) {
        String str = cursor.getString(columnIndex);
        String[] parts = (str.length() > 0) ? str.split("\\" + SEP) : new String[0];
        if (isArray(valType)) {
            return toTypeArr(arrCollItemType, parts);
        } else {
            @SuppressWarnings("unchecked")
            Collection<Object> coll = (Collection<Object>) instantiate(valType);
            coll.addAll(toTypeColl(arrCollItemType, parts));
            return coll;
        }
    } else {
        throw new IllegalArgumentException("Need to manually read " + valType.getName() + " from cursor.");
    }
}

From source file:com.bangz.smartmute.LocationsMapFragment.java

private String makeTriggerInfoString(Cursor cursor) {
    String strcondition = cursor.getString(cursor.getColumnIndex(RulesColumns.CONDITION));
    LocationCondition condition = new LocationCondition(strcondition);

    float radius = cursor.getFloat(cursor.getColumnIndex(RulesColumns.RADIUS));
    LocationCondition.TriggerCondition tc = condition.getTriggerCondition();
    Resources res = getResources();

    if (tc.getTransitionType() == Geofence.GEOFENCE_TRANSITION_ENTER) {
        return String.format(res.getString(R.string.info_trigger_by_enter), (int) radius);
    } else {/* w w w  . j a va2s  .  c o  m*/
        return String.format(res.getString(R.string.info_trigger_by_dwell), (int) radius,
                tc.getLoiteringDelay() / Constants.ONE_MINUTE_IN_MS);
    }

}

From source file:org.chromium.chrome.browser.util.ChromeFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Uri fileUri = getFileUriWhenReady(uri);
    if (fileUri == null)
        return null;

    // Workaround for a bad assumption that particular MediaStore columns exist by certain third
    // party applications.
    // http://crbug.com/467423.
    Cursor source = super.query(fileUri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames)
        return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);/* w  w w.j  a va  2  s. c o m*/
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
            case Cursor.FIELD_TYPE_INTEGER:
                row.add(source.getInt(i));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                row.add(source.getFloat(i));
                break;
            case Cursor.FIELD_TYPE_STRING:
                row.add(source.getString(i));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                row.add(source.getBlob(i));
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                row.add(null);
                break;
            }
        }
    }

    source.close();
    return cursor;
}

From source file:com.meiste.tempalarm.ui.CurrentTemp.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.current_temp);
    ButterKnife.inject(this);

    mAdapter = new SimpleCursorAdapter(this, R.layout.record, null, FROM_COLUMNS, TO_FIELDS, 0);
    mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override/*  w ww  . ja  v  a  2  s . c  o m*/
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
            final TextView textView = (TextView) view;
            switch (columnIndex) {
            case COLUMN_TIMESTAMP:
                // Convert timestamp to human-readable date
                textView.setText(DateUtils.formatDateTime(getApplicationContext(), cursor.getLong(columnIndex),
                        AppConstants.DATE_FORMAT_FLAGS));
                return true;
            case COLUMN_DEGF:
                // Restrict to one decimal place
                textView.setText(String.format("%.1f", cursor.getFloat(columnIndex)));
                return true;
            case COLUMN_LIGHT:
                if (cursor.getInt(columnIndex) < mLightThreshold) {
                    textView.setText(getText(R.string.lights_on));
                } else {
                    textView.setText(getText(R.string.lights_off));
                }
                return true;
            }
            return false;
        }
    });

    final View header = getLayoutInflater().inflate(R.layout.record_header, mListView, false);
    final FrameLayout frameLayout = ButterKnife.findById(header, R.id.graph_placeholder);
    mGraph = new LineGraphView(this, "");
    mGraph.setDrawBackground(true);
    mGraph.setBackgroundColor(getResources().getColor(R.color.primary_graph));
    mGraph.setCustomLabelFormatter(new CustomLabelFormatter() {
        @Override
        public String formatLabel(final double value, final boolean isValueX) {
            if (isValueX) {
                return DateUtils.formatDateTime(getApplicationContext(), (long) value,
                        AppConstants.DATE_FORMAT_FLAGS_GRAPH);
            }
            return String.format(Locale.getDefault(), "%.1f", value);
        }
    });
    mGraph.getGraphViewStyle().setNumHorizontalLabels(AppConstants.GRAPH_NUM_HORIZONTAL_LABELS);
    frameLayout.addView(mGraph);

    mListView.addHeaderView(header, null, false);
    mListView.setAdapter(mAdapter);
    getLoaderManager().initLoader(0, null, this);
}

From source file:edu.mit.mobile.android.livingpostcards.CardDetailsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
    switch (loader.getId()) {
    case LOADER_CARD:
        if (c.moveToFirst()) {
            if (BuildConfig.DEBUG) {
                ProviderUtils.dumpCursorToLog(c, CARD_PROJECTION);
            }//ww  w  . j ava 2  s  .  c o m
            final View v = getView();
            final String description = c.getString(c.getColumnIndexOrThrow(Card.COL_DESCRIPTION));
            final TextView descriptionTv = ((TextView) v.findViewById(R.id.description));
            if (description != null && description.length() > 0) {
                descriptionTv.setVisibility(View.VISIBLE);
                descriptionTv.setText(description);
            } else {
                descriptionTv.setVisibility(View.GONE);
            }

            mStaticMap.setMap(c.getFloat(c.getColumnIndexOrThrow(Card.COL_LATITUDE)),
                    c.getFloat(c.getColumnIndexOrThrow(Card.COL_LONGITUDE)), false);

            mTiming = c.getInt(c.getColumnIndexOrThrow(Card.COL_TIMING));
            final String pubMediaUri = c.getString(c.getColumnIndexOrThrow(Card.COL_MEDIA_URL));
            if (pubMediaUri != null) {
                LocastSyncService.startSync(getActivity(),
                        ((LocastApplication) getActivity().getApplication())
                                .getNetworkClient(getActivity(), Authenticator.getFirstAccount(getActivity()))
                                .getFullUrl(pubMediaUri),
                        mCardMedia, false);
            }
        }
        break;
    }
}

From source file:net.simonvt.cathode.ui.adapter.BaseMoviesAdapter.java

@Override
protected void onBindViewHolder(T holder, Cursor cursor, int position) {
    final String title = cursor.getString(cursor.getColumnIndex(MovieColumns.TITLE));
    final boolean watched = cursor.getInt(cursor.getColumnIndex(MovieColumns.WATCHED)) == 1;
    final boolean collected = cursor.getInt(cursor.getColumnIndex(MovieColumns.IN_COLLECTION)) == 1;
    final boolean inWatchlist = cursor.getInt(cursor.getColumnIndex(MovieColumns.IN_WATCHLIST)) == 1;
    final boolean watching = cursor.getInt(cursor.getColumnIndex(MovieColumns.WATCHING)) == 1;
    final boolean checkedIn = cursor.getInt(cursor.getColumnIndex(MovieColumns.CHECKED_IN)) == 1;

    holder.poster.setImage(cursor.getString(cursor.getColumnIndex(MovieColumns.POSTER)));
    holder.title.setText(title);// w w  w  .j  a va 2 s  . co m
    holder.overview.setText(cursor.getString(cursor.getColumnIndex(MovieColumns.OVERVIEW)));

    if (holder.rating != null) {
        final float rating = cursor.getFloat(cursor.getColumnIndex(MovieColumns.RATING));
        holder.rating.setValue(rating);
    }

    holder.overflow.removeItems();
    setupOverflowItems(holder.overflow, watched, collected, inWatchlist, watching, checkedIn);
}

From source file:com.rjfun.cordova.sms.SMSPlugin.java

private JSONObject getJsonFromCursor(Cursor cur) {
    JSONObject json = new JSONObject();

    int nCol = cur.getColumnCount();
    String keys[] = cur.getColumnNames();

    try {//  w  w  w  .  j  a  va2  s. c  o m
        for (int j = 0; j < nCol; j++) {
            switch (cur.getType(j)) {
            case Cursor.FIELD_TYPE_NULL:
                json.put(keys[j], null);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                json.put(keys[j], cur.getLong(j));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                json.put(keys[j], cur.getFloat(j));
                break;
            case Cursor.FIELD_TYPE_STRING:
                json.put(keys[j], cur.getString(j));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                json.put(keys[j], cur.getBlob(j));
                break;
            }
        }
    } catch (Exception e) {
        return null;
    }

    return json;
}

From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java

/**
 * Processes new data, adds notifications if any
 *
 * @param tickersList JSONObject with new tickers data
 * @param oldData     JSONObject with old tickers data
 * @return String with all notifications
 *///  ww w  . j a va2  s .  c  o  m
private String checkNotifiers(ArrayList<Ticker> tickersList, Map<String, Ticker> oldData) {

    DBWorker dbWorker = DBWorker.getInstance(this);
    Cursor cursor = dbWorker.getNotifiers();

    StringBuilder stringBuilder = new StringBuilder();
    for (Ticker ticker : tickersList) {
        cursor.moveToFirst();
        String pair = ticker.getPair();
        if (oldData.size() != 0 && oldData.containsKey(pair)) {
            double oldValue = oldData.get(pair).getLast();
            double newValue = ticker.getLast();
            while (!cursor.isAfterLast()) {
                boolean pairMatched = pair.replace("_", "/").toUpperCase(Locale.US)
                        .equals(cursor.getString(cursor.getColumnIndex("Pair")));
                if (pairMatched) {
                    float percent;
                    switch (cursor.getInt(cursor.getColumnIndex("Type"))) {
                    case PANIC_BUY_TYPE:
                        percent = cursor.getFloat(cursor.getColumnIndex("Value")) / 100;
                        if (newValue > ((1 + percent) * oldValue)) {
                            stringBuilder.append("Panic Buy for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case PANIC_SELL_TYPE:
                        percent = cursor.getFloat(cursor.getColumnIndex("Value")) / 100;
                        if (newValue < ((1 - percent) * oldValue)) {
                            stringBuilder.append("Panic Sell for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case STOP_LOSS_TYPE:
                        if (newValue < cursor.getFloat(cursor.getColumnIndex("Value"))) {
                            stringBuilder.append("Stop Loss for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case TAKE_PROFIT_TYPE:
                        if (newValue > cursor.getFloat(cursor.getColumnIndex("Value"))) {
                            stringBuilder.append("Take Profit for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    default:
                        break;
                    }
                }
                cursor.moveToNext();
            }
        }
    }
    cursor.close();
    return stringBuilder.toString();
}

From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final Context context = getContext();

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    final Cursor cursor = (Cursor) mAdapter.getItem(info.position);

    switch (item.getItemId()) {
    case R.id.menu_share:
        if (context != null && cursor != null) {
            final String title = cursor.getString(cursor.getColumnIndex(Tables.Entries.TITLE));
            final float rating = cursor.getFloat(cursor.getColumnIndex(Tables.Entries.RATING));
            EntryUtils.share(context, title, rating);
        }/*  w  ww  .  j  a va2 s. com*/
        return true;
    case R.id.menu_edit_entry:
        if (context != null && cursor != null) {
            EditEntryActivity.startActivity(context, info.id,
                    cursor.getString(cursor.getColumnIndex(Tables.Entries.CAT)));
        }
        return true;
    case R.id.menu_delete_entry:
        if (cursor != null) {
            final FragmentManager fm = getFragmentManager();
            if (fm != null) {
                final String title = cursor.getString(cursor.getColumnIndex(Tables.Entries.TITLE));
                final Intent deleteIntent = new Intent();
                deleteIntent.putExtra(EXTRA_ENTRY_ID, info.id);
                ConfirmationDialog.showDialog(fm, this, REQUEST_DELETE_ENTRY,
                        getString(R.string.title_delete_entry),
                        getString(R.string.message_confirm_delete, title), R.drawable.ic_delete, deleteIntent);
            }
        }
        return true;
    }
    return super.onContextItemSelected(item);
}

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

private List<Geofence> fillGeofences(Cursor cursor) {

    List<Geofence> geofences = new ArrayList<Geofence>();
    long id;/*  w w w  .  j  a v a 2 s . c om*/
    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;
}