You are on page 1of 98

Android

- 02403

2012



.
/

-i-

:
:

1.
2.
3.

-ii-


, (smartphones) .
:

Android (, , ).

Android :
o

server side http .

, .

GPS .

server-side Android .
, .


30/06/2012

-iii-


........................................................................................................................... III
...................................................................................................................... V
1 .......................................................................................................................... 1
2 SMARTPHONES ............................................................................................................... 3
2.1 ....................................................................................................... 3
2.2 ............................................................................................ 4
2.2.1 Windows Phone ............................................................................................ 4
2.2.2 iOS .................................................................................................................. 6
2.2.3 Android ........................................................................................................... 8
2.2.4 ................................................................... 14
2.3 ANDROID ......................................................................................... 14
2.3.1 Linux............................................................................................. 15
2.3.2 (Native Libraries) ................................................... 16
2.3.3 (Android Runtime) ...................................................... 16
2.3.4 (Application Framework) ......................................... 16
2.3.5 Widgets ............................................................................. 17
2.4 ANDROID; .......................................................................................................... 18
3 ANDROID ............................................................................... 19
3.1 ................................................................... 19
3.2 ..................................................................................... 19
3.3 ............................................................................ 19
3.3.1 ............................................................................................... 20
3.3.2 Android SDK Manager AVD Manager............................................... 22
3.3.3 Project ...................................................................................... 25
3.4 ANDROID ...................................................................... 26
3.4.1 src ................................................................................................. 26
3.4.2 gen ................................................................................................ 26
3.4.3 .................................................................................................... 26
-v-

3.4.4 Assets........................................................................................... 27
3.4.5 Res ............................................................................................... 27
3.4.6 AndroidManifest.xml ................................................................................... 29
3.5 ANDROIDMANIFEST.XML ...................................................................................... 29
4 & ............................................................. 33
4.1 ...................................................................................... 33
4.2 ................................................................................................... 33
4.3 ............................................................................................ 35
4.4 SERVER..................................................................................... 39
4.4.1 .......................................................................... 39
4.4.2 ................................................................ 42
4.5 ............................................................................................... 43
4.5.1 .............................................................................................. 44
4.5.2 ............................................................. 48
4.5.3 .............................................................................. 50
4.5.4 ......................................................................... 52
4.6 OFF-LINE ..................................................................................... 54
5 GASFINDER ............................................................................................ 59
5.1 ............................................................................................................. 59
5.2 ......................................................................................... 59
5.3 ................................................................................................... 59
5.4 ........................................................................................... 61
5.5 ............................................................................................................. 62
5.6 ..................................................................................................................... 63
5.7 OFF-LINE ..................................................................................... 64
5.8 ...................................................................................... 65
6 ........................................................................................................... 67
..................................................................................................................... 69
...................................................................................................................... 71
......................................................................................................................... 73

-vi-

1

.
. Smartphones ( ).
. , , ,
, (
),

.

. .
.
smartphones , Android .

.

-1-

2 Smartphones
2.1
.
Smartphones ( ). Smartphones .
PDA (Personal Digital Assistant) .
/ e-mail, , .
.
,
. Social Media Facebook, Twitter Google+.
smartphones .
smartphones
. .

.
, , RA, ,
GPS .
iOS, Android, Windows Phone Symbian, .

-3-

2.2
hardware .
. Android Google,
iOS Apple Windows Phone Microsoft .
Symbian Nokia, Ericsson , Palm Os ( Garnet
OS) RIM Blackberry OS.
. iPhone
,
, iPhone .
Android
, hardware Android
. Android
.
Windows Phone
. Windows Phone 8
. Microsoft Microsoft .

.

2.2.1 Windows Phone


Windows Phone ( 2.1)
Microsoft Windows Mobile.
. , , , ,
, 2010, -4-

2011. Windows Phone Microsoft


Metro,
Microsoft, .

2.1 Windows Phone

Windows Mobile 2004 Photon, project . 2008 Microsoft


.
2009 Windows Phone Microsoft Windows Mobile 6.5 . Windows Phone
Windows Mobile.
Windows Phone
Microsoft Windows Mobile
. Microsoft Windows Mobile Windows Phone. Windows Phone 7 Series Windows Phone 7.
2010 Microsoft Mobile Word Congress Windows Phone, MIX 2010.
2010 CEO Microsoft Steve Ballmer 10 Windows Phone HTC, Dell, Samsung LG. 2011 Nokia Windows Phone

-5-

Nokia. C++.
Windows Phone.

7.0.7004 Windows Phone OS.

7.0.7008 .

7.0.7390 NoDo CDMA,


.

7.0.7392 .

7.0.7403 Mango.

7.10.7720 Windows Phone 7.5 Mango 2011. mobile


Internet Explorer 9, multi-tasking , Windows Live Sky Drive
.

7.10.7740 e-mail Microsoft Exchange Server


2003 .

7.10.8107 LTE
.

Windows Phone Tango


o NoDo Windows Phone RAM 256Mb.

2.2.2 iOS
To iOS ( iPhone OS) Apple
(Error! Reference source not found.). Apple iPhone Apple. Mac OS
Unix. Objective-C ( C) Cocoa
Touch API.

2007
Apple , iPhone
OS X.

-6-

2008 beta SDK



iPhone OS.

2010 iPhone OS iOS.


Apple iOS CISCO router .

2010 iOS 4 iOS


4.01 iOS 3.2.1 iPad.

To iOS 4.1 iPhone iPod Touch


bugs .

iOS 4.2 iOS 4.2.1


2010 iPad.

iOS 4.2.5 CDMA.

H iOS 4.2.6 iPhone


CDMA.

H iOS 4.3 2011 .


CDMA
(iOS 4.2.x) iOS 5
2011.

iOS 5.0.1 2011 bugs .

2012 iOS 5.1 iOS developers.

2.2 Apple

-7-

2.2.3 Android
Linux Android ( 2.3) smart phones . Java
Google . H Google Open Handset Alliance.
2007, Open Handset Alliance, 48 hardware (Google, HTC, Samsung,
Motorola, AT&T, Verizon ..), . Google
Android Apache License,
.

2.3 Android

Android
2007. HTC Dream (
T-Mobile G1) 2008 T-Mobile.
Google SDK Release Candidate 1.0.
1.1 2009. 1.1 ,
.
2009 Android 1.5 Cupcake ( 2.4). Cupcake
(User Interface).
-8-

