Example usage for android.database Cursor getShort

List of usage examples for android.database Cursor getShort

Introduction

In this page you can find the example usage for android.database Cursor getShort.

Prototype

short getShort(int columnIndex);

Source Link

Document

Returns the value of the requested column as a short.

Usage

From source file:Main.java

public static short getShort(Cursor cursor, String columnName) {
    return cursor.getShort(cursor.getColumnIndexOrThrow(columnName));
}

From source file:Main.java

public static short getShort(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getShort(cursor.getColumnIndex(columnName));
}

From source file:Main.java

public static void keep_setShort(Field field, Object obj, Cursor cursor, int i) {
    try {//from w ww. j  a  v  a 2s . c o  m
        if (field.getType().equals(Short.TYPE))
            field.setShort(obj, cursor.getShort(i));
        else
            field.set(obj, Short.valueOf(cursor.getShort(i)));
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

/**
 * @param v the view to bind/*from   w  w  w.j  a  v a 2s . c om*/
 * @param context standard activity context
 * @param c the cursor source for the object in the db object table.
 * Must include _id in the projection.
 * 
 * @param allowInteractions controls whether the bound view is
 * allowed to intercept touch events and do its own processing.
 */
public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) {
    TextView nameText = (TextView) v.findViewById(R.id.name_text);
    ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content);
    frame.removeAllViews();

    // make sure we have all the columns we need
    Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID));
    String[] projection = null;
    String selection = DbObj.COL_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(objId) };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs,
            sortOrder);
    if (!c.moveToFirst()) {
        Log.w(TAG, "could not find obj " + objId);
        c.close();
        return;
    }
    DbObj obj = App.instance().getMusubi().objForCursor(c);
    if (obj == null) {
        nameText.setText("Failed to access database.");
        Log.e("DbObject", "cursor was null for bindView of DbObject");
        return;
    }
    DbUser sender = obj.getSender();
    Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP));
    Long hash = obj.getHash();
    short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED));
    String feedName = obj.getFeedName();
    String type = obj.getType();
    Date date = new Date(timestamp);
    c.close();
    c = null;

    if (sender == null) {
        nameText.setText("Message from unknown contact.");
        return;
    }
    nameText.setText(sender.getName());

    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
    if (sViewProfileAction == null) {
        sViewProfileAction = new OnClickViewProfile((Activity) context);
    }
    icon.setTag(sender.getLocalId());
    if (allowInteractions) {
        icon.setOnClickListener(sViewProfileAction);
        v.setTag(objId);
    }
    icon.setImageBitmap(sender.getPicture());

    if (deleted == 1) {
        v.setBackgroundColor(sDeletedColor);
    } else {
        v.setBackgroundColor(Color.TRANSPARENT);
    }

    TextView timeText = (TextView) v.findViewById(R.id.time_text);
    timeText.setText(RelativeDate.getRelativeDate(date));

    frame.setTag(objId); // TODO: error prone! This is database id
    frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id
    FeedRenderer renderer = DbObjects.getFeedRenderer(type);
    if (renderer != null) {
        renderer.render(context, frame, obj, allowInteractions);
    }

    if (!allowInteractions) {
        v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
        v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
    } else {
        if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) {
            v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
            v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
        } else {
            ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon);
            TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments);
            attachmentCountButton.setVisibility(View.VISIBLE);

            if (hash == 0) {
                attachmentCountButton.setVisibility(View.GONE);
            } else {
                //int color = DbObject.colorFor(hash);
                boolean selfPost = false;
                DBHelper helper = new DBHelper(context);
                try {
                    Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE });
                    try {
                        attachmentCountText.setText("+" + attachments.getCount());

                        if (attachments.moveToFirst()) {
                            while (!attachments.isAfterLast()) {
                                if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) {
                                    selfPost = true;
                                    break;
                                }
                                attachments.moveToNext();

                            }
                        }
                    } finally {
                        attachments.close();
                    }
                } finally {
                    helper.close();
                }
                if (selfPost) {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red);
                } else {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love);
                }
                attachmentCountText.setTag(R.id.object_entry, hash);
                attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName));
                attachmentCountText.setOnClickListener(LikeListener.getInstance(context));
            }
        }
    }
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a Short out of a column in a Cursor and writes it to a ContentValues.
 * Adds nothing to the ContentValues if the column isn't present or if its value is null.
 *
 * @param cursor The cursor to read from
 * @param column The column to read/*from   w  ww .ja v  a2  s .  com*/
 * @param values The {@link ContentValues} to put the value into
 */
