no cross platform popup

This commit is contained in:
Dmitry Kunin 2014-02-17 18:17:18 +03:00 committed by Alex Zolotarev
parent 09fdd1d7d2
commit 87e651313a
20 changed files with 575 additions and 242 deletions

View file

@ -561,7 +561,7 @@ namespace android
void Framework::OnProcessTouchTask(double x, double y, unsigned ms)
{
m_wasLongClick = (ms == LONG_TOUCH_MS);
GetBalloonManager().OnClick(m2::PointD(x, y), m_wasLongClick);
GetPinClickManager().OnClick(m2::PointD(x, y), m_wasLongClick);
}
BookmarkAndCategory Framework::AddBookmark(size_t cat, Bookmark & bm)
@ -601,7 +601,7 @@ namespace android
void Framework::DeactivatePopup()
{
GetBalloonManager().Hide();
GetPinClickManager().Hide();
}
string Framework::GetOutdatedCountriesString()
@ -653,6 +653,18 @@ extern "C"
jniEnv->CallVoidMethod(*obj.get(), methodID, apiPoint.m_lat, apiPoint.m_lon, j_name, j_id);
}
// Additional layer
void CallOnAdditionalLayerActivatedListener(shared_ptr<jobject> obj, size_t index)
{
JNIEnv * jniEnv = jni::GetEnv();
const jmethodID methodID = jni::GetJavaMethodID(jniEnv,
*obj.get(),
"onAdditionalLayerActivated",
"(J)V");
jniEnv->CallVoidMethod(*obj.get(), methodID, static_cast<jlong>(index));
}
// POI
void CallOnPoiActivatedListener(shared_ptr<jobject> obj, m2::PointD const & globalPoint, search::AddressInfo const & addrInfo)
{
@ -688,6 +700,14 @@ extern "C"
jniEnv->CallVoidMethod(*obj.get(), methodId, lat, lon);
}
// Dismiss information box
void CallOnDismissListener(shared_ptr<jobject> obj)
{
JNIEnv * jniEnv = jni::GetEnv();
const jmethodID methodId = jni::GetJavaMethodID(jniEnv, *obj.get(), "onDismiss", "()V");
jniEnv->CallVoidMethod(*obj.get(), methodId);
}
/// @name JNI EXPORTS
//@{
JNIEXPORT jstring JNICALL
@ -710,19 +730,21 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeConnectBalloonListeners(JNIEnv * env, jclass clazz, jobject l)
{
BalloonManager & manager = g_framework->GetBalloonManager();
PinClickManager & manager = g_framework->GetPinClickManager();
shared_ptr<jobject> obj = jni::make_global_ref(l);
manager.ConnectApiListener(bind(&CallOnApiPointActivatedListener, obj, _1));
manager.ConnectPoiListener(bind(&CallOnPoiActivatedListener, obj, _1, _2));
manager.ConnectBookmarkListener(bind(&CallOnBookmarkActivatedListener, obj, _1));
manager.ConnectPositionListener(bind(&CallOnMyPositionActivatedListener, obj, _1, _2));
manager.ConnectAdditionalListener(bind(&CallOnAdditionalLayerActivatedListener, obj, _1));
manager.ConnectDismissListener(bind(&CallOnDismissListener, obj));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeClearBalloonListeners(JNIEnv * env, jobject thiz)
{
g_framework->GetBalloonManager().ClearListeners();
g_framework->GetPinClickManager().ClearListeners();
}
JNIEXPORT jstring JNICALL
@ -862,4 +884,21 @@ extern "C"
g_framework->ShowTrack(cat, track);
}
JNIEXPORT void Java_com_mapswithme_maps_Framework_injectData(JNIEnv * env, jclass clazz, jobject jsearchResult, jlong index)
{
Bookmark * b = g_framework->NativeFramework()->
GetBookmarkManager().AdditionalPoiLayerGetBookmark(static_cast<size_t>(index));
static jclass javaClazz = env->GetObjectClass(jsearchResult);
static jfieldID nameId = env->GetFieldID(javaClazz, "mName", "Ljava/lang/String;");
env->SetObjectField(jsearchResult, nameId, jni::ToJavaString(env, b->GetName()));
static jfieldID latId = env->GetFieldID(javaClazz, "mLat", "D");
env->SetDoubleField(jsearchResult, latId, static_cast<jdouble>(b->GetOrg().y));
static jfieldID lonId = env->GetFieldID(javaClazz, "mLon", "D");
env->SetDoubleField(jsearchResult, latId, static_cast<jdouble>(b->GetOrg().x));
}
}

View file

