[android, ios] setup but pro and route builded callbacks

This commit is contained in:
ExMix 2014-10-08 15:14:00 +03:00 committed by Alex Zolotarev
parent f5d69850f4
commit ff911e6098
6 changed files with 125 additions and 61 deletions

View file

@ -786,11 +786,20 @@ extern "C"
jniEnv->CallVoidMethod(*obj.get(), methodId);
}
void CallRoutingErrorListener(shared_ptr<jobject> obj, string const & messageID, DialogOptions const & options)
void CallRoutingErrorListener(shared_ptr<jobject> obj, bool isSuccess, string const & messageID, bool openDownloader)
{
JNIEnv * jniEnv = jni::GetEnv();
const jmethodID methodId = jni::GetJavaMethodID(jniEnv, *obj.get(), "onRoutingError", "(Ljava/lang/String;)V");
jniEnv->CallVoidMethod(*obj.get(), methodId, jni::ToJavaString(jniEnv, messageID));
const jmethodID methodId = jni::GetJavaMethodID(jniEnv, *obj.get(), "onRoutingError", "(ZLjava/lang/String;Z)V");
ASSERT(jmethodID != nullptr, ());
jniEnv->CallVoidMethod(*obj.get(), methodId, isSuccess, jni::ToJavaString(jniEnv, messageID), openDownloader);
}
void CallBuyProListener(shared_ptr<jobject> obj)
{
JNIEnv * jniEnv = jni::GetEnv();
const jmethodID methodId = jni::GetJavaMethodID(jniEnv, *obj.get(), "onBuyPro", "()V");
ASSERT(jmethodID != nullptr, ());
jniEnv->CallVoidMethod(*obj.get(), methodId);
}
/// @name JNI EXPORTS
@ -1233,9 +1242,14 @@ extern "C"
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeAddRoutingListener(JNIEnv * env, jobject thiz, jobject listener)
Java_com_mapswithme_maps_Framework_nativeSetRoutingListener(JNIEnv * env, jobject thiz, jobject listener)
{
shared_ptr<jobject> sharedListener = jni::make_global_ref(listener);
frm()->SetShowDialogListener(bind(&CallRoutingErrorListener, sharedListener, _1, _2));
frm()->SetRouteBuildingListener(bind(&CallRoutingErrorListener, jni::make_global_ref(listener), _1, _2, _3));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeSetBuyProListener(JNIEnv * env, jobject thiz, jobject listener)
{
frm()->SetBuyProListener(bind(&CallBuyProListener, jni::make_global_ref(listener)));
}
}

View file

@ -33,7 +33,12 @@ public class Framework
public interface RoutingListener
{
void onRoutingError(String messageId);
void onRoutingError(boolean isSuccess, String message, boolean openDownloader);
}
public interface ButProListener
{
void onBuyPro();
}
// this class is just bridge between Java and C++ worlds, we must not create it
@ -142,7 +147,8 @@ public class Framework
public native static LocationState.RoutingInfo nativeGetRouteFollowingInfo();
public native static void nativeAddRoutingListener(RoutingListener listener);
public native static void nativeSetRoutingListener(RoutingListener listener);
public native static void nativeSetBuyProListener(ButProListener listener);
//@}
public native static String nativeGetCountryNameIfAbsent(double lat, double lon);

View file