video CamCorder mode.

video youtube Picasa, .

Bluetooth A2DP AVRCP.

headset .

Widgets, .

Screen Transitions.

2.4 Cupcake

Android 1.6 Donut ( 2.5) 2009.

2.5 Donut

Android Market.

Gallery.

voice search.

, , ..
-9-

CDMA/EVDO, 802.1x, VPNs, text-to-speech.

WVGA.

Gesture framework Gesture Builder.

turn-by-turn Google.

Android 2.0 Eclair ( 2.6) 2009 Android 2.0.1 (Eclair 0.1) Android 2.1 (Eclair MR1)
2009 2010 .
:

hardware.

UI.

Browser UI HTML5.

Contrast Ratio Backgrounds

Google Maps 3.1.2

Microsoft Exchange Server, ActiveSync 2.5

Flash .

zoom.

Multi-Touch.

Bluetooth 2.1.

Live Wallpapers.

2.6 Eclair

Android 2.2 Froyo ( 2.7) 2010.


-10-

OS, .

Chrome V8 JavaScript Browsers .

Microsoft Exchange.

Application Launcher
Browser.

USB Tethering Wi-Fi Hotspot.

(Data Access over


Mobile Network).

Market updates.

Adobe Flash 10.1.

DPI 4 720p.

2.7 Froyo

Android 2.3 Gingerbread ( 2.8) 2010


Android 2.3.3 2011.
:

UI Design.

(WXGA ).

VoIP Telephony.

WebM/VP8 video Playback AAC Audio Encoding.


-11-

reverb, equalization, headphone virtualization, bass


boost.

Multi-Touch .

Development.

Developers .

(
).

Download Manager .

YAFFS ext4 file system.

2.8 Gingerbread

Android 3.0 Honeycomb ( 2.9) 2011 .

2.9 Honeycomb

-12-

3D, Render script.

Video Chat Google Talk.

Google eBooks.

Android 4.0 Ice Cream Sandwich ( 2.10) 2011


.
:

(Face Unlock).

(Panorama Mode).

NFC (Android
Beam).

Web Browser Gmail.

e-mail ( 30), internet (Offline mode Gmail).

(People App).

Notification Center.


(Recent Apps).

2.10 Ice Cream Sandwich

Android . 2.11, Froyo. - .

-13-

2.11 Android .

2.2.4

Symbian Os RIM Blackberry OS. To Symbian OS EPOC PSION . Symbian Ltd C++. 2008 Symbian
Foundation Symbian Ltd. Symbian OS Nokia, Sony Ericsson ( Sony), BenqSiemens, Samsung, Motorola, NTT DoCoMo. Symbian OS Nokia Series 60, Series 80, Series 90, UIQ FOMA.
smartphones Blackberry OS. BlackBerry smartphone
Research In Motion
(RIM) 1999. PDA,
, .
/ e-mail . C++
1999.
Java.

2.3 Android
Android ,
. Linux
-14-

. Android
. ,
. Android 2.12.

2.12 Android OS

2.3.1

Linux

To Linux 2.6 (Linux Kernel)


Android.
:

, , , Wi-Fi, Flash,
( ).

-15-

2.3.2

(Native Libraries)

C C++ interface Java.


:

Surface Manager
(2D) (3D) .

Media Framework (codecs) mp2,mpeg .

SQLite
SQL.

Web Kit
(browsers).

2.3.3

(Android Runtime)

Java

Dalvik Virtual Machine .

Android Java
. Dalvik VM
(Dalvik Executable) (*.dex). dex VM
, .

2.3.4

(Application Framework)


Application Framework

.
Application Framework :

-16-

Content Providers: .

Notification Manager: Status Bar.

Activity Manager: ( 2.13).

Resource Manager:
.

View System: , , ,
.

2.13

2.3.5

Widgets

widgets, . , widget

.
-17-

2.4 Android;

. Android
.
.

open-source .

, .

-18-

3 Android
3.1
Android.
.
Android .
.
.

Android. (, , )

.
, .

3.2
Android Java.
C++.
NDK (Native Development Kit) C & C++ Java Android.

3.3
Eclipse IDE, Android SDK, ADT Plug In for Eclipse JDK.

-19-

3.3.1


. JDK
( 3.1) Oracle .

3.1 JDK Download

Android, Android SDK ( 3.2). (Android SDK)


. Windows 7. SDK Android SDK Manager.
API .
API . Google API 10
(Android 2.3.3)

-20-

3.2 Android SDK Download

Eclipse Eclipse
Classic 3.7.1 ( 3.3). Eclipse, Help Install New Software. Work With ADT Plug In,
Developer Tools 3.4
.

3.3 Eclipse Download

-21-

3.4 ADT Plug In Install

AVD Manager .
AVD Manager .
Android.

3.3.2 Android SDK Manager AVD Manager


Android SDK Manager
AVD Manager. Android SDK Manager 3.5
. Android, extra. Android SDK Tools Android SDK Platform Tools.
,
.

-22-

Android
API. To API Application Programming
Interface, , ,
. API SDK Platform API. Samples For SDK , . Google APIs by Google Inc .
, Google . API, Android.
Android
. Ice Cream
Sandwich (API 14) Gingerbread
(API 10). T Ice
Cream Sandwich (API 14) Gingerbread (API 10).
Google API 10 .
extra . Google Analytics SDK
, Google Admob ADS SDK , .

3.5 Android SDK Manager


-23-

Android Virtual Device Manager ( 3.6) . ,


.

3.6 AVD Manager

Name: .

Target: (API) .

CPU/ABI:
. Target.

SD Card: .

Snapshot: AVD, .

-24-

Skin: . .

Hardware: RAM
, , .

3.3.3 Project
Project Eclipse
. Project .
.

3.7 Android Project

1. Eclipse File New(Alt + Shift + N) Project


Android Project Next 3.7.
2. Project Name Project .
.
Next.
3. .
-25-

4. Application Name , Minimum


SDK API
Package Name .
5. Finish, Eclipse
.

3.4 Android
Eclipse Project
.

3.4.1

src

src ( Source, ). .

3.4.2

gen

gen , .

Project (Package Name).

3.4.3

*.jar ( Java Archive). ,


