diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c6cbe56
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+*.iml
+.gradle
+/local.properties
+/.idea/workspace.xml
+/.idea/libraries
+.DS_Store
+/build
+/captures
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..90b2abe
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+Retofit2Example
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..9a8b7e5
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
new file mode 100644
index 0000000..e7bedf3
--- /dev/null
+++ b/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..cd2ead8
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..f976130
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Android Lint
+
+
+ Groovy
+
+
+ HTML
+
+
+ J2ME issues
+
+
+ Java language level issues
+
+
+ JavaBeans issues
+
+
+ Pattern Validation
+
+
+ Threading issues
+
+
+ Threading issuesGroovy
+
+
+ XML
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..705e23c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4936dfd
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# Retrofit2Example
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..966edff
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,28 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 24
+ buildToolsVersion "23.0.3"
+
+ defaultConfig {
+ applicationId "com.opendroid.droid.retofit2example"
+ minSdkVersion 15
+ targetSdkVersion 24
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+ testCompile 'junit:junit:4.12'
+ compile 'com.android.support:appcompat-v7:24.2.0'
+ compile 'com.squareup.retrofit2:retrofit:2.1.0'
+ compile 'com.squareup.retrofit2:converter-gson:2.1.0'
+}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..2397c38
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Users/ajaythakur/Developer/android-sdk-macosx/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/app/src/androidTest/java/com/opendroid/droid/retofit2example/ApplicationTest.java b/app/src/androidTest/java/com/opendroid/droid/retofit2example/ApplicationTest.java
new file mode 100644
index 0000000..861e654
--- /dev/null
+++ b/app/src/androidTest/java/com/opendroid/droid/retofit2example/ApplicationTest.java
@@ -0,0 +1,13 @@
+package com.opendroid.droid.retofit2example;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * Testing Fundamentals
+ */
+public class ApplicationTest extends ApplicationTestCase {
+ public ApplicationTest() {
+ super(Application.class);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..33b00c4
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/opendroid/droid/retofit2example/MainActivity.java b/app/src/main/java/com/opendroid/droid/retofit2example/MainActivity.java
new file mode 100644
index 0000000..5c921b3
--- /dev/null
+++ b/app/src/main/java/com/opendroid/droid/retofit2example/MainActivity.java
@@ -0,0 +1,324 @@
+package com.opendroid.droid.retofit2example;
+
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.lang.ref.WeakReference;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import okhttp3.ResponseBody;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+public class MainActivity extends AppCompatActivity {
+ protected final String TAG = getClass().getSimpleName();
+ private RetainedAppData mRetainedAppData;
+ // UX handlers
+ private ProgressBar mProgressBar;
+ private EditText mInputCityName;
+ private TextView mCityNameTextView;
+ private TextView mCountryNameTextView;
+ private TextView mCodTextView;
+ private TextView mCoordsTextView;
+ private TextView mTempTextView;
+ private TextView mSunriseTextView;
+ private TextView mSunsetTextView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ mProgressBar = (ProgressBar) findViewById(R.id.progress_bar_id);
+ mInputCityName = (EditText) findViewById(R.id.input_city_id);
+ // Data saved
+ if (savedInstanceState != null) {
+ if (getLastCustomNonConfigurationInstance() != null) {
+ mRetainedAppData = (RetainedAppData) getLastCustomNonConfigurationInstance();
+ Log.d(TAG,"onCreate(): Reusing retained data set");
+ }
+ } else {
+ mRetainedAppData = new RetainedAppData();
+ Log.d(TAG, "onCreate(): Creating new data set");
+ }
+
+ // Setup activity reference
+ // mActivityRef = new WeakReference<>(this);
+ mRetainedAppData.setAppContext(this);
+
+ if (mRetainedAppData.mData != null) {
+ updateUXWithWeather(mRetainedAppData.mData);
+ }
+ // Setup the progress bar
+ if (mRetainedAppData.isFetchInProgress()) {
+ mProgressBar.setVisibility(View.VISIBLE);
+ } else {
+ mProgressBar.setVisibility(View.INVISIBLE);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // mActivityRef = null;
+ mRetainedAppData.setAppContext(null);
+ Log.d(TAG,"onDestroy()");
+ }
+
+ @Override
+ public Object onRetainCustomNonConfigurationInstance() {
+ return mRetainedAppData;
+ }
+
+ public void expandWeatherSync(View v) {
+ hideKeyboard(MainActivity.this, mInputCityName.getWindowToken());
+ String city = mInputCityName.getText().toString();
+ if (city.isEmpty()) {
+ Toast.makeText(getApplicationContext(),"No city specified.",
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ mRetainedAppData.runRetrofitTestSync(city);
+ }
+
+ public void expandWeatherAsync(View v) {
+ hideKeyboard(MainActivity.this, mInputCityName.getWindowToken());
+ String city = mInputCityName.getText().toString();
+ if (city.isEmpty()) {
+ Toast.makeText(getApplicationContext(),"No city specified.",
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ mRetainedAppData.runRetrofitTestAsync(city);
+ }
+
+ /**
+ * This method is used to hide a keyboard after a user has
+ * finished typing the url.
+ */
+ public static void hideKeyboard(Activity activity,
+ IBinder windowToken) {
+ InputMethodManager mgr = (InputMethodManager) activity.getSystemService
+ (Context.INPUT_METHOD_SERVICE);
+ mgr.hideSoftInputFromWindow(windowToken, 0);
+ }
+
+ void updateUXWithWeather (final Weather data) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // Setup UX handlers
+ // Get the UX handlers every time. This is to avoid a condition
+ // when runOnUiThread may not have updated UX handles when screen is rotated.
+ // 'mActivityRef.get()'
+ mProgressBar = (ProgressBar) findViewById(R.id.progress_bar_id);
+ mInputCityName = (EditText) findViewById(R.id.input_city_id);
+ mCityNameTextView = (TextView) findViewById(R.id.city_name_id);
+ mCountryNameTextView = (TextView) findViewById(R.id.country_name_id);
+ mCodTextView = (TextView) findViewById(R.id.cod_id);
+ mCoordsTextView = (TextView) findViewById(R.id.coords_id);
+ mTempTextView = (TextView) findViewById(R.id.temp_id);
+ mSunriseTextView = (TextView) findViewById(R.id.sunrise_id);
+ mSunsetTextView = (TextView) findViewById(R.id.sunset_id);
+
+ // Refresh UX data
+ if (mRetainedAppData.isFetchInProgress()) {
+ mProgressBar.setVisibility(View.VISIBLE);
+ } else {
+ mProgressBar.setVisibility(View.INVISIBLE);
+ }
+
+ // Print data to Android display
+ Resources res = getResources();
+ String textToPrint = res.getString(R.string.city) + data.getName();
+ mCityNameTextView.setText(textToPrint);
+ textToPrint = res.getString(R.string.country) + data.getCountry();
+ mCountryNameTextView.setText(textToPrint);
+ textToPrint = res.getString(R.string.coordinates) +"(" + data.getLat() + "," + data.getLon() + ")";
+ mCoordsTextView.setText(textToPrint);
+ textToPrint = res.getString(R.string.cod) + data.getCod();
+ mCodTextView.setText(textToPrint);
+ String tempF = String.format(Locale.UK,"Temperature: %.2f F", (data.getTemp() - 273.15) * 1.8 + 32.00);
+ mTempTextView.setText(tempF);
+ DateFormat dfLocalTz = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.UK);
+ Date sunriseTime = new Date(data.getSunrise() * 1000);
+ Date sunsetTime = new Date(data.getSunset() * 1000);
+ textToPrint = res.getString(R.string.sunrise) + dfLocalTz.format(sunriseTime);
+ mSunriseTextView.setText(textToPrint);
+ textToPrint = res.getString(R.string.sunset) + dfLocalTz.format(sunsetTime);
+ mSunsetTextView.setText(textToPrint);
+ }
+ });
+ }
+
+ /**
+ * This is main class object that should save all data upon configuration changes.
+ * This object is saved by the 'onRetainCustomNonConfigurationInstance' method.
+ *
+ * Note: In the video it is referred to as 'private class TestWeather'
+ */
+ private static class RetainedAppData {
+ private WeakReference mActivityRef;
+ protected final String TAG = "RTD";
+ private Weather mData; // Weather data received
+ private AtomicBoolean mInProgress = new AtomicBoolean(false); // Is a download in progress
+ private WeatherRestAdapter mWeatherRestAdapter; // REST Adapter
+ private Callback mWeatherCallback = new Callback() {
+ @Override
+ public void onResponse(Call call, Response response) {
+ // response.isSuccessful() is true if the response code is 2xx
+ if (response.isSuccessful()) {
+ Weather data = response.body();
+ Log.d(TAG, "Async success: Weather: Name:" + data.getName() + ", cod:" + data.getCod()
+ + ",Coord: (" + data.getLat() + "," + data.getLon()
+ + "), Temp:" + data.getTemp()
+ + "\nSunset:" + data.getSunset() + ", " + data.getSunrise()
+ + ", Country:" + data.getCountry());
+ mData = data;
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().updateUXWithWeather(mData);
+ mActivityRef.get().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mActivityRef.get().mProgressBar = (ProgressBar) mActivityRef.get().
+ findViewById(R.id.progress_bar_id);
+ mActivityRef.get().mProgressBar.setVisibility(View.INVISIBLE);
+ }
+ });
+ }
+ mInProgress.set(false);
+ } else {
+ int statusCode = response.code();
+
+ // handle request errors yourself
+ ResponseBody errorBody = response.errorBody();
+ Log.d(TAG,"Error code:" + statusCode + ", Error:" + errorBody);
+ }
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable t) {
+ mInProgress.set(false);
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mActivityRef.get().mProgressBar = (ProgressBar) mActivityRef.get().
+ findViewById(R.id.progress_bar_id);
+ mActivityRef.get().mProgressBar.setVisibility(View.INVISIBLE);
+ }
+ });
+ }
+ }
+ };
+ // Method to test Async. call
+ public void runRetrofitTestAsync (final String city) {
+ if ( (mActivityRef.get() != null) && (mInProgress.get())) {
+ Toast.makeText(mActivityRef.get(),"Weather fetch in progress.",
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ // Get the Adapter
+ if (mWeatherRestAdapter == null)
+ mWeatherRestAdapter = new WeatherRestAdapter();
+
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().mProgressBar.setVisibility(View.VISIBLE);
+ }
+
+ // Test delay
+ try {
+ mInProgress.set(true);
+ mWeatherRestAdapter.testWeatherApi(city, mWeatherCallback); // Call Async API
+ } catch (Exception e) {
+ Log.d(TAG, "Thread sleep error" + e);
+ }
+ }
+
+ // Method to test sync. call
+ public void runRetrofitTestSync (final String city) {
+
+ if ((mActivityRef.get() != null) && (mInProgress.get())) {
+ Toast.makeText(mActivityRef.get(),"Weather fetch in progress.",
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().mProgressBar.setVisibility(View.VISIBLE);
+ }
+
+ if (mWeatherRestAdapter == null)
+ mWeatherRestAdapter = new WeatherRestAdapter();
+
+ mInProgress.set(true);
+
+ // Test Sync version -- in a separate thread
+ // Not doing this will crash the app. As Retro sync calls can not be made from
+ // UI thread.
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // Call Async API -- always call in a try block if you dont want app to
+ // crash. You get 'HTTP/1.1 500 Internal Server Error' more often than
+ // you think.
+ Thread.sleep(10000);
+ Weather data = mWeatherRestAdapter.testWeatherApiSync(city);
+ if (data != null) {
+ Log.d(TAG, "Sync: Data: cod:" + data.getName() + ", cod:" + data.getCod()
+ + ",Coord: (" + data.getLat() + "," + data.getLon()
+ + "), Temp:" + data.getTemp()
+ + "\nSunset:" + data.getSunset() + ", " + data.getSunrise()
+ + ", Country:" + data.getCountry());
+ mData = data;
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().updateUXWithWeather(mData);
+ }
+ } else {
+ Log.e(TAG, "Sync: no data fetched");
+ }
+ } catch (Exception ex) {
+ Log.e(TAG, "Sync: exception", ex);
+ if (mActivityRef.get() != null) {
+ mActivityRef.get().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mActivityRef.get().mProgressBar = (ProgressBar) mActivityRef.get().
+ findViewById(R.id.progress_bar_id);
+ mActivityRef.get().mProgressBar.setVisibility(View.INVISIBLE);
+ }
+ });
+ }
+ } finally {
+ mInProgress.set(false);
+ }
+ }
+ }).start();
+ }
+
+ void setAppContext (MainActivity ref) {
+ mActivityRef = new WeakReference<>(ref);
+ }
+
+ boolean isFetchInProgress() {
+ return mInProgress.get();
+ }
+ }
+}
diff --git a/app/src/main/java/com/opendroid/droid/retofit2example/Weather.java b/app/src/main/java/com/opendroid/droid/retofit2example/Weather.java
new file mode 100644
index 0000000..d53e7ca
--- /dev/null
+++ b/app/src/main/java/com/opendroid/droid/retofit2example/Weather.java
@@ -0,0 +1,282 @@
+package com.opendroid.droid.retofit2example;
+
+import java.util.List;
+
+/**
+ * Created by ajaythakur on 6/16/15.
+ *
+ * {
+ * "coord":{"lon":-122.08,"lat":37.39},
+ * "sys":{
+ * "type":1,"id":451,"message":1.1091,
+ * "country":"United States of America",
+ * "sunrise":1434545231,"sunset":1434598293
+ * },
+ * "weather":[{"id":701,"main":"Mist","description":"mist","icon":"50n"}],
+ * "base":"stations",
+ * "main":{"temp":288.73,"pressure":1014,"humidity":82,"temp_min":284.26,"temp_max":294.15},
+ * "visibility":16093,
+ * "wind":{"speed":4.1,"deg":350},
+ * "clouds":{"all":20},
+ * "dt":1434517063,
+ * "id":5375480,
+ * "name":"Mountain View",
+ * "cod":200
+ * }
+ */
+public class Weather {
+ private Coord coord;
+ private int cod;
+ private String base;
+ private String name;
+ private Main main;
+ private List weather;
+ private Sys sys;
+
+ public Weather(Coord coord, int code, String base, String name, Main main) {
+ this.coord = coord;
+ this.cod = code;
+ this.base = base;
+ this.name = name;
+ this.main = main;
+ }
+
+ public int getCod() {
+ return cod;
+ }
+
+ public void setCod(int code) {
+ this.cod = code;
+ }
+
+ public String getBase() {
+ return base;
+ }
+
+ public void setBase(String base) {
+ this.base = base;
+ }
+
+ public Coord getCoord() {
+ return coord;
+ }
+
+ public void setCoord(Coord coord) {
+ this.coord = coord;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Main getMain() {
+ return main;
+ }
+
+ public void setMain(Main main) {
+ this.main = main;
+ }
+
+ class Main {
+ double temp;
+ double pressure;
+ int humidity;
+
+ public Main(double temp, int pressure, int humidity) {
+ this.temp = temp;
+ this.pressure = pressure;
+ this.humidity = humidity;
+ }
+
+ public double getTemp() {
+ return temp;
+ }
+
+ public void setTemp(double temp) {
+ this.temp = temp;
+ }
+
+ public double getPressure() {
+ return pressure;
+ }
+
+ public void setPressure(double pressure) {
+ this.pressure = pressure;
+ }
+
+ public int getHumidity() {
+ return humidity;
+ }
+
+ public void setHumidity(int humidity) {
+ this.humidity = humidity;
+ }
+ }
+
+ class Coord {
+ double lat;
+ double lon;
+
+ public Coord(double lat, double lon) {
+ this.lat = lat;
+ this.lon = lon;
+ }
+
+ public double getLat() {
+ return lat;
+ }
+
+ public void setLat(double lat) {
+ this.lat = lat;
+ }
+
+ public double getLon() {
+ return lon;
+ }
+
+ public void setLon(double lon) {
+ this.lon = lon;
+ }
+ }
+
+ class WeatherDetails {
+ private int id;
+ String main;
+ String description;
+ String icon;
+
+ public WeatherDetails() {
+ }
+
+ public WeatherDetails(int id, String main, String description, String icon) {
+ this.id = id;
+ this.main = main;
+ this.description = description;
+ this.icon = icon;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getMain() {
+ return main;
+ }
+
+ public void setMain(String main) {
+ this.main = main;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+ }
+
+ class Sys {
+ int type;
+ int id;
+ String country;
+ long sunrise;
+ long sunset;
+
+ public Sys() {
+ }
+
+ public Sys(int type, int id, String country, long sunrise, long sunset) {
+ this.type = type;
+ this.id = id;
+ this.country = country;
+ this.sunrise = sunrise;
+ this.sunset = sunset;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public long getSunrise() {
+ return sunrise;
+ }
+
+ public void setSunrise(long sunrise) {
+ this.sunrise = sunrise;
+ }
+
+ public long getSunset() {
+ return sunset;
+ }
+
+ public void setSunset(long sunset) {
+ this.sunset = sunset;
+ }
+ }
+
+ // Accesor methods
+ public double getLat() {
+ return coord.getLat();
+ }
+
+ public double getLon() {
+ return coord.getLon();
+ }
+
+ public double getPressure() {
+ return main.getPressure();
+ }
+
+ public double getTemp() {
+ return main.getTemp();
+ }
+
+ public String getCountry() {
+ return sys.getCountry();
+ }
+
+ public long getSunrise() {
+ return sys.getSunrise();
+ }
+
+ public long getSunset() {
+ return sys.getSunset();
+ }
+}
diff --git a/app/src/main/java/com/opendroid/droid/retofit2example/WeatherApi.java b/app/src/main/java/com/opendroid/droid/retofit2example/WeatherApi.java
new file mode 100644
index 0000000..e0f18f3
--- /dev/null
+++ b/app/src/main/java/com/opendroid/droid/retofit2example/WeatherApi.java
@@ -0,0 +1,15 @@
+package com.opendroid.droid.retofit2example;
+
+/**
+ * Created by ajaythakur on 8/23/16.
+ */
+import retrofit2.Call;
+import retrofit2.http.GET;
+import retrofit2.http.Query;
+
+public interface WeatherApi {
+ @GET("/data/2.5/weather")
+ Call getWeatherFromApi (
+ @Query("q") String cityName,
+ @Query("APPID") String appId);
+}
diff --git a/app/src/main/java/com/opendroid/droid/retofit2example/WeatherRestAdapter.java b/app/src/main/java/com/opendroid/droid/retofit2example/WeatherRestAdapter.java
new file mode 100644
index 0000000..a34fc0f
--- /dev/null
+++ b/app/src/main/java/com/opendroid/droid/retofit2example/WeatherRestAdapter.java
@@ -0,0 +1,49 @@
+package com.opendroid.droid.retofit2example;
+
+/**
+ * Created by ajaythakur on 8/23/16.
+ */
+import android.util.Log;
+
+import java.io.IOException;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Retrofit;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+public class WeatherRestAdapter {
+ protected final String TAG = getClass().getSimpleName();
+ protected Retrofit mRestAdapter;
+ protected WeatherApi mApi;
+ static final String WEATHER_URL="http://api.openweathermap.org/";
+ static final String OPEN_WEATHER_API = "51337ba29f38cb7a5664cda04d84f4cd";
+
+ public WeatherRestAdapter() {
+ mRestAdapter = new Retrofit.Builder()
+ .baseUrl(WEATHER_URL)
+ .addConverterFactory(GsonConverterFactory.create())
+ .build();
+ mApi = mRestAdapter.create(WeatherApi.class); // create the interface
+ Log.d(TAG, "WeatherRestAdapter -- created");
+ }
+
+ public void testWeatherApi(String city, Callback callback){
+ Log.d(TAG, "testWeatherApi: for city:" + city);
+ mApi.getWeatherFromApi(city, OPEN_WEATHER_API).enqueue(callback);
+ }
+
+ public Weather testWeatherApiSync(String city) {
+ Log.d(TAG, "testWeatherApi: for city:" + city);
+
+ Call call = mApi.getWeatherFromApi(city, OPEN_WEATHER_API);
+ Weather result = null;
+ try {
+ result = call.execute().body();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..07ef6b1
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..cde69bc
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..c133a0c
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..bfa42f0
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..324e72c
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..aee44e1
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml
new file mode 100644
index 0000000..63fc816
--- /dev/null
+++ b/app/src/main/res/values-w820dp/dimens.xml
@@ -0,0 +1,6 @@
+
+
+ 64dp
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..237fe52
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,12 @@
+
+
+ #3F51B5
+ #303F9F
+ #FF4081
+ #42A5F5
+ #0D47A1
+ #1E88E5
+ #CDDC39
+ #2196F3
+ #2962FF
+
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..47c8224
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 16dp
+ 16dp
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..8551cf3
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,11 @@
+
+ Retofit2Example
+ Settings
+ City:
+ Country:
+ Coordinates:
+ COD:
+ Temperature:
+ Sunrise:
+ Sunset:
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..5885930
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/app/src/test/java/com/opendroid/droid/retofit2example/ExampleUnitTest.java b/app/src/test/java/com/opendroid/droid/retofit2example/ExampleUnitTest.java
new file mode 100644
index 0000000..2eecd3a
--- /dev/null
+++ b/app/src/test/java/com/opendroid/droid/retofit2example/ExampleUnitTest.java
@@ -0,0 +1,15 @@
+package com.opendroid.droid.retofit2example;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * To work on unit tests, switch the Test Artifact in the Build Variants view.
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() throws Exception {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..77ce66e
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,23 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:2.1.3'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..1d3591c
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..13372ae
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..f19c2cd
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Aug 23 08:24:11 PDT 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..9d82f78
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..e7b4def
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':app'