forked from organicmaps/organicmaps-tmp
[and] Base notifications.
This commit is contained in:
parent
16cab934d6
commit
909a094901
9 changed files with 244 additions and 24 deletions
|
@ -68,7 +68,8 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
|
|||
new HttpGe0IntentProcessor(),
|
||||
new Ge0IntentProcessor(),
|
||||
new MapsWithMeIntentProcessor(),
|
||||
new GooggleMapsIntentProcessor()
|
||||
new GooggleMapsIntentProcessor(),
|
||||
new OpenCountryTaskProcessor(),
|
||||
};
|
||||
|
||||
private void setDownloadMessage(int bytesToDownload)
|
||||
|
@ -644,7 +645,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
|
|||
return "ge0.me".equals(data.getHost());
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -722,6 +723,26 @@ public class DownloadResourcesActivity extends MapsWithMeBaseActivity
|
|||
|
||||
}
|
||||
|
||||
public static String EXTRA_COUNTRY_INDEX = ".extra.index";
|
||||
private class OpenCountryTaskProcessor implements IntentProcessor
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isIntentSupported(Intent intent)
|
||||
{
|
||||
return intent.hasExtra(EXTRA_COUNTRY_INDEX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processIntent(Intent intent)
|
||||
{
|
||||
final Index index = (Index) intent.getSerializableExtra(EXTRA_COUNTRY_INDEX);
|
||||
mMapTaskToForward = new MWMActivity.ShowCountryTask(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private native int getBytesToDownload();
|
||||
private native boolean isWorldExists(String path);
|
||||
private native int startNextFileDownload(Object observer);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
||||
import com.mapswithme.maps.guides.GuideInfo;
|
||||
|
||||
/**
|
||||
* This class wraps android::Framework.cpp class
|
||||
|
@ -78,6 +79,10 @@ public class Framework
|
|||
nativeUpdateSavedDataVersion();
|
||||
}
|
||||
|
||||
public static native void updateGuidesData();
|
||||
|
||||
public static native GuideInfo getGuideInfoForCountry(String countryId);
|
||||
|
||||
/*
|
||||
* "Implementation" - native methods
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.Framework.OnBalloonListener;
|
||||
import com.mapswithme.maps.MapStorage.Index;
|
||||
import com.mapswithme.maps.api.ParsedMmwRequest;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
|
@ -1063,6 +1064,23 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
}
|
||||
}
|
||||
|
||||
public static class ShowCountryTask implements MapTask
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Index mIndex;
|
||||
|
||||
public ShowCountryTask(Index index)
|
||||
{
|
||||
mIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(MWMActivity target)
|
||||
{
|
||||
target.getMapStorage().showCountry(mIndex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
////
|
||||
// NATIVE callbacks and methods
|
||||
|
@ -1133,6 +1151,12 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
});
|
||||
}
|
||||
|
||||
public static Intent createShowMapIntent(Context context, Index index)
|
||||
{
|
||||
return new Intent(context, DownloadResourcesActivity.class)
|
||||
.putExtra(DownloadResourcesActivity.EXTRA_COUNTRY_INDEX, index);
|
||||
}
|
||||
|
||||
private native void nativeStorageConnected();
|
||||
private native void nativeStorageDisconnected();
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ import android.util.Log;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.MapStorage.Index;
|
||||
import com.mapswithme.maps.background.Notifier;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.guides.GuideInfo;
|
||||
import com.mapswithme.maps.guides.GuidesUtils;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
import com.mapswithme.maps.state.AppStateManager;
|
||||
import com.mapswithme.maps.state.SuppotedState;
|
||||
|
@ -33,7 +36,7 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
private MapStorage m_storage = null;
|
||||
private int m_slotID = 0;
|
||||
|
||||
private AppStateManager mAppStateManager = new AppStateManager();
|
||||
private final AppStateManager mAppStateManager = new AppStateManager();
|
||||
|
||||
private boolean m_isProVersion = false;
|
||||
|
||||
|
@ -67,18 +70,37 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
@Override
|
||||
public void onCountryStatusChanged(Index idx)
|
||||
{
|
||||
final Notifier notifier = new Notifier(this);
|
||||
switch (m_storage.countryStatus(idx))
|
||||
{
|
||||
case MapStorage.ON_DISK:
|
||||
showDownloadToast(R.string.download_country_success, idx);
|
||||
notifier.placeDownloadCompleted(idx, getMapStorage().countryName(idx));
|
||||
tryNotifyGuideAvailable(idx);
|
||||
break;
|
||||
|
||||
case MapStorage.DOWNLOAD_FAILED:
|
||||
showDownloadToast(R.string.download_country_failed, idx);
|
||||
notifier.placeDownloadFailed(idx, getMapStorage().countryName(idx));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void tryNotifyGuideAvailable(Index idx)
|
||||
{
|
||||
if (Utils.hasAnyGoogleStoreInstalled())
|
||||
{
|
||||
final String countryId = getMapStorage().countryFileNameByIndex(idx);
|
||||
final GuideInfo info = Framework.getGuideInfoForCountry(countryId);
|
||||
|
||||
if (info != null && !GuidesUtils.isGuideInstalled(info.getAppId(), this))
|
||||
{
|
||||
final Notifier notifier = new Notifier(this);
|
||||
notifier.placeGuideAvailable(info.getAppName(),
|
||||
info.getAppId(),
|
||||
getMapStorage().countryName(idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCountryProgress(Index idx, long current, long total)
|
||||
{
|
||||
|
@ -98,12 +120,12 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
// get url for PRO version
|
||||
if (!m_isProVersion)
|
||||
{
|
||||
AssetManager assets = getAssets();
|
||||
final AssetManager assets = getAssets();
|
||||
InputStream stream = null;
|
||||
try
|
||||
{
|
||||
stream = assets.open("app_info.txt");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
|
||||
final String s = reader.readLine();
|
||||
if (s.length() > 0)
|
||||
|
@ -111,7 +133,7 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
|
||||
Log.i(TAG, "Pro version url: " + m_proVersionURL);
|
||||
}
|
||||
catch (IOException ex)
|
||||
catch (final IOException ex)
|
||||
{
|
||||
// suppress exceptions - pro version doesn't need app_info.txt
|
||||
}
|
||||
|
@ -177,7 +199,7 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
{
|
||||
return getPackageManager().getApplicationInfo(getPackageName(), 0).sourceDir;
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
catch (final NameNotFoundException e)
|
||||
{
|
||||
Log.e(TAG, "Can't get apk path from PackageManager");
|
||||
return "";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.mapswithme.maps;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -24,8 +26,10 @@ public class MapStorage
|
|||
public void onCountryProgress(Index idx, long current, long total);
|
||||
};
|
||||
|
||||
public static class Index
|
||||
public static class Index implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
int mGroup;
|
||||
int mCountry;
|
||||
int mRegion;
|
||||
|
@ -56,7 +60,7 @@ public class MapStorage
|
|||
|
||||
public Index getChild(int position)
|
||||
{
|
||||
Index ret = new Index(mGroup, mCountry, mRegion);
|
||||
final Index ret = new Index(mGroup, mCountry, mRegion);
|
||||
|
||||
if (ret.mGroup == -1) ret.mGroup = position;
|
||||
else if (ret.mCountry == -1) ret.mCountry = position;
|
||||
|
@ -71,7 +75,7 @@ public class MapStorage
|
|||
|
||||
public Index getParent()
|
||||
{
|
||||
Index ret = new Index(mGroup, mCountry, mRegion);
|
||||
final Index ret = new Index(mGroup, mCountry, mRegion);
|
||||
|
||||
if (ret.mRegion != -1) ret.mRegion = -1;
|
||||
else if (ret.mCountry != -1) ret.mCountry = -1;
|
||||
|
@ -108,6 +112,7 @@ public class MapStorage
|
|||
}
|
||||
}
|
||||
|
||||
public native String countryFileNameByIndex(Index idx);
|
||||
public native int countriesCount(Index idx);
|
||||
public native int countryStatus(Index idx);
|
||||
public native long countryLocalSizeInBytes(Index idx);
|
||||
|
|
|
@ -8,14 +8,19 @@ import android.content.Intent;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.mapswithme.maps.DownloadUI;
|
||||
import com.mapswithme.maps.MWMActivity;
|
||||
import com.mapswithme.maps.MapStorage.Index;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.guides.GuidesUtils;
|
||||
|
||||
public class Notifier
|
||||
{
|
||||
private final static int ID_UPDATE_AVAIL = 0x1;
|
||||
private final static int ID_GUIDE_AVAIL = 0x2;
|
||||
private final static int ID_DOWNLOAD_STATUS = 0x3;
|
||||
|
||||
private NotificationManager mNotificationManager;
|
||||
private Context mContext;
|
||||
private final NotificationManager mNotificationManager;
|
||||
private final Context mContext;
|
||||
|
||||
public Notifier(Context context)
|
||||
{
|
||||
|
@ -43,6 +48,36 @@ public class Notifier
|
|||
mNotificationManager.notify(ID_UPDATE_AVAIL, notification);
|
||||
}
|
||||
|
||||
public void placeDownloadCompleted(Index idx, String name)
|
||||
{
|
||||
final String title = mContext.getString(R.string.app_name);
|
||||
final String content = mContext.getString(R.string.download_country_success, name);
|
||||
|
||||
placeDownloadNoti(title, content, idx);
|
||||
}
|
||||
|
||||
public void placeDownloadFailed(Index idx, String name)
|
||||
{
|
||||
final String title = mContext.getString(R.string.app_name);
|
||||
final String content = mContext.getString(R.string.download_country_failed, name);
|
||||
|
||||
placeDownloadNoti(title, content, idx);
|
||||
}
|
||||
|
||||
private void placeDownloadNoti(String title, String content, Index idx)
|
||||
{
|
||||
final PendingIntent pi = PendingIntent
|
||||
.getActivity(mContext, 0, MWMActivity.createShowMapIntent(mContext, idx), Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
final Notification notification = getBuilder()
|
||||
.setContentTitle(title)
|
||||
.setContentText(content)
|
||||
.setTicker(title + content)
|
||||
.setContentIntent(pi)
|
||||
.build();
|
||||
|
||||
mNotificationManager.notify(ID_DOWNLOAD_STATUS, notification);
|
||||
}
|
||||
|
||||
public NotificationCompat.Builder getBuilder()
|
||||
{
|
||||
|
@ -52,4 +87,24 @@ public class Notifier
|
|||
.setSmallIcon(R.drawable.ic_launcher);
|
||||
}
|
||||
|
||||
public void placeGuideAvailable(String guideName, String packageName, String country)
|
||||
{
|
||||
// TODO: Add string resources
|
||||
final String title = String.format("Going to %s?", country);
|
||||
final String content = String.format("%s will help you!", guideName);
|
||||
|
||||
final PendingIntent pi = PendingIntent
|
||||
.getActivity(mContext, 0, GuidesUtils.getGoogleStoreIntentForPackage(packageName), 0);
|
||||
|
||||
final Notification guideNoti = new NotificationCompat.Builder(mContext)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentIntent(pi)
|
||||
.setContentTitle(title)
|
||||
.setContentText(content)
|
||||
.build();
|
||||
|
||||
mNotificationManager.notify(ID_GUIDE_AVAIL, guideNoti);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
30
android/src/com/mapswithme/maps/guides/GuideInfo.java
Normal file
30
android/src/com/mapswithme/maps/guides/GuideInfo.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package com.mapswithme.maps.guides;
|
||||
|
||||
public class GuideInfo
|
||||
{
|
||||
private final String mAppName;
|
||||
private final String mAppId;
|
||||
private final String mAppUrl;
|
||||
|
||||
public GuideInfo(String appName, String appId, String appUrl)
|
||||
{
|
||||
this.mAppName = appName;
|
||||
this.mAppId = appId;
|
||||
this.mAppUrl = appUrl;
|
||||
}
|
||||
|
||||
public String getAppName()
|
||||
{
|
||||
return mAppName;
|
||||
}
|
||||
|
||||
public String getAppId()
|
||||
{
|
||||
return mAppId;
|
||||
}
|
||||
|
||||
public String getAppUrl()
|
||||
{
|
||||
return mAppUrl;
|
||||
}
|
||||
}
|
32
android/src/com/mapswithme/maps/guides/GuidesUtils.java
Normal file
32
android/src/com/mapswithme/maps/guides/GuidesUtils.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package com.mapswithme.maps.guides;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.Uri;
|
||||
|
||||
public class GuidesUtils
|
||||
{
|
||||
public static boolean isGuideInstalled(String appId, Context context)
|
||||
{
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
try
|
||||
{
|
||||
// throws if has no package
|
||||
pm.getPackageInfo(appId, PackageManager.GET_META_DATA);
|
||||
return true;
|
||||
}
|
||||
catch (final NameNotFoundException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Intent getGoogleStoreIntentForPackage(String packageName)
|
||||
{
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("market://details?id=" + packageName));
|
||||
return intent;
|
||||
}
|
||||
}
|
|
@ -3,14 +3,19 @@ package com.mapswithme.util;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -31,7 +36,7 @@ final public class Utils
|
|||
{
|
||||
stream.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (final IOException e)
|
||||
{
|
||||
Log.e(TAG, "Can't close stream", e);
|
||||
}
|
||||
|
@ -40,7 +45,7 @@ final public class Utils
|
|||
|
||||
public static String readStreamAsString(InputStream is)
|
||||
{
|
||||
Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
final Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
return scanner.hasNext() ? scanner.next() : "";
|
||||
}
|
||||
|
||||
|
@ -50,6 +55,27 @@ final public class Utils
|
|||
return byAmazon;
|
||||
}
|
||||
|
||||
|
||||
public static boolean hasAnyGoogleStoreInstalled()
|
||||
{
|
||||
return hasAnyGoogleStoreInstalled(MWMApplication.get());
|
||||
}
|
||||
|
||||
public static boolean hasAnyGoogleStoreInstalled(Context context)
|
||||
{
|
||||
final String GooglePlayStorePackageNameOld = "com.google.market";
|
||||
final String GooglePlayStorePackageNameNew = "com.android.vending";
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final List<PackageInfo> packages = pm.getInstalledPackages(0);
|
||||
for (final PackageInfo packageInfo : packages)
|
||||
{
|
||||
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld)
|
||||
|| packageInfo.packageName.equals(GooglePlayStorePackageNameNew))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// if enabled, screen will be turned off automatically by the system
|
||||
// if disabled, screen will be always turn on
|
||||
public static void automaticIdleScreen(boolean enable, Window w)
|
||||
|
@ -62,10 +88,10 @@ final public class Utils
|
|||
|
||||
public static float getAttributeDimension(Activity activity, int attr)
|
||||
{
|
||||
android.util.TypedValue value = new android.util.TypedValue();
|
||||
boolean b = activity.getTheme().resolveAttribute(attr, value, true);
|
||||
final android.util.TypedValue value = new android.util.TypedValue();
|
||||
final boolean b = activity.getTheme().resolveAttribute(attr, value, true);
|
||||
assert(b);
|
||||
android.util.DisplayMetrics metrics = new android.util.DisplayMetrics();
|
||||
final android.util.DisplayMetrics metrics = new android.util.DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
return value.getDimension(metrics);
|
||||
}
|
||||
|
@ -112,16 +138,16 @@ final public class Utils
|
|||
{
|
||||
if (apiLowerThan(11))
|
||||
{
|
||||
android.text.ClipboardManager clipbord =
|
||||
final android.text.ClipboardManager clipbord =
|
||||
(android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipbord.setText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is different classes in different packages
|
||||
android.content.ClipboardManager clipboard =
|
||||
final android.content.ClipboardManager clipboard =
|
||||
(android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("MapsWithMe: " + text, text);
|
||||
final ClipData clip = ClipData.newPlainText("MapsWithMe: " + text, text);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
}
|
||||
|
@ -131,8 +157,8 @@ final public class Utils
|
|||
if (map == null) return "[null]";
|
||||
if (map.isEmpty()) return "[]";
|
||||
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
for (K key : map.keySet())
|
||||
final StringBuilder sb = new StringBuilder("[");
|
||||
for (final K key : map.keySet())
|
||||
sb.append(String.valueOf(key))
|
||||
.append('=')
|
||||
.append(map.get(key))
|
||||
|
|
Loading…
Add table
Reference in a new issue