This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These two need to be declared outside the try/catch | |
// so that they can be closed in the finally block. | |
HttpURLConnection urlConnection = null; | |
BufferedReader reader = null; | |
// Will contain the raw JSON response as a string. | |
String forecastJsonStr = null; | |
try { | |
// Construct the URL for the OpenWeatherMap query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String FORECAST_BASE_URL = | |
+ "http://api.openweathermap.org/data/2.5/forecast/daily?"; | |
+ final String QUERY_PARAM = "q"; | |
+ final String FORMAT_PARAM = "mode"; | |
+ final String UNITS_PARAM = "units"; | |
+ final String DAYS_PARAM = "cnt"; | |
+ final String APPID_PARAM = "APPID"; | |
+ | |
+ Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon() | |
+ .appendQueryParameter(QUERY_PARAM, params[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The date/time conversion code is going to be moved outside the asynctask later, | |
* so for convenience we're breaking it out into its own method now. | |
*/ | |
private String getReadableDateString(long time){ | |
// Because the API returns a unix timestamp (measured in seconds), | |
// it must be converted to milliseconds in order to be converted to valid date. | |
SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd"); | |
return shortenedDateFormat.format(time); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onPostExecute(String[] result) { | |
if(result != null) { | |
mForecastAdapter.clear(); | |
for (String dayForecastStr : result) { | |
mForecastAdapter.add(dayForecastStr); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2014 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2014 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Date format for displaying day of week and date (i.e. Mon Jun 1) [CHAR LIMIT=20] --> | |
<string name="format_full_friendly_date"><xliff:g id="day">%1$s</xliff:g>, <xliff:g id="date">%2$s</xliff:g></string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Format used for storing dates in the database. ALso used for converting those strings | |
// back into date objects for comparison/processing. | |
public static final String DATE_FORMAT = "yyyyMMdd"; | |
/** | |
* Helper method to convert the database representation of the date into something to display | |
* to users. As classy and polished a user experience as "20140102" is, we can do better. | |
* | |
* @param context Context to use for resource localization | |
* @param dateInMillis The date in milliseconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="format_temperature"><xliff:g id="temp">%1.0f</xliff:g>\u00B0</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void getRegionsList() { | |
Log.d("mtender", "ProfilePresenter > getRegionsList"); | |
final LinkedHashMap<Integer, List<SpinnerItem>> regionsWithCities = new LinkedHashMap<>(); | |
final List<SpinnerItem> regionsList = new ArrayList<>(); | |
String USER_REGIONS_URL = "http://46.101.144.46/frontend/web/api/v1/region/list"; | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() |
OlderNewer