Java . Android ,
Android 2.3.3, Google APIs Android ,
Google APIs [Android 2.3.3].

-26-

3.4.4

Assets

Assets (
),
.

3.4.5

Res

res (res
resources) . , , , xml, raw. Res . o
1 , , XML .
1 Android

XML

/res/values/

strings.xml()

<string>

/res/values/

strings.xml()

<plurals>, <item>

/res/values/

strings.xml()

<string-array>,

<item>

Boolean

/res/values/

bools.xml()

<bool>

/res/values/

Colors.xml()

<color>

/res/color/

<selector>, <item>

buttonstates.xml

indicators.xml

/res/values/

dimens.xml()

<dimen>

/res/values/

integers.xml()

<integer>

/res/values/

integers.xml()

<integer-array>,

<item>

-27-

/res/values/

arrays.xml()

<array>, <item>

/res/values/

drawable.xml()

<drawable>

/res/drawable/

icon.png, logo.jpg

XML


,
.
tween

/res/anim/

<set>, <alpha>, <scale>,

fadesequence.xml

<translate>, <rotates>

spinswquence.xml

/res/drawable/

<animation-list>, <item>

sequence1.xml
sequence2.xml

/res/menu/

<menu>

mainmenu.xml
helpmenu.xml
XML

/res/xml/

/res/raw/

data.xml, data2.xml

jingle.mp3,somvideo.mp4,

helptext.txt

/res/layout/

. -

main.xml,help.xml

-28-

/res/values/

styles.xml
themes.xml()

<style>

3.4.6

AndroidManifest.xml

AndroidManifest.xml ,
, . .

3.5 AndroidManifest.xml
AndroidManifest.xml (/root) project. ,
Android . :

Java ,
ID .

(activities),
(services), (broadcast receivers) . . (Intents
messages) . Android
.

API .

Instrumentation Classes
. , .

Android API .

AndroidManifest.xml
. 3.8
.

-29-

3.8 AndroidManifest.xml

AndroidManifest.xml .

<XML> :
xml. version xml encoding .

<manifest> : <application>. <uses-permission>, < permission>, <permission-group>


<permission-tree>, <uses-configuration> <instrumentation>.
3.8 :
Package: . gr.gasFinder.bazpap.
android:versionCode: . . . .
android:VersionName: .

-30-

<uses-sdk>: API .

<application>: . <activity>, <service>, <provider>, <activity-alias>, <provider> <userlibrary>. :


android:icon: .
android:label:
.

<activity>: (activity) user interface .


AndroidManifest
. <intent-filter> <meta-data> . :
android:label:
. .
android:name: . . () , gr.gasFinder.bazpap.

<intent-filter>: intents , . .
. <activity>, <service>, <receiver> <activityalias>. <action> , <category>
<data>.
<action>: intents .
<category>:
intent.

-31-

4 &

4.1

. .
.
,
. .
.

.

.
.

. , , Offline .
.

.

4.2
.
-33-

server. :

.
.
Off-line ( 4.6).
( 4.5.4).
server (4.4).

.

splash.xml
Main.java . splash.xml 4.1 ( 5), ( 3 & 4) ( 6).

4.1 XML

Main.java
( 4.2)
( 23). isInternetOn() ( 32-44) . Offline
( 27 & 28). startService() .
server .
server 4.5.4 4.4 .

isInternetOn(). connectivityManager
( 33). ( 34-42) 3G (getNetworkInfo(0)) wi-fi (getNetworkInfo(1)).
true -34-

false.
( 4.15 20).

4.2 Main

4.3
.
background ,
,
.

. , , .
xml Preferences , ,
. xml radiusList.xml
, typeLlist.xml
-35-

timeList.xml

. xml
4.3.

4.3 XML
xml preferences.xml ( 4.4) xml
. (listPreference) xml
.
(android:entries &
android:entryValues

).

(android:defaultValue), (android:key), (android:selectable),


(android:summary) (android:title).
PreferenceScreen checkbox
checkboxes( ). . checkbox
android:disableDependentsState="true"
checkboxes checkbox android:dependency="all".

-36-

4.4 XML

xml (
4.5). ,
PreferenceActivity ( 9). onCreate(). setCon-37-

tentView(),

addPreferencesFromResource ( 14) layout


preferences.xml.
.
SharedPreferences Android. SharedPreferences
( 10) .
. getSharedPreferences ( 31 & 32)
. SharedPreferences.Editor
( 33) editor commit().

4.5 Preferences


. -38-

onBackPressed() ( 18-27)
.
,
save() ( 29-46,
) .
save() Map
( 21-23).
server ( 24 & 25)
( 26).
Preferences

4.4 Server
server

.
. org.apache.http
HTTP. 3.0 Android (HoneyComb)
Google
. AsyncTask (Asynchronous task), .
4.6 ServerConnection.

4.4.1


AsyncTask.

doInBackground, onPreExecute onPostExecute.


: onPreExecute ( ), doInBackground
-39-

onPostExecute ( ).
AsyncTask .
,

AsyncTask. Void . execute.

4.6 ServerConnection()

server ServerConnection AsyncTask. constructor


Context, ServerConnectionListener , .
. onPreExecute . onPostExecute
-40-

ServerConnectionListener. O ServerConnectionListener . nterface 4.7 ServerConnectionListener Interface.


Listener Implements ServerConnectionListener
ServerConnectionComplete 4.8.
Main Preferences.
.
( ) .

4.7 ServerConnectionListener Interface

4.8 ServerConnectionComplete

doInBackground server. HTTP


HttpClient ( 56)
HTTP .
HttpPost (

57).

http://mpazigos.dyndns.org/gasFinder/gasFinder.php.
Post Get .

.
NameValuePair
-41-

