List of usage examples for android.database Cursor getFloat
float getFloat(int columnIndex);
From source file:com.mobile.system.db.abatis.AbatisService.java
public Object parseToObject(Class beanClass, Cursor cur) throws IllegalAccessException, InstantiationException, SecurityException, NoSuchMethodException { Object obj = null;//from w w w. j ava 2 s. c o m Field[] props = beanClass.getDeclaredFields(); if (props == null || props.length == 0) { Log.d(TAG, "Class" + beanClass.getName() + " has no fields"); return null; } // Create instance of this Bean class obj = beanClass.newInstance(); // Set value of each member variable of this object for (int i = 0; i < props.length; i++) { String fieldName = props[i].getName(); if (props[i].getModifiers() == (Modifier.PUBLIC | Modifier.STATIC)) { continue; } Class type = props[i].getType(); String typeName = type.getName(); // Check for Custom type Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { int curIdx = cur.getColumnIndex(fieldName); if (curIdx != -1) { int nDotIdx = typeName.lastIndexOf("."); if (nDotIdx >= 0) { typeName = typeName.substring(nDotIdx); } if (typeName.equals("int")) { m.invoke(obj, cur.getInt(curIdx)); } else if (typeName.equals("double")) { m.invoke(obj, cur.getDouble(curIdx)); } else if (typeName.equals("String")) { m.invoke(obj, cur.getString(curIdx)); } else if (typeName.equals("long")) { m.invoke(obj, cur.getLong(curIdx)); } else if (typeName.equals("float")) { m.invoke(obj, cur.getFloat(curIdx)); } else if (typeName.equals("Date")) { m.invoke(obj, cur.getString(curIdx)); } else if (typeName.equals("byte[]") || typeName.equals("[B")) { m.invoke(obj, cur.getBlob(curIdx)); } else { m.invoke(obj, cur.getString(curIdx)); } } } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } return obj; }
From source file:com.upenn.chriswang1990.sunshine.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); //read city name and update String cityName = data.getString(COL_CITY_NAME); mCityNameView.setText(cityName); mCityNameView.setContentDescription(getString(R.string.a11y_city_name, cityName)); // Read date from cursor and update views for day of week and date long unixTimestamp = data.getLong(COL_WEATHER_DATE_UNIX); String timezoneID = data.getString(COL_TIMEZONE_ID); String dateText = Utility.getFullFriendlyDayString(getActivity(), unixTimestamp, timezoneID); mDateView.setText(dateText);//from ww w . ja va2 s.c o m // Read description from cursor and update view String description = 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 double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = 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 = 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(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(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()); forecastStr = String.format(getContext().getString(R.string.format_share_string), cityName, dateText, description, highString, lowString); 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 (activity instanceof DetailActivity) { 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.detail_fragment); finishCreatingMenu(toolbarView.getMenu()); } } } }
From source file:com.nadmm.airports.wx.WxCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor c) { ViewHolder holder = getViewHolder(view); String name = c.getString(c.getColumnIndex(Wxs.STATION_NAME)); if (name != null && !name.isEmpty()) { holder.stationName.setText(name); }/*ww w .j a v a2s .c o m*/ String stationId = c.getString(c.getColumnIndex(Wxs.STATION_ID)); holder.stationId.setText(stationId); view.setTag(R.id.TAG_STATION_ID, stationId); StringBuilder info = new StringBuilder(); String city = c.getString(c.getColumnIndex(Airports.ASSOC_CITY)); if (city != null && !city.isEmpty()) { info.append(city); } String state = c.getString(c.getColumnIndex(Airports.ASSOC_STATE)); if (state != null && !state.isEmpty()) { if (info.length() > 0) { info.append(", "); } info.append(state); } if (info.length() == 0) { info.append("Location not available"); } holder.stationInfo.setText(info.toString()); info.setLength(0); String freq = c.getString(c.getColumnIndex(Awos1.STATION_FREQUENCY)); if (freq == null || freq.length() == 0) { freq = c.getString(c.getColumnIndex(Awos1.SECOND_STATION_FREQUENCY)); } if (freq != null && freq.length() > 0) { try { info.append(FormatUtils.formatFreq(Float.valueOf(freq))); } catch (NumberFormatException e) { info.append(freq); } } holder.stationFreq.setText(info.toString()); info.setLength(0); String type = c.getString(c.getColumnIndex(Awos1.WX_SENSOR_TYPE)); if (type == null || type.length() == 0) { type = "ASOS/AWOS"; } info.append(type); info.append(", "); int elevation = c.getInt(c.getColumnIndex(Wxs.STATION_ELEVATOIN_METER)); info.append(FormatUtils.formatFeetMsl(DataUtils.metersToFeet(elevation))); holder.stationInfo2.setText(info.toString()); info.setLength(0); String phone = c.getString(c.getColumnIndex(Awos1.STATION_PHONE_NUMBER)); if (phone != null && phone.length() > 0) { info.append(phone); } holder.stationPhone.setText(info.toString()); info.setLength(0); if (c.getColumnIndex(LocationColumns.DISTANCE) >= 0 && c.getColumnIndex(LocationColumns.BEARING) >= 0) { float distance = c.getFloat(c.getColumnIndex(LocationColumns.DISTANCE)); float bearing = c.getFloat(c.getColumnIndex(LocationColumns.BEARING)); info.append(FormatUtils.formatNauticalMiles(distance)); info.append(" "); info.append(GeoUtils.getCardinalDirection(bearing)); holder.stationDistance.setText(info.toString()); holder.stationDistance.setVisibility(View.VISIBLE); } else { holder.stationDistance.setVisibility(View.GONE); } if (mStationWx != null) { Metar metar = mStationWx.get(stationId); showMetarInfo(view, c, metar); } }
From source file:fr.eoit.activity.util.StationListViewBinder.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); boolean isNull = cursor.isNull(columnIndex); TextView textView;/*from w ww .j a va 2 s.c om*/ ImageView imageView; String[] stationNameArray; double price; long volume; int role, stationId = cursor.getInt(cursor.getColumnIndexOrThrow(Station._ID)); switch (viewId) { case R.id.station_name: stationName = cursor.getString(columnIndex); textView = (TextView) view; stationNameArray = stationName.split(" - "); textView.setText(stationNameArray[stationNameArray.length - 1]); break; case R.id.location_name: String regionName = cursor.getString(columnIndex); textView = (TextView) view; stationNameArray = stationName.split(" - "); StringBuilder sb = new StringBuilder(regionName); if (stationNameArray.length == 2) { sb.append(" > ").append(stationNameArray[0]); } else if (stationNameArray.length == 3) { sb.append(" > ").append(stationNameArray[0]).append(" - ").append(stationNameArray[1]); } textView.setText(sb.toString()); break; case R.id.station_icon: int id = cursor.getInt(columnIndex); imageView = (ImageView) view; IconUtil.initRender(id, imageView); break; case R.id.favorite_station: boolean favorite = cursor.getInt(columnIndex) == 1; CheckBox favoriteCheckBox = (CheckBox) view; favoriteCheckBox.setChecked(favorite); favoriteCheckBox.setOnCheckedChangeListener( new FavoriteStationsOnCheckedChangeListener(stationId, favoriteCheckBox.getContext())); break; case R.id.station_prod_icon: role = cursor.getInt(columnIndex); imageView = (ImageView) view; if (role == EOITConst.Stations.TRADE_ROLE || isNull) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } break; case R.id.station_trade_icon: role = cursor.getInt(columnIndex); imageView = (ImageView) view; if (role == EOITConst.Stations.PRODUCTION_ROLE || isNull) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } break; case R.id.corp_standing: float standing = cursor.getFloat(columnIndex); textView = (TextView) view; textView.setText(nf.format(standing)); if (standing > 0) { textView.setTextColor(view.getResources().getColor(R.color.green)); } else if (standing == 0) { textView.setTextColor(view.getResources().getColor(R.color.grey)); } else if (standing < 0) { textView.setTextColor(view.getResources().getColor(R.color.red)); } break; case R.id.buy_price: case R.id.sell_price: price = cursor.getDouble(columnIndex); textView = (TextView) view; PricesUtils.setPrice(textView, price, true); break; case R.id.buy_volume: case R.id.sell_volume: volume = cursor.getLong(columnIndex); textView = (TextView) view; textView.setText(nfVolume.format(volume)); break; default: throw new IllegalArgumentException("viewId : " + viewId); } return true; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<QuizAttempt> getAllQuizAttempts() { ArrayList<QuizAttempt> quizAttempts = new ArrayList<QuizAttempt>(); Cursor c = db.query(QUIZATTEMPTS_TABLE, null, null, null, null, null, null); c.moveToFirst();//from w w w . j av a 2 s . c o m while (c.isAfterLast() == false) { QuizAttempt qa = new QuizAttempt(); qa.setId(c.getInt(c.getColumnIndex(QUIZATTEMPTS_C_ID))); qa.setActivityDigest(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_ACTIVITY_DIGEST))); qa.setData(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_DATA))); qa.setSent(Boolean.parseBoolean(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_SENT)))); qa.setCourseId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_COURSEID))); qa.setUserId(c.getLong(c.getColumnIndex(QUIZATTEMPTS_C_USERID))); qa.setScore(c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_SCORE))); qa.setMaxscore(c.getFloat(c.getColumnIndex(QUIZATTEMPTS_C_MAXSCORE))); qa.setPassed(Boolean.parseBoolean(c.getString(c.getColumnIndex(QUIZATTEMPTS_C_PASSED)))); quizAttempts.add(qa); c.moveToNext(); } c.close(); return quizAttempts; }
From source file:ru.arturvasilov.udacity.sunshinewatches.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); }//from w w w . j av a 2 s. co m // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(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 = Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); // Get description from weather condition ID String description = 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)); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = 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 = 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(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); if (activity.getSupportActionBar() != null) { 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:com.nadmm.airports.ActivityBase.java
public void showAirportTitle(Cursor c) { View root = findViewById(R.id.airport_title_layout); TextView tv = (TextView) root.findViewById(R.id.facility_name); String code = c.getString(c.getColumnIndex(Airports.ICAO_CODE)); if (code == null || code.length() == 0) { code = c.getString(c.getColumnIndex(Airports.FAA_CODE)); }//w w w . j a v a2 s.c om String tower = c.getString(c.getColumnIndex(Airports.TOWER_ON_SITE)); int color = tower.equals("Y") ? Color.rgb(48, 96, 144) : Color.rgb(128, 72, 92); tv.setTextColor(color); String name = c.getString(c.getColumnIndex(Airports.FACILITY_NAME)); String siteNumber = c.getString(c.getColumnIndex(Airports.SITE_NUMBER)); String type = DataUtils.decodeLandingFaclityType(siteNumber); tv.setText(String.format(Locale.US, "%s %s", name, type)); tv = (TextView) root.findViewById(R.id.facility_id); tv.setTextColor(color); tv.setText(code); tv = (TextView) root.findViewById(R.id.facility_info); String city = c.getString(c.getColumnIndex(Airports.ASSOC_CITY)); String state = c.getString(c.getColumnIndex(States.STATE_NAME)); if (state == null) { state = c.getString(c.getColumnIndex(Airports.ASSOC_COUNTY)); } tv.setText(String.format(Locale.US, "%s, %s", city, state)); tv = (TextView) root.findViewById(R.id.facility_info2); int distance = c.getInt(c.getColumnIndex(Airports.DISTANCE_FROM_CITY_NM)); String dir = c.getString(c.getColumnIndex(Airports.DIRECTION_FROM_CITY)); String status = c.getString(c.getColumnIndex(Airports.STATUS_CODE)); tv.setText(String.format(Locale.US, "%s, %d miles %s of city center", DataUtils.decodeStatus(status), distance, dir)); tv = (TextView) root.findViewById(R.id.facility_info3); float elev_msl = c.getFloat(c.getColumnIndex(Airports.ELEVATION_MSL)); int tpa_agl = c.getInt(c.getColumnIndex(Airports.PATTERN_ALTITUDE_AGL)); String est = ""; if (tpa_agl == 0) { tpa_agl = 1000; est = " (est.)"; } tv.setText(String.format(Locale.US, "%s MSL elev. - %s MSL TPA %s", FormatUtils.formatFeet(elev_msl), FormatUtils.formatFeet(elev_msl + tpa_agl), est)); String s = c.getString(c.getColumnIndex(Airports.EFFECTIVE_DATE)); GregorianCalendar endDate = new GregorianCalendar(Integer.valueOf(s.substring(6)), Integer.valueOf(s.substring(3, 5)), Integer.valueOf(s.substring(0, 2))); // Calculate end date of the 56-day cycle endDate.add(GregorianCalendar.DAY_OF_MONTH, 56); Calendar now = Calendar.getInstance(); if (now.after(endDate)) { // Show the expired warning tv = (TextView) root.findViewById(R.id.expired_label); tv.setVisibility(View.VISIBLE); } CheckBox cb = (CheckBox) root.findViewById(R.id.airport_star); cb.setChecked(mDbManager.isFavoriteAirport(siteNumber)); cb.setTag(siteNumber); cb.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CheckBox cb = (CheckBox) v; String siteNumber = (String) cb.getTag(); if (cb.isChecked()) { mDbManager.addToFavoriteAirports(siteNumber); Toast.makeText(ActivityBase.this, "Added to favorites list", Toast.LENGTH_LONG).show(); } else { mDbManager.removeFromFavoriteAirports(siteNumber); Toast.makeText(ActivityBase.this, "Removed from favorites list", Toast.LENGTH_LONG).show(); } } }); ImageView iv = (ImageView) root.findViewById(R.id.airport_map); String lat = c.getString(c.getColumnIndex(Airports.REF_LATTITUDE_DEGREES)); String lon = c.getString(c.getColumnIndex(Airports.REF_LONGITUDE_DEGREES)); if (lat.length() > 0 && lon.length() > 0) { iv.setTag("geo:" + lat + "," + lon + "?z=16"); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String tag = (String) v.getTag(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tag)); startActivity(intent); } }); } else { iv.setVisibility(View.GONE); } }
From source file:com.example.barni.sunshine.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); }//from w w w .j a v a 2 s. c o m // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(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 = Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); // Get description from weather condition ID String description = 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 = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = 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 = 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(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 (activity instanceof DetailActivity) { 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:com.example.weather.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); }/*from w ww . j av a2 s .c o m*/ // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(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 = Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); // Get description from weather condition ID String description = 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 = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = 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 = 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(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:com.appniche.android.sunshine.app.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 a v a 2s.co m*/ // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(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 = Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); // Get description from weather condition ID String description = 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 = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = 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 = 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(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()); } } }