1
0
Fork 0

Initial Import. Version 2.0

master
Carlos Mogas da Silva 14 years ago
commit fbbd2673ff
  1. 8
      .classpath
  2. 2
      .gitignore
  3. 33
      .project
  4. 3
      .settings/org.eclipse.core.resources.prefs
  5. 22
      AndroidManifest.xml
  6. BIN
      bin/Farmacias.apk
  7. BIN
      bin/classes.dex
  8. BIN
      bin/resources.ap_
  9. 13
      default.properties
  10. 339
      gpl-2.0.txt
  11. BIN
      libs/admob-sdk-android.jar
  12. BIN
      res/drawable-hdpi/dialog.9.png
  13. BIN
      res/drawable-hdpi/list_location.9.png
  14. BIN
      res/drawable-mdpi/arrow.png
  15. BIN
      res/drawable-mdpi/button_normal.9.png
  16. BIN
      res/drawable-mdpi/button_pressed.9.png
  17. BIN
      res/drawable-mdpi/compass_background.png
  18. BIN
      res/drawable-mdpi/compass_needle.png
  19. BIN
      res/drawable-mdpi/copy.png
  20. BIN
      res/drawable-mdpi/droid.png
  21. BIN
      res/drawable-mdpi/gps.png
  22. 4
      res/drawable-mdpi/gps_fix.xml
  23. BIN
      res/drawable-mdpi/gps_fix1.png
  24. BIN
      res/drawable-mdpi/icon.png
  25. BIN
      res/drawable-mdpi/icon_call.png
  26. BIN
      res/drawable-mdpi/icon_car.png
  27. BIN
      res/drawable-mdpi/icon_details.png
  28. 7
      res/drawable-mdpi/network_fix.xml
  29. BIN
      res/drawable-mdpi/network_fix1.png
  30. BIN
      res/drawable-mdpi/network_fix2.png
  31. BIN
      res/drawable-mdpi/network_fix3.png
  32. BIN
      res/drawable-mdpi/pin_off.png
  33. BIN
      res/drawable-mdpi/pin_on.png
  34. BIN
      res/drawable-mdpi/refresh.png
  35. BIN
      res/drawable-mdpi/status_off.png
  36. BIN
      res/drawable-mdpi/status_on.png
  37. 8
      res/layout/about.xml
  38. 28
      res/layout/list.xml
  39. 15
      res/layout/list_row.xml
  40. 10
      res/layout/map.xml
  41. 11
      res/layout/mylocation_balloon.xml
  42. 76
      res/layout/pharmacy_balloon.xml
  43. 157
      res/layout/pharmacyinfo.xml
  44. 42
      res/values-en/strings.xml
  45. 42
      res/values-pt/strings.xml
  46. 10
      res/values/attrs.xml
  47. 6
      res/xml/dialog_button.xml
  48. 15
      res/xml/preferences.xml
  49. 23
      src/org/r3pek/pharmacies/ConfigValues.java
  50. 54
      src/org/r3pek/pharmacies/GetPositionOverlay.java
  51. 161
      src/org/r3pek/pharmacies/MyPositionOverlay.java
  52. 18
      src/org/r3pek/pharmacies/MyPreferences.java
  53. 166
      src/org/r3pek/pharmacies/PharmaciesOverlay.java
  54. 91
      src/org/r3pek/pharmacies/Pharmacy.java
  55. 169
      src/org/r3pek/pharmacies/PharmacyInfo.java
  56. 148
      src/org/r3pek/pharmacies/PharmacyList.java
  57. 53
      src/org/r3pek/pharmacies/PharmacyListSimpleAdapter.java
  58. 324
      src/org/r3pek/pharmacies/ViewOnMap.java
  59. 111
      src/org/r3pek/pharmacies/XMLParserHandler.java
  60. 121
      src/org/r3pek/pharmacies/utils/GeoUtils.java
  61. 19
      src/org/r3pek/pharmacies/utils/GlobalVars.java
  62. 9
      src/org/r3pek/pharmacies/utils/OnPositionChangeListener.java
  63. 175
      src/org/r3pek/pharmacies/utils/Positioner.java
  64. 97
      src/org/r3pek/pharmacies/widgets/Arrow.java
  65. 101
      src/org/r3pek/pharmacies/widgets/Compass.java
  66. 5
      src/org/r3pek/pharmacies/widgets/ImageOrientationSensor.java
  67. 48
      src/org/r3pek/pharmacies/widgets/ImageRotater.java
  68. 147
      src/org/r3pek/pharmacies/widgets/ScrollTextView.java
  69. 103
      src/org/r3pek/pharmacies/widgets/SeekBarPreference.java

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/admob-sdk-android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

2
.gitignore vendored

@ -0,0 +1,2 @@
/gen
/bin

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Farmacias</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,3 @@
#Thu Apr 15 12:30:11 WEST 2010
eclipse.preferences.version=1
encoding/<project>=UTF-8

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.r3pek.pharmacies" android:versionCode="9" android:versionName="2.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name="MyPreferences"></activity>
<activity android:name="PharmacyList"></activity>
<activity android:name="PharmacyInfo"></activity>
<activity android:label="@string/app_name" android:name="ViewOnMap">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
<meta-data android:value="a14be6d1c69912b" android:name="ADMOB_PUBLISHER_ID"/>
</application>
<uses-sdk android:minSdkVersion="3"/>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<supports-screens android:smallScreens="true" android:normalScreens="true" android:resizeable="true" android:largeScreens="true" android:anyDensity="false"></supports-screens>
</manifest>

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,13 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=Google Inc.:Google APIs:4

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/gps_fix1"/>
</level-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/network_fix1"/>
<item android:maxLevel="1" android:drawable="@drawable/network_fix2"/>
<item android:maxLevel="2" android:drawable="@drawable/network_fix3"/>
<item android:maxLevel="3" android:drawable="@drawable/network_fix2"/>
</level-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/aboutRoot">
<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_width="fill_parent"><ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:layout_marginLeft="15dip" android:textSize="20dip" android:text="@string/app_name" android:autoLink="web"></TextView>
</LinearLayout>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/about" android:gravity="center" android:id="@+id/tvAbout" android:layout_marginBottom="20dip" android:layout_marginTop="20dip"></TextView>
</LinearLayout>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:background="@drawable/list_location">
<ImageView android:id="@+id/ImageView01"
android:layout_gravity="center"
android:background="@drawable/gps_fix1"
android:scaleType="centerCrop"
android:layout_width="30dip"
android:layout_height="30dip"/>
<org.r3pek.pharmacies.widgets.ScrollTextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvLocation"
android:singleLine="true"/>
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/list"/>
</LinearLayout>

