build a professional weather app - sunshine

43
Building a Professio nal WeatherApp 04/04/2015 @MZouinkhi I S S A T S o G o o g l e C l u b First Session

Upload: marwan-zouinkhi

Post on 03-Aug-2015

92 views

Category:

Technology


1 download

TRANSCRIPT

Smart Phone == Small ComputerLow processing powerLimited RAMLimited data connections ( low bandwidth)Limited battery life

Android devices

Android Versions

Android Architecture

Android Studio

ANDROIDSTUDIO

Object Oriented Programming

Should use

Our App

- ListViews / Adapters- Recycler View / CardView - WebServices.- AsyncTasks.- JSON Parsing.- SQLite.- JUnit Tests.

Let's Fly !#Sunshine

For today

Details

Min level & target level

Start a new project called Sunshinewith Blank Activity with fragment

Add new XML Activity called treewith

Picture Text

Button

AbsoluteLayout Is Evil

Layout

FrameLayout

LinearLayout

RelativeLayout

Add new layout XML called list_item_forecast

containing TextView with id=”@+id/

list_item_forecast_textview”

Modify fragment_main- RelativeLayout to FrameLayout- TextView to ListView with:

id=”@+id/listview_forecast”width=”match_parent”height=”match_parent”

Java- create a table of Strings

called forecastArray[] which contains static data :“Today - Sunny - 78/63”, …- Create a list WeekForecast

from forecastArray[] Arrays.asList()

Adapter

ScrollView -> ListView + recycle-> Recycling view

Initialise ArrayAdapterin onCreateView()

ArrayAdapter<String> called mForecastAdapter

contextID of list item layoutID of text Viewlist of data

Initialise ArrayAdapterin onCreateView()

ArrayAdapter<String> called mForecastAdapter with parametrescontext getActivity()ID of list item layout R.layout.liste_item_forecastID of text View R.id.list_item_forecast_textviewlist of data weekForecast

Find View

JAVA XML

(Type) this.findViewById(R.id.X)

findView of ListView R.id.listview_forecast with name listView

findView of ListView R.id.listview_forecast with name listView

ListView listView= (ListView) this.findViewById(R.id.listview_forecast )

Set our Adapter mForecastAdapter on listView

Set our Adapter mForecastAdapter on listView

listview.setAdapter(mForecastAdapter )

Run it !

Toast

In Android

Toast.makeText(context,text,length).show();

Add a onItemClickListener on listViewOverride onItemClick to show a toast with item text

to get Text: mForecastAdapter.getItem(position); .

Create New Blanc Activity with Fragmentcalled DetailActivity with father

MainActivitywith textView id="@+id/text_detail"

Intent

Intent nameIntent= new Intent(context,Activity.class).putExtra(Intent.EXTRA_TEXT,text); startActivity(nameIntent);

Override onItemClick start a new Activity DetailActivity and send the item text in Extra

on onCreateView of DetailActivityfind view of textView text_detail

test if you have an extraif yes put the extra String in textView

Intent

if (intent!=null && intent.hasExtra(Intent.EXTRA_TEXT)) { mForecastStr = intent.getStringExtra(Intent.EXTRA_TEXT); ((TextView) rootView.findViewById(R.id.text_detail)) .setText(mForecastStr);

Android is a major step

towards an ethical, user-

controlled, free-software

portable phone, but there is a

long way to go.Richard

stallman

See you next time- openweathermap.org/API- JSONParsing