Repository: lemberg/mappwidget
Branch: master
Commit: a5e233469da9
Files: 139
Total size: 453.0 KB
Directory structure:
gitextract_albf_jio/
├── .gitignore
├── LICENSE
├── README.md
├── bin/
│ ├── mAppWidget-1.4.2-javadoc.jar
│ └── mAppWidget-1.4.2.jar
├── mAppWidget/
│ ├── build.gradle
│ ├── demo1app/
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src/
│ │ └── main/
│ │ ├── AndroidManifest.xml
│ │ ├── assets/
│ │ │ ├── grid/
│ │ │ │ └── grid.xml
│ │ │ ├── grid2/
│ │ │ │ └── grid.xml
│ │ │ └── map/
│ │ │ └── map.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── ls/
│ │ │ └── demo/
│ │ │ └── demo1/
│ │ │ ├── BrowseMapActivity.java
│ │ │ ├── CaptionMapObject.java
│ │ │ ├── Category.java
│ │ │ ├── ExBrowseMapActivity.java
│ │ │ ├── HomeActivity.java
│ │ │ ├── Location.java
│ │ │ ├── Model.java
│ │ │ ├── Sample1Activity.java
│ │ │ ├── Sample2Activity.java
│ │ │ ├── model/
│ │ │ │ ├── MapObjectContainer.java
│ │ │ │ └── MapObjectModel.java
│ │ │ └── popup/
│ │ │ ├── MapPopupBase.java
│ │ │ └── TextPopup.java
│ │ └── res/
│ │ ├── layout/
│ │ │ ├── home.xml
│ │ │ └── main.xml
│ │ ├── menu/
│ │ │ ├── a1menu.xml
│ │ │ ├── map_menu.xml
│ │ │ └── menu.xml
│ │ └── values/
│ │ ├── strings.xml
│ │ ├── styles.xml
│ │ └── theme.xml
│ ├── demo2app/
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src/
│ │ ├── androidTest/
│ │ │ └── java/
│ │ │ └── com/
│ │ │ └── ls/
│ │ │ └── demo/
│ │ │ └── demo2/
│ │ │ └── ApplicationTest.java
│ │ └── main/
│ │ ├── AndroidManifest.xml
│ │ ├── assets/
│ │ │ └── map/
│ │ │ └── map.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── ls/
│ │ │ └── demo/
│ │ │ └── demo2/
│ │ │ ├── BrowseMapActivity.java
│ │ │ ├── model/
│ │ │ │ ├── MapObjectContainer.java
│ │ │ │ └── MapObjectModel.java
│ │ │ └── popup/
│ │ │ ├── MapPopupBase.java
│ │ │ └── TextPopup.java
│ │ └── res/
│ │ ├── layout/
│ │ │ ├── activity_main.xml
│ │ │ └── main.xml
│ │ ├── menu/
│ │ │ ├── menu.xml
│ │ │ └── menu_main.xml
│ │ ├── values/
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── theme.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ ├── gradle/
│ │ └── wrapper/
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── mappwidgetlib/
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src/
│ │ ├── androidTest/
│ │ │ ├── assets/
│ │ │ │ └── map/
│ │ │ │ └── map.xml
│ │ │ └── java/
│ │ │ └── com/
│ │ │ └── ls/
│ │ │ └── widgets/
│ │ │ └── map/
│ │ │ ├── AllTests.java
│ │ │ ├── CellTest.java
│ │ │ ├── GridTest.java
│ │ │ ├── MapLayerTest.java
│ │ │ ├── MapObjectTest.java
│ │ │ ├── MapWidgetTest.java
│ │ │ ├── OfflineMapConfigTest.java
│ │ │ └── OfflineMapUtilTest.java
│ │ └── main/
│ │ ├── AndroidManifest.xml
│ │ └── java/
│ │ └── com/
│ │ └── ls/
│ │ └── widgets/
│ │ └── map/
│ │ ├── MapWidget.java
│ │ ├── commands/
│ │ │ ├── GetTileTask.java
│ │ │ ├── MapCommand.java
│ │ │ └── MapCommandDelegate.java
│ │ ├── config/
│ │ │ ├── GPSConfig.java
│ │ │ ├── MapConfigParser.java
│ │ │ ├── MapGraphicsConfig.java
│ │ │ ├── OfflineMap.java
│ │ │ └── OfflineMapConfig.java
│ │ ├── events/
│ │ │ ├── MapScrolledEvent.java
│ │ │ ├── MapTouchedEvent.java
│ │ │ └── ObjectTouchEvent.java
│ │ ├── interfaces/
│ │ │ ├── Layer.java
│ │ │ ├── MapEventsListener.java
│ │ │ ├── MapLocationListener.java
│ │ │ ├── OnGridReadyListener.java
│ │ │ ├── OnLocationChangedListener.java
│ │ │ ├── OnMapDoubleTapListener.java
│ │ │ ├── OnMapLongClickListener.java
│ │ │ ├── OnMapScrollListener.java
│ │ │ ├── OnMapTilesFinishedLoadingListener.java
│ │ │ ├── OnMapTouchListener.java
│ │ │ └── TileManagerDelegate.java
│ │ ├── location/
│ │ │ └── PositionMarker.java
│ │ ├── model/
│ │ │ ├── Cell.java
│ │ │ ├── Grid.java
│ │ │ ├── MapLayer.java
│ │ │ ├── MapObject.java
│ │ │ └── MapTouchable.java
│ │ ├── providers/
│ │ │ ├── AssetTileProvider.java
│ │ │ ├── ExternalStorageTileProvider.java
│ │ │ ├── GPSLocationProvider.java
│ │ │ └── TileProvider.java
│ │ └── utils/
│ │ ├── GeoUtils.java
│ │ ├── Graphics.java
│ │ ├── LogUtils.java
│ │ ├── MapCalibrationData.java
│ │ ├── MathUtils.java
│ │ ├── OfflineMapUtil.java
│ │ ├── PivotFactory.java
│ │ ├── Resources.java
│ │ ├── Size.java
│ │ └── TransformUtils.java
│ └── settings.gradle
└── slicingtool/
├── .classpath
├── .project
├── .settings/
│ └── org.eclipse.jdt.core.prefs
├── META-INF/
│ └── MANIFEST.MF
├── build.properties
├── contexts.xml
├── libs/
│ └── org.eclipse.core.resources.jar
├── plugin.xml
└── src/
└── com/
└── ls/
└── mappwidget/
└── slicingtool/
├── Activator.java
├── cutter/
│ ├── Constants.java
│ ├── Cutter.java
│ ├── ImageXML.java
│ ├── OnCompliteListener.java
│ └── OnProgressUpdateListener.java
├── utils/
│ ├── EclipseUtils.java
│ ├── FileUtils.java
│ └── XMLUtils.java
├── views/
│ ├── DirectoryChooser.java
│ ├── FileChooser.java
│ ├── GPSChooser.java
│ ├── MainView.java
│ └── RadioGroup.java
└── vo/
└── PointVO.java
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.gradle
.idea
local.properties
*.iml
.DS_Store
build
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
================================================
FILE: README.md
================================================

Map services are a major growth area for mobile applications. Services like Google maps have brought map technology to the masses in recent years, but it has been hard to integrate them into applications as Google maps and others require a constant Internet connection and use proprietary resources. This means that if the app has to work offline, use original graphics or other features, a custom map has to be built.
At Lemberg we’ve developed many Android apps with custom maps, and to streamline this process we came up with the mAppWidget code library.

