Java Code Examples for android.database.Cursor.getFloat()

The following are Jave code examples for showing how to use getFloat() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: SimpleEntityNotNullDao.java   Source Code and License Vote up 6 votes
@Override
public SimpleEntityNotNull readEntity(Cursor cursor, int offset) {
    SimpleEntityNotNull entity = new SimpleEntityNotNull( //
        cursor.getLong(offset + 0), // id
        cursor.getShort(offset + 1) != 0, // simpleBoolean
        (byte) cursor.getShort(offset + 2), // simpleByte
        cursor.getShort(offset + 3), // simpleShort
        cursor.getInt(offset + 4), // simpleInt
        cursor.getLong(offset + 5), // simpleLong
        cursor.getFloat(offset + 6), // simpleFloat
        cursor.getDouble(offset + 7), // simpleDouble
        cursor.getString(offset + 8), // simpleString
        cursor.getBlob(offset + 9) // simpleByteArray
    );
    return entity;
}
 
Example 2
Project: OftenPorter   File: TypeUtil.java   Source Code and License Vote up 6 votes
static Object getObject(Cursor cursor, int columnIndex) throws Exception
{
    int type = getType(cursor, columnIndex);
    Object value;
    switch (type)
    {
        case Cursor.FIELD_TYPE_BLOB:
            value = cursor.getBlob(columnIndex);
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            value = cursor.getFloat(columnIndex);
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            value = cursor.getLong(columnIndex);
            break;
        case Cursor.FIELD_TYPE_NULL:
            value = null;
            break;
        case Cursor.FIELD_TYPE_STRING:
            value = cursor.getString(columnIndex);
            break;
        default:
            value = cursor.getString(columnIndex);
    }
    return value;
}
 
Example 3
Project: amap   File: MapDatebaseManager.java   Source Code and License Vote up 6 votes
/**
 * 查询所有数据
 * @return
 */
public ArrayList<Location> query(){

        Cursor cursor=db.rawQuery("select * from location ",null);
    ArrayList<Location> list=new ArrayList<>();
    if (cursor.moveToFirst()) {
        do {
            Location location =new Location();
            location.time=cursor.getString(1);
            location.lat=cursor.getFloat(2);
            location.lng=cursor.getFloat(3);
            location.address=cursor.getString(4);
            location.userid=cursor.getString(5);

            list.add(location);
        }while(cursor.moveToNext());

    }
    cursor.close();
    return list;

}
 
Example 4
Project: amap   File: MapDatebaseManager.java   Source Code and License Vote up 6 votes
/**
 * 查询最后几条数据
 * @return
 */
public ArrayList<Location> querylastLocation(int n){

    Cursor cursor=db.rawQuery("select * from location order by id desc limit "+n,null);
    ArrayList<Location> list=new ArrayList<>();
    if (cursor.moveToFirst()) {


        do {
            Location location =new Location();
            location.time=cursor.getString(1);
            location.lat=cursor.getFloat(2);
            location.lng=cursor.getFloat(3);
            location.address=cursor.getString(4);
            location.userid=cursor.getString(5);

            list.add(location);
        }while(cursor.moveToNext());

    }
    cursor.close();
    return list;


}
 
Example 5
Project: GitHub   File: LitePalTestCase.java   Source Code and License Vote up 5 votes
protected List<Book> getBooks(String[] columns, String selection, String[] selectionArgs,
		String groupBy, String having, String orderBy, String limit) {
	List<Book> books = new ArrayList<Book>();
	Cursor cursor = Connector.getDatabase().query(getTableName(Book.class), columns, selection, selectionArgs,
			groupBy, having, orderBy, limit);
	if (cursor.moveToFirst()) {
		do {
			long id = cursor.getLong(cursor.getColumnIndexOrThrow("id"));
			String bookName = cursor.getString(cursor.getColumnIndexOrThrow("bookname"));
			int pages = cursor.getInt(cursor.getColumnIndexOrThrow("pages"));
			double price = cursor.getDouble(cursor.getColumnIndexOrThrow("price"));
			char level = cursor.getString(cursor.getColumnIndexOrThrow("level")).charAt(0);
			short isbn = cursor.getShort(cursor.getColumnIndexOrThrow("isbn"));
			float area = cursor.getFloat(cursor.getColumnIndexOrThrow("area"));
			boolean isPublished = cursor.getInt(cursor.getColumnIndexOrThrow("ispublished")) == 1;
			Book book = new Book();
			book.setId(id);
			book.setBookName(bookName);
			book.setPages(pages);
			book.setPrice(price);
			book.setLevel(level);
			book.setIsbn(isbn);
			book.setArea(area);
			book.setPublished(isPublished);
			books.add(book);
		} while (cursor.moveToNext());
	}
	cursor.close();
	return books;
}
 