@ -0,0 +1,15 @@
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip">
<ImageView android:layout_column="0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ivStatus" android:layout_marginLeft="5dip" android:layout_gravity="center_vertical"></ImageView>
<TextView android:layout_column="1" android:text="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textSize="20dip" android:id="@+id/tvNome" android:layout_marginLeft="10dip" android:layout_gravity="center_vertical"></TextView>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_column="1" android:text="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:id="@+id/tvMorada" android:layout_marginLeft="10dip"></TextView>
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="5dip">
<LinearLayout android:layout_column="1" android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="5dip" android:layout_gravity="center_vertical">
<TextView android:text="@+id/TextView01" android:layout_width="wrap_content" android:id="@+id/tvDistancia" android:layout_marginLeft="10dip" android:layout_height="wrap_content" android:layout_gravity="center_vertical"></TextView>
<org.r3pek.pharmacies.widgets.Arrow android:id="@+id/ivDirection" android:layout_marginLeft="5dip" android:layout_height="20dip" android:layout_width="20dip"></org.r3pek.pharmacies.widgets.Arrow>
</LinearLayout>
</TableRow>
</TableLayout>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout01" android:orientation="vertical">
<com.google.android.maps.MapView android:id="@+id/MapView"
android:layout_width="fill_parent"
android:apiKey="0DR5WqW9XXYhbuY0iKmL3qQ6CIbplUTonfkmHjA" android:layout_height="wrap_content">
</com.google.android.maps.MapView>
</LinearLayout>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/dialog">
<TextView android:text="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tvLocation" android:layout_gravity="center" android:textColor="#000000"></TextView>
</LinearLayout>

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="270dip"
android:orientation="vertical"
android:background="@drawable/dialog">
<LinearLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ivStatus"
android:layout_gravity="center"/>
<TextView android:textColor="#000000"
android:id="@+id/tvBalloonName"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="left|center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_marginLeft="5dip"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dip"
android:id="@+id/tvDistance"
android:textColor="#000000"
android:gravity="right"
android:textSize="12dip"/>
<org.r3pek.pharmacies.widgets.Compass android:id="@+id/compass"
android:layout_height="15dip"
android:layout_width="15dip"
android:layout_marginLeft="5dip"
android:gravity="right"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dip"
android:layout_width="fill_parent"
android:gravity="center">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnBalloonDetalhes"
android:background="@xml/dialog_button"
android:drawableLeft="@drawable/icon_details"
android:drawablePadding="5dip"
android:text="@string/details"
android:paddingLeft="5dip"
android:paddingRight="5dip"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnBalloonTelef"
android:layout_marginLeft="5dip"
android:background="@xml/dialog_button"
android:drawablePadding="5dip"
android:drawableLeft="@drawable/icon_call"
android:text="@string/dial"
android:paddingRight="5dip"
android:paddingLeft="5dip"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnBalloonNav"
android:layout_marginLeft="5dip"
android:background="@xml/dialog_button"
android:drawableLeft="@drawable/icon_car"
android:text="@string/navigate"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:drawablePadding="5dip"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout02"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:myapp="http://schemas.android.com/apk/res/org.r3pek.pharmacies"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_width="fill_parent">
<TextView android:text="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_margin="10dip"
android:gravity="center"
android:layout_marginRight="10dip"
android:id="@+id/tvName"
android:textColor="#FFFFFF"
android:textSize="22dip"
android:scrollHorizontally="true"/>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_marginLeft="10dip">
<TableRow android:id="@+id/TableRow07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/address"
android:textStyle="bold"/>
<TextView android:id="@+id/tvAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
<TableRow android:id="@+id/TableRow06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/parish"
android:textStyle="bold"/>
<TextView android:id="@+id/tvParish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
<TableRow android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/distance"
android:textStyle="bold"/>
<LinearLayout android:id="@+id/LinearLayout04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip">
<TextView android:text="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDistance"/>
<org.r3pek.pharmacies.widgets.Arrow android:id="@+id/ivInfoDirection"
android:layout_marginLeft="5dip"
android:layout_height="20dip"
android:layout_width="20dip"/>
</LinearLayout>
</TableRow>
<TableRow android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phone_number"
android:textStyle="bold"/>
<TextView android:id="@+id/tvPhoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
<TableRow android:id="@+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/at_service"
android:textStyle="bold"/>
<TextView android:id="@+id/tvOnDuty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
<TableRow android:id="@+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/latitude"
android:textStyle="bold"/>
<TextView android:id="@+id/tvLatitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
<TableRow android:id="@+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip">
<TextView android:id="@+id/TextView05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/longitude"
android:textStyle="bold"/>
<TextView android:id="@+id/tvLongitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="10dip"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
/>
</RelativeLayout>

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about">Fármacias was developed by Carlos Silva and uses Sapo's services to fetch the information about the pharmacies. If the application was usefull, and if you want to, make a donation at www.r3pek.org. It also uses some icons from Yusuke Kamiyamane (p.yusukekamiyamane.com). Thanks.</string>
<string name="app_name">Farmácias</string>
<string name="pref_gen_cat">General</string>
<string name="pref_gen_onservice">Only display on Service</string>
<string name="pref_gen_maxdist">Max Distance</string>
<string name="distance">Distance:</string>
<string name="phone_number">Phone Number:</string>
<string name="at_service">At Service:</string>
<string name="latitude">Latitude:</string>
<string name="longitude">Longitude:</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="parish">Parish:</string>
<string name="address">Address:</string>
<string name="location_acquired">Location acquired</string>
<string name="dial">Dial</string>
<string name="share">Share</string>
<string name="navigate">Navigate</string>
<string name="copy_to_clipboard">Copy to Clipboard</string>
<string name="copied_to_clipboard">Copied to Clipboard</string>
<string name="shared_pharmacy">Shared Pharmacy</string>
<string name="details">Details</string>
<string name="error_getting_pharmacies">Error while retreiving pharmacies</string>
<string name="menu_refresh">Refresh</string>
<string name="menu_settings">Settings</string>
<string name="menu_list">List</string>
<string name="menu_about">About</string>
<string name="no_localization_active">You don't have any localization system active. Want to activate now?</string>
<string name="menu_get_gps_pos">Get GPS position</string>
<string name="menu_set_my_location">Set my location</string>
<string name="tap_on_screen">Tap on the screen to select your location</string>
<string name="now_from_GPS">Now using GPS for location</string>
<string name="menu_my_location">Goto my location</string>
<string name="not_available">Street name not available</string>
<string name="not_pharmacies_returned">Didn\'t get any pharmacies, try to increase the distance</string>
<string name="na">Not available</string>
<string name="show_on_map">Show on Map</string>
<string name="go_back">Now go back to the map</string>
<string name="loading">Loading...</string>
</resources>

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about">A aplicação Farmácias de Serviço foi desenvolvida por Carlos Silva e usa os serviços da Sapo para ir buscar as informações sobre as farmácias. Se a aplicação lhe foi útil, e se achar que deve, faça um donativo em www.r3pek.org. Também são usados alguns icons do Yusuke Kamiyamane (p.yusukekamiyamane.com). Obrigado.</string>
<string name="app_name">Farmácias</string>
<string name="pref_gen_cat">Beral</string>
<string name="pref_gen_onservice">Só de serviço</string>
<string name="pref_gen_maxdist">Distância Máxima</string>
<string name="distance">Distância:</string>
<string name="phone_number">Telefone:</string>
<string name="at_service">De serviço:</string>
<string name="latitude">Latitude:</string>
<string name="longitude">Longitude:</string>
<string name="yes">Sim</string>
<string name="no">Não</string>
<string name="parish">Freguesia:</string>
<string name="address">Morada:</string>
<string name="location_acquired">Obtida localização</string>
<string name="dial">Telefonar</string>
<string name="share">Partilhar</string>
<string name="navigate">Navegar</string>
<string name="copy_to_clipboard">Copiar para o Clipboard</string>
<string name="copied_to_clipboard">Copiado para o Clipboard</string>
<string name="shared_pharmacy">Farmácia Partilhada</string>
<string name="details">Detalhes</string>
<string name="error_getting_pharmacies">Erro ao receber as Farmácias</string>
<string name="menu_refresh">Actualizar</string>
<string name="menu_settings">Configurações</string>
<string name="menu_list">Lista</string>
<string name="menu_about">Sobre</string>
<string name="no_localization_active">Não tem nenhum sistema de localização activo. Deseja activar?</string>
<string name="menu_get_gps_pos">Obter via GPS</string>
<string name="menu_set_my_location">Definir localização</string>
<string name="tap_on_screen">Toque no ecrã para definir a sua localização</string>
<string name="now_from_GPS">Agora a usar o GPS para obter a localização</string>
<string name="menu_my_location">Ir para localização</string>
<string name="not_available">Nome da rua não disponível</string>
<string name="not_pharmacies_returned">Nenhuma farmácia obtida, tenta aumentar a distância máxima</string>
<string name="na">Não disponível</string>
<string name="show_on_map">Mostrar no Mapa</string>
<string name="go_back">Volte para o mapa</string>
<string name="loading">À procura...</string>
</resources>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</declare-styleable>
</resources>

@ -0,0 +1,6 @@
<?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/button_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="preferences">
<PreferenceCategory android:key="general"
android:title="@string/pref_gen_cat">
<CheckBoxPreference android:title="@string/pref_gen_onservice"
android:key="pref_gen_just_onservice"/>
<org.r3pek.pharmacies.widgets.SeekBarPreference android:key="pref_gen_maxdist"
android:title="@string/pref_gen_maxdist"
android:max="10"
android:defaultValue="2"
android:text=" Km"/>
</PreferenceCategory>
</PreferenceScreen>

@ -0,0 +1,23 @@
package org.r3pek.pharmacies;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class ConfigValues {
private static SharedPreferences settings;
public ConfigValues(Context ctx) {
settings = PreferenceManager.getDefaultSharedPreferences(ctx);
}
public boolean isOnlyService() {
return settings.getBoolean("pref_gen_just_onservice", false);
}
public int getRadius() {
int dist = settings.getInt("pref_gen_maxdist", 2000);
return dist == 2000 ? dist : dist * 1000;
}
}

