Updated description of advertisement API, added function to request new ad.
This commit is contained in:
@@ -43,4 +43,8 @@ class Advertisement
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void requestNewAd()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,14 +422,37 @@ public class MainActivity extends Activity
|
||||
mGLView.requestFocus();
|
||||
};
|
||||
|
||||
public void setAdvertisementPosition(int left, int top)
|
||||
final static int ADVERTISEMENT_POSITION_RIGHT = -1;
|
||||
final static int ADVERTISEMENT_POSITION_BOTTOM = -1;
|
||||
final static int ADVERTISEMENT_POSITION_CENTER = -2;
|
||||
|
||||
public void setAdvertisementPosition(int x, int y)
|
||||
{
|
||||
|
||||
if( _ad.getView() != null )
|
||||
{
|
||||
final FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT);
|
||||
layout.leftMargin = left;
|
||||
layout.topMargin = top;
|
||||
final FrameLayout.LayoutParams layout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
layout.gravity = 0;
|
||||
layout.leftMargin = 0;
|
||||
layout.topMargin = 0;
|
||||
if( x == ADVERTISEMENT_POSITION_RIGHT )
|
||||
layout.gravity |= Gravity.RIGHT;
|
||||
else if ( x == ADVERTISEMENT_POSITION_CENTER )
|
||||
layout.gravity |= Gravity.CENTER_HORIZONTAL;
|
||||
else
|
||||
{
|
||||
layout.gravity |= Gravity.LEFT;
|
||||
layout.leftMargin = x;
|
||||
}
|
||||
if( y == ADVERTISEMENT_POSITION_BOTTOM )
|
||||
layout.gravity |= Gravity.BOTTOM;
|
||||
else if ( x == ADVERTISEMENT_POSITION_CENTER )
|
||||
layout.gravity |= Gravity.CENTER_VERTICAL;
|
||||
else
|
||||
{
|
||||
layout.gravity |= Gravity.TOP;
|
||||
layout.topMargin = y;
|
||||
}
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public void run()
|
||||
@@ -472,6 +495,20 @@ public class MainActivity extends Activity
|
||||
params[4] = _ad.getView().getMeasuredHeight();
|
||||
}
|
||||
}
|
||||
public void requestNewAdvertisement()
|
||||
{
|
||||
if( _ad.getView() != null )
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_ad.requestNewAd();
|
||||
}
|
||||
}
|
||||
runOnUiThread(new Callback());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, final KeyEvent event)
|
||||
|
||||
@@ -575,6 +575,10 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
context.setAdvertisementPosition(left, top);
|
||||
}
|
||||
public void requestNewAdvertisement()
|
||||
{
|
||||
context.requestNewAdvertisement();
|
||||
}
|
||||
|
||||
private int PowerOf2(int i)
|
||||
{
|
||||
|
||||
@@ -64,4 +64,12 @@ class Advertisement
|
||||
{
|
||||
return ad;
|
||||
}
|
||||
|
||||
public void requestNewAd()
|
||||
{
|
||||
AdRequest adRequest = new AdRequest();
|
||||
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // Copy GoogleAdMobAdsSdk.jar to the directory project/libs
|
||||
adRequest.addTestDevice(Globals.AdmobTestDeviceId);
|
||||
ad.loadAd(adRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,3 +45,7 @@ AppLdflags=''
|
||||
AppSubdirsBuild=''
|
||||
AppCmdline=''
|
||||
ReadmeText='^Readme text'
|
||||
MinimumScreenSize=s
|
||||
AdmobPublisherId=n
|
||||
AdmobTestDeviceId=
|
||||
AdmobBannerSize=
|
||||
|
||||
@@ -45,3 +45,7 @@ AppLdflags=''
|
||||
AppSubdirsBuild=''
|
||||
AppCmdline=''
|
||||
ReadmeText='^Readme text'
|
||||
MinimumScreenSize=n
|
||||
AdmobPublisherId=a14fe4dd0ebe974
|
||||
AdmobTestDeviceId=66133194946FB6C1CD0ED2EFCCB82539
|
||||
AdmobBannerSize=BANNER
|
||||
|
||||
@@ -30,7 +30,7 @@ RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
|
||||
AppTouchscreenKeyboardKeysAmount=0
|
||||
AppTouchscreenKeyboardKeysAmountAutoFire=0
|
||||
RedefinedKeysScreenKb="0 1 2 3 4 5 6 7 8 9"
|
||||
StartupMenuButtonTimeout=3000
|
||||
StartupMenuButtonTimeout=500
|
||||
HiddenMenuOptions='OptionalDownloadConfig'
|
||||
FirstStartMenuOptions=''
|
||||
MultiABI=n
|
||||
|
||||
@@ -433,7 +433,7 @@ int main(int argc, char* argv[])
|
||||
float x_speed, y_speed, z_speed;
|
||||
SDL_Rect adSize;
|
||||
int physicalW = 0, physicalH = 0;
|
||||
int showAd = 0;
|
||||
int showAd = 0, newAd = 0;
|
||||
|
||||
SDL_ANDROID_GetAdvertisementParams(NULL, &adSize);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Advertisement size %dx%d pos %d:%d", (int)adSize.w, (int)adSize.h, (int)adSize.x, (int)adSize.y);
|
||||
@@ -569,8 +569,16 @@ int main(int argc, char* argv[])
|
||||
if(showAd > 3)
|
||||
showAd = 0;
|
||||
SDL_ANDROID_SetAdvertisementVisible(showAd);
|
||||
if(showAd == 1)
|
||||
{
|
||||
newAd++;
|
||||
if(newAd % 5)
|
||||
SDL_ANDROID_RequestNewAdvertisement();
|
||||
}
|
||||
}
|
||||
|
||||
if(adSize.w == 0 || adSize.h == 0)
|
||||
SDL_ANDROID_GetAdvertisementParams(NULL, &adSize);
|
||||
int adX = abs(x_offs / 100) % (physicalW - adSize.w);
|
||||
int adY = abs(y_offs / 80) % (physicalH - adSize.h);
|
||||
SDL_ANDROID_SetAdvertisementPosition(adX, adY);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
/*
|
||||
Sets callbacks to be called when OS decides to put application to background, and restored to foreground.
|
||||
*/
|
||||
typedef void ( * SDL_ANDROID_ApplicationPutToBackgroundCallback_t ) (void);
|
||||
@@ -45,12 +45,36 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_SetApplicationPutToBackgroundCallback(
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_PauseAudioPlayback(void);
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_ResumeAudioPlayback(void);
|
||||
|
||||
/* Get the advertisement size, position and visibility */
|
||||
/*
|
||||
Get the advertisement size, position and visibility.
|
||||
If the advertisement is not yet loaded, this function will return zero width and height,
|
||||
so you'll need to account for that in your code, because you can never know
|
||||
whether the user has no access to network, or if ad server is accessbile.
|
||||
This function will return the coordinates in the physical screen pixels,
|
||||
not in the "stretched" coordinates, which you get when you call SDL_SetVideoMode(640, 480, 0, 0);
|
||||
The physical screen size is returned by SDL_ListModes(NULL, 0)[0].
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_GetAdvertisementParams(int * visible, SDL_Rect * position);
|
||||
/* Control the advertisement placement */
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_SetAdvertisementVisible(int visible);
|
||||
/* Control the advertisement visibility */
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_SetAdvertisementPosition(int left, int top);
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_SetAdvertisementVisible(int visible);
|
||||
/*
|
||||
Control the advertisement placement, you may use constants
|
||||
ADVERTISEMENT_POSITION_RIGHT, ADVERTISEMENT_POSITION_BOTTOM, ADVERTISEMENT_POSITION_CENTER
|
||||
to position the advertisement on the screen without needing to know the advertisment size
|
||||
(which may be reported as zero, if the ad is still not loaded),
|
||||
and to convert between "stretched" and physical coorinates.
|
||||
*/
|
||||
enum {
|
||||
ADVERTISEMENT_POSITION_LEFT = 0,
|
||||
ADVERTISEMENT_POSITION_TOP = 0,
|
||||
ADVERTISEMENT_POSITION_RIGHT = -1,
|
||||
ADVERTISEMENT_POSITION_BOTTOM = -1,
|
||||
ADVERTISEMENT_POSITION_CENTER = -2
|
||||
};
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_SetAdvertisementPosition(int x, int y);
|
||||
|
||||
/* Request a new advertisement to be loaded */
|
||||
extern DECLSPEC int SDLCALL SDL_ANDROID_RequestNewAdvertisement(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ static jmethodID JavaToggleScreenKeyboardWithoutTextInput = NULL;
|
||||
static jmethodID JavaGetAdvertisementParams = NULL;
|
||||
static jmethodID JavaSetAdvertisementVisible = NULL;
|
||||
static jmethodID JavaSetAdvertisementPosition = NULL;
|
||||
static jmethodID JavaRequestNewAdvertisement = NULL;
|
||||
static int glContextLost = 0;
|
||||
static int showScreenKeyboardDeferred = 0;
|
||||
static const char * showScreenKeyboardOldText = "";
|
||||
@@ -299,6 +300,7 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t
|
||||
JavaGetAdvertisementParams = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "getAdvertisementParams", "([I)V");
|
||||
JavaSetAdvertisementVisible = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementVisible", "(I)V");
|
||||
JavaSetAdvertisementPosition = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementPosition", "(II)V");
|
||||
JavaRequestNewAdvertisement = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "requestNewAdvertisement", "()V");
|
||||
|
||||
ANDROID_InitOSKeymap();
|
||||
}
|
||||
@@ -392,3 +394,8 @@ int SDLCALL SDL_ANDROID_SetAdvertisementPosition(int left, int top)
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaSetAdvertisementPosition, (jint)left, (jint)top );
|
||||
return 1;
|
||||
}
|
||||
int SDLCALL SDL_ANDROID_RequestNewAdvertisement(void)
|
||||
{
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaRequestNewAdvertisement );
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user