public static void cursorShortToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) {
    final int index = cursor.getColumnIndexOrThrow(column);
    if (!cursor.isNull(index)) {
        values.put(column, cursor.getShort(index));
    }
}

From source file:fr.eoit.activity.loader.InvestItemsLoader.java

private static SparseItemBeanArray getInvestItems(Context context, long itemId) {
    SparseItemBeanArray items = new SparseItemBeanArray();

    final Cursor cursor = context.getContentResolver().query(
            ContentUris.withAppendedId(Item.CONTENT_ID_URI_INVEST, itemId),
            new String[] { Item._ID, Item.COLUMN_NAME_NAME, Item.COLUMN_NAME_CHOSEN_PRICE_ID,
                    Blueprint.COLUMN_NAME_PRODUCE_ITEM_ID, Prices.COLUMN_NAME_OWN_PRICE,
                    Prices.COLUMN_NAME_BUY_PRICE, Prices.COLUMN_NAME_SELL_PRICE,
                    Prices.COLUMN_NAME_PRODUCE_PRICE },
            null, null, null);/*from   www  .  jav a  2s.co m*/

    try {
        if (DbUtil.hasAtLeastOneRow(cursor)) {

            while (!cursor.isAfterLast()) {

                long producedItemId = cursor
                        .getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PRODUCE_ITEM_ID));
                ItemBeanWithMaterials item = new ItemBeanWithMaterials();
                item.id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID));
                item.name = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
                item.price = PricesUtils.getPriceOrNaN(cursor);
                item.quantity = 1;
                item.chosenPriceId = cursor
                        .getShort(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID));
                item.volume = Double.NaN;

                items.append(item);
                items.putAll(getInvestItems(context, producedItemId));

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

    return items;
}

From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

/**
 * Checks that there are enough books to loan out this copy
 *//*from ww w.j  a  va 2  s. c  om*/
public boolean canLoanBook() {
    // Get the quantity of books stored
    Uri bookQuery = ContentUris.withAppendedId(PapyrusContentProvider.Books.CONTENT_URI, selectedBookID);
    String[] columns = { PapyrusContentProvider.Books.FIELD_QUANTITY };
    // store result of query
    Cursor result = resolver.query(bookQuery, columns, null, null, null);
    result.moveToFirst();
    int qty = result.getShort(0);

    String selection = PapyrusContentProvider.Loans.FIELD_BOOK_ID + " = ?";
    String[] selectionArgs = { Long.toString(selectedBookID) };
    columns[0] = PapyrusContentProvider.Loans.FIELD_ID;

    // store result of query
    result = resolver.query(PapyrusContentProvider.Loans.CONTENT_URI, columns, selection, selectionArgs, null);

    if (result.getCount() < qty) {
        result.close();
        return true;
    } else {
        result.close();
        return false;
    }
}

From source file:org.robobees.recyclerush.MatchStatsRR.java

