Incapsulate balloon activating in Framework::ShowMapForURL.

This commit is contained in:
vng 2013-08-21 18:41:40 +03:00 committed by Alex Zolotarev
parent 2f6acb337e
commit 457c2eec01
8 changed files with 81 additions and 75 deletions

View file

@ -583,18 +583,12 @@ namespace android
return m_work.Storage().IsDownloadInProgress();
}
bool Framework::SetViewportByUrl(string const & url, bool needPadding)
bool Framework::ShowMapForURL(string const & url)
{
/// @todo this is weird hack, we should reconsider Android lifecycle handling design
m_doLoadState = false;
url_scheme::ResultPoint point;
if (m_work.SetViewportByURL(url, point))
{
GetBalloonManager().ShowURLPoint(point, needPadding);
return true;
}
return false;
return m_work.ShowMapForURL(url);
}
void Framework::DeactivatePopup()

View file

@ -125,7 +125,7 @@ namespace android
bool IsDownloadingActive();
bool SetViewportByUrl(string const & url, bool needPadding);
bool ShowMapForURL(string const & url);
void DeactivatePopup();

View file

@ -141,9 +141,8 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_MWMActivity_setViewPortByUrl(JNIEnv * env, jobject thiz,
jstring url, jboolean needPadding)
Java_com_mapswithme_maps_MWMActivity_showMapForUrl(JNIEnv * env, jobject thiz, jstring url)
{
return g_framework->SetViewportByUrl(jni::ToNativeString(env, url), needPadding);
return g_framework->ShowMapForURL(jni::ToNativeString(env, url));
}
} // extern "C"

View file

@ -611,7 +611,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
@Override
public boolean processIntent(Intent intent)
{
mMapTaskToForward = new OpenUrlTask(intent.getData().toString(), false);
mMapTaskToForward = new OpenUrlTask(intent.getData().toString());
return true;
}
}
@ -627,7 +627,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
@Override
public boolean processIntent(Intent intent)
{
mMapTaskToForward = new OpenUrlTask(intent.getData().toString(), false);
mMapTaskToForward = new OpenUrlTask(intent.getData().toString());
return true;
}
}
@ -654,7 +654,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
if (data != null)
{
final String ge0Url = "ge0:/" + data.getPath();
mMapTaskToForward = new OpenUrlTask(ge0Url, false);
mMapTaskToForward = new OpenUrlTask(ge0Url);
return true;
}
else
@ -684,7 +684,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
Statistics.INSTANCE.trackApiCall(request);
getMwmApplication().getAppStateManager().transitionTo(SuppotedState.API_REQUEST);
mMapTaskToForward = new OpenUrlTask(apiUrl, true);
mMapTaskToForward = new OpenUrlTask(apiUrl);
return true;
}
return false;
@ -714,7 +714,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
final Matcher m = p.matcher(data.getQueryParameter("q"));
final String ll = m.find() ? m.group() : "0,0";
mMapTaskToForward = new OpenUrlTask("geo://" + ll, false);
mMapTaskToForward = new OpenUrlTask("geo://" + ll);
return true;
}
return false;

View file

@ -1049,21 +1049,17 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
{
private static final long serialVersionUID = 1L;
private final String mUrl;
private final boolean mPadding;
/// @param[in] padding Pass true only for URL's with pins on map (API), otherwise - false.
public OpenUrlTask(String url, boolean padding)
public OpenUrlTask(String url)
{
Utils.checkNotNull(url);
mUrl = url;
mPadding = padding;
}
@Override
public boolean run(MWMActivity target)
{
return target.setViewPortByUrl(mUrl, mPadding);
return target.showMapForUrl(mUrl);
}
}
@ -1151,5 +1147,5 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
private native boolean nativeIsInChina(double lat, double lon);
public native boolean setViewPortByUrl(String url, boolean padding);
public native boolean showMapForUrl(String url);
}

View file