@ -0,0 +1,54 @@
package org.r3pek.pharmacies;
import org.r3pek.pharmacies.utils.GlobalVars;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Handler;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
public class GetPositionOverlay extends ItemizedOverlay<OverlayItem> {
private PharmaciesOverlay pharmacies;
private MyPositionOverlay myLocation;
private Handler onSelectionHandler;
public GetPositionOverlay(Drawable defaultMarker, PharmaciesOverlay pharmacies, MyPositionOverlay myLocation, Handler onSelectionHandler) {
super(defaultMarker);
this.pharmacies = pharmacies;
this.myLocation = myLocation;
this.onSelectionHandler = onSelectionHandler;
populate();
}
@Override
protected OverlayItem createItem(int i) {
return null;
}
@Override
public int size() {
return 0;
}
@Override
public boolean onTap(GeoPoint p, MapView map) {
Location l = new Location(LocationManager.GPS_PROVIDER);
l.setLatitude(p.getLatitudeE6()/1000000.0);
l.setLongitude(p.getLongitudeE6()/1000000.0);
l.setAccuracy(0.0f);
GlobalVars.getPharmacies().clear();
pharmacies.refresh();
onSelectionHandler.sendEmptyMessage(0);
GlobalVars.positioner.setFixedLocation(l);
map.getOverlays().clear();
map.getOverlays().add(pharmacies);
map.getOverlays().add(myLocation);
map.postInvalidate();
return super.onTap(p, map);
}
}

@ -0,0 +1,161 @@
package org.r3pek.pharmacies;
import java.util.Timer;
import java.util.TimerTask;
import org.r3pek.pharmacies.utils.GeoUtils;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.utils.OnPositionChangeListener;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.google.android.maps.MapView.LayoutParams;
public class MyPositionOverlay extends Overlay implements OnPositionChangeListener {
private static final float dotScale = 0.6f;
private MapView map;
private Runnable runOnFirstFix;
private boolean isFirstFix;
private LevelListDrawable netLocationImage;
private LevelListDrawable gpsLocationImage;
private Timer updateDotTask;
private Context context;
private View shownView;
private Activity mapActivity;
public MyPositionOverlay(Context ctx, MapView mapView, Activity mapActivity) {
super();
map = mapView;
this.mapActivity = mapActivity;
GlobalVars.positioner.registerNotification(this);
isFirstFix = true;
context = ctx;
netLocationImage = (LevelListDrawable) ctx.getResources().getDrawable(R.drawable.network_fix);
gpsLocationImage = (LevelListDrawable) ctx.getResources().getDrawable(R.drawable.gps_fix);
updateDotTask = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
if (GlobalVars.positioner.isGPSFix()) return;
int current = netLocationImage.getLevel();
current = (current + 1) % 4;
netLocationImage.setLevel(current);
map.postInvalidate();
}
};
updateDotTask.scheduleAtFixedRate(tt, 100, 500);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if (shadow || isFirstFix) return;
if (GlobalVars.positioner.getLastGeoPoint() == null) return;
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(GlobalVars.positioner.getLastGeoPoint(), point);
// Draw the accuracy circle
float radius = projection.metersToEquatorPixels(GlobalVars.positioner.getLastAccuracy());
canvas.save();
Paint circlePaint = new Paint();
circlePaint.setStyle(Style.FILL);
circlePaint.setARGB(10, 0, 0, 255);
canvas.drawCircle(point.x, point.y, radius, circlePaint);
circlePaint.setARGB(200, 0, 0, 255);
circlePaint.setStyle(Style.STROKE);
canvas.drawCircle(point.x, point.y, radius, circlePaint);
canvas.restore();
// Draw in the right spot
Drawable d = GlobalVars.positioner.isGPSFix() ? gpsLocationImage.getCurrent() : netLocationImage.getCurrent();
int scaledImageWidth = (int)(d.getIntrinsicWidth() * dotScale);
int scaledImageHeight = (int)(d.getIntrinsicHeight() * dotScale);
float scaledImageCenterX = scaledImageWidth / 2;
float scaledImageCenterY = scaledImageHeight / 2;
canvas.save();
canvas.translate(-(scaledImageCenterX - point.x), -(scaledImageCenterY - point.y));
d.setBounds(0, 0, scaledImageWidth, scaledImageHeight);
d.getCurrent().draw(canvas);
canvas.restore();
super.draw(canvas, mapView, shadow);
}
@Override
public void onLocationChange(GeoPoint currentPos, float accuracy) {
if (isFirstFix) {
isFirstFix = false;
runOnFirstFix.run();
}
map.postInvalidate();
}
public void disableMyLocation() {
GlobalVars.positioner.unregisterNotification(this);
}
public void enableMyLocation() {
GlobalVars.positioner.registerNotification(this);
}
public void runOnFirstFix(Runnable r) {
runOnFirstFix = r;
}
@Override
public boolean onTap(GeoPoint p, MapView map) {
Point pointTap = map.getProjection().toPixels(p, null);
Point pointMap = map.getProjection().toPixels(GlobalVars.positioner.getLastGeoPoint(), null);
if (Math.abs(pointTap.x - pointMap.x) <= 20 && Math.abs(pointMap.y - pointTap.y) <= 20 && shownView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout)inflater.inflate(R.layout.mylocation_balloon, null);
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, GlobalVars.positioner.getLastGeoPoint(), 0, -35, LayoutParams.MODE_MAP | LayoutParams.CENTER);
final TextView tvLocation = (TextView)ll.findViewById(R.id.tvLocation);
tvLocation.setText(context.getString(R.string.loading));
map.getController().animateTo(GlobalVars.positioner.getLastGeoPoint());
map.addView(ll, lp);
shownView = ll;
GeoUtils.getLocationName(context, new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
final String location = msg.getData().getString("location");
mapActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
tvLocation.setText(location);
}
});
return true;
}
}));
} else if (shownView != null) {
map.removeView(shownView);
shownView = null;
}
return super.onTap(p, map);
}
}

@ -0,0 +1,18 @@
package org.r3pek.pharmacies;
import org.r3pek.pharmacies.widgets.SeekBarPreference;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class MyPreferences extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
SeekBarPreference sbp = (SeekBarPreference) findPreference("pref_gen_maxdist");
sbp.setMin(1);
}
}

@ -0,0 +1,166 @@
package org.r3pek.pharmacies;
import java.util.LinkedList;
import org.r3pek.pharmacies.utils.GeoUtils;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.widgets.Compass;
import org.r3pek.pharmacies.widgets.ImageRotater;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.MapView.LayoutParams;
public class PharmaciesOverlay extends ItemizedOverlay<OverlayItem> {
private Context ctx;
private MapView mapView;
private View shownView;
private SensorManager sm;
private ImageRotater cRotator;
private Compass compass;
private LinkedList<Pharmacy> pharmacies;
public PharmaciesOverlay(Drawable defaultMarker, Context ctx, MapView mapView) {
super(boundCenterBottom(defaultMarker));
this.ctx = ctx;
this.mapView = mapView;
shownView = null;
populate();
sm = (SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
cRotator = new ImageRotater();
pharmacies = new LinkedList<Pharmacy>();
}
@Override
protected synchronized OverlayItem createItem(int i) {
Pharmacy p = pharmacies.get(i);
OverlayItem result = new OverlayItem(p.getGeoPoint(), p.getName(), "");
if (p.isAtService())
result.setMarker(boundCenterBottom(ctx.getResources().getDrawable(R.drawable.pin_on)));
return result;
}
@Override
public synchronized int size() {
if (pharmacies == null) return 0;
return pharmacies.size();
}
@Override
protected boolean onTap(final int i) {
if (mapView.getChildCount() > 0) return true;
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout)inflater.inflate(R.layout.pharmacy_balloon, null);
final Pharmacy pharm = GlobalVars.getPharmacies().get(i);
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, pharm.getGeoPoint(), 0, -70, LayoutParams.MODE_MAP | LayoutParams.CENTER);
TextView tvName = (TextView)ll.findViewById(R.id.tvBalloonName);
TextView tvDistance = (TextView)ll.findViewById(R.id.tvDistance);
ImageView ivStatus = (ImageView)ll.findViewById(R.id.ivStatus);
Button btnDetalhes = (Button)ll.findViewById(R.id.btnBalloonDetalhes);
Button btnTelef = (Button)ll.findViewById(R.id.btnBalloonTelef);
Button btnNav = (Button)ll.findViewById(R.id.btnBalloonNav);
compass = (Compass)ll.findViewById(R.id.compass);
btnTelef.setEnabled(!pharm.getPhoneNumber().equals(""));
compass.setBearing(GeoUtils.bearing(GlobalVars.positioner.getLastGeoPoint(), pharm.getGeoPoint()));
compass.setOrientation(cRotator.getLastOrientation());
sm.registerListener(cRotator, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
cRotator.addImage(compass);
tvName.setText(pharm.getName());
tvDistance.setText(pharm.getDistance().substring(0, pharm.getDistance().indexOf(".")) + "m");
ivStatus.setBackgroundResource(pharm.isAtService() ? R.drawable.status_on : R.drawable.status_off);
btnDetalhes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent pharmInfo = new Intent(ctx, PharmacyInfo.class);
pharmInfo.putExtra("org.r3pek.pharmacies.Pharmacy", pharm);
pharmInfo.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(pharmInfo);
}
});
btnTelef.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + pharm.getPhoneNumber()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
}
});
btnNav.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder url = new StringBuilder();
url.append("http://maps.google.com/maps?f=d&hl=en");
url.append("&saddr=");
url.append( Double.toString((double)GlobalVars.positioner.getLastGeoPoint().getLatitudeE6()/1.0E6 ));
url.append(",");
url.append( Double.toString((double)GlobalVars.positioner.getLastGeoPoint().getLongitudeE6()/1.0E6 ));
url.append("&daddr=");
url.append( Double.toString((double)pharm.getGeoPoint().getLatitudeE6()/1.0E6 ));
url.append(",");
url.append( Double.toString((double)pharm.getGeoPoint().getLongitudeE6()/1.0E6 ));
url.append("&dirflg=d&nav=1");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url.toString()));
intent.addFlags(0x10800000);
intent.setClassName("com.google.android.apps.m4ps", "com.google.android.maps.driveabout.app.NavigationActivity");
try {
ctx.startActivity(intent);
} catch (ActivityNotFoundException e) {
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.driveabout.app.NavigationActivity");
try {
ctx.startActivity(intent);
} catch (ActivityNotFoundException e2) { }
}
}
});
shownView = ll;
mapView.addView(ll, lp);
mapView.getController().animateTo(pharm.getGeoPoint());
return super.onTap(i);
}
public void removeBallon() {
cRotator.delImage(compass);
sm.unregisterListener(cRotator);
mapView.removeView(shownView);
}
@Override
public boolean onTap(GeoPoint p, MapView map) {
removeBallon();
return super.onTap(p, map);
}
public synchronized void refresh() {
pharmacies.clear();
for (Pharmacy p : GlobalVars.getPharmacies())
pharmacies.add(p);
populate();
}
}

