Weather app design android

Create a Weather App on Android

A lot of the popular weather apps on Google Play are either full of ads, require too many permissions, or include features that most of us never use. Wouldn’t it be great if you could build your own weather app from scratch?

In this tutorial, I’m going to show you how. Our app will have a simple and minimalist user interface, showing the user exactly what they need to know about the current weather conditions. Let’s get started.

Looking for a Shortcut?

This tutorial will teach you to build a weather app from scratch, but one alternative is to use one of the Android weather app templates on Envato Market.

For example, Weminder provides a simple, clean user interface and all the essential features of a weather app, so that you can then customize it for your own purposes.

Weminder weather app template on Envato Market

Or, if you want something unique and custom-built, head over to Envato Studio to check out the selection of mobile and app development services on offer there.

1. Prerequisites

Before you continue, double-check that you have the following set up:

  • Eclipse ADT Bundle: You can download it at the Android Developer website.
  • OpenWeatherMap API Key : This isn’t required to complete the tutorial, but it’s free. You can obtain one by signing up at the OpenWeatherMap website.
  • Icons: I recommend you download the weather icons font created by Erik Flowers. You need to download the TTF file, because we’ll be using it in a native app. We’ll use the font to render various icons depending on the weather conditions.

2. Create a New Project

I’m going to call this app SimpleWeather, but feel free to give it any name you like. Enter a unique package name, set the minimum required SDK to Android 2.2, and set the target SDK to Android 4.4. You can leave the theme at Holo Dark.

This app will only have one Activity and it will be based on the Blank Activity template as shown below.

Name the Activity WeatherActivity. We’ll be using a Fragment inside this Activity . The layout associated with the Activity is activity_weather.xml. The layout associated with the Fragment is fragment_weather.xml.

3. Add the Custom Font

Copy weathericons-regular-webfont.ttf to your project’s assets/fonts directory and rename it to weather.ttf.

4. Edit the Manifest

The only permission this app needs is android.permission.INTERNET .

To keep this tutorial simple, we’re only going to support portrait mode. The activity node of the manifest should look like this:

5. Edit the Activity’s Layout

There isn’t much to change in activity_weather.xml. It should already have a FrameLayout . Add an extra property to change the color of the background to #FF0099CC .

6. Edit the Fragment’s Layout

Edit fragment_weather.xml by adding five TextView tags to show the following information:

  • city and country
  • current temperature
  • an icon showing the current weather condition
  • a timestamp telling the user when the weather information was last updated
  • more detailed information about the current weather, such as description and humidity

Use a RelativeLayout to arrange the text views. You can adjust the textSize to suit various devices.

7. Edit strings.xml

This file contains the strings used in our app as well as the Unicode character codes that we’ll use to render the weather icons. The application will be able to display eight different types of weather conditions. If you want to handle more, then refer to this cheat sheet. Add the following to values/strings.xml:

8. Add a Menu Item

The user should be able to choose the city whose weather they want to see. Edit menu/weather.xml and add an item for this option.

Now that all the XML files are ready to use, let’s move on and query the OpenWeatherMap API to fetch weather data.

9. Fetch Data From OpenWeatherMap

We can get the current weather details of any city formatted as JSON using the OpenWeatherMap API. In the query string, we pass the city’s name and the metric system the results should be in.

Читайте также:  Блокировка рекламы для андроид без root прав

For example, to get the current weather information for Canberra, using the metric system, we send a request to http://api.openweathermap.org/data/2.5/weather?q=Canberra&units=metric

The response we get back from the API looks like this:

Create a new Java class and name it RemoteFetch.java. This class is responsible for fetching the weather data from the OpenWeatherMap API.

We use the HttpURLConnection class to make the remote request. The OpenWeatherMap API expects the API key in an HTTP header named x-api-key . This is specified in our request using the setRequestProperty method.

We use a BufferedReader to read the API’s response into a StringBuffer . When we have the complete response, we convert it to a JSONObject object.

As you can see in the above response, the JSON data contains a field named cod . Its value is 200 if the request was successful. We use this value to check whether the JSON response has the current weather information or not.

The RemoteFetch.java class should look like this:

10. Store the City as a Preference

The user shouldn’t have to specify the name of the city every time they want to use the app. The app should remember the last city the user was interested in. We do this by making use of SharedPreferences . However, instead of directly accessing these preferences from our Activity class, it is better to create a separate class for this purpose.

Create a new Java class and name it CityPreference.java. To store and retrieve the name of the city, create two methods setCity and getCity . The SharedPreferences object is initialized in the constructor. The CityPreference.java class should look like this:

11. Create the Fragment

Create a new Java class and name it WeatherFragment.java. This fragment uses fragment_weather.xml as its layout. Declare the five TextView objects and initialize them in the onCreateView method. Declare a new Typeface object named weatherFont . The TypeFace object will point to the web font you downloaded and stored in the assets/fonts folder.

We will be making use of a separate Thread to asynchronously fetch data from the OpenWeatherMap API. We cannot update the user interface from such a background thread. We therefore need a Handler object, which we initialize in the constructor of the WeatherFragment class.