@ -121,7 +121,7 @@ namespace android
size_t ChangeBookmarkCategory(BookmarkAndCategory const & ind, size_t newCat);
::Framework * NativeFramework();
BalloonManager & GetBalloonManager() { return m_work.GetBalloonManager(); }
PinClickManager & GetPinClickManager() { return m_work.GetBalloonManager(); }
bool IsDownloadingActive();

View file

@ -5,12 +5,6 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="@dimen/abs__action_bar_default_height"
android:layout_gravity="top|center_horizontal"
layout="@layout/map_title_bar" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
@ -36,6 +30,7 @@
android:layout_height="match_parent"
layout="@layout/drawer_main" />
<!-- Dark vertical line -->
<View
android:layout_width="3dp"
android:layout_height="match_parent"

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_box_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_holo_light"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/info_title"
style="@style/Holo.TextAppearance.Large.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/info_subtitle"
style="@style/Holo.TextAppearance.Medium.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_holo_light"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="&lt;NO BODY>" />
</LinearLayout>
</LinearLayout>

View file

@ -2,7 +2,8 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:gravity="bottom" >
<android.view.SurfaceView
android:id="@+id/map_surfaceview"
@ -29,8 +30,14 @@
android:id="@+id/map_butons_container_ref"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_above="@+id/info_box"
android:layout_margin="0dp"
layout="@layout/map_button_bottom" />
<com.mapswithme.maps.widget.MapInfoView
android:id="@+id/info_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>

View file

@ -2,6 +2,7 @@ package com.mapswithme.maps;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.bookmarks.data.MapObject.SearchResult;
import com.mapswithme.maps.bookmarks.data.Track;
import com.mapswithme.maps.guides.GuideInfo;
import com.mapswithme.util.Utils;
@ -18,6 +19,8 @@ public class Framework
public void onPoiActivated(String name, String type, String address, double lat, double lon);
public void onBookmarkActivated(int category, int bookmarkIndex);
public void onMyPositionActivated(double lat, double lon);
public void onAdditionalLayerActivated(long index);
public void onDismiss();
}
// Interface
@ -126,4 +129,6 @@ public class Framework
// this class is just bridge between Java and C++ worlds, we must not create it
private Framework() {}
public native static void injectData(SearchResult searchResult, long index);
}

View file