@ -0,0 +1,91 @@
package org.r3pek.pharmacies;
import java.io.Serializable;
import com.google.android.maps.GeoPoint;
public class Pharmacy implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String address;
private String phoneNumber;
private String latitude;
private String longitude;
private String distance;
private Boolean atService;
private String parish;
public Pharmacy() {
}
public String getName() {
return name == null ? "" : name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address == null ? "" : address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber == null ? "" : phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getLatitude() {
return latitude == null ? "" : latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude == null ? "" : longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getDistance() {
return distance == null ? "" : distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public boolean isAtService() {
return atService;
}
public void setAtService(boolean atService) {
this.atService = atService;
}
public String getParish() {
return parish == null ? "" : parish;
}
public void setParish(String parish) {
this.parish = parish;
}
public GeoPoint getGeoPoint() {
return new GeoPoint((int)(Double.parseDouble(latitude) * 1E6), (int)(Double.parseDouble(longitude) * 1E6));
}
}

@ -0,0 +1,169 @@
package org.r3pek.pharmacies;
import org.r3pek.pharmacies.utils.GeoUtils;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.widgets.Arrow;
import org.r3pek.pharmacies.widgets.ImageRotater;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class PharmacyInfo extends Activity {
private final static int MENU_DIAL = 0;
private final static int MENU_SHARE = 1;
private final static int MENU_NAVIGATE = 2;
private final static int MENU_COPY = 3;
private final static int MENU_SHOWONMAP = 4;
private SensorManager sm;
private Pharmacy p;
private ImageRotater arrowChangerSensor;
private int pharmacyIndex;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pharmacyinfo);
p = (Pharmacy)getIntent().getSerializableExtra("org.r3pek.pharmacies.Pharmacy");
pharmacyIndex = getIntent().getIntExtra("org.r3pek.pharmacies.PharmacyIndex", -1);
TextView tvName = (TextView)findViewById(R.id.tvName);
TextView tvAddress = (TextView)findViewById(R.id.tvAddress);
TextView tvParish = (TextView)findViewById(R.id.tvParish);
TextView tvPhoneNumber = (TextView)findViewById(R.id.tvPhoneNumber);
TextView tvLatitude = (TextView)findViewById(R.id.tvLatitude);
TextView tvLongitude = (TextView)findViewById(R.id.tvLongitude);
TextView tvDist = (TextView)findViewById(R.id.tvDistance);
Arrow arrow = (Arrow)findViewById(R.id.ivInfoDirection);
TextView tvService = (TextView)findViewById(R.id.tvOnDuty);
sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
arrowChangerSensor = new ImageRotater();
arrow.setBearing(GeoUtils.bearing(GlobalVars.positioner.getLastGeoPoint(), p.getGeoPoint()));
arrow.setOrientation(arrowChangerSensor.getLastOrientation());
tvName.setText(p.getName());
tvAddress.setText(p.getAddress());
tvParish.setText(p.getParish());
tvPhoneNumber.setText(p.getPhoneNumber().equals("") ? getString(R.string.na) : p.getPhoneNumber());
tvLatitude.setText(p.getLatitude());
tvLongitude.setText(p.getLongitude());
tvDist.setText(p.getDistance().substring(0, p.getDistance().indexOf(".")) + "m");
tvService.setText(p.isAtService() ? getString(R.string.yes) : getString(R.string.no));
}
@Override
public void onResume() {
sm.registerListener(arrowChangerSensor, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
arrowChangerSensor.addImage((Arrow)findViewById(R.id.ivInfoDirection));
super.onResume();
}
@Override
public void onPause() {
arrowChangerSensor.delImage((Arrow)findViewById(R.id.ivInfoDirection));
sm.unregisterListener(arrowChangerSensor);
super.onPause();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_DIAL, 0, getString(R.string.dial)).setIcon(android.R.drawable.ic_menu_call);
menu.add(0, MENU_SHARE, 1, getString(R.string.share)).setIcon(android.R.drawable.ic_menu_share);
menu.add(0, MENU_NAVIGATE, 2, getString(R.string.navigate)).setIcon(android.R.drawable.ic_menu_directions);
menu.add(0, MENU_COPY, 3, getString(R.string.copy_to_clipboard)).setIcon(R.drawable.copy);
menu.add(0, MENU_SHOWONMAP, 4, getString(R.string.show_on_map)).setIcon(android.R.drawable.ic_menu_mapmode);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(MENU_DIAL).setEnabled(!p.getPhoneNumber().equals(""));
menu.findItem(MENU_SHOWONMAP).setEnabled(pharmacyIndex != -1);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_DIAL:
makeCall();
break;
case MENU_SHARE:
share();
break;
case MENU_NAVIGATE:
openNavigation();
break;
case MENU_COPY:
copyAddrToClipboard();
break;
case MENU_SHOWONMAP:
showOnMap();
break;
}
return true;
}
private void showOnMap() {
GlobalVars.pharmaciesOverlay.onTap(pharmacyIndex);
Toast.makeText(getApplicationContext(), R.string.go_back, Toast.LENGTH_SHORT).show();
}
private void share() {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, p.getName() + '\n' +
getString(R.string.address) + " " + p.getAddress() + '\n' +
getString(R.string.distance) + " " + p.getDistance().substring(0, p.getDistance().indexOf(".")) + "m" + '\n' +
getString(R.string.phone_number) + " " + (p.getPhoneNumber().equals("") ? getString(R.string.na) : p.getPhoneNumber()) + '\n' +
getString(R.string.at_service) + " " + (p.isAtService() ? getString(R.string.yes) : getString(R.string.no)));
startActivity(i);
}
private void copyAddrToClipboard() {
ClipboardManager cm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
cm.setText(p.getAddress());
Toast.makeText(getApplicationContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
private void makeCall() {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + p.getPhoneNumber()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
private void openNavigation() {
double lat = Double.parseDouble(p.getLatitude());
double lng = Double.parseDouble(p.getLongitude());
Location loc = GlobalVars.positioner.getLastLocation();
StringBuilder url = new StringBuilder();
url.append("http://maps.google.com/maps?f=d&hl=en");
url.append("&saddr=");
url.append( Double.toString(loc.getLatitude()));
url.append(",");
url.append( Double.toString(loc.getLongitude()));
url.append("&daddr=");
url.append( Double.toString(lat));
url.append(",");
url.append( Double.toString(lng));
url.append("&ie=UTF8&0&om=0");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url.toString()));
startActivity(intent);
}
}