@ -38,6 +38,7 @@ import com.mapswithme.maps.Ads.AdsManager;
import com.mapswithme.maps.Ads.MenuAd;
import com.mapswithme.maps.Framework.OnBalloonListener;
import com.mapswithme.maps.Framework.RoutingListener;
import com.mapswithme.maps.Framework.ButProListener;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.api.ParsedMmwRequest;
import com.mapswithme.maps.background.WorkerService;
@ -74,7 +75,7 @@ import java.util.Stack;
public class MWMActivity extends NvEventQueueActivity
implements LocationService.LocationListener, OnBalloonListener, OnVisibilityChangedListener,
OnClickListener, RoutingListener
OnClickListener, RoutingListener, ButProListener
{
public static final String EXTRA_TASK = "map_task";
private final static String TAG = "MWMActivity";
@ -724,7 +725,8 @@ public class MWMActivity extends NvEventQueueActivity
setUpInfoBox();
setUpRoutingBox();
Framework.nativeAddRoutingListener(this);
Framework.nativeSetRoutingListener(this);
Framework.nativeSetBuyProListener(this);
Framework.nativeConnectBalloonListeners(this);
final Intent intent = getIntent();
@ -1413,29 +1415,8 @@ public class MWMActivity extends NvEventQueueActivity
showRoutingDisclaimer();
return;
}
if (LocationState.INSTANCE.getLocationStateMode() < LocationState.NOT_FOLLOW)
{
Toast.makeText(this, R.string.unknown_current_position, Toast.LENGTH_LONG).show();
return;
}
Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
alphaAnimation.setFillBefore(true);
alphaAnimation.setFillAfter(true);
alphaAnimation.setDuration(VERT_TOOLBAR_ANIM_DURATION);
mRlRoutingBox.startAnimation(alphaAnimation);
mRlRoutingBox.setVisibility(View.VISIBLE);
mRlRoutingBox.bringToFront();
mInfoView.setState(State.HIDDEN);
Framework.nativeBuildRoute(mInfoView.getMapObject().getLat(), mInfoView.getMapObject().getLon());
if (mIsLocationLocked)
{
final LocationState.RoutingInfo info = Framework.nativeGetRouteFollowingInfo();
if (info != null)
mTvRoutingDistance.setText(info.mDistToTarget + info.mUnits);
}
}
private void showRoutingDisclaimer()
@ -1517,27 +1498,62 @@ public class MWMActivity extends NvEventQueueActivity
}
@Override
public void onRoutingError(final String messageId)
public void onRoutingError(final boolean isSuccess, final String message, boolean openDownloader)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
new AlertDialog.Builder(MWMActivity.this)
.setMessage(messageId)
.setCancelable(true)
.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
if (isSuccess)
{
Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
alphaAnimation.setFillBefore(true);
alphaAnimation.setFillAfter(true);
alphaAnimation.setDuration(VERT_TOOLBAR_ANIM_DURATION);
mRlRoutingBox.startAnimation(alphaAnimation);
mRlRoutingBox.setVisibility(View.VISIBLE);
mRlRoutingBox.bringToFront();
mInfoView.setState(State.HIDDEN);
if (mIsLocationLocked)
{
final LocationState.RoutingInfo info = Framework.nativeGetRouteFollowingInfo();
if (info != null)
mTvRoutingDistance.setText(info.mDistToTarget + info.mUnits);
}
}
else
{
/// if openDownloader == true than we need show dialog with 2 button. On positive button - open downloader
new AlertDialog.Builder(MWMActivity.this)
.setMessage(message)
.setCancelable(true)
.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener()
{
closeRouting();
dialog.dismiss();
}
})
.create()
.show();
@Override
public void onClick(DialogInterface dialog, int which)
{
closeRouting();
dialog.dismiss();
}
})
.create()
.show();
}
}
});
}
public void onBuyPro()
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
showProVersionBanner(getString(R.string.routing_failed_buy_pro));
}
});
}

View file

@ -135,6 +135,14 @@ public class MWMApplication extends android.app.Application implements MapStorag
nativeAddLocalization("my_position", getString(R.string.my_position));
nativeAddLocalization("routes", getString(R.string.routes));
nativeAddLocalization("routing_failed_unknown_my_position", getString(R.string.routing_failed_unknown_my_position));
nativeAddLocalization("routing_failed_has_no_routing_file", getString(R.string.routing_failed_has_no_routing_file));
nativeAddLocalization("routing_failed_start_point_not_found", getString(R.string.routing_failed_start_point_not_found));
nativeAddLocalization("routing_failed_dst_point_not_found", getString(R.string.routing_failed_dst_point_not_found));
nativeAddLocalization("routing_failed_cross_mwm_building", getString(R.string.routing_failed_cross_mwm_building));
nativeAddLocalization("routing_failed_route_not_found", getString(R.string.routing_failed_route_not_found));
nativeAddLocalization("routing_failed_internal_error", getString(R.string.routing_failed_internal_error));
// init BookmarkManager (automatically loads bookmarks)
if (hasBookmarks())