@ -31,10 +31,12 @@ import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
@ -44,6 +46,9 @@ import com.mapswithme.maps.LocationButtonImageSetter.ButtonState;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.api.ParsedMmwRequest;
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.location.LocationService;
import com.mapswithme.maps.promo.ActivationSettings;
import com.mapswithme.maps.promo.PromocodeActivationDialog;
@ -51,6 +56,7 @@ import com.mapswithme.maps.search.SearchController;
import com.mapswithme.maps.settings.SettingsActivity;
import com.mapswithme.maps.settings.UnitLocale;
import com.mapswithme.maps.state.SuppotedState;
import com.mapswithme.maps.widget.MapInfoView;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.ShareAction;
import com.mapswithme.util.UiUtils;
@ -78,12 +84,15 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
// for API
private View mTitleBar;
private ImageView mAppIcon;
private TextView mAppTitle;
// private View mTitleBar;
// private ImageView mAppIcon;
// private TextView mAppTitle;
// Map tasks that we run AFTER rendering initialized
private final Stack<MapTask> mTasks = new Stack<MWMActivity.MapTask>();
//info box
MapInfoView mInfoView;
// Drawer components
private DrawerLayout mDrawerLayout;
@ -567,15 +576,15 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
//set up view
mLocationButton = (ImageButton) findViewById(R.id.map_button_myposition);
mTitleBar = findViewById(R.id.title_bar);
mAppIcon = (ImageView) findViewById(R.id.app_icon);
mAppTitle = (TextView) findViewById(R.id.app_title);
mMapSurface = (SurfaceView) findViewById(R.id.map_surfaceview);
setUpDrawer();
yotaSetup();
alignControls();
setUpInfoBox();
showInfoBox(false);
Framework.connectBalloonListeners(this);
final Intent intent = getIntent();
@ -590,6 +599,11 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
mSearchController.onCreate(this);
}
private void setUpInfoBox()
{
mInfoView = (MapInfoView) findViewById(R.id.info_box);
}
private void setUpDrawer()
{
final boolean isPro = mApplication.isProVersion();
@ -953,33 +967,33 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
@Override
public void setViewFromState(SuppotedState state)
{
if (state == SuppotedState.API_REQUEST && ParsedMmwRequest.hasRequest())
{
// show title
mTitleBar.findViewById(R.id.up_block).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
onBackPressed();
}
});
final ParsedMmwRequest request = ParsedMmwRequest.getCurrentRequest();
if (request.hasTitle())
mAppTitle.setText(request.getTitle());
else
mAppTitle.setText(request.getCallerName(this));
mAppIcon.setImageDrawable(request.getIcon(this));
mTitleBar.setVisibility(View.VISIBLE);
}
else
{
// hide title
mTitleBar.setVisibility(View.GONE);
}
// if (state == SuppotedState.API_REQUEST && ParsedMmwRequest.hasRequest())
// {
// // show title
// mTitleBar.findViewById(R.id.up_block).setOnClickListener(new OnClickListener()
// {
// @Override
// public void onClick(View v)
// {
// onBackPressed();
// }
// });
//
// final ParsedMmwRequest request = ParsedMmwRequest.getCurrentRequest();
// if (request.hasTitle())
// mAppTitle.setText(request.getTitle());
// else
// mAppTitle.setText(request.getCallerName(this));
//
// mAppIcon.setImageDrawable(request.getIcon(this));
// mTitleBar.setVisibility(View.VISIBLE);
//
// }
// else
// {
// // hide title
// mTitleBar.setVisibility(View.GONE);
// }
}
@Override
@ -1245,6 +1259,8 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
final ParsedMmwRequest request = ParsedMmwRequest.getCurrentRequest();
request.setPointData(lat, lon, name, id);
// TODO this is crappy moment now
if (request.doReturnOnBalloonClick())
{
request.sendResponseAndFinish(this, true);
@ -1258,7 +1274,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
@Override
public void run()
{
MapObjectActivity.startWithApiPoint(getActivity(), name, null, null, lat, lon);
// showInfoBoxWithText("Api Point", name);
}
});
}
@ -1266,12 +1282,18 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
@Override
public void onPoiActivated(final String name, final String type, final String address, final double lat, final double lon)
{
final MapObject.Poi poi = new MapObject.Poi(name, lat, lon, type);
runOnUiThread(new Runnable()
{
@Override
public void run()
{
MapObjectActivity.startWithPoi(getActivity(), name, type, address, lat, lon);
if (!mInfoView.hasThatObject(poi))
{
mInfoView.setMapObject(poi);
showInfoBox(true);
}
}
});
}
@ -1284,11 +1306,18 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
@Override
public void run()
{
MapObjectActivity.startWithBookmark(getActivity(), category, bookmarkIndex);
final Bookmark b = BookmarkManager.getBookmarkManager().getBookmark(category, bookmarkIndex);
if (!mInfoView.hasThatObject(b))
{
mInfoView.setMapObject(b);
showInfoBox(true);
}
}
});
}
@Override
public void onMyPositionActivated(final double lat, final double lon)
{
@ -1297,11 +1326,86 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
@Override
public void run()
{
MapObjectActivity.startWithMyPosition(getActivity(), lat, lon);
// showInfoBoxWithText(getString(R.string.my_position), Framework.latLon2DMS(lat, lon));
}
});
}
@Override
public void onAdditionalLayerActivated(final long index)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
final MapObject sr = new MapObject.SearchResult(index);
if (!mInfoView.hasThatObject(sr))
{
mInfoView.setMapObject(sr);
showInfoBox(true);
}
}
});
}
@Override
public void onDismiss()
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
showInfoBox(false);
mInfoView.setMapObject(null);
}
});
}
private void showInfoBox(boolean show)
{
final View mapButtonBottom = findViewById(R.id.map_butons_container_ref);
final RelativeLayout.LayoutParams lp = (LayoutParams) mapButtonBottom.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, show ? 0 : RelativeLayout.TRUE);
mapButtonBottom.setLayoutParams(lp);
if (show)
{
final Animation slideIn = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0.f, TranslateAnimation.RELATIVE_TO_SELF, 0.f, // X
TranslateAnimation.RELATIVE_TO_SELF, 1.f, TranslateAnimation.RELATIVE_TO_SELF, 0.f); // Y
slideIn.setDuration(300);
mInfoView.startAnimation(slideIn);
mapButtonBottom.startAnimation(slideIn);
UiUtils.showAndAnimate(mInfoView, slideIn);
mapButtonBottom.startAnimation(slideIn);
}
else
{
final Animation slideOutInfo = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0.f, TranslateAnimation.RELATIVE_TO_SELF, 0.f, // X
TranslateAnimation.RELATIVE_TO_SELF, 0.f, TranslateAnimation.RELATIVE_TO_SELF, 1.f); // Y
slideOutInfo.setDuration(300);
final Animation slideOutButtons = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0.f, TranslateAnimation.RELATIVE_TO_SELF, 0.f, // X
TranslateAnimation.RELATIVE_TO_SELF, -1.f, TranslateAnimation.RELATIVE_TO_SELF, 0.f); // Y
slideOutButtons.setDuration(300);
mapButtonBottom.startAnimation(slideOutButtons);
UiUtils.animateAndHide(mInfoView, slideOutInfo);
}
}
// private void showInfoBoxWithText(CharSequence title, CharSequence subtitle)
// {
// mInfoView.setTextAndShow(title, subtitle);
// showInfoBox(true);
// }
public static Intent createShowMapIntent(Context context, Index index)
{
return new Intent(context, DownloadResourcesActivity.class)

View file

@ -18,9 +18,9 @@ import android.view.MenuItem;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType;
import com.mapswithme.maps.bookmarks.data.ParcelablePointD;
public class MapObjectActivity extends FragmentActivity
@ -44,7 +44,7 @@ public class MapObjectActivity extends FragmentActivity
public static void startWithBookmark(Context context, int categoryIndex, int bookmarkIndex)
{
final Intent i = new Intent(context, MapObjectActivity.class);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectFragment.MapObjectType.BOOKMARK);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectType.BOOKMARK);
i.putExtra(EXTRA_BMK_CAT, categoryIndex);
i.putExtra(EXTRA_BMK_INDEX, bookmarkIndex);
context.startActivity(i);
@ -53,7 +53,7 @@ public class MapObjectActivity extends FragmentActivity
public static void startWithPoi(Context context, String name, String type, String address, double lat, double lon)
{
final Intent i = new Intent(context, MapObjectActivity.class);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectFragment.MapObjectType.POI);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectType.POI);
i.putExtra(EXTRA_NAME, name);
i.putExtra(EXTRA_TYPE, type);
i.putExtra(EXTRA_ADDRESS, address);
@ -65,7 +65,7 @@ public class MapObjectActivity extends FragmentActivity
public static void startWithApiPoint(Context context, String name, String type, String address, double lat, double lon)
{
final Intent i = new Intent(context, MapObjectActivity.class);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectFragment.MapObjectType.API_POINT);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectType.API_POINT);
i.putExtra(EXTRA_NAME, name);
i.putExtra(EXTRA_LAT, lat);
i.putExtra(EXTRA_LON, lon);
@ -75,7 +75,7 @@ public class MapObjectActivity extends FragmentActivity
public static void startWithMyPosition(Context context, double lat, double lon)
{
final Intent i = new Intent(context, MapObjectActivity.class);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectFragment.MapObjectType.MY_POSITION);
i.putExtra(EXTRA_OBJECT_TYPE, MapObjectType.MY_POSITION);
i.putExtra(EXTRA_LAT, lat);
i.putExtra(EXTRA_LON, lon);
context.startActivity(i);

