[android] Back url support for deeplink

This commit is contained in:
Александр Зацепин 2019-12-26 18:26:33 +03:00 committed by yoksnod
parent a1618769ad
commit e8efeb3a07
5 changed files with 123 additions and 13 deletions

View file

@ -7,9 +7,11 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
@ -174,6 +176,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
public static final String EXTRA_TASK = "map_task";
public static final String EXTRA_LAUNCH_BY_DEEP_LINK = "launch_by_deep_link";
public static final String EXTRA_BACK_URL = "back_url";
private static final String EXTRA_CONSUMED = "mwm.extra.intent.processed";
private static final String[] DOCKED_FRAGMENTS = { SearchFragment.class.getName(),
@ -2444,6 +2447,38 @@ public class MwmActivity extends BaseMwmFragmentActivity
IntroductionDialogFragment.show(getSupportFragmentManager(), deepLink, factory);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_DOWN:
Statistics.INSTANCE.trackEvent(Statistics.EventName.ZOOM_OUT);
MapFragment.nativeScaleMinus();
return true;
case KeyEvent.KEYCODE_DPAD_UP:
Statistics.INSTANCE.trackEvent(Statistics.EventName.ZOOM_IN);
MapFragment.nativeScalePlus();
return true;
case KeyEvent.KEYCODE_ESCAPE:
Intent currIntent = getIntent();
if (currIntent == null || !currIntent.hasExtra(EXTRA_BACK_URL))
return super.onKeyUp(keyCode, event);
String backUrl = currIntent.getStringExtra(EXTRA_BACK_URL);
if (TextUtils.isEmpty(backUrl))
return super.onKeyUp(keyCode, event);
Uri back_uri = Uri.parse(backUrl);
if (back_uri == null)
return super.onKeyUp(keyCode, event);
return Utils.openUri(this, back_uri);
default:
return super.onKeyUp(keyCode, event);
}
}
private class CurrentPositionClickListener implements OnClickListener
{
@Override

View file

@ -0,0 +1,49 @@
package com.mapswithme.maps.intent;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.mapswithme.maps.MwmActivity;
public class BackUrlMapTaskWrapper implements MapTask
{
private static final String BACK_URL_PARAMETER = "back_url";
private static final long serialVersionUID = 5078514919824594790L;
@NonNull
private final MapTask mMapTask;
@NonNull
private final String mUrl;
private BackUrlMapTaskWrapper(@NonNull MapTask mapTask, @NonNull String url)
{
mMapTask = mapTask;
mUrl = url;
}
@Override
public boolean run(@NonNull MwmActivity target)
{
final boolean success = mMapTask.run(target);
Uri uri = Uri.parse(mUrl);
String backUrl = uri.getQueryParameter(BACK_URL_PARAMETER);
if (TextUtils.isEmpty(backUrl))
return success;
Intent intent = target.getIntent();
if (intent == null)
return success;
intent.putExtra(MwmActivity.EXTRA_BACK_URL, backUrl);
return success;
}
@NonNull
static MapTask wrap(@NonNull MapTask task, @NonNull String url)
{
return new BackUrlMapTaskWrapper(task, url);
}
}

View file

@ -3,12 +3,12 @@ package com.mapswithme.maps.intent;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import com.crashlytics.android.Crashlytics;
import com.mapswithme.maps.DownloadResourcesLegacyActivity;
import com.mapswithme.maps.Framework;
@ -188,7 +188,7 @@ public class Factory
@Override
MapTask createMapTask(@NonNull String uri)
{
return new OpenUrlTask(uri);
return BackUrlMapTaskWrapper.wrap(new OpenUrlTask(uri), uri);
}
}
@ -406,7 +406,7 @@ public class Factory
Uri coreUri = uri.buildUpon()
.scheme(SCHEME_CORE)
.authority("").build();
return new OpenUrlTask(coreUri.toString());
return BackUrlMapTaskWrapper.wrap(new OpenUrlTask(coreUri.toString()), url);
}
@Nullable

View file

@ -14,14 +14,6 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.core.app.NavUtils;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@ -31,6 +23,14 @@ import android.view.View;
import android.view.Window;
import android.widget.Toast;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NavUtils;
import androidx.fragment.app.Fragment;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
@ -246,6 +246,29 @@ public class Utils
}
}
public static boolean openUri(@NonNull Context context, @NonNull Uri uri)
{
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
try
{
context.startActivity(intent);
return true;
}
catch (ActivityNotFoundException e)
{
CrashlyticsUtils.logException(e);
return false;
}
catch (AndroidRuntimeException e)
{
CrashlyticsUtils.logException(e);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return false;
}
}
private static boolean isHttpOrHttpsScheme(@NonNull String url)
{
return url.startsWith("http://") || url.startsWith("https://");

View file

@ -324,7 +324,10 @@ bool ParsedMapApi::RouteKeyValue(string const & key, string const & value, vecto
{
using namespace route;
if (pattern.empty() || key != pattern.front())
if (pattern.empty())
return true;
if (key != pattern.front())
return false;
if (key == kSourceLatLon || key == kDestLatLon)