public void fromCursor(Cursor c, DB db, SQLiteDatabase database) {
    super.fromCursor(c, db, database);

    auto_move = c.getInt(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_MOVE)) != 0;
    auto_totes = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_TOTES));
    auto_stack_2 = c.getInt(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_STACK_2)) != 0;
    auto_stack_3 = c.getInt(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_STACK_3)) != 0;
    auto_bin = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_BIN));
    auto_step_bin = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_AUTO_STEP_BIN));

    for (int i = 1; i <= TOTES_IN_STACK; i++)
        totes[i - 1] = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_TOTES_1
                .substring(0, FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_TOTES_1.length() - 1) + i));
    for (int i = 1; i <= COOP_TOTES_STACK; i++)
        coops[i - 1] = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_COOP_1
                .substring(0, FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_COOP_1.length() - 1) + i));
    for (int i = 1; i <= TOTES_IN_STACK; i++)
        bins[i - 1] = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_BIN_1
                .substring(0, FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_BIN_1.length() - 1) + i));

    bin_litter = c.getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_BIN_LITTER));
    landfill_litter = c/*from w w  w .  j av  a2 s  .  c om*/
            .getShort(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_LANDFILL_LITTER));
    tipped_stack = c.getInt(c.getColumnIndexOrThrow(FACT_MATCH_DATA_2015_Entry.COLUMN_NAME_TIPPED_STACK)) != 0;

}

From source file:net.daverix.urlforward.SaveFilterFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_LOAD_FILTER:
        if (data != null && data.moveToFirst()) {
            filter.setTitle(data.getString(0));
            filter.setFilterUrl(data.getString(1));
            filter.setReplaceText(data.getString(2));
            filter.setCreated(data.getLong(3));
            filter.setEncoded(data.getShort(4) != 1);
            filter.setReplaceSubject(data.getString(5));
        }//from  w w w. j  a va 2 s .  c  o  m
        break;
    }
}

From source file:fr.eoit.activity.fragment.blueprint.InventionFragment.java

@Override
public void onLoadFinished(Cursor data) {
    if (DbUtil.hasAtLeastOneRow(data)) {

        parentTypeId = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PARENT_TYPE_ID));
        int maxProdLimit = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_MAX_PRODUCTION_LIMIT));
        metaLevel = data.getShort(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_INVENTION_ITEM_META_LEVEL));
        decryptorId = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_DECRYPTOR_ID));
        double cost = data.getDouble(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_PRICE));

        if (decryptorId != 0) {
            currentDecryptorBonuses = DecryptorUtil.getDecryptorBonusesOrDefault(decryptorId);
        }//from www.j  av  a  2 s .  com

        requiredSkillInventionFragment.setParentFragment(this);
        requiredSkillInventionFragment.setParentTypeId(parentTypeId);

        requiredItemsInventionFragment.setParentFragment(this);
        requiredItemsInventionFragment.setDecryptorId(decryptorId);
        requiredItemsInventionFragment.setParentTypeId(parentTypeId);
        requiredItemsInventionFragment.setMaxProdLimit(maxProdLimit);

        requiredDecryptorFragment.setParentFragment(this);
        requiredDecryptorFragment.setBlueprintId(blueprintId);
        requiredDecryptorFragment.setProducedItemId(producedItemId);

        int metaGroupId = getArguments().getInt("metaGroupId", -1);
        Bundle blueprintBundle = BlueprintUtil.getBlueprintBundle(data, metaGroupId, true, false);

        int numberOfRuns = blueprintBundle.getInt("numberOfRuns", 0);
        int unitPerBatch = blueprintBundle.getInt("unitPerBatch", 0);
        double sellPrice = getArguments().getDouble("sellPrice", 0);
        producePrice = getArguments().getDouble("producePrice", 0);
        double profitOnSingleItem = sellPrice - producePrice;
        double blueprintProfit = profitOnSingleItem * unitPerBatch * numberOfRuns;

        if (!data.isNull(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_PRICE))) {
            BlueprintUtil.setBlueprintCost(costTextView, cost, getResources());
            profitTextView.setText(PricesUtils.formatPrice(blueprintProfit, getActivity(), true));
        } else {
            costTextView.setVisibility(View.GONE);
            profitTextView.setVisibility(View.GONE);
        }
    }
}