Example 6
Project: natumassas-app   File: PedidoRepositorio.java   Source Code and License Vote up 5 votes
@Override
public List<Object> searchAll() {
    List<Object> pedidos = new ArrayList<>();

    StringBuilder sql = new StringBuilder();

    sql.append("SELECT  CODIGO, TITULO, DATAENTREGA, DESCRICAO, VALOR, PAGO, CODCLIENTE ");
    sql.append("    FROM PEDIDO");

    Cursor resultado = connection.rawQuery(sql.toString(), null);

    if(resultado.getCount() > 0){
        resultado.moveToFirst();

        do{
            Pedido pedido = new Pedido();

            pedido.codigo = resultado.getInt(resultado.getColumnIndexOrThrow("CODIGO"));
            pedido.titulo = resultado.getString(resultado.getColumnIndexOrThrow("TITULO"));
            pedido.setDataEntrega(resultado.getString(resultado.getColumnIndexOrThrow("DATAENTREGA")));
            pedido.descricao = resultado.getString(resultado.getColumnIndexOrThrow("DESCRICAO"));
            pedido.valor = resultado.getFloat(resultado.getColumnIndexOrThrow("VALOR"));
            pedido.pago = resultado.getInt(resultado.getColumnIndexOrThrow("PAGO"));
            pedido.codCliente = resultado.getInt(resultado.getColumnIndexOrThrow("CODCLIENTE"));

            pedidos.add(pedido);
        }
        while (resultado.moveToNext());
    }

    resultado.close();

    return pedidos;
}
 
Example 7
Project: RoadLab-Pro   File: BaseDAO.java   Source Code and License Vote up 5 votes
public double getSum(long folderId, long roadId, long measurementId, String column, String table) {
    double sum = 0;
    try {
        String queryStr = getQueryStr(folderId, roadId, measurementId);
        String calcDistanceQuery = "SELECT SUM(" + column
                + ") FROM " + table
                + " WHERE " + queryStr;
        final Cursor cursor = getDatabase().rawQuery(calcDistanceQuery, null);
        cursor.moveToFirst();
        sum = cursor.getFloat(0);
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    }
    return sum;
}
 
Example 8
Project: CSipSimple   File: SipConfigManager.java   Source Code and License Vote up 5 votes
/**
 * Helper method to retrieve a csipsimple float config value
 * 
 * @param ctxt The context of your app
 * @param key the key for the setting you want to get
 * @param defaultValue the value you want to return if nothing found
 * @return the preference value
 */
public static Float getPreferenceFloatValue(Context ctxt, String key, Float defaultValue) {
    Float value = defaultValue;
    Uri uri = getPrefUriForKey(key);
    Cursor c = ctxt.getContentResolver().query(uri, null, Float.class.getName(), null, null);
    if (c != null) {
        c.moveToFirst();
        Float fValue = c.getFloat(1);
        if (fValue != null) {
            value = fValue;
        }
        c.close();
    }
    return value;
}
 
Example 9
Project: RetrofitAppArchitecture   File: Utils.java   Source Code and License Vote up 5 votes
public static Map<String, Object> cursor2Map(Cursor cursor) {
    Map<String, Object> map = new HashMap<>();
    if (cursor != null && cursor.getColumnCount() > 0) {
        int count = cursor.getColumnCount();
        for (int i = 0; i < count; i++) {
            int type = cursor.getType(i);

            Object value = null;
            switch (type) {
                case Cursor.FIELD_TYPE_STRING:
                    value = cursor.getString(i);
                    break;
                case Cursor.FIELD_TYPE_INTEGER:
                    value = cursor.getInt(i);
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    value = cursor.getFloat(i);
                    break;
                case Cursor.FIELD_TYPE_NULL:
                    LogUtils.d("未知的参数类型,type:" + type);
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    LogUtils.d("未知的参数类型,type:" + type);
                    break;
            }
            if (value != null) {
                String name = cursor.getColumnName(i);
                map.put(name, value);
            }
        }
    }
    return map;
}
 
