Professional Documents
Culture Documents
- 02403
2012
.
/
-i-
:
:
1.
2.
3.
-ii-
, (smartphones) .
:
Android (, , ).
Android :
o
, .
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 .
.
-5-
Nokia. C++.
Windows Phone.
7.0.7008 .
7.0.7392 .
7.0.7403 Mango.
7.10.8107 LTE
.
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-
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-
headset .
Widgets, .
Screen Transitions.
2.4 Cupcake
2.5 Donut
Android Market.
Gallery.
voice search.
, , ..
-9-
WVGA.
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.
Flash .
zoom.
Multi-Touch.
Bluetooth 2.1.
Live Wallpapers.
2.6 Eclair
OS, .
Microsoft Exchange.
Application Launcher
Browser.
Market updates.
DPI 4 720p.
2.7 Froyo
UI Design.
(WXGA ).
VoIP Telephony.
Multi-Touch .
Development.
Developers .
(
).
Download Manager .
2.8 Gingerbread
2.9 Honeycomb
-12-
Google eBooks.
(Face Unlock).
(Panorama Mode).
NFC (Android
Beam).
(People App).
Notification Center.
(Recent Apps).
-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
, , , Wi-Fi, Flash,
( ).
-15-
2.3.2
(Native Libraries)
Surface Manager
(2D) (3D) .
SQLite
SQL.
Web Kit
(browsers).
2.3.3
(Android Runtime)
Java
Android Java
. Dalvik VM
(Dalvik Executable) (*.dex). dex VM
, .
2.3.4
(Application Framework)
Application Framework
.
Application Framework :
-16-
Content Providers: .
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 .
-20-
Eclipse Eclipse
Classic 3.7.1 ( 3.3). Eclipse, Help Install New Software. Work With ADT Plug In,
Developer Tools 3.4
.
-21-
AVD Manager .
AVD Manager .
Android.
-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 , .
Name: .
Target: (API) .
CPU/ABI:
. Target.
SD Card: .
Snapshot: AVD, .
-24-
Skin: . .
Hardware: RAM
, , .
3.3.3 Project
Project Eclipse
. Project .
.
3.4 Android
Eclipse Project
.
3.4.1
src
src ( Source, ). .
3.4.2
gen
gen , .
Project (Package Name).
3.4.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/
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 .
-30-
<uses-sdk>: API .
<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
).
-36-
4.4 XML
xml (
4.5). ,
PreferenceActivity ( 9). onCreate(). setCon-37-
tentView(),
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.
onPostExecute ( ).
AsyncTask .
,
AsyncTask. Void . execute.
4.6 ServerConnection()
4.8 ServerConnectionComplete
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-
DTD . DTD
, XML ( 4.10)
DTD. XML ( 2).
XML 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-
-45-
AndroidManifest ( 4.15)
( 26) Android.
(
16) .
uses-permission application uses-library .
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
( stations gasstation ).
NodeList getElementsByTagName() gasstation ( 258).
gasstation
NodeList ( gasstation ) .
. ( 260) .
XML String. ( 263)
( XML) String .
. XML .
4.20 XML
-49-
4.5.3
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.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
, , , .
.
.
:
.
/.
.
.
.
-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;
-73-
-74-
-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;
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-
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;
-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;
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;
-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-
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-
-90-