├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── androidmads │ │ └── openweatherapi │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── Lato-Bold.ttf │ ├── java │ │ └── com │ │ │ └── androidmads │ │ │ └── openweatherapi │ │ │ ├── MainActivity.java │ │ │ ├── WeatherResponse.java │ │ │ └── WeatherService.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── androidmads │ └── openweatherapi │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.androidmads.openweatherapi" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | 29 | implementation 'com.squareup.retrofit2:retrofit:2.4.0' 30 | implementation 'com.squareup.retrofit2:converter-gson:2.4.0' 31 | implementation 'com.ajts.androidmads.fontutils:fontutils:1.0.2' 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/androidmads/openweatherapi/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.androidmads.openweatherapi; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.androidmads.openweatherapi", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/assets/Lato-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidmads/OpenWeatherApiSample/ceed3d2d07e1ed3572fa11ed3948ec08d0b2fd06/app/src/main/assets/Lato-Bold.ttf -------------------------------------------------------------------------------- /app/src/main/java/com/androidmads/openweatherapi/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.androidmads.openweatherapi; 2 | 3 | import android.graphics.Typeface; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | import com.ajts.androidmads.fontutils.FontUtils; 11 | 12 | import retrofit2.Call; 13 | import retrofit2.Callback; 14 | import retrofit2.Response; 15 | import retrofit2.Retrofit; 16 | import retrofit2.converter.gson.GsonConverterFactory; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | public static String BaseUrl = "http://api.openweathermap.org/"; 21 | public static String AppId = "2e65127e909e178d0af311a81f39948c"; 22 | public static String lat = "35"; 23 | public static String lon = "139"; 24 | 25 | private TextView weatherData; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | weatherData = findViewById(R.id.textView); 33 | 34 | Typeface typeface = Typeface.createFromAsset(getAssets(), "Lato-Bold.ttf"); 35 | FontUtils fontUtils = new FontUtils(); 36 | fontUtils.applyFontToView(weatherData, typeface); 37 | 38 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | getCurrentData(); 42 | } 43 | }); 44 | } 45 | 46 | void getCurrentData() { 47 | Retrofit retrofit = new Retrofit.Builder() 48 | .baseUrl(BaseUrl) 49 | .addConverterFactory(GsonConverterFactory.create()) 50 | .build(); 51 | WeatherService service = retrofit.create(WeatherService.class); 52 | Call call = service.getCurrentWeatherData(lat, lon, AppId); 53 | call.enqueue(new Callback() { 54 | @Override 55 | public void onResponse(@NonNull Call call, @NonNull Response response) { 56 | if (response.code() == 200) { 57 | WeatherResponse weatherResponse = response.body(); 58 | assert weatherResponse != null; 59 | 60 | String stringBuilder = "Country: " + 61 | weatherResponse.sys.country + 62 | "\n" + 63 | "Temperature: " + 64 | weatherResponse.main.temp + 65 | "\n" + 66 | "Temperature(Min): " + 67 | weatherResponse.main.temp_min + 68 | "\n" + 69 | "Temperature(Max): " + 70 | weatherResponse.main.temp_max + 71 | "\n" + 72 | "Humidity: " + 73 | weatherResponse.main.humidity + 74 | "\n" + 75 | "Pressure: " + 76 | weatherResponse.main.pressure; 77 | 78 | weatherData.setText(stringBuilder); 79 | } 80 | } 81 | 82 | @Override 83 | public void onFailure(@NonNull Call call, @NonNull Throwable t) { 84 | weatherData.setText(t.getMessage()); 85 | } 86 | }); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/androidmads/openweatherapi/WeatherResponse.java: -------------------------------------------------------------------------------- 1 | package com.androidmads.openweatherapi; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * Created by Mushtaq on 05-11-2018. 9 | */ 10 | 11 | public class WeatherResponse { 12 | 13 | @SerializedName("coord") 14 | public Coord coord; 15 | @SerializedName("sys") 16 | public Sys sys; 17 | @SerializedName("weather") 18 | public ArrayList weather = new ArrayList(); 19 | @SerializedName("main") 20 | public Main main; 21 | @SerializedName("wind") 22 | public Wind wind; 23 | @SerializedName("rain") 24 | public Rain rain; 25 | @SerializedName("clouds") 26 | public Clouds clouds; 27 | @SerializedName("dt") 28 | public float dt; 29 | @SerializedName("id") 30 | public int id; 31 | @SerializedName("name") 32 | public String name; 33 | @SerializedName("cod") 34 | public float cod; 35 | } 36 | 37 | class Weather { 38 | @SerializedName("id") 39 | public int id; 40 | @SerializedName("main") 41 | public String main; 42 | @SerializedName("description") 43 | public String description; 44 | @SerializedName("icon") 45 | public String icon; 46 | } 47 | 48 | class Clouds { 49 | @SerializedName("all") 50 | public float all; 51 | } 52 | 53 | class Rain { 54 | @SerializedName("3h") 55 | public float h3; 56 | } 57 | 58 | class Wind { 59 | @SerializedName("speed") 60 | public float speed; 61 | @SerializedName("deg") 62 | public float deg; 63 | } 64 | 65 | class Main { 66 | @SerializedName("temp") 67 | public float temp; 68 | @SerializedName("humidity") 69 | public float humidity; 70 | @SerializedName("pressure") 71 | public float pressure; 72 | @SerializedName("temp_min") 73 | public float temp_min; 74 | @SerializedName("temp_max") 75 | public float temp_max; 76 | } 77 | 78 | class Sys { 79 | @SerializedName("country") 80 | public String country; 81 | @SerializedName("sunrise") 82 | public long sunrise; 83 | @SerializedName("sunset") 84 | public long sunset; 85 | } 86 | 87 | class Coord { 88 | @SerializedName("lon") 89 | public float lon; 90 | @SerializedName("lat") 91 | public float lat; 92 | } -------------------------------------------------------------------------------- /app/src/main/java/com/androidmads/openweatherapi/WeatherService.java: -------------------------------------------------------------------------------- 1 | package com.androidmads.openweatherapi; 2 | 3 | import java.util.List; 4 | 5 | import retrofit2.Call; 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | import retrofit2.http.Query; 9 | 10 | /** 11 | * Created by Mushtaq on 05-11-2018. 12 | */ 13 | 14 | public interface WeatherService { 15 | @GET("data/2.5/weather?") 16 | Call getCurrentWeatherData(@Query("lat") String lat, @Query("lon") String lon, @Query("APPID") String app_id); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 |