List of usage examples for android.database Cursor getFloat
float getFloat(int columnIndex);
From source file:com.example.bryan.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); }//from ww w . j a v 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(WeatherIconUtility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(WeatherIconUtility.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.clough.android.androiddbviewer.ADBVApplication.java
@Override public void onCreate() { super.onCreate(); // Getting user configured(custom) SQLiteOpenHelper instance. sqliteOpenHelper = getDataBase();// www . j a v a 2s . c o m // getDataBase() could return a null if (sqliteOpenHelper != null) { // Background operation of creating the server socket. new Thread(new Runnable() { @Override public void run() { try { // Server socket re create when device is being disconnected or // when AndroidDBViewer desktop application is being closed. // Creating server socket will exit when // android application runs in low memory or when // android application being terminated due some reasons. l1: while (flag) { serverSocket = new ServerSocket(1993); socket = serverSocket.accept(); br = new BufferedReader(new InputStreamReader(socket.getInputStream())); pw = new PrintWriter(socket.getOutputStream(), true); // Keeps a continuous communication between android application and // AndroidDBViewer desktop application through IO streams of the accepted socket connection. // There will be continuous data parsing between desktop application and android application. // Identification of device being disconnected or desktop application being closed will be determined // only when there is a NULL data being received. l2: while (flag) { // Format of the parsing data string is JSON, a content of a 'Data' instance String requestJSONString = br.readLine(); if (requestJSONString == null) { // Received a null response from desktop application, due to disconnecting the // device or closing the AndroidDBViewer desktop application. // Therefore, closing all current connections and streams to re create the server // socket so that desktop application can connect in it's next run. // Device disconnection doesn't produce an IOException. // Also, even after calling // socket.close(), socket.shutdownInput() and socket.shutdownOutput() // within a shutdown hook in desktop application, the socket connection // in this async task always gives // socket.isConnected() as 'true' , // socket.isClosed() as 'false' , // socket.isInputShutdown() as 'false' and // socket.isOutputShutdown() as 'false' . // But, bufferedReader.readLine() starts returning 'null' continuously. // So, inorder to desktop application to connect with the device again, // there should be a ServerSocket waiting to accept a socket connection, in device. closeConnection(); continue l1; } else { // Received a valid response from the desktop application. Data data; try { // Converting received request to a 'Data' instance. data = new Data(new JSONObject(requestJSONString)); int status = data.getStatus(); if (status == Data.CONNECTION_REQUEST) { // Very first request from desktop application to // establish the connection and setting the response as // connection being accepted. data.setStatus(Data.CONNECTION_ACCEPTED); } else if (status == Data.LIVE_CONNECTION) { // When there is no user interaction in desktop application, // data being passed from desktop application to android // application with the status of LIVE_CONNECTION, and the // same data send again to the desktop application from android application, // to notify that connection is still alive. // This exchange won't change until there is a request from // desktop application with a different status. } else if (status == Data.QUERY) { // Requesting to perform a query execution. String result = "No result"; try { // Performing select, insert, delete and update queries. Cursor cursor = sqliteOpenHelper.getWritableDatabase() .rawQuery(data.getQuery(), null); // Flag to identify the firs move of the cursor boolean firstTime = true; int columnCount = 0; // JSONArray to hold the all JSONObjects, created per every row // of the result returned, executing the given query. JSONArray jsonArray = new JSONArray(); // Moving the cursor to the next row of retrieved result // after executing the requested query. while (cursor.moveToNext()) { if (firstTime) { // Column count of the result returned, executing the given query. columnCount = cursor.getColumnCount(); firstTime = false; } // JOSNObject to hold the values of a single row JSONObject jsonObject = new JSONObject(); for (int i = 0; i < columnCount; i++) { int columnType = cursor.getType(i); String columnName = cursor.getColumnName(i); if (columnType == Cursor.FIELD_TYPE_STRING) { jsonObject.put(columnName, cursor.getString(i)); } else if (columnType == Cursor.FIELD_TYPE_BLOB) { jsonObject.put(columnName, cursor.getBlob(i).toString()); } else if (columnType == Cursor.FIELD_TYPE_FLOAT) { jsonObject.put(columnName, String.valueOf(cursor.getFloat(i))); } else if (columnType == Cursor.FIELD_TYPE_INTEGER) { jsonObject.put(columnName, String.valueOf(cursor.getInt(i))); } else if (columnType == Cursor.FIELD_TYPE_NULL) { jsonObject.put(columnName, "NULL"); } else { jsonObject.put(columnName, "invalid type"); } } jsonArray.put(jsonObject); } result = jsonArray.toString(); cursor.close(); } catch (Exception e) { // If SQL error is occurred when executing the requested query, // error content will be the response to the desktop application. StringWriter sw = new StringWriter(); PrintWriter epw = new PrintWriter(sw); e.printStackTrace(epw); result = sw.toString(); epw.close(); sw.close(); } finally { data.setResult(result); } } else if (status == Data.DEVICE_NAME) { // Requesting device information data.setResult(Build.BRAND + " " + Build.MODEL); } else if (status == Data.APPLICATION_ID) { // Requesting application id (package name) data.setResult(getPackageName()); } else if (status == Data.DATABASE_NAME) { // Requesting application database name. // Will provide the database name according // to the SQLiteOpenHelper user provided data.setResult(sqliteOpenHelper.getDatabaseName()); } else { // Unidentified request state. closeConnection(); continue l1; } String responseJSONString = data.toJSON().toString(); pw.println(responseJSONString); } catch (JSONException e) { // Response couldn't convert to a 'Data' instance. // Desktop application will be notified to close the application. closeConnection(); continue l1; } } } } } catch (IOException e) { // Cannot create a server socket. Letting background process to end. } } }).start(); } }
From source file:com.alboteanu.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); }/*from w w w .j a v a 2s . c om*/ // 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); //orig String description = data.getString(COL_WEATHER_DESC); //eu 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()); } } /* adRequest = new AdRequest.Builder() .addTestDevice(getString(R.string.test_device)) .build(); adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); adView.setVisibility(View.VISIBLE); } }); adView.loadAd(adRequest);*/ getView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mInterstitial == null) mInterstitial = Utility.requestNewInterstitial(getActivity()); else if (mInterstitial.isLoaded()) mInterstitial.show(); } }); }
From source file:org.mythtv.android.player.app.loaders.VideosTvSeriesAsyncTaskLoader.java
private Video convertCursorToVideo(Cursor cursor) { Video video = new Video(); video.setId(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_ID))); video.setTitle(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_TITLE))); if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SUB_TITLE) != -1) { video.setSubTitle(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SUB_TITLE))); }//from w ww . java 2 s. co m if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_TAGLINE) != -1) { video.setTagline(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_TAGLINE))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_DIRECTOR) != -1) { video.setDirector(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_DIRECTOR))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_STUDIO) != -1) { video.setStudio(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_STUDIO))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_DESCRIPTION) != -1) { video.setDescription(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_DESCRIPTION))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_CERTIFICATION) != -1) { video.setCertification( cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_CERTIFICATION))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_INETREF) != -1) { video.setInetref(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_INETREF))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_COLLECTIONREF) != -1) { video.setCollectionref(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_COLLECTIONREF))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_HOMEPAGE) != -1) { video.setHomePage(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_HOMEPAGE))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_RELEASE_DATE) != -1) { video.setReleaseDate( new DateTime(cursor.getLong(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_RELEASE_DATE)))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_ADD_DATE) != -1) { video.setAddDate( new DateTime(cursor.getLong(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_ADD_DATE)))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_USER_RATING) != -1) { video.setUserRating(cursor.getFloat(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_USER_RATING))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_LENGTH) != -1) { video.setLength(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_LENGTH))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PLAY_COUNT) != -1) { video.setPlayCount(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PLAY_COUNT))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SEASON) != -1) { video.setSeason(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SEASON))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_EPISODE) != -1) { video.setEpisode(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_EPISODE))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PARENTAL_LEVEL) != -1) { video.setParentalLevel(cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PARENTAL_LEVEL))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_VISIBLE) != -1) { video.setVisible( cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_VISIBLE)) == 0 ? Boolean.FALSE : Boolean.TRUE); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_WATCHED) != -1) { video.setWatched( cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_WATCHED)) == 0 ? Boolean.FALSE : Boolean.TRUE); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PROCESSED) != -1) { video.setProcessed( cursor.getInt(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_PROCESSED)) == 0 ? Boolean.FALSE : Boolean.TRUE); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_CONTENT_TYPE) != -1) { video.setContentType(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_CONTENT_TYPE))); } video.setFilePath(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_FILEPATH))); video.setFileName(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_FILENAME))); if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_HASH) != -1) { video.setHash(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_HASH))); } video.setHostName(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_HOSTNAME))); if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_COVERART) != -1) { video.setCoverart(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_COVERART))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_FANART) != -1) { video.setFanart(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_FANART))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_BANNER) != -1) { video.setBanner(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_BANNER))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SCREENSHOT) != -1) { video.setScreenshot(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SCREENSHOT))); } if (cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SCREENSHOT) != -1) { video.setTrailer(cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_VIDEO_SCREENSHOT))); } String castMembers = cursor.getString(cursor.getColumnIndex(VideoConstants.FIELD_CAST_MEMBER_NAMES)); if (null != castMembers && !"".equals(castMembers)) { List<CastMember> castMemberNames = new ArrayList<>(); StringTokenizer st = new StringTokenizer(castMembers, "|"); while (st.hasMoreTokens()) { CastMember member = new CastMember(); member.setName(st.nextToken()); castMemberNames.add(member); } video.setCastMembers(castMemberNames); } return video; }
From source file:com.harlie.android.sunshine.app.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (getView() != null) { if (data != null && data.moveToFirst()) { ViewParent vp = getView().getParent(); if (vp != null) { if (vp instanceof CardView) { ((View) vp).setVisibility(View.VISIBLE); }//from ww w.jav a 2 s . c o m } // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics()) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this).load(Utility.getArtUrlForWeatherCondition(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(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 @SuppressWarnings("UnusedAssignment") boolean isMetric = Utility.isMetric(); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(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(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 != null) { activity.supportStartPostponedEnterTransition(); if (null != toolbarView && null != activity.getSupportActionBar()) { 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.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); }/*w ww . j a v 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:com.aware.utils.WebserviceHelper.java
@Override protected void onHandleIntent(Intent intent) { WEBSERVER = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER); DEVICE_ID = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID); DEBUG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true"); DATABASE_TABLE = intent.getStringExtra(EXTRA_TABLE); TABLES_FIELDS = intent.getStringExtra(EXTRA_FIELDS); CONTENT_URI = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI)); //Fixed: not using webservices if (WEBSERVER.length() == 0) return;/*from w w w .ja v a2 s . c om*/ if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_SYNC_TABLE)) { //Check if we should do this only over Wi-Fi boolean wifi_only = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY) .equals("true"); if (wifi_only) { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo active_network = cm.getActiveNetworkInfo(); if (active_network != null && active_network.getType() != ConnectivityManager.TYPE_WIFI) { if (DEBUG) { Log.i("AWARE", "User not connected to Wi-Fi, skipping data sync."); } return; } } //Check first if we have database table remotely, otherwise create it! ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>(); fields.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); fields.add(new BasicNameValuePair(EXTRA_FIELDS, TABLES_FIELDS)); //Create table if doesn't exist on the remote webservice server HttpResponse response = new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/create_table", fields); if (response != null && response.getStatusLine().getStatusCode() == 200) { if (DEBUG) { HttpResponse copy = response; try { if (DEBUG) Log.d(Aware.TAG, EntityUtils.toString(copy.getEntity())); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } String[] columnsStr = new String[] {}; Cursor columnsDB = getContentResolver().query(CONTENT_URI, null, null, null, null); if (columnsDB != null && columnsDB.moveToFirst()) { columnsStr = columnsDB.getColumnNames(); if (DEBUG) Log.d(Aware.TAG, "Total records on " + DATABASE_TABLE + ": " + columnsDB.getCount()); } if (columnsDB != null && !columnsDB.isClosed()) columnsDB.close(); try { ArrayList<NameValuePair> request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); //check the latest entry in remote database HttpResponse latest = new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/latest", request); if (latest == null) return; String data = "[]"; try { data = EntityUtils.toString(latest.getEntity()); } catch (IllegalStateException e) { Log.d(Aware.TAG, "Unable to connect to webservices..."); } if (DEBUG) { Log.d(Aware.TAG, "Webservice response: " + data); } //If in a study, get from joined date onwards String study_condition = ""; if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0 && Aware.getSetting(getApplicationContext(), "study_start").length() > 0) { String study_start = Aware.getSetting(getApplicationContext(), "study_start"); study_condition = " AND timestamp > " + Long.parseLong(study_start); } if (DATABASE_TABLE.equalsIgnoreCase("aware_device")) study_condition = ""; JSONArray remoteData = new JSONArray(data); Cursor context_data; if (remoteData.length() == 0) { if (exists(columnsStr, "double_end_timestamp")) { context_data = getContentResolver().query(CONTENT_URI, null, "double_end_timestamp != 0" + study_condition, null, "timestamp ASC"); } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { context_data = getContentResolver().query(CONTENT_URI, null, "double_esm_user_answer_timestamp != 0" + study_condition, null, "timestamp ASC"); } else { context_data = getContentResolver().query(CONTENT_URI, null, "1" + study_condition, null, "timestamp ASC"); } } else { long last = 0; if (exists(columnsStr, "double_end_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_end_timestamp"); context_data = getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition, null, "timestamp ASC"); } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp"); context_data = getContentResolver().query( CONTENT_URI, null, "timestamp > " + last + " AND double_esm_user_answer_timestamp != 0" + study_condition, null, "timestamp ASC"); } else { last = remoteData.getJSONObject(0).getLong("timestamp"); context_data = getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + study_condition, null, "timestamp ASC"); } } JSONArray context_data_entries = new JSONArray(); if (context_data != null && context_data.moveToFirst()) { if (DEBUG) Log.d(Aware.TAG, "Uploading " + context_data.getCount() + " from " + DATABASE_TABLE); do { JSONObject entry = new JSONObject(); String[] columns = context_data.getColumnNames(); for (String c_name : columns) { //Skip local database ID if (c_name.equals("_id")) continue; if (c_name.equals("timestamp") || c_name.contains("double")) { entry.put(c_name, context_data.getDouble(context_data.getColumnIndex(c_name))); } else if (c_name.contains("float")) { entry.put(c_name, context_data.getFloat(context_data.getColumnIndex(c_name))); } else if (c_name.contains("long")) { entry.put(c_name, context_data.getLong(context_data.getColumnIndex(c_name))); } else if (c_name.contains("blob")) { entry.put(c_name, context_data.getBlob(context_data.getColumnIndex(c_name))); } else if (c_name.contains("integer")) { entry.put(c_name, context_data.getInt(context_data.getColumnIndex(c_name))); } else { entry.put(c_name, context_data.getString(context_data.getColumnIndex(c_name))); } } context_data_entries.put(entry); if (context_data_entries.length() == 1000) { request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); request.add(new BasicNameValuePair("data", context_data_entries.toString())); new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request); context_data_entries = new JSONArray(); } } while (context_data.moveToNext()); if (context_data_entries.length() > 0) { request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); request.add(new BasicNameValuePair("data", context_data_entries.toString())); new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request); } } else { if (DEBUG) Log.d(Aware.TAG, "Nothing new in " + DATABASE_TABLE + "!" + " URI=" + CONTENT_URI.toString()); } if (context_data != null && !context_data.isClosed()) context_data.close(); } catch (ParseException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } //Clear database table remotely if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_CLEAR_TABLE)) { ArrayList<NameValuePair> request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); new Https(getApplicationContext()).dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/clear_table", request); } }
From source file:com.gelakinetic.mtgfam.helpers.ResultListAdapter.java
/** * Binds all of the field names passed into the "to" parameter of the constructor with their corresponding cursor * columns as specified in the "from" parameter. Binding occurs in two phases. First, if a * SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) is * invoked. If the returned value is true, binding has occurred. If the returned value is false and the view to bind * is a TextView, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is * an ImageView, setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an * IllegalStateException is thrown.//from w w w.j a v a 2 s .co m * * @param view Existing view, returned earlier by newView * @param context Interface to application's global information * @param cursor The cursor from which to get the data. The cursor is already moved to the correct position. */ @Override public void bindView(@NotNull View view, Context context, @NotNull Cursor cursor) { boolean hideCost = true; boolean hideSet = true; boolean hideType = true; boolean hideAbility = true; boolean hidePT = true; boolean hideLoyalty = true; boolean hideRarity = true; /* make sure these elements are showing (views get recycled) */ view.findViewById(R.id.cardp).setVisibility(View.VISIBLE); view.findViewById(R.id.cardslash).setVisibility(View.VISIBLE); view.findViewById(R.id.cardt).setVisibility(View.VISIBLE); /* Iterate through the mFrom, find the appropriate view in mTo */ for (int i = 0; i < mFrom.length; i++) { TextView textField = (TextView) view.findViewById(mTo[i]); switch (mFrom[i]) { case CardDbAdapter.KEY_NAME: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); textField.setText(name); break; } case CardDbAdapter.KEY_MANACOST: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideCost = false; CharSequence csq = ImageGetterHelper.formatStringWithGlyphs(name, mImgGetter); textField.setText(csq); break; } case CardDbAdapter.KEY_SET: { char rarity = (char) cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_RARITY)); String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideSet = false; textField.setText(name); switch (rarity) { case 'c': case 'C': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_common))); break; case 'u': case 'U': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_uncommon))); break; case 'r': case 'R': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_rare))); break; case 'm': case 'M': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_mythic))); break; case 't': case 'T': textField.setTextColor( ContextCompat.getColor(context, getResourceIdFromAttr(R.attr.color_timeshifted))); break; } break; } case CardDbAdapter.KEY_RARITY: { char rarity = (char) cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_RARITY)); textField.setText("(" + rarity + ")"); hideRarity = false; break; } case CardDbAdapter.KEY_SUPERTYPE: { String name = CardDbAdapter.getTypeLine(cursor); hideType = false; textField.setText(name); break; } case CardDbAdapter.KEY_ABILITY: { String name = cursor.getString(cursor.getColumnIndex(mFrom[i])); hideAbility = false; CharSequence csq = ImageGetterHelper.formatStringWithGlyphs(name, mImgGetter); textField.setText(csq); break; } case CardDbAdapter.KEY_POWER: float p = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (p != CardDbAdapter.NO_ONE_CARES) { String pow; hidePT = false; if (p == CardDbAdapter.STAR) pow = "*"; else if (p == CardDbAdapter.ONE_PLUS_STAR) pow = "1+*"; else if (p == CardDbAdapter.TWO_PLUS_STAR) pow = "2+*"; else if (p == CardDbAdapter.SEVEN_MINUS_STAR) pow = "7-*"; else if (p == CardDbAdapter.STAR_SQUARED) pow = "*^2"; else if (p == CardDbAdapter.X) pow = "X"; else { if (p == (int) p) { pow = Integer.valueOf((int) p).toString(); } else { pow = Float.valueOf(p).toString(); } } textField.setText(pow); } break; case CardDbAdapter.KEY_TOUGHNESS: float t = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (t != CardDbAdapter.NO_ONE_CARES) { hidePT = false; String tou; if (t == CardDbAdapter.STAR) tou = "*"; else if (t == CardDbAdapter.ONE_PLUS_STAR) tou = "1+*"; else if (t == CardDbAdapter.TWO_PLUS_STAR) tou = "2+*"; else if (t == CardDbAdapter.SEVEN_MINUS_STAR) tou = "7-*"; else if (t == CardDbAdapter.STAR_SQUARED) tou = "*^2"; else if (t == CardDbAdapter.X) tou = "X"; else { if (t == (int) t) { tou = Integer.valueOf((int) t).toString(); } else { tou = Float.valueOf(t).toString(); } } textField.setText(tou); } break; case CardDbAdapter.KEY_LOYALTY: float l = cursor.getFloat(cursor.getColumnIndex(mFrom[i])); if (l != CardDbAdapter.NO_ONE_CARES) { hideLoyalty = false; if (l == CardDbAdapter.X) { ((TextView) textField.findViewById(R.id.cardt)).setText("X"); } else if (l == (int) l) { ((TextView) textField.findViewById(R.id.cardt)).setText(Integer.toString((int) l)); } else { ((TextView) textField.findViewById(R.id.cardt)).setText(Float.toString(l)); } } break; } } /* Hide the fields if they should be hidden (didn't exist in mTo)*/ if (hideCost) { view.findViewById(R.id.cardcost).setVisibility(View.GONE); } if (hideSet) { view.findViewById(R.id.cardset).setVisibility(View.GONE); } if (hideType) { view.findViewById(R.id.cardtype).setVisibility(View.GONE); } if (hideAbility) { view.findViewById(R.id.cardability).setVisibility(View.GONE); } if (!hideLoyalty) { view.findViewById(R.id.cardp).setVisibility(View.GONE); view.findViewById(R.id.cardslash).setVisibility(View.GONE); } else if (hidePT) { view.findViewById(R.id.cardp).setVisibility(View.GONE); view.findViewById(R.id.cardslash).setVisibility(View.GONE); view.findViewById(R.id.cardt).setVisibility(View.GONE); } if (hideRarity) { view.findViewById(R.id.rarity).setVisibility(View.GONE); } }
From source file:inforuh.eventfinder.ui.DetailActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data == null) { return;//from w w w . j a v a2 s . c o m } if (data.moveToFirst()) { String title = data.getString(Event.TITLE); collapsingToolbar.setTitle(""); eventTitle.setText(title); eventContent.setText(Html.fromHtml(data.getString(Event.CONTENT))); Glide.with(this).load(data.getString(Event.IMAGE)).diskCacheStrategy(DiskCacheStrategy.SOURCE) .centerCrop().into(eventImage); String startDate = data.getString(Event.START_DATE); String endDate = data.getString(Event.END_DATE); Date startDateFormat = Config.parseDate(startDate, TimeZone.getDefault()); Date endDateFormat = Config.parseDate(endDate, TimeZone.getDefault()); Calendar startCal = Calendar.getInstance(); Calendar endCal = Calendar.getInstance(); startCal.setTime(startDateFormat); endCal.setTime(endDateFormat); int startMonth = startCal.get(Calendar.MONTH); int startDateInWeek = startCal.get(Calendar.DAY_OF_MONTH); int startYear = startCal.get(Calendar.YEAR); int endMonth = endCal.get(Calendar.MONTH); int endDateInWeek = endCal.get(Calendar.DAY_OF_MONTH); int endYear = endCal.get(Calendar.YEAR); String completeDate; if (getResources().getConfiguration().locale.getDisplayName().equals(Locale.US.getDisplayName())) { String formattedStartDate = Config.formatMonth(this, startMonth) + " " + Config.formatDate(this, startDateInWeek) + ", " + startYear; String formattedEndDate = Config.formatMonth(this, endMonth) + " " + Config.formatDate(this, endDateInWeek) + ", " + endYear; completeDate = formattedStartDate + " - " + formattedEndDate; } else { String formattedStartDate = Config.formatDate(this, startDateInWeek) + " " + Config.formatMonth(this, startMonth) + " " + startYear; String formattedEndDate = Config.formatDate(this, endDateInWeek) + " " + Config.formatMonth(this, endMonth) + " " + endYear; completeDate = formattedStartDate + " - " + formattedEndDate; } eventDate.setText(completeDate); String location = data.getString(Event.LOCATION); eventLocation.setText(location); String price = getString(R.string.ticket_price).toUpperCase() + " " + data.getString(Event.PRICE).toUpperCase(); eventPrice.setText(price); String name = data.getString(Event.ORGANIZER); contactName.setText(name); String contact = data.getString(Event.CONTACT_MAIN); contactMain.setText(contact); String twitter = "Twitter: " + data.getString(Event.CONTACT_TWITTER); contactTwitter.setText(twitter); String facebook = "Facebook: " + data.getString(Event.CONTACT_FACEBOOK); contactFacebook.setText(facebook); String line = "Line: " + data.getString(Event.CONTACT_LINE); contactLine.setText(line); String instagram = "Instagram: " + data.getString(Event.CONTACT_INSTAGRAM); contactInstagram.setText(instagram); String path = "Path: " + data.getString(Event.CONTACT_PATH); contactPath.setText(path); String url = data.getString(Event.URL); shareMessage = title + ", " + completeDate + ", " + url + " #eventfinderid"; Glide.with(this).load(data.getString(Event.BARCODE)).diskCacheStrategy(DiskCacheStrategy.SOURCE) .centerCrop().into(eventBarcode); if (googleMap != null) { setUpEventLocation(data.getDouble(Event.LONGITUDE), data.getDouble(Event.LATITUDE), data.getFloat(Event.MAP_ZOOM)); } } }
From source file:de.sindzinski.wetter.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); // 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); // } if (Utility.getProvider(getActivity()).equals(this.getString(R.string.pref_provider_wug))) { String icon = data.getString(COL_WEATHER_ICON); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String artPack = prefs.getString(this.getString(R.string.pref_art_pack_wug_key), this.getString(R.string.pref_art_pack_wug_alt_black)); Glide.with(this).load(String.format(Locale.US, artPack, icon)) //.error(defaultImage) .crossFade().into(mIconView); } else {/*from www .j ava 2s .c om*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String artPack = prefs.getString(this.getString(R.string.pref_art_pack_key), this.getString(R.string.pref_art_pack_sunshine)); if (artPack.equals(this.getString(R.string.pref_art_pack_owm))) { String icon = data.getString(COL_WEATHER_ICON); Glide.with(this).load(String.format(Locale.US, artPack, icon)) // .error(defaultImage) .crossFade().into(mIconView); } else if (artPack.equals(this.getString(R.string.pref_art_pack_cute_dogs))) { Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) // .error(defaultImage) .crossFade().into(mIconView); } else { // local images mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } } // Read date from cursor and update views for day of week and date long date = data.getLong(COL_WEATHER_DATE); String timeZoneName = data.getString(COL_TIME_ZONE); String friendlyDateText = Utility.getDailyDayString(getActivity(), date, timeZoneName); String dateText = Utility.getFormattedMonthDay(getActivity(), date, timeZoneName); mFriendlyDateView.setText(friendlyDateText); mDateView.setText(dateText); // Read description from cursor and update view String description = data.getString(COL_WEATHER_DESC); mDescriptionView.setText(description); // For accessibility, add a content description to the icon field mIconView.setContentDescription(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, isMetric); mHighTempView.setText(highString); // Read low temperature from cursor and update view double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low, isMetric); mLowTempView.setText(lowString); // Read humidity from cursor and update view float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); // 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)); // Read pressure from cursor and update view float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure)); // We still need this for the share intent mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); // If onCreateOptionsMenu has already happened, we need to update the share intent now. if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareForecastIntent()); } } }