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:ru.gkpromtech.exhibition.db.Table.java

private void fillFieldValue(int type, Field field, Object entity, Cursor cursor, int i)
        throws IllegalAccessException {
    if (cursor.isNull(i)) {
        field.set(entity, null);//from  w  ww.  j a va 2s. c o m
        return;
    }
    switch (type) {
    case INTEGER:
        field.set(entity, cursor.getInt(i));
        break;
    case SHORT:
        field.set(entity, cursor.getShort(i));
        break;
    case LONG:
        field.set(entity, cursor.getLong(i));
        break;
    case FLOAT:
        field.set(entity, cursor.getFloat(i));
        break;
    case DOUBLE:
        field.set(entity, cursor.getDouble(i));
        break;
    case STRING:
        field.set(entity, cursor.getString(i));
        break;
    case BYTE_ARRAY:
        field.set(entity, cursor.getBlob(i));
        break;
    case DATE:
        field.set(entity, new Date(cursor.getLong(i)));
        break;
    case BOOLEAN:
        field.set(entity, cursor.getInt(i) != 0);
        break;
    }
}

From source file:at.tm.android.fitacity.MainActivity.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    List<Exercise> exercises = new ArrayList<>();

    // To start from the beginning every time
    cursor.moveToFirst();/*  w  ww. ja  v a2s  .  co  m*/
    cursor.moveToPrevious();

    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_ID));
        String name = cursor.getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_NAME));
        String description = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_DESCRIPTION));
        int category = cursor.getInt(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_CATEGORY));
        String equipment = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_EQUIPMENT));
        float difficulty = cursor
                .getFloat(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_DIFFICULTY));
        String videoUrl = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_VIDEO_URL));
        String imgUrl = cursor.getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_IMG_URL));

        // Get all exercises from the cursor and put them to the exercise list
        exercises.add(new Exercise(id, name, description, category, equipment, difficulty, videoUrl, imgUrl));
    }

    if (exercises.size() > 0) {
        mEmptyRecyclerView.setVisibility(View.INVISIBLE);
    } else {
        mEmptyRecyclerView.setVisibility(View.VISIBLE);
    }

    mExerciseRecyclerViewAdapter.updateExerciseData(exercises);
}

From source file:net.simonvt.cathode.ui.fragment.MovieFragment.java

private void updateView(final Cursor cursor) {
    if (cursor == null || !cursor.moveToFirst())
        return;/* w  w w  . j a  v  a2  s. com*/
    loaded = true;

    final String title = cursor.getString(cursor.getColumnIndex(MovieColumns.TITLE));
    if (!title.equals(movieTitle)) {
        movieTitle = title;
        setTitle(movieTitle);
    }
    final int year = cursor.getInt(cursor.getColumnIndex(MovieColumns.YEAR));
    final String certification = cursor.getString(cursor.getColumnIndex(MovieColumns.CERTIFICATION));

    final String fanartUrl = cursor.getString(cursor.getColumnIndex(MovieColumns.FANART));
    fanart.setImage(fanartUrl);
    final String posterUrl = cursor.getString(cursor.getColumnIndex(MovieColumns.POSTER));
    poster.setImage(posterUrl);

    currentRating = cursor.getInt(cursor.getColumnIndex(MovieColumns.USER_RATING));
    final float ratingAll = cursor.getFloat(cursor.getColumnIndex(MovieColumns.RATING));
    rating.setValue(ratingAll);

    final String overview = cursor.getString(cursor.getColumnIndex(MovieColumns.OVERVIEW));
    watched = cursor.getInt(cursor.getColumnIndex(MovieColumns.WATCHED)) == 1;
    collected = cursor.getInt(cursor.getColumnIndex(MovieColumns.IN_COLLECTION)) == 1;
    inWatchlist = cursor.getInt(cursor.getColumnIndex(MovieColumns.IN_WATCHLIST)) == 1;
    watching = cursor.getInt(cursor.getColumnIndex(MovieColumns.WATCHING)) == 1;
    checkedIn = cursor.getInt(cursor.getColumnIndex(MovieColumns.CHECKED_IN)) == 1;

    isWatched.setVisibility(watched ? View.VISIBLE : View.GONE);
    collection.setVisibility(collected ? View.VISIBLE : View.GONE);
    watchlist.setVisibility(inWatchlist ? View.VISIBLE : View.GONE);

    this.year.setText(String.valueOf(year));
    this.certification.setText(certification);
    this.overview.setText(overview);

    setContentVisible(true);
    invalidateMenu();
}