View file

@ -1,7 +1,5 @@
package com.mapswithme.maps;
import java.io.Serializable;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Color;
@ -31,6 +29,7 @@ import com.mapswithme.maps.bookmarks.BookmarkActivity;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType;
import com.mapswithme.util.ShareAction;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
@ -41,15 +40,6 @@ import com.mapswithme.util.statistics.Statistics;
public class MapObjectFragment extends Fragment
implements OnClickListener
{
public static enum MapObjectType implements Serializable
{
POI,
API_POINT,
BOOKMARK,
MY_POSITION
}
private static final int MENU_ADD = 0x01;
private static final int MENU_EDIT = 0x02;
private static final int MENU_SHARE = 0x10;
@ -305,7 +295,6 @@ public class MapObjectFragment extends Fragment
{
if (!MWMApplication.get().hasBookmarks())
{
// TODO this cast if safe, but style is bad
final MapObjectActivity activity = (MapObjectActivity) getActivity();
activity.showProVersionBanner(getString(R.string.bookmarks_in_pro_version));
}

View file

@ -3,7 +3,6 @@ package com.mapswithme.maps.bookmarks.data;
import android.content.Context;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
import com.mapswithme.maps.R;
public class Bookmark extends MapObject

View file

@ -1,13 +1,122 @@
package com.mapswithme.maps.bookmarks.data;
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
import java.io.Serializable;
import com.mapswithme.maps.Framework;
public abstract class MapObject
{
public abstract double getScale();
public double getScale() { return 0; };
// Interface
public abstract String getName();
public abstract double getLat();
public abstract double getLon();
public abstract MapObjectType getType();
// interface
public static Integer checkSum(MapObject mo)
{
if (mo == null) return 0;
final int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23};
final int base = primes[mo.getType().ordinal()];
final int sum = base*Double.valueOf(mo.getLat()).hashCode()
+ base*Double.valueOf(mo.getLon()).hashCode()
+ mo.getName() == null ? 1 : mo.getName().hashCode();
return sum;
}
public static enum MapObjectType implements Serializable
{
POI,
API_POINT,
BOOKMARK,
MY_POSITION,
ADDITIONAL_LAYER
}
public static class Poi extends MapObject
{
private final String mName;
private final double mLat;
private final double mLon;
private final String mCategory;
public Poi(String name, double lat, double lon, String category)
{
mName = name;
mLat = lat;
mLon = lon;
mCategory = category;
}
@Override
public String getName()
{
return mName;
}
@Override
public double getLat()
{
return mLat;
}
@Override
public double getLon()
{
return mLon;
}
@Override
public MapObjectType getType()
{
return MapObjectType.POI;
}
public String getCategory()
{
return mCategory;
}
}
public static class SearchResult extends MapObject
{
private String mName;
private double mLat;
private double mLon;
public SearchResult(long index)
{
Framework.injectData(this, index);
}
@Override
public String getName()
{
return mName;
}
@Override
public double getLat()
{
return mLat;
}
@Override
public double getLon()
{
return mLon;
}
@Override
public MapObjectType getType()
{
return MapObjectType.ADDITIONAL_LAYER;
}
}
}

View file

@ -0,0 +1,109 @@
package com.mapswithme.maps.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.util.UiUtils;
public class MapInfoView extends LinearLayout
{
private boolean mIsHeaderVisible;
private boolean mIsBodyVisible;
private boolean mIsVisible;
private final ViewGroup mHeaderGroup;
private final ViewGroup mBodyGroup;
private final View mView;
// Header
private final TextView mTitle;;
private final TextView mSubtitle;
// Data
MapObject mMapObject;
public MapInfoView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
final LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = li.inflate(R.layout.info_box, this, true);
mHeaderGroup = (ViewGroup) mView.findViewById(R.id.header);
mBodyGroup = (ViewGroup) mView.findViewById(R.id.body);
showBody(false);
showHeader(false);
show(false);
// Header
mTitle = (TextView) mHeaderGroup.findViewById(R.id.info_title);
mSubtitle = (TextView) mHeaderGroup.findViewById(R.id.info_subtitle);
}
public MapInfoView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public MapInfoView(Context context)
{
this(context, null, 0);
}
public void showBody(boolean show)
{
UiUtils.hideIf(!show, mBodyGroup);
mIsBodyVisible = show;
}
public void showHeader(boolean show)
{
UiUtils.hideIf(!show, mHeaderGroup);
mIsBodyVisible = show;
}
public void show(boolean show)
{
UiUtils.hideIf(!show, mView);
mIsVisible = show;
}
private void setTextAndShow(CharSequence title, CharSequence subtitle)
{
mTitle.setText(title);
mSubtitle.setText(subtitle);
show(true);
showHeader(true);
}
public boolean hasThatObject(MapObject mo)
{
return MapObject.checkSum(mo).equals(MapObject.checkSum(mMapObject));
}
public void setMapObject(MapObject mo)
{
if (!hasThatObject(mo))
{
if (mo != null)
{
mMapObject = mo;
setTextAndShow(mo.getName(), mo.getType().toString());
}
else
{
mMapObject = mo;
}
}
}
}