Example 10
Project: XPrivacy   File: XContentResolver.java   Source Code and License Vote up 5 votes
private void copyColumns(Cursor cursor, MatrixCursor result, int count) {
	try {
		Object[] columns = new Object[count];
		for (int i = 0; i < count; i++)
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_NULL:
				columns[i] = null;
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columns[i] = cursor.getInt(i);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columns[i] = cursor.getFloat(i);
				break;
			case Cursor.FIELD_TYPE_STRING:
				columns[i] = cursor.getString(i);
				break;
			case Cursor.FIELD_TYPE_BLOB:
				columns[i] = cursor.getBlob(i);
				break;
			default:
				Util.log(this, Log.WARN, "Unknown cursor data type=" + cursor.getType(i));
			}
		result.addRow(columns);
	} catch (Throwable ex) {
		Util.bug(this, ex);
	}
}
 
Example 11
Project: Android-Scrapper   File: MultiProcessPreference.java   Source Code and License Vote up 5 votes
private static float getFloatValue(Cursor cursor, float def) {
    if (cursor == null)
        return def;
    float value = def;
    if (cursor.moveToFirst()) {
        value = cursor.getFloat(0);
    }
    cursor.close();
    return value;
}
 
Example 12
Project: GitHub   File: FloatColumnConverter.java   Source Code and License Vote up 4 votes
@Override
public Float getFieldValue(final Cursor cursor, int index) {
    return cursor.isNull(index) ? null : cursor.getFloat(index);
}
 
Example 13
Project: AndiCar   File: DBReportAdapter.java   Source Code and License Vote up 4 votes
public ArrayList<chartData> getRefuelsByTagChartData(String[] selectionArgs, boolean getValue) {
    ArrayList<chartData> retVal = new ArrayList<>();
    float totalValue = 0f;

    String sqlWhere = " WHERE " + sqlConcatTableColumn(TABLE_NAME_REFUEL, COL_NAME_REFUEL__CAR_ID) + " = ?";
    if(selectionArgs.length > 1 && !selectionArgs[1].equals("0"))
        sqlWhere = sqlWhere + " AND " + sqlConcatTableColumn(TABLE_NAME_REFUEL, COL_NAME_REFUEL__DATE) + " >= ?";
    else
        sqlWhere = sqlWhere + " AND '0' = ? ";

    if(selectionArgs.length > 2 && !selectionArgs[2].equals("0"))
        sqlWhere = sqlWhere + " AND " + sqlConcatTableColumn(TABLE_NAME_REFUEL, COL_NAME_REFUEL__DATE) + " <= ?";
    else
        sqlWhere = sqlWhere + " AND '0' = ? ";

    String selColName;
    if(getValue)
        selColName = COL_NAME_REFUEL__AMOUNT;
    else
        selColName = COL_NAME_REFUEL__QUANTITY;

    //get the sum for calculating the percent of each type
    String selectSql =
            " SELECT SUM(" + sqlConcatTableColumn(TABLE_NAME_REFUEL, selColName) + ") " +
            " FROM " + TABLE_NAME_REFUEL +
            sqlWhere;

    Cursor c = mDb.rawQuery(selectSql, selectionArgs);
    if (c.moveToFirst()) {
        totalValue = c.getFloat(0);
    }
    c.close();
    if (totalValue == 0f)
        return retVal; //no entries

    selectSql =
            " SELECT SUM(" + sqlConcatTableColumn(TABLE_NAME_REFUEL, selColName) + "), " +
                    "SUM(" + sqlConcatTableColumn(TABLE_NAME_REFUEL, selColName) + ") * 100 / " + totalValue + ", " + //in percent
                    "COALESCE( " + sqlConcatTableColumn(TABLE_NAME_TAG, COL_NAME_GEN_NAME) + ", 'N/A')" +
            " FROM " + TABLE_NAME_REFUEL +
            " LEFT OUTER JOIN " + TABLE_NAME_TAG + " ON " +
                    sqlConcatTableColumn(TABLE_NAME_REFUEL, COL_NAME_REFUEL__TAG_ID) +
                    "=" + sqlConcatTableColumn(TABLE_NAME_TAG, COL_NAME_GEN_ROWID) +
            sqlWhere +
            " GROUP BY COALESCE( " + sqlConcatTableColumn(TABLE_NAME_TAG, COL_NAME_GEN_NAME) + ", 'N/A')" +
            " ORDER BY 1 DESC";
    c = mDb.rawQuery(selectSql, selectionArgs);
    while (c.moveToNext()) {
        chartData cd = new chartData();
        cd.value = c.getFloat(0);
        cd.value2 = c.getFloat(1);
        cd.totalValue = totalValue;
        cd.label = c.getString(2);
        retVal.add(cd);
    }
    c.close();
    return retVal;
}
 