From source file:com.bydavy.card.receipts.fragments.ReceiptFragment.java

private void updateView(Cursor c) {
    final boolean hasReceipt = ((c != null) && c.moveToFirst());

    // Update receipt container only if has a receipt to display
    // Otherwise this view is GONE
    if (hasReceipt) {
        final int shopColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_SHOP);
        final int noteColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_NOTE);
        final int totalColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_TOTAL);
        final int dateColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_DATE);
        final int verifiedColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_VERIFIED);
        final int picturePathColumnIndex = c.getColumnIndex(Receipts.COLUMN_NAME_PICTURE_PATH);

        mViewShop.setText(c.getString(shopColumnIndex));
        mViewNote.setText(c.getString(noteColumnIndex));
        mViewTotal.setText(mCurrencyFormat.format(c.getFloat(totalColumnIndex)));
        mViewDate.setText(mDateFormat.format(c.getInt(dateColumnIndex)));

        mViewVerified.setOnCheckedChangeListener(null);
        mViewVerified.setChecked(c.getInt(verifiedColumnIndex) == 1);
        mViewVerified.setOnCheckedChangeListener(this);

        // Cancel picture task
        if (mViewPictureWorker != null) {
            mViewPictureWorker.cancel(true);
        }//from  ww  w. j  ava 2  s  .c  o  m
        mPicturePath = c.getString(picturePathColumnIndex);
        updateThumbnail(mPicturePath);
    }

    setReceiptViewsVisibility(hasReceipt);
    setLoadingScreenVisible(false);
}

From source file:net.potterpcs.recipebook.RecipeData.java

public Recipe getSingleRecipeObject(long rid) {
    Recipe r = new Recipe();
    Cursor c = getSingleRecipe(rid);
    c.moveToFirst();/*  w  ww  .j  a v  a2 s  . c  o m*/
    r.id = c.getLong(c.getColumnIndex(RT_ID));
    r.name = c.getString(c.getColumnIndex(RT_NAME));
    r.description = c.getString(c.getColumnIndex(RT_DESCRIPTION));
    r.rating = c.getFloat(c.getColumnIndex(RT_RATING));
    r.creator = c.getString(c.getColumnIndex(RT_CREATOR));
    r.date = c.getString(c.getColumnIndex(RT_DATE));
    r.serving = c.getInt(c.getColumnIndex(RT_SERVING));
    r.time = c.getInt(c.getColumnIndex(RT_TIME));
    r.photo = c.getString(c.getColumnIndex(RT_PHOTO));

    r.ingredients = getRecipeIngredientStrings(rid);
    r.directions = getRecipeDirectionStrings(rid);
    r.directions_photos = getRecipeDirectionPhotoStrings(rid);
    r.tags = getRecipeTagStrings(rid);

    c.close();
    return r;
}

From source file:com.alley.android.ppi.app.OverviewFragment.java