View file

@ -597,9 +597,25 @@
f.Invalidate();
f.LoadBookmarks();
f.SetShowDialogListener([&](string const & messageID, DialogOptions const & options)
f.SetRouteBuildingListener([&](bool isSuccess, string const & message, bool openDownloader)
{
[self showDialogWithMessageID:messageID andOptions:options];
if (isSuccess)
{
// [placePage setState:PlacePageStateHidden animated:YES withCallback:YES];
// [self performAfterDelay:0.3 block:^{
// [self.routeView setVisible:YES animated:YES];
// }];
}
else
{
/// if openDownloader == true than we need show dialog with 2 button. On positive button - open downloader
[self showDialogWithMessageID:message];
}
});
f.SetBuyProListener([&]()
{
[self showBuyProDialog];
});
}
@ -608,9 +624,16 @@
}
#pragma mark - ShowDialog callback
- (void)showDialogWithMessageID:(string const &)messageID andOptions:(DialogOptions const &)options
- (void)showDialogWithMessageID:(string const &)message
{
///@TODO for goga
///@TODO for goga.
[[[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:message.c_str()] message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil] show];
}
- (void)showBuyProDialog
{
///@TODO for goga. Show buy pro dialog with text [routing_failed_buy_pro]
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"routing_failed_buy_pro", nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil] show];
}
#pragma mark - Getters
@ -773,18 +796,7 @@
- (void)placePageViewDidStartRouting:(PlacePageView *)placePage
{
if ([MapsAppDelegate theApp].m_locationManager.lastLocation)
{
GetFramework().BuildRoute([placePage pinPoint]);
[placePage setState:PlacePageStateHidden animated:YES withCallback:YES];
[self performAfterDelay:0.3 block:^{
[self.routeView setVisible:YES animated:YES];
}];
}
else
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"unknown_current_position", nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil] show];
}
GetFramework().BuildRoute([placePage pinPoint]);
}
- (void)placePageView:(PlacePageView *)placePage willShareText:(NSString *)text point:(m2::PointD)point

View file

@ -43,6 +43,14 @@ void InitLocalizedStrings()
f.AddString("my_places", [NSLocalizedString(@"my_places", nil) UTF8String]);
f.AddString("my_position", [NSLocalizedString(@"my_position", nil) UTF8String]);
f.AddString("routes", [NSLocalizedString(@"routes", nil) UTF8String]);
f.AddString("routing_failed_unknown_my_position", [NSLocalizedString(@"routing_failed_unknown_my_position", nil) UTF8String]);
f.AddString("routing_failed_has_no_routing_file", [NSLocalizedString(@"routing_failed_has_no_routing_file", nil) UTF8String]);
f.AddString("routing_failed_start_point_not_found", [NSLocalizedString(@"routing_failed_start_point_not_found", nil) UTF8String]);
f.AddString("routing_failed_dst_point_not_found", [NSLocalizedString(@"routing_failed_dst_point_not_found", nil) UTF8String]);
f.AddString("routing_failed_cross_mwm_building", [NSLocalizedString(@"routing_failed_cross_mwm_building", nil) UTF8String]);
f.AddString("routing_failed_route_not_found", [NSLocalizedString(@"routing_failed_route_not_found", nil) UTF8String]);
f.AddString("routing_failed_internal_error", [NSLocalizedString(@"routing_failed_internal_error", nil) UTF8String]);
}
@interface MapsAppDelegate()