Initialize the weatherFont object by calling createFromAsset on the Typeface class. We also invoke the updateWeatherData method in onCreate .

In updateWeatherData , we start a new thread and call getJSON on the RemoteFetch class. If the value returned by getJSON is null , we display an error message to the user. If it isn’t, we invoke the renderWeather method.

Only the main Thread is allowed to update the user interface of an Android app. Calling Toast or renderWeather directly from the background thread would lead to a runtime error. That is why we call these methods using the handler ‘s post method.

The renderWeather method uses the JSON data to update the TextView objects. The weather node of the JSON response is an array of data. In this tutorial, we will only be using the first element of the array of weather data.

At the end of the renderWeather method, we invoke setWeatherIcon with the id of the current weather as well as the times of sunrise and sunset. Setting the weather icon is a bit tricky, because the OpenWeatherMap API supports more weather conditions than we can support with the web font we’re using. Fortunately, the weather ids follow a pattern, which you can read more about on the OpenWeatherMap website.

This is how we map a weather id to an icon:

  • the weather codes in the 200 range are related to thunderstorms, which means we can use R.string.weather_thunder for these
  • the weather codes in the 300 range are related to drizzles and we use R.string.weather_drizzle for these
  • the weather codes in the 500 range signify rain and we use R.string.weather_rain for them
  • and so on .

We use the sunrise and sunset times to display the sun or the moon, depending on the current time of the day and only if the weather is clear.

Of course, you can handle more weather conditions by adding more case statements to the switch statement of the setWeatherIcon method.

Finally, add a changeCity method to the fragment to let the user update the current city. The changeCity method will only be called from the main Activity class.

12. Edit the Activity

During the project’s setup, Eclipse populated WeatherActivity.java with some boilerplate code. Replace the default implementation of the onCreate method with the one below in which we use the WeatherFragment . The onCreate method should look like this:

Next, edit the onOptionsItemSelected method and handle the only menu option we have. All you have to do here is invoke the showInputDialog method.

In the showInputDialog method, we use AlertDialog.Builder to create a Dialog object that prompts the user to enter the name of a city. This information is passed on to the changeCity method, which stores the name of the city using the CityPreference class and calls the Fragment ‘s changeCity method.

Читайте также:  Навигатор для китайских андроидов

Your weather app is now ready. Build the project and deploy it to an Android device for testing.

Conclusion

You now have a fully functional weather application. Feel free to explore the OpenWeatherMap API to further enhance your application. You may also want to make use of more weather icons, because we are currently using only a small subset of them.

Источник

10 Best Weather App Templates

By using a premium weather app template, you will be able to easily create a fully functional and professionally designed weather app that your users will love.

This is one of the newest Android weather app designs on CodeCanyon.

Developing any type of app from scratch can be an overwhelming process. You will have to spend time and money to get the app up and running. Developers will need to be hired, time will need to be spent working alongside the developer, and the app will need to be continually tested before it is ready to launch.

By purchasing one of the many high-quality weather app templates available on CodeCanyon, you will be able to put together a fully functional weather application in no time!

The Best Weather App Templates on CodeCanyon

Explore some of the best weather app designs on CodeCanyon. With just one small payment, you can purchase one of these premium weather app templates and create a weather app that your users will love.

Here are some of the best-selling weather app templates on CodeCanyon for 2021:

Buy the best weather app designs from CodeCanyon.

These premium weather app concepts give you everything you need to create a fully functional weather app for Android and iOS. These templates give you plenty of flexibility and customization to create a weather app that works for you and your business. Here are a few features that you can expect from the weather app templates on CodeCanyon:

  • hourly forecasting
  • automatic location detection
  • seven-day forecasts
  • humidity, pressure, and wind forecast details

Don’t spend another second looking for an app developer. Head on over to CodeCanyon and purchase a weather app template today!

Best Android Weather App Designs of 2021

1. Weather Flow: Live Weather Forecast Design App

WeatherFlow is the simplest and most effective Android weather app template. This complete weather app concept shows hourly, daily, and weekly weather updates in the chosen location.

This weather app design also shows air quality, wind speed, and UV index. Weather Flow provides different options in the Settings menu. You can change the theme (light or dark), temperature unit (Celsius or Fahrenheit), and much more.

2. Weather App Android Template With AdMob

This weather app concept is one of the newest Android weather app designs on CodeCanyon. The weather app Android template provides weather details according to set locations. It features 24-hour forecasts, daily forecasts, multiple locations, UV index, and more.

The weather forecast design is based on Android Studio and comes with full documentation.

3. Simple Weather 5: Android Weather App Template

This is a simple weather template with two screens—the main screen, which contains the weather info, and the settings screen to control the units. Along with an attractive layout, its notable features include five-day weather forecasts updated every hour, the ability to add multiple locations, and AdMob integration. This template is already integrated with the OpenWeatherMap API, but you can easily customize it to any other API if you want.

4. Weatherize: Android Weather App Design

