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:com.example.android.contactslist.ui.chartActivity.ContactDetailChartFragment.java

private void setContactStatsFromCursor(Cursor cursor) {
    if (cursor.moveToFirst()) {
        mContactStats = new ContactInfo(
                cursor.getString(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_CONTACT_NAME)),
                cursor.getString(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_CONTACT_KEY)),
                cursor.getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_CONTACT_ID)));

        mContactStats.setRowId(cursor.getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry._ID)));

        mContactStats.setDateLastEventIn(
                cursor.getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DATE_LAST_EVENT_IN)));
        mContactStats.setDateLastEventOut(
                cursor.getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DATE_LAST_EVENT_OUT)));
        mContactStats.setDateLastEvent(//w ww . j a  v a  2  s.  c o m
                cursor.getString(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DATE_LAST_EVENT)));
        mContactStats.setDateContactDue(
                cursor.getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DATE_CONTACT_DUE)));

        mContactStats.setDateRecordLastUpdated(cursor
                .getLong(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DATE_RECORD_LAST_UPDATED)));
        mContactStats.setEventIntervalLimit(
                cursor.getInt(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_EVENT_INTERVAL_LIMIT)));
        mContactStats.setEventIntervalLongest(cursor
                .getInt(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_EVENT_INTERVAL_LONGEST)));
        mContactStats.setEventIntervalAvg(
                cursor.getInt(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_EVENT_INTERVAL_AVG)));

        /*mContactStats.setCallDurationTotal(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_CALL_DURATION_TOTAL)));
        mContactStats.setCallDurationAvg(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_CALL_DURATION_AVG)));
        mContactStats.setWordCountAvgIn(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_WORD_COUNT_AVG_IN)));
        mContactStats.setWordCountAvgOut(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_WORD_COUNT_AVG_OUT)));
                
        mContactStats.setWordCountIn(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_WORD_COUNT_IN)));
        mContactStats.setWordCountOut(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_WORD_COUNT_OUT)));
        mContactStats.setMessageCountIn(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_MESSAGE_COUNT_IN)));
        mContactStats.setMessageCountOut(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_MESSAGE_COUNT_OUT)));
                
        mContactStats.setCallCountIn(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_CALL_COUNT_IN)));
        mContactStats.setCallCountOut(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_CALL_COUNT_OUT)));
        mContactStats.setCallCountMissed(cursor.getInt(cursor.getColumnIndex(
            ContactStatsContract.TableEntry.KEY_CALL_COUNT_MISSED)));*/

        mContactStats.setEventCount(
                cursor.getInt(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_EVENT_COUNT)));
        mContactStats.setStanding(
                cursor.getFloat(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_STANDING)));

        mContactStats.setDecay_rate(
                cursor.getFloat(cursor.getColumnIndex(ContactStatsContract.TableEntry.KEY_DECAY_RATE)));

        mContactStats.resetUpdateFlag(); //because this is just reporting on the database content
    }
}

From source file:com.example.android.diegobaldi.sunshine.DetailActivity.java