Designed to simplify custom map building, mAppWidget is a powerful tool that significantly cuts time and reduces the cost of the developing offline maps. Now any Android developer can benefit from our experience.
Using apps developed with mAppWidget is possible without data connection, unlike most of the other solutions. mAppWidget also uses a tiling technique for graphics that generates a larger map byre-using smaller images (tiles). This approach saves RAM and increases real-time performance, which is especially important on mobile devices. Zooming into images is not limited by the resolution of the input map image, as beyond the maximum zoom level of the image, the library uses digital zoom.
## Features
* Create map from any image
* Tile engine rendering
* GPS support
* Zoom in/out
* Pinch to zoom gesture
* Zoom on double tap
* Digital zoom
* Pan
* Inertial scroll
* Smooth tiles appearing
* Support of more than one map per application
* Ability to move the map object after it was added to the map
* Add/remove layers
* Add/remove objects
* Click handlers/info bubbles
* Works offline
* External storage support
## Requirements
* Android API 7 or higher
* Android OS 2.1 or higher
* Latest JDK, Android Studio 1.1 is recommended
## Demo app
mAppWidget demo is available for download on Google Play -
[https://play.google.com/store/apps/details?id=com.ls.mappwidgetdemo](https://play.google.com/store/apps/details?id=com.ls.mappwidgetdemo)
## How to use
Here you can find information on how to use mAppWidget library and FAQ's -
[http://lemberg.github.io/mappwidget/user_guide.html](http://lemberg.github.io/mappwidget/user_guide.html)
## Proudly brought to you
mAppWidget code library has been developed and open sourced by Lemberg Solutions Android development team. If you are interested in integration or customization of the mAppWidget or looking for any other mobile app development solution please feel free to reach us - [http://lemberg.co.uk](http://lemberg.co.uk).
================================================
FILE: mAppWidget/build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
================================================
FILE: mAppWidget/demo1app/.gitignore
================================================
/build
================================================
FILE: mAppWidget/demo1app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.ls.demo.demo1"
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':mappwidgetlib')
}
================================================
FILE: mAppWidget/demo1app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/dmytrobaryskyy/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: mAppWidget/demo1app/src/main/AndroidManifest.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/assets/grid/grid.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/assets/grid2/grid.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/assets/map/map.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/BrowseMapActivity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import com.ls.widgets.map.MapWidget;
import com.ls.widgets.map.config.OfflineMap;
import com.ls.widgets.map.events.MapTouchedEvent;
import com.ls.widgets.map.interfaces.Layer;
import com.ls.widgets.map.interfaces.MapEventsListener;
import com.ls.widgets.map.interfaces.OnLocationChangedListener;
import com.ls.widgets.map.interfaces.OnMapTouchListener;
import com.ls.widgets.map.model.MapLayer;
import java.io.IOException;
import java.io.InputStream;
public class BrowseMapActivity
extends Activity
{
/** Called when the activity is first created. */
private MapWidget mapWidget;
// private static long PIN_ID = 0xdb70bca16186d187L;
public static final long LAYER_ATTRACTIONS = 1000;
public static final long LAYER_KIDS = 2000;
public static final long LAYER_SPORT_AND_LEASURE = 3000;
public static final long PIN_LAYER = 4000;
private Model model;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.model = new Model();
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
mapWidget = new MapWidget(this, OfflineMap.MAP_ROOT);
// mapWidget.setMemoryEconomyMode(true);
mapWidget.setBackgroundColor(Color.GREEN);
MapLayer layer = mapWidget.createLayer(LAYER_ATTRACTIONS);
initLayer(layer, Model.CAT_MAIN_ATTRACTIONS);
layer = mapWidget.createLayer(LAYER_KIDS);
initLayer(layer, Model.CAT_KIDS);
layer = mapWidget.createLayer(LAYER_SPORT_AND_LEASURE);
initLayer(layer, Model.CAT_SPORT_AND_LEISURE);
mapWidget.getConfig().setMapCenteringEnabled(false);
mapWidget.createLayer(PIN_LAYER);
// layer.addTouchable(id, drawable, offsetX, offsetY)
// mapWidget.addLayer(2);
mapWidget.setAnimationEnabled(true);
mapWidget.setOnMapTouchListener(new OnMapTouchListener() {
@Override
public void onTouch(MapWidget v, MapTouchedEvent event){
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setMessage("OnTouch, X: " + event.getScreenX() + " Y: " + event.getScreenY()
+ " MAPX: " + event.getMapX() + " MAPY: " + event.getMapY() +
" Touched Count: " + event.getTouchedObjectIds().size());
builder.create().show();
}
});
mapWidget.addMapEventsListener(new MapEventsListener() {
public void onPreZoomOut()
{
Log.i("BrowseMapActivity", "On Map will zoom out");
}
public void onPreZoomIn()
{
Log.i("BrowseMapActivity", "On Map will zoom in");
}
public void onPostZoomOut()
{
Log.i("BrowseMapActivity", "On Map did zoom out");
}
public void onPostZoomIn()
{
Log.i("BrowseMapActivity", "On Map did zoom in");
}
});
mapWidget.setOnLocationChangedListener(new OnLocationChangedListener()
{
@Override
public void onLocationChanged(MapWidget v, Location location)
{
v.scrollMapTo(location);
}
});
mapWidget.setMinZoomLevel(1);
// mapWidget.setScale(2.0f);
layout.addView(mapWidget);
// Runnable runnable = new Runnable() {
// @Override
// public void run() {
// generateRandomMarkers();
// BitmapDrawable image = (BitmapDrawable) getResources().getDrawable(R.drawable.maps_blue_dot);
// if (image != null) {
// Layer layer = mapWidget.getLayerById(PIN_LAYER);
// MapObject object = new MapObject(PIN_ID, image, new Point(500, 250), PivotFactory.createPivotPoint(image, PivotPosition.PIVOT_CENTER), true);
// layer.addMapObject(object);
// // Pin pin = new Pin(PIN_ID, image, new android.graphics.Point(image.getBitmap().getWidth()/2, image.getBitmap().getHeight()/2));
// // pin.moveTo(500, 250);
// // mapWidget.getPinLayer().addPin(pin);
// // mapWidget.setPinLayerVisible(true);
// }
// }
// };
//
// Thread thread = new Thread(runnable);
// thread.setPriority(Thread.MIN_PRIORITY);
// thread.start();
}
// private void generateRandomMarkers() {
// try {
// final int GREEN_POINT_COUNT = 100;
// final int BLUE_POINT_COUNT = GREEN_POINT_COUNT;
// final int MAP_WIDTH = 1500;
// final int MAP_HEIGHT = 900;
//
// InputStream is = getAssets().open("other/trail_difficulty_green_circle.png");
// BitmapDrawable drawable = new BitmapDrawable(is);
// is.close();
// Random random = new Random(System.currentTimeMillis());
//
// for (int i = 0; i < GREEN_POINT_COUNT; ++i) {
// int randW = random.nextInt(MAP_WIDTH);
// int randH = random.nextInt(MAP_HEIGHT);
// BitmapDrawable dr = new BitmapDrawable(drawable.getBitmap());
//
// Layer layer = mapWidget.getLayer(0);
// layer.addMapObject(new MapObject(new Integer(random.nextInt(1000)), dr, randW, randH));
// }
//
//
// is = getAssets().open("other/trail_difficulty_blue_rect.png");
// drawable = new BitmapDrawable(is);
// is.close();
// for (int i = 0; i < BLUE_POINT_COUNT; ++i) {
// int randW = random.nextInt(MAP_WIDTH);
// int randH = random.nextInt(MAP_HEIGHT);
//
// BitmapDrawable dr = new BitmapDrawable(drawable.getBitmap());
//
// Layer layer = mapWidget.getLayer(1);
// layer.addMapObject(new MapObject(new Integer(random.nextInt(1000)), dr, randW, randH, true, false));
// }
//
// } catch (IOException e) {
// Log.e("TileManagerWorkerThread", "Exception: " + e);
// e.printStackTrace();
// }
// }
private void initLayer(Layer theLayer, String theCategoryId)
{
// List listLocations = this.model.getLocations();
//
// for (Location location : listLocations)
// {
// try
// {
// String categoryId = location.getCategoryId();
//
// if (categoryId.equals(theCategoryId))
// {
// Point point = location.getPoint();
// MapObject object = new MapObject(location.getId(),
// getIcon(categoryId),
// point,
// true, // Touchable
// false); // scalable
//
// theLayer.addMapObject(object);
// }
//
// } catch (IOException e)
// {
// e.printStackTrace();
// }
// }
theLayer.setVisible(true);
// if (settings.isCategorySelected(CategoryIds.LEISURE))
// {
// layerLeisure.enable();
// }
}
public Drawable getIcon(String theCatId) throws IOException
{
String path = "media/icons/";
if (Model.CAT_MAIN_ATTRACTIONS.equalsIgnoreCase(theCatId))
{
path += "map_icon_leisure.png";
} else if (Model.CAT_KIDS.equalsIgnoreCase(theCatId))
{
path += "map_icon_meals.png";
} else if (Model.CAT_SPORT_AND_LEISURE.equalsIgnoreCase(theCatId))
{
path += "map_icon_others_3.png";
}
AssetManager manager = getAssets();
InputStream input = manager.open(path);
return Drawable.createFromStream(input, null);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.map_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
int i = item.getItemId();
if (i == R.id.zoom_in) {
try {
mapWidget.zoomIn();
} catch (Exception e) {
Log.e("BrowseMapActivity", "Exception while zoom in. " + e);
}
return true;
}
else if (i == R.id.zoom_out) {
try {
mapWidget.zoomOut();
} catch (Exception e) {
Log.e("BrowseMapActivity", "Exception while zoom out. " + e);
}
return true;
}
else if (i == R.id.double_size) {
mapWidget.setScale(2.0f);
return true;
}
else if (i == R.id.original_size) {
mapWidget.setScale(1.0f);
return true;
}
else if (i == R.id.half_size) {
mapWidget.setScale(0.5f);
return true;
}
else if (i == R.id.open_map) {
Intent intent = new Intent(this, BrowseMapActivity.class);
startActivity(intent);
return true;
}
else {
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Layer layer = null;
switch (keyCode) {
case KeyEvent.KEYCODE_1:
layer = mapWidget.getLayer(0);
break;
case KeyEvent.KEYCODE_2:
layer = mapWidget.getLayer(1);
break;
}
if (layer != null) {
layer.setVisible(!layer.isVisible());
return true;
} else
return super.onKeyDown(keyCode, event);
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onDestroy()
{
// mapWidget.destroy();
super.onDestroy();
}
};
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/CaptionMapObject.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Point;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import com.ls.widgets.map.model.MapObject;
public class CaptionMapObject extends MapObject
{
private String caption;
private Paint paint;
public CaptionMapObject(Object id, Drawable drawable, Point position,
Point pivotPoint, boolean isTouchable, boolean isScalable) {
super(id, drawable, position, pivotPoint, isTouchable, isScalable);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(14);
paint.setTypeface(Typeface.SANS_SERIF);
paint.setFakeBoldText(true);
paint.setShadowLayer(1, 0, 0, Color.BLACK);
}
public void setCaption(String caption)
{
this.caption = caption;
}
@Override
public void draw(Canvas canvas)
{
super.draw(canvas);
if (caption != null) {
canvas.drawText(caption, posScaled.x, posScaled.y - 10, paint);
}
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/Category.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
public class Category
{
private String id;
private String name;
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/ExBrowseMapActivity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import com.ls.widgets.map.MapWidget;
import com.ls.widgets.map.config.MapGraphicsConfig;
import com.ls.widgets.map.config.OfflineMapConfig;
import com.ls.widgets.map.events.MapScrolledEvent;
import com.ls.widgets.map.events.MapTouchedEvent;
import com.ls.widgets.map.interfaces.Layer;
import com.ls.widgets.map.interfaces.MapEventsListener;
import com.ls.widgets.map.interfaces.OnLocationChangedListener;
import com.ls.widgets.map.interfaces.OnMapScrollListener;
import com.ls.widgets.map.interfaces.OnMapTouchListener;
import com.ls.widgets.map.model.MapObject;
import com.ls.widgets.map.utils.PivotFactory;
import com.ls.widgets.map.utils.PivotFactory.PivotPosition;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
public class ExBrowseMapActivity
extends Activity
{
/** Called when the activity is first created. */
private MapWidget mapWidget;
private Thread animationThread;
private boolean stopThreads;
public static final long LAYER_A = 1000;
public static final long LAYER_B = 2000;
public static final long LAYER_C = 3000;
public static final long PIN_LAYER = 4000;
private int amplitude = 400;
private float currX = 0;
private float currY = 0;
private boolean followPointer;
public static final long[] LAYERS = new long[]{};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
stopThreads = false;
followPointer = true;
File dir = Environment.getExternalStorageDirectory();
Log.d("ExBrowseActivity", "External Storage Directory: " + Environment.getDataDirectory().getAbsolutePath() + "/maps/grid2");
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Log.d("ExBrowseActivity", "Window format is: " + getWindow().getAttributes().format);
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
layout.setBackgroundColor(0xFFFFFFFF);
mapWidget = new MapWidget(savedInstanceState, this, new File("/sdcard/maps/grid2"),12);
mapWidget.createLayer(0);
mapWidget.createLayer(1);
mapWidget.setAnimationEnabled(true);
mapWidget.setZoomButtonsVisible(true);
MapGraphicsConfig gconfig = mapWidget.getMapGraphicsConfig();
if (gconfig != null) {
gconfig.setAccuracyAreaBorderColor(Color.RED);
gconfig.setAccuracyAreaColor(0x4400FF00);
}
mapWidget.setOnMapTouchListener(new OnMapTouchListener() {
@Override
public void onTouch(MapWidget v, MapTouchedEvent event) {
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setMessage("OnTouch, X: " + event.getScreenX() + " Y: " + event.getScreenY()
+ " MAPX: " + event.getMapX() + " MAPY: " + event.getMapY() +
" Touched Count: " + event.getTouchedObjectIds().size());
builder.create().show();
}
});
mapWidget.setOnMapScrolledListener(new OnMapScrollListener()
{
@Override
public void onScrolledEvent(MapWidget v, MapScrolledEvent event)
{
if (event.isByUser()) {
followPointer = false;
}
}
});
mapWidget.setMinZoomLevel(1);
mapWidget.setMaxZoomLevel(12);
// mapWidget.setZoomButtonsVisible(true);
// mapWidget.setScale(2.0f);
layout.addView(mapWidget);
mapWidget.addMapEventsListener(new MapEventsListener() {
public void onPreZoomOut()
{
Log.i("BrowseMapActivity", "On Map will zoom out");
}
public void onPreZoomIn()
{
Log.i("BrowseMapActivity", "On Map will zoom in");
}
public void onPostZoomOut()
{
Log.i("BrowseMapActivity", "On Map did zoom out");
}
public void onPostZoomIn()
{
Log.i("BrowseMapActivity", "On Map did zoom in");
}
});
mapWidget.setOnLocationChangedListener(new OnLocationChangedListener()
{
@Override
public void onLocationChanged(MapWidget v, Location location)
{
if (followPointer) {
v.scrollMapTo(location);
}
}
});
Runnable runnable = new Runnable() {
@Override
public void run() {
generateRandomMarkers();
// BitmapDrawable image = (BitmapDrawable) getResources().getDrawable(R.drawable.maps_blue_dot);
// if (image != null) {
// Layer layer = mapWidget.getLayerById(PIN_LAYER);
// MapObject object = new MapObject(PIN_ID, image, new Point(500, 250), PivotFactory.createPivotPoint(image, PivotPosition.PIVOT_CENTER), false, true);
// layer.addMapObject(object);
// layer.setVisible(true);
// }
}
};
Thread thread = new Thread(runnable);
thread.setPriority(Thread.MIN_PRIORITY);
thread.run();
OfflineMapConfig config = mapWidget.getConfig();
if (config != null) {
config.setFlingEnabled(true);
config.setMapCenteringEnabled(false);
}
//layout.removeView(mapWidget);
//mapWidget.setShowMyPosition(true);
mapWidget.centerMap();
}
private void generateRandomMarkers() {
try {
final int GREEN_POINT_COUNT = 100;
final int BLUE_POINT_COUNT = GREEN_POINT_COUNT;
final int MAP_WIDTH = 1500;
final int MAP_HEIGHT = 900;
InputStream is = getAssets().open("other/trail_difficulty_green_circle.png");
BitmapDrawable drawable = new BitmapDrawable(is);
is.close();
Random random = new Random(System.currentTimeMillis());
Layer layer = mapWidget.getLayer(0);
for (int i = 0; i < GREEN_POINT_COUNT; ++i) {
int randW = random.nextInt(MAP_WIDTH);
int randH = random.nextInt(MAP_HEIGHT);
BitmapDrawable dr = new BitmapDrawable(drawable.getBitmap());
MapObject object = new MapObject(Integer.valueOf(random.nextInt(1000)), dr, randW, randH, false);
layer.addMapObject(object);
//layer.addTouchable(new Integer(random.nextInt(1000)), dr, randW, randH);
}
is = getAssets().open("other/trail_difficulty_blue_rect.png");
drawable = new BitmapDrawable(is);
is.close();
layer = mapWidget.getLayer(1);
for (int i = 0; i < BLUE_POINT_COUNT; ++i) {
int randW = random.nextInt(MAP_WIDTH);
int randH = random.nextInt(MAP_HEIGHT);
BitmapDrawable dr = new BitmapDrawable(drawable.getBitmap());
MapObject object = new MapObject(Integer.valueOf((random.nextInt(1000))), dr, new Point(randW, randH), PivotFactory.createPivotPoint(dr, PivotPosition.PIVOT_CENTER), true, false);
layer.addMapObject(object);
// layer.addTouchable(new Integer(random.nextInt(1000)), dr, new Point(randW, randH), PivotFactory.createPivotPoint(dr, PivotPosition.PIVOT_CENTER), false);
// mapWidget.addDrawable(dr, randW, randH);
}
} catch (IOException e) {
Log.e("TileManagerWorkerThread", "Exception: " + e);
e.printStackTrace();
}
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.map_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
int i = item.getItemId();
if (i == R.id.zoom_in) {
try {
mapWidget.zoomIn();
mapWidget.scrollMapTo(1500, 700);
} catch (Exception e) {
Log.e("BrowseMapActivity", "Exception while zoom in. " + e);
}
return true;
}
else if (i == R.id.zoom_out) {
try {
mapWidget.zoomOut();
} catch (Exception e) {
Log.e("BrowseMapActivity", "Exception while zoom out. " + e);
}
return true;
}
else if (i == R.id.double_size) {
mapWidget.setScale(2.0f);
return true;
}
else if (i == R.id.original_size) {
mapWidget.setScale(1.0f);
return true;
}
else if (i == R.id.half_size) {
mapWidget.setScale(0.5f);
return true;
}
else if (i == R.id.open_map) {
Intent intent = new Intent(this, ExBrowseMapActivity.class);
startActivity(intent);
return true;
}
else if (i == R.id.my_location) {
//mapWidget.scrollToCurrentLocation();
//followPointer = true;
mapWidget.centerMap();
return true;
}
else {
return super.onOptionsItemSelected(item);
}
}
private void animatePin() {
// if (animationThread == null || (animationThread != null && !animationThread.isAlive())) {
// animationThread = new Thread(new Runnable() {
// @Override
// public void run() {
// // MapObject pin = mapWidget.getLayerById(PIN_LAYER).getMapObject(PIN_ID);
//
// if (pin == null) {
// Log.e("PIN", "Pin not foind");
// }
//
// while (!stopThreads) {
// currX += 0.01;
// currY += 0.01;
//
// if (pin != null) {
// pin.moveTo((int)(700 + Math.sin(currX) * amplitude), (int)(350 + Math.cos(currY)*250));
// }
//
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// return;
// }
// }
//
// }
// });
//
// animationThread.start();
// }
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Layer layer = null;
switch (keyCode) {
case KeyEvent.KEYCODE_1:
layer = mapWidget.getLayer(0);
break;
case KeyEvent.KEYCODE_2:
layer = mapWidget.getLayer(1);
break;
}
if (layer != null) {
layer.setVisible(!layer.isVisible());
return true;
} else
return super.onKeyDown(keyCode, event);
}
@Override
protected void onStop() {
stopThreads = true;
super.onStop();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onDestroy()
{
//mapWidget.destroy();
super.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
mapWidget.saveState(outState);
super.onSaveInstanceState(outState);
}
};
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/HomeActivity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HomeActivity
extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
initWidgets();
}
private void initWidgets()
{
Button button1 = (Button) findViewById(R.id.button_sample_1);
button1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
doOpenSample1();
}
});
Button button2 = (Button) findViewById(R.id.button_sample_2);
button2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
doOpenSample2();
}
});
Button button3 = (Button) findViewById(R.id.button_sample_3);
button3.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
doOpenExBrowseActivity();
}
});
}
private void doOpenExBrowseActivity()
{
Intent intent = new Intent(this, ExBrowseMapActivity.class);
startActivity(intent);
}
private void doOpenSample1()
{
Intent intent = new Intent(this,Sample1Activity.class);
startActivity(intent);
}
private void doOpenSample2()
{
Intent intent = new Intent(this,Sample2Activity.class);
startActivity(intent);
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/Location.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.graphics.Point;
public class Location
{
private String id;
private String title;
private String categoryId;
private Point point;
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getCategoryId()
{
return categoryId;
}
public void setCategoryId(String categoryId)
{
this.categoryId = categoryId;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public Point getPoint()
{
return point;
}
public void setPoint(Point point)
{
this.point = point;
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/Model.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Point;
public class Model
{
public static final String CAT_MAIN_ATTRACTIONS = "category.main.attractions";
public static final String CAT_KIDS = "category.kids";
public static final String CAT_SPORT_AND_LEISURE = "category.sport.and.leisure";
private List locations;
private List categories;
public Model()
{
createCategories();
createLocations();
}
public List getCategories()
{
return categories;
}
public List getLocations()
{
return locations;
}
private void createCategories()
{
this.categories = new ArrayList();
Category category = new Category();
category.setId(CAT_MAIN_ATTRACTIONS);
category.setName("Main Attractions");
this.categories.add(category);
category = new Category();
category.setId(CAT_KIDS);
category.setName("Kids In the Park");
this.categories.add(category);
category = new Category();
category.setId(CAT_SPORT_AND_LEISURE);
category.setName("Sport and Leisure");
this.categories.add(category);
}
private void createLocations()
{
this.locations = new ArrayList();
Point point = new Point(20, 100);
Location location = new Location();
location.setId("id.thehub");
location.setTitle("The Hub");
location.setCategoryId(CAT_MAIN_ATTRACTIONS);
location.setPoint(point);
this.locations.add(location);
point = new Point(20, 100);
location = new Location();
location.setId("id.queen.mary.garden");
location.setTitle("Queen Mary's Garden");
location.setCategoryId(CAT_MAIN_ATTRACTIONS);
location.setPoint(point);
this.locations.add(location);
point = new Point(20, 100);
location = new Location();
location.setId("id.wildlifegarden");
location.setTitle("Wildlife Garden");
location.setCategoryId(CAT_KIDS);
location.setPoint(point);
this.locations.add(location);
point = new Point(20, 100);
location = new Location();
location.setId("id.boatinglake");
location.setTitle("Boating Lake");
location.setCategoryId(CAT_KIDS);
location.setPoint(point);
this.locations.add(location);
point = new Point(20, 100);
location = new Location();
location.setId("id.openairtheatre");
location.setTitle("Open Air Theatre");
location.setCategoryId(CAT_SPORT_AND_LEISURE);
location.setPoint(point);
this.locations.add(location);
point = new Point(20, 100);
location = new Location();
location.setId("id.tenniscenter");
location.setTitle("Tennis Center");
location.setCategoryId(CAT_SPORT_AND_LEISURE);
location.setPoint(point);
this.locations.add(location);
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/Sample1Activity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.ls.widgets.map.MapWidget;
import com.ls.widgets.map.config.OfflineMap;
import com.ls.widgets.map.events.MapTouchedEvent;
import com.ls.widgets.map.interfaces.MapEventsListener;
import com.ls.widgets.map.interfaces.OnMapDoubleTapListener;
import com.ls.widgets.map.model.MapLayer;
import com.ls.widgets.map.model.MapObject;
import com.ls.widgets.map.utils.PivotFactory;
import com.ls.widgets.map.utils.PivotFactory.PivotPosition;
public class Sample1Activity
extends Activity
{
public static final int MAP_ID = 1;
private static final long LAYER_ID = 5;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final int initialZoomLevel = 10;
final MapWidget mapWidget = new MapWidget(savedInstanceState, this, OfflineMap.MAP_ROOT, initialZoomLevel);
mapWidget.setId(MAP_ID);
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
layout.addView(mapWidget);
mapWidget.getConfig().setFlingEnabled(true);
mapWidget.getConfig().setPinchZoomEnabled(true);
mapWidget.setMaxZoomLevel(13);
mapWidget.setUseSoftwareZoom(true);
mapWidget.setZoomButtonsVisible(true);
mapWidget.setBackgroundColor(Color.GREEN);
mapWidget.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(Sample1Activity.this, "Long press works!", Toast.LENGTH_SHORT).show();
return true;
}
});
mapWidget.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
return false;
}
});
mapWidget.setOnDoubleTapListener(new OnMapDoubleTapListener() {
@Override
public boolean onDoubleTap(MapWidget v, MapTouchedEvent event) {
Log.d("Sample1Activity", "On double tap");
Toast.makeText(Sample1Activity.this, "Double tap overridden", Toast.LENGTH_SHORT).show();
return true;
}
});
MapLayer layer = mapWidget.createLayer(LAYER_ID);
// getting icon from assets
Drawable icon = getResources().getDrawable(R.drawable.map_icon_attractions);
// define coordinates of icon on map
int x = 240;
int y = 362;
// set ID for the object
final long OBJ_ID = 25;
// adding object to layer
layer.addMapObject(new MapObject(OBJ_ID, icon, new Point(x, y), PivotFactory.createPivotPoint(icon, PivotPosition.PIVOT_CENTER), false, false));
mapWidget.addMapEventsListener(new MapEventsListener() {
@Override
public void onPreZoomOut() {
// TODO Auto-generated method stub
}
@Override
public void onPreZoomIn() {
// TODO Auto-generated method stub
}
@Override
public void onPostZoomOut() {
runOnUiThread(new Runnable() {
@Override
public void run() {
setTitle("Zoom level: " + mapWidget.getZoomLevel());
}
});
}
@Override
public void onPostZoomIn() {
runOnUiThread(new Runnable() {
@Override
public void run() {
setTitle("Zoom level: " + mapWidget.getZoomLevel());
}
});
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
MapWidget map = (MapWidget) findViewById(MAP_ID);
map.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.a1menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
MapWidget map = (MapWidget) findViewById(MAP_ID);
int i = item.getItemId();
if (i == R.id.scrollTo)
{
map.scrollMapTo(new Point(240, 320));
}
else if (i == R.id.jumpTo)
{
map.jumpTo(new Point(240, 320));
}
return super.onOptionsItemSelected(item);
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/Sample2Activity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1;
import android.app.Activity;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.ls.widgets.map.MapWidget;
import com.ls.widgets.map.events.MapTouchedEvent;
import com.ls.widgets.map.interfaces.Layer;
import com.ls.widgets.map.interfaces.MapEventsListener;
import com.ls.widgets.map.interfaces.OnLocationChangedListener;
import com.ls.widgets.map.interfaces.OnMapDoubleTapListener;
import com.ls.widgets.map.interfaces.OnMapLongClickListener;
import com.ls.widgets.map.interfaces.OnMapTilesFinishedLoadingListener;
import com.ls.widgets.map.model.MapLayer;
import com.ls.widgets.map.model.MapObject;
import com.ls.widgets.map.utils.GeoUtils;
import com.ls.widgets.map.utils.PivotFactory;
import com.ls.widgets.map.utils.PivotFactory.PivotPosition;
public class Sample2Activity
extends Activity
{
public static final int MAP_ID = 1;
private int currId = 35;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
final MapWidget mapWidget = new MapWidget(savedInstanceState, this, "map", 10);
mapWidget.setSaveEnabled(true);
mapWidget.getConfig().setMinZoomLevelLimit(10);
mapWidget.getConfig().setZoomBtnsVisible(false);
mapWidget.setId(MAP_ID);
// create map layer with specified ID
final long LAYER_ID = 5;
MapLayer layer = mapWidget.createLayer(LAYER_ID);
// getting icon from assets
Drawable icon = getResources().getDrawable(R.drawable.map_icon_attractions);
// define coordinates of icon on map
int x = 200;
int y = 300;
// set ID for the object
final long OBJ_ID = 25;
// adding object to layer
MapObject obj = new MapObject(OBJ_ID, icon, new Point(x, y), PivotFactory.createPivotPoint(icon, PivotPosition.PIVOT_CENTER), true, false);
// obj.setCaption("5434 KNNB");
//MapObject(OBJ_ID, icon, new Point(x, y), PivotFactory.createPivotPoint(icon, PivotPosition.PIVOT_CENTER), true, false)
layer.addMapObject(obj);
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
layout.setBackgroundColor(0xFFFFFFFF);
layout.addView(mapWidget);
mapWidget.getMapGraphicsConfig().setArrowPointerDrawableId(R.drawable.maps_blue_arrow);
mapWidget.getMapGraphicsConfig().setDotPointerDrawableId(R.drawable.maps_blue_dot);
mapWidget.setOnMapTilesFinishLoadingListener(new OnMapTilesFinishedLoadingListener() {
@Override
public void onMapTilesFinishedLoading() {
mapWidget.zoomIn();
mapWidget.scrollMapTo(1000, 800);
mapWidget.setOnMapTilesFinishLoadingListener(null);
}
});
// mapWidget.setShowMyPosition(true);
mapWidget.addMapEventsListener(new MapEventsListener()
{
@Override
public void onPreZoomOut()
{
// TODO Auto-generated method stub
}
@Override
public void onPreZoomIn()
{
// TODO Auto-generated method stub
}
@Override
public void onPostZoomOut()
{
// TODO Auto-generated method stub
}
@Override
public void onPostZoomIn()
{
// TODO Auto-generated method stub
}
});
mapWidget.setOnLocationChangedListener(new OnLocationChangedListener() {
@Override
public void onLocationChanged(MapWidget v, Location location)
{
v.scrollMapTo(location);
}
});
mapWidget.setOnDoubleTapListener(new OnMapDoubleTapListener() {
@Override
public boolean onDoubleTap(MapWidget v, MapTouchedEvent event) {
Log.d("Sample1Activity", "On double tap");
Location location = addObjetWhereTouched(mapWidget, event, R.drawable.map_icon_attractions);
Toast.makeText(Sample2Activity.this, "New object coords: Lat: " + location.getLatitude() + " Lon:" + location.getLongitude(), Toast.LENGTH_SHORT).show();
return true;
}
});
mapWidget.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
return false;
}
});
mapWidget.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public boolean onLongClick(MapWidget v, MapTouchedEvent e) {
if (e.getTouchedObjectIds().size() == 0) {
addObjetWhereTouched(v, e, R.drawable.map_icon_leasure);
} else {
Toast.makeText(Sample2Activity.this, "Layer Id: " + e.getTouchedObjectIds().get(0).getLayerId(), Toast.LENGTH_SHORT).show();
}
return false;
}
});
}
private Location addObjetWhereTouched(final MapWidget mapWidget, MapTouchedEvent event, int iconId) {
// getting icon from assets
Drawable icon = getResources().getDrawable(iconId);
MapObject obj = new MapObject(currId++, icon, new Point(0, 0),
PivotFactory.createPivotPoint(icon, PivotPosition.PIVOT_CENTER), true, false);
Layer layer = mapWidget.getLayerById(5);
layer.addMapObject(obj);
Location location = new Location("custom");
GeoUtils.translate(mapWidget, event.getMapX(), event.getMapY(), location);
obj.moveTo(location);
return location;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
MapWidget map = (MapWidget) findViewById(MAP_ID);
map.saveState(outState);
super.onSaveInstanceState(outState);
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/model/MapObjectContainer.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1.model;
import java.util.ArrayList;
public class MapObjectContainer
{
private ArrayList container;
public MapObjectContainer()
{
container = new ArrayList();
}
public void addObject(MapObjectModel object)
{
container.add(object);
}
public void removeObject(MapObjectModel object)
{
container.remove(object);
}
public MapObjectModel getObject(int index)
{
return container.get(index);
}
public MapObjectModel getObjectById(int id)
{
for (MapObjectModel model:container) {
if (model.getId() == id) {
return model;
}
}
return null;
}
public int size()
{
return container.size();
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/model/MapObjectModel.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1.model;
import android.location.Location;
public class MapObjectModel
{
private int x;
private int y;
private int id;
private String caption;
private Location location;
public MapObjectModel(int id, Location location, String caption)
{
this.location = location;
this.caption = caption;
this.id = id;
}
public MapObjectModel(int id, int x, int y, String caption)
{
this.id = id;
this.x = x;
this.y = y;
this.caption = caption;
}
public int getId()
{
return id;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Location getLocation()
{
return location;
}
public String getCaption()
{
return caption;
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/popup/MapPopupBase.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1.popup;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class MapPopupBase
{
protected ViewGroup parentView;
protected LinearLayout container;
protected float dipScaleFactor;
protected int lastX;
protected int lastY;
protected int screenHeight;
protected int screenWidth;
public MapPopupBase(Context context, ViewGroup parentView)
{
screenHeight = context.getResources().getDisplayMetrics().heightPixels;
screenWidth = context.getResources().getDisplayMetrics().widthPixels;
this.parentView = parentView;
dipScaleFactor = context.getResources().getDisplayMetrics().density;
container = new LinearLayout(context);
container.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
lastX = lastY = -1;
}
public void show(ViewGroup view, int theX, int theY)
{
hide();
container.measure(view.getWidth(), view.getHeight());
int x = theX - (getWidth() / 2);
int y = theY - getHeight();
container.setPadding(x, y, 0, 0);
lastX = x;
lastY = y;
parentView.addView(container);
container.setVisibility(View.VISIBLE);
}
public int getHeight()
{
return container.getMeasuredHeight();
}
public int getWidth()
{
return container.getMeasuredWidth();
}
public boolean isVisible()
{
return container.getVisibility() == View.VISIBLE;
}
public void hide()
{
container.setPadding(0, 0, 0, 0);
container.setVisibility(View.INVISIBLE);
parentView.removeView(container);
}
public void setOnClickListener(View.OnTouchListener listener)
{
if(container != null){
container.setOnTouchListener(listener);
}
}
}
================================================
FILE: mAppWidget/demo1app/src/main/java/com/ls/demo/demo1/popup/TextPopup.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo1.popup;
import com.ls.demo.demo1.R;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class TextPopup
extends MapPopupBase
{
public final static int ZERO = 0;
public final static int PADDING_BOTTOM = 11;
public final static int PADDING_TOP = 5;
public final static int PADDING_LEFT = 15;
public final static int PADDING_RIGHT = 10;
public final static float DEF_TEXT_SIZE = 16;
public final static int IMAGE_SIZE = 30;
public final static int MAX_EMS = 14;
private TextView text;
public TextPopup(Context context, ViewGroup parentView)
{
super(context, parentView);
text = new TextView(context);
text.setPadding((int)(PADDING_LEFT * dipScaleFactor),
(int)(PADDING_TOP * dipScaleFactor),
(int)(PADDING_RIGHT * dipScaleFactor),
(int)(PADDING_BOTTOM * dipScaleFactor));
text.setBackgroundResource(R.drawable.map_description_background);
text.setTextSize(DEF_TEXT_SIZE);
text.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
text.setMaxEms(MAX_EMS);
text.setTextColor(Color.WHITE);
container.addView(text);
text.setFocusable(true);
text.setClickable(true);
}
public void moveBy(int dx, int dy)
{
if (lastX != -1 && lastY != -1){
int paddingBottom = 0;
int paddingRight = 0;
if(container.getPaddingTop() > (screenHeight - (text.getHeight() + 3))){
paddingBottom = (container.getPaddingBottom() - dy);
}
if(container.getPaddingLeft() > (screenWidth - (text.getWidth() + 3))){
paddingRight = container.getPaddingRight() - dx;
}
container.setPadding(container.getPaddingLeft() + dx,
container.getPaddingTop() + dy,
paddingRight, paddingBottom);
}
}
public void setText(String theText)
{
text.setPadding((int)(PADDING_LEFT * dipScaleFactor),
(int)(PADDING_TOP * dipScaleFactor),
(int)(PADDING_RIGHT * dipScaleFactor),
(int)(PADDING_BOTTOM * dipScaleFactor));
text.setText(theText + " ");
}
public void setIcon(BitmapDrawable theDrawable)
{
if (theDrawable != null) {
theDrawable.setBounds(0,0, (int) (theDrawable.getBitmap().getWidth()),
(int)(theDrawable.getBitmap().getHeight()));
}
text.setCompoundDrawables(null, null, theDrawable, null);
}
public void removeIcon()
{
text.setCompoundDrawables(null, null, null, null);
}
public void setOnClickListener(View.OnTouchListener listener)
{
if(text != null){
text.setOnTouchListener(listener);
}
}
}
================================================
FILE: mAppWidget/demo1app/src/main/res/layout/home.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/layout/main.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/menu/a1menu.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/menu/map_menu.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/menu/menu.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/values/strings.xml
================================================
mAppWidget
================================================
FILE: mAppWidget/demo1app/src/main/res/values/styles.xml
================================================
================================================
FILE: mAppWidget/demo1app/src/main/res/values/theme.xml
================================================
================================================
FILE: mAppWidget/demo2app/.gitignore
================================================
/build
================================================
FILE: mAppWidget/demo2app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.ls.demo.demo2"
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':mappwidgetlib')
}
================================================
FILE: mAppWidget/demo2app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/dmytrobaryskyy/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: mAppWidget/demo2app/src/androidTest/java/com/ls/demo/demo2/ApplicationTest.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase {
public ApplicationTest() {
super(Application.class);
}
}
================================================
FILE: mAppWidget/demo2app/src/main/AndroidManifest.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/assets/map/map.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/java/com/ls/demo/demo2/BrowseMapActivity.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2;
import java.util.ArrayList;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;
import com.ls.demo.demo2.model.MapObjectContainer;
import com.ls.demo.demo2.model.MapObjectModel;
import com.ls.demo.demo2.popup.TextPopup;
import com.ls.widgets.map.MapWidget;
import com.ls.widgets.map.config.GPSConfig;
import com.ls.widgets.map.config.MapGraphicsConfig;
import com.ls.widgets.map.config.OfflineMapConfig;
import com.ls.widgets.map.events.MapScrolledEvent;
import com.ls.widgets.map.events.MapTouchedEvent;
import com.ls.widgets.map.events.ObjectTouchEvent;
import com.ls.widgets.map.interfaces.Layer;
import com.ls.widgets.map.interfaces.MapEventsListener;
import com.ls.widgets.map.interfaces.OnLocationChangedListener;
import com.ls.widgets.map.interfaces.OnMapScrollListener;
import com.ls.widgets.map.interfaces.OnMapTouchListener;
import com.ls.widgets.map.location.PositionMarker;
import com.ls.widgets.map.model.MapObject;
import com.ls.widgets.map.utils.PivotFactory;
import com.ls.widgets.map.utils.PivotFactory.PivotPosition;
public class BrowseMapActivity extends Activity
implements MapEventsListener,
OnMapTouchListener
{
private static final String TAG = "BrowseMapActivity";
private static final Integer LAYER1_ID = 0;
private static final Integer LAYER2_ID = 1;
private static final int MAP_ID = 23;
private int nextObjectId;
private int pinHeight;
private MapObjectContainer model;
private MapWidget map;
private TextPopup mapObjectInfoPopup;
private Location points[];
private int currentPoint;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nextObjectId = 0;
model = new MapObjectContainer();
initTestLocationPoints();
initMap(savedInstanceState);
initModel();
initMapObjects();
initMapListeners();
// Will show the position of the user on a map.
// Do not forget to enable ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permission int the manifest.
// Uncomment this if you are at Filitheyo island :)
// map.setShowMyPosition(true);
map.centerMap();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
map.saveState(outState);
}
private void initTestLocationPoints()
{
points = new Location[5];
for (int i=0; i touchedObjs = event.getTouchedObjectIds();
if (touchedObjs.size() > 0) {
int xInMapCoords = event.getMapX();
int yInMapCoords = event.getMapY();
int xInScreenCoords = event.getScreenX();
int yInScreenCoords = event.getScreenY();
ObjectTouchEvent objectTouchEvent = event.getTouchedObjectIds().get(0);
// Due to a bug this is not actually the layer id, but index of the layer in layers array.
// Will be fixed in the next release.
long layerId = objectTouchEvent.getLayerId();
Integer objectId = (Integer)objectTouchEvent.getObjectId();
// User has touched one or more map object
// We will take the first one to show in the toast message.
String message = "You touched the object with id: " + objectId + " on layer: " + layerId +
" mapX: " + xInMapCoords + " mapY: " + yInMapCoords + " screenX: " + xInScreenCoords + " screenY: " +
yInScreenCoords;
Log.d(TAG, message);
MapObjectModel objectModel = model.getObjectById(objectId.intValue());
if (objectModel != null) {
// This is a case when we want to show popup info exactly above the pin image
float density = getResources().getDisplayMetrics().density;
int imgHeight = (int) (pinHeight / density / 2);
// Calculating position of popup on the screen
int x = xToScreenCoords(objectModel.getX());
int y = yToScreenCoords(objectModel.getY()) - imgHeight;
// Show it
showLocationsPopup(x, y, objectModel.getCaption());
} else {
// This is a case when we want to show popup where the user has touched.
showLocationsPopup(xInScreenCoords, yInScreenCoords, "Shows where user touched");
}
// Hint: If user touched more than one object you can show the dialog in which ask
// the user to select concrete object
} else {
if (mapObjectInfoPopup != null) {
mapObjectInfoPopup.hide();
}
}
}
private void showLocationsPopup(int x, int y, String text)
{
RelativeLayout mapLayout = (RelativeLayout) findViewById(R.id.rootLayout);
if (mapObjectInfoPopup != null)
{
mapObjectInfoPopup.hide();
}
((TextPopup) mapObjectInfoPopup).setIcon((BitmapDrawable) getResources().getDrawable(R.drawable.map_popup_arrow));
((TextPopup) mapObjectInfoPopup).setText(text);
mapObjectInfoPopup.setOnClickListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_UP)
{
if (mapObjectInfoPopup != null)
{
mapObjectInfoPopup.hide();
}
}
return false;
}
});
((TextPopup) mapObjectInfoPopup).show(mapLayout, x, y);
}
/***
* Transforms coordinate in map coordinate system to screen coordinate system
* @param mapCoord - X in map coordinate in pixels.
* @return X coordinate in screen coordinates. You can use this value to display any object on the screen.
*/
private int xToScreenCoords(int mapCoord)
{
return (int)(mapCoord * map.getScale() - map.getScrollX());
}
private int yToScreenCoords(int mapCoord)
{
return (int)(mapCoord * map.getScale() - map.getScrollY());
}
}
================================================
FILE: mAppWidget/demo2app/src/main/java/com/ls/demo/demo2/model/MapObjectContainer.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2.model;
import java.util.ArrayList;
public class MapObjectContainer
{
private ArrayList container;
public MapObjectContainer()
{
container = new ArrayList();
}
public void addObject(MapObjectModel object)
{
container.add(object);
}
public void removeObject(MapObjectModel object)
{
container.remove(object);
}
public MapObjectModel getObject(int index)
{
return container.get(index);
}
public MapObjectModel getObjectById(int id)
{
for (MapObjectModel model:container) {
if (model.getId() == id) {
return model;
}
}
return null;
}
public int size()
{
return container.size();
}
}
================================================
FILE: mAppWidget/demo2app/src/main/java/com/ls/demo/demo2/model/MapObjectModel.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2.model;
import android.location.Location;
public class MapObjectModel
{
private int x;
private int y;
private int id;
private String caption;
private Location location;
public MapObjectModel(int id, Location location, String caption)
{
this.location = location;
this.caption = caption;
this.id = id;
}
public MapObjectModel(int id, int x, int y, String caption)
{
this.id = id;
this.x = x;
this.y = y;
this.caption = caption;
}
public int getId()
{
return id;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Location getLocation()
{
return location;
}
public String getCaption()
{
return caption;
}
}
================================================
FILE: mAppWidget/demo2app/src/main/java/com/ls/demo/demo2/popup/MapPopupBase.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2.popup;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class MapPopupBase
{
protected ViewGroup parentView;
protected LinearLayout container;
protected float dipScaleFactor;
protected int lastX;
protected int lastY;
protected int screenHeight;
protected int screenWidth;
public MapPopupBase(Context context, ViewGroup parentView)
{
screenHeight = context.getResources().getDisplayMetrics().heightPixels;
screenWidth = context.getResources().getDisplayMetrics().widthPixels;
this.parentView = parentView;
dipScaleFactor = context.getResources().getDisplayMetrics().density;
container = new LinearLayout(context);
container.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
lastX = lastY = -1;
}
public void show(ViewGroup view, int theX, int theY)
{
hide();
container.measure(view.getWidth(), view.getHeight());
int x = theX - (getWidth() / 2);
int y = theY - getHeight();
container.setPadding(x, y, 0, 0);
lastX = x;
lastY = y;
parentView.addView(container);
container.setVisibility(View.VISIBLE);
}
public int getHeight()
{
return container.getMeasuredHeight();
}
public int getWidth()
{
return container.getMeasuredWidth();
}
public boolean isVisible()
{
return container.getVisibility() == View.VISIBLE;
}
public void hide()
{
container.setPadding(0, 0, 0, 0);
container.setVisibility(View.INVISIBLE);
parentView.removeView(container);
}
public void setOnClickListener(View.OnTouchListener listener)
{
if(container != null){
container.setOnTouchListener(listener);
}
}
}
================================================
FILE: mAppWidget/demo2app/src/main/java/com/ls/demo/demo2/popup/TextPopup.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.demo.demo2.popup;
import com.ls.demo.demo2.R;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class TextPopup
extends MapPopupBase
{
public final static int ZERO = 0;
public final static int PADDING_BOTTOM = 11;
public final static int PADDING_TOP = 5;
public final static int PADDING_LEFT = 15;
public final static int PADDING_RIGHT = 10;
public final static float DEF_TEXT_SIZE = 16;
public final static int IMAGE_SIZE = 30;
public final static int MAX_EMS = 14;
private TextView text;
public TextPopup(Context context, ViewGroup parentView)
{
super(context, parentView);
text = new TextView(context);
text.setPadding((int)(PADDING_LEFT * dipScaleFactor),
(int)(PADDING_TOP * dipScaleFactor),
(int)(PADDING_RIGHT * dipScaleFactor),
(int)(PADDING_BOTTOM * dipScaleFactor));
text.setBackgroundResource(R.drawable.map_description_background);
text.setTextSize(DEF_TEXT_SIZE);
text.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
text.setMaxEms(MAX_EMS);
text.setTextColor(Color.WHITE);
container.addView(text);
text.setFocusable(true);
text.setClickable(true);
}
public void moveBy(int dx, int dy)
{
if (lastX != -1 && lastY != -1){
int paddingBottom = 0;
int paddingRight = 0;
if(container.getPaddingTop() > (screenHeight - (text.getHeight() + 3))){
paddingBottom = (container.getPaddingBottom() - dy);
}
if(container.getPaddingLeft() > (screenWidth - (text.getWidth() + 3))){
paddingRight = container.getPaddingRight() - dx;
}
container.setPadding(container.getPaddingLeft() + dx,
container.getPaddingTop() + dy,
paddingRight, paddingBottom);
}
}
public void setText(String theText)
{
text.setPadding((int)(PADDING_LEFT * dipScaleFactor),
(int)(PADDING_TOP * dipScaleFactor),
(int)(PADDING_RIGHT * dipScaleFactor),
(int)(PADDING_BOTTOM * dipScaleFactor));
text.setText(theText + " ");
}
public void setIcon(BitmapDrawable theDrawable)
{
if (theDrawable != null) {
theDrawable.setBounds(0,0, (int) (theDrawable.getBitmap().getWidth()),
(int)(theDrawable.getBitmap().getHeight()));
}
text.setCompoundDrawables(null, null, theDrawable, null);
}
public void removeIcon()
{
text.setCompoundDrawables(null, null, null, null);
}
public void setOnClickListener(View.OnTouchListener listener)
{
if(text != null){
text.setOnTouchListener(listener);
}
}
}
================================================
FILE: mAppWidget/demo2app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/layout/main.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/menu/menu.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/menu/menu_main.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/values/dimens.xml
================================================
16dp16dp
================================================
FILE: mAppWidget/demo2app/src/main/res/values/strings.xml
================================================
Demo2Hello world!Settings
================================================
FILE: mAppWidget/demo2app/src/main/res/values/styles.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/values/theme.xml
================================================
================================================
FILE: mAppWidget/demo2app/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: mAppWidget/gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
================================================
FILE: mAppWidget/gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: mAppWidget/gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: mAppWidget/gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: mAppWidget/mappwidgetlib/.gitignore
================================================
/build
================================================
FILE: mAppWidget/mappwidgetlib/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.4.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task cleanJar(type: Delete) {
delete 'build/outputs/mAppWidget.jar'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'mAppWidget.jar')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.1.1'
}
================================================
FILE: mAppWidget/mappwidgetlib/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/dmytrobaryskyy/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: mAppWidget/mappwidgetlib/src/androidTest/assets/map/map.xml
================================================
================================================
FILE: mAppWidget/mappwidgetlib/src/androidTest/java/com/ls/widgets/map/AllTests.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.widgets.map;
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
//$JUnit-BEGIN$
suite.addTestSuite(OfflineMapUtilTest.class);
suite.addTestSuite(GridTest.class);
suite.addTestSuite(CellTest.class);
suite.addTestSuite(OfflineMapConfigTest.class);
suite.addTestSuite(MapLayerTest.class);
suite.addTestSuite(MapWidgetTest.class);
//$JUnit-END$
return suite;
}
}
================================================
FILE: mAppWidget/mappwidgetlib/src/androidTest/java/com/ls/widgets/map/CellTest.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.widgets.map;
import com.ls.widgets.map.config.OfflineMapConfig;
import com.ls.widgets.map.model.Cell;
import com.ls.widgets.map.model.Grid;
import com.ls.widgets.map.providers.AssetTileProvider;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.test.AndroidTestCase;
import android.widget.LinearLayout;
public class CellTest extends AndroidTestCase
{
private static final int MAP_ORIGINAL_WIDTH = 1520;
private static final int MAP_ORIGINAL_HEIGHT = 920;
private static final int MAX_ZOOM_LEVEL = 11;
private OfflineMapConfig config;
private AssetTileProvider tileManager;
private Drawable drawable;
protected void setUp() throws Exception {
super.setUp();
config = new OfflineMapConfig("map", MAP_ORIGINAL_WIDTH, MAP_ORIGINAL_HEIGHT, 256, 1, "png");
tileManager = new AssetTileProvider(getContext(), config);
drawable = new BitmapDrawable(Bitmap.createBitmap(config.getTileSize(), config.getTileSize(), Bitmap.Config.RGB_565));
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testRecalculateDrawableRect()
{
Grid grid = new Grid(new LinearLayout(getContext()), config, tileManager, MAX_ZOOM_LEVEL);
CellImpl cell = new CellImpl(grid, tileManager, 6, 0, 0, config.getTileSize(), 1.0f);
cell.setImage(drawable);
cell.recalculateDrawableRect(0, 0);
Rect imageRect = cell.getDrawableRect();
Rect shouldBe = new Rect(0,0,256,256);
assertEquals(shouldBe, imageRect);
cell.setScale(2.0f);
imageRect = cell.getDrawableRect();
shouldBe.set(0,0, 512, 512);
assertEquals(shouldBe, imageRect);
cell = new CellImpl(grid, tileManager, 11, 1, 1, config.getTileSize(), 1.0f);
drawable = new BitmapDrawable(Bitmap.createBitmap(config.getTileSize(), config.getTileSize(), Bitmap.Config.RGB_565));
cell.setImage(drawable);
cell.setScale(1.0f);
cell.recalculateDrawableRect(0, 0);
shouldBe.set(256, 256, 512, 512);
imageRect = cell.getDrawableRect();
assertEquals(shouldBe, imageRect);
}
private void assertEquals(Rect r1, Rect r2)
{
assertEquals(r1.top, r2.top);
assertEquals(r1.left, r2.left);
assertEquals(r1.bottom, r2.bottom);
assertEquals(r1.right, r2.right);
}
private static class CellImpl extends Cell
{
public CellImpl(Grid parent, AssetTileProvider tileManager, int zoomLevel, int col, int row, int tileSize, float scale) {
super(parent, tileManager, zoomLevel, col, row, tileSize, scale);
}
@Override
protected void recalculateDrawableRect(float dx, float dy) {
// TODO Auto-generated method stub
super.recalculateDrawableRect(dx, dy);
}
public void setImage(Drawable drawable)
{
this.image = drawable;
}
public Rect getDrawableRect()
{
return image.getBounds();
}
}
}
================================================
FILE: mAppWidget/mappwidgetlib/src/androidTest/java/com/ls/widgets/map/GridTest.java
================================================
/*************************************************************************
* Copyright (c) 2015 Lemberg Solutions
*
* 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.
**************************************************************************/
package com.ls.widgets.map;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.test.AndroidTestCase;
import android.view.View;
import android.widget.LinearLayout;
import com.ls.widgets.map.config.OfflineMapConfig;
import com.ls.widgets.map.interfaces.TileManagerDelegate;
import com.ls.widgets.map.model.Grid;
import com.ls.widgets.map.providers.AssetTileProvider;
public class GridTest extends AndroidTestCase {
OfflineMapConfig config;
AssetTileProvider tileManager;
private static final int MAP_ORIGINAL_WIDTH = 1520;
private static final int MAP_ORIGINAL_HEIGHT = 920;
private static final int MAX_ZOOM_LEVEL = 11;
private int colCount[] = {1,1,1,1,1,1,1,1,1,2,3,6}; // col count on each zoom level
private int rowCount[] = {1,1,1,1,1,1,1,1,1,1,2,4}; // row count on each zoom level
private int widthOnZoomLevel[] = {1,2,3,6,12,24,48,95,190,380,760,1520}; // width of the grid on each zoom level in pixels
private int heightOnZoomLevel[] = {1,1,2,4,8,15,29,58,115,230,460,920}; // height of the grid on each zoom level in pixels
// scale on each zoom level
private double scaleOnZoomLevel[] = {0.00048828125f, 0.0009765625f, 0.001953125f, 0.00390625f, 0.0078125f, 0.015625f, 0.03125f, 0.0625f, 0.125f, 0.25f, 0.5f, 1.0f};
private BitmapDrawable drawable;
protected void setUp() throws Exception
{
super.setUp();
config = new OfflineMapConfig("map", MAP_ORIGINAL_WIDTH, MAP_ORIGINAL_HEIGHT, 256, 1, "png");
drawable = new BitmapDrawable(getContext().getResources(),
BitmapFactory.decodeResource(getContext().getResources(),
com.ls.widgets.map.test.R.drawable.maps_blue_dot));
tileManager = new TestTileManager(getContext(), config);
}
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testGetHeight()
{
for (int i=0; i< heightOnZoomLevel.length; ++i) {
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, i);
assertEquals(heightOnZoomLevel[i], grid.getHeight());
}
}
public void testGetOriginalHeight()
{
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, MAX_ZOOM_LEVEL);
assertEquals(MAP_ORIGINAL_HEIGHT, grid.getOriginalHeight());
}
public void testGetOriginalWidth()
{
for (int i=0; i<=MAX_ZOOM_LEVEL; ++i) {
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, MAX_ZOOM_LEVEL);
assertEquals(MAP_ORIGINAL_WIDTH, grid.getOriginalWidth());
}
}
public void testGetWidth()
{
for (int i=0; i<=MAX_ZOOM_LEVEL; ++i) {
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, i);
assertEquals(widthOnZoomLevel[i], grid.getWidth());
}
}
public void testGetMaxZoomLevel()
{
for (int i=0; i<= MAX_ZOOM_LEVEL; ++i) {
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, i);
assertEquals(MAX_ZOOM_LEVEL, grid.getMaxZoomLevel());
}
}
public void testGetMinZoomLevel()
{
for (int i=0; i<= MAX_ZOOM_LEVEL; ++i) {
GridToTest grid = new GridToTest(new LinearLayout(getContext()), config, tileManager, i);
assertEquals(0, grid.getMinZoomLevel());
}
}
public void testGetColCount()
{
for (int i=0; i touchedIds = ((MapLayer)layer).getTouched(touchedX, touchedY);
//
// if (touchable) {
// assertEquals(1, touchedIds.size());
// } else {
// assertEquals(0, touchedIds.size());
// }
//
// if (touchable) {
// Object id = touchedIds.get(0);
// assertEquals(counter, id);
// }
//
// counter += 1;
// }
// }
// }
private void getTouchedTest2(boolean touchable)
{
int counter = 0;
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
getTouchedGenerateMapObjects(touchable, width, height);
counter = 0;
for (int i=0; i < 480/width; ++i) {
for (int j=0; j < 800/height; ++j) {
int touchedX = (int)((float)i*(float)width+(float)width/2.0f);
int touchedY = (int)((float)j*(float)height+(float)height/2.0f);
ArrayList