With Weatherize, you will be able to display weather data based on location in real time. You will be able to implement simple menus that are easy for your users to navigate. The interface allows users to type in a new location via the search function, or you can use the phone’s GPS to get your current location. The smooth and simple animations help create a modern and pleasing user experience.

5. Simple Live Weather Forecast Design App

This weather app can automatically detect your location and display the weather forecast. It uses the OpenWeatherMap API to receive forecast information. Here are a few notable features of this weather app:

  • automatic location detection
  • multiple weather providers
  • current weather conditions
  • hourly weather forecast

6. WeatherHQ: Weather App Android Template

WeatherHQ is another new Android weather app design. This weather app Android template is packed with great features.

It comes with a live API, graphs, weekly forecasts, and a clean design. This weather app concept is fast and features a well-organized Android Studio project.

Best iOS Weather App Templates of 2021

7. Simple Weather: iPhone Weather App Template

This iPhone weather app download makes it easy to customize the colors for icons, labels, backgrounds, and buttons so you can make it fit any color scheme for your business. You can display four-day forecasts in detailed information with this app template.

A detailed user guide is included with your purchase, so you can get the app up and running hassle-free. Whether you need the weather forecast for your current location or any location around the world, this app will give you an accurate forecast. It’s one of our best iOS weather app templates!

Читайте также:  Phones compatible with android

8. Store Finder: iPhone Weather App Template

Store Finder is another iOS app template that’s more than just a weather app. Store Finder is packed with features such as the ability to locate a store—and it has a weather feature that fetches and displays the current weather information for a location.

Unlike most of the iOS apps in this list, it is written in Objective-C, so if that is your language of choice, Store Finder might be the template for you. The iPhone weather app download also includes a PHP back-end and Google Maps integration. This app template is compatible with iOS 10.

9. Uhmweather: iOS Weather App Template

Looking for iPhone weather app templates? Uhmweather is one of the best iOS weather app templates.

Uhmweather is an iOS weather app developed in Xcode using Swift 5. The iPhone weather app takes the user’s current location to determine the weather. Users can also search for the current weather of other cities and see a forecast of the weather in the coming seven days or more. Check out this iPhone weather app download!

10. Ionic 5 Weather App Template HTML

The best feature of Ionic app templates is that they’re compatible with both iOS and Android. And this weather app template HTML is a fantastic option.

This Ionic 5 weather forecast design features current, hourly, and seven-day forecasts. It’s a great weather app concept with a clean design and 22 animated icons.

5 Free Weather Forecast Designs for Download in 2021

Now that we’ve gone over some of the best weather app designs from the premium marketplace, let’s go over some free weather apps for Android.

Designing your weather app can be difficult if you’re not a graphic designer. If your design is not up to par with today’s modern designs, then your app will have a difficult time performing well. Another option would be to hire a designer to create this design for you, but this can be quite costly.

To help you save money on your weather app costs, I have collected five of the top weather app designs for you to download in 2021.

1. Weather App UI Design Screens

This minimal weather app design will give your users a unique experience. Half of the app features an illustration of the current weather, and the other half gives the weekly forecast.

2. Weather App Ui Design: Free Weather App Download

This contemporary-looking design allows you to display a multi-day forecast and hourly forecasting. The hourly forecasting features a chart and forecasting details with icons for a more visually appealing user experience.

3. Weather Template: Free Weather App Download

This simple but effective weather app design allows you to display the entire week’s forecast on a single screen. The two color blocking themes make the design look uniform and professional. Each type of forecast will be displayed by nine different icons.

4. Weather App Concept: Free Weather App Download

This design features vibrant colors and a unique layout. It displays a four-day forecast by letting users swipe to choose a day and then displaying that day’s forecast on the entire screen. This design is great if you are looking to have your app stand out.

5. Weather Application Design: Free Weather App Download

This design features visually appealing designs and a spacious layout. This design is great for adding interest to your app. Based on the current design, you can only display the temperature.

Still looking for more app templates? Now we will show you even more best-selling app templates that you can use for the development of your next app.

Discover More Awesome App Templates for 2021

The weather app templates mentioned above are the best weather app designs available on CodeCanyon for 2021. However, if these app templates don’t fit your particular needs or you are looking into creating a different type of app, there are plenty more app templates on CodeCanyon that can work for you.

Feel free to check out a few of the other Envato Tuts+ articles that will highlight even more high-quality app templates you can use for the creation of your next app.

Take Advantage of the App Templates Available on CodeCanyon Now!

When it comes to creating an application for mobile devices, using app templates is your best option. You can not only cut down on the time it takes to hire and work with a developer, but also save a great deal of money by purchasing an app template.

CodeCanyon offers the best weather app templates on the web for you to download for a low one-time cost. These app templates are fully customizable and give you the power to mold the app to fit your particular business’s needs. The weather app templates available contain all of the features needed for a weather app, including detailed forecasts, location detection and search, and hourly forecasting.

Get your weather app up and running in no time by purchasing one of the many high-quality weather app templates on CodeCanyon!

This post has been updated with contributions from Maria Villanueva. Maria is a staff writer with Envato Tuts+.

Источник

Оцените статью