View file

@ -15,9 +15,9 @@ import android.view.Menu;
import android.view.MenuItem;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MapObjectFragment.MapObjectType;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType;
import com.mapswithme.util.statistics.Statistics;
public abstract class ShareAction

View file

@ -13,6 +13,8 @@ import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import com.mapswithme.maps.Framework;
@ -63,6 +65,42 @@ public final class UiUtils
show(views);
}
public static void animateAndHide(final View target, Animation anim)
{
anim.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
}
@Override
public void onAnimationRepeat(Animation animation)
{
}
@Override
public void onAnimationEnd(Animation animation)
{
try
{
hide(target);
} catch (final Exception e)
{
// ignore
}
}
});
target.startAnimation(anim);
}
public static void showAndAnimate(final View target, Animation anim)
{
show(target);
target.startAnimation(anim);
}
public static Drawable setCompoundDrawableBounds(int drawableId, int dimenId, Resources res)
{

View file

@ -1,4 +1,3 @@
#include "bookmark_balloon.hpp"
#include "balloon_manager.hpp"
#include "framework.hpp"
@ -9,124 +8,34 @@
#include "../gui/controller.hpp"
BalloonManager::BalloonManager(Framework & f)
PinClickManager::PinClickManager(Framework & f)
: m_f(f), m_updateForLocation(false)
{}
void PinClickManager::RenderPolicyCreated(graphics::EDensity density)
{}
void PinClickManager::LocationChanged(location::GpsInfo const & info)
{}
void PinClickManager::OnPositionClicked(m2::PointD const & pt)
{
}
void BalloonManager::CreateBookmarkBalloon()
{
CHECK(m_f.GetGuiController(), ());
CHECK(m_f.GetLocationState(), ());
BookmarkBalloon::Params bp;
bp.m_position = graphics::EPosAbove;
bp.m_depth = graphics::balloonBaseDepth;
bp.m_pivot = m2::PointD(0, 0);
bp.m_framework = &m_f;
m_balloon.reset(new BookmarkBalloon(bp));
m_balloon->setIsVisible(false);
m_f.GetGuiController()->AddElement(m_balloon);
m_f.GetLocationState()->AddOnPositionClickListener(bind(&BalloonManager::OnPositionClicked, this, _1));
}
void BalloonManager::RenderPolicyCreated(graphics::EDensity density)
{
if (m_balloon == 0)
CreateBookmarkBalloon();
m_balloon->setImage(graphics::Image::Info("arrow.png", density));
}
void BalloonManager::ScreenSizeChanged(int width, int height)
{
if (m_balloon)
m_balloon->onScreenSize(width, height);
}
void BalloonManager::LocationChanged(location::GpsInfo const & info)
{
if (m_balloon && m_updateForLocation)
{
m_balloon->setGlbPivot(m2::PointD(MercatorBounds::LonToX(info.m_longitude),
MercatorBounds::LatToY(info.m_latitude)));
}
}
void BalloonManager::OnPositionClicked(m2::PointD const & pt)
{
Show(pt, m_f.GetStringsBundle().GetString("my_position"), "", false);
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivateMyPosition, this, _1));
m_positionListener(pt.x, pt.y);
m_updateForLocation = true;
}
void BalloonManager::Show(m2::PointD const & pt, string const & name, string const & type, bool needPadding)
void PinClickManager::Hide()
{
m_updateForLocation = false;
m_balloon->setGlbPivot(pt);
m_balloon->setBookmarkCaption(name, type);
m_balloon->showAnimated(needPadding);
m_f.Invalidate();
}
void BalloonManager::Hide()
{
m_updateForLocation = false;
m_balloon->hide();
m_f.Invalidate();
}
void BalloonManager::ShowAddress(m2::PointD const & pt, search::AddressInfo const & info)
{
string name = info.GetPinName();
string type = info.GetPinType();
if (name.empty() && type.empty())
name = m_f.GetStringsBundle().GetString("dropped_pin");
Show(pt, name, type, false);
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivatePOI, this, _1, info));
}
void BalloonManager::ShowURLPoint(url_scheme::ResultPoint const & point, bool needPadding)
{
Show(point.GetOrg(), point.GetName(), "", needPadding);
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivateAPI, this, _1, point));
}
void BalloonManager::ShowBookmark(BookmarkAndCategory bmAndCat)
{
Bookmark const * pBM = m_f.GetBmCategory(bmAndCat.first)->GetBookmark(bmAndCat.second);
Show(pBM->GetOrg(), pBM->GetName(), "", true);
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivateBookmark, this, _1, bmAndCat));
}
void BalloonManager::ShowAdditionalLayerBookmark(size_t index)
{
ASSERT(index < m_f.AdditionalLayerNumberOfPoi(), ());
Bookmark const * pBM = m_f.AdditionalPoiLayerGetBookmark(index);
Show(pBM->GetOrg(), pBM->GetName(), "", true);
search::AddressInfo info;
info.m_name = pBM->GetName();
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivatePOI, this, _1, info));
}
void BalloonManager::OnClick(m2::PointD const & pxPoint, bool isLongTouch)
void PinClickManager::OnClick(m2::PointD const & pxPoint, bool isLongTouch)
{
url_scheme::ResultPoint apiPoint;
if (m_f.GetMapApiPoint(pxPoint, apiPoint))
{
Show(apiPoint.GetOrg(), apiPoint.GetName(), "", true);
m_balloon->setOnClickListener(bind(&BalloonManager::OnActivateAPI, this, _1, apiPoint));
OnActivateAPI(apiPoint);
}
else
{
@ -138,64 +47,70 @@ void BalloonManager::OnClick(m2::PointD const & pxPoint, bool isLongTouch)
{
case Framework::BOOKMARK:
{
ShowBookmark(bmAndCat);
OnActivateBookmark(bmAndCat);
return;
}
case Framework::ADDTIONAL_LAYER:
{
ShowAdditionalLayerBookmark(bmAndCat.second);
OnAdditonalLayer(bmAndCat.second);
return;
}
case Framework::POI:
if (!m_balloon->isVisible())
{
ShowAddress(m_f.PtoG(pxPivot), addrInfo);
OnActivatePOI(m_f.PtoG(pxPoint), addrInfo);
return;
}
default:
if (isLongTouch)
{
m2::PointD const glbPoint = m_f.PtoG(pxPoint);
m_f.GetAddressInfoForGlobalPoint(glbPoint, addrInfo);
ShowAddress(glbPoint, addrInfo);
OnActivatePOI(glbPoint, addrInfo);
return;
}
}
// hide the balloon by default if no any Show before
Hide();
OnDismiss();
}
}
void BalloonManager::ClearListeners()
void PinClickManager::ClearListeners()
{
m_poiListener.clear();
m_bookmarkListener.clear();
m_apiListener.clear();
m_positionListener.clear();
m_additionalLayerListener.clear();
m_dismissListener.clear();
}
void BalloonManager::OnActivateMyPosition(gui::Element *)
void PinClickManager::OnActivateMyPosition()
{
m2::PointD const & pt = m_balloon->glbPivot();
m_positionListener(MercatorBounds::YToLat(pt.y),
MercatorBounds::XToLon(pt.x));
m_positionListener(0,0);
}
void BalloonManager::OnActivatePOI(gui::Element *, search::AddressInfo const & info)
void PinClickManager::OnActivatePOI(m2::PointD const & globalPoint, search::AddressInfo const & info)
{
m_poiListener(m_balloon->glbPivot(), info);
m_poiListener(globalPoint, info);
}
void BalloonManager::OnActivateAPI(gui::Element *, url_scheme::ResultPoint const & apiPoint)
void PinClickManager::OnActivateAPI(url_scheme::ResultPoint const & apiPoint)
{
m_apiListener(apiPoint.GetPoint());
}
void BalloonManager::OnActivateBookmark(gui::Element *, BookmarkAndCategory const & bmAndCat)
void PinClickManager::OnActivateBookmark(BookmarkAndCategory const & bmAndCat)
{
m_bookmarkListener(bmAndCat);
}
void PinClickManager::OnAdditonalLayer(size_t index)
{
m_additionalLayerListener(index);
}
void PinClickManager::OnDismiss()
{
m_dismissListener();
}