Example 14
Project: TaBeTa   File: InternalDB.java   Source Code and License Vote up 4 votes
public float GetPointX(int level, int n){
	Cursor cu = mydb.query("Pointsx", null, "ID="+level, null, null, null, null);
	cu.moveToPosition(0);
	float point = cu.getFloat(n+1);
	return point;
}
 
Example 15
Project: boohee_v5.6   File: UserDao.java   Source Code and License Vote up 4 votes
public User selectWithCursor(Cursor cursor) {
    if (cursor == null) {
        return null;
    }
    String token = cursor.getString(cursor.getColumnIndex("token"));
    String user_key = cursor.getString(cursor.getColumnIndex("user_key"));
    String cellphone = cursor.getString(cursor.getColumnIndex("cellphone"));
    String user_name = cursor.getString(cursor.getColumnIndex(USER_NAME));
    String sex_type = cursor.getString(cursor.getColumnIndex("sex_type"));
    String birthday = cursor.getString(cursor.getColumnIndex("birthday"));
    float height = cursor.getFloat(cursor.getColumnIndex("height"));
    float begin_weight = cursor.getFloat(cursor.getColumnIndex(BEGIN_WEIGHT));
    float target_weight = cursor.getFloat(cursor.getColumnIndex("target_weight"));
    String target_date = cursor.getString(cursor.getColumnIndex("target_date"));
    int target_calory = cursor.getInt(cursor.getColumnIndex("target_calory"));
    String updated_at = cursor.getString(cursor.getColumnIndex("updated_at"));
    String avatar = cursor.getString(cursor.getColumnIndex(AVATAR));
    String description = cursor.getString(cursor.getColumnIndex("description"));
    float latest_weight = cursor.getFloat(cursor.getColumnIndex("latest_weight"));
    String latest_weight_at = cursor.getString(cursor.getColumnIndex(LATEST_WEIGHT_AT));
    float latest_waist = cursor.getFloat(cursor.getColumnIndex(LATEST_WAIST));
    String latest_waist_at = cursor.getString(cursor.getColumnIndex(LATEST_WAIST_AT));
    int post_count = cursor.getInt(cursor.getColumnIndex(POST_COUNT));
    int envious_count = cursor.getInt(cursor.getColumnIndex(ENVIOUS_COUNT));
    int following_count = cursor.getInt(cursor.getColumnIndex(FOLLOWING_COUNT));
    int follower_count = cursor.getInt(cursor.getColumnIndex(FOLLOWER_COUNT));
    int badges_count = cursor.getInt(cursor.getColumnIndex(BADGES_COUNT));
    String sport_condition = cursor.getString(cursor.getColumnIndex(SPORT_CONDITION));
    String diseaes = cursor.getString(cursor.getColumnIndex(DISEASES));
    int need_test = cursor.getInt(cursor.getColumnIndex(NEED_TEST));
    String begin_date = cursor.getString(cursor.getColumnIndex("begin_date"));
    cursor.close();
    return new Builder().setToken(token).setUserKey(user_key).setCellPhone(cellphone)
            .setUserName(user_name).setSexType(sex_type).setBirthDay(birthday).setHeight
                    (height).setBeginWeight(begin_weight).setTargetWeight(target_weight)
            .setTargetDate(target_date).setTargetCalory(target_calory).setUpdateAt
                    (updated_at).setAvatarUrl(avatar).setDescription(description)
            .setLatestWeight(latest_weight).setLatestWeightAt(latest_weight_at)
            .setLatestWaist(Float.valueOf(latest_waist)).setLatestWaistAt(latest_waist_at)
            .setPostCount(post_count).setEnviousCount(envious_count).setFollowingCount(following_count).setFollowerCount(follower_count).setBadgesCount(badges_count).setSportCondition(sport_condition).setDiseases(diseaes).setNeedTest(need_test).setBeginDate(begin_date).create();
}
 
