/***
* Copyright (c) 2010 readyState Software Ltd
*
* 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.readystatesoftware.mapviewballoons;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
/**
* An abstract extension of ItemizedOverlay for displaying an information balloon
* upon screen-tap of each marker overlay.
*
* @author Jeff Gilfelt
*/
public abstract class BalloonItemizedOverlay<Item extends OverlayItem> extends ItemizedOverlay<Item> {
private static final long BALLOON_INFLATION_TIME = 300;
private static Handler handler = new Handler();
private MapView mapView;
private BalloonOverlayView<Item> balloonView;
private View clickRegion;
private View closeRegion;
private int viewOffset;
final MapController mc;
private Item currentFocusedItem;
private int currentFocusedIndex;
private boolean showClose = true;
private boolean showDisclosure = false;
private boolean snapToCenter = true;
private static boolean isInflating = false;
/**
* Create a new BalloonItemizedOverlay
*
* @param defaultMarker - A bounded Drawable to be drawn on the map for each item in the overlay.
* @param mapView - The view upon which the overlay items are to be drawn.
*/
public BalloonItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(defaultMarker);
this.mapView = mapView;
viewOffset = 0;
mc = mapView.getController();
}
/**
* Set the horizontal distance between the marker and the bottom of the information
* balloon. The default is 0 which works well for center bounded markers. If your
* marker is center-bottom bounded, call this before adding overlay items to ensure
* the balloon hovers exactly above the marker.
*
* @param pixels - The padding between the center point and the bottom of the
* information balloon.
*/
public void setBalloonBottomOffset(int pixels) {
viewOffset = pixels;
}
public int getBalloonBottomOffset() {
return viewOffset;
}
/**
* Override this method to handle a "tap" on a balloon. By default, does nothing
* and returns false.
*
* @param index - The index of the item whose balloon is tapped.
* @param item - The item whose balloon is tapped.
* @return true if you handled the tap, otherwise false.
*/
protected boolean onBalloonTap(int index, Item item) {
return false;
}
/**
* Override this method to perform actions upon an item being tapped before
* its balloon is displayed.
*
* @param index - The index of the item tapped.
*/
protected void onBalloonOpen(int index) {}
/* (non-Javadoc)
* @see com.google.android.maps.ItemizedOverlay#onTap(int)
*/
@Override
//protected final boolean onTap(int index) {
public final boolean onTap(int index) {
handler.removeCallbacks(finishBalloonInflation);
isInflating = true;
handler.postDelayed(finishBalloonInflation, BALLOON_INFLATION_TIME);
currentFocusedIndex = index;
currentFocusedItem = createItem(index);
setLastFocusedIndex(index);
onBalloonOpen(index);
createAndDisplayBalloonOverlay();
if (snapToCenter) {
animateTo(index, currentFocusedItem.getPoint());
}
return true;
}
/**
* Animates to the given center point. Override to customize how the
* MapView is animated to the given center point
*
* @param index The index of the item to center
* @param center The center point of the item
*/
protected void animateTo(int index, GeoPoint center) {
mc.animateTo(center);
}
/**
* Creates the balloon view. Override to create a sub-classed view that
* can populate additional sub-views.
*/
protected BalloonOverlayView<Item> createBalloonOverlayView() {
return new BalloonOverlayView<Item>(getMapView().getContext(), getBalloonBottomOffset());
}
/**
* Expose map view to subclasses.
* Helps with creation of balloon views.
*/
protected MapView getMapView() {
return mapView;
}
/**
* Makes the balloon the topmost item by calling View.bringToFront().
*/
public void bringBalloonToFront() {
if (balloonView != null) {
balloonView.bringToFront();
}
}
/**
* Sets the visibility of this overlay's balloon view to GONE and unfocus the item.
*/
public void hideBalloon() {
if (balloonView != null) {
balloonView.setVisibility(View.GONE);
}
currentFocusedItem = null;
}
/**
* Hides the balloon view for any other BalloonItemizedOverlay instances
* that might be present on the MapView.
*
* @param overlays - list of overlays (including this) on the MapView.
*/
private void hideOtherBalloons(List<Overlay> overlays) {
for (Overlay overlay : overlays) {
if (overlay instanceof BalloonItemizedOverlay<?> && overlay != this) {
((BalloonItemizedOverlay<?>) overlay).hideBalloon();
}
}
}
public void hideAllBalloons() {
if (!isInflating) {
List<Overlay> mapOverlays = mapView.getOverlays();
if (mapOverlays.size() > 1) {
hideOtherBalloons(mapOverlays);
}
hideBalloon();
}
}
/**
* Sets the onTouchListener for the balloon being displayed, calling the
* overridden {@link #onBalloonTap} method.
*/
private OnTouchListener createBalloonTouchListener() {
return new OnTouchListener() {
float startX;
float startY;
public boolean onTouch(View v, MotionEvent event) {
View l = ((View) v.getParent()).findViewById(R.id.balloon_main_layout);
Drawable d = l.getBackground();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (d != null) {
int[] states = {android.R.attr.state_pressed};
if (d.setState(states)) {
d.invalidateSelf();
}
}
startX = event.getX();
startY = event.getY();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (d != null) {
int newStates[] = {};
if (d.setState(newStates)) {
d.invalidateSelf();
}
}
if (Math.abs(startX - event.getX()) < 40 &&
Math.abs(startY - event.getY()) < 40 ) {
// call overridden method
onBalloonTap(currentFocusedIndex, currentFocusedItem);
}
return true;
} else {
return false;
}
}
};
}
/* (non-Javadoc)
* @see com.google.android.maps.ItemizedOverlay#getFocus()
*/
@Override
public Item getFocus() {
return currentFocusedItem;
}
/* (non-Javadoc)
* @see com.google.android.maps.ItemizedOverlay#setFocus(Item)
*/
@Override
public void setFocus(Item item) {
super.setFocus(item);
currentFocusedIndex = getLastFocusedIndex();
currentFocusedItem = item;
if (currentFocusedItem == null) {
hideBalloon();
} else {
createAndDisplayBalloonOverlay();
}
}
/**
* Creates and displays the balloon overlay by recycling the current
* balloon or by inflating it from xml.
* @return true if the balloon was recycled false otherwise
*/
private boolean createAndDisplayBalloonOverlay(){
boolean isRecycled;
if (balloonView == null) {
balloonView = createBalloonOverlayView();
clickRegion = (View) b
没有合适的资源?快使用搜索试试~ 我知道了~
android-mapviewballoons-master
共42个文件
java:12个
png:12个
xml:9个
3星 · 超过75%的资源 需积分: 9 7 下载量 51 浏览量
2013-06-19
11:39:14
上传
评论
收藏 54KB RAR 举报
温馨提示
android-mapviewballoons-master是一个基于android谷歌地图的图层,加载气球图标,表明自己的位置。
资源推荐
资源详情
资源评论
收起资源包目录
android-mapviewballoons-master.rar (42个子文件)
android-mapviewballoons-master
.gitignore 233B
android-mapviewballoons-example
.project 834B
AndroidManifest.xml 1KB
src
mapviewballoons
Main.java 2KB
example
simple
SimpleMap.java 4KB
SimpleItemizedOverlay.java 2KB
tapcontrolled
TapControlledMap.java 5KB
custom
CustomItemizedOverlay.java 2KB
CustomMap.java 3KB
CustomBalloonOverlayView.java 3KB
CustomOverlayItem.java 1KB
project.properties 432B
res
values
strings.xml 126B
layout
balloon_overlay_example2.xml 2KB
main_example3.xml 370B
main.xml 309B
drawable-hdpi
marker2.png 2KB
marker.png 2KB
icon.png 4KB
drawable
marker2.png 1KB
marker.png 1KB
icon.png 3KB
.classpath 356B
LICENSE 11KB
README.markdown 4KB
android-mapviewballoons
.project 826B
AndroidManifest.xml 516B
src
com
readystatesoftware
maps
TapControlledMapView.java 2KB
OnSingleTapListener.java 157B
mapviewballoons
BalloonItemizedOverlay.java 10KB
BalloonOverlayView.java 4KB
project.properties 482B
res
values
ids.xml 152B
drawable-tvdpi
balloon_overlay_unfocused.9.png 2KB
balloon_overlay_focused.9.png 2KB
layout
balloon_overlay.xml 2KB
drawable-hdpi
balloon_overlay_unfocused.9.png 2KB
balloon_overlay_focused.9.png 2KB
balloon_disclosure.png 524B
balloon_overlay_close.png 778B
drawable
balloon_overlay_bg_selector.xml 334B
.classpath 372B
共 42 条
- 1
资源评论
- xch2022022014-07-06很好,值得参考
半棵树
- 粉丝: 2537
- 资源: 247
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数学建模算法学习参考资料
- Java开发面试题整理含答案(计网、Java、操作系统、数据库、框架)
- 基于mask rcnn的发根豆芽根部相关参数的检测(获取发根豆芽的根部长度、根部直径、侧根数目、根部面积)
- 基于STM32的智能导盲拐杖源码+详细文档+全部资料(优秀项目).zip
- 电子设计电路图出租车计价器论文
- 电子设计电路图智能健康监护仪的研究毕业设计论文资料
- 电子设计电路图交通控制器设计论文资料
- 基于Python+Flask的智能图书借阅系统-毕业设计源码+使用文档(高分优秀项目).zip
- 电子设计电路图简易智能电动车论文资料
- 基于Python+Flask的智能图书借阅系统-毕业设计源码+使用文档(高分优秀项目).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功