View file

@ -10,7 +10,6 @@
class Framework;
class BookmarkBalloon;
namespace location { class GpsInfo; }
namespace gui { class Element; }
namespace search { struct AddressInfo; }
@ -20,34 +19,24 @@ namespace url_scheme
class ResultPoint;
}
class BalloonManager
class PinClickManager
{
Framework & m_f;
shared_ptr<BookmarkBalloon> m_balloon;
bool m_updateForLocation;
void CreateBookmarkBalloon();
void OnPositionClicked(m2::PointD const & pt);
void OnActivateMyPosition(gui::Element *);
void OnActivatePOI(gui::Element *, search::AddressInfo const & info);
void OnActivateAPI(gui::Element *, url_scheme::ResultPoint const & apiPoint);
void OnActivateBookmark(gui::Element *, BookmarkAndCategory const & bmAndCat);
void Show(m2::PointD const & pt, string const & name, string const & type, bool needPadding);
void OnActivateMyPosition();
void OnActivatePOI(const m2::PointD & globalPoint, search::AddressInfo const & info);
void OnActivateAPI(url_scheme::ResultPoint const & apiPoint);
void OnActivateBookmark(BookmarkAndCategory const & bmAndCat);
void OnAdditonalLayer(size_t index);
void OnDismiss();
public:
BalloonManager(Framework & f);
PinClickManager(Framework & f);
void RenderPolicyCreated(graphics::EDensity density);
void LocationChanged(location::GpsInfo const & info);
void ScreenSizeChanged(int width, int height);
void ShowAddress(m2::PointD const & pt, search::AddressInfo const & info);
void ShowURLPoint(url_scheme::ResultPoint const & point, bool needPadding);
void ShowBookmark(BookmarkAndCategory bmAndCat);
void ShowAdditionalLayerBookmark(size_t index);
void OnClick(m2::PointD const & pxPoint, bool isLongTouch);
void Hide();
@ -56,15 +45,19 @@ private:
/// @name Platform dependent listeners to show special activities.
//@{
function<void (m2::PointD const &, search::AddressInfo const &)> m_poiListener;
function<void (BookmarkAndCategory const &)> m_bookmarkListener;
function<void (url_scheme::ApiPoint const &)> m_apiListener;
function<void (double, double)> m_positionListener;
function<void (BookmarkAndCategory const &)> m_bookmarkListener;
function<void (url_scheme::ApiPoint const &)> m_apiListener;
function<void (double, double)> m_positionListener;
function<void (size_t)> m_additionalLayerListener;
function<void (void)> m_dismissListener;
public:
template <class T> void ConnectPoiListener(T const & t) { m_poiListener = t; }
template <class T> void ConnectBookmarkListener(T const & t) { m_bookmarkListener = t; }
template <class T> void ConnectApiListener(T const & t) { m_apiListener = t; }
template <class T> void ConnectPositionListener(T const & t) { m_positionListener = t; }
template <class T> void ConnectPoiListener(T const & t) { m_poiListener = t; }
template <class T> void ConnectBookmarkListener(T const & t) { m_bookmarkListener = t; }
template <class T> void ConnectApiListener(T const & t) { m_apiListener = t; }
template <class T> void ConnectPositionListener(T const & t) { m_positionListener = t; }
template <class T> void ConnectAdditionalListener(T const & t) { m_additionalLayerListener = t; }
template <class T> void ConnectDismissListener(T const & t) { m_dismissListener = t; }
void ClearListeners();
//@}

View file

@ -458,7 +458,6 @@ void Framework::ShowBookmark(BookmarkAndCategory bnc)
StopLocationFollow();
// show ballon above
GetBalloonManager().ShowBookmark(bnc);
Bookmark const * bmk = m_bmManager.GetBmCategory(bnc.first)->GetBookmark(bnc.second);
double scale = bmk->GetScale();
@ -685,10 +684,7 @@ void Framework::OnSize(int w, int h)
if (m_renderPolicy)
{
m_informationDisplay.setDisplayRect(m2::RectI(0, 0, w, h));
m_renderPolicy->OnSize(w, h);
m_balloonManager.ScreenSizeChanged(w, h);
}
m_width = w;
@ -1221,6 +1217,8 @@ bool Framework::GetCurrentPosition(double & lat, double & lon) const
else return false;
}
#define DO_NOT_INCLUDE_IN_RELEASE
void Framework::ShowSearchResult(search::Result const & res)
{
#ifdef DO_NOT_INCLUDE_IN_RELEASE
@ -1233,7 +1231,7 @@ void Framework::ShowSearchResult(search::Result const & res)
for (size_t i = 0; i < searchRes.GetCount(); ++i)
{
search::Result const & tmpRes = searchRes.GetResult(i);
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(tmpRes.GetFeatureCenter(), tmpRes.GetString(), "placemark-orange"));
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(tmpRes.GetFeatureCenter(), tmpRes.GetString(), "api_pin"));
if (res == tmpRes)
resIndex = i;
}
@ -1270,14 +1268,6 @@ void Framework::ShowSearchResult(search::Result const & res)
StopLocationFollow();
ShowRectExVisibleScale(m_scales.GetRectForDrawScale(scale, center));
#ifdef DO_NOT_INCLUDE_IN_RELEASE
m_balloonManager.ShowAdditionalLayerBookmark(resIndex);
#else
search::AddressInfo info;
info.MakeFrom(res);
m_balloonManager.ShowAddress(center, info);
#endif
}
bool Framework::GetDistanceAndAzimut(m2::PointD const & point,
@ -1489,10 +1479,6 @@ bool Framework::ShowMapForURL(string const & url)
StopLocationFollow();
SetViewPortASync(rect);
// show balloon
if (result != NO_BALLOON)
m_balloonManager.ShowURLPoint(point, result == BALLOON_PADDING);
return true;
}
else

