Creearea Unei Aplicatii Android de Turism
Content
1. Rezumat
1.1 Introducere
1.2 Sistemul de operare Android
1.3.Hardware
1.4.Limbaje folosite
1.5 Structura proiectului
1.6 Funcționarea aplicației
2. Work planning
3. State of the Art
4. Theoretical Fundamentals
4.1 General considerations
4.2 Mobile operating systems
4.2.1 Symbian
4.2.2 Windows Mobile
4.2.3 BlackBerry
4.2.4 Windows Phone
4.2.5 iOS
4.2.6 Android
4.3 Technical analysis of Android OS
4.3.1 Hardware
4.3.2 Update versions
4.4 Java programming language
4.5 XML
4.6 PHP
4.7 JSON
4.8 SQL
5. Implementation
5.1 Android Studio
5.2 Structure of the Android application
5.2.1 How it works
5.2.2 Main Activity
5.2.3 Contact
5.2.4 Submenu
5.2.5 DetailedList
5.2.6 PlaceDetails
5.2.7 MapsActivity
5.2.8 Taxi
5.2.9 Weather
5.2.10 Events
5.2.11 Manifest
6. Results
7. Conclusions
8. References
9. Appendix
10. CV
Figures’ list
Figura 1. Structura proiectului…………………………………………………………………………………………….6
Figura 2. Funcționarea aplicației…………………………………………………………………………………………7
Figure 1.World-wide smartphone sales………………………………………………………….12
Figure 2. ARM architecture ……………………………………………………………………..13
Figure 3.Android Studio Software……………………………………………………………….21
Figure 4.Structure of the application……………………………………………………………..22
Figure 5.Computer languages involved…………………………………………………………..23
Figure 6.Tables from the database………………………………………………………………..24
Figure 7. PHP functions………………………………………………………………………….24
Figure 8.Example of generated JSON……………………………………………………………25
Figure 9.The Home Icon………………………………………………………………………………………………………..26
Figure 10.Diagram of Java classes……………………………..…………………………………27
Figure 11.Cycle of Activity ………………………………………………………………………28
Figure 12.Main Activity…………………………………………………………………………………………………..29
Figure 13.Contact Form……………………………………………………………………………………………………30
Figure 14.Submenu……………………………………………………………………………………………………31
Figure 15.DetailedList……………………………………………………………………………………………………32
Figure 15.1DetailedList…………………………………………………………………………………………………32
Figure 16.PlaceDetails……………………………………………………………………………………………………33
Figure 16.1.PlaceDetails…………………………………………………………………………………………………33
Figure 17.Maps Activity…………………………………………………………………………………………………..30
Figure 18.Taxi Activity……………………………………………………………………………………………………30
Figure 19.Weather Activity………………………………………………………………………………………………30
Figure 20.Events……………………………………………………………………………………………………………..30
Figure 21.Contact Form……………………………………………………………………………………………………30
Figure 22.Contact Form……………………………………………………………………………………………………30
Tabels’ list
Tabel 1. Work planning……………………………………………………………………………………………………..8
1.Rezumat
1.1 Introducere
Conceptul proiectului este creearea unei aplicații Android de turism folosită cu scopul de a afla informații relevante despre orașul Cluj-Napoca.Accesând această aplicație,utilizatorul va cunoaște care sunt atracțiile principale,viața socială a orașului Cluj Napoca,evenimentele,vremea pe o săptamană,locația exactă in momentul respectiv,istoria,tururi de vizitat precum și informații despre taxi,ca mijloc de transport.In caz că utilizatorul are ceva nelămuriri sau ar vrea sa-și exprime părerea legat de orice,acesta poate trimite un email developerului prin formularul de contact sau poate introduce comentarii.
Termenul "App" este o prescurtare a termenului "application". Acest termen a devenit foarte popular, iar în 2010 a fost propus ca "Cuvântul anului" de catre American Dialect Society. O aplicatie de mobil este un program conceput pentru a rula pe smartphone-uri, tablete și alte dispozitive.
Aplicațiile sunt disponibile online și sunt operate de către proprietarul sistemului de operare mobil, cele mai populare platforme de unde se pot downloada sunt:Apple App Store, Google Play, Windows Phone Store și BlackBerry App World. Unele aplicații sunt gratuite, în timp ce altele pot fi cumpărate. De obicei, acestea sunt descărcate de pe platforma, dar uneori acestea pot fi descărcate pe laptop-uri sau computere desktop.Dezvoltarea de aplicații pentru dispozitive mobile necesită luarea în considerare a constrângerilor și caracteristicilor acestor dispozitive. Dispozitive mobile sunt mentinute de baterie,au procesoare mai puternice decât calculatoarele personale și au de asemenea, mai multe caracteristici, cum ar fi detectarea locației și camere video/foto. Dezvoltatorii trebuie, de asemenea, să ia în considerare o gamă largă de dimensiuni pentru ecran, specificații hardware și configurații din cauza concurenței mari în software. Implementarea aplicațiilor mobile necesită utilizarea de medii de dezvoltare integrate,specializate. Aplicațiile mobile sunt mai întâi testate în mediul de dezvoltare, folosind emulatoare și ulterior supuse unor teste practice. Emulatoarele oferă un mod ieftin de a testa aplicații pe telefoanele mobile, la care dezvoltatorii nu pot avea acces fizic.
1.2 Sistemul de operare Android
Android este un sistem de operare destinat dispozitivelor mobile care are la bază sistemul de operare Linux Kernel. Android a fost dezvoltat la inceput de către Google, urmand ca mai apoi să fie lansat ca produs al aliantei Open Handset Alliance. OHA a fost inființată in 2007 și din cadrul său fac parte si companiile Google, HTC și Nvidia. Inceputurile sistemului datează din anul 2005, când Google a cumparat compania Android. Printre cofondatorii companiei se numară Andy Rubin, cel care a inceput sa lucreze pentru Google și a dezvoltat impreună cu echipa sa sistemul Android după ce compania sa a fost preluată.
Istoria versiunilor sistemului de operare mobil Android a inceput cu lansarea beta Android în noiembrie 2007. Prima versiune comerciala, Android 1.0, a fost lansată în septembrie 2008. Sistemul de operare Android este în curs de dezvoltare în curs de desfășurare de către Google și Open Handset Alliance (OHA) și a văzut o serie de modificari de la lansarea sa inițială. Cea mai recentă actualizare majoră este Android 5.0 "Lollipop", care a fost lansată pe 3 noiembrie 2014. Din aprilie 2009, versiunile Android au fost dezvoltate sub un nume cod, cu tematica din cofetărie care sunt lansate în ordine alfabetică, începând cu Android 1.5 "Cupcake ", în versiunile anterioare 1.0 și 1.1 nu au fost puse sub denumiri specifice de cod.
Versiunile sistemului de operare Android:
Cupcake (1.5)
Donut (1.6)
Eclair (2.0–2.1)
Froyo (2.2–2.2.3)
Gingerbread (2.3–2.3.7)
Honeycomb (3.0–3.2.6)
Ice Cream Sandwich (4.0–4.0.4)
Jelly Bean (4.1–4.3.1)
KitKat (4.4–4.4.4, 4.4W–4.4W.2)
Lollipop (5.0–5.1.1)
1.3 Hardware
Deoarece dispozitivele Android sunt de obicei cu baterii, Androidul este conceput pentru a gestiona memoria (RAM), avand consumul de energie la un nivel minim, în contrast cu sistemele de operare desktop care sunt conectate la sursa nelimitata de energie electrică.
Atunci când o activitate Android nu mai este în folosire, sistemul de operare o va suspenda automat în memorie. Activitatea este încă din punct de vedere tehnic "deschisa",deoarece aplicațiile suspendate consuma resurse (de exemplu, baterie sau putere de procesare) astfel ele rămân inactive în fundal până când sunt necesare din nou. Androidul administrează aplicațiile stocate în memorie în mod automat: atunci când memoria este redusă, sistemul va începe terminarea aplicațiilor și proceselor care au fost inactive pentru o vreme, în ordine inversă, deoarece acestea au fost utilizate ultimele (incepand cu prima cea mai veche).
Principala componentă hardware pentru Android este arhitectura ARM (ARMv7 și arhitecturi ARMv8-A), cu x86 și arhitecturi MIPS.De asemenea, unele dispozitive Android încorporează mai multe componente hardware opționale, inclusiv camere video, GPS, senzori de orientare, de control dedicate pentru jocuri, accelerometre, giroscoape, barometre, magnetometre, senzori de proximitate, senzori de presiune, termometre și ecrane tactile.
1.4 Limbaje folosite
Java, limbaj de programare
Java este un limbaj de programare de calculator, care este bazat pe clase concurente, funcționale, orientate pe obiect. Când a fost creat, a fost destinat sa poate fi compilat in cod Java și sa poată rula pe toate platformele care suportă Java, fară a fi nevoie de recompilare. Aplicațiile Java sunt de obicei compilate in bytecode, care poate rula pe orice mașină virtuală Java (JVM), indiferent de arhitectura de calculator. Din 2015, Java este unul dintre cele mai populare limbaje de programare în utilizare, în special pentru aplicații web client-server, cu un raportate 9 milioane de programatori. Java a fost inițial dezvoltat de James Gosling de la Sun Microsystems (apoi achizitionat de Oracle Corporation) și lansat în 1995 ca o componentă de bază a platformei Java Sun Microsystems. Limbajul implementat seamănă foarte mult cu sintaxa de la C și C ++ și are mai puține facilități de nivel scăzut decât oricare.Compilatoarele originale de implementare de referință Java, mașini virtuale și biblioteci de clasă sunt eliberate de Sun sub licente de proprietate.
Extensible Markup Language (XML)
Extensible Markup Language (XML) este o simplificare a limbajului SGML (din care derivă HTML) și a fost creat pentru transferul de date între aplicații pe internet, descriere structurilor de date. După cum sugerează și numele, este un sistem extensibil de marcare, adică, mai simplu, este un sistem de marcare similar cu HTML, doar că este mult mai bun și mai dinamic, diferența esențială fiind că tagurile nu sunt definite, programatorul putând fiind liber să experimenteze.XML este un format popular pentru schimbul de date pe internet,iar site-urile care actualizează frecvent conținutul lor, cum ar fi site-uri de știri sau bloguri, oferă adesea un feed XML, astfel încât programele externe pot ține pasul cu schimbările de conținut. Încărcarea și parsarea de date XML este o sarcină comună pentru aplicațiile conectate la rețea.
PHP
Acronimul PHP provine de la Hypertext Preprocessor utilizat inițial pentru a produce pagini web dinamice, este folosit pe scară largă în dezvoltarea paginilor și aplicațiilor web. Se folosește în principal impreuna cu HTML, permițând crearea de aplicații independente. Este unul din cele mai importante limbaje de programare web open-source și server-side, existând versiuni disponibile pentru majoritatea web serverelor și pentru toate sistemele de operare. Inițial, limbajul a fost dezvoltat de creatorul său, Rasmus Lerdorf. Odată cu creșterea numărului de utilizatori, dezvoltarea a fost preluată de o nouă entitate, numită The PHP Group (Grupul PHP).
JSON
JSON este un format de reprezentare a datelor între aplicații informatice Este simplu, iar formatul de schimb de date poate fi ușor de citit de oameni și mașini. JSON este un format text independent,acestla rețea.
PHP
Acronimul PHP provine de la Hypertext Preprocessor utilizat inițial pentru a produce pagini web dinamice, este folosit pe scară largă în dezvoltarea paginilor și aplicațiilor web. Se folosește în principal impreuna cu HTML, permițând crearea de aplicații independente. Este unul din cele mai importante limbaje de programare web open-source și server-side, existând versiuni disponibile pentru majoritatea web serverelor și pentru toate sistemele de operare. Inițial, limbajul a fost dezvoltat de creatorul său, Rasmus Lerdorf. Odată cu creșterea numărului de utilizatori, dezvoltarea a fost preluată de o nouă entitate, numită The PHP Group (Grupul PHP).
JSON
JSON este un format de reprezentare a datelor între aplicații informatice Este simplu, iar formatul de schimb de date poate fi ușor de citit de oameni și mașini. JSON este un format text independent,acesta reprezintând datele într-un format text astfel încât să poată fi ușor de analizat si interpretat,fiind utilizat pentru reprezentarea obiectelor și a altor structuri de date și este folosit în special pentru a transmite date structurate prin rețea, procesul purtând numele de serializare. JSON este alternativa mai simplă, mai facilă decât limbajul XML. Eleganța formatului JSON provine din faptul că este un subset al limbajului JavaScript, fiind utilizat alături de acest limbaj. Formatul JSON a fost creat de Douglas Crockford și standardizat prin RFC 4627. Tipul de media pe care trebuie să îl transmită un document JSON este application/json. Extensia fișierelor JSON este .json.
SQL
SQL (Structured Query Language – Limbaj Structurat de Interogare) este un limbaj specific pentru manipularea datelor în sistemele bazelor de date. Acesta are ca scop inserarea datelor, interogații, actualizare și ștergere, modificarea și crearea schemelor, precum și controlul accesului la date. A devenit un standard în domeniu (standardizat ANSI-ISO), fiind cel mai popular limbaj utilizat pentru creearea, modificarea, regăsirea și manipularea datelor .SQL permite atât accesul la conținutul bazelor de date, cât și la structura acestora.
1.5 Structura proiectului
Aplicația a fost creată cu scopul a integra cat mai multe informații utile despre orașul Cluj-Napoca astfel incât să poată fi accesată cat mai ușor de orice utilizator.Proiectul e compus din
nouă activități: Main Activity(activitatea principală de unde utilizatorul poate accesa orice buton reprezentând un anumit domeniu) ,Submenu,DetaiedlList,PlaceDetails,Contact(formularul de contact),Taxi,Events,Weather(vremea),Maps(harta cu locația exactă a utilizatorului in momentul respectiv).Activitatile Submenu,DetailedList si Place Details formează un intreg care face legătura cu baza de date SQL,unde sunt toate tabelele legate de restaurante,cafenele,atracții de vizitat,pub-uri,parcuri si istoricul orașului.Tabelele inglobează poze si informații precise in fiecare categorie.In diagrama (Figura1.) de mai jos se poate observa legatura dintre activitati si cum relationeaza intre ele.
Figura 1.Structura proiectului
1.6 Funcționarea aplicației
La implementarea aplicației au fost utilizate diferite limbaje de programare.In Android Studio a fost utilizat limbajul de programare Java, pentru dezvoltarea activităților, și XML, care este un limbaj de markup specific pentru interfata. Pentru baza de date a fost folosit SQL și legătura dintre aplicație și baza de date a fost făcută în PHP care generează JSON ce este interpretat de Java.In Figura 2. este ilustrata relatia dintre limbajele folosite care inglobeaza aplicația.
Figura 2. Funcționarea aplicației
2. Work planning
3.State of the Art
From 1973 to 1993 mobile phones used embedded systems to control operations.In 1995 the first smartphone,the IBM Simon ,had a touchscreen,email and PDA features.
The idea of creating applications on mobile devices was originally thought in Java ME Technology.In 1999 Java released J2ME to create such an environment for developing mobile applications,which is still the preffered technology.Windows Mobile appeared in April 2000 and Symbian in 1998 which formed a partnership between Ericsson,Nokia,Motorola and Psion.
Android based on Linux Kernel is from Goole and it has the largest installed base worldwide on smartphones.It is free and open source software being the most popular operating system.The last version of Android is Lollipop 5.x.x.IOS is the second largest installed base with closed source and propietary, having large profits due to extreme price competition between Android manufacturers.It’s last version is IOS 8.x.Windows phone is from Microsoft,being closed source and propietary and is the third largest installed base with the last version Windows Phone 8.1.
Mobile apps were originally offered for general productivity and information retrieval, including email, calendar, contacts, stock market and weather information. However, public demand and the availability of developer tools became rapid expansion into other categories, such as those handled by desktop packages. As with other software, the explosion in number and variety of apps led to the creation of a wide range of review, recommendation including blogs, magazines, and dedicated online app-discovery services. In 2014 government agencies began trying to regulate and curate apps, particularly medical apps.
The popularity of mobile apps has continued to rise, as their usage has become increasingly prevalent across mobile phone users. A May 2012 study reported that during the previous quarter, more mobile subscribers used apps than browsed the web on their devices: 51.1% vs. 49.8% respectively. Researchers found that usage of mobile apps strongly correlates with user context and depends on user's location and time of the day.
Mobile applications can be put in three phases of development. The most persuasive concept is the idea of the “card” as it can dominate customer’s attention and experience with practical information. Secondly, mobile is moving out of the pocket and becoming wearable with the growth of wearable tech, the need for intelligent aggregation of content will fuel app innovation. One possible future is that apps as we know them will eventually cease to exist at all. Thirdly, the idea of multiscreen could become “every-screen”.
App developers won’t design for desktop and mobile any more. They will design a single solution that will stretch across any internet connected terminal. That brings back to the concept of cards and how content presented in this way could work well for users on almost any type of screen and be meaningful.
As a conclusion the future of Android applications may seem bright and shiny, but there will always appear new technologies which will put the old ones in shadow. Android applications could be developed for new devices that can stretch unlimited possibilities for humankind.
4.Theoretical Fundamentals
4.1 General considerations
The term "app" derives from the word "application ". It has become very popular and in 2010 was listed as "Word of the Year" by the American Dialect Society. A mobile app is a computer program created to run on smartphones, tablets and any other mobile devices. Apps are available through application distribution platform, which began appearing in 2008 and are typically operated by the owner of the mobile operating system, such as the Apple App Store, Google Play, Windows Phone Store, and BlackBerry App World. Some apps are free to download, while others can be bought. Developing apps for mobile devices requires considering the constraints and features of these devices. Mobile devices function on battery and have less powerful processors than personal computers and also have more features such as location detection and photo/video cameras. Developers also have to take into consideration a wide area of screen sizes, hardware specifications and configurations because of extreme competition in mobile software and changes within each of the platforms. Mobile application development requires use of specialized integrated development environments. Mobile apps are first tested within the development environment using emulators and later tested in practice. Emulators represent an inexpensive and easy way to test applications on mobile phones to which developers may not have physical access.
4.2 Mobile operating systems
A mobile operating system is used for smartphones, tablets, phablets or other mobile devices. Mobile operating systems combine features of operating system with other features for mobile. It usually includes most of the following considered essential in modern mobile systems such as a touchscreen, cellular, Bluetooth, Wi-Fi, GPS mobile navigation, photo camera, video camera, speech recognition, voice recorder, music player, near field communication and infrared. There are a lot of operating systems for mobile devices and are categorized in discontinued software platforms and current software platforms. The most important discontinued operating systems are Symbian and Windows Mobile, while the most used current platforms are Android, iOS, Windows Phone and BlackBerry.
4.2.1 Symbian
The Symbian platform was developed by Nokia for some models of smartphones and is proprietary software. The operating system was discontinued in 2012, although a version for basic phones was still developed until July 2014. Microsoft officially closed the platform in favor of Windows Phone after the acquisition of Nokia.
4.2.2 Windows Mobile
Windows Mobile is a discontinued operating system from Microsoft and it was replaced with Windows Phone. Also, it is closed source and proprietary. The two improved versions of this operating system, Windows Mobile 6 Professional (for touch screen devices) and Windows Mobile 6 Standard, were introduced in February 2007. It was criticized for having a user interface which is not optimized for touch input by fingers. However, unlike iOS, it supports both touch screen and physical keyboard configurations.
4.2.3 BlackBerry
BlackBerry 10 (based on the QNX OS) is current software platform from BlackBerry. As a smart phone OS, it is closed source and proprietary. It is used mostly by government employees. BlackBerry 10 is the next generation platform for BlackBerry smartphones and tablets. All phones and tablets are manufactured by Blackberry itself. Once one of the dominant platforms in the world, its global market share has been reduced to 0.4% by the end of 2014.
Current BlackBerry 10's version list:
BlackBerry 10.0
BlackBerry 10.1
BlackBerry 10.2
BlackBerry 10.3 (Major UI revamp)
4.2.4 Windows Phone
Windows Phone is current software platform from Microsoft and it is closed source and proprietary. It has third largest installed base on smartphones behind Android and iOS. On February 15, 2010, Microsoft unveiled its next-generation mobile OS, Windows Phone. The new mobile OS includes a completely new UI inspired by Microsoft. It includes full integration of Microsoft services such as OneDrive and Office, Xbox Music, Xbox Video, Xbox Live games and Bing, but also integrates with many other non-Microsoft services such as Facebook and Google accounts. Windows Phone devices are made primarily by Nokia, along with HTC, Samsung. As of 21 January 2015, Microsoft has announced that the Windows Phone brand will be phased out and replaced with Windows 10 Mobile. It will primarily aim to bring tighter integration and unification with its PC counterpart Windows 10, and provide a platform for both smartphones, and small tablets under 8 inches in screen size. By the end of 2014, Windows Phone global market share was 2.7%.
Current Windows Phone's version list:
Windows Phone 7
Windows Phone 7.5
Windows Phone 7.8
Windows Phone 8 (GDR1, GDR2 & GDR3)
Windows Phone 8.1 (GDR1 & GDR2)
iOS
iOS (previously known as iPhone OS) is a current software platform from Apple Inc.It has the second largest installed base worldwide on smartphones, but the largest profits, due to aggressive price competition between Android-based manufacturers. It is closed source and proprietary. The Apple iPhone, iPod Touch, iPad and second-generation Apple TV all use iOS, which is derived from OS X.Currently all iOS devices are developed by Apple and manufactured by Foxconn or another of Apple's partners.By the end of 2014, iOS global market share was 14.8%.
Current iOS's version list:
iPhone OS 1.x
iPhone OS 2.x
iPhone OS 3.x
iOS 4.x
iOS 5.x
iOS 6.x
iOS 7.x (Major UI revamp)
iOS 8.x
4.2.6 Android
Android is a current software platform from Google Inc. It has the largest installed base worldwide on smartphones. In fact it is the most popular operating system for general purpose computers. Android is free and open software while most commonly in actual devices, a large amount of proprietary software is bundled with it (such as Play Store, Google Search, Google Play Services, Google Music) are licensed proprietary, closed source applications and contract (join the Open Handset Alliance) not to manufacture cellulars that replace Google applications or services.In 2006, Android, iOS and Windows Phone did not exist and just 64 million smartphones were sold. In 2014, more than a billion smartphones were sold and global market share was 85% for Android, 11% for iOS, 3% for Windows Phone and remaining 1% for all other platforms.
Figure 1.World-wide smartphone sales
Technical analysis of Android OS
This platform can be used in specialized user interfaces for television (Android TV),car(Android Auto) and wrist watchers (Android Wear). The OS uses touch inputs actions like swiping, tapping, pinching used on smartscreens with virtual keyboards. The market store of Android is Google Play where there are more than 1 million apps.
Android Inc.was founded in Palo Alto, Califonia in October 2003 by Andy Rubin,Rich Miner,Nick Sears and Chris White. The early intentions of the company were to develop an advanced operating system for digital cameras. Though, when it was realized that the market for the devices was not large enough, the company diverted its efforts toward producing smatphone operating system that would rival Symbian and Microsoft Windows Mobile.
Applications ("apps"), that extend the functionality of devices, are written primarily in the Java programming using the Android software development kit (SDK).
The SDK includes a comprehensive set of development tools, including a debugger, software libraries, a handset emulator, documentation, sample code, and tutorials.
Initially, Google's supported integrated development environment(IDE) was Eclipse using the Android Development Tools (ADT) plugin. In December 2014, Google released Android Studio, based on IntelliJ IDEA, as its primary IDE for Android application development.
4.3.1 Hardware
Since Android devices are usually battery-powered, Android is designed to manage memory (RAM) to keep power consumption at a minimum, in contrast to desktop operating systems which generally means they are connected to unlimited source of electricity.
When an Android application is no longer in use, the system will automatically suspend it in memory. While the application is still technically "open", suspended applications consume no resources (for example, battery power or processing power) and stay idle in the background until needed again. Android manages the applications stored in memory automatically: when memory is low, the system will begin killing applications and processes that have been inactive for a while, in reverse order since they were last used (oldest first). This process is designed to be invisible to the user, so that users do not need to manage memory or the killing of applications themselves.
The main hardware platform for Android is the ARM architecture (ARMv7 and ARMv8-A architectures),with x86 and MIPS architectures.
Officially supported Android devices incorporate many optional hardware components, including video cameras, GPS, orientation sensors, dedicated gaming controls, accelerometers,gyroscopes,
barometers, magnetometers, proximity sensors, pressure sensors, thermometers, and touchscreens.
Figure 2. ARM architecture
4.3.2 Update versions
Google provides major incremental upgrades to Android every six to nine months, with confectionery-themed names. The latest major release is Android 5.0 "Lollipop".Compared to its chief rival mobile operating system, namely iOS, Android updates are typically slow to reach actual devices.The version history of the Android operating system began with the release of the Android beta in November 2007.Android is under ongoing development by Google and the Open Handset Alliance (OHA), and has seen a number of updates to its base operating system since its initial release.The most recent major Android update is Android 5.0 "Lollipop", which was released on November 3, 2014. Since April 2009, Android versions have been developed under a confectionery-themed code name and released in alphabetical order, beginning with Android 1.5 "Cupcake".The earlier versions 1.0 and 1.1 were not released under specific code names.The development of Android started in 2003 by Android, Inc., which was purchased by Google in 2005.The versions that were implemented until now are:
Alpha
There were at least two internal releases of the software inside Google and the OHA, before the beta version was released in November 2007. For the milestones in internal releases, names of fictional robots were chosen, with various releases named "Astro Boy", "Bender" and "R2-D2". Dan Morrill created some of the first mascot logos, but the current green Android logo was designed by Irina Blok. The project manager, Ryan Gibson, conceived the confectionary-themed naming scheme that has been used for the majority of the public releases, starting with Android 1.5 "Cupcake".
Beta
The beta was released on November 5, 2007,while the software development kit(SDK) was introduced in November 12, 2007.The November 5 date is popularly celebrated as Android's "birthday".Last version was in September 23, 2008: 1.0-r1.
Cupcake (1.5)
It was the first one that had a code name for a delicious dessert, this was Cupcake in April 2009. It improved support for videos, added a home screen architecture, application widgets, copy and paste, the web browser and many other new features.
▪ Donut (1.6)
It was released in September of 2009, it expanded the number of gestures available for multi touch devices and added an integrated image gallery.
Eclair (2.0–2.1)
Eclair came along in October of 2009, that was version 2.0, and it added support for multiple Google accounts, upgraded to Bluetooth 2.1, added support for Microsoft Exchange, search of SMS messages and supported more screen sizes to better support the variety of devices that were coming on to the market.
Froyo (2.2–2.2.3)
This is the most recent version of Android,that is still actively used, that is on devices that's actually in people's hands. It was released in May of 2009 and it significantly speeded up the operating system, and improved memory management. In Chrome, the new JavaScript engine named V8 was added and features were added including USB tethering and Wi-Fi hotspots.
Gingerbread (2.3–2.3.7)
Gingerbread, came along in December of 2010 and this is the dominant version of the operating system that's still used on low memory, low power devices.Gingerbread added a concurrent garbage collector, video and audio improvements, NFC or near field communication, and enhancements to the clipboard. Around this time, Android tablets started appearing.
Honeycomb (3.0–3.2.6)
It came along in February of 2011. It was specifically optimized for tablets and included the new fragments API, the action bar, which is very important to modern Android apps.The Honeycomb operating system was popular on tablets, and for a short time,developers had to build two distinct operating systems, Gingerbread for phones, and Honeycomb for tablets.
Ice Cream Sandwich (4.0–4.0.4)
Ice Cream Sandwich came along, in October of 2011. Ice Cream Sandwich, or version 4.0, unified the SDKs for tablets and smartphones and added improved audio support and a customizable launcher environment.
Jelly Bean (4.1–4.3.1)
There are three variants of Jelly Bean, version 4.1 improved performance and it was known as "Project Butter", as in, smooth like butter. Version 4.2, released in November 2012, improved the camera support, added multi-user support on tablets and added a unified interface layout engine, and 4.3 which came along in the summer of 2013, still named Jelly Bean, added Bluetooth low energy, improved gaming graphics, and more.
▪ KitKat (4.4–4.4.4, 4.4W–4.4W.2)
It was released in October 2013.Version 4.4 add significant new tools for memory and power management, with the ultimate goal of having a single operating system for both powerful tablets, and modern phones and less costly low powered and low memory devices.
▪ Lollipop (5.0–5.1.1)
The next version is Android 5.0 "Lollipop" under the codename "Android L" on June 25, 2014, during Google I/O. It became available as official over-the-air (OTA) updates on November 12, 2014, for select devices that run distributions of Android serviced by Google, including Nexus and Google Play edition devices. Its source code was made available on November 3, 2014. Lollipop features a redesigned user interface built around a responsive design language referred to as "material design". Other changes include improvements to the notifications, which can be accessed from the lockscreen and displayed within applications as top-of-the-screen banners. Furthermore, Google made internal changes to the platform, with the Android Runtime (ART) officially replacing Dalvik for improved application performance, and with changes intended to improve and optimize battery usage.
4.4 Java programming language
Java is a computer programming language that is concurrent, functional,class-based, object-oriented. When created was intended that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. As of 2015, Java is one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language implemented much of its syntax from C and C++, but it has fewer low-level facilities than either of them.The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licences. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 199. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. The language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar. Sun Microsystems released the first public implementation as Java 1.0 in 1995.It promised "Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run Java applets within web pages, and Java quickly became popular. On November 13, 2006, Sun released much of Java as free and open-source software, (FOSS), under the terms of the GNU General Public License (GPL). On May 8, 2007, Sun finished the process, making all of Java's core code available under free software/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright. Current and the last version is Java SE 8 (March 18, 2014).Oracle Corporation is the current owner of the official implementation of the Java SE platform, following their acquisition of Sun Microsystems on January 27, 2010. This implementation is based on the original implementation of Java by Sun. The Oracle implementation is packaged into two different distributions: The Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end users, and the Java Development Kit (JDK), which is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger. Java uses an automatic garbage collector to manage memory in the object lifecycle. The programmer determines when objects are created, and the Java runtime is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the unreachable memory becomes eligible to be freed automatically by the garbage collector. Something similar to a memory leak may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use. If methods for a nonexistent object are called, a "null pointer exception" is thrown.One of the ideas behind Java's automatic memory management model is that programmers can be spared the burden of having to perform manual memory management. In some languages, memory for the creation of objects is implicitly allocated on the stack, or explicitly allocated and deallocated from the heap. In the latter case the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a memory leak occurs. If the program attempts to access or deallocate memory that has already been deallocated, the result is undefined and difficult to predict, and the program is likely to become unstable and/or crash. This can be partially remedied by the use of smart pointers, but these add overhead and complexity. Note that garbage collection does not prevent "logical" memory leaks, i.e., those where the memory is still referenced but never used. Garbage collection may happen at any time. Ideally, it will occur when a program is idle. It is guaranteed to be triggered if there is insufficient free memory on the heap to allocate a new object; this can cause a program to stall momentarily. The Java Class Library is the standard library, developed to support application development in Java. It is controlled by Sun Microsystems in cooperation with others through the Java Community Process program. The classes in the Java APIs are organized into separate groups called packages. Each package contains a set of related interfaces, classes and exceptions.
4.5 Extensible Markup Language (XML)
Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format which is both human-readable and machine-readable. It is defined by the W3C's XML 1.0 Specification and by several other related specifications all of which are free open standards. The design goals of XML emphasize simplicity, generality and usability across the Internet. It is a textual data format with strong support via Unicode for different human languages. Although the design of XML focuses on documents, it is widely used for the representation of arbitrary data structures such as those used in web services. Several schema systems exist to aid in the definition of XML-based languages, while many application programming interfaces (APIs) have been developed to aid the processing of XML data. As of 2009, hundreds of document formats using XML syntax have been developed, including RSS, Atom, SOAP, and XHTML. XML-based formats have become the default for many office-productivity tools, including Microsoft Office (Office Open XML), OpenOffice.org and LibreOffice (OpenDocument), and Apple's iWork. XML has also been employed as the base language for communication protocols, such as XMPP. Applications for the Microsoft .NET Framework use XML files for configuration.XML has come into common use for the interchange of data over the Internet. The use of text/xml has been criticized as a potential source of encoding problems and it has been suggested that it should be deprecated.XML documents consist entirely of characters from the Unicode repertoire. Except for a small number of specifically excluded control characters, any character defined by Unicode may appear within the content of an XML document.XML includes facilities for identifying the encoding of the Unicode characters that make up the document, and for expressing characters that, for one reason or another, cannot be used directly.XML has been used to describe structured data and to serialize objects. Various XML-based protocols exist to represent the same kind of data structures as JSON for the same kind of data interchange purposes. Data can be encoded in XML several ways. The most expansive form using tag pairs results in a much larger representation than JSON, but if data is stored in attributes and 'short tag' form where the closing tag is replaced with 'slash-greater than', the representation is often about the same size as JSON or just a little larger. If the data is compressed using an algorithm like gzip, there is little difference because compression is good at saving space when a pattern is repeated.XML also has the concept of schema. This permits strong typing, user-defined types, predefined tags, and formal structure, allowing for formal validation of an XML stream in a portable way.
4.6 PHP
PHP is a server-side scripting language created in 1995 and designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers Originally created by Rasmus Lerdorf in 1994 the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group.While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, which is a recursive backronym.PHP code can be simply mixed with HTML code, or it can be used in combination with various templating engines and web frameworks. PHP code is usually processed by a PHP interpreter, which is usually implemented as a web server's native module or a Common Gateway Interface (CGI) executable. After the PHP code is interpreted and executed, the web server sends resulting output to its client, usually in form of a part of the generated web page; for example, PHP code can generate a web page's HTML code, an image, or some other data. The canonical PHP interpreter, powered by the Zend Engine, is free software released under the PHP License. PHP has been widely ported and can be deployed on most web servers on almost every operating system and platform, free of charge. Despite its popularity, no written specification or standard existed for the PHP language until 2014, leaving the canonical PHP interpreter as a de facto standard. Since 2014, there is ongoing work on creating a formal PHP specification. PHP is a general-purpose scripting language that is especially suited to server-side web development, in which case PHP generally runs on a web server. Any PHP code in a requested file is executed by the PHP runtime, usually to create dynamic web page content or dynamic images used on websites or elsewhere. It can also be used for command-line scripting and client-side graphical user interface (GUI) applications. PHP can be deployed on most web servers, many operating systems and platforms, and can be used with many relational database management systems (RDBMS). Most web hosting providers support PHP for use by their clients. It is available free of charge, and the PHP Group provides the complete source code for users to build, customize and extend for their own use..PHP acts primarily as a filter taking input from a file or stream containing text and/or PHP instructions and outputting another stream of data. Most commonly the output will be HTML, although it could be JSON, XML or binary data such as image or audio formats. PHP includes various free and open-source libraries in its source distribution, or uses them in resulting PHP binary builds. PHP is fundamentally an Internet-aware system with built-in modules for accessing File Transfer Protocol (FTP) servers and many database servers, including PostgreSQL, MySQL, Microsoft SQL Server and SQLite (which is an embedded database), LDAP servers, and others.Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.As of 2014, work is underway on a new major PHP version named PHP 7. Beginning on June 28, 2011, the PHP Group began following a timeline for when new versions of PHP will be released. Under this timeline, at least one release should occur every month. Once per year, a minor release should occur which can include new features. Every minor release should at least have two years of security and bug fixes, followed by at least one year of security-only fixes, for a total of a three-year release process for every minor release. No new features (unless small and self-contained) will be introduced into a minor release during the three-year release process.
4.7 JSON
JSON or JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML. Although originally derived from the JavaScript scripting language, JSON is a language-independent data format. Code for parsing and generating JSON data is readily available in many programming languages. The JSON format was originally specified by Douglas Crockford. The official Internet media type for JSON is application/json. The JSON filename extension is .json. JSON grew out of a need for stateful, real-time server-to-browser communication without using browser plugins such as Flash or Java applets, which were the dominant method in the early 2000s.Douglas Crockford was the first to specify and popularize the JSON format. The XML encoding may therefore be comparable in length to the equivalent JSON encoding.
4.8 SQL
SQL(Structured Query Language) is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS), or for stream processing in a relational data stream management system (RDSMS). The scope of SQL includes data insert, query, update and delete, schema creation and modification, and data access control. SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987. Despite the existence of such standards, though, most SQL code is not completely portable among different database systems without adjustments. SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. The SQL standard has gone through a number of revisions and the last version is SQL:2011.
5.Implementation
For developing Cluj-Napoca Android App was used Android Studio,based on IntelliJIDEA software in Windows 8, 64 bit.
5.1 Android Studio
Android Studio is an integrated development environment(IDE) for programming on the Android platform. It was announced on May 16, 2013 at the Google I/O conference by Google’s Product Manager, Katherine Chou that Android Studio is freely available under the Apache License 2.0.Android Studio was in early access preview stage starting from version 0.1 in May 2013, then entered beta stage starting from version 0.8 which was released in June 2014.The first stable build was released in December 2014, starting from version 1.0.This program is based on JetBrains' IntelliJ IDEA software, and it is designed specifically for Android development.It is available for download on Windows, Mac OS X and Linux and replaced Eclipse Android Development Tools (ADT) as Google's primary IDE for native Android application development.
The following features are provided in the current version:
Live Layout: WYSIWYG Editor – Live Coding – Real-time App Rendering.[10]
Gradle-based build support.
Android-specific refactoring and quick fixes.
Lint tools to catch performance, usability, version compatibility and other problems.
ProGuard and app-signing capabilities.
Template-based wizards to create common Android designs and components.
A rich layout editor that allows users to drag-and-drop UI components, option to preview layouts on multiple screen configurations.
Support for building Android Wear apps
Built-in support for Google Cloud Platform, enabling integration with Google Cloud Messaging and App Engine
5.2 Structure of the Android application
This section of the document will cover the structural development, design of the user interface and also any kind of functions used in building the app. An Android project is made to help develop a single Android app, and it has a specific structure with a set of directory and file names that are always the same. The first folder is the source folder, written src. This contains the Java code. There's a package that contains classes representing the app's activities. This is the base package and this package is the globally unique ID for the app. The package is registered in the Android Manifest file. It's in the root elements package attribute and the package must be universally unique because it's used by the operating system to uniquely identify the app. Next is the gen folder, this contains classes that are generated automatically during development. One of the most important is simply named R, it has nested classes and fields representing resources that are bundled with the application. When developing in Eclipse, it is automatically running a server that's running in the background and watching the res directory and its subdirectories. Whenever adding or changing a resource, such as this graphic, or an XML file, the R class is automatically regenerated. Next is the SDK folder which points to a jar file that's a part of the SDK installation. The Android private libraries include one reference, android-support-v4.jar. This is called the Android support library and it contains packages and classes, that let emulate modern features of Android apps, on older versions of the Android operating system. Next is the assets folder, which is empty by default. The assets folder can contain any files the developer wants to include in the project that don't have to be directly addressable as Java objects. Unlike the res directory, which has directories and files that map to classes and fields, in the generated R class, these files are just packaged with the app. The bin directory is like the gen directory, it will include compiled files including .apk files that contain the compiled class files from Java code, jar files for libraries the app uses, and other critical resources. The res directory, as previously described, contains a variety of files that define the app's appearance and behavior. Graphic files are placed in the drawable directories. These directories are named to indicate which screen their contents are for. The layout, menu, and values directories contain XML files. Layout has files that control the layout of the app's screens. Menu has files that declare menu and action bar items. Values has files for strings, dimensions, and styles. Including anim for animation resources, and color, for predefined colors. Finally, there's the all-important manifest file. This is an XML file, which always has the same name, AndroidManifest.xml. This is where developer will set the app's identity, control how it appears on an Android device's start screen, and declare its activities and other capabilities. A lot of an Android app's behavior is managed here, rather than in Java code.
Figure 3.Android Studio Software
5.2.1 How it works?
The concept of the project is to create a tourism Android application used in order to find relevant information about the city of Cluj- Napoca. Accessing this application , the user will know which are the main attractions, social life of the city of Cluj Napoca , events , weather for a week, exact location, history of the town , tours and taxi information as means of transport. In case that the user has some queries or would like to express any opinion related ,he or she can send an email via the contact form or enter comments .
The application was created with the aim to integrate useful information about the city Cluj-Napoca so that it can be accessed more easily by any user. The project is composed of nine activities: Main Activity ( main screen where the user can access any button representing a particular area ) , Submenu , DetaiedlList , PlaceDetails , Contact ( contact form ) , Taxi, Events, Weather,Maps ( map with the exact location).The activities: Submenu, DetailedList and Place Details form a whole that connects to SQL database where all tables are linked to each other. Tables contain categories ,each having the specific image and information.The structure of the application can be seen in Figure 4,which is the diagram of all the activites involved.
Figure 4.Structure of the application
In implementing Cluj Napoca app were used different computer languages. In Android Studio was used Java programming language, used for developing the activities, and XML, which is a markup language specific for design interface. For the database was used SQL and the link between the app and database was made in PHP which generates JSON and then interpreted by Java .In the figure below is ilustrated how these computer languages relate with each other, in order for the application to work properly. In figure 5 it is shown how these languages interact with each other.
Figure 5.Computer languages involved
For transferring the information was used HTTP protocol from program to database and reverse. The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. Hypertext is structured text that uses logical links (hyperlinks) between nodes containing text. HTTP is the protocol to exchange or transfer hypertext.
When the application was started to be implemented, it was known that it needed a database, where must be put all the interests, facts, history, places and comments involving the city Cluj-Napoca. A hosting server was necessary, to create the tables that link the application with the database. During the searching for a server, there were encountered some issues regarding which one is the most suitable to choose. For the moment, the database is available on a free hosting server, maintained by www.000webhost.com. In the database were created three tables, one entitled “categories” so that the information can be found by id, title and submenu. The other table is “pointsofinterest” with the id, category_id, image_name, title and text. The last table is for comments, any user can share his experience or opinion regarding the points of interest. The diagram illustrating the tables from the database is in shown in Figure 6.
Figure 6.Tables from the database
The way the database connects with the program is through PHP. There are two files of PHP api.php and model.php. In the api file there is a switch structure with the cases of the functions involved. In the model.php are presented the methods necessary for the Model.java class to make the connection with the database through some SQL instructions. As mentioned before in Theoretical Fundamentals SQL is a special-purpose programming language designed for managing data held in a relational database management system or for stream processing in a relational data stream management system. The scope of SQL includes data insert, query, update and delete, schema creation and modification, and data access control. It was used the SELECT statement to select data from a database. In the execute_query function is established the connection with the host and the database. The diagram with all the functions from the Model.php can be observed in Figure 7.
Figure 7. PHP functions
The function get_submenu() is used to get the list of submenus, to create the submenu activity with the proper buttons. The Url example generates a JSON:
http://clujnapoca.uphero.com/api.php?action=get_submenu&submenu=attractions
JSONgenerated:{"status":"success","data":[["1","Churches","attractions"],["2","Monuments","attractions"],["3","Museums","attractions"],["4","Entertainment","attractions"]]}
For the url “http://clujnapoca.uphero.com/api.php?action=get_submenu&submenu=dsadsa”
when an error appears, it returns this:
{"status":"fail","message":"the submenu was not found in the database"}
Actions contain the string that identifies the API action. Submenu is the identifier for the submenu, that the developer wants to retrieve from the database. To query the database from submenu, was used SQL:SELECT*FROM categories WHERE submenu=’$submenu’. This retrieves the submenu from the database, and with the retrieved data, it creates a JSON to return as the HTTP Response. Example of returnated JSON is in Figure 8.
Figure 8.Example of generated JSON
The function get_pointsofinterest() behaves the same as get_submenu,but instead of retrieving the submenu,it get the points of interests.The SQL query is " SELECT * FROM pointsofinterest WHERE category_id='$category_id'.
The function get_single_pointofinterest() uses " SELECT * FROM pointsofinterest WHERE id='$poi_id'" and for the comments to be put in the descendant order: "SELECT * FROM comments WHERE pointofinterest_id = '$poi_id' ORDER BY id DESC ".In this way the last comment will be seen first by any user.
The function is used to send the message created by the user in the Contact Form to the developer’s email.
Function add_comment_to_poi(),as the name implies, adds all the comments made by the user in the database.
The helper functions for the PHP Model are the execute_query(), success_response() and fail_response().These functions helps the programmer to connect to the database and to find out if there are any problems.Execute_query() gets a query string as a parameter and it executes and return the result of the database call. Success and fail response functions get an array as a parameter,creates a JSON which contains the status of the HTTP call and add the received data as a parameter to the JSON.
In the next section of the chapter will be presented the Java classes and the activities involved in the application. All the actions from these classes are implemented with the events handlers and listeners.
Event handling
Change in the state of an object is known how the event describes the change in state of source. Events are generated as result of user interaction with the graphical user interface components. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen.
The Event listener represents the interfaces responsible to handle events. Java provides us various Event listener classes but we will discuss those which are more frequently used. Every method of an event listener method has a single argument as an object which is subclass of EventObject class. For example, mouse event listener methods will accept instance of MouseEvent, where MouseEvent derives from EventObject.
All the events and listeners are very important in each Java project, because they represent the action the developer wants to create and has to function.
The event handlers with all the used Java functions and activities can be observed in Figure 9.In this project the most important used events handlers are handleMenuItemClick() and OnTouchEvent().The handleMenuItemClick() event has the role to be able to go to the home interface of the application, contact form or to exit it, by just clicking on the submenu bar from the upper side of the application, wherever the user is in the application. The home button is the green star icon which can be observed in Figure 9.The image is situated in the res folder,mipmap and drawable subfolder.
Figure 9.Home Icon
The Java classes and the developed activities are made in Android Studio. As it can be observed in Figure 9., the activities entitled Contact, DetailedList, PlaceDetails and Submenu are all linked to the Model.java Class which connects to the database from the external server. The rest of the activities are independent.
Figure 10. Diagram of Java Classes
Before exploring the activities involved in the application, it must be understood the lifecycle of a general activity. The main functions of any activity are illustrated below in Figure 10.
Figure 11. Cycle of Activity
5.2.1 Main activity
protected void onCreate(Bundle savedInstanceState);
This function is called when the activity is first created. This is where the developer should do all of the normal static set up: create views, bind data to lists. This method also provides the developer with a Bundle containing the activity's previously frozen state, if there was one. It is always followed by onStart().
Bundle is used to save & recover state information for the activity. In instances like orientation changes or killing of the app or any other scenario that leads to calling of onCreate() again, the savedInstanceState bundle can be used to reload the previous state information.
public void gotoActivity(View view);
This function is made to link the buttons: Attractions,Social,Food,About,Tours,Shopping to the activities:Submenu,DetailsList,PlaceDetails in order for the program to find fast de requested task.
The below functions each link the activity with the button accessed by the user:
public void gotToWeather(View view);
public void gotoTaxi(View view);
public void gotoContact(View view);
public void gotoExit(View view);
public void gotoMap(View view;
public void gotoEvents(View view);
As it was mentioned before, in Main Activity are englobed al the buttons that directs the user in the desired option.
The user can choose to read and find out more about the principal attractions,social life,best restaurants,weather on seven days,map to find out the exact location,tours,taxi,events and shopping.A usual tourist can find out almost everything of city Cluj-Napoca just by accessing this application.
The design of this activity was implemented in the activity_main .xml,in a RelativeLayout having widgets with the right dimensions,made specific to appear in a friendly interface for any user.
Each button will conduct the user to the desired domain. If the user has any questions about the application can anytime send an email through the contact form to get in touch with the developer. If the user wants to close the application, the exit button will make it stop.
Figure 12.Main Activity
5.2.2 Contact
In this activity is used OnClickListener which when activated,it enables the button the user presses, to send the message the user created.The implemented method is:
buttonSend.setOnClickListener(new OnClickListener();
The used functions are:
show.toast();
A toast is a view containing a quick little message for the user. When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. A toast provides simple feedback about an operation in a small pop-up. It only fills the amount of space required for the message and the current activity remains visible and interactive.
First, it must be instantiated a Toast object with one of the makeText() methods. This method takes three parameters: the application Context, the text message, and the duration for the toast. It returns a properly initialized Toast object. The toast notification can be displayed with show();
getText();
This method can be used to retrieve the data, a String variable to store the data.
getApplicationContext();
Returns the context for the entire application (the process all the Activities are running inside of).
The contact form is constructed in such a way that if the user wants to write in just one space,is obliged to complete all the required fields because the developer needs at least the name,message and email to be able to reply.After completing the form,the user will press the send button in order for the message to be sent.In the shorthet time possible,the developer will send back an answer regarding the message received.
Figure 13.Contact Form
5.2.3 Submenu
The submenu interface for attractions looks like in Figure 14.The design was made in the submenu.xml.There are the TextView and ScrollView widgets, all inserted in a RelativeLayout.
The chosen colours for the buttons are inserted in the Submenu.java class. The colours were chosen in nounce of grey and green so that the interface could look friendly and easy to use for any user.This activity uses the onCreateOptionsMenu(Menu menu) function to give the user the freedom of navigating through the application as he/she wants.In the upper side of the interface,it can be observed that it has two buttons.One is the home icon button,which once activated it directs the user to the home interface.The other button gives the user the option of choosing between going to the Contact Form and exist the application.The function which enables these actions is entitled public void handleMenuitemClick(MenuItem menuitem) and it can be observed in Figure 15.1
The dimensions were chosen from intuition so that the interface could be as firendly as possible for any user.
As it cand be observed form Figure 14,the submenu has categorised the attractions in Churches,Monuments,Museums and Entertainment. Once clicked the category,the program will direct the user to a list of the chosen category.For example,if the user clicks on the churches button,the application will direct the user to the list of churches in Cluj-Napoca.
In the entertainment section it can be found all that is about nature and having fun regarding Cluj Napoca,from parks to garden.
Submenu is the first activity the application uses when the user clicks on any of the following buttons:Attractions,Food,Social,About,Tours,Shopping.
When the user chooses what he/she wants,the application directs to the DetailedList and after that PlaceDetails activity.All these activities are connected to the external server where is the database with the tables,mentioned before.
Figure 14.Submenu
5.2.4 DetailedList
The interface from this activity consists of large buttons,having title of the interest with its’ corresponding image.In the upper side of the interface is the menu bar,mentioned before,having the function public void handleMenuitemClick(MenuItem menuitem),with the contact form and exit buttons the user can access.
The layout is the same as in submenu.xml being relative an incorporating a TextView for the title together with a ScrollView..
This activity connects,like the submenu and DetailsPlace activity to the database,from the external server through HTTP protocol,requesting and receiving information.
Figure 15.1 DetailedList Figure 15. DetailedList
5.2.5 PlaceDetails
In this activity it is show all the information regardin the interests points.It is the title,the corresponding image and the text.At the bottom the usr can make a comment which will apper the the descendent order,as it can be observed in
Figure 16.
Figure 16.PlaceDetails
Figure 16.1 PlaceDetails
5.2.6 MapsActivity
For creating the map it was used this function:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
}
By pressing the location button,situated in the upper-right side of the app,it directs to the location of the user.After that,the user can use the zoom in and out buttons to find out the place is searching.
Figure 18. Maps Activity
5.2.7 Taxi
In this activity is used OnClickListener which when activated,it enables the button the user presses, to make a call at the requested number.The implemented method is:
PhoneCallListener phoneListener = new PhoneCallListener();
The use listeners for the activity are:
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
The function for the button listener:
// add button listener
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:0744777111"));
startActivity(callIntent1);
}
});
Figure 19.Taxi Activity
Another used function is:public void onCallStateChanged(int state, String incomingNumber);
It is composed from three if clauses regarding CALL_STATE_RINGING, CALL_STATE_OFFHOOK and CALL_STATE_IDLE.These are actions on how the app behaves during the call moment.
5.2.8 Weather
public void showWeatherForDay( int day );
public boolean onTouchEvent(MotionEvent event);
public void nextDay();
public void prevDay();
public String getIconFromWeatherIcon( String icon );
Figure 20.Weather
5.2.9 Events
String e_feed = getResponseFromUrl("http://feeds.feedburner.com/Vinsieu-Cluj-Napoca?format=html")
public static String getResponseFromUrl(String url )
String get_day_from_interval(String interval)
String get_month_name_from_interval (String interval
5.2.11 Manifest
The Android Manifest file is an XML file that describes to the operating system, the application's ID and its capabilities. The name of the file is always the same.
Every application must have an AndroidManifest.xml file in its root directory. The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. Among other things, the manifest does the following:
It names the Java package for the application. The package name serves as a unique identifier for the application.
It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
It determines which processes will host application components.
It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
It also declares the permissions that others are required to have in order to interact with the application's components.
It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
It declares the minimum level of the Android API that the application requires.
It lists the libraries that the application must be linked against.
In Cluj Napoca application there are nine activities,each of them defined in the proper way in the Manifest file.
<android:name=".MainActivity">
<activity android:name=".Submenu" />
<activity android:name=".Contact" />
<activity android:name=".DetailedList" />
<activity android:name=".PlaceDetails" />
<activity android:name=".Events" />
<activity android:name=".Taxi" />
<activity android:name=".Weather" />
<activity android:name=".Maps" />
For the Map activity it was necessary a Google Maps API Key that had to be put in the manifest file.
In the manifest there are also specified the user permissions.In the application were used:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
6.Experimental Results
7.Conclusions
se comentează corespondența dintre rezultatele experimentale obținute și cerințele specificate în tema lucrării.
8.References
(2015) Wikipedia website
http://en.wikipedia.org/wiki/Android_%28operating_system%29
M. Wegmuller, J. P. von der Weid, P. Oberson, and N. Gisin, “High resolution fiber distributed measurements with coherent OFDR,” in Proc. ECOC’00, 2000, paper 11.3.4, p. 109.
R. E. Sorace, V. S. Reinhardt, and S. A. Vaughn, “High-speed digital-to-RF converter,” U.S. Patent 5 668 842, Sep. 16, 1997.
(2007) The IEEE website, http://www.ieee.org/
“PDCA12-70 data sheet,” Opto Speed SA, Mezzovico, Switzerland.
A. Karnik, “Performance of TCP congestion control with rate feedback: TCP/ABR and rate adaptive TCP/IP,” M. Eng. thesis, Indian Institute of Science, Bangalore, India, Jan. 1999.
Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specification, IEEE Std. 802.11, 1997.
Neural Network Toolbox Help, Matlab R2010a.
http://en.wikipedia.org/wiki/SQL
[5]
9.Appendix
9.1 Appendix A – Source code
9.1.1 Main Activity
onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
9.1.2
public void gotoActivity(View view){
/*Intent intent=new Intent(this,Submenu.class);
startActivity(intent);*/
Intent intent = null;
String tag = view.getTag().toString();
int int_tag = Integer.parseInt(tag);
switch( int_tag ){
case 1: //id-ul butonului "Activities"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","attractions");
break;
case 2://id-ul butonului "Social"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","social");
break;
case 3://id-ul butonului "Food"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","food");
break;
case 4://id-ul butonului "Taxi"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","taxi");
break;
case 5://id-ul butonului "Shopping"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","shopping");
break;
case 6://id-ul butonului "Tours"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","tours");
break;
case 7://id-ul butonului "About"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","about");
break;
default:
break;
}
startActivity(intent);
}
public void gotToWeather(View view) {
Intent intent=new Intent(this,Weather.class);
startActivity(intent);
}
public void gotoTaxi(View view) {
Intent intent=new Intent(this,Taxi.class);
startActivity(intent);
}
public void gotoContact(View view) {
Intent intent=new Intent(this,Contact.class);
startActivity(intent);
}
public void gotoExit(View view) {
Intent intent = null;
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
public void gotoMap(View view) {
Intent intent=new Intent(this,MapsActivity.class);
startActivity(intent);
}
public void gotoEvents(View view) {
Intent intent=new Intent(this,Events.class);
startActivity(intent);
}
XML Activity Main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/bk1"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">
<TextView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="79dp"
android:layout_height="116dp"
android:textSize="45sp"
android:textColor="#ffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Cluj"
android:id="@+id/textView"
android:layout_row="6"
android:layout_column="1"
android:layout_rowSpan="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="@string/attractions"
android:onClick="gotoActivity"
android:tag="1"
android:textColor="#ffffffff"
android:id="@+id/button7"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Social"
android:onClick="gotoActivity"
android:tag="2"
android:textColor="#ffffffff"
android:id="@+id/button6"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Food"
android:onClick="gotoActivity"
android:tag="3"
android:textColor="#ffffffff"
android:id="@+id/button5"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="Weather"
android:onClick="gotToWeather"
android:tag="weather"
android:textColor="#ffffffff"
android:id="@+id/button10"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Map"
android:onClick="gotoMap"
android:textColor="#ffffffff"
android:id="@+id/button11"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Taxi"
android:onClick="gotoTaxi"
android:tag="4"
android:textColor="#ffffffff"
android:id="@+id/button2"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="Shopping"
android:onClick="gotoActivity"
android:tag="5"
android:textColor="#ffffffff"
android:id="@+id/button9"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Tours"
android:onClick="gotoActivity"
android:tag="6"
android:textColor="#ffffffff"
android:id="@+id/button12"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Events"
android:onClick="gotoEvents"
android:textColor="#ffffffff"
android:id="@+id/button"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="About"
android:onClick="gotoActivity"
android:tag="7"
android:textColor="#ffffffff"
android:id="@+id/button8"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Contact"
android:tag="contact"
android:onClick="gotoContact"
android:textColor="#ffffffff"
android:id="@+id/button4"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Exit"
android:tag="exit"
android:onClick="gotoExit"
android:textColor="#ffffffff"
android:id="@+id/button3"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="2" />
</GridLayout>
</RelativeLayout>
Contact Activity
public class Contact extends Activity {
Button buttonSend;
EditText textMessage; // mesajul
EditText textName; //numele
EditText textEmail; //numele
Model model;
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
model = new Model();
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
buttonSend = (Button) findViewById(R.id.button16);
textMessage = (EditText) findViewById(R.id.editText);
textName = (EditText) findViewById( R.id.editName );
textEmail = (EditText) findViewById( R.id.editEmail );
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String message = textMessage.getText().toString();
String name = textName.getText().toString();
String email = textEmail.getText().toString();
boolean success = model.send_message_to_dev(name, email, message);
Context context = getApplicationContext();
CharSequence text = "Message sent!";
if(!success) {
text = " Message could not be send ";
}
if( message.length() < 4 ) {
text = "Please fill your message";
}
if( email.length() < 10 ) {
text = "Please fill your email";
}
if( name.length() < 4 ) {
text = "Please fill your name";
}
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
textMessage.setText("Message:");
textEmail.setText("Email:");
textName.setText("Name:");
}
});
}
}
Submenu Activity functions
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.add("Contact"); //your desired title here
item.setIcon(R.drawable.web_hi_res_512); //your desired icon here
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity( new Intent( Submenu.this, Contact.class ) );
return false;
}
});
return true;
}
public void handleMenuitemClick(MenuItem menuitem){
Intent intent = null;
switch (menuitem.getItemId() ){
case R.id.homeico:
intent = new Intent(this, MainActivity.class );
break;
case R.id.action_exit:
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
break;
}
startActivity(intent);
}
PublicDetails Activity
public void handleAddComment(View view){
EditText authorView = (EditText) findViewById( R.id.authorText );
EditText messageView = (EditText) findViewById( R.id.messageText );
String author = authorView.getText().toString();
String message = messageView.getText().toString();
String poi_id = point_of_interest.get("id");
boolean result = model.add_coment_to_point_of_interest(poi_id, author, message);
Context context = getApplicationContext();
CharSequence text = "Comment Added sent!";
if(!result) {
text = " Message could not be send ";
}
if( result ){
LinearLayout commentsView = (LinearLayout) findViewById( R.id.commentsView );
TextView crt_comm_view = new TextView(this);
crt_comm_view.setText( "\n\nauthor: " + author + "\ncomment:" + message +"" );
commentsView.addView(crt_comm_view);
}
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
Maps Activity
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
/**
* Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
* installed) and the map has not already been instantiated.. This will ensure that we only ever
* call {@link #setUpMap()} once when {@link #mMap} is not null.
* <p/>
* If it isn't installed {@link SupportMapFragment} (and
* {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
* install/update the Google Play services APK on their device.
* <p/>
* A user can return to this FragmentActivity after following the prompt and correctly
* installing/updating/enabling the Google Play services. Since the FragmentActivity may not
* have been completely destroyed during this process (it is likely that it would only be
* stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
* method in {@link #onResume()} to guarantee that it will be called.
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.button11))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p/>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
Taxi Activity
public class Taxi extends Activity {
final Context context = this;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.taxi);
Button btn1 = (Button) findViewById(R.id.button23);
Button btn2 = (Button) findViewById(R.id.button24);
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
// add button listener
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:0744777111"));
startActivity(callIntent1);
}
});
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:0765527322"));
startActivity(callIntent1);
}
});
}
//monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
}
Weather Activity
public class Weather extends Activity {
Typeface weatherFont;
private static final String OPEN_WEATHER_MAP_API =
"http://api.openweathermap.org/data/2.5/forecast/daily?q=Cluj&mode=json&units=metric&cnt=7";
List<Map<String, String> > weather_forecast;
int CURRENT_DAY = 0;
boolean swipe_initiated = false;
float swipe_start = 0;
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.weather);
weatherFont = Typeface.createFromAsset( getAssets() , "weather.ttf");
TextView weatherIcon = (TextView) findViewById( R.id.iconTextView );
weatherIcon.setTypeface( weatherFont );
String weather_response = getResponseFromUrl( OPEN_WEATHER_MAP_API );
weather_forecast = new ArrayList<>();
try {
JSONObject forecast_json = new JSONObject( weather_response );
JSONArray daysForecast = forecast_json.getJSONArray("list");
for( int i= 0; i < 7 ; i++ ){
JSONObject crt_day = daysForecast.getJSONObject(i);
Map<String, String> crt_day_map = new HashMap<>();
JSONObject temp = crt_day.getJSONObject("temp");
crt_day_map.put("temp_day", temp.getString("day") );
crt_day_map.put("temp_night", temp.getString("night"));
crt_day_map.put("pressure", crt_day.getString("pressure"));
crt_day_map.put("humidity", crt_day.getString("humidity"));
JSONArray crt_weather = crt_day.getJSONArray("weather");
JSONObject crt_weather_obj = crt_weather.getJSONObject(0);
crt_day_map.put("description", crt_weather_obj.getString("description") );
crt_day_map.put("weather", crt_weather_obj.getString("main") );
crt_day_map.put("icon", crt_weather_obj.getString("icon") );
weather_forecast.add( crt_day_map);
}
} catch (JSONException e) {
e.printStackTrace();
Log.v("Weather", "!!!!!!!!!!!!!!!!!!!!!!!!!!!! Everything WENT WRONG!!!!!!!!!!!");
return;
}
showWeatherForDay(CURRENT_DAY);
}
public void showWeatherForDay( int day ){
Map<String, String> crt_day_map = weather_forecast.get(day);
TextView day_view = (TextView) findViewById( R.id.weather_day );
TextView night_view = (TextView) findViewById( R.id.weather_night );
TextView pressure_view = (TextView) findViewById( R.id.weather_pressure );
TextView humidity_view = (TextView) findViewById( R.id.weather_humidity );
TextView description_view = (TextView) findViewById( R.id.weather_description );
TextView title_view = (TextView) findViewById( R.id.weather_title );
TextView weatherIcon = (TextView) findViewById( R.id.iconTextView );
day_view.setText( "Day: " + crt_day_map.get("temp_day") +" C");
night_view.setText( "Night: " + crt_day_map.get("temp_night")+" C" );
pressure_view.setText( "Pressure: " + crt_day_map.get("pressure") );
humidity_view.setText( "Humidity: " + crt_day_map.get("humidity") );
description_view.setText( "" + crt_day_map.get("description") ); // alegem icon-ul potrivit
weatherIcon.setText( getIconFromWeatherIcon( crt_day_map.get("icon") ) );
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DAY_OF_WEEK);
String day_str = "";
today = today + day;
if( today > 7 ) {
today = today – 7;
}
switch ( today ){
case 1:
day_str = "Sunday";
break;
case 2:
day_str = "Monday";
break;
case 3:
day_str = "Tuesday";
break;
case 4:
day_str = "Wednesday";
break;
case 5:
day_str = "Thursday";
break;
case 6:
day_str = "Friday";
break;
case 7:
day_str = "Saturday";
break;
default:
day_str = " err";
}
title_view.setText( day_str );
// Log.v("Weather", crt_day_map.get("icon") );
}
public static Context getContext(){
return Weather.getContext();
}
public static String getResponseFromUrl(String url ) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
String responseString = out.toString();
out.close();
return responseString;
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch( IOException e ){
return "error" + e.getMessage();
}
}
@Override
public boolean onTouchEvent(MotionEvent event){
int action = MotionEventCompat.getActionMasked(event);
AlphaAnimation anim;
TextView icon_view = (TextView) findViewById( R.id.iconTextView );
switch(action) {
case (MotionEvent.ACTION_DOWN) :
swipe_initiated = true;
swipe_start = event.getRawX();
icon_view.setAlpha(1.0f);
anim = new AlphaAnimation(1.0f, 0.0f);
anim.setDuration(300);
icon_view.startAnimation(anim);
icon_view.setAlpha(0.0f);
return true;
case (MotionEvent.ACTION_UP) :
if( swipe_initiated ){
swipe_initiated = false;
float swipe_end = event.getRawX();
float swipe_diff = swipe_end – swipe_start;
if( Math.abs(swipe_diff) > 300 ) { /// if( swipe_diff < -300 || swipe_diff > 300 )
if ( swipe_diff > 0 ) {
prevDay();
} else {
nextDay();
}
icon_view.setAlpha(0.0f);
anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(300);
icon_view.startAnimation(anim);
icon_view.setAlpha(1.0f);
} else {
icon_view.setAlpha(1.0f);
}
}
return true;
default :
return super.onTouchEvent(event);
}
}
public void nextDay() {
if ( CURRENT_DAY < 6) {
CURRENT_DAY ++ ;
showWeatherForDay( CURRENT_DAY );
}
}
public void prevDay() {
if( CURRENT_DAY == 0 ) {
// return home
} else {
CURRENT_DAY – ;
showWeatherForDay(CURRENT_DAY);
}
}
public String getIconFromWeatherIcon( String icon ) {
switch( icon ) {
case "10d":
return getString( R.string.weather_drizzle );
case "1nd":
return getString( R.string.weather_clear_night );
case "02d":
return getString( R.string.weather_cloudy );
case "01d":
return getString( R.string.weather_sunny );
case "03d":
return getString( R.string.weather_cloudy);
case "05d":
return getString( R.string.weather_rainy );
case "11d":
return getString( R.string.weather_thunder );
case "13d":
return getString( R.string.weather_snowy );
case "50d":
return getString( R.string.weather_foggy );
default:
return getString( R.string.weather_sunny );
}
}
}
References
(2015) Wikipedia website
http://en.wikipedia.org/wiki/Android_%28operating_system%29
M. Wegmuller, J. P. von der Weid, P. Oberson, and N. Gisin, “High resolution fiber distributed measurements with coherent OFDR,” in Proc. ECOC’00, 2000, paper 11.3.4, p. 109.
R. E. Sorace, V. S. Reinhardt, and S. A. Vaughn, “High-speed digital-to-RF converter,” U.S. Patent 5 668 842, Sep. 16, 1997.
(2007) The IEEE website, http://www.ieee.org/
“PDCA12-70 data sheet,” Opto Speed SA, Mezzovico, Switzerland.
A. Karnik, “Performance of TCP congestion control with rate feedback: TCP/ABR and rate adaptive TCP/IP,” M. Eng. thesis, Indian Institute of Science, Bangalore, India, Jan. 1999.
Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specification, IEEE Std. 802.11, 1997.
Neural Network Toolbox Help, Matlab R2010a.
http://en.wikipedia.org/wiki/SQL
[5]
9.Appendix
9.1 Appendix A – Source code
9.1.1 Main Activity
onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
9.1.2
public void gotoActivity(View view){
/*Intent intent=new Intent(this,Submenu.class);
startActivity(intent);*/
Intent intent = null;
String tag = view.getTag().toString();
int int_tag = Integer.parseInt(tag);
switch( int_tag ){
case 1: //id-ul butonului "Activities"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","attractions");
break;
case 2://id-ul butonului "Social"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","social");
break;
case 3://id-ul butonului "Food"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","food");
break;
case 4://id-ul butonului "Taxi"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","taxi");
break;
case 5://id-ul butonului "Shopping"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","shopping");
break;
case 6://id-ul butonului "Tours"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","tours");
break;
case 7://id-ul butonului "About"
intent = new Intent(this, Submenu.class);
intent.putExtra("submenu","about");
break;
default:
break;
}
startActivity(intent);
}
public void gotToWeather(View view) {
Intent intent=new Intent(this,Weather.class);
startActivity(intent);
}
public void gotoTaxi(View view) {
Intent intent=new Intent(this,Taxi.class);
startActivity(intent);
}
public void gotoContact(View view) {
Intent intent=new Intent(this,Contact.class);
startActivity(intent);
}
public void gotoExit(View view) {
Intent intent = null;
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
public void gotoMap(View view) {
Intent intent=new Intent(this,MapsActivity.class);
startActivity(intent);
}
public void gotoEvents(View view) {
Intent intent=new Intent(this,Events.class);
startActivity(intent);
}
XML Activity Main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/bk1"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">
<TextView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="79dp"
android:layout_height="116dp"
android:textSize="45sp"
android:textColor="#ffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Cluj"
android:id="@+id/textView"
android:layout_row="6"
android:layout_column="1"
android:layout_rowSpan="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="@string/attractions"
android:onClick="gotoActivity"
android:tag="1"
android:textColor="#ffffffff"
android:id="@+id/button7"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Social"
android:onClick="gotoActivity"
android:tag="2"
android:textColor="#ffffffff"
android:id="@+id/button6"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Food"
android:onClick="gotoActivity"
android:tag="3"
android:textColor="#ffffffff"
android:id="@+id/button5"
android:layout_row="8"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="Weather"
android:onClick="gotToWeather"
android:tag="weather"
android:textColor="#ffffffff"
android:id="@+id/button10"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Map"
android:onClick="gotoMap"
android:textColor="#ffffffff"
android:id="@+id/button11"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Taxi"
android:onClick="gotoTaxi"
android:tag="4"
android:textColor="#ffffffff"
android:id="@+id/button2"
android:layout_row="9"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="Shopping"
android:onClick="gotoActivity"
android:tag="5"
android:textColor="#ffffffff"
android:id="@+id/button9"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Tours"
android:onClick="gotoActivity"
android:tag="6"
android:textColor="#ffffffff"
android:id="@+id/button12"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Events"
android:onClick="gotoEvents"
android:textColor="#ffffffff"
android:id="@+id/button"
android:layout_row="10"
android:background="@android:color/transparent"
android:layout_column="2" />
<Button
android:layout_width="118dp"
android:layout_height="70dp"
android:text="About"
android:onClick="gotoActivity"
android:tag="7"
android:textColor="#ffffffff"
android:id="@+id/button8"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="0" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Contact"
android:tag="contact"
android:onClick="gotoContact"
android:textColor="#ffffffff"
android:id="@+id/button4"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="1" />
<Button
android:layout_width="110dp"
android:layout_height="70dp"
android:text="Exit"
android:tag="exit"
android:onClick="gotoExit"
android:textColor="#ffffffff"
android:id="@+id/button3"
android:layout_row="11"
android:background="@android:color/transparent"
android:layout_column="2" />
</GridLayout>
</RelativeLayout>
Contact Activity
public class Contact extends Activity {
Button buttonSend;
EditText textMessage; // mesajul
EditText textName; //numele
EditText textEmail; //numele
Model model;
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
model = new Model();
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
buttonSend = (Button) findViewById(R.id.button16);
textMessage = (EditText) findViewById(R.id.editText);
textName = (EditText) findViewById( R.id.editName );
textEmail = (EditText) findViewById( R.id.editEmail );
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String message = textMessage.getText().toString();
String name = textName.getText().toString();
String email = textEmail.getText().toString();
boolean success = model.send_message_to_dev(name, email, message);
Context context = getApplicationContext();
CharSequence text = "Message sent!";
if(!success) {
text = " Message could not be send ";
}
if( message.length() < 4 ) {
text = "Please fill your message";
}
if( email.length() < 10 ) {
text = "Please fill your email";
}
if( name.length() < 4 ) {
text = "Please fill your name";
}
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
textMessage.setText("Message:");
textEmail.setText("Email:");
textName.setText("Name:");
}
});
}
}
Submenu Activity functions
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.add("Contact"); //your desired title here
item.setIcon(R.drawable.web_hi_res_512); //your desired icon here
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity( new Intent( Submenu.this, Contact.class ) );
return false;
}
});
return true;
}
public void handleMenuitemClick(MenuItem menuitem){
Intent intent = null;
switch (menuitem.getItemId() ){
case R.id.homeico:
intent = new Intent(this, MainActivity.class );
break;
case R.id.action_exit:
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
break;
}
startActivity(intent);
}
PublicDetails Activity
public void handleAddComment(View view){
EditText authorView = (EditText) findViewById( R.id.authorText );
EditText messageView = (EditText) findViewById( R.id.messageText );
String author = authorView.getText().toString();
String message = messageView.getText().toString();
String poi_id = point_of_interest.get("id");
boolean result = model.add_coment_to_point_of_interest(poi_id, author, message);
Context context = getApplicationContext();
CharSequence text = "Comment Added sent!";
if(!result) {
text = " Message could not be send ";
}
if( result ){
LinearLayout commentsView = (LinearLayout) findViewById( R.id.commentsView );
TextView crt_comm_view = new TextView(this);
crt_comm_view.setText( "\n\nauthor: " + author + "\ncomment:" + message +"" );
commentsView.addView(crt_comm_view);
}
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
Maps Activity
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
/**
* Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
* installed) and the map has not already been instantiated.. This will ensure that we only ever
* call {@link #setUpMap()} once when {@link #mMap} is not null.
* <p/>
* If it isn't installed {@link SupportMapFragment} (and
* {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
* install/update the Google Play services APK on their device.
* <p/>
* A user can return to this FragmentActivity after following the prompt and correctly
* installing/updating/enabling the Google Play services. Since the FragmentActivity may not
* have been completely destroyed during this process (it is likely that it would only be
* stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
* method in {@link #onResume()} to guarantee that it will be called.
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.button11))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p/>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
Taxi Activity
public class Taxi extends Activity {
final Context context = this;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.taxi);
Button btn1 = (Button) findViewById(R.id.button23);
Button btn2 = (Button) findViewById(R.id.button24);
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
// add button listener
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:0744777111"));
startActivity(callIntent1);
}
});
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:0765527322"));
startActivity(callIntent1);
}
});
}
//monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
}
Weather Activity
public class Weather extends Activity {
Typeface weatherFont;
private static final String OPEN_WEATHER_MAP_API =
"http://api.openweathermap.org/data/2.5/forecast/daily?q=Cluj&mode=json&units=metric&cnt=7";
List<Map<String, String> > weather_forecast;
int CURRENT_DAY = 0;
boolean swipe_initiated = false;
float swipe_start = 0;
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.weather);
weatherFont = Typeface.createFromAsset( getAssets() , "weather.ttf");
TextView weatherIcon = (TextView) findViewById( R.id.iconTextView );
weatherIcon.setTypeface( weatherFont );
String weather_response = getResponseFromUrl( OPEN_WEATHER_MAP_API );
weather_forecast = new ArrayList<>();
try {
JSONObject forecast_json = new JSONObject( weather_response );
JSONArray daysForecast = forecast_json.getJSONArray("list");
for( int i= 0; i < 7 ; i++ ){
JSONObject crt_day = daysForecast.getJSONObject(i);
Map<String, String> crt_day_map = new HashMap<>();
JSONObject temp = crt_day.getJSONObject("temp");
crt_day_map.put("temp_day", temp.getString("day") );
crt_day_map.put("temp_night", temp.getString("night"));
crt_day_map.put("pressure", crt_day.getString("pressure"));
crt_day_map.put("humidity", crt_day.getString("humidity"));
JSONArray crt_weather = crt_day.getJSONArray("weather");
JSONObject crt_weather_obj = crt_weather.getJSONObject(0);
crt_day_map.put("description", crt_weather_obj.getString("description") );
crt_day_map.put("weather", crt_weather_obj.getString("main") );
crt_day_map.put("icon", crt_weather_obj.getString("icon") );
weather_forecast.add( crt_day_map);
}
} catch (JSONException e) {
e.printStackTrace();
Log.v("Weather", "!!!!!!!!!!!!!!!!!!!!!!!!!!!! Everything WENT WRONG!!!!!!!!!!!");
return;
}
showWeatherForDay(CURRENT_DAY);
}
public void showWeatherForDay( int day ){
Map<String, String> crt_day_map = weather_forecast.get(day);
TextView day_view = (TextView) findViewById( R.id.weather_day );
TextView night_view = (TextView) findViewById( R.id.weather_night );
TextView pressure_view = (TextView) findViewById( R.id.weather_pressure );
TextView humidity_view = (TextView) findViewById( R.id.weather_humidity );
TextView description_view = (TextView) findViewById( R.id.weather_description );
TextView title_view = (TextView) findViewById( R.id.weather_title );
TextView weatherIcon = (TextView) findViewById( R.id.iconTextView );
day_view.setText( "Day: " + crt_day_map.get("temp_day") +" C");
night_view.setText( "Night: " + crt_day_map.get("temp_night")+" C" );
pressure_view.setText( "Pressure: " + crt_day_map.get("pressure") );
humidity_view.setText( "Humidity: " + crt_day_map.get("humidity") );
description_view.setText( "" + crt_day_map.get("description") ); // alegem icon-ul potrivit
weatherIcon.setText( getIconFromWeatherIcon( crt_day_map.get("icon") ) );
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DAY_OF_WEEK);
String day_str = "";
today = today + day;
if( today > 7 ) {
today = today – 7;
}
switch ( today ){
case 1:
day_str = "Sunday";
break;
case 2:
day_str = "Monday";
break;
case 3:
day_str = "Tuesday";
break;
case 4:
day_str = "Wednesday";
break;
case 5:
day_str = "Thursday";
break;
case 6:
day_str = "Friday";
break;
case 7:
day_str = "Saturday";
break;
default:
day_str = " err";
}
title_view.setText( day_str );
// Log.v("Weather", crt_day_map.get("icon") );
}
public static Context getContext(){
return Weather.getContext();
}
public static String getResponseFromUrl(String url ) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
String responseString = out.toString();
out.close();
return responseString;
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch( IOException e ){
return "error" + e.getMessage();
}
}
@Override
public boolean onTouchEvent(MotionEvent event){
int action = MotionEventCompat.getActionMasked(event);
AlphaAnimation anim;
TextView icon_view = (TextView) findViewById( R.id.iconTextView );
switch(action) {
case (MotionEvent.ACTION_DOWN) :
swipe_initiated = true;
swipe_start = event.getRawX();
icon_view.setAlpha(1.0f);
anim = new AlphaAnimation(1.0f, 0.0f);
anim.setDuration(300);
icon_view.startAnimation(anim);
icon_view.setAlpha(0.0f);
return true;
case (MotionEvent.ACTION_UP) :
if( swipe_initiated ){
swipe_initiated = false;
float swipe_end = event.getRawX();
float swipe_diff = swipe_end – swipe_start;
if( Math.abs(swipe_diff) > 300 ) { /// if( swipe_diff < -300 || swipe_diff > 300 )
if ( swipe_diff > 0 ) {
prevDay();
} else {
nextDay();
}
icon_view.setAlpha(0.0f);
anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(300);
icon_view.startAnimation(anim);
icon_view.setAlpha(1.0f);
} else {
icon_view.setAlpha(1.0f);
}
}
return true;
default :
return super.onTouchEvent(event);
}
}
public void nextDay() {
if ( CURRENT_DAY < 6) {
CURRENT_DAY ++ ;
showWeatherForDay( CURRENT_DAY );
}
}
public void prevDay() {
if( CURRENT_DAY == 0 ) {
// return home
} else {
CURRENT_DAY – ;
showWeatherForDay(CURRENT_DAY);
}
}
public String getIconFromWeatherIcon( String icon ) {
switch( icon ) {
case "10d":
return getString( R.string.weather_drizzle );
case "1nd":
return getString( R.string.weather_clear_night );
case "02d":
return getString( R.string.weather_cloudy );
case "01d":
return getString( R.string.weather_sunny );
case "03d":
return getString( R.string.weather_cloudy);
case "05d":
return getString( R.string.weather_rainy );
case "11d":
return getString( R.string.weather_thunder );
case "13d":
return getString( R.string.weather_snowy );
case "50d":
return getString( R.string.weather_foggy );
default:
return getString( R.string.weather_sunny );
}
}
}
Copyright Notice
© Licențiada.org respectă drepturile de proprietate intelectuală și așteaptă ca toți utilizatorii să facă același lucru. Dacă consideri că un conținut de pe site încalcă drepturile tale de autor, te rugăm să trimiți o notificare DMCA.
Acest articol: Creearea Unei Aplicatii Android de Turism (ID: 138646)
Dacă considerați că acest conținut vă încalcă drepturile de autor, vă rugăm să depuneți o cerere pe pagina noastră Copyright Takedown.