Example 16
Project: natumassas-app   File: PedidoRepositorio.java   Source Code and License Vote up 4 votes
public List<Object> searchAllSortedByActive() {
    List<Object> pedidos = new ArrayList<>();

    List<Pedido> pedidosAtivos = new ArrayList<>();
    List<Pedido> pedidosFinalizados = new ArrayList<>();

    StringBuilder sql = new StringBuilder();

    sql.append("SELECT  CODIGO, TITULO,FINALIZADO, DATAENTREGA, DESCRICAO, VALOR, PAGO, CODCLIENTE ");
    sql.append("    FROM PEDIDO");

    Cursor resultado = connection.rawQuery(sql.toString(), null);

    if(resultado.getCount() > 0){
        resultado.moveToFirst();

        do{
            Pedido pedido = new Pedido();

            pedido.codigo = resultado.getInt(resultado.getColumnIndexOrThrow("CODIGO"));
            pedido.titulo = resultado.getString(resultado.getColumnIndexOrThrow("TITULO"));
            pedido.finalizado = resultado.getInt(resultado.getColumnIndexOrThrow("FINALIZADO"));
            pedido.setDataEntrega(resultado.getString(resultado.getColumnIndexOrThrow("DATAENTREGA")));
            pedido.descricao = resultado.getString(resultado.getColumnIndexOrThrow("DESCRICAO"));
            pedido.valor = resultado.getFloat(resultado.getColumnIndexOrThrow("VALOR"));
            pedido.pago = resultado.getInt(resultado.getColumnIndexOrThrow("PAGO"));
            pedido.codCliente = resultado.getInt(resultado.getColumnIndexOrThrow("CODCLIENTE"));

            if(pedido.finalizado == 0)
                pedidosAtivos.add(pedido);
            else
                pedidosFinalizados.add(pedido);
        }
        while (resultado.moveToNext());
    }

    resultado.close();

    pedidosAtivos = QuickSortPedidos.sortAtivos(pedidosAtivos);
    pedidosFinalizados = QuickSortPedidos.sortFinalizados(pedidosFinalizados);

    pedidos.addAll(pedidosAtivos);
    pedidos.addAll(pedidosFinalizados);

    return pedidos;
}
 
Example 17
Project: hyperrail-for-android   File: StationsDb.java   Source Code and License Vote up 4 votes
/**
 * Load stations from a cursor. This method <strong>does not close the cursor afterwards</strong>.
 *
 * @param c The cursor from which stations should be loaded.
 * @return The array of loaded stations
 */
private Station[] loadStationCursor(Cursor c) {
    if (c.isClosed()) {
        FirebaseCrash.logcat(SEVERE.intValue(), LOGTAG, "Tried to load closed cursor");
        return null;
    }

    if (c.getCount() == 0) {
        FirebaseCrash.logcat(SEVERE.intValue(), LOGTAG, "Tried to load cursor with 0 results!");
        return null;
    }

    c.moveToFirst();
    Station[] result = new Station[c.getCount()];
    int i = 0;
    while (!c.isAfterLast()) {

        String locale = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_stations_language", "");
        if (locale.isEmpty()) {
            // Only get locale when needed
            locale = Locale.getDefault().getISO3Language();
            PreferenceManager.getDefaultSharedPreferences(context).edit().putString("pref_stations_language", locale).apply();
        }

        String name = c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_NAME));
        String localizedName = null;

        String nl = c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_ALTERNATIVE_NL));
        String fr = c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_ALTERNATIVE_FR));
        String de = c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_ALTERNATIVE_DE));
        String en = c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_ALTERNATIVE_EN));

        switch (locale) {
            case "nld":
                localizedName = nl;
                break;
            case "fra":
                localizedName = fr;
                break;
            case "deu":
                localizedName = de;
                break;
            case "eng":
                localizedName = en;
                break;
        }

        if (localizedName == null || localizedName.isEmpty()) {
            localizedName = name;
        }

        Station s = new Station(
                c.getString(c.getColumnIndex(StationsDataColumns._ID)),
                name,
                nl,
                fr,
                de,
                en,
                localizedName,
                c.getString(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_COUNTRY_CODE)),
                c.getDouble(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_LATITUDE)),
                c.getDouble(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_LONGITUDE)),
                c.getFloat(c.getColumnIndex(StationsDataColumns.COLUMN_NAME_AVG_STOP_TIMES)));

        c.moveToNext();
        result[i] = s;
        i++;
    }
    return result;
}
 