private void paintHousesOnMap(Cursor cursor) {
    int count = 0;
    if (cursor != null) {
        Log.i(LOG_TAG, "Cursor had " + cursor.getCount() + " entries, current position" + cursor.getPosition());
        if (mMap == null) {
            // Log.e(LOG_TAG, "Camera was null - ");
            return;
        }// w  w  w  . j  av a 2s  . c om
        mMap.clear();
        int cursorCount = cursor.getCount();
        Log.i(LOG_TAG, "After movetoFirst Cursor had " + cursor.getCount() + " entries, current position"
                + cursor.getPosition());
        LatLng house = null;
        ArrayList<MarkerOptions> markers = new ArrayList<MarkerOptions>();
        while (count < cursorCount) { // this sucks but moveToFirst loses first entry so cant use cursor.moveToNext
            cursor.moveToPosition(count);
            float lat = cursor.getFloat(COL_COORD_LAT);
            float lon = cursor.getFloat(COL_COORD_LONG);
            if (lat != 0 && lon != 0) {
                house = new LatLng(lat, lon);
                if (latitude == 0 && longitude == 0 && zoom == 0 && lat != 0 && lon != 0) {
                    if (house != null) {
                        Log.i(LOG_TAG, " moving to house " + house.toString());
                        latitude = lat;
                        longitude = lon;
                        zoom = 15;
                        CameraUpdate center = CameraUpdateFactory.newLatLngZoom(house, zoom);
                        mMap.moveCamera(center);
                    }
                }
                MarkerOptions marker = new MarkerOptions().position(house)
                        .title(cursor.getString(OverviewFragment.COL_PRICE))
                        .snippet(cursor.getString(OverviewFragment.COL_SEARCH_STRING_USED) + "/"
                                + cursor.getString(OverviewFragment.COL_DESCRIPTION))
                        .icon(getBitmap(cursor.getString(OverviewFragment.COLUMN_NUM_BEDS),
                                cursor.getString(OverviewFragment.COL_APARTMENT_HOUSE)));
                mMap.addMarker(marker);
                markers.add(marker);
                Log.i(LOG_TAG,
                        count + " " + cursor.getString(OverviewFragment.COL_PRICE) + " " + house.toString());
            } else {
                Log.i(LOG_TAG, count + " lat " + lat + " long " + lon);
            }
            count++;
        }
        zoomToViewableObjects(markers);
    }
}

From source file:org.ohmage.reminders.types.location.LocTrigMapsActivity.java

/**
 * Check if a location overlaps a location is another category.
 *
 * @param categId/*from   ww  w  . ja v  a  2s  .  co  m*/
 * @param gp
 * @param radius
 * @return the name of the overlapping category. Returns null otherwise.
 */
private String chekLocOverlap(int categId, LatLng gp, double radius) {

    String cName = null;
    Cursor c = mDb.getAllLocations();
    if (c.moveToFirst()) {
        do {
            int cId = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_CATEGORY_ID));

            if (cId != categId) {

                int lat = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LAT));
                int lng = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LONG));

                float locr = c.getFloat(c.getColumnIndexOrThrow(LocTrigDB.KEY_RADIUS));

                // TODO: change the db to use decimal values
                float[] dist = new float[1];
                Location.distanceBetween(gp.latitude, gp.longitude, lat / 1E6, lng / 1E6, dist);

                // Check overlap
                if (dist[0] < locr + radius + LocTrigConfig.MIN_LOC_GAP) {
                    cName = mDb.getCategoryName(cId);
                    break;
                }
            }

        } while (c.moveToNext());
    }

    c.close();
    // return the name of overlapping category
    return cName;
}