( 59) ( )
( 79) ( 81).
server ( 81 87) .
ftype ( ), recency
( ), radius ( ), latitude
& longitude allStationsValue , (shellValue, etekaValue, bpValue, jetoilValue, revoilValue, silkoilValue, kaoilValue,
aegeanValue, ekoeldaValue, avinValue, elpetrolValue, elinoilValue, cyclonValue, dracoilValue, medoilValue, argoValue, kmoilValue, apValue).
NameValuePair add(new BasicNameValuePair("
", " ")) ( 62).

4.4.2

XML
. DTD.
DTD XML .
XML, , , .
DTD 4.9. stations (
) () gasstation
( 2), ( )
( 3). (
) . #PCDATA,
.

-42-

4.9 Document Type Definition

DTD . DTD
, XML ( 4.10)
DTD. XML ( 2).
XML DTD XML
.

4.10 DTD XML

4.5

.
.
server, ( ).

, ,
.
-43-

4.5.1

Google
Google Maps.
MD5
. Map API Key
.
( Obtaining a Maps API Key). Map API
Key .
(cmd) bin JDK
keytool.

4.11.

4.11 MD5

keystore
keystore,
Eclipse Window-Preferences-Android-Build ( 4.12).
Map API Key
Sign Up for the Android Maps API,
Generate API Key
( 4.13).
API Key
( 4.14) , .

-44-

4.12 Debug Keystore

4.13 API Key

4.14 API Key

-45-

AndroidManifest ( 4.15)
( 26) Android.
(
16) .
uses-permission application uses-library .

4.15 & internet

xml
. o xml 4.16.
ID ( 3),
( 4 & 5),
( 7)
API KEY ( 6) .
.

4.16 Map.xml

xml .
Java ( 4.17). MapActivity Activity.
. MapView
.
onCreate()
-46-

.
( ) xml
MapView ( 58 & 59 ).
zoom-in & zoom-out ( 60). 4.18.

4.17 Map

4.18

-47-

4.5.2

xml . 4.19.
stations .
gasstation ( )
. gasstation lat ( ), long ( ), price ( ), type ( ),
name( ), address ( ), owner ( )
lastUpdate ( ).

4.19 xml

4.20. Error! Reference source not found. XML javax.xml.parsers org.w3c.dom.


XML
Document Object Model (DOM). DocumentBuilder DocumentBuilderFactory Document, Node, NodeList Element.
( 253).
DocumentBuilderFactory ( 254)
(parser) XML
DOM DocumentBuilder ( 255) . , Document
parse() ( 256).
getDocumentElement()( 257) Element
-48-

( stations gasstation ).
NodeList getElementsByTagName() gasstation ( 258).
gasstation
NodeList ( gasstation ) .
. ( 260) .
XML String. ( 263)
( XML) String .
. XML .

4.20 XML

-49-

4.5.3

( Offline View 4.6) .


.
. (
)
(, ). .
.
( 4.21):

1. MapView ( 54).
2. Drawable ( 73)
.
3. MyItemizedOverlay ( 74) (
) Drawable
MapView. .
4. GeoPoint ( 75)
.
5. OverlayItem ( 78)
GeoPoint String .
6. addOverlay(OverlayItem) ( 79)
,
3 .
7.
mapOverlays.add(MyItemizedOverlay) (
80). mapOverlays ( 68) Overlay
.

-50-

4.21

4.22. XML .

4.22

-51-

4.5.4

server
AsyncTask.
. Main
Map .

GPS. . UserLocation
4.23.
UserLocation
AsyncTask ( 94). LocationListener ( 97), LocationManager ( 96)
ProgressDialog .
AsyncTask onPreExecute,
doInBackground onPostExecute.
LocationListener ( 99) LocationManager
( 100). LocationManager requestLocationUpdates LocationListener
( 101 & 102) ( 103 107). requestLocationUpdates :
GPS ( ), , LocationListener. 0 .
doInBackground
( 121). . onPostExecute
( 111), server ( 112 & 113),
(
114 116) ( 117).

-52-

LocationListener
. LocationListener implement ( 125). . onLocationChanged, onProviderDisabled, onProviderEnabled onStatusChanged. .
Location. .
getLatitude getLongitude
( 128 & 129).
( 127 130)
( 130 134). Log .
Map UserLocation
. onPreExecute
, onPostExecute
doInBackground . LocationListener
, , GPS
. .
.
.
GPS.

GPS . ,
.

-53-

4.23 UserLocation

4.6 Off-line
4.2
. -

-54-

Offline
View . .
Offline View .
server .

. Offline View

.
. 4.5.2 String
.
.
Offline View .
String .
.
xml .
layout (list.xml)
(list view) ( 4.24) layout listAdapter .

4.24 List View Layout

Android layout listAdapter .


-55-

layout mylist.xml 4.25 layout (simple_list_item_1) .



layout .

4.25 mylist.xml

4.26 Offline

layout
. 4.26
onCreate()
list.xml ( 26). gasStations
( 27) null,
. . setListAdapter
( 33 & 34) layout mylist.xml -56-

gasStations
\t ( tab).
. ( \t)

. Offline Offline.

-57-

5 gasFinder
5.1
.
smartphones . , Android.

.

5.2
GasFinder (Gas
gasoline ) .
. ,
.
. Vehicle ()

-. .
GasFinder .
. . Off-line . .
.

5.3
5.1
. -

-59-

.
server
5.2 ( ).
server.
Off-line .
.

5.1

5.2

-60-

5.4
.
.
5.3 .

( 5.3 ).

.
5.4.
, (,
) Off-line . .

5.3 () ()

-61-

5.4

5.5
.
5.5 4.3 , ,
( 5.6).
save()
.

5.5

-62-

5.6

5.6
.
. Offline .
,
,
( 5.7).

-63-

5.7 .

5.7 Off-line
. H
. ( 5.8 )
5.6
.
.
4.6
5.8 .
, ,

.

.

-64-

5.8 () Off-line View () off-line view

5.8
, , , .
.

.
:

.
/.
.
.
.

-65-

6
smartphones .
Android. , ,
, .
, .
Android
.
Android
Android.

-67-


[01] Lauren Darcey Shane Conder, Android, , . , 2011
[02] Wei-Meng Lee, Beginning Android Application Development, Wiley Publishing Inc,
2011.
[03] Satya Komatineni Dave MacLean Sayed Y. Hashimi, Pro Android 3, Apress,
2011.
[04] W. Frank Ableson Robi Sen Chris King, Android In Action, Second Edition, Revised Edition of Unlocking Android, Manning, 2011.
[05] Mark L. Murphy, The Busy Coders Guide To Android Development, CommonsWare, 2011.
[06] Android Development Guide From Google.
http://developer.android.com/guide/basics/what-is-android.html
[07] Android Tutorials.
http://www.vogella.com/android.html
[08] Android Tutorials.
http://www.bogotobogo.com/Android/android.php
[09] Android Application Video Tutorials.
http://www.youtube.com/watch?v=SUOWNXGRc6g&feature=BFa&list=PL2F07DBC
DCC01493A
[10] Questions/Answers Site.
http://stackoverflow.com/

-69-


A2DP - Advanced Audio Distribution Profile
AAC - Advanced Audio Coding
ABI - Application Binary Interface
ADT - Android Development Tools
API - Application Program Interface
AVD Manager - (Android Virtual Device Manager)
AVRCP - Audio/Video Remote Control Profile
CDMA - Code division multiple access
DPI - Dots per inch
DTD - Document Type Definition
EVDO - Evolution Data Optimized
GPS - Global Positioning System
JDK - Java Development Kit
LTE - Long Term Evolution
NFC - Near field communication
PCDATA - Parsed Character Data
SDK - Software development kit
VoIP - Voice over IP
VPN - Virtual private network
WVGA - Wide Video Graphics Array
WXGA - Wide Extended Graphics Array
YAFFS - Yet Another Flash File System

-71-


ServerConnection
package gr.gasFinder.bazpap;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

java.io.IOException;
java.io.OutputStreamWriter;
java.io.UnsupportedEncodingException;
java.util.ArrayList;
java.util.List;
org.apache.http.NameValuePair;
org.apache.http.client.ClientProtocolException;
org.apache.http.client.HttpClient;
org.apache.http.client.ResponseHandler;
org.apache.http.client.entity.UrlEncodedFormEntity;
org.apache.http.client.methods.HttpPost;
org.apache.http.impl.client.BasicResponseHandler;
org.apache.http.impl.client.DefaultHttpClient;
org.apache.http.message.BasicNameValuePair;
org.apache.http.params.CoreProtocolPNames;
android.app.ProgressDialog;
android.content.Context;
android.content.SharedPreferences;
android.os.AsyncTask;
android.preference.PreferenceManager;
java.io.FileOutputStream;

public class ServerConnection extends AsyncTask<Context, Void, String> {


Context context;
String response = null;
Exception lastException = null;
ServerConnectionListener listenerCL = null;
ProgressDialog PD;
static double lat ;
static double longit;
public ServerConnection(Context baseContext,
ServerConnectionListener listenerCL, double lati, double longi) {
context = baseContext;
this.listenerCL = listenerCL;
lat = lati;
longit = longi;
}
protected void onPreExecute() {
PD = ProgressDialog.show(context, "", "Connecting ...");
PD.setCancelable(true);
}

-73-

protected void onPostExecute(String result) {


PD.dismiss();
listenerCL.ServerConnectionComplete(result, isCancelled(),
lastException);
}
protected String doInBackground(Context... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mpazigos.dyndns.org/gasFinder/gasFinder");
httppost.getParams().setParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
boolean comp;
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(context);
nameValuePairs.add(new BasicNameValuePair("ftype", getPrefs.getString(
"listType", "1")));
if (getPrefs.getString("listTime", "1").equals("1")) {
nameValuePairs.add(new BasicNameValuePair("recency","0" ));
} else if (getPrefs.getString("listTime", "2").equals("2")) {
nameValuePairs.add(new BasicNameValuePair("recency","2" ));
} else if (getPrefs.getString("listTime", "3").equals("3")) {
nameValuePairs.add(new BasicNameValuePair("recency","7" ));
} else if (getPrefs.getString("listTime", "4").equals("4")) {
nameValuePairs.add(new BasicNameValuePair("recency","30" ));
} else if (getPrefs.getString("listTime", "5").equals("5")) {
nameValuePairs.add(new BasicNameValuePair("recency","1000" ));
}
if (getPrefs.getString("listAA", "1").equals("1")) {
nameValuePairs.add(new BasicNameValuePair("radius","5" ));
} else if (getPrefs.getString("listAA", "2").equals("2")) {
nameValuePairs.add(new BasicNameValuePair("radius","10" ));
} else if (getPrefs.getString("listAA", "3").equals("3")) {
nameValuePairs.add(new BasicNameValuePair("radius","20" ));
} else if (getPrefs.getString("listAA", "4").equals("4")) {
nameValuePairs.add(new BasicNameValuePair("radius","30" ));
} else if (getPrefs.getString("listAA", "5").equals("5")) {
nameValuePairs.add(new BasicNameValuePair("radius","50" ));
}
boolean compAll = getPrefs.getBoolean("all", true);
if (compAll == true) {
nameValuePairs.add(new BasicNameValuePair("allStationsValue", "1"));
} else if (compAll == false) {
nameValuePairs.add(new BasicNameValuePair("allStationsValue", "0"));
comp = getPrefs.getBoolean("Shell", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("shellValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("shellValue", "0"));
}
comp = getPrefs.getBoolean("Eteka", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("etekaValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("etekaValue", "0"));
}
comp = getPrefs.getBoolean("BP", false);
if (comp == true) {

-74-

nameValuePairs.add(new BasicNameValuePair("bpValue", "1"));


} else {
nameValuePairs.add(new BasicNameValuePair("bpValue", "0"));
}
comp = getPrefs.getBoolean("JetOil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("jetoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("jetoilValue", "0"));
}
comp = getPrefs.getBoolean("Revoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("revoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("revoilValue", "0"));
}
comp = getPrefs.getBoolean("Silkoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("silkoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("silkoilValue", "0"));
}
comp = getPrefs.getBoolean("Kaoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("kaoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("kaoilValue", "0"));
}
comp = getPrefs.getBoolean("Aegean", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("aegeanValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("aegeanValue", "0"));
}
comp = getPrefs.getBoolean("EE", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("ekoeldaValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("ekoeldaValue", "0"));
}
comp = getPrefs.getBoolean("Avin", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("avinValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("avinValue", "0"));
}
comp = getPrefs.getBoolean("EP", false);
if (comp == true) {
nameValuePairs
.add(new BasicNameValuePair("elpetrolValue", "1"));
} else {
nameValuePairs
.add(new BasicNameValuePair("elpetrolValue", "0"));
}
comp = getPrefs.getBoolean("Elinoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("elinoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("elinoilValue", "0"));

-75-

}
comp = getPrefs.getBoolean("Cyclon", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("cyclonValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("cyclonValue", "0"));
}
comp = getPrefs.getBoolean("KMoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("kmoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("kmoilValue", "0"));
}
comp = getPrefs.getBoolean("Medoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("medoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("medoilValue", "0"));
}
comp = getPrefs.getBoolean("Dracoil", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("dracoilValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("dracoilValue", "0"));
}
comp = getPrefs.getBoolean("Argo", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("argoValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("argoValue", "0"));
}
comp = getPrefs.getBoolean("AP", false);
if (comp == true) {
nameValuePairs.add(new BasicNameValuePair("apValue", "1"));
} else {
nameValuePairs.add(new BasicNameValuePair("apValue", "0"));
}
}
nameValuePairs.add(new BasicNameValuePair("latitude", Double
.toString(lat)));
nameValuePairs.add(new BasicNameValuePair("longitude", Double
.toString(longit)));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
response = httpclient.execute(httppost, responseHandler);
FileOutputStream fOut = context.getApplicationContext()
.openFileOutput("data.xml", Context.MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(response);
osw.flush();
osw.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

-76-

return response;
}
}


BallonItemizedOverlay.java
package gr.gasFinder.bazpap;
import
import
import
import
import
import
import
import
import
import
import
import
import

java.util.List;
android.graphics.drawable.Drawable;
android.view.MotionEvent;
android.view.View;
android.view.View.OnClickListener;
android.view.View.OnTouchListener;
android.view.ViewGroup.LayoutParams;
com.google.android.maps.GeoPoint;
com.google.android.maps.ItemizedOverlay;
com.google.android.maps.MapController;
com.google.android.maps.MapView;
com.google.android.maps.Overlay;
com.google.android.maps.OverlayItem;

public abstract class BalloonItemizedOverlay<Item extends OverlayItem> extends


ItemizedOverlay<Item> {
private MapView mapView;
private BalloonOverlayView<Item> balloonView;
private View clickRegion;
private View closeRegion;
private int viewOffset;
final MapController mc;
private Item currentFocusedItem;
private int currentFocusedIndex;
public BalloonItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(defaultMarker);
this.mapView = mapView;
viewOffset = 0;
mc = mapView.getController();
}
public void setBalloonBottomOffset(int pixels) {
viewOffset = pixels;
}
public int getBalloonBottomOffset() {
return viewOffset;
}
protected boolean onBalloonTap(int index, Item item) {
return false;
}
protected void onBalloonOpen(int index) {
}
public final boolean onTap(int index) {
-77-

currentFocusedIndex = index;
currentFocusedItem = createItem(index);
setLastFocusedIndex(index);
onBalloonOpen(index);
createAndDisplayBalloonOverlay();
mc.animateTo(currentFocusedItem.getPoint());
return true;
}
protected BalloonOverlayView<Item> createBalloonOverlayView() {
return new BalloonOverlayView<Item>(getMapView().getContext(),
getBalloonBottomOffset());
}
protected MapView getMapView() {
return mapView;
}
public void hideBalloon() {
if (balloonView != null) {
balloonView.setVisibility(View.GONE);
}
currentFocusedItem = null;
}
private void hideOtherBalloons(List<Overlay> overlays) {
for (Overlay overlay : overlays) {
if (overlay instanceof BalloonItemizedOverlay<?> && overlay != this) {
((BalloonItemizedOverlay<?>) overlay).hideBalloon();
}
}
}
private OnTouchListener createBalloonTouchListener() {
return new OnTouchListener() {
float startX;
float startY;
public boolean onTouch(View v, MotionEvent event) {
View l = ((View) v.getParent())
.findViewById(R.id.balloon_main_layout);
Drawable d = l.getBackground();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int[] states = { android.R.attr.state_pressed };
if (d.setState(states)) {
d.invalidateSelf();
}
startX = event.getX();
startY = event.getY();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
int newStates[] = {};
if (d.setState(newStates)) {
d.invalidateSelf();

-78-

}
if (Math.abs(startX - event.getX()) < 40
&& Math.abs(startY - event.getY()) < 40) {
onBalloonTap(currentFocusedIndex, currentFocusedItem);
}
return true;
} else {
return false;
}
}
};
}
public Item getFocus() {
return currentFocusedItem;
}
public void setFocus(Item item) {
super.setFocus(item);
currentFocusedIndex = getLastFocusedIndex();
currentFocusedItem = item;
if (currentFocusedItem == null) {
hideBalloon();
} else {
createAndDisplayBalloonOverlay();
}
}
private boolean createAndDisplayBalloonOverlay() {
boolean isRecycled;
if (balloonView == null) {
balloonView = createBalloonOverlayView();
clickRegion = (View) balloonView
.findViewById(R.id.balloon_inner_layout);
clickRegion.setOnTouchListener(createBalloonTouchListener());
closeRegion = (View) balloonView.findViewById(R.id.balloon_close);
if (closeRegion != null) {
closeRegion.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
hideBalloon();
}
});
}
isRecycled = false;
} else {
isRecycled = true;
}
balloonView.setVisibility(View.GONE);
List<Overlay> mapOverlays = mapView.getOverlays();
if (mapOverlays.size() > 1) {
hideOtherBalloons(mapOverlays);
}
if (currentFocusedItem != null)
balloonView.setData(currentFocusedItem);

-79-

GeoPoint point = currentFocusedItem.getPoint();


MapView.LayoutParams params = new MapView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, point,
MapView.LayoutParams.BOTTOM_CENTER);
params.mode = MapView.LayoutParams.MODE_MAP;
balloonView.setVisibility(View.VISIBLE);
if (isRecycled) {
balloonView.setLayoutParams(params);
} else {
mapView.addView(balloonView, params);
}
return isRecycled;
}
}