Example 18
Project: Recognize-it   File: MediaReader.java   Source Code and License Vote up 4 votes
/**
 * Scan for image files.
 */
@WorkerThread
private void scanImageFile(Map<String, AlbumFolder> albumFolderMap, AlbumFolder allFileFolder) {
    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cursor = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            IMAGES,
            null,
            null,
            MediaStore.Images.Media.DATE_ADDED);

    if (cursor != null) {
        while (cursor.moveToNext()) {
            String path = cursor.getString(cursor.getColumnIndex(IMAGES[0]));

            File file = new File(path);
            if (!file.exists() || !file.canRead()) continue;

            String name = cursor.getString(cursor.getColumnIndex(IMAGES[1]));
            String title = cursor.getString(cursor.getColumnIndex(IMAGES[2]));
            int bucketId = cursor.getInt(cursor.getColumnIndex(IMAGES[3]));
            String bucketName = cursor.getString(cursor.getColumnIndex(IMAGES[4]));
            String mimeType = cursor.getString(cursor.getColumnIndex(IMAGES[5]));
            long addDate = cursor.getLong(cursor.getColumnIndex(IMAGES[6]));
            long modifyDate = cursor.getLong(cursor.getColumnIndex(IMAGES[7]));
            float latitude = cursor.getFloat(cursor.getColumnIndex(IMAGES[8]));
            float longitude = cursor.getFloat(cursor.getColumnIndex(IMAGES[9]));
            long size = cursor.getLong(cursor.getColumnIndex(IMAGES[10]));

            AlbumFile imageFile = new AlbumFile();
            imageFile.setMediaType(AlbumFile.TYPE_IMAGE);
            imageFile.setPath(path);
            imageFile.setName(name);
            imageFile.setTitle(title);
            imageFile.setBucketId(bucketId);
            imageFile.setBucketName(bucketName);
            imageFile.setMimeType(mimeType);
            imageFile.setAddDate(addDate);
            imageFile.setModifyDate(modifyDate);
            imageFile.setLatitude(latitude);
            imageFile.setLongitude(longitude);
            imageFile.setSize(size);

            // Filter.
            if (mSizeFilter != null && mSizeFilter.filter(size)) {
                if (!mFilterVisibility) continue;
                imageFile.setEnable(false);
            }
            if (mMimeFilter != null && mMimeFilter.filter(mimeType)) {
                if (!mFilterVisibility) continue;
                imageFile.setEnable(false);
            }

            allFileFolder.addAlbumFile(imageFile);
            AlbumFolder albumFolder = albumFolderMap.get(bucketName);

            if (albumFolder != null)
                albumFolder.addAlbumFile(imageFile);
            else {
                albumFolder = new AlbumFolder();
                albumFolder.setId(bucketId);
                albumFolder.setName(bucketName);
                albumFolder.addAlbumFile(imageFile);

                albumFolderMap.put(bucketName, albumFolder);
            }
        }
        cursor.close();
    }
}
 
