Skip to content

VTom21/Weather-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Weather App


androidauto Β Β Β Β  kotlin Β Β Β Β  xml Β Β Β Β  gradle

An Android weather application built with Kotlin that provides real-time weather data and detailed atmospheric metrics based on your current GPS location. No API key required.


πŸ“Έ App Preview

Β Β Β  Β Β Β 

πŸ“± Screens

Screen Description
Home App entry point
Weather Current temperature + 8 key weather stats
Details 12 advanced metrics in scrollable cards

✨ Features

  • Real-time weather fetched from your GPS location
  • Two levels of weather data: basic overview and advanced details
  • Scrollable card-based UI for detailed metrics
  • Bottom navigation between screens
  • Portrait-locked orientation for consistent layout
  • No API key needed

πŸ› οΈ Tech Stack

Tool Purpose
Kotlin Primary language
XML UI layouts
Gradle Build system
Android Studio IDE
Open-Meteo API Free weather data, no API key
Google Play Services Fused Location Provider for GPS
Material Design 3 UI components (cards, bottom nav)
RecyclerView Scrollable advanced data cards
ConstraintLayout Responsive screen layouts

🌐 API β€” Open-Meteo

This app uses the free Open-Meteo API β€” no account or API key required.

Screen 1 β€” Weather Overview (MainActivity2)

Fetches basic current conditions and today's minimum temperature.

Endpoint:

GET https://api.open-meteo.com/v1/forecast
  ?latitude={lat}
  &longitude={lon}
  &current=temperature_2m,relative_humidity_2m,wind_speed_10m,rain,dew_point_2m,sunshine_duration
  &daily=temperature_2m_min

Data used:

Field Source Unit Displayed As
temperature_2m current Β°C Main temperature
rain current mm Rain amount
relative_humidity_2m current % Humidity
wind_speed_10m current km/h Wind speed
dew_point_2m current Β°C Dew point
sunshine_duration current s Sunshine span
temperature_2m_min daily[0] Β°C Min temperature

Screen 2 β€” Advanced Details (MainActivity3)

Fetches deeper atmospheric data from current, daily, and hourly fields.

Endpoint:

GET https://api.open-meteo.com/v1/forecast
  ?latitude={lat}
  &longitude={lon}
  &current=apparent_temperature,precipitation,showers,snowfall,cloud_cover,direct_radiation,surface_pressure,pressure_msl
  &daily=daylight_duration,uv_index_max
  &hourly=cape,soil_temperature_0cm

Data used:

Field Source Unit Displayed As
apparent_temperature current Β°C Apparent Temp
precipitation current mm Precipitation
showers current mm Showers
snowfall current cm Snowfall
cloud_cover current % Cloud Cover
direct_radiation current W/mΒ² Radiation
surface_pressure current hPa Surface Pressure
pressure_msl current hPa Sea Level Pressure
daylight_duration daily[0] s Daylight Span
uv_index_max daily[0] - UV Index Max
cape hourly[0] J/kg Storm Energy
soil_temperature_0cm hourly[0] Β°C Soil Temp 0cm

πŸ’» Code Snippets

Fetching location

fusedLocationClient.lastLocation
   .addOnSuccessListener { location ->
      if (location != null) {
         fetchData(location.latitude, location.longitude).start()
      }
   }

Making the API request

val url = URL(
   "https://api.open-meteo.com/v1/forecast?" +
           "latitude=$lat&longitude=$lon&" +
           "current=apparent_temperature,precipitation,showers,snowfall," +
           "cloud_cover,direct_radiation,surface_pressure,pressure_msl&" +
           "daily=daylight_duration,uv_index_max&" +
           "hourly=cape,soil_temperature_0cm"
)
val connection = url.openConnection() as HttpsURLConnection

Parsing the JSON response

val json = org.json.JSONObject(reader.readText())

val current = json.getJSONObject("current")
val daily   = json.getJSONObject("daily")
val hourly  = json.getJSONObject("hourly")

val weather = WeatherAdvanced(
   apparentTemp     = current.optDouble("apparent_temperature", 0.0),
   precipitation    = current.optDouble("precipitation", 0.0),
   cloudCover       = current.optDouble("cloud_cover", 0.0),
   daylightDuration = daily.getJSONArray("daylight_duration").optDouble(0, 0.0),
   uvIndexMax       = daily.getJSONArray("uv_index_max").optDouble(0, 0.0),
   cape             = hourly.getJSONArray("cape").optDouble(0, 0.0),
   soilTemp         = hourly.getJSONArray("soil_temperature_0cm").optDouble(0, 0.0)
)