/**
 * Runs on the main thread when a load is complete. If initLoader is called (we call it from
 * onCreate in DetailActivity) and the LoaderManager already has completed a previous load
 * for this Loader, onLoadFinished will be called immediately. Within onLoadFinished, we bind
 * the data to our views so the user can see the details of the weather on the date they
 * selected from the forecast./*from   w  w w. ja v  a  2s .c  om*/
 *
 * @param loader The cursor loader that finished.
 * @param data   The cursor that is being returned.
 */
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    /*
     * Before we bind the data to the UI that will display that data, we need to check the
     * cursor to make sure we have the results that we are expecting. In order to do that, we
     * check to make sure the cursor is not null and then we call moveToFirst on the cursor.
     * Although it may not seem obvious at first, moveToFirst will return true if it contains
     * a valid first row of data.
     *
     * If we have valid data, we want to continue on to bind that data to the UI. If we don't
     * have any data to bind, we just return from this method.
     */
    boolean cursorHasValidData = false;
    if (data != null && data.moveToFirst()) {
        /* We have valid data, continue on to bind the data to the UI */
        cursorHasValidData = true;
    }

    if (!cursorHasValidData) {
        /* No data to display, simply return and do nothing */
        return;
    }

    /****************
     * Weather Icon *
     ****************/
    /* Read weather condition ID from the cursor (ID provided by Open Weather Map) */
    int weatherId = data.getInt(INDEX_WEATHER_CONDITION_ID);
    /* Use our utility method to determine the resource ID for the proper art */
    int weatherImageId = SunshineWeatherUtils.getLargeArtResourceIdForWeatherCondition(weatherId);

    /* Set the resource ID on the icon to display the art */
    mDetailBinding.primaryInfo.weatherIcon.setImageResource(weatherImageId);

    /****************
     * Weather Date *
     ****************/
    /*
     * Read the date from the cursor. It is important to note that the date from the cursor
     * is the same date from the weather SQL table. The date that is stored is a GMT
     * representation at midnight of the date when the weather information was loaded for.
     *
     * When displaying this date, one must add the GMT offset (in milliseconds) to acquire
     * the date representation for the local date in local time.
     * SunshineDateUtils#getFriendlyDateString takes care of this for us.
     */
    long localDateMidnightGmt = data.getLong(INDEX_WEATHER_DATE);
    String dateText = SunshineDateUtils.getFriendlyDateString(this, localDateMidnightGmt, true);

    mDetailBinding.primaryInfo.date.setText(dateText);

    /***********************
     * Weather Description *
     ***********************/
    /* Use the weatherId to obtain the proper description */
    String description = SunshineWeatherUtils.getStringForWeatherCondition(this, weatherId);

    /* Create the accessibility (a11y) String from the weather description */
    String descriptionA11y = getString(R.string.a11y_forecast, description);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.primaryInfo.weatherDescription.setText(description);
    mDetailBinding.primaryInfo.weatherDescription.setContentDescription(descriptionA11y);

    /* Set the content description on the weather image (for accessibility purposes) */
    mDetailBinding.primaryInfo.weatherIcon.setContentDescription(descriptionA11y);

    /**************************
     * High (max) temperature *
     **************************/
    /* Read high temperature from the cursor (in degrees celsius) */
    double highInCelsius = data.getDouble(INDEX_WEATHER_MAX_TEMP);
    /*
     * If the user's preference for weather is fahrenheit, formatTemperature will convert
     * the temperature. This method will also append either C or F to the temperature
     * String.
     */
    String highString = SunshineWeatherUtils.formatTemperature(this, highInCelsius);

    /* Create the accessibility (a11y) String from the weather description */
    String highA11y = getString(R.string.a11y_high_temp, highString);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.primaryInfo.highTemperature.setText(highString);
    mDetailBinding.primaryInfo.highTemperature.setContentDescription(highA11y);

    /*************************
     * Low (min) temperature *
     *************************/
    /* Read low temperature from the cursor (in degrees celsius) */
    double lowInCelsius = data.getDouble(INDEX_WEATHER_MIN_TEMP);
    /*
     * If the user's preference for weather is fahrenheit, formatTemperature will convert
     * the temperature. This method will also append either C or F to the temperature
     * String.
     */
    String lowString = SunshineWeatherUtils.formatTemperature(this, lowInCelsius);

    String lowA11y = getString(R.string.a11y_low_temp, lowString);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.primaryInfo.lowTemperature.setText(lowString);
    mDetailBinding.primaryInfo.lowTemperature.setContentDescription(lowA11y);

    /************
     * Humidity *
     ************/
    /* Read humidity from the cursor */
    float humidity = data.getFloat(INDEX_WEATHER_HUMIDITY);
    String humidityString = getString(R.string.format_humidity, humidity);

    String humidityA11y = getString(R.string.a11y_humidity, humidityString);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.extraDetails.humidity.setText(humidityString);
    mDetailBinding.extraDetails.humidity.setContentDescription(humidityA11y);

    mDetailBinding.extraDetails.humidityLabel.setContentDescription(humidityA11y);

    /****************************
     * Wind speed and direction *
     ****************************/
    /* Read wind speed (in MPH) and direction (in compass degrees) from the cursor  */
    float windSpeed = data.getFloat(INDEX_WEATHER_WIND_SPEED);
    float windDirection = data.getFloat(INDEX_WEATHER_DEGREES);
    String windString = SunshineWeatherUtils.getFormattedWind(this, windSpeed, windDirection);

    String windA11y = getString(R.string.a11y_wind, windString);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.extraDetails.windMeasurement.setText(windString);
    mDetailBinding.extraDetails.windMeasurement.setContentDescription(windA11y);

    mDetailBinding.extraDetails.windLabel.setContentDescription(windA11y);

    /************
     * Pressure *
     ************/
    /* Read pressure from the cursor */
    float pressure = data.getFloat(INDEX_WEATHER_PRESSURE);

    /*
     * Format the pressure text using string resources. The reason we directly access
     * resources using getString rather than using a method from SunshineWeatherUtils as
     * we have for other data displayed in this Activity is because there is no
     * additional logic that needs to be considered in order to properly display the
     * pressure.
     */
    String pressureString = getString(R.string.format_pressure, pressure);

    String pressureA11y = getString(R.string.a11y_pressure, pressureString);

    /* Set the text and content description (for accessibility purposes) */
    mDetailBinding.extraDetails.pressure.setText(pressureString);
    mDetailBinding.extraDetails.pressure.setContentDescription(pressureA11y);

    mDetailBinding.extraDetails.pressureLabel.setContentDescription(pressureA11y);

    /* Store the forecast summary String in our forecast summary field to share later */
    mForecastSummary = String.format("%s - %s - %s/%s", dateText, description, highString, lowString);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testRawQueryWithData_ExpectPass() {
    String tableId = testTable;/*from  w  w w  .j av  a2 s . co m*/
    String query = "SELECT * FROM " + tableId;
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, query, null, null, accessContext);
    Cursor refCursor = db.rawQuery(query, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testQueryWithData_ExpectPass() {
    String tableId = testTable;/*from   w  ww  . j ava 2  s  .c  o  m*/
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().queryForTest(db, tableId, null, null, null, null, null, null,
            null);
    Cursor refCursor = db.query(tableId, null, null, null, null, null, null, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

@Test
public void testRawQueryWithData_ExpectPass() {
    String tableId = testTable;/*w ww  . j  a v  a2s . c om*/
    String query = "SELECT * FROM " + tableId;
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, query, null, null, accessContext);
    Cursor refCursor = db.rawQuery(query, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat, 0.0);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

@Test
public void testQueryWithData_ExpectPass() {
    String tableId = testTable;/*  ww  w .j a  v  a  2  s.com*/
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().queryForTest(db, tableId, null, null, null, null, null, null,
            null);
    Cursor refCursor = db.query(tableId, null, null, null, null, null, null, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat, 0.0);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * This will fill the UI elements with information from the database
 * It also saves information for AsyncTasks to use later and manages the transform/flip button
 *
 * @param id the ID of the the card to be displayed
 * @return true if the UI was filled in, false otherwise
 *///  w ww  .j  a  v  a 2 s  .  c  om
public void setInfoFromID(final long id) {

    /* If the views are null, don't attempt to fill them in */
    if (mSetTextView == null) {
        return;
    }

    ImageGetter imgGetter = ImageGetterHelper.GlyphGetter(getActivity());

    SQLiteDatabase database = DatabaseManager.getInstance(getActivity(), false).openDatabase(false);
    Cursor cCardById;
    try {
        cCardById = CardDbAdapter.fetchCards(new long[] { id }, null, database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }

    /* http://magiccards.info/scans/en/mt/55.jpg */
    mCardName = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME));
    mCardCMC = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_CMC));
    mSetCode = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET));

    /* Start building a description */
    addToDescription(getString(R.string.search_name), mCardName);
    try {
        mSetName = CardDbAdapter.getSetNameFromCode(mSetCode, database);
        addToDescription(getString(R.string.search_set), mSetName);
    } catch (FamiliarDbException e) {
        /* no set for you */
    }

    try {
        mMagicCardsInfoSetCode = CardDbAdapter
                .getCodeMtgi(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)), database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }
    mCardNumber = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER));

    switch ((char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY))) {
    case 'C':
    case 'c':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_common)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Common));
        break;
    case 'U':
    case 'u':
        mSetTextView.setTextColor(
                ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_uncommon)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Uncommon));
        break;
    case 'R':
    case 'r':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_rare)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Rare));
        break;
    case 'M':
    case 'm':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_mythic)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Mythic));
        break;
    case 'T':
    case 't':
        mSetTextView.setTextColor(
                ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_timeshifted)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Timeshifted));
        break;
    }

    String sCost = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_MANACOST));
    addToDescription(getString(R.string.search_mana_cost), sCost);
    CharSequence csCost = ImageGetterHelper.formatStringWithGlyphs(sCost, imgGetter);
    mCostTextView.setText(csCost);

    String sAbility = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ABILITY));
    addToDescription(getString(R.string.search_text), sAbility);
    CharSequence csAbility = ImageGetterHelper.formatStringWithGlyphs(sAbility, imgGetter);
    mAbilityTextView.setText(csAbility);
    mAbilityTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String sFlavor = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_FLAVOR));
    addToDescription(getString(R.string.search_flavor_text), sFlavor);
    CharSequence csFlavor = ImageGetterHelper.formatStringWithGlyphs(sFlavor, imgGetter);
    mFlavorTextView.setText(csFlavor);

    mNameTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME)));
    mCardType = CardDbAdapter.getTypeLine(cCardById);
    mTypeTextView.setText(mCardType);
    mSetTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)));
    mArtistTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST)));
    String numberAndRarity = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)) + " ("
            + (char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY)) + ")";
    mNumberTextView.setText(numberAndRarity);

    addToDescription(getString(R.string.search_type), CardDbAdapter.getTypeLine(cCardById));
    addToDescription(getString(R.string.search_artist),
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST)));
    addToDescription(getString(R.string.search_collectors_number),
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)));

    int loyalty = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_LOYALTY));
    float p = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_POWER));
    float t = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_TOUGHNESS));
    if (loyalty != CardDbAdapter.NO_ONE_CARES) {
        if (loyalty == CardDbAdapter.X) {
            mPowTouTextView.setText("X");
        } else {
            mPowTouTextView.setText(Integer.valueOf(loyalty).toString());
        }
    } else if (p != CardDbAdapter.NO_ONE_CARES && t != CardDbAdapter.NO_ONE_CARES) {

        String powTouStr = "";

        if (p == CardDbAdapter.STAR)
            powTouStr += "*";
        else if (p == CardDbAdapter.ONE_PLUS_STAR)
            powTouStr += "1+*";
        else if (p == CardDbAdapter.TWO_PLUS_STAR)
            powTouStr += "2+*";
        else if (p == CardDbAdapter.SEVEN_MINUS_STAR)
            powTouStr += "7-*";
        else if (p == CardDbAdapter.STAR_SQUARED)
            powTouStr += "*^2";
        else if (p == CardDbAdapter.X)
            powTouStr += "X";
        else {
            if (p == (int) p) {
                powTouStr += (int) p;
            } else {
                powTouStr += p;
            }
        }

        powTouStr += "/";

        if (t == CardDbAdapter.STAR)
            powTouStr += "*";
        else if (t == CardDbAdapter.ONE_PLUS_STAR)
            powTouStr += "1+*";
        else if (t == CardDbAdapter.TWO_PLUS_STAR)
            powTouStr += "2+*";
        else if (t == CardDbAdapter.SEVEN_MINUS_STAR)
            powTouStr += "7-*";
        else if (t == CardDbAdapter.STAR_SQUARED)
            powTouStr += "*^2";
        else if (t == CardDbAdapter.X)
            powTouStr += "X";
        else {
            if (t == (int) t) {
                powTouStr += (int) t;
            } else {
                powTouStr += t;
            }
        }

        addToDescription(getString(R.string.search_power), powTouStr);

        mPowTouTextView.setText(powTouStr);
    } else {
        mPowTouTextView.setText("");
    }

    boolean isMultiCard = false;
    switch (CardDbAdapter.isMultiCard(mCardNumber,
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)))) {
    case NOPE:
        isMultiCard = false;
        mTransformButton.setVisibility(View.GONE);
        mTransformButtonDivider.setVisibility(View.GONE);
        break;
    case TRANSFORM:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_transform);
        break;
    case FUSE:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_fuse);
        break;
    case SPLIT:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_other_half);
        break;
    }

    if (isMultiCard) {
        if (mCardNumber.contains("a")) {
            mTransformCardNumber = mCardNumber.replace("a", "b");
        } else if (mCardNumber.contains("b")) {
            mTransformCardNumber = mCardNumber.replace("b", "a");
        }
        try {
            mTransformId = CardDbAdapter.getIdFromSetAndNumber(mSetCode, mTransformCardNumber, database);
        } catch (FamiliarDbException e) {
            handleFamiliarDbException(true);
            DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
            return;
        }
        if (mTransformId == -1) {
            mTransformButton.setVisibility(View.GONE);
            mTransformButtonDivider.setVisibility(View.GONE);
        } else {
            mTransformButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    releaseImageResources(true);
                    mCardNumber = mTransformCardNumber;
                    setInfoFromID(mTransformId);
                }
            });
        }
    }

    mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_MULTIVERSEID));

    /* Do we load the image immediately to the main page, or do it in a dialog later? */
    if (mActivity.mPreferenceAdapter.getPicFirst()) {
        mImageScrollView.setVisibility(View.VISIBLE);
        mTextScrollView.setVisibility(View.GONE);

        mActivity.setLoading();
        if (mAsyncTask != null) {
            mAsyncTask.cancel(true);
        }
        mAsyncTask = new FetchPictureTask();
        ((FetchPictureTask) mAsyncTask).execute(MAIN_PAGE);
    } else {
        mImageScrollView.setVisibility(View.GONE);
        mTextScrollView.setVisibility(View.VISIBLE);
    }

    /* Figure out how large the color indicator should be. Medium text is 18sp, with a border its 22sp */
    int dimension = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 22,
            getResources().getDisplayMetrics());

    mColorIndicatorLayout.removeAllViews();
    ColorIndicatorView civ = new ColorIndicatorView(this.getActivity(), dimension, dimension / 15,
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_COLOR)), sCost);
    if (civ.shouldInidcatorBeShown()) {
        mColorIndicatorLayout.setVisibility(View.VISIBLE);
        mColorIndicatorLayout.addView(civ);
    } else {
        mColorIndicatorLayout.setVisibility(View.GONE);
    }

    String allLanguageKeys[][] = {
            { Language.Chinese_Traditional, CardDbAdapter.KEY_NAME_CHINESE_TRADITIONAL,
                    CardDbAdapter.KEY_MULTIVERSEID_CHINESE_TRADITIONAL },
            { Language.Chinese_Simplified, CardDbAdapter.KEY_NAME_CHINESE_SIMPLIFIED,
                    CardDbAdapter.KEY_MULTIVERSEID_CHINESE_SIMPLIFIED },
            { Language.French, CardDbAdapter.KEY_NAME_FRENCH, CardDbAdapter.KEY_MULTIVERSEID_FRENCH },
            { Language.German, CardDbAdapter.KEY_NAME_GERMAN, CardDbAdapter.KEY_MULTIVERSEID_GERMAN },
            { Language.Italian, CardDbAdapter.KEY_NAME_ITALIAN, CardDbAdapter.KEY_MULTIVERSEID_ITALIAN },
            { Language.Japanese, CardDbAdapter.KEY_NAME_JAPANESE, CardDbAdapter.KEY_MULTIVERSEID_JAPANESE },
            { Language.Portuguese_Brazil, CardDbAdapter.KEY_NAME_PORTUGUESE_BRAZIL,
                    CardDbAdapter.KEY_MULTIVERSEID_PORTUGUESE_BRAZIL },
            { Language.Russian, CardDbAdapter.KEY_NAME_RUSSIAN, CardDbAdapter.KEY_MULTIVERSEID_RUSSIAN },
            { Language.Spanish, CardDbAdapter.KEY_NAME_SPANISH, CardDbAdapter.KEY_MULTIVERSEID_SPANISH },
            { Language.Korean, CardDbAdapter.KEY_NAME_KOREAN, CardDbAdapter.KEY_MULTIVERSEID_KOREAN } };

    // Clear the translations first
    mTranslatedNames.clear();

    // Add English
    Card.ForeignPrinting englishPrinting = new Card.ForeignPrinting();
    englishPrinting.mLanguageCode = Language.English;
    englishPrinting.mName = mCardName;
    englishPrinting.mMultiverseId = mMultiverseId;
    mTranslatedNames.add(englishPrinting);

    // Add all the others
    for (String lang[] : allLanguageKeys) {
        Card.ForeignPrinting fp = new Card.ForeignPrinting();
        fp.mLanguageCode = lang[0];
        fp.mName = cCardById.getString(cCardById.getColumnIndex(lang[1]));
        fp.mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(lang[2]));
        if (fp.mName != null && !fp.mName.isEmpty()) {
            mTranslatedNames.add(fp);
        }
    }

    cCardById.close();

    /* Find the other sets this card is in ahead of time, so that it can be remove from the menu if there is only
       one set */
    Cursor cCardByName;
    try {
        cCardByName = CardDbAdapter.fetchCardByName(mCardName,
                new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_SET,
                        CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID,
                        CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_NUMBER },
                false, database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }
    mPrintings = new LinkedHashSet<>();
    mCardIds = new LinkedHashSet<>();
    while (!cCardByName.isAfterLast()) {
        try {
            String number = cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_NUMBER));
            if (!(number == null || number.length() == 0)) {
                number = " (" + number + ")";
            } else {
                number = "";
            }
            if (mPrintings.add(CardDbAdapter.getSetNameFromCode(
                    cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_SET)), database)
                    + number)) {
                mCardIds.add(cCardByName.getLong(cCardByName.getColumnIndex(CardDbAdapter.KEY_ID)));
            }
        } catch (FamiliarDbException e) {
            handleFamiliarDbException(true);
            DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
            return;
        }
        cCardByName.moveToNext();
    }
    cCardByName.close();
    /* If it exists in only one set, remove the button from the menu */
    if (mPrintings.size() == 1) {
        mActivity.supportInvalidateOptionsMenu();
    }
    DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);

    if (mShouldReportView) {
        reportAppIndexViewIfAble();
    }
}