@ -0,0 +1,148 @@
package org.r3pek.pharmacies;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import org.r3pek.pharmacies.utils.GeoUtils;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.widgets.ImageRotater;
import org.r3pek.pharmacies.widgets.ScrollTextView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class PharmacyList extends Activity implements OnItemClickListener {
private Context context;
private SensorManager sm;
private ImageRotater arrowChangerSensor;
private ListView list;
private ScrollTextView tvLocation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
context = getApplicationContext();
list = (ListView)findViewById(R.id.list);
sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
arrowChangerSensor = new ImageRotater();
tvLocation = (ScrollTextView) findViewById(R.id.tvLocation);
tvLocation.setText(getString(R.string.loading));
tvLocation.setRndDuration(10000);
GeoUtils.getLocationName(context, new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
final String location = msg.getData().getString("location");
runOnUiThread(new Runnable() {
@Override
public void run() {
tvLocation.setText(location);
}
});
if (location.equals(getString(R.string.not_available))) {
final LinearLayout ll02 = (LinearLayout)findViewById(R.id.LinearLayout02);
TranslateAnimation anim = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f
);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
ll02.setVisibility(View.GONE);
}
});
anim.setStartOffset(2000);
anim.setDuration(2000);
anim.setInterpolator(new AccelerateInterpolator(1));
ll02.startAnimation(anim);
} else
runOnUiThread(new Runnable() {
@Override
public void run() {
tvLocation.startScroll();
}
});
return true;
}
}));
list.setOnItemClickListener(this);
LinkedList<Pharmacy> allPharm = GlobalVars.getPharmacies();
ArrayList<HashMap<String, String>> pharmacies = new ArrayList<HashMap<String, String>>();
for (Pharmacy p : allPharm) {
HashMap<String, String> pharmacy = new HashMap<String, String>();
pharmacy.put("name", p.getName());
pharmacy.put("addr", p.getAddress());
DecimalFormat df = new DecimalFormat("#.#");
double dist = Double.parseDouble(p.getDistance().substring(0, p.getDistance().indexOf("."))) / 1000;
pharmacy.put("dist", df.format(dist) + "km");
pharmacies.add(pharmacy);
}
/* Create the Adapter to show the information */
SimpleAdapter adap;
adap = new PharmacyListSimpleAdapter(context, pharmacies, R.layout.list_row,
new String[] {"name", "addr", "dist"},
new int[] {R.id.tvNome, R.id.tvMorada, R.id.tvDistancia},
arrowChangerSensor
);
list.setAdapter(adap);
}
@Override
protected void onResume() {
super.onResume();
sm.registerListener(arrowChangerSensor, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
sm.unregisterListener(arrowChangerSensor);
super.onPause();
}
@Override
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
Intent i = new Intent(getApplicationContext(), PharmacyInfo.class);
i.putExtra("org.r3pek.pharmacies.Pharmacy", GlobalVars.getPharmacies().get(position));
i.putExtra("org.r3pek.pharmacies.PharmacyIndex", position);
startActivity(i);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
tvLocation.startScroll();
}
}

@ -0,0 +1,53 @@
package org.r3pek.pharmacies;
import java.util.List;
import java.util.Map;
import org.r3pek.pharmacies.utils.GeoUtils;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.widgets.Arrow;
import org.r3pek.pharmacies.widgets.ImageRotater;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class PharmacyListSimpleAdapter extends SimpleAdapter {
private ImageRotater arrowCallback;
public PharmacyListSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to, ImageRotater arrowCallback) {
super(context, data, resource, from, to);
this.arrowCallback = arrowCallback;
}
private Pharmacy getPharmacyWithName(String name) {
for (Pharmacy p : GlobalVars.getPharmacies())
if (p.getName().equals(name)) return p;
return null;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ImageView ivStatus = (ImageView) v.findViewById(R.id.ivStatus);
Arrow ivDirection = (Arrow) v.findViewById(R.id.ivDirection);
TextView tvNome = (TextView) v.findViewById(R.id.tvNome);
Pharmacy p = getPharmacyWithName(tvNome.getText().toString());
ivDirection.setBearing(GeoUtils.bearing(GlobalVars.positioner.getLastGeoPoint(), p.getGeoPoint()));
ivDirection.setOrientation(arrowCallback.getLastOrientation());
arrowCallback.addImage(ivDirection);
if (p.isAtService())
ivStatus.setImageResource(R.drawable.status_on);
else
ivStatus.setImageResource(R.drawable.status_off);
return v;
}
}

@ -0,0 +1,324 @@
package org.r3pek.pharmacies;
import java.net.URL;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.r3pek.pharmacies.utils.GlobalVars;
import org.r3pek.pharmacies.utils.OnPositionChangeListener;
import org.r3pek.pharmacies.utils.Positioner;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class ViewOnMap extends MapActivity implements OnPositionChangeListener {
private static final int MENU_REFRESH = 0;
private static final int MENU_SETTINGS = 1;
private static final int MENU_LIST = 2;
private static final int MENU_ABOUT = 3;
private static final int MENU_SETMYPOSITION = 4;
private static final int MENU_GETPOSITIONFROMGPS = 5;
private static final int MENU_MYPOSITION = 6;
private static final int DIALOG_ABOUT = 0;
private PharmaciesOverlay pharmaciesOverlay;
private MyPositionOverlay myPositionOverlay;
private MapView map;
private ConfigValues configs;
private Handler endThreadHandler;
private boolean hadFirstFix;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
/* Create objects */
map = (MapView)findViewById(R.id.MapView);
pharmaciesOverlay = new PharmaciesOverlay(getResources().getDrawable(R.drawable.pin_off), getApplicationContext(), map);
GlobalVars.pharmaciesOverlay = pharmaciesOverlay;
configs = new ConfigValues(getApplicationContext());
GlobalVars.positioner = new Positioner(getApplicationContext());
myPositionOverlay = new MyPositionOverlay(getApplicationContext(), map, this);
GlobalVars.getPharmacies().clear();
pharmaciesOverlay.refresh();
/* Check if we have location providers enabled */
checkLocationProviders();
/* Setup the map */
map.setBuiltInZoomControls(true);
map.setClickable(true);
map.setEnabled(true);
MapController mc = map.getController();
List<Overlay> mapOverlays = map.getOverlays();
mapOverlays.add(pharmaciesOverlay);
mapOverlays.add(myPositionOverlay);
mc.setZoom(15);
/* Center view on ourselfs on first fix */
myPositionOverlay.runOnFirstFix(new Runnable() {
@Override
public void run() {
hadFirstFix = true;
GeoPoint p = GlobalVars.positioner.getLastGeoPoint();
populatePharmacies(p);
map.getController().animateTo(p);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), R.string.location_acquired, Toast.LENGTH_SHORT).show();
}
});
}
});
/* Create the handler for when we receive the Pharmacy list */
endThreadHandler = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == 0) {
pharmaciesOverlay.refresh();
map.postInvalidate();
map.setClickable(true);
if (GlobalVars.getPharmacies().size() == 0)
Toast.makeText(getApplicationContext(), R.string.not_pharmacies_returned, Toast.LENGTH_LONG).show();
} else
Toast.makeText(getApplicationContext(), R.string.error_getting_pharmacies, Toast.LENGTH_SHORT).show();
return true;
}
});
hadFirstFix = false;
}
private void checkLocationProviders() {
if (!GlobalVars.positioner.isLocalizationActive())
buildAlertMessageNoProviders();
}
private void buildAlertMessageNoProviders() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.no_localization_active)
.setCancelable(false)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
launchGPSOptions();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
private void launchGPSOptions() {
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
public void onPause() {
myPositionOverlay.disableMyLocation();
GlobalVars.positioner.unregisterNotification(this);
GlobalVars.positioner.cancelUpdates();
super.onPause();
}
public void onResume() {
myPositionOverlay.enableMyLocation();
GlobalVars.positioner.registerNotification(this);
GlobalVars.positioner.requestUpdates();
super.onResume();
}
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_REFRESH, 0, R.string.menu_refresh).setIcon(R.drawable.refresh);
menu.add(0, MENU_GETPOSITIONFROMGPS, 0, R.string.menu_get_gps_pos).setIcon(R.drawable.gps);
menu.add(0, MENU_SETMYPOSITION, 0, R.string.menu_set_my_location).setIcon(android.R.drawable.ic_menu_myplaces);
menu.add(0, MENU_MYPOSITION, 0, R.string.menu_my_location).setIcon(android.R.drawable.ic_menu_mylocation);
menu.add(0, MENU_LIST, 0, R.string.menu_list).setIcon(android.R.drawable.ic_menu_agenda);
menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences);
menu.add(0, MENU_ABOUT, 0, R.string.menu_about).setIcon(android.R.drawable.ic_menu_info_details);;
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(MENU_REFRESH).setEnabled(hadFirstFix);
menu.findItem(MENU_LIST).setEnabled(GlobalVars.getPharmacies().size() > 0);
if (GlobalVars.positioner.isFixedLocation()) {
menu.findItem(MENU_GETPOSITIONFROMGPS).setVisible(true);
menu.findItem(MENU_SETMYPOSITION).setVisible(false);
} else {
menu.findItem(MENU_GETPOSITIONFROMGPS).setVisible(false);
menu.findItem(MENU_SETMYPOSITION).setVisible(true);
}
menu.findItem(MENU_MYPOSITION).setEnabled(hadFirstFix);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_REFRESH:
populatePharmacies(GlobalVars.positioner.getLastGeoPoint());
return true;
case MENU_SETTINGS:
startActivity(new Intent(getApplicationContext(), MyPreferences.class));
return true;
case MENU_LIST:
Intent i = new Intent(getApplicationContext(), PharmacyList.class);
startActivity(i);
return true;
case MENU_ABOUT:
showDialog(DIALOG_ABOUT);
return true;
case MENU_SETMYPOSITION:
setMyLocation();
return true;
case MENU_GETPOSITIONFROMGPS:
getLocationFromGPS();
return true;
case MENU_MYPOSITION:
gotoMyLocation();
return true;
}
return false;
}
private void gotoMyLocation() {
map.getController().animateTo(GlobalVars.positioner.getLastGeoPoint());
}
private void setMyLocation() {
List<Overlay> mapOverlays = map.getOverlays();
pharmaciesOverlay.removeBallon();
mapOverlays.clear();
Handler h = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
hadFirstFix = true;
GlobalVars.getPharmacies().clear();
pharmaciesOverlay.refresh();
populatePharmacies(GlobalVars.positioner.getLastGeoPoint());
return true;
}
});
mapOverlays.add(new GetPositionOverlay(null, pharmaciesOverlay, myPositionOverlay, h));
map.postInvalidate();
Toast.makeText(getApplicationContext(), R.string.tap_on_screen, Toast.LENGTH_LONG).show();
}
private void getLocationFromGPS() {
hadFirstFix = false;
GlobalVars.positioner.cancelFixedLocation();
GlobalVars.getPharmacies().clear();
pharmaciesOverlay.refresh();
map.postInvalidate();
Toast.makeText(getApplicationContext(), R.string.now_from_GPS, Toast.LENGTH_SHORT).show();
}
public void populatePharmacies(final GeoPoint curPos) {
Runnable r = new Runnable() {
@Override
public void run() {
String service = configs.isOnlyService() ? "GetPharmaciesAtServiceByCoordinates" : "GetPharmaciesByCoordinates";
try {
URL url = new URL("http://services.sapo.pt/Pharmacy/" + service + "?latitude=" + (curPos.getLatitudeE6() / 1E6) + "&longitude=" + (curPos.getLongitudeE6() / 1E6) + "&radius=" + configs.getRadius());
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader*/
XMLParserHandler handler = new XMLParserHandler();
xr.setContentHandler(handler);
/* Parse the xml-data from our URL. */
xr.parse(new InputSource(url.openStream()));
/* Parsing has finished. */
GlobalVars.getPharmacies().clear();
pharmaciesOverlay.refresh();
/* Check if server returned an error */
if (handler.getPharmacies() == null) {
endThreadHandler.sendEmptyMessage(1);
return;
}
/* Our XMLParserHandler now provides the parsed data to us. */
for (Pharmacy p : handler.getPharmacies())
GlobalVars.getPharmacies().add(p);
pharmaciesOverlay.refresh();
endThreadHandler.sendEmptyMessage(0);
} catch (Exception e) { endThreadHandler.sendEmptyMessage(1); }
}
};
Thread t = new Thread(r);
t.start();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
public Dialog onCreateDialog(int id) {
Dialog d;
switch (id) {
case DIALOG_ABOUT: {
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about, (ViewGroup)findViewById(R.id.aboutRoot));
ImageView image = (ImageView)layout.findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.icon);
Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
d = builder.create();
break;
}
default: d = null;
}
return d;
}
@Override
public void onLocationChange(GeoPoint currentPos, float accuracy) {
if (!hadFirstFix) {
map.getController().animateTo(currentPos);
populatePharmacies(currentPos);
hadFirstFix = true;
}
map.postInvalidate();
}
}