Data classes

data class Weather(
   val temp: Double,
   val rainAmount: Double,
   val humidity: Double,
   val windSpeed: Double,
   val dewPoint: Double,
   val sunshineSpan: Double,
   val tempMin: Double
)

data class WeatherAdvanced(
   val apparentTemp: Double,
   val precipitation: Double,
   val showers: Double,
   val snowfall: Double,
   val cloudCover: Double,
   val directRadiation: Double,
   val daylightDuration: Double,
   val surfacePressure: Double,
   val pressureMsl: Double,
   val uvIndexMax: Double,
   val cape: Double,
   val soilTemp: Double
)

Updating the UI on the main thread

private fun UpdateUI(weather: Weather, lat: Double, lon: Double) {
   runOnUiThread {
      findViewById<TextView>(R.id.Degree).text        = "${weather.temp}Β°C"
      findViewById<TextView>(R.id.rain_amount).text   = "${weather.rainAmount}mm"
      findViewById<TextView>(R.id.humidity_amount).text = "${weather.humidity}%"
      findViewById<TextView>(R.id.wind_amount).text   = "${weather.windSpeed}km/h"
      findViewById<TextView>(R.id.dew_amount).text    = "${weather.dewPoint}Β°C"
      findViewById<TextView>(R.id.sun_span).text      = "${weather.sunshineSpan}s"
      findViewById<TextView>(R.id.min_temp).text      = "${weather.tempMin}Β°C"
      findViewById<TextView>(R.id.latitude).text      = "Latitude:%.2f".format(lat)
      findViewById<TextView>(R.id.longtitude).text    = "Longitude:%.2f".format(lon)
   }
}

πŸ“‚ Structure Snippet

app/
β”œβ”€β”€ manifests/
β”‚   └── AndroidManifest.xml
β”œβ”€β”€ kotlin/com/example/weatherapp/
β”‚   β”œβ”€β”€ MainActivity.kt          # Home screen
β”‚   β”œβ”€β”€ MainActivity2.kt         # Weather overview screen
β”‚   β”œβ”€β”€ MainActivity3.kt         # Advanced details screen
β”‚   β”œβ”€β”€ WeatherAdapter.kt        # RecyclerView adapter
β”‚   β”œβ”€β”€ Weather.kt               # Basic weather data class
β”‚   β”œβ”€β”€ WeatherAdvanced.kt       # Advanced weather data class
β”‚   β”œβ”€β”€ WeatherData.kt           # RecyclerView item data class
β”‚   └── Navigate.kt              # Bottom nav helper
└── res/
    β”œβ”€β”€ layout/
    β”‚   β”œβ”€β”€ activity_main.xml
    β”‚   β”œβ”€β”€ activity_main2.xml
    β”‚   β”œβ”€β”€ activity_main3.xml
    β”‚   └── data_card.xml
    β”œβ”€β”€ menu/
    β”‚   └── bottom_nav.xml
    └── color/
        └── nav_item_color.xml

πŸ”‘ Permissions

Declared in AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

Location permission is also requested at runtime:

ActivityCompat.requestPermissions(
   this,
   arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
   1
)

πŸš€ Getting Started

Prerequisites

  • Android Studio (Hedgehog or newer recommended)
  • Android SDK 24+
  • A physical Android device or an emulator with location mocking enabled

Steps

  1. Clone the repository

    git clone https://github.com/yourusername/weatherapp.git
  2. Open in Android Studio

    • File β†’ Open β†’ select the project folder
  3. Let Gradle sync

    • Android Studio will automatically download dependencies
  4. Run the app

    • Connect a physical device via USB with USB debugging enabled
    • Or launch an emulator
    • Press Run β–Ά or Shift + F10
  5. Grant permissions

    • Accept the location permission prompt on first launch

⚠️ A physical device gives the most accurate GPS results. Emulators require manual location mocking via Extended Controls.


πŸ“¦ Dependencies

In build.gradle (app):

dependencies {
    implementation 'com.google.android.gms:play-services-location:21.0.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

πŸ“„ License

This project is open source and free to use for personal and educational purposes.


Weather data provided by Open-Meteo β€” free and open-source weather API, no key required.

Β Β Β Β  heart

About

An Android weather application built with Kotlin, XML and Gradle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages