Promo action notification.

This commit is contained in:
Dmitry Yunitsky 2014-08-08 18:05:53 +03:00 committed by Alex Zolotarev
parent 8963d8b431
commit 8f569fed5d
6 changed files with 101 additions and 4 deletions

View file

@ -155,6 +155,8 @@ public class MWMApplication extends android.app.Application implements MapStorag
// init BookmarkManager (automatically loads bookmarks)
if (hasBookmarks())
BookmarkManager.getBookmarkManager(getApplicationContext());
new Notifier(this).schedulePromoNotification();
}
public LocationService getLocationService()

View file

@ -1,25 +1,31 @@
package com.mapswithme.maps.background;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import com.mapswithme.country.DownloadActivity;
import com.mapswithme.maps.MWMActivity;
import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.MapStorage.Index;
import com.mapswithme.maps.R;
import com.mapswithme.maps.guides.GuidesUtils;
import com.mapswithme.util.statistics.Statistics;
import java.util.Calendar;
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 final static int ID_DOWNLOAD_NEW_COUNTRY = 0x4;
private final static int ID_MWM_PRO_PROMOACTION = 0x5;
private final NotificationManager mNotificationManager;
private final Context mContext;
@ -113,8 +119,50 @@ public class Notifier
.setContentIntent(pi)
.build();
mNotificationManager.notify(ID_DOWNLOAD_STATUS, notification);
mNotificationManager.notify(ID_DOWNLOAD_NEW_COUNTRY, notification);
Statistics.INSTANCE.trackDownloadCountryNotificationShown();
}
public void schedulePromoNotification()
{
final Intent intent = new Intent(MWMApplication.get(), WorkerService.class).
setAction(WorkerService.ACTION_PROMO_NOTIFICATION_SHOW);
final PendingIntent pendingIntent = PendingIntent.getService(MWMApplication.get(), 0, intent, 0);
final int promoDate = 17;
final int promoHour = 12;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, Calendar.AUGUST);
calendar.set(Calendar.DAY_OF_MONTH, promoDate);
calendar.set(Calendar.HOUR_OF_DAY, promoHour);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
if (System.currentTimeMillis() < calendar.getTimeInMillis())
{
AlarmManager alarm = (AlarmManager) MWMApplication.get().getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
alarm.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
else
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
}
public void placePromoNotification()
{
final Intent intent = new Intent(MWMApplication.get(), WorkerService.class).
setAction(WorkerService.ACTION_PROMO_NOTIFICATION_CLICK);
final PendingIntent pendingIntent = PendingIntent.getService(MWMApplication.get(), 0, intent, 0);
// TODO add correct string from resources after translations
final Notification notification = getBuilder()
.setContentTitle("promo action")
.setContentText("download mwmpro for 1 dollar!")
.setTicker("promo action" + ": " + "download mwmpro for 1 dollar")
.setContentIntent(pendingIntent)
.build();
mNotificationManager.notify(ID_MWM_PRO_PROMOACTION, notification);
}
}

View file

@ -6,11 +6,15 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.R;
import com.mapswithme.util.LocationUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.StubLogger;
import com.mapswithme.util.statistics.Statistics;
@ -25,9 +29,14 @@ import java.util.TimerTask;
*/
public class WorkerService extends IntentService
{
private static final String ACTION_PUSH_STATISTICS = "com.mapswithme.maps.action.stat";
private static final String ACTION_CHECK_UPDATE = "com.mapswithme.maps.action.update";
private static final String ACTION_DOWNLOAD_COUNTRY = "com.mapswithme.maps.action.download_country";
public static final String ACTION_PUSH_STATISTICS = "com.mapswithme.maps.action.stat";
public static final String ACTION_CHECK_UPDATE = "com.mapswithme.maps.action.update";
public static final String ACTION_DOWNLOAD_COUNTRY = "com.mapswithme.maps.action.download_country";
public static final String ACTION_PROMO_NOTIFICATION_SHOW = "com.mapswithme.maps.action.notification.show";
public static final String ACTION_PROMO_NOTIFICATION_CLICK = "com.mapswithme.maps.action.notification.click";
private static final String PROMO_SHOW_EVENT_NAME = "PromoShowAndroid";
private static final String PROMO_CLICK_EVENT_NAME = "PromoClickAndroid";
private Logger mLogger = StubLogger.get();
// = SimpleLogger.get("MWMWorkerService");
@ -103,6 +112,12 @@ public class WorkerService extends IntentService
case ACTION_DOWNLOAD_COUNTRY:
handleActionCheckLocation();
break;
case ACTION_PROMO_NOTIFICATION_SHOW:
showPromoNotification();
break;
case ACTION_PROMO_NOTIFICATION_CLICK:
promoNotificationClicked();
break;
}
}
}
@ -197,4 +212,23 @@ public class WorkerService extends IntentService
}
}
}
private void showPromoNotification()
{
new Notifier(getApplicationContext()).placePromoNotification();
Statistics.INSTANCE.trackSimpleNamedEvent(PROMO_SHOW_EVENT_NAME);
}
private void promoNotificationClicked()
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MWMApplication.get().getProVersionURL())).
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (!Utils.isIntentAvailable(intent))
{
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MWMApplication.get().getDefaultProVersionURL())).
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
startActivity(intent);
Statistics.INSTANCE.trackSimpleNamedEvent(PROMO_CLICK_EVENT_NAME);
}
}

View file

@ -11,6 +11,7 @@ public class Constants
public static final String HTTP_GE0_PREFIX = "http://ge0.me/";
public static final String PLAY_MARKET_APP_PREFIX = "market://details?id=";
public static final String PLAY_MARKET_HTTPS_PREFIX = "http://play.google.com/store/apps/details?id=";
public static final String GEOLOCATION_SERVER_MAPSME = "http://geolocation.server/";
public static final String FB_MAPSME_COMMUNITY_HTTP = "http://www.facebook.com/MapsWithMe";

View file

@ -207,5 +207,11 @@ public class Utils
return installed;
}
public static boolean isIntentAvailable(Intent intent)
{
PackageManager mgr = MWMApplication.get().getPackageManager();
return mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
private Utils() {}
}

View file

@ -212,6 +212,12 @@ public enum Statistics
getEventBuilder().getSimpleNamedEvent("Download country notification clicked").post();
}
public void trackSimpleNamedEvent(String eventName)
{
ensureConfigured(MWMApplication.get());
getEventBuilder().getSimpleNamedEvent(eventName).post();
}
public void startActivity(Activity activity)
{
ensureConfigured(activity);