@ -0,0 +1,111 @@
package org.r3pek.pharmacies;
import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class XMLParserHandler extends DefaultHandler {
private boolean inName = false;
private boolean inAddress = false;
private boolean inZipCode = false;
private boolean inMunicipality = false;
private boolean inLatitude = false;
private boolean inLongitude = false;
private boolean inPhone = false;
private boolean inDistance = false;
private boolean inIsAtService = false;
private boolean inParish = false;
private boolean error = false;
private boolean inErrorMessage;
private String errorMessage;
private Pharmacy currentPharmacy;
private ArrayList<Pharmacy> result;
public XMLParserHandler() {
result = new ArrayList<Pharmacy>();
}
private void checkTag(String tag, boolean newValue) {
if ((tag.equals("GetPharmaciesByCoordinatesResponse") || tag.equals("GetPharmaciesAtServiceByCoordinatesResponse")) && newValue) {
if (error) error = false;
result.clear();
} else if (tag.equals("Pharmacy")) {
if (newValue)
currentPharmacy = new Pharmacy();
else
result.add(currentPharmacy);
} else if (tag.equals("Name"))
inName = newValue;
else if (tag.equals("Street"))
inAddress = newValue;
else if (tag.equals("ZipCode"))
inZipCode = newValue;
else if (tag.equals("Municipality"))
inMunicipality = newValue;
else if (tag.equals("Latitude"))
inLatitude = newValue;
else if (tag.equals("Longitude"))
inLongitude = newValue;
else if (tag.equals("Phone"))
inPhone = newValue;
else if (tag.equals("Distance"))
inDistance = newValue;
else if (tag.equals("IsAtService"))
inIsAtService = newValue;
else if (tag.equals("Parish"))
inParish = newValue;
else if (tag.equals("Fault"))
error = true;
else if (tag.equals("FaultString"))
inErrorMessage = newValue;
}
public void startElement(String uri, String name, String qName, Attributes atts) {
checkTag(name.trim(), true);
}
public void endElement(String uri, String name, String qName) {
checkTag(name.trim(), false);
}
public void characters(char ch[], int start, int length) {
String chars = (new String(ch).substring(start, start + length));
if (inName)
currentPharmacy.setName(currentPharmacy.getName() + chars);
else if (inAddress)
currentPharmacy.setAddress(currentPharmacy.getAddress() + chars);
else if (inZipCode)
currentPharmacy.setAddress(currentPharmacy.getAddress() + "\n" + chars);
else if (inMunicipality)
currentPharmacy.setAddress(currentPharmacy.getAddress() + " " + chars);
else if (inLatitude)
currentPharmacy.setLatitude(currentPharmacy.getLatitude() + chars);
else if (inLongitude)
currentPharmacy.setLongitude(currentPharmacy.getLongitude() + chars);
else if (inPhone)
currentPharmacy.setPhoneNumber(currentPharmacy.getPhoneNumber() + chars);
else if (inDistance)
currentPharmacy.setDistance(currentPharmacy.getDistance() + chars);
else if (inIsAtService)
currentPharmacy.setAtService(Boolean.parseBoolean(chars));
else if (inParish)
currentPharmacy.setParish(currentPharmacy.getParish() + chars);
else if (inErrorMessage)
errorMessage += chars;
}
public ArrayList<Pharmacy> getPharmacies() {
if (error) return null;
return result;
}
public String getErrorMessage() {
return errorMessage;
}
}