BallonOverlayView.java
package gr.gasFinder.bazpap;
import
import
import
import
import
import
import
import
import
import

android.content.Context;
android.util.AttributeSet;
android.view.Gravity;
android.view.LayoutInflater;
android.view.View;
android.view.ViewGroup;
android.widget.FrameLayout;
android.widget.LinearLayout;
android.widget.TextView;
com.google.android.maps.OverlayItem;

public class BalloonOverlayView<Item extends OverlayItem> extends FrameLayout {


private LinearLayout layout;
private TextView title;
private TextView snippet;
public BalloonOverlayView(Context context, int balloonBottomOffset) {
super(context);
setPadding(10, 0, 10, balloonBottomOffset);
layout = new LimitLinearLayout(context);
layout.setVisibility(VISIBLE);
setupView(context, layout);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.NO_GRAVITY;
addView(layout, params);

-80-

}
protected void setupView(Context context, final ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.balloon_overlay, parent);
title = (TextView) v.findViewById(R.id.balloon_item_title);
snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
}
public void setData(Item item) {
layout.setVisibility(VISIBLE);
setBalloonData(item, layout);
}
protected void setBalloonData(Item item, ViewGroup parent) {
if (item.getTitle() != null) {
title.setVisibility(VISIBLE);
title.setText(item.getTitle());
} else {
title.setText("");
title.setVisibility(GONE);
}
if (item.getSnippet() != null) {
snippet.setVisibility(VISIBLE);
snippet.setText(item.getSnippet());
} else {
snippet.setText("");
snippet.setVisibility(GONE);
}
}
private class LimitLinearLayout extends LinearLayout {
private static final int MAX_WIDTH_DP = 280;
final float SCALE = getContext().getResources().getDisplayMetrics().density;
public LimitLinearLayout(Context context) {
super(context);
}
public LimitLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mode = MeasureSpec.getMode(widthMeasureSpec);
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
int adjustedMaxWidth = (int)(MAX_WIDTH_DP * SCALE + 0.5f);
int adjustedWidth = Math.min(measuredWidth, adjustedMaxWidth);
int adjustedWidthMeasureSpec =
MeasureSpec.makeMeasureSpec(adjustedWidth, mode);
super.onMeasure(adjustedWidthMeasureSpec, heightMeasureSpec);
}
}
}