View file

@ -141,7 +141,7 @@ protected:
BenchmarkEngine * m_benchmarkEngine;
BookmarkManager m_bmManager;
BalloonManager m_balloonManager;
PinClickManager m_balloonManager;
void ClearAllCaches();
@ -449,7 +449,7 @@ public:
StringsBundle const & GetStringsBundle();
BalloonManager & GetBalloonManager() { return m_balloonManager; }
PinClickManager & GetBalloonManager() { return m_balloonManager; }
/// Checks, whether the country which contains
/// the specified point is loaded
@ -494,4 +494,6 @@ public:
guides::GuidesManager & GetGuidesManager() { return m_storage.GetGuideManager(); }
bool GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info) const;
//@}
BookmarkManager & GetBookmarkManager() { return m_bmManager; }
};

View file

@ -85,7 +85,7 @@ namespace qt
m_pScale(0)
{
// Initialize with some stubs for test.
BalloonManager & manager = GetBalloonManager();
PinClickManager & manager = GetBalloonManager();
manager.ConnectApiListener(&DummyAPI);
manager.ConnectBookmarkListener(&DummyBookmark);
manager.ConnectPoiListener(&DummyPOI);

View file

@ -146,6 +146,6 @@ namespace qt
m2::PointD m_taskPoint;
bool m_wasLongClick, m_isCleanSingleClick;
BalloonManager & GetBalloonManager() { return m_framework->GetBalloonManager(); }
PinClickManager & GetBalloonManager() { return m_framework->GetBalloonManager(); }
};
}