@ -0,0 +1,121 @@
package org.r3pek.pharmacies.utils;
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import java.util.List;
import org.r3pek.pharmacies.R;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.google.android.maps.GeoPoint;
/**
* Library for some use useful latitude/longitude math
*/
public class GeoUtils {
private static double MILLION = 1000000;
/**
* Computes the bearing in degrees between two points on Earth.
*
* @param lat1 Latitude of the first point
* @param lon1 Longitude of the first point
* @param lat2 Latitude of the second point
* @param lon2 Longitude of the second point
* @return Bearing between the two points in degrees. A value of 0 means due
* north.
*/
public static float bearing(double lat1, double lon1, double lat2, double lon2) {
double lat1Rad = Math.toRadians(lat1);
double lat2Rad = Math.toRadians(lat2);
double deltaLonRad = Math.toRadians(lon2 - lon1);
double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad);
double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad)
* Math.cos(deltaLonRad);
return radToBearing(Math.atan2(y, x));
}
/**
* Computes the bearing in degrees between two points on Earth.
*
* @param p1 First point
* @param p2 Second point
* @return Bearing between the two points in degrees. A value of 0 means due
* north.
*/
public static float bearing(GeoPoint p1, GeoPoint p2) {
double lat1 = p1.getLatitudeE6() / MILLION;
double lon1 = p1.getLongitudeE6() / MILLION;
double lat2 = p2.getLatitudeE6() / MILLION;
double lon2 = p2.getLongitudeE6() / MILLION;
return bearing(lat1, lon1, lat2, lon2);
}
/**
* Converts an angle in radians to degrees
*/
public static float radToBearing(double rad) {
return (float) ((Math.toDegrees(rad) + 360) % 360);
}
/**
* Returns the current's location address
*/
public static void getLocationName(final Context context, final Handler h) {
Runnable r = new Runnable() {
@Override
public void run() {
Geocoder g = new Geocoder(context);
Message m = new Message();
Bundle b = new Bundle();
List<Address> addresses = null;
try {
addresses = g.getFromLocation(GlobalVars.positioner.getLastLocation().getLatitude(), GlobalVars.positioner.getLastLocation().getLongitude(), 1);
} catch (IOException e) { }
if (addresses == null || addresses.size() == 0) {
b.putString("location", context.getString(R.string.not_available));
m.setData(b);
h.dispatchMessage(m);
}
String result = "";
for (int i = 0; i <= addresses.get(0).getMaxAddressLineIndex(); i++)
result += addresses.get(0).getAddressLine(i) + ", ";
if (result.equals(""))
b.putString("location", context.getString(R.string.not_available));
else
b.putString("location", result.substring(0, result.length() - 2));
m.setData(b);
h.dispatchMessage(m);
}
};
Thread t = new Thread(r);
t.start();
}
}

@ -0,0 +1,19 @@
package org.r3pek.pharmacies.utils;
import java.util.LinkedList;
import org.r3pek.pharmacies.PharmaciesOverlay;
import org.r3pek.pharmacies.Pharmacy;
public class GlobalVars {
public static Positioner positioner;
public static PharmaciesOverlay pharmaciesOverlay;
private static LinkedList<Pharmacy> pharmacies;
public synchronized static LinkedList<Pharmacy> getPharmacies() {
if (pharmacies == null)
pharmacies = new LinkedList<Pharmacy>();
return pharmacies;
}
}

@ -0,0 +1,9 @@
package org.r3pek.pharmacies.utils;
import com.google.android.maps.GeoPoint;
public interface OnPositionChangeListener {
void onLocationChange(GeoPoint currentPos, float accuracy);
}