-81-

MyItemizedOverlay.java
package gr.gasFinder.bazpap;
import
import
import
import
import

java.util.ArrayList;
android.content.Context;
android.graphics.drawable.Drawable;
com.google.android.maps.MapView;
com.google.android.maps.OverlayItem;

public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {


private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;
public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
public int size() {
return m_overlays.size();
}
protected boolean onBalloonTap(int index, OverlayItem item) {
return true;
}
public void removeOverlay(OverlayItem overlay) {
m_overlays.remove(overlay);
populate();
}
public void clear() {
m_overlays.clear();
populate();
}
}
Balloon_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="25dip"
android:paddingLeft="10dip"
android:minWidth="200dip"
android:id="@+id/balloon_main_layout"
android:background="@drawable/balloon_overlay_bg_selector"
-82-

android:paddingTop="0dip"
android:paddingRight="0dip">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginTop="6dip"
android:minHeight="40dip"
android:gravity="center_vertical"
android:id="@id/balloon_inner_layout">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/balloon_item_title"
android:text="balloon_item_title"
android:textSize="16dip"
android:textColor="@android:color/primary_text_light"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/balloon_item_snippet"
android:text="balloon_item_snippet"
android:textSize="12dip"
android:textColor="@android:color/secondary_text_light"/>
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/balloon_overlay_close"
android:id="@id/balloon_close"
android:paddingLeft="10dip"
android:paddingBottom="10dip"
android:paddingRight="5dip"
android:paddingTop="5dip"/>
</LinearLayout>
Balloon_overlay_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/balloon_overlay_focused" />
<item
android:state_pressed="false"
android:drawable="@drawable/balloon_overlay_unfocused" />
</selector>

