[android] Show Buy Pro version banner in Lite. Some refactoring of banner's routine.

This commit is contained in:
vng 2012-11-10 00:15:35 +03:00 committed by Alex Zolotarev
parent 64a95e363b
commit b52cb4a765
8 changed files with 167 additions and 97 deletions

View file

@ -10,9 +10,13 @@
#include "../core/jni_helper.hpp"
#include "../platform/Platform.hpp"
#include "../../../../../platform/settings.hpp"
#include "../../../../../map/information_display.hpp"
#include "../../../../../map/location_state.hpp"
#include "../../../../../map/dialog_settings.hpp"
#include "../../../../../platform/settings.hpp"
extern "C"
{
@ -44,18 +48,18 @@ extern "C"
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_MWMApplication_nativeShouldShowFacebookDialog(JNIEnv * env,
jobject thiz)
Java_com_mapswithme_maps_MWMApplication_shouldShowDialog(
JNIEnv * env, jobject thiz, jint dlg)
{
return static_cast<jboolean>(g_framework->NativeFramework()->ShouldShowFacebookDialog());
return static_cast<jboolean>(dlg_settings::ShouldShow(static_cast<dlg_settings::DialogT>(dlg)));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMApplication_nativeSubmitFacebookDialogResult(JNIEnv * env,
jobject thiz,
jint result)
Java_com_mapswithme_maps_MWMApplication_submitDialogResult(
JNIEnv * env, jobject thiz, jint dlg, jint res)
{
g_framework->NativeFramework()->SaveFacebookDialogResult(static_cast<int>(result));
dlg_settings::SaveResult(static_cast<dlg_settings::DialogT>(dlg),
static_cast<dlg_settings::ResultT>(res));
}
JNIEXPORT jboolean JNICALL

View file

@ -142,6 +142,7 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
checkMeasurementSystem();
checkUpdateMaps();
checkFacebookDialog();
checkBuyProDialog();
}
});
}
@ -325,6 +326,34 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
alignZoomButtons();
}
private void showDialogImpl(final int dlgID, int resMsg, DialogInterface.OnClickListener okListener)
{
new AlertDialog.Builder(this)
.setCancelable(false)
.setMessage(getString(resMsg))
.setPositiveButton(getString(R.string.ok), okListener)
.setNeutralButton(getString(R.string.later), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
dlg.dismiss();
mApplication.submitDialogResult(dlgID, MWMApplication.LATER);
}
})
.setNegativeButton(getString(R.string.never), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
dlg.dismiss();
mApplication.submitDialogResult(dlgID, MWMApplication.NEVER);
}
})
.create()
.show();
}
private void showFacebookPage()
{
Intent intent = null;
@ -383,42 +412,21 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
private void checkFacebookDialog()
{
if ((ConnectionState.getState(this) != ConnectionState.NOT_CONNECTED) &&
mApplication.nativeShouldShowFacebookDialog() &&
mApplication.shouldShowDialog(MWMApplication.FACEBOOK) &&
!isChinaRegion())
{
new AlertDialog.Builder(this)
.setCancelable(false)
.setMessage(getString(R.string.share_on_facebook_text))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener()
showDialogImpl(MWMApplication.FACEBOOK, R.string.share_on_facebook_text,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
mApplication.submitDialogResult(MWMApplication.FACEBOOK, MWMApplication.OK);
dlg.dismiss();
mApplication.nativeSubmitFacebookDialogResult(0);
showFacebookPage();
}
})
.setNeutralButton(getString(R.string.later), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
dlg.dismiss();
mApplication.nativeSubmitFacebookDialogResult(1);
}
})
.setNegativeButton(getString(R.string.never), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
dlg.dismiss();
mApplication.nativeSubmitFacebookDialogResult(2);
}
})
.create()
.show();
});
}
}
@ -449,6 +457,28 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
.show();
}
private void checkBuyProDialog()
{
if (!mApplication.isProVersion() &&
(ConnectionState.getState(this) != ConnectionState.NOT_CONNECTED) &&
mApplication.shouldShowDialog(MWMApplication.BUYPRO))
{
showDialogImpl(MWMApplication.BUYPRO, R.string.pro_version_available,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
mApplication.submitDialogResult(MWMApplication.BUYPRO, MWMApplication.OK);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(mApplication.getProVersionURL()));
dlg.dismiss();
startActivity(i);
}
});
}
}
private void runSearchActivity()
{
startActivity(new Intent(this, SearchActivity.class));

View file

@ -31,7 +31,7 @@ public class MWMApplication extends android.app.Application implements MapStorag
// Set default string to Google Play page.
private String m_proVersionURL =
"https://play.google.com/store/apps/details?id=com.mapswithme.maps.pro";
"https://play.google.com/store/apps/details?id=com.mapswithme.maps.pro";
private void showDownloadToast(int resID, Index idx)
{
@ -188,11 +188,18 @@ public class MWMApplication extends android.app.Application implements MapStorag
public native boolean nativeIsBenchmarking();
/// Dealing with Facebook dialog
/// @name Dealing with dialogs.
/// @note Constants should be equal with map/dialog_settings.hpp
/// @{
public native boolean nativeShouldShowFacebookDialog();
static public final int FACEBOOK = 0;
static public final int BUYPRO = 1;
public native boolean shouldShowDialog(int dlg);
/// values of result param should correspond to values defined in map/Framework.hpp
public native void nativeSubmitFacebookDialogResult(int result);
static public final int OK = 0;
static public final int LATER = 1;
static public final int NEVER = 2;
public native void submitDialogResult(int dlg, int res);
/// @}
/// Dealing with Settings

67
map/dialog_settings.cpp Normal file
View file

@ -0,0 +1,67 @@
#include "dialog_settings.hpp"
#include "../platform/settings.hpp"
#include "../base/assert.hpp"
namespace dlg_settings
{
/// @note Add new values to the end and do not change order.
//@{
char const * g_arrSettingsName[] =
{
"FacebookDialog",
"BuyProDialog"
};
int g_arrMinForegroundTime[] = { 30 * 60, 60 * 60 };
//@}
bool ShouldShow(DialogT dlg)
{
string const name = g_arrSettingsName[dlg];
bool flag = true;
(void)Settings::Get("ShouldShow" + name, flag);
if (!flag)
return false;
double val = 0;
(void)Settings::Get(name + "ForegroundTime", val);
return (val >= g_arrMinForegroundTime[dlg]);
}
void SaveResult(DialogT dlg, ResultT res)
{
string const name = g_arrSettingsName[dlg];
switch (res)
{
case OK: case Never:
Settings::Set("ShouldShow" + name, false);
break;
case Later:
Settings::Set(name + "ForegroundTime", 0);
break;
default:
ASSERT ( false, () );
break;
}
}
void EnterBackground(double elapsed)
{
for (int i = 0; i < DlgCount; ++i)
{
string const name = string(g_arrSettingsName[i]) + "ForegroundTime";
double val = 0;
(void)Settings::Get(name, val);
Settings::Set(name, val + elapsed);
}
}
}

16
map/dialog_settings.hpp Normal file
View file

@ -0,0 +1,16 @@
#pragma once
namespace dlg_settings
{
/// @note Do not change numeric values, order and leave DlgCount last.
//@{
enum DialogT { FacebookDlg = 0, BuyProDlg, DlgCount };
enum ResultT { OK = 0, Later, Never };
//@}
void EnterBackground(double elapsed);
bool ShouldShow(DialogT dlg);
void SaveResult(DialogT dlg, ResultT res);
}

View file

@ -5,6 +5,7 @@
#include "benchmark_engine.hpp"
#include "geourl_process.hpp"
#include "measurement_utils.hpp"
#include "dialog_settings.hpp"
#include "../defines.hpp"
@ -891,10 +892,6 @@ void Framework::MemoryWarning()
LOG(LINFO, ("MemoryWarning"));
}
#define MIN_FOREGROUND_TIME_TO_SHOW_FACEBOOK_DIALOG 60 * 60
#define FOREGROUND_TIME_SETTINGS "ForegroundTime"
#define SHOW_FACEBOOK_SETTINGS "ShouldShowFacebookDialog"
void Framework::EnterBackground()
{
// Do not clear caches for Android. This function is called when main activity is paused,
@ -903,9 +900,7 @@ void Framework::EnterBackground()
ClearAllCaches();
#endif
double val = 0;
(void)Settings::Get(FOREGROUND_TIME_SETTINGS, val);
Settings::Set(FOREGROUND_TIME_SETTINGS, my::Timer::LocalTime() - m_StartForegroundTime + val);
dlg_settings::EnterBackground(my::Timer::LocalTime() - m_StartForegroundTime);
}
void Framework::EnterForeground()
@ -1394,31 +1389,6 @@ bool Framework::IsBenchmarking() const
return m_benchmarkEngine != 0;
}
bool Framework::ShouldShowFacebookDialog() const
{
double val = 0;
bool flag = true;
(void)Settings::Get(FOREGROUND_TIME_SETTINGS, val);
(void)Settings::Get(SHOW_FACEBOOK_SETTINGS, flag);
return (flag && (val >= MIN_FOREGROUND_TIME_TO_SHOW_FACEBOOK_DIALOG));
}
void Framework::SaveFacebookDialogResult(int result)
{
switch (result)
{
case 0: case 2:
Settings::Set(SHOW_FACEBOOK_SETTINGS, false);
break;
case 1:
Settings::Set(FOREGROUND_TIME_SETTINGS, 0);
break;
default:
LOG(LINFO, ("Unknown Facebook dialog result!"));
break;
}
}
shared_ptr<graphics::OverlayElement> const GetClosestToPivot(list<shared_ptr<graphics::OverlayElement> > const & l,
m2::PointD const & pxPoint)
{

View file

@ -416,16 +416,6 @@ public:
bool IsBenchmarking() const;
/// @{ Dealing with "Like us on a Facebook" dialog
bool ShouldShowFacebookDialog() const;
/// values for @param result are as follows
/// 0 - "OK" pressed
/// 1 - "Later" pressed
/// 2 - "Never" pressed
void SaveFacebookDialogResult(int result);
/// @}
/// Checks, whether the country which contains
/// the specified point is loaded
bool IsCountryLoaded(m2::PointD const & pt) const;

View file

@ -49,6 +49,7 @@ HEADERS += \
animator.hpp \
move_screen_task.hpp \
change_viewport_task.hpp \
dialog_settings.hpp \
SOURCES += \
feature_vec_model.cpp \
@ -89,25 +90,10 @@ SOURCES += \
animator.cpp \
move_screen_task.cpp \
change_viewport_task.cpp \
dialog_settings.cpp \
!iphone*:!bada*:!android* {
HEADERS += qgl_render_context.hpp
SOURCES += qgl_render_context.cpp
QT += opengl
}