@ -0,0 +1,175 @@
package org.r3pek.pharmacies.utils;
import java.util.LinkedList;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import com.google.android.maps.GeoPoint;
public class Positioner implements LocationListener {
private Location currentLocation;
private GeoPoint currentGeoPoint;
private float currentAccuracy;
private LinkedList<OnPositionChangeListener> toNotify;
private LocationManager locationManager;
private boolean isUpdating;
private boolean hadGPSFix;
private boolean isFixedLocation;
private boolean isGPSFix;
public Positioner(Context context) {
toNotify = new LinkedList<OnPositionChangeListener>();
locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
isUpdating = false;
hadGPSFix = false;
isFixedLocation = false;
isGPSFix = false;
initLocation();
requestUpdates();
}
private void initLocation() {
if (!isLocalizationActive()) return;
Location loc_net = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location loc_gps = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location loc = loc_gps == null ? loc_net : loc_gps;
if (loc == null) return;
currentLocation = loc;
currentGeoPoint = new GeoPoint((int)(loc.getLatitude() * 1E6),
(int)(loc.getLongitude() * 1E6));
currentAccuracy = loc.getAccuracy();
notifyAllClients();
}
private String getBestLocationProvider() {
if (!isLocalizationActive())
return LocationManager.GPS_PROVIDER;
else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
return LocationManager.GPS_PROVIDER;
else return LocationManager.NETWORK_PROVIDER;
}
public void requestUpdates() {
if (isUpdating) return;
Log.d("Positioner", "Enabling location Updates");
if (getBestLocationProvider().equals(LocationManager.GPS_PROVIDER) && !hadGPSFix)
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(getBestLocationProvider(), 0, 0, this);
isUpdating = true;
}
public void cancelUpdates() {
if (!isUpdating) return;
Log.d("Positioner", "Disabling location Updates");
locationManager.removeUpdates(this);
isUpdating = false;
}
public boolean isLocalizationActive() {
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
public void registerNotification(OnPositionChangeListener object) {
Log.d("Positioner", "Adding notification " + object.getClass().getCanonicalName());
toNotify.add(object);
}
public void unregisterNotification(OnPositionChangeListener object) {
Log.d("Positioner", "Removing notification " + object.getClass().getCanonicalName());
toNotify.remove(object);
}
public Location getLastLocation() {
return currentLocation;
}
public GeoPoint getLastGeoPoint() {
return currentGeoPoint;
}
public float getLastAccuracy() {
return currentAccuracy;
}
@Override
public synchronized void onLocationChanged(Location location) {
Log.d("Positioner", "New location arrived");
/* If we already have a GPS fix, discard Network locations */
if (hadGPSFix && location.getProvider().equals(LocationManager.NETWORK_PROVIDER))
return;
/* Save location */
currentLocation = location;
currentGeoPoint = new GeoPoint((int)(location.getLatitude() * 1E6),
(int)(location.getLongitude() * 1E6));
currentAccuracy = location.getAccuracy();
/* Did it come from GPS or Network? */
if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
hadGPSFix = true;
isGPSFix = true;
} else {
hadGPSFix = false;
isGPSFix = false;
}
/* Notify the clients if there is any */
if (toNotify.size() > 0)
notifyAllClients();
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Positioner", "Provider enabled: " + provider);
initLocation();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
private synchronized void notifyAllClients() {
Log.d("Positioner", "Notifying clients");
for (OnPositionChangeListener l : toNotify)
l.onLocationChange(currentGeoPoint, currentAccuracy);
}
public synchronized void setFixedLocation(Location location) {
if (!isFixedLocation) {
cancelUpdates();
isFixedLocation = true;
}
onLocationChanged(location);
}
public void cancelFixedLocation() {
if (!isFixedLocation) return;
hadGPSFix = false;
requestUpdates();
isFixedLocation = false;
}
public boolean isFixedLocation() {
return isFixedLocation;
}
public boolean isGPSFix() {
return isGPSFix;
}
}

@ -0,0 +1,97 @@
package org.r3pek.pharmacies.widgets;
import org.r3pek.pharmacies.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
public class Arrow extends View implements ImageOrientationSensor {
/* Orientation
* 0 -> portrait
* 1 -> landscape
* 2 -> inverted portrait
* 3 -> inverted landscape
*/
private final int orientationCompensation[] = {0, 90, 180, 270};
private Context ctx;
private float bearing;
private float orientation;
private Drawable d;
public Arrow(Context context) {
super(context);
ctx = context;
setDrawable();
}
public Arrow(Context context, AttributeSet attrs) {
super(context, attrs);
ctx = context;
setDrawable();
}
public Arrow(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ctx = context;
setDrawable();
}
private void setDrawable() {
d = ctx.getResources().getDrawable(R.drawable.arrow);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Display display = ((WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
float rotation = bearing - orientation - orientationCompensation[display.getOrientation()];
float keyPoints[] = {0, -9, -5, 9, 5, 9};
Matrix matrix = new Matrix();
matrix.preRotate(rotation);
matrix.mapPoints(keyPoints);
float maxX, maxY;
maxX = maxY = Float.MIN_VALUE;
float minX, minY;
minX = minY = Float.MAX_VALUE;
for (int i = 0; i < keyPoints.length; i++) {
if (i % 2 == 0) {
if (maxX < keyPoints[i]) maxX = keyPoints[i];
if (minX > keyPoints[i]) minX = keyPoints[i];
} else {
if (maxY < keyPoints[i]) maxY = keyPoints[i];
if (minY > keyPoints[i]) minY = keyPoints[i];
}
}
canvas.save();
canvas.translate((maxX + minX) / -2f, (maxY + minY) / -2f);
canvas.rotate(rotation, 10, 10);
d.setBounds(0, 0, 20, 20);
d.draw(canvas);
canvas.restore();
}
public void setBearing(float bearing) {
this.bearing = bearing;
}
public void setOrientation(float orientation) {
this.orientation = orientation;
postInvalidate();
}
}

@ -0,0 +1,101 @@
package org.r3pek.pharmacies.widgets;
import org.r3pek.pharmacies.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
public class Compass extends View implements ImageOrientationSensor {
/* Orientation
* 0 -> portrait
* 1 -> landscape
* 2 -> inverted portrait
* 3 -> inverted landscape
*/
private final int orientationCompensation[] = {0, 90, 180, 270};
private Context ctx;
private float bearing;
private float orientation;
private Drawable needleBackgound;
private Drawable needle;
public Compass(Context context) {
super(context);
ctx = context;
setDrawable();
}
public Compass(Context context, AttributeSet attrs) {
super(context, attrs);
ctx = context;
setDrawable();
}
public Compass(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ctx = context;
setDrawable();
}
private void setDrawable() {
needleBackgound = ctx.getResources().getDrawable(R.drawable.compass_background);
needle = ctx.getResources().getDrawable(R.drawable.compass_needle);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Display display = ((WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
float rotation = bearing - orientation - orientationCompensation[display.getOrientation()] - 45;
float keyPoints[] = {-4, 4, 4, -4};
Matrix matrix = new Matrix();
matrix.preRotate(rotation);
matrix.mapPoints(keyPoints);
float maxX, maxY;
maxX = maxY = Float.MIN_VALUE;
float minX, minY;
minX = minY = Float.MAX_VALUE;
for (int i = 0; i < keyPoints.length; i++) {
if (i % 2 == 0) {
if (maxX < keyPoints[i]) maxX = keyPoints[i];
if (minX > keyPoints[i]) minX = keyPoints[i];
} else {
if (maxY < keyPoints[i]) maxY = keyPoints[i];
if (minY > keyPoints[i]) minY = keyPoints[i];
}
}
canvas.save();
needleBackgound.setBounds(0, 0, 15, 15);
needleBackgound.draw(canvas);
canvas.translate((maxX + minX) / -2f, (maxY + minY) / -2f);
canvas.rotate(rotation, 8, 8);
needle.setBounds(0, 0, 15, 15);
needle.draw(canvas);
canvas.restore();
}
public void setBearing(float bearing) {
this.bearing = bearing;
}
public void setOrientation(float orientation) {
this.orientation = orientation;
postInvalidate();
}
}

@ -0,0 +1,5 @@
package org.r3pek.pharmacies.widgets;
public interface ImageOrientationSensor {
public void setOrientation(float orientation);
}

@ -0,0 +1,48 @@
package org.r3pek.pharmacies.widgets;
import java.util.LinkedList;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.view.View;
public class ImageRotater implements SensorEventListener {
private LinkedList<ImageOrientationSensor> images = new LinkedList<ImageOrientationSensor>();
private float lastOrientation = 0;
public void addImage(ImageOrientationSensor image) {
synchronized (images) {
if (images.contains(image)) return;
images.add(image);
}
}
public void delImage(ImageOrientationSensor image) {
synchronized (images) {
images.remove(image);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public float getLastOrientation() {
return lastOrientation;
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != Sensor.TYPE_ORIENTATION) return;
if (Math.abs(event.values[0] - lastOrientation) < 5) return;
lastOrientation = event.values[0];
synchronized (images) {
for (ImageOrientationSensor a : images) {
if (((View)a).isShown())
a.setOrientation(lastOrientation);
}
}
}
}

@ -0,0 +1,147 @@
package org.r3pek.pharmacies.widgets;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
import android.widget.TextView;
public class ScrollTextView extends TextView {
// scrolling feature
private Scroller mSlr;
// milliseconds for a round of scrolling
private int mRndDuration = 250;
// the X offset when paused
private int mXPaused = 0;
// whether it's being paused
private boolean mPaused = true;
/*
* constructor
*/
public ScrollTextView(Context context) {
this(context, null);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.textViewStyle);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// customize the TextView
setSingleLine();
setEllipsize(null);
}
/**
* begin to scroll the text from the original position
*/
public void startScroll() {
// begin from the very right side
mXPaused = -1 * getWidth();
// assume it's paused
mPaused = true;
resumeScroll();
}
/**
* resume the scroll from the pausing point
*/
public void resumeScroll() {
if (!mPaused)
return;
// Do not know why it would not scroll sometimes
// if setHorizontallyScrolling is called in constructor.
setHorizontallyScrolling(true);
// use LinearInterpolator for steady scrolling
mSlr = new Scroller(getContext(), new LinearInterpolator());
setScroller(mSlr);
int scrollingLen = calculateScrollingLen();
int distance = scrollingLen - (getWidth() + mXPaused);
int duration = (new Double(mRndDuration * distance * 1.00000
/ scrollingLen)).intValue();
setVisibility(VISIBLE);
mSlr.startScroll(mXPaused, 0, distance, 0, duration);
mPaused = false;
}
/**
* calculate the scrolling length of the text in pixel
*
* @return the scrolling length in pixels
*/
private int calculateScrollingLen() {
TextPaint tp = getPaint();
Rect rect = new Rect();
String strTxt = getText().toString();
tp.getTextBounds(strTxt, 0, strTxt.length(), rect);
int scrollingLen = rect.width() + getWidth();
rect = null;
return scrollingLen;
}
/**
* pause scrolling the text
*/
public void pauseScroll() {
if (null == mSlr)
return;
if (mPaused)
return;
mPaused = true;
// abortAnimation sets the current X to be the final X,
// and sets isFinished to be true
// so current position shall be saved
mXPaused = mSlr.getCurrX();
mSlr.abortAnimation();
}
@Override
/*
* override the computeScroll to restart scrolling when finished so as that
* the text is scrolled forever
*/
public void computeScroll() {
super.computeScroll();
if (null == mSlr) return;
if (mSlr.isFinished() && (!mPaused)) {
this.startScroll();
}
}
public int getRndDuration() {
return mRndDuration;
}
public void setRndDuration(int duration) {
this.mRndDuration = duration;
}
public boolean isPaused() {
return mPaused;
}
}

@ -0,0 +1,103 @@
package org.r3pek.pharmacies.widgets;
/* The following code was written by Matthew Wiggins
* and is released under the APACHE 2.0 license
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
private static final String androidns="http://schemas.android.com/apk/res/android";
private SeekBar mSeekBar;
private TextView mSplashText,mValueText;
private Context mContext;
private String mDialogMessage, mSuffix;
private int mDefault, mMax, mValue, mMin = 0;
public SeekBarPreference(Context context, AttributeSet attrs) {
super(context,attrs);
mContext = context;
mDialogMessage = attrs.getAttributeValue(androidns,"dialogMessage");
mSuffix = attrs.getAttributeValue(androidns,"text");
mDefault = attrs.getAttributeIntValue(androidns,"defaultValue", 0);
mMax = attrs.getAttributeIntValue(androidns,"max", 100);
mMin = attrs.getAttributeIntValue(androidns,"min", 0);
}
@Override
protected View onCreateDialogView() {
LinearLayout.LayoutParams params;
LinearLayout layout = new LinearLayout(mContext);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(6,6,6,6);
mSplashText = new TextView(mContext);
if (mDialogMessage != null)
mSplashText.setText(mDialogMessage);
layout.addView(mSplashText);
mValueText = new TextView(mContext);
mValueText.setGravity(Gravity.CENTER_HORIZONTAL);
mValueText.setTextSize(32);
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mValueText, params);
mSeekBar = new SeekBar(mContext);
mSeekBar.setOnSeekBarChangeListener(this);
layout.addView(mSeekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
if (shouldPersist())
mValue = getPersistedInt(mDefault);
mSeekBar.setMax(mMax - mMin);
mSeekBar.setProgress(mValue - mMin);
return layout;
}
@Override
protected void onBindDialogView(View v) {
super.onBindDialogView(v);
mSeekBar.setMax(mMax - mMin);
mSeekBar.setProgress(mValue - mMin);
String t = String.valueOf(mValue);
mValueText.setText(mSuffix == null ? t : t.concat(mSuffix));
}
@Override
protected void onSetInitialValue(boolean restore, Object defaultValue) {
super.onSetInitialValue(restore, defaultValue);
if (restore)
mValue = shouldPersist() ? getPersistedInt(mDefault) : 0;
else
mValue = (Integer)defaultValue;
}
public void onProgressChanged(SeekBar seek, int value, boolean fromTouch) {
String t = String.valueOf(value + mMin);
mValueText.setText(mSuffix == null ? t : t.concat(mSuffix));
if (shouldPersist())
persistInt(value + mMin);
callChangeListener(new Integer(value));
}
public void onStartTrackingTouch(SeekBar seek) {}
public void onStopTrackingTouch(SeekBar seek) {}
public void setMin(int min) {
mMin = min;
}
}
Loading…
Cancel
Save