From source file:org.ohmage.reminders.types.location.LocTrigMapsActivity.java

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

    setContentView(R.layout.trigger_loc_maps);

    // Get the category id from the intent
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        Log.e(TAG, "Maps: Intent extras is null");

        finish();// w  ww  .  j  a va2  s .co m
        return;
    }

    mCategId = extras.getInt(LocTrigDB.KEY_ID);
    Log.v(TAG, "Maps: category id = " + mCategId);

    TouchableSupportMapFragment mapFragment = (TouchableSupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.triggers_map);
    mMap = mapFragment.getMap();
    mMap.setMyLocationEnabled(true);

    // Set the info window so it has an add button
    mMap.setInfoWindowAdapter(
            new LocTrigInfoAdapter((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)));

    // Set the on Long click handler. This takes care of adding a pin,
    // deleting a pin and entering radius update mode
    mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng point) {

            // First check to see if there is a marker close enough that the
            // user is trying to remove
            if (removeLocation(point))
                return;

            // Then check to see if we are in the radius of the marker to
            // start an update
            if (testMarkerRadiusUpdate(point)) {
                onRadiusUpdateStart();
                return;
            }

            // The default action for a long press is to add a new temporary
            // marker
            onAddTemporaryMarker(point);
        }
    });

    // When the user taps the map, reset all temporary pins
    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            resetMapPins();
        }
    });

    // When a marker is clicked, focus the marker so the radius can be
    // edited
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (!marker.equals(mAddMarker)) {
                onRadiusUpdateFocus(marker);
                return true;
            }
            return false;
        }
    });

    // When the info window is clicked, interpret as adding a point
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            onAddLocation();
        }
    });

    // Watch for touches to handle resizing of the radius
    mapFragment.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(MotionEvent event) {

            if (mRadiusUpdate) {
                // Update the radius movement if we are in the middle of a
                // radius update

                if (MotionEvent.ACTION_MOVE == event.getAction()) {
                    // Continue the radius update since we got a move touch
                    // event
                    Point p = new Point((int) event.getX(), (int) event.getY());
                    onRadiusUpdate(p);
                    return true;
                } else {
                    // End the radius update since we got a touch movement
                    // which wasn't move
                    onRadiusUpdateStop();
                }
            }
            return false;
        }
    });

    // Handle done button and exit this activity
    Button bDone = (Button) findViewById(R.id.button_maps_done);
    bDone.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    mDb = new LocTrigDB(this);
    mDb.open();

    final Builder bounds = new LatLngBounds.Builder();

    // Add locations to the map
    Cursor c = mDb.getLocations(mCategId);
    while (c.moveToNext()) {
        MarkerInfo info = new MarkerInfo();
        int latE6 = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LAT));
        int longE6 = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LONG));
        info.radius = c.getFloat(c.getColumnIndexOrThrow(LocTrigDB.KEY_RADIUS));
        info.id = c.getLong(c.getColumnIndexOrThrow(LocTrigDB.KEY_ID));
        LatLng position = new LatLng(latE6 / 1E6, longE6 / 1E6);

        Marker marker = mMap.addMarker(new MarkerOptions().position(position));
        bounds.include(marker.getPosition());
        markerInfos.put(marker, info);
    }

    // We need to wait for the map to be layed out before we can animate to
    // show all the points
    final LinearLayout map = (LinearLayout) findViewById(R.id.trigger_maps_container);
    if (map.getViewTreeObserver().isAlive()) {
        map.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                map.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                Location myLocation = Utilities.getCurrentLocation(LocTrigMapsActivity.this);
                if (myLocation != null) {
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), 16));
                }

                if (!markerInfos.isEmpty()) {
                    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(),
                            getResources().getDimensionPixelSize(R.dimen.map_marker_gutter)));
                }
            }
        });
    }

    // Display appropriate title text
    updateTitleText();

    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    };

    if (!shouldSkipToolTip()) {
        // Show the tool tip after a small delay
        new Handler().postDelayed(runnable, TOOL_TIP_DELAY);
    }
}

From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java

