Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorDmitry Kunin <dkunin@mapswith.me>2013-05-29 20:59:33 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:55:32 +0300
commit50393615dde78a45d83ce2e6878a96da07c85928 (patch)
tree1e675de519dd87add77b0195470b97fb5910dd41 /api
parentc50066b02e097fdfc2e0492f207b3f058381936a (diff)
[android] Refactored to PendingIntent.
This is more flexible and reliable approach.
Diffstat (limited to 'api')
-rw-r--r--api/android/lib/src/com/mapswithme/maps/api/Const.java13
-rw-r--r--api/android/lib/src/com/mapswithme/maps/api/MWMResponse.java21
-rw-r--r--api/android/lib/src/com/mapswithme/maps/api/MWMResponseHandler.java9
-rw-r--r--api/android/lib/src/com/mapswithme/maps/api/MWMResponseReciever.java28
-rw-r--r--api/android/lib/src/com/mapswithme/maps/api/MapsWithMeApi.java27
5 files changed, 19 insertions, 79 deletions
diff --git a/api/android/lib/src/com/mapswithme/maps/api/Const.java b/api/android/lib/src/com/mapswithme/maps/api/Const.java
index b9f6195fc4..768a2dcb8d 100644
--- a/api/android/lib/src/com/mapswithme/maps/api/Const.java
+++ b/api/android/lib/src/com/mapswithme/maps/api/Const.java
@@ -3,26 +3,19 @@ package com.mapswithme.maps.api;
public class Const
{
- /* Codes */
- // status
- public static final int STATUS_OK = 0;
- public static final int STATUS_CANCEL = 1;
-
/* Request extras */
static final String AUTHORITY = "com.mapswithme.maps.api";
public static final String EXTRA_URL = AUTHORITY + ".url";
public static final String EXTRA_TITLE = AUTHORITY + ".title";
- public static final String EXTRA_CALLMEBACK_MODE = AUTHORITY + ".callmeback_mode";
- public static final String EXTRA_CALLBACK_ACTION = AUTHORITY + ".callback";
public static final String EXTRA_API_VERSION = AUTHORITY + ".version";
public static final String EXTRA_CALLER_APP_INFO = AUTHORITY + ".caller_app_info";
+ public static final String EXTRA_HAS_PENDING_INTENT = AUTHORITY + ".has_pen_intent";
+ public static final String EXTRA_CALLER_PENDING_INTENT = AUTHORITY + ".pending_intent";
/* Response extras */
- public static final String EXTRA_MWM_RESPONSE_STATUS = AUTHORITY + ".status";
/* Point part-by-part*/
- public static final String EXTRA_MWM_RESPONSE_HAS_POINT = AUTHORITY + ".has_point";
public static final String EXTRA_MWM_RESPONSE_POINT_NAME = AUTHORITY + ".point_name";
public static final String EXTRA_MWM_RESPONSE_POINT_LAT = AUTHORITY + ".point_lat";
public static final String EXTRA_MWM_RESPONSE_POINT_LON = AUTHORITY + ".point_lon";
@@ -31,7 +24,7 @@ public class Const
static final int API_VERSION = 1;
static final String CALLBACK_PREFIX = "mapswithme.client.";
- static final String ACTION_MWM_REQUEST = AUTHORITY + ".request";
+ public static final String ACTION_MWM_REQUEST = AUTHORITY + ".request";
private Const() {}
}
diff --git a/api/android/lib/src/com/mapswithme/maps/api/MWMResponse.java b/api/android/lib/src/com/mapswithme/maps/api/MWMResponse.java
index 3fe8410f61..741faeae0f 100644
--- a/api/android/lib/src/com/mapswithme/maps/api/MWMResponse.java
+++ b/api/android/lib/src/com/mapswithme/maps/api/MWMResponse.java
@@ -6,35 +6,28 @@ import android.content.Intent;
// TODO add javadoc for public interface
public class MWMResponse
{
- private int mStatus;
private MWMPoint mPoint;
- public boolean isCanceled() { return Const.STATUS_CANCEL == mStatus; }
- public boolean isSuccessful() { return Const.STATUS_OK == mStatus; }
-
public MWMPoint getPoint() { return mPoint; }
public boolean hasPoint() { return mPoint != null; }
@Override
public String toString()
{
- return "MWMResponse [mStatus=" + mStatus + ", mSelectedPoint=" + mPoint + "]";
+ return "MWMResponse [mSelectedPoint=" + mPoint + "]";
}
static MWMResponse extractFromIntent(Context context, Intent intent)
{
final MWMResponse response = new MWMResponse();
// parse status
- response.mStatus = intent.getIntExtra(Const.EXTRA_MWM_RESPONSE_STATUS, Const.STATUS_OK);
// parse point
- if (intent.getBooleanExtra(Const.EXTRA_MWM_RESPONSE_HAS_POINT, false))
- {
- final double lat = intent.getDoubleExtra(Const.EXTRA_MWM_RESPONSE_POINT_LAT, 0);
- final double lon = intent.getDoubleExtra(Const.EXTRA_MWM_RESPONSE_POINT_LON, 0);
- final String name = intent.getStringExtra(Const.EXTRA_MWM_RESPONSE_POINT_NAME);
- final String id = intent.getStringExtra(Const.EXTRA_MWM_RESPONSE_POINT_ID);
- response.mPoint = new MWMPoint(lat, lon, name, id);
- }
+ final double lat = intent.getDoubleExtra(Const.EXTRA_MWM_RESPONSE_POINT_LAT, 0);
+ final double lon = intent.getDoubleExtra(Const.EXTRA_MWM_RESPONSE_POINT_LON, 0);
+ final String name = intent.getStringExtra(Const.EXTRA_MWM_RESPONSE_POINT_NAME);
+ final String id = intent.getStringExtra(Const.EXTRA_MWM_RESPONSE_POINT_ID);
+ response.mPoint = new MWMPoint(lat, lon, name, id);
+
return response;
}
diff --git a/api/android/lib/src/com/mapswithme/maps/api/MWMResponseHandler.java b/api/android/lib/src/com/mapswithme/maps/api/MWMResponseHandler.java
deleted file mode 100644
index e938619705..0000000000
--- a/api/android/lib/src/com/mapswithme/maps/api/MWMResponseHandler.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.mapswithme.maps.api;
-
-import android.content.Context;
-
-// TODO add javadoc
-public interface MWMResponseHandler
-{
- public void onResponse(Context context, MWMResponse response);
-}
diff --git a/api/android/lib/src/com/mapswithme/maps/api/MWMResponseReciever.java b/api/android/lib/src/com/mapswithme/maps/api/MWMResponseReciever.java
deleted file mode 100644
index 47cebd1cd8..0000000000
--- a/api/android/lib/src/com/mapswithme/maps/api/MWMResponseReciever.java
+++ /dev/null
@@ -1,28 +0,0 @@
-
-package com.mapswithme.maps.api;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-
-// TODO add javadoc with example
-public final class MWMResponseReciever extends BroadcastReceiver
-{
- // I believe this it not the best approach
- // But we leave it to keep things simple
- static MWMResponseHandler sResponseHandler;
-
- @Override
- final public void onReceive(Context context, Intent intent)
- {
- if (sResponseHandler != null
- && MapsWithMeApi.getCallbackAction(context).equals(intent.getAction()))
- {
- sResponseHandler.onResponse(context, MWMResponse.extractFromIntent(context, intent));
- // clean up handler to avoid context-leak
- sResponseHandler = null;
- }
- }
-
-}
diff --git a/api/android/lib/src/com/mapswithme/maps/api/MapsWithMeApi.java b/api/android/lib/src/com/mapswithme/maps/api/MapsWithMeApi.java
index 7f8e680718..d3ac6d596d 100644
--- a/api/android/lib/src/com/mapswithme/maps/api/MapsWithMeApi.java
+++ b/api/android/lib/src/com/mapswithme/maps/api/MapsWithMeApi.java
@@ -2,6 +2,7 @@
package com.mapswithme.maps.api;
import android.app.Activity;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -21,7 +22,7 @@ public final class MapsWithMeApi
public static void showPointOnMap(Activity caller, double lat, double lon, String name, String id)
{
- showPointsOnMap(caller, (String)null, (MWMResponseHandler)null, new MWMPoint(lat, lon, name));
+ showPointsOnMap(caller, (String)null, (PendingIntent)null, new MWMPoint(lat, lon, name));
}
public static void showPointsOnMap(Activity caller, String title, MWMPoint... points)
@@ -29,29 +30,20 @@ public final class MapsWithMeApi
showPointsOnMap(caller, title, null, points);
}
- public static void showPointsOnMap(Activity caller, String title, MWMResponseHandler responseHandler, MWMPoint... points)
+ public static void showPointsOnMap(Activity caller, String title, PendingIntent pendingIntent, MWMPoint... points)
{
final Intent mwmIntent = new Intent(Const.ACTION_MWM_REQUEST);
- mwmIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-
+
mwmIntent.putExtra(Const.EXTRA_URL, createMwmUrl(caller, title, points).toString());
mwmIntent.putExtra(Const.EXTRA_TITLE, title);
- mwmIntent.putExtra(Const.EXTRA_CALLMEBACK_MODE, responseHandler != null);
+
+ final boolean hasIntent = pendingIntent != null;
+ mwmIntent.putExtra(Const.EXTRA_HAS_PENDING_INTENT, hasIntent);
+ if (hasIntent)
+ mwmIntent.putExtra(Const.EXTRA_CALLER_PENDING_INTENT, pendingIntent);
addCommonExtras(caller, mwmIntent);
- MWMResponseReciever.sResponseHandler = responseHandler;
- if (responseHandler != null)
- {
- // detect if it is registered
- // throw if not
- final Intent callbackIntentStub = new Intent(getCallbackAction(caller));
- final boolean recieverEnabled = caller.getPackageManager().queryBroadcastReceivers(callbackIntentStub, 0).size() > 0;
- if (!recieverEnabled)
- throw new IllegalStateException(String.format(
- "BroadcastReciever with intent-filter for action \"%s\" must be added to manifest.", getCallbackAction(caller)));
- }
-
if (isMapsWithMeInstalled(caller))
{
// Match activity for intent
@@ -111,7 +103,6 @@ public final class MapsWithMeApi
{
intent.putExtra(Const.EXTRA_CALLER_APP_INFO, context.getApplicationInfo());
intent.putExtra(Const.EXTRA_API_VERSION, Const.API_VERSION);
- intent.putExtra(Const.EXTRA_CALLBACK_ACTION, getCallbackAction(context));
return intent;
}