@ -63,19 +63,20 @@ void InitLocalizedStrings()
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIPasteboard * pasteboard = [UIPasteboard generalPasteboard];
if (GetPlatform().IsPro() && !m_didOpenedWithUrl)
{
UIPasteboard * pasteboard = [UIPasteboard generalPasteboard];
if (pasteboard.string.length)
{
url_scheme::ResultPoint point;
if (GetFramework().SetViewportByURL([pasteboard.string UTF8String], point))
if (GetFramework().ShowMapForURL([pasteboard.string UTF8String]))
{
[self showParsedBookmarkOnMap:point withPadding:NO];
[self showMap];
pasteboard.string = @"";
}
}
}
m_didOpenedWithUrl = NO;
}
@ -189,33 +190,28 @@ void InitLocalizedStrings()
// geo scheme support, see http://tools.ietf.org/html/rfc5870
if ([scheme isEqualToString:@"geo"] || [scheme isEqualToString:@"ge0"])
{
url_scheme::ResultPoint point;
if (f.SetViewportByURL([url.absoluteString UTF8String], point))
if (f.ShowMapForURL([url.absoluteString UTF8String]))
{
[self showParsedBookmarkOnMap:point withPadding:NO];
m_didOpenedWithUrl = YES;
if ([scheme isEqualToString:@"geo"])
[[Statistics instance] logEvent:@"geo Import"];
if ([scheme isEqualToString:@"ge0"])
[[Statistics instance] logEvent:@"ge0(zero) Import"];
[self showMap];
return YES;
}
}
if ([scheme isEqualToString:@"mapswithme"] || [scheme isEqualToString:@"mwm"])
{
url_scheme::ResultPoint apiPoint;
if (f.SetViewportByURL([url.absoluteString UTF8String], apiPoint));
if (f.ShowMapForURL([url.absoluteString UTF8String]));
{
m_didOpenedWithUrl = YES;
[[Statistics instance] logApiUsage:sourceApplication];
f.GetBalloonManager().Hide();
if (f.GetMapApiPoints().size() == 1)
[self showParsedBookmarkOnMap:apiPoint withPadding:YES];
else
[self showMap];
[self showMap];
[m_mapViewController prepareForApi];
return YES;
}
@ -223,7 +219,7 @@ void InitLocalizedStrings()
if ([scheme isEqualToString:@"file"])
{
if (!GetFramework().AddBookmarksFile([[url relativePath] UTF8String]))
if (!f.AddBookmarksFile([[url relativePath] UTF8String]))
{
[self showLoadFileAlertIsSuccessful:NO];
return NO;
@ -271,12 +267,6 @@ void InitLocalizedStrings()
[m_navController setNavigationBarHidden:YES animated:YES];
}
-(void) showParsedBookmarkOnMap:(url_scheme::ResultPoint const &) point withPadding:(BOOL) padding
{
[self showMap];
GetFramework().GetBalloonManager().ShowURLPoint(point, padding == YES);
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([viewController isMemberOfClass:NSClassFromString(@"MapViewController")] && ![m_mapViewController shouldShowNavBar])

View file

@ -1376,65 +1376,93 @@ void Framework::AddBookmarkAndSetViewport(Bookmark & bm, m2::RectD const & viewP
}
*/
void Framework::CheckParams(url_scheme::ResultPoint & point) const
namespace
{
void CheckPointName(url_scheme::ResultPoint & point, StringsBundle const & bundle)
{
string & name = point.GetName();
if (name.empty())
name = m_stringsBundle.GetString("dropped_pin");
name = bundle.GetString("dropped_pin");
}
bool Framework::SetViewportByURL(string const & url, url_scheme::ResultPoint & point)
{
if (strings::StartsWith(url, "geo"))
{
using namespace url_scheme;
}
bool Framework::ShowMapForURL(string const & url)
{
url_scheme::ResultPoint point;
m2::RectD rect;
enum ResultT { FAILED, NO_BALLOON, BALLOON, BALLOON_PADDING };
ResultT result = FAILED;
// always hide current balloon here
m_balloonManager.Hide();
using namespace url_scheme;
using namespace strings;
if (StartsWith(url, "geo"))
{
Info info;
ParseGeoURL(url, info);
if (info.IsValid())
{
StopLocationFollow();
point.MakeFrom(info.m_lat, info.m_lon);
CheckParams(point);
CheckPointName(point, m_stringsBundle);
SetViewPortASync(m_scales.GetRectForDrawScale(info.m_zoom, point.GetOrg()));
return true;
rect = m_scales.GetRectForDrawScale(info.m_zoom, point.GetOrg());
result = BALLOON;
}
}
else if (strings::StartsWith(url, "ge0"))
else if (StartsWith(url, "ge0"))
{
StopLocationFollow();
url_scheme::Ge0Parser parser;
Ge0Parser parser;
double zoom;
url_scheme::ApiPoint pt;
ApiPoint pt;
if (parser.Parse(url, pt, zoom))
{
point.MakeFrom(pt);
CheckParams(point);
CheckPointName(point, m_stringsBundle);
SetViewPortASync(m_scales.GetRectForDrawScale(zoom, point.GetOrg()));
return true;
rect = m_scales.GetRectForDrawScale(zoom, point.GetOrg());
result = BALLOON;
}
}
else if (strings::StartsWith(url, "mapswithme://") || strings::StartsWith(url, "mwm://"))
else if (StartsWith(url, "mapswithme://") || StartsWith(url, "mwm://"))
{
if (m_ParsedMapApi.SetUriAndParse(url))
{
StopLocationFollow();
SetViewPortASync(GetMapApiViewportRect());
rect = GetMapApiViewportRect();
if (!m_ParsedMapApi.GetPoints().empty())
{
point.MakeFrom(m_ParsedMapApi.GetPoints().front());
return true;
result = BALLOON_PADDING;
}
else
{
// show world rect without balloon
result = NO_BALLOON;
}
}
}
return false;
if (result != FAILED)
{
// set viewport and stop follow mode if any
StopLocationFollow();
SetViewPortASync(rect);
// show balloon
if (result != NO_BALLOON)
m_balloonManager.ShowURLPoint(point, result == BALLOON_PADDING);
return true;
}
else
return false;
}
void Framework::SetViewPortASync(m2::RectD const & r)

View file

@ -313,9 +313,8 @@ public:
m2::PointD GetViewportCenter() const;
void SetViewportCenter(m2::PointD const & pt);
/// @param[out] point is a point in url, where we need to show balloon
void CheckParams(url_scheme::ResultPoint & point) const;
bool SetViewportByURL(string const & url, url_scheme::ResultPoint & point);
/// Set correct viewport, parse API, show balloon.
bool ShowMapForURL(string const & url);
bool NeedRedraw() const;
void SetNeedRedraw(bool flag);