List of usage examples for android.database Cursor getShort
short getShort(int columnIndex);
From source file:info.curtbinder.reefangel.phone.StatusActivity.java
private String[] getAITextValues(Cursor c) { String[] sa = new String[Controller.MAX_AI_CHANNELS]; sa[Controller.AI_WHITE] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_AIW)), c.getShort(c.getColumnIndex(StatusTable.COL_AIWO))); sa[Controller.AI_BLUE] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_AIB)), c.getShort(c.getColumnIndex(StatusTable.COL_AIBO))); sa[Controller.AI_ROYALBLUE] = Controller.getPWMDisplayValue( c.getShort(c.getColumnIndex(StatusTable.COL_AIRB)), c.getShort(c.getColumnIndex(StatusTable.COL_AIRBO))); return sa;/*from w w w . j a v a 2s .co m*/ }
From source file:info.curtbinder.reefangel.phone.StatusActivity.java
private String[] getSCPWMETextValues(Cursor c) { String[] sa = new String[Controller.MAX_SCPWM_EXPANSION_PORTS]; sa[0] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME0)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME0O))); sa[1] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME1)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME1O))); sa[2] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME2)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME2O))); sa[3] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME3)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME3O))); sa[4] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME4)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME4O))); sa[5] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME5)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME5O))); sa[6] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME6)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME6O))); sa[7] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME7)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME7O))); sa[8] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME8)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME8O))); sa[9] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME9)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME9O))); sa[10] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME10)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME10O))); sa[11] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME11)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME11O))); sa[12] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME12)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME12O))); sa[13] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME13)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME13O))); sa[14] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME14)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME14O))); sa[15] = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME15)), c.getShort(c.getColumnIndex(StatusTable.COL_SCPWME15O))); return sa;//from w ww . j av a 2 s .c o m }
From source file:info.curtbinder.reefangel.phone.StatusActivity.java
private String[] getControllerValues(Cursor c) { // FIXME switch to only setting the string to 1 or 0 // FIXME so the controllerpage can easily update the images String l, h;/*from w ww . j a v a 2 s. co m*/ if (c.getShort(c.getColumnIndex(StatusTable.COL_ATOLO)) == 1) l = getString(R.string.labelON); // ACTIVE, GREEN, ON else l = getString(R.string.labelOFF); // INACTIVE, RED, OFF if (c.getShort(c.getColumnIndex(StatusTable.COL_ATOHI)) == 1) h = getString(R.string.labelON); // ACTIVE, GREEN, ON else h = getString(R.string.labelOFF); // INACTIVE, RED, OFF String apText = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_AP)), c.getShort(c.getColumnIndex(StatusTable.COL_PWMAO))); String dpText = Controller.getPWMDisplayValue(c.getShort(c.getColumnIndex(StatusTable.COL_DP)), c.getShort(c.getColumnIndex(StatusTable.COL_PWMDO))); return new String[] { c.getString(c.getColumnIndex(StatusTable.COL_T1)), c.getString(c.getColumnIndex(StatusTable.COL_T2)), c.getString(c.getColumnIndex(StatusTable.COL_T3)), c.getString(c.getColumnIndex(StatusTable.COL_PH)), dpText, apText, l, h, c.getString(c.getColumnIndex(StatusTable.COL_SAL)) + " ppt", c.getString(c.getColumnIndex(StatusTable.COL_ORP)) + " mV", c.getString(c.getColumnIndex(StatusTable.COL_PHE)), c.getString(c.getColumnIndex(StatusTable.COL_WL)) + "%", c.getString(c.getColumnIndex(StatusTable.COL_WL1)) + "%", c.getString(c.getColumnIndex(StatusTable.COL_WL2)) + "%", c.getString(c.getColumnIndex(StatusTable.COL_WL3)) + "%", c.getString(c.getColumnIndex(StatusTable.COL_WL4)) + "%", c.getString(c.getColumnIndex(StatusTable.COL_HUM)) + "%" }; }
From source file:th.in.ffc.person.PersonDetailEditFragment.java
private void getDefaultHouseDetail(String hcode) { // TODO get default house parameter String selection = null;//from w w w .j a v a 2 s .c om String[] selectionArgs = null; if (!TextUtils.isEmpty(hcode)) { selection = "hcode = ? AND provcodemoi IS NOT NULL"; selectionArgs = new String[] { mHcode }; } Cursor c = getFFCActivity().getContentResolver().query(Person.CONTENT_URI, new String[] { Person.ADDR_NO, Person.ADDR_MU, Person.ADDR_ROAD, Person.ADDR_SUBDIST, Person.ADDR_DIST, Person.ADDR_PROVICE, Person.POSTCODE }, selection, selectionArgs, Person.DEFAULT_SORTING); if (c.moveToFirst()) { hno.setText(c.getString(0)); mu.setText(c.getString(1)); road.setText(c.getString(2)); System.out.println("Prov:" + c.getString(5) + " Dist:" + c.getString(4) + " S.Dist:" + c.getString(3)); provcode.setSelectionById(c.getString(5)); distcode.setSelectionById(c.getString(4), "distcode =? AND provcode ='" + c.getString(5) + "'"); subdistcode.setSelectionById(c.getString(3), "subdistcode=? AND distcode='" + c.getString(4) + "' AND provcode='" + c.getShort(5) + "'"); postcode.setText(c.getString(6)); } }
From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java
@SuppressWarnings("unchecked") protected <T> T get(Cursor cursor, Class<T> clazz, int columnIndex) { Object result = null;//from w w w .j a va2s . com if (clazz.equals(String.class)) { result = (String) cursor.getString(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Integer) cursor.getInt(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Double) cursor.getDouble(columnIndex); } else if (clazz.equals(Float.class)) { result = (Float) cursor.getFloat(columnIndex); } else if (clazz.equals(Long.class)) { result = (Long) cursor.getLong(columnIndex); } else if (clazz.equals(Date.class) || clazz.equals(Timestamp.class)) { String dateString = cursor.getString(columnIndex); if (dateString.contains("-")) { result = Timestamp.valueOf(dateString); } else { result = new Timestamp(Long.parseLong(dateString)); } } else if (clazz.equals(Short.class)) { result = (Short) cursor.getShort(columnIndex); } else if (clazz.equals(byte[].class)) { result = (byte[]) cursor.getBlob(columnIndex); } else { throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); } return (T) result; }
From source file:com.nonninz.robomodel.RoboModel.java
private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); final int columnIndex = query.getColumnIndex(field.getName()); field.setAccessible(true);//from w ww. j a v a 2s.c om /* * TODO: There is the potential of a problem here: * What happens if the developer changes the type of a field between releases? * * If he saves first, then the column type will be changed (In the future). * If he loads first, we don't know if an Exception will be thrown if the * types are incompatible, because it's undocumented in the Cursor documentation. */ try { if (type == String.class) { field.set(this, query.getString(columnIndex)); } else if (type == Boolean.TYPE) { final boolean value = query.getInt(columnIndex) == 1 ? true : false; field.setBoolean(this, value); } else if (type == Byte.TYPE) { field.setByte(this, (byte) query.getShort(columnIndex)); } else if (type == Double.TYPE) { field.setDouble(this, query.getDouble(columnIndex)); } else if (type == Float.TYPE) { field.setFloat(this, query.getFloat(columnIndex)); } else if (type == Integer.TYPE) { field.setInt(this, query.getInt(columnIndex)); } else if (type == Long.TYPE) { field.setLong(this, query.getLong(columnIndex)); } else if (type == Short.TYPE) { field.setShort(this, query.getShort(columnIndex)); } else if (type.isEnum()) { final String string = query.getString(columnIndex); if (string != null && string.length() > 0) { final Object[] constants = type.getEnumConstants(); final Method method = type.getMethod("valueOf", Class.class, String.class); final Object value = method.invoke(constants[0], type, string); field.set(this, value); } } else { // Try to de-json it (db column must be of type text) try { final Object value = mMapper.readValue(query.getString(columnIndex), field.getType()); field.set(this, value); } catch (final Exception e) { final String msg = String.format("Type %s is not supported for field %s", type, field.getName()); Ln.w(e, msg); throw new IllegalArgumentException(msg); } } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } catch (IllegalStateException e) { // This is when there is no column in db, but there is in the model throw new DatabaseNotUpToDateException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public short firstShort(SQLiteDatabase db, String table, String column, String orderBy) { Cursor cursor = null; short value = 0; try {//from ww w .j ava 2s . c o m cursor = query(db, table, new String[] { column }, orderBy); if (cursor.moveToFirst()) { value = cursor.getShort(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public short firstShort(Uri uri, String column, String orderBy) { Cursor cursor = null; short value = 0; try {/*from w ww. ja va 2s. co m*/ cursor = select(uri, new String[] { column }, orderBy, false); if (cursor.moveToFirst()) { value = cursor.getShort(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public short[] selectShortArray(Uri uri, String column, String orderBy) { Cursor cursor = null; try {//from www . java2 s .c o m cursor = select(uri, new String[] { column }, orderBy, false); short[] array = new short[cursor.getCount()]; for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); array[i] = cursor.getShort(0); } return array; } finally { Closeables.closeSilently(cursor); } }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public List<Short> selectShortList(Uri uri, String column, String orderBy) { Cursor cursor = null; try {/*w ww . j av a2s. c o m*/ cursor = select(uri, new String[] { column }, orderBy, false); List<Short> list = new ArrayList<Short>(cursor.getCount()); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); list.add(cursor.getShort(0)); } return list; } finally { Closeables.closeSilently(cursor); } }