List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.ichi2.anki.SyncClient.java
private JSONArray bundleHistory() { JSONArray bundledHistory = new JSONArray(); Cursor cursor = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()).getDatabase().rawQuery( "SELECT cardId, time, lastInterval, nextInterval, ease, delay, lastFactor, nextFactor, reps, " + "thinkingTime, yesCount, noCount FROM reviewHistory " + "WHERE time > " + String.format(Utils.ENGLISH_LOCALE, "%f", mDeck.getLastSync()), null);//from w w w . ja v a2 s . c o m while (cursor.moveToNext()) { try { JSONArray review = new JSONArray(); // cardId review.put(cursor.getLong(0)); // time review.put(cursor.getDouble(1)); // lastInterval review.put(cursor.getDouble(2)); // nextInterval review.put(cursor.getDouble(3)); // ease review.put(cursor.getInt(4)); // delay review.put(cursor.getDouble(5)); // lastFactor review.put(cursor.getDouble(6)); // nextFactor review.put(cursor.getDouble(7)); // reps review.put(cursor.getDouble(8)); // thinkingTime review.put(cursor.getDouble(9)); // yesCount review.put(cursor.getDouble(10)); // noCount review.put(cursor.getDouble(11)); bundledHistory.put(review); } catch (JSONException e) { Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } } cursor.close(); Log.i(AnkiDroidApp.TAG, "Last sync = " + String.format(Utils.ENGLISH_LOCALE, "%f", mDeck.getLastSync())); Log.i(AnkiDroidApp.TAG, "Bundled history = " + bundledHistory.toString()); return bundledHistory; }
From source file:android.support.content.InMemoryCursor.java
/** * @param cursor source of data to copy. Ownership is reserved to the called, meaning * we won't ever close it. *///from w w w . jav a 2s.c o m InMemoryCursor(Cursor cursor, int offset, int length, int disposition) { checkArgument(offset < cursor.getCount()); // NOTE: The cursor could simply be saved to a field, but we choose to wrap // in a dedicated relay class to avoid hanging directly onto a reference // to the cursor...so future authors are not enticed to think there's // a live link between the delegate cursor and this cursor. mObserverRelay = new ObserverRelay(cursor); mColumnNames = cursor.getColumnNames(); mRowCount = Math.min(length, cursor.getCount() - offset); int numColumns = cursor.getColumnCount(); mExtras = ContentPager.buildExtras(cursor.getExtras(), cursor.getCount(), disposition); mColumnType = new int[numColumns]; mTypedColumnIndex = new int[NUM_TYPES][numColumns]; mColumnTypeCount = new int[NUM_TYPES]; if (!cursor.moveToFirst()) { throw new RuntimeException("Can't position cursor to first row."); } for (int col = 0; col < numColumns; col++) { int type = cursor.getType(col); mColumnType[col] = type; mTypedColumnIndex[type][col] = mColumnTypeCount[type]++; } mLongs = new long[mRowCount * mColumnTypeCount[FIELD_TYPE_INTEGER]]; mDoubles = new double[mRowCount * mColumnTypeCount[FIELD_TYPE_FLOAT]]; mBlobs = new byte[mRowCount * mColumnTypeCount[FIELD_TYPE_BLOB]][]; mStrings = new String[mRowCount * mColumnTypeCount[FIELD_TYPE_STRING]]; for (int row = 0; row < mRowCount; row++) { if (!cursor.moveToPosition(offset + row)) { throw new RuntimeException("Unable to position cursor."); } // Now copy data from the row into primitive arrays. for (int col = 0; col < mColumnType.length; col++) { int type = mColumnType[col]; int position = getCellPosition(row, col, type); switch (type) { case FIELD_TYPE_NULL: throw new UnsupportedOperationException("Not implemented."); case FIELD_TYPE_INTEGER: mLongs[position] = cursor.getLong(col); break; case FIELD_TYPE_FLOAT: mDoubles[position] = cursor.getDouble(col); break; case FIELD_TYPE_BLOB: mBlobs[position] = cursor.getBlob(col); break; case FIELD_TYPE_STRING: mStrings[position] = cursor.getString(col); break; } } } }
From source file:com.coderming.weatherwatch.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { ViewParent vp = getView().getParent(); if (vp instanceof CardView) { ((View) vp).setVisibility(View.VISIBLE); }/* ww w.j av a 2s. c o m*/ // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (com.coderming.weatherwatch.Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource( com.coderming.weatherwatch.Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this) .load(com.coderming.weatherwatch.Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(com.coderming.weatherwatch.Utility.getArtResourceForWeatherCondition(weatherId)) .crossFade().into(mIconView); } // Read date from cursor and update views for day of week and date long date = data.getLong(COL_WEATHER_DATE); String dateText = com.coderming.weatherwatch.Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); // Get description from weather condition ID String description = com.coderming.weatherwatch.Utility.getStringForWeatherCondition(getActivity(), weatherId); mDescriptionView.setText(description); mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description)); // For accessibility, add a content description to the icon field. Because the ImageView // is independently focusable, it's better to have a description of the image. Using // null is appropriate when the image is purely decorative or when the image already // has text describing it in the same UI component. mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description)); // Read high temperature from cursor and update view boolean isMetric = com.coderming.weatherwatch.Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = com.coderming.weatherwatch.Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString)); // Read low temperature from cursor and update view double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = com.coderming.weatherwatch.Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); mLowTempView.setContentDescription(getString(R.string.a11y_low_temp, lowString)); // Read humidity from cursor and update view float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); mHumidityView.setContentDescription(getString(R.string.a11y_humidity, mHumidityView.getText())); mHumidityLabelView.setContentDescription(mHumidityView.getContentDescription()); // Read wind speed and direction from cursor and update view float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText( com.coderming.weatherwatch.Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText())); mWindLabelView.setContentDescription(mWindView.getContentDescription()); // Read pressure from cursor and update view float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getString(R.string.format_pressure, pressure)); mPressureView.setContentDescription(getString(R.string.a11y_pressure, mPressureView.getText())); mPressureLabelView.setContentDescription(mPressureView.getContentDescription()); // We still need this for the share intent mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); } AppCompatActivity activity = (AppCompatActivity) getActivity(); Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar); // We need to start the enter transition after the data has loaded if (mTransitionAnimation) { activity.supportStartPostponedEnterTransition(); if (null != toolbarView) { activity.setSupportActionBar(toolbarView); activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } else { if (null != toolbarView) { Menu menu = toolbarView.getMenu(); if (null != menu) menu.clear(); toolbarView.inflateMenu(R.menu.detailfragment); finishCreatingMenu(toolbarView.getMenu()); } } }
From source file:org.opendatakit.common.android.utilities.ODKDatabaseUtils.java
/** * Return the data stored in the cursor at the given index and given position * (ie the given row which the cursor is currently on) as null OR a String. * <p>// w w w . ja va 2 s.c om * NB: Currently only checks for Strings, long, int, and double. * * @param c * @param i * @return */ @SuppressLint("NewApi") public String getIndexAsString(Cursor c, int i) { // If you add additional return types here be sure to modify the javadoc. if (i == -1) return null; if (c.isNull(i)) { return null; } switch (c.getType(i)) { case Cursor.FIELD_TYPE_STRING: return c.getString(i); case Cursor.FIELD_TYPE_FLOAT: return Double.toString(c.getDouble(i)); case Cursor.FIELD_TYPE_INTEGER: return Long.toString(c.getLong(i)); case Cursor.FIELD_TYPE_NULL: return c.getString(i); default: case Cursor.FIELD_TYPE_BLOB: throw new IllegalStateException("Unexpected data type in SQLite table"); } }
From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java
/** * Creates a JSON Object from a Tweet TODO: Move this where it belongs! * /*from w w w . ja v a2 s . com*/ * @param c * @return * @throws JSONException */ protected JSONObject getJSON(Cursor c) throws JSONException { JSONObject o = new JSONObject(); if (c.getColumnIndex(Tweets.COL_USER_TID) < 0 || c.getColumnIndex(TwitterUsers.COL_SCREEN_NAME) < 0) { Log.i(TAG, "missing user data"); return null; } else { o.put(Tweets.COL_USER_TID, c.getLong(c.getColumnIndex(Tweets.COL_USER_TID))); o.put(TYPE, MESSAGE_TYPE_TWEET); o.put(TwitterUsers.COL_SCREEN_NAME, c.getString(c.getColumnIndex(TwitterUsers.COL_SCREEN_NAME))); if (c.getColumnIndex(Tweets.COL_CREATED_AT) >= 0) o.put(Tweets.COL_CREATED_AT, c.getLong(c.getColumnIndex(Tweets.COL_CREATED_AT))); if (c.getColumnIndex(Tweets.COL_CERTIFICATE) >= 0) o.put(Tweets.COL_CERTIFICATE, c.getString(c.getColumnIndex(Tweets.COL_CERTIFICATE))); if (c.getColumnIndex(Tweets.COL_SIGNATURE) >= 0) o.put(Tweets.COL_SIGNATURE, c.getString(c.getColumnIndex(Tweets.COL_SIGNATURE))); if (c.getColumnIndex(Tweets.COL_TEXT) >= 0) o.put(Tweets.COL_TEXT, c.getString(c.getColumnIndex(Tweets.COL_TEXT))); if (c.getColumnIndex(Tweets.COL_REPLY_TO_TWEET_TID) >= 0) o.put(Tweets.COL_REPLY_TO_TWEET_TID, c.getLong(c.getColumnIndex(Tweets.COL_REPLY_TO_TWEET_TID))); if (c.getColumnIndex(Tweets.COL_LAT) >= 0) o.put(Tweets.COL_LAT, c.getDouble(c.getColumnIndex(Tweets.COL_LAT))); if (c.getColumnIndex(Tweets.COL_LNG) >= 0) o.put(Tweets.COL_LNG, c.getDouble(c.getColumnIndex(Tweets.COL_LNG))); if (!c.isNull(c.getColumnIndex(Tweets.COL_MEDIA_URIS))) { String photoUri = c.getString(c.getColumnIndex(Tweets.COL_MEDIA_URIS)); Uri uri = Uri.parse(photoUri); o.put(Tweets.COL_MEDIA_URIS, uri.getLastPathSegment()); } if (c.getColumnIndex(Tweets.COL_HTML_PAGES) >= 0) o.put(Tweets.COL_HTML_PAGES, c.getString(c.getColumnIndex(Tweets.COL_HTML_PAGES))); if (c.getColumnIndex(Tweets.COL_SOURCE) >= 0) o.put(Tweets.COL_SOURCE, c.getString(c.getColumnIndex(Tweets.COL_SOURCE))); if (c.getColumnIndex(Tweets.COL_TID) >= 0 && !c.isNull(c.getColumnIndex(Tweets.COL_TID))) o.put(Tweets.COL_TID, c.getLong(c.getColumnIndex(Tweets.COL_TID))); if (c.getColumnIndex(TwitterUsers.COL_PROFILE_IMAGE_URI) >= 0 && c.getColumnIndex(TweetsContentProvider.COL_USER_ROW_ID) >= 0) { String imageUri = c.getString(c.getColumnIndex(TwitterUsers.COL_PROFILE_IMAGE_URI)); Bitmap profileImage = ImageLoader.getInstance().loadImageSync(imageUri); if (profileImage != null) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); profileImage.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); String profileImageBase64 = Base64.encodeToString(byteArray, Base64.DEFAULT); o.put(TwitterUsers.JSON_FIELD_PROFILE_IMAGE, profileImageBase64); } } return o; } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java
/** * On loading finished get the data that we need for populating the viewpager fragments and set * the local dagvergunning vars//from www . j av a 2 s . c o m * @param loader the loader * @param data a cursor with one record containing the joined dagvergunning details */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { // dagvergunning values mErkenningsnummer = data.getString( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE)); mErkenningsnummerInvoerMethode = data.getString( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_METHODE)); mRegistratieDatumtijd = data.getString( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD)); mRegistratieGeolocatieLatitude = data.getDouble( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LAT)); mRegistratieGeolocatieLongitude = data.getDouble( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LONG)); mTotaleLengte = data .getInt(data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE)); mSollicitatieStatus = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE)); mKoopmanAanwezig = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_AANWEZIG)); mKoopmanId = data.getInt(data.getColumnIndex("koopman_koopman_id")); mKoopmanVoorletters = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS)); mKoopmanAchternaam = data .getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM)); mKoopmanFoto = data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL)); mRegistratieAccountId = data.getInt(data.getColumnIndex("account_account_id")); mRegistratieAccountNaam = data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Account.COL_NAAM)); mSollicitatieId = data.getInt(data.getColumnIndex("sollicitatie_sollicitatie_id")); mSollicitatieNummer = data .getInt(data.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER)); mNotitie = data.getString(data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE)); mVervangerId = data.getInt(data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ID)); mVervangerErkenningsnummer = data.getString( data.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER)); String[] productParams = getResources().getStringArray(R.array.array_product_param); for (String product : productParams) { mProducten.put(product, data.getInt(data.getColumnIndex("dagvergunning_" + product))); mProductenVast.put(product, data.getInt(data.getColumnIndex(product + "_vast"))); } // update the view elements of the currently selected tab setFragmentValuesByPosition(mCurrentTab); // load the koopman details from the api (will get his sollicitaties at other markten) if (mErkenningsnummer != null && !mErkenningsnummer.equals("")) { ApiGetKoopmanByErkenningsnummer getKoopman = new ApiGetKoopmanByErkenningsnummer(getContext(), LOG_TAG); getKoopman.setErkenningsnummer(mErkenningsnummer); getKoopman.enqueue(); } // destroy the loader when we are done (this only to prevent it from being called when // exiting the activity by navigating back to the dagvergunningen activity) getLoaderManager().destroyLoader(DAGVERGUNNING_LOADER); } }
From source file:com.money.manager.ex.adapter.AllDataAdapter.java
@SuppressWarnings({}) @Override//from www . j a v a2 s. c om public void bindView(View view, Context context, Cursor cursor) { // take a pointer of object UI LinearLayout linDate = (LinearLayout) view.findViewById(R.id.linearLayoutDate); TextView txtDay = (TextView) view.findViewById(R.id.textViewDay); TextView txtMonth = (TextView) view.findViewById(R.id.textViewMonth); TextView txtYear = (TextView) view.findViewById(R.id.textViewYear); TextView txtStatus = (TextView) view.findViewById(R.id.textViewStatus); TextView txtAmount = (TextView) view.findViewById(R.id.textViewAmount); TextView txtPayee = (TextView) view.findViewById(R.id.textViewPayee); TextView txtAccountName = (TextView) view.findViewById(R.id.textViewAccountName); TextView txtCategorySub = (TextView) view.findViewById(R.id.textViewCategorySub); TextView txtNotes = (TextView) view.findViewById(R.id.textViewNotes); TextView txtBalance = (TextView) view.findViewById(R.id.textViewBalance); // header index if (!mHeadersAccountIndex.containsKey(cursor.getInt(cursor.getColumnIndex(ACCOUNTID)))) { mHeadersAccountIndex.put(cursor.getInt(cursor.getColumnIndex(ACCOUNTID)), cursor.getPosition()); } // write status txtStatus.setText(mApplication.getStatusAsString(cursor.getString(cursor.getColumnIndex(STATUS)))); // color status int colorBackground = getBackgroundColorFromStatus(cursor.getString(cursor.getColumnIndex(STATUS))); linDate.setBackgroundColor(colorBackground); txtStatus.setTextColor(Color.GRAY); // date group try { Date date = new SimpleDateFormat("yyyy-MM-dd").parse(cursor.getString(cursor.getColumnIndex(DATE))); txtMonth.setText(new SimpleDateFormat("MMM").format(date)); txtYear.setText(new SimpleDateFormat("yyyy").format(date)); txtDay.setText(new SimpleDateFormat("dd").format(date)); } catch (ParseException e) { Log.e(AllDataAdapter.class.getSimpleName(), e.getMessage()); } // take transaction amount double amount = cursor.getDouble(cursor.getColumnIndex(AMOUNT)); // set currency id setCurrencyId(cursor.getInt(cursor.getColumnIndex(CURRENCYID))); // manage transfer and change amount sign if ((cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)) != null) && (Constants.TRANSACTION_TYPE_TRANSFER .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE))))) { if (getAccountId() != cursor.getInt(cursor.getColumnIndex(TOACCOUNTID))) { amount = -(amount); // -total } else if (getAccountId() == cursor.getInt(cursor.getColumnIndex(TOACCOUNTID))) { amount = cursor.getDouble(cursor.getColumnIndex(TOTRANSAMOUNT)); // to account = account setCurrencyId(cursor.getInt(cursor.getColumnIndex(TOCURRENCYID))); } } // check amount sign CurrencyUtils currencyUtils = new CurrencyUtils(mContext); txtAmount.setText(currencyUtils.getCurrencyFormatted(getCurrencyId(), amount)); // text color amount if (Constants.TRANSACTION_TYPE_TRANSFER .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)))) { txtAmount.setTextColor(Color.GRAY); } else if (Constants.TRANSACTION_TYPE_DEPOSIT .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE)))) { txtAmount.setTextColor(mCore.resolveColorAttribute(R.attr.holo_green_color_theme)); } else { txtAmount.setTextColor(mCore.resolveColorAttribute(R.attr.holo_red_color_theme)); } // compose payee description txtPayee.setText(cursor.getString(cursor.getColumnIndex(PAYEE))); // compose account name if (isShowAccountName()) { if (mHeadersAccountIndex.containsValue(cursor.getPosition())) { txtAccountName.setText(cursor.getString(cursor.getColumnIndex(ACCOUNTNAME))); txtAccountName.setVisibility(View.VISIBLE); } else { txtAccountName.setVisibility(View.GONE); } } else { txtAccountName.setVisibility(View.GONE); } // write ToAccountName if ((!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(TOACCOUNTNAME))))) { if (getAccountId() != cursor.getInt(cursor.getColumnIndex(TOACCOUNTID))) txtPayee.setText(cursor.getString(cursor.getColumnIndex(TOACCOUNTNAME))); else txtPayee.setText(cursor.getString(cursor.getColumnIndex(ACCOUNTNAME))); } // compose category description String categorySub = cursor.getString(cursor.getColumnIndex(CATEGORY)); // check sub category if (!(TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(SUBCATEGORY))))) { categorySub += " : <i>" + cursor.getString(cursor.getColumnIndex(SUBCATEGORY)) + "</i>"; } // write category/subcategory format html if (!TextUtils.isEmpty(categorySub)) { txtCategorySub.setText(Html.fromHtml(categorySub)); } else { txtCategorySub.setText(""); } // notes if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(NOTES)))) { txtNotes.setText( Html.fromHtml("<small>" + cursor.getString(cursor.getColumnIndex(NOTES)) + "</small>")); txtNotes.setVisibility(View.VISIBLE); } else { txtNotes.setVisibility(View.GONE); } // check if item is checked if (mCheckedPosition.get(cursor.getPosition(), false)) { view.setBackgroundResource(R.color.holo_blue_light); } else { view.setBackgroundResource(android.R.color.transparent); } // balance account or days left if (mTypeCursor == TypeCursor.ALLDATA) { if (isShowBalanceAmount() && getDatabase() != null) { int transId = cursor.getInt(cursor.getColumnIndex(ID)); // create thread for calculate balance amount BalanceAmount balanceAmount = new BalanceAmount(); balanceAmount.setAccountId(getAccountId()); balanceAmount.setDate(cursor.getString(cursor.getColumnIndex(DATE))); balanceAmount.setTextView(txtBalance); balanceAmount.setContext(mContext); balanceAmount.setDatabase(getDatabase()); balanceAmount.setTransId(transId); // execute thread balanceAmount.execute(); } else { txtBalance.setVisibility(View.GONE); } } else { int daysLeft = cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.DAYSLEFT)); if (daysLeft == 0) { txtBalance.setText(R.string.inactive); } else { txtBalance.setText(Integer.toString(Math.abs(daysLeft)) + " " + context.getString(daysLeft > 0 ? R.string.days_remaining : R.string.days_overdue)); } txtBalance.setVisibility(View.VISIBLE); } }
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
private void displayResult() { String[] projection = { TestTable.TABLE_TEST + "." + TestTable.COLUMN_ID, TestTable.TABLE_TEST + "." + TestTable.COLUMN_DATE, TestTable.COLUMN_RESULT, TestTable.COLUMN_TYPE, TestTable.COLUMN_FOLDER, LocationTable.COLUMN_NAME, LocationTable.COLUMN_STREET, LocationTable.COLUMN_TOWN, LocationTable.COLUMN_CITY, LocationTable.COLUMN_STATE, LocationTable.COLUMN_COUNTRY, LocationTable.COLUMN_STREET, LocationTable.COLUMN_SOURCE }; Log.d("Result", mId + " test"); Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null); cursor.moveToFirst();/*w w w. j a va 2 s . c om*/ mAddressText.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_NAME)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_STREET))); mAddress2Text.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_TOWN)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_CITY))); mAddress3Text.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_STATE)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_COUNTRY))); if (mAddress2Text.getText().equals(", ")) { mAddress2Text.setVisibility(View.GONE); } else { mAddress2Text.setVisibility(View.VISIBLE); } if (mAddress3Text.getText().equals(", ")) { mAddress3Text.setVisibility(View.GONE); } else { mAddress3Text.setVisibility(View.VISIBLE); } String[] sourceArray = getResources().getStringArray(R.array.source_types); int sourceType = cursor.getInt(cursor.getColumnIndex(LocationTable.COLUMN_SOURCE)); if (sourceType > -1) { mSourceText.setText(sourceArray[sourceType]); mSourceText.setVisibility(View.VISIBLE); } else { mSourceText.setVisibility(View.GONE); } Date date = new Date(cursor.getLong(cursor.getColumnIndex(TestTable.COLUMN_DATE))); SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy"); DateFormat tf = android.text.format.DateFormat.getTimeFormat(getActivity()); // Gets system TF String dateString = df.format(date.getTime()) + ", " + tf.format(date.getTime()); mTestType = DataHelper.getTestTitle(getActivity(), cursor.getInt(cursor.getColumnIndex(TestTable.COLUMN_TYPE))); mTestTypeId = cursor.getInt(cursor.getColumnIndex(TestTable.COLUMN_TYPE)); mTitleView.setText(mTestType); mDateView.setText(dateString); Double resultPpm = cursor.getDouble(cursor.getColumnIndex(TestTable.COLUMN_RESULT)); if (mTestTypeId == Globals.PH_INDEX) { mPpmText.setText(""); } else { mPpmText.setText(R.string.ppm); } if (resultPpm < 0) { mResultTextView.setText("0.0"); //mResultIcon.setVisibility(View.GONE); mPpmText.setVisibility(View.GONE); } else { mResultTextView.setText(String.format("%.2f", resultPpm)); Context context = getActivity().getApplicationContext(); int resourceAttribute; if (resultPpm <= Globals.FLUORIDE_MAX_DRINK) { resourceAttribute = R.attr.drink; } else if (resultPpm <= Globals.FLUORIDE_MAX_COOK) { resourceAttribute = R.attr.cook; } else if (resultPpm <= Globals.FLUORIDE_MAX_BATHE) { resourceAttribute = R.attr.bath; } else { resourceAttribute = R.attr.wash; } TypedArray a = context.getTheme().obtainStyledAttributes( ((MainApp) context.getApplicationContext()).CurrentTheme, new int[] { resourceAttribute }); int attributeResourceId = a.getResourceId(0, 0); //mResultIcon.setImageResource(attributeResourceId); //mResultIcon.setVisibility(View.VISIBLE); mPpmText.setVisibility(View.VISIBLE); } cursor.close(); }
From source file:cn.apputest.ctria.sql.DBManager.java
public InsuranceCardDataEntity queryInsuranceCard_Cargo(String PlateNumber) { Cursor c = queryTheCursorInsuranceCard_Cargo(PlateNumber); InsuranceCardDataEntity insurance = new InsuranceCardDataEntity(); while (c.moveToNext()) { String endTime = c.getString(c.getColumnIndex("INSURANCE_TIME")); if (StringUtils.isNotBlank(endTime)) { String a[] = endTime.split(","); endTime = a[1];/*from w ww. java 2 s. com*/ } insurance.setPlateNumber(c.getString(c.getColumnIndex("LICENSE_NUMBER"))); // insurance // .setEndDate(c.getString(c.getColumnIndex("INSURANCE_TIME"))); insurance.setInsuranceInfo("\n" + "?" + c.getString(c.getColumnIndex("LICENSE_NUMBER")) + "\n" + "???" + c.getString(c.getColumnIndex("ENGINE_NUMBER")) + "\n" + "?" + c.getString(c.getColumnIndex("SIGN_DATE")) + "\n" + "" + c.getString(c.getColumnIndex("POSTCODE")) + "\n" + "?" + c.getString(c.getColumnIndex("INSURED_PERSON")) + "\n" + "??" + c.getString(c.getColumnIndex("TELEPHONE_NUMBER")) + "\n" + "????" + c.getString(c.getColumnIndex("INSURANCE_COMPANY")) + "\n" + "?" + c.getString(c.getColumnIndex("UNDERWRITING")) + "\n" + "?" + c.getString(c.getColumnIndex("PREPARE_DOCUMENT")) + "\n" + "?" + c.getDouble(c.getColumnIndex("PREMIUM_FEE")) + "\n" + "????" + queryType(c.getInt(c.getColumnIndex("INSURANCE_SOLVE_WAY"))) + "\n" + "?" + c.getString(c.getColumnIndex("VERIFICATION_CODE")) + "\n" + "??" + c.getString(c.getColumnIndex("BUSINESS_ADDRESS")) + "\n" + "" + endTime + "\n" + "???" + c.getString(c.getColumnIndex("WARRANTY_NUMBER")) + "\n" + "??" + c.getString(c.getColumnIndex("SERVICE_TEL")) + "\n" + "???" + c.getString(c.getColumnIndex("DANGER_NAME")) + "\n" + "???" + c.getString(c.getColumnIndex("INSURER_ADDRESS")) + "\n" + "?" + c.getInt(c.getColumnIndex("RISK_CAR_COUNT")) + "\n" + "?" + c.getString(c.getColumnIndex("VIN")) + "\n" + "" + c.getString(c.getColumnIndex("FAX")) + "\n" + "??" + c.getString(c.getColumnIndex("TRANSMISSION_RANGE")) + "\n" + "?" + c.getString(c.getColumnIndex("HANDLE")) + "\n" + "" + c.getInt(c.getColumnIndex("CREATOR")) + "\n" + "" + c.getString(c.getColumnIndex("CREATE_TIME")) + "\n" + "\n"); } c.close(); return insurance; }
From source file:org.liberty.android.fantastischmemopro.DatabaseHelper.java
public Item getItemById(int id, int flag, boolean forward, String filter) { // These function are related to read db operation // flag = 0 means no condition // flag = 1 means new items, the items user have never seen // flag = 2 means item due, they need to be reviewed. // flag = 3 means items that is ahead of time // filter = null or filter = "": no filter // filter = #numA-#numB, items between numA and numB HashMap<String, String> hm = new HashMap<String, String>(); String query = "SELECT learn_tbl._id, date_learn, interval, grade, easiness, acq_reps, ret_reps, lapses, acq_reps_since_lapse, ret_reps_since_lapse, question, answer, note, category FROM dict_tbl INNER JOIN learn_tbl ON dict_tbl._id=learn_tbl._id WHERE dict_tbl._id " + (forward ? ">=" : "<=") + id + " "; if (flag == 1) { query += "AND acq_reps = 0 "; } else if (flag == 2) { query += "AND round((julianday(date('now', 'localtime')) - julianday(date_learn))) - interval >= 0 AND acq_reps > 0 "; } else if (flag == 3) { query = "SELECT learn_tbl._id, date_learn, interval, grade, easiness, acq_reps, ret_reps, lapses, acq_reps_since_lapse, ret_reps_since_lapse, question, answer, note, category FROM dict_tbl INNER JOIN learn_tbl ON dict_tbl._id=learn_tbl._id WHERE round((julianday(date('now', 'localtime')) - julianday(date_learn))) - interval < 0 AND acq_reps > 0 "; }//from w w w.j av a 2 s.c o m if (filter != null) { if (Pattern.matches("#\\d+-\\d+", filter)) { Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(filter); m.find(); String min = m.group(); m.find(); String max = m.group(); query += "AND learn_tbl._id >=" + min + " AND learn_tbl._id <= " + max + " "; } else if (Pattern.matches("#\\d+", filter)) { Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(filter); m.find(); String min = m.group(); query += "AND learn_tbl._id >= " + min + " "; } else if (!filter.equals("")) { /* Replace * and ? to % and _ used in SQL */ filter = filter.replace("*", "%"); filter = filter.replace("?", "_"); /* First remove white spaces at beginning */ String realFilter = filter.replaceAll("^\\s+", ""); String control = filter.length() >= 2 ? filter.substring(0, 2) : ""; /* Also remove the control text */ realFilter = realFilter.replaceAll("^%\\w\\s+", ""); Log.v(TAG, "Control " + control); Log.v(TAG, "Filter " + realFilter); if (control.equals("%q")) { query += "AND ((question LIKE '" + realFilter + "')) "; } else if (control.equals("%a")) { query += "AND ((answer LIKE '" + realFilter + "')) "; } else if (control.equals("%n")) { query += "AND ((note LIKE '" + realFilter + "')) "; } else if (control.equals("%c")) { query += "AND ((category LIKE '" + realFilter + "')) "; } else { query += "AND ((question LIKE '" + realFilter + "') OR (answer LIKE '" + realFilter + "') OR (note LIKE '" + realFilter + "') OR (category LIKE '" + realFilter + "')) "; } } } if (flag == 3) { query += "ORDER BY RANDOM() "; } else { query += "ORDER BY learn_tbl._id " + (forward ? "ASC " : "DESC "); } query += "LIMIT 1"; Cursor result; //result = myDatabase.query(true, "dict_tbl", null, querySelection, null, null, null, "_id", null); //result = myDatabase.query("dict_tbl", null, querySelection, null, null, null, "_id"); //result = myDatabase.query(true, "dict_tbl", null, querySelection, null, null, null, null, "1"); try { result = myDatabase.rawQuery(query, null); } catch (Exception e) { Log.e("Query item error", e.toString()); return null; } //System.out.println("The result is: " + result.getString(0)); //return result.getString(1); if (result.getCount() == 0) { result.close(); return null; } result.moveToFirst(); //int resultId = result.getInt(result.getColumnIndex("_id")); hm.put("_id", Integer.toString(result.getInt(result.getColumnIndex("_id")))); hm.put("question", result.getString(result.getColumnIndex("question"))); hm.put("answer", result.getString(result.getColumnIndex("answer"))); hm.put("note", result.getString(result.getColumnIndex("note"))); hm.put("category", result.getString(result.getColumnIndex("category"))); //querySelection = " _id = " + resultId; //result = myDatabase.query(true, "learn_tbl", null, querySelection, null, null, null, null, "1"); //if(result.getCount() == 0){ // return null; //} //result.moveToFirst(); hm.put("date_learn", result.getString(result.getColumnIndex("date_learn"))); hm.put("interval", Integer.toString(result.getInt(result.getColumnIndex("interval")))); hm.put("grade", Integer.toString(result.getInt(result.getColumnIndex("grade")))); hm.put("easiness", Double.toString(result.getDouble(result.getColumnIndex("easiness")))); hm.put("acq_reps", Integer.toString(result.getInt(result.getColumnIndex("acq_reps")))); hm.put("ret_reps", Integer.toString(result.getInt(result.getColumnIndex("ret_reps")))); hm.put("lapses", Integer.toString(result.getInt(result.getColumnIndex("lapses")))); hm.put("acq_reps_since_lapse", Integer.toString(result.getInt(result.getColumnIndex("acq_reps_since_lapse")))); hm.put("ret_reps_since_lapse", Integer.toString(result.getInt(result.getColumnIndex("ret_reps_since_lapse")))); result.close(); Item resultItem = new Item(); resultItem.setData(hm); return resultItem; }