ids.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="balloon_inner_layout" />
<item type="id" name="balloon_close" />
</resources>
-83-

Offline
package gr.gasFinder.bazpap;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

java.io.File;
java.util.Vector;
javax.xml.parsers.DocumentBuilder;
javax.xml.parsers.DocumentBuilderFactory;
org.w3c.dom.Document;
org.w3c.dom.Node;
org.w3c.dom.NodeList;
android.app.ListActivity;
android.content.Intent;
android.content.SharedPreferences;
android.os.Bundle;
android.preference.PreferenceManager;
android.view.Menu;
android.view.MenuInflater;
android.view.MenuItem;
android.widget.ArrayAdapter;
android.widget.Toast;

public class Offline extends ListActivity {


private int allFlag = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
String gasStations = readXML();
if (gasStations == null) {
allFlag = 1;
Toast.makeText(getBaseContext()," . ",
1000).show();
gasStations = readXML();
setListAdapter(new ArrayAdapter<String>(this, R.layout.mylist,
gasStations.split("\t")));
} else {
setListAdapter(new ArrayAdapter<String>(this, R.layout.mylist,
gasStations.split("\t")));
}
}
public String readXML() {
try {
SharedPreferences offPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
int trueCounter = 0;
Boolean comp;
Vector<String> displayNames = new Vector<String>();
String price = null, name = null, address = null, update = null, type =
null, owner = null;
String gasStationTemp = null;
File file;
file = new File("/data/data/gr.gasFinder.bazpap/files/data.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(file);
org.w3c.dom.Element root = doc.getDocumentElement();
-84-

NodeList items = root.getElementsByTagName("gasstation");


boolean compAll = offPrefs.getBoolean("all", true);
if (compAll == true) {
displayNames.add("all");
allFlag = 1;
} else {
comp = offPrefs.getBoolean("Shell", false);
if (comp == true) {
displayNames.add("Shell");
trueCounter++;
}
comp = offPrefs.getBoolean("Eteka", false);
if (comp == true) {
displayNames.add("");
trueCounter++;
}
comp = offPrefs.getBoolean("BP", false);
if (comp == true) {
displayNames.add("BP");
trueCounter++;
}
comp = offPrefs.getBoolean("JetOil", false);
if (comp == true) {
displayNames.add("JetOil");
trueCounter++;
}
comp = offPrefs.getBoolean("Revoil", false);
if (comp == true) {
displayNames.add("REVOIL");
trueCounter++;
}
comp = offPrefs.getBoolean("Silkoil", false);
if (comp == true) {
displayNames.add("Silkoil");
trueCounter++;
}
comp = offPrefs.getBoolean("Kaoil", false);
if (comp == true) {
displayNames.add("Kaoil");
trueCounter++;
}
comp = offPrefs.getBoolean("Aegean", false);
if (comp == true) {
displayNames.add(" (AEGEAN)");
trueCounter++;
}
comp = offPrefs.getBoolean("EE", false);
if (comp == true) {
displayNames.add("Eko");
trueCounter++;
}
comp = offPrefs.getBoolean("Avin", false);
if (comp == true) {
displayNames.add("Avin");
trueCounter++;
}
comp = offPrefs.getBoolean("EP", false);
if (comp == true) {
displayNames.add("EL-PETROIL");

-85-

trueCounter++;
}
comp = offPrefs.getBoolean("Elinoil", false);
if (comp == true) {
displayNames.add("");
trueCounter++;
}
comp = offPrefs.getBoolean("Cyclon", false);
if (comp == true) {
displayNames.add("Cyclon");
trueCounter++;
}
comp = offPrefs.getBoolean("KMoil", false);
if (comp == true) {
displayNames.add("KMoil");
trueCounter++;
}
comp = offPrefs.getBoolean("Medoil", false);
if (comp == true) {
displayNames.add("Medoil");
trueCounter++;
}
comp = offPrefs.getBoolean("Dracoil", false);
if (comp == true) {
displayNames.add("Dracoil");
trueCounter++;
}
comp = offPrefs.getBoolean("Argo", false);
if (comp == true) {
displayNames.add("");
trueCounter++;
}
comp = offPrefs.getBoolean("AP", false);
if (comp == true) {
displayNames.add(" ");
trueCounter++;
}
}
for (int i = 0; i < items.getLength(); i++) {
Node item = items.item(i);
NodeList values = item.getChildNodes();
int flag = 0;
if (allFlag == 1) {
flag = 1;
}
for (int j = 0; j < values.getLength(); j++) {
Node property = values.item(j);
String nodeName = property.getNodeName();
if (nodeName.equalsIgnoreCase("price")) {
price = property.getFirstChild().getNodeValue();
}
if (nodeName.equalsIgnoreCase("type")) {
type = property.getFirstChild().getNodeValue();
}
if (nodeName.equalsIgnoreCase("name")) {
name = property.getFirstChild().getNodeValue();
int x = 0;
while (flag == 0 && x < displayNames.size()
&& trueCounter != 0) {

-86-

if (displayNames.get(x).equalsIgnoreCase(name)) {
flag = 1;
}
x++;
}
}
if (nodeName.equalsIgnoreCase("address")) {
address = property.getFirstChild().getNodeValue();
}
if (nodeName.equalsIgnoreCase("owner")) {
owner = property.getFirstChild().getNodeValue();
}
if (nodeName.equalsIgnoreCase("lastUpdate")) {
update = property.getFirstChild().getNodeValue();
update = update.substring(0, update.length() - 3);
if (update.substring(0, 1).equalsIgnoreCase(":")) {
update = update.substring(2);
}
}
}
if (flag == 1 || trueCounter == 0) {
if (gasStationTemp == null) {
gasStationTemp = name + " - " + type + "\n" + price
+ "(" + update + ")" + "\n" + owner + "\n"
+ address + "\t";
} else if (gasStationTemp != null) {
gasStationTemp += name + " - " + type + "\n" + price
+ " (" + update + ")" + "\n" + owner + "\n"
+ address + "\t";
}
}
}
return gasStationTemp;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater m = getMenuInflater();
m.inflate(R.menu.offline_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.offlinepreferences:
finish();
startActivity(new Intent("gr.gasFinder.bazpap.OFFLINEPREFERENCES"));
return true;
case R.id.about:
startActivity(new Intent("gr.gasFinder.bazpap.ABOUT"));
return true;
}
return false;
}
}

-87-


Main
public class UserLocation extends AsyncTask<String, Integer, String> {
ProgressDialog progDailog = null;
public LocationManager userLocationManager;
public UserLocationListener userLocationListener;
protected void onPreExecute() {
userLocationListener = new UserLocationListener();
userLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
userLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0,
userLocationListener);
progDailog = new ProgressDialog(Main.this);
progDailog.setMessage(" ..");
progDailog.setIndeterminate(true);
progDailog.setCancelable(true);
progDailog.show();
}
protected void onPostExecute(String result) {
progDailog.dismiss();
ServerConnection srvcon = new ServerConnection(Main.this,
Main.this, lati, longit);
srvcon.execute();
Map mapObj = new Map();
mapObj.setLatitude(lati);
mapObj.setLongitude(longit);
stopService();
}
protected String doInBackground(String... params) {
while (lati == 0.0) {
}
return null;
}
public class UserLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
try {
lati = location.getLatitude();
longit = location.getLongitude();
} catch (Exception e) {
progDailog.dismiss();
Toast.makeText(Main.this, " ",
Toast.LENGTH_LONG).show();
}
}
public void onProviderDisabled(String provider) {
Log.i("OnProviderDisabled", "OnProviderDisabled");
}
public void onProviderEnabled(String provider) {
Log.i("onProviderEnabled", "onProviderEnabled");
}
-88-