Example 19
Project: iosched-reader   File: MarkerLoadingTask.java   Source Code and License Vote up 4 votes
@Override
public List<MarkerEntry> loadInBackground() {
    List<MarkerEntry> list = null;

    // Create a URI to get a cursor of all map markers
    final Uri uri = ScheduleContract.MapMarkers.buildMarkerUri();
    Cursor cursor = getContext().getContentResolver().query(uri, MarkerQuery.PROJECTION,
            null, null, null);

    // Create a MarkerModel for each entry
    final int count = cursor.getCount();
    if (cursor != null) {

        list = new ArrayList<>(count);
        final IconGenerator labelIconGenerator = MapUtils.getLabelIconGenerator(getContext());
        cursor.moveToFirst();

        while (!cursor.isAfterLast()) {
            // get data
            final String id = cursor.getString(MarkerQuery.MARKER_ID);
            final int floor = cursor.getInt(MarkerQuery.MARKER_FLOOR);
            final float lat = cursor.getFloat(MarkerQuery.MARKER_LATITUDE);
            final float lon = cursor.getFloat(MarkerQuery.MARKER_LONGITUDE);
            final int type =
                    MapUtils.detectMarkerType(cursor.getString(MarkerQuery.MARKER_TYPE));
            final String label = cursor.getString(MarkerQuery.MARKER_LABEL);

            final LatLng position = new LatLng(lat, lon);
            MarkerOptions marker = null;
            if (type == MarkerModel.TYPE_LABEL) {
                // Label markers contain the label as its icon
                marker = MapUtils.createLabelMarker(labelIconGenerator, id, position, label);
            } else if (type != MarkerModel.TYPE_INACTIVE) {
                // All other markers (that are not inactive) contain a pin icon
                marker = MapUtils.createPinMarker(id, position);
            }

            MarkerModel model = new MarkerModel(id, floor, type, label, null);
            MarkerEntry entry = new MarkerEntry(model, marker);

            list.add(entry);

            cursor.moveToNext();
        }
        cursor.close();
    }

    return list;
}
 
Example 20
Project: AndiCar   File: DBReportAdapter.java   Source Code and License Vote up 4 votes
public ArrayList<chartData> getMileageByTypeChartData(String[] selectionArgs) {
        ArrayList<chartData> retVal = new ArrayList<>();
        float totalValue = 0f;

        String sqlWhere = " WHERE " + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTOP) + " IS NOT NULL AND " +
                                sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__CAR_ID) + " = ?";
        if(selectionArgs.length > 1 && !selectionArgs[1].equals("0"))
            sqlWhere = sqlWhere + " AND " + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__DATE) + " >= ?";
        else
            sqlWhere = sqlWhere + " AND '0' = ? ";

        if(selectionArgs.length > 2 && !selectionArgs[2].equals("0"))
            sqlWhere = sqlWhere + " AND " + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__DATE) + " <= ?";
        else
            sqlWhere = sqlWhere + " AND '0' = ? ";

        //get the sum of the mileage for calculating the percent of each type
        String selectSql =
                " SELECT SUM(" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTOP) +
                        "-" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTART) + ") " +
                " FROM " + TABLE_NAME_MILEAGE +
                sqlWhere;

        Cursor c = mDb.rawQuery(selectSql, selectionArgs);
        if(c.moveToFirst()){
            totalValue = c.getFloat(0);
        }
        c.close();
        if (totalValue == 0f)
            return retVal; //no entries

        selectSql =
                " SELECT SUM(" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTOP) +
                                        "-" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTART) + "), " +
                        "SUM(" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTOP) +
                        "-" + sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__INDEXSTART) + ") * 100 / " + totalValue + ", " + //in percent
                        sqlConcatTableColumn(TABLE_NAME_EXPENSETYPE, COL_NAME_GEN_NAME) +
                " FROM " + TABLE_NAME_MILEAGE +
                "   JOIN " + TABLE_NAME_EXPENSETYPE + " ON " +
                        sqlConcatTableColumn(TABLE_NAME_MILEAGE, COL_NAME_MILEAGE__EXPENSETYPE_ID) +
                        "=" + sqlConcatTableColumn(TABLE_NAME_EXPENSETYPE, COL_NAME_GEN_ROWID) +
                sqlWhere +
                " GROUP BY " + sqlConcatTableColumn(TABLE_NAME_EXPENSETYPE, COL_NAME_GEN_NAME) +
                " ORDER BY 1 DESC";
//                " ORDER BY " + sqlConcatTableColumn(TABLE_NAME_EXPENSETYPE, COL_NAME_GEN_NAME);
        c = mDb.rawQuery(selectSql, selectionArgs);
        while (c.moveToNext()){
            chartData cd = new chartData();
            cd.value = c.getFloat(0);
            cd.value2 = c.getFloat(1);
            cd.totalValue = totalValue;
            cd.label = c.getString(2);
            retVal.add(cd);
        }
        c.close();
        return retVal;
    }