[android, api] Download MWM dialog.
BIN
api/android/lib/res/drawable-hdpi/button.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
api/android/lib/res/drawable-hdpi/button_pressed.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
api/android/lib/res/drawable-hdpi/logo.png
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
api/android/lib/res/drawable-ldpi/button.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
api/android/lib/res/drawable-ldpi/button_pressed.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
api/android/lib/res/drawable-ldpi/logo.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
api/android/lib/res/drawable-mdpi/button.png
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
api/android/lib/res/drawable-mdpi/button_pressed.png
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
api/android/lib/res/drawable-mdpi/logo.png
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
api/android/lib/res/drawable-xhdpi/button.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
api/android/lib/res/drawable-xhdpi/button_pressed.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
api/android/lib/res/drawable-xhdpi/logo.png
Normal file
After Width: | Height: | Size: 145 KiB |
BIN
api/android/lib/res/drawable-xxhdpi/button.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
api/android/lib/res/drawable-xxhdpi/button_pressed.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
api/android/lib/res/drawable-xxhdpi/logo.png
Normal file
After Width: | Height: | Size: 328 KiB |
5
api/android/lib/res/drawable/background_pattern.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:src="@drawable/pattern"
|
||||
android:tileMode="repeat"
|
||||
android:dither="true"/>
|
7
api/android/lib/res/drawable/download_btn_selector.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/button"/>
|
||||
|
||||
</selector>
|
BIN
api/android/lib/res/drawable/pattern.png
Normal file
After Width: | Height: | Size: 66 KiB |
50
api/android/lib/res/layout/dlg_install_mwm.xml
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/background_pattern"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/margin_mid"
|
||||
android:paddingRight="@dimen/margin_mid" >
|
||||
|
||||
<TextView
|
||||
style="@android:style/TextAppearance.Medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:gravity="center"
|
||||
android:text="@string/dlg_title"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
<TextView
|
||||
style="@android:style/TextAppearance.Large"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:gravity="center"
|
||||
android:text="@string/download_please"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_mid"
|
||||
android:src="@drawable/logo" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/download"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_mid"
|
||||
android:layout_marginTop="@dimen/margin_mid"
|
||||
android:background="@null"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/download_btn_selector"/>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
5
api/android/lib/res/values/dimen.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="margin_large">24dp</dimen>
|
||||
<dimen name="margin_mid">12dp</dimen>
|
||||
</resources>
|
7
api/android/lib/res/values/strings.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="downolad_url">http://www.mapswithme.com/get/</string>
|
||||
<string name="mapswithme">MapsWithMe</string>
|
||||
<string name="dlg_title">We have partnered with <b><font fgcolor="#ff70B82A">MapsWithMe</font></b> to provide you with offline maps of the entire world.</string>
|
||||
<string name="download_please">To continue please\ndownload the app</string>
|
||||
</resources>
|
|
@ -0,0 +1,37 @@
|
|||
package com.mapswithme.maps.api;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapwithme.maps.api.R;
|
||||
|
||||
public class DownloadMapsWithMeDialog extends Dialog implements android.view.View.OnClickListener
|
||||
{
|
||||
|
||||
public DownloadMapsWithMeDialog(Context context)
|
||||
{
|
||||
super(context);
|
||||
|
||||
setTitle(R.string.mapswithme);
|
||||
setContentView(R.layout.dlg_install_mwm);
|
||||
findViewById(R.id.download).setOnClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
public void onDownloadButtonClicked(){
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(getContext().getString(R.string.downolad_url)));
|
||||
getContext().startActivity(i);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (v.getId() == R.id.download)
|
||||
onDownloadButtonClicked();
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
package com.mapswithme.maps.api;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
//TODO add javadoc for public interface
|
||||
public final class MapsWithMeApi
|
||||
|
@ -20,7 +20,7 @@ public final class MapsWithMeApi
|
|||
|
||||
/**
|
||||
* Shows single point on the map.
|
||||
*
|
||||
*
|
||||
* @param caller
|
||||
* @param lat
|
||||
* @param lon
|
||||
|
@ -30,12 +30,12 @@ public final class MapsWithMeApi
|
|||
{
|
||||
showPointsOnMap(caller, (String)null, (PendingIntent)null, new MWMPoint(lat, lon, name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows single point on the map using specified
|
||||
|
||||
|
||||
/**
|
||||
* Shows single point on the map using specified
|
||||
* zoom level in range from {@link MapsWithMeApi#ZOOM_MIN} to {@link MapsWithMeApi#ZOOM_MAX}.
|
||||
*
|
||||
*
|
||||
* @param caller
|
||||
* @param lat
|
||||
* @param lon
|
||||
|
@ -49,7 +49,7 @@ public final class MapsWithMeApi
|
|||
|
||||
/**
|
||||
* Shows set of points on the map.
|
||||
*
|
||||
*
|
||||
* @param caller
|
||||
* @param title
|
||||
* @param points
|
||||
|
@ -62,7 +62,7 @@ public final class MapsWithMeApi
|
|||
/**
|
||||
* Shows set of points on the maps
|
||||
* and allows MapsWithMeApplication to send {@link PendingIntent} provided by client application.
|
||||
*
|
||||
*
|
||||
* @param caller
|
||||
* @param title
|
||||
* @param pendingIntent
|
||||
|
@ -72,11 +72,11 @@ public final class MapsWithMeApi
|
|||
{
|
||||
showPointsOnMap(caller, title, -1, pendingIntent, points);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detects if any version (Lite, Pro) of MapsWithMe, which supports
|
||||
* API calls are installed on the device.
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
|
@ -85,16 +85,16 @@ public final class MapsWithMeApi
|
|||
final Intent intent = new Intent(Const.ACTION_MWM_REQUEST);
|
||||
return context.getPackageManager().resolveActivity(intent, 0) != null;
|
||||
}
|
||||
|
||||
// Internal only code
|
||||
|
||||
|
||||
// Internal only code
|
||||
|
||||
private static void showPointsOnMap(Activity caller, String title, double zoomLevel, PendingIntent pendingIntent, MWMPoint... points)
|
||||
{
|
||||
final Intent mwmIntent = new Intent(Const.ACTION_MWM_REQUEST);
|
||||
|
||||
|
||||
mwmIntent.putExtra(Const.EXTRA_URL, createMwmUrl(caller, title, zoomLevel, points).toString());
|
||||
mwmIntent.putExtra(Const.EXTRA_TITLE, title);
|
||||
|
||||
|
||||
final boolean hasIntent = pendingIntent != null;
|
||||
mwmIntent.putExtra(Const.EXTRA_HAS_PENDING_INTENT, hasIntent);
|
||||
if (hasIntent)
|
||||
|
@ -109,11 +109,13 @@ public final class MapsWithMeApi
|
|||
mwmIntent.setClassName(aInfo.packageName, aInfo.name);
|
||||
caller.startActivity(mwmIntent);
|
||||
}
|
||||
//TODO this is temporally solution, add dialog
|
||||
else
|
||||
Toast.makeText(caller, "MapsWithMe is not installed.", Toast.LENGTH_LONG).show();
|
||||
else
|
||||
{
|
||||
final DownloadMapsWithMeDialog dialog = new DownloadMapsWithMeDialog(caller);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static StringBuilder createMwmUrl(Context context, String title, double zoomLevel, MWMPoint ... points)
|
||||
{
|
||||
StringBuilder urlBuilder = new StringBuilder("mapswithme://map?");
|
||||
|
@ -129,20 +131,20 @@ public final class MapsWithMeApi
|
|||
appendIfNotNull(urlBuilder, "appname", title);
|
||||
// zoom
|
||||
appendIfNotNull(urlBuilder, "z", isValidZoomLevel(zoomLevel) ? String.valueOf(zoomLevel) : null);
|
||||
|
||||
|
||||
// points
|
||||
for (MWMPoint point : points)
|
||||
{
|
||||
if (point != null)
|
||||
{
|
||||
{
|
||||
urlBuilder.append("ll=")
|
||||
.append(String.format(Locale.US, "%f,%f&", point.getLat(), point.getLon()));
|
||||
|
||||
|
||||
appendIfNotNull(urlBuilder, "n", point.getName());
|
||||
appendIfNotNull(urlBuilder, "u", point.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return urlBuilder;
|
||||
}
|
||||
|
||||
|
@ -151,14 +153,14 @@ public final class MapsWithMeApi
|
|||
return Const.CALLBACK_PREFIX + context.getPackageName();
|
||||
}
|
||||
|
||||
private static Intent addCommonExtras(Context context, Intent intent)
|
||||
@SuppressLint("NewApi") private static Intent addCommonExtras(Context context, Intent intent)
|
||||
{
|
||||
intent.putExtra(Const.EXTRA_CALLER_APP_INFO, context.getApplicationInfo());
|
||||
intent.putExtra(Const.EXTRA_API_VERSION, Const.API_VERSION);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
private static StringBuilder appendIfNotNull(StringBuilder builder, String key, String value)
|
||||
{
|
||||
if (value != null)
|
||||
|
@ -166,10 +168,10 @@ public final class MapsWithMeApi
|
|||
.append("=")
|
||||
.append(Uri.encode(value))
|
||||
.append("&");
|
||||
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isValidZoomLevel(double zoom)
|
||||
{
|
||||
return zoom >= ZOOM_MIN && zoom <= ZOOM_MAX;
|
||||
|
|