public void onStatusChanged(String provider, int status,


Bundle extras) {
Log.i("onStatusChanged", "onStatusChanged");
}
}
}

Map
public class UserLocation extends AsyncTask<String, Integer, String> {
ProgressDialog progDailog = null;
public double lati = 0.0;
public double longi = 0.0;
public LocationManager userLocationManager;
public UserLocationListener userLocationListener;
protected void onPreExecute() {
userLocationListener = new UserLocationListener();
userLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
userLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0,
userLocationListener);
}
protected String doInBackground(String... params) {
while (this.lati == 0.0) {
}
return null;
}
public class UserLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String address;
try {
Geocoder geocoder = new Geocoder(getApplicationContext(),
Locale.getDefault());
address = geocoder.getFromLocation(userLat, userLongit, 1)
.get(0).getFeatureName();
GeoPoint userPoint = new GeoPoint((int) (userLat * 1E6),
(int) (userLongit * 1E6));
lati = location.getLatitude();
longi = location.getLongitude();
overlayItem = new OverlayItem(userPoint, " ",
address);
if (itemizedOverlay != null) {
itemizedOverlay.clear();
}
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
} catch (Exception e) {
progDailog.dismiss();
Toast.makeText(Map.this, " ",
Toast.LENGTH_LONG).show();
}
}

-89-

public void onProviderDisabled(String provider) {


Log.i("OnProviderDisabled", "OnProviderDisabled");
}
public void onProviderEnabled(String provider) {
Log.i("onProviderEnabled", "onProviderEnabled");
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
Log.i("onStatusChanged", "onStatusChanged");
}
}
}

-90-

You might also like