public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types) throws NotFoundException {
    Cursor cursor = mContentResolver.query(uri, proj, null, null, null);

    try {//from  ww w .  j a  v  a2  s.c o m
        HashMap<String, Object> result = new HashMap<String, Object>(proj.length);
        if (cursor != null && cursor.moveToFirst()) {
            int pos = 0;
            for (String p : proj) {
                switch (types[pos]) {
                case FIELD_TYPE_NULL:
                    result.put(p, cursor.isNull(pos));
                    break;
                case FIELD_TYPE_INTEGER:
                    result.put(p, cursor.getLong(pos));
                    break;
                case FIELD_TYPE_FLOAT:
                    result.put(p, cursor.getFloat(pos));
                    break;
                case FIELD_TYPE_STRING:
                    result.put(p, cursor.getString(pos));
                    break;
                case FIELD_TYPE_BLOB:
                    result.put(p, cursor.getBlob(pos));
                    break;
                }
                pos += 1;
            }
        }

        return result;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.dpcsoftware.mn.CategoryStats.java

public void renderGraph() {
    SQLiteDatabase db = DatabaseHelper.quickDb(this, 0);
    if (date == null)
        date = Calendar.getInstance().getTime();

    String queryModifier = "";
    if (isByMonth)
        queryModifier = " AND strftime('%Y-%m'," + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_DATAT + ") = '"
                + app.dateToDb("yyyy-MM", date) + "'";

    Cursor c = db.rawQuery("SELECT " + Db.Table2.TABLE_NAME + "." + Db.Table2._ID + "," + Db.Table2.TABLE_NAME
            + "." + Db.Table2.COLUMN_NCAT + "," + Db.Table2.TABLE_NAME + "." + Db.Table2.COLUMN_CORCAT + ","
            + "SUM(" + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_VALORT + ")" + " FROM "
            + Db.Table1.TABLE_NAME + "," + Db.Table2.TABLE_NAME + " WHERE " + Db.Table1.TABLE_NAME + "."
            + Db.Table1.COLUMN_IDCAT + " = " + Db.Table2.TABLE_NAME + "." + Db.Table2._ID + " AND "
            + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_IDGRUPO + " = " + app.activeGroupId + queryModifier
            + " GROUP BY " + Db.Table1.TABLE_NAME + "." + Db.Table1.COLUMN_IDCAT + " ORDER BY "
            + Db.Table2.COLUMN_NCAT, null);

    float[] values = new float[c.getCount()];
    int[] colors = new int[c.getCount()];
    float total = 0;

    while (c.moveToNext()) {
        values[c.getPosition()] = c.getFloat(3);
        colors[c.getPosition()] = c.getInt(2);
        total += c.getFloat(3);//from  w  w  w  . jav a  2 s.  c  o m
    }

    BarChart v = new BarChart(this, values, colors);
    v.setPadding(10, 10, 10, 10);
    FrameLayout graphLayout = ((FrameLayout) findViewById(R.id.FrameLayout1));
    if (graphLayout.getChildCount() == 1)
        graphLayout.removeViewAt(0);
    graphLayout.addView(v);

    ListView lv = ((ListView) findViewById(R.id.listView1));
    ((TextView) footer.findViewById(R.id.textView2)).setText(app.printMoney(total));

    int days = 1;
    if (!isByMonth) {
        SimpleDateFormat dateF = new SimpleDateFormat("yyyy-MM-dd");
        dateF.setTimeZone(TimeZone.getDefault());

        Cursor cTemp = db.rawQuery("SELECT " + Db.Table1.COLUMN_DATAT + " FROM " + Db.Table1.TABLE_NAME
                + " WHERE " + Db.Table1.COLUMN_IDGRUPO + " = " + app.activeGroupId + " ORDER BY "
                + Db.Table1.COLUMN_DATAT + " DESC", null);
        try {
            cTemp.moveToFirst();
            Date date2 = dateF.parse(cTemp.getString(0));
            cTemp.moveToLast();
            Date date1 = dateF.parse(cTemp.getString(0));

            days = (int) Math.ceil((date2.getTime() - date1.getTime()) / (1000.0 * 24 * 60 * 60)) + 1;

            App.Log("" + days);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        Calendar now = Calendar.getInstance();
        if (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)
                && cal.get(Calendar.YEAR) == now.get(Calendar.YEAR))
            days = now.get(Calendar.DAY_OF_MONTH);
        else
            days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    ((TextView) footer2.findViewById(R.id.textView2)).setText(app.printMoney(total / days));

    ((TextView) findViewById(R.id.textViewMonth)).setText(app.dateToUser("MMMM / yyyy", date));

    if (adapter == null) {
        adapter = new CategoryStatsAdapter(this, c, total);
        lv.setAdapter(adapter);
    } else {
        adapter.changeCursor(c, total);
        adapter.notifyDataSetChanged();
    }
}