com.sponsorpay.sdk.android.publisher
Class SponsorPayPublisher

java.lang.Object
  extended by com.sponsorpay.sdk.android.publisher.SponsorPayPublisher

public class SponsorPayPublisher
extends java.lang.Object

Provides convenience calls to load and show the mobile Offer Wall and the mobile Interstitial.


Nested Class Summary
static class SponsorPayPublisher.UIStringIdentifier
          Enumeration identifying the different messages which can be displayed in the user interface.
 
Field Summary
static int DEFAULT_OFFERWALL_REQUEST_CODE
          The default request code needed for starting the Offer Wall activity.
static java.lang.String PREFERENCES_FILENAME
           
static int PUBLISHER_SDK_INTERNAL_VERSION
          Publisher SDK version number sent to the server on each request.
private static OfferBanner.AdShape sDefaultOfferBannerAdShape
          Default OfferBanner.AdShape used to request Offer Banners to the backend.
private static boolean sShouldUseStagingUrls
           
private static java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.String> sUIStrings
          Messages which can be displayed in the user interface.
 
Constructor Summary
SponsorPayPublisher()
           
 
Method Summary
static Intent getIntentForOfferWallActivity(Context context, java.lang.String userId)
           Returns an Intent that can be used to launch the OfferWallActivity.
static Intent getIntentForOfferWallActivity(Context context, java.lang.String userId, boolean shouldStayOpen)
           Returns an Intent that can be used to launch the OfferWallActivity.
static Intent getIntentForOfferWallActivity(Context context, java.lang.String userId, boolean shouldStayOpen, java.lang.String overrideAppId)
           Returns an Intent that can be used to launch the OfferWallActivity.
static java.lang.String getUIString(SponsorPayPublisher.UIStringIdentifier identifier)
          Gets a particular UI message identified by a SponsorPayPublisher.UIStringIdentifier.
private static void initUIStrings()
          Fills sUIStrings with the default messages.
static void loadShowInterstitial(Activity callingActivity, java.lang.String userId, InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener)
          Starts the mobile interstitial request / loading / showing process using default values for shouldStayOpen, backgroundUrl, skinName, loadingTimeoutSecs and retrieving the application id from the Android Manifest.
static void loadShowInterstitial(Activity callingActivity, java.lang.String userId, InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener, java.lang.Boolean shouldStayOpen)
          Starts the mobile interstitial request / loading / showing process using default values for backgroundUrl, skinName, loadingTimeoutSecs and retrieving the application id from the Android Manifest.
static void loadShowInterstitial(Activity callingActivity, java.lang.String userId, InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener, java.lang.Boolean shouldStayOpen, java.lang.String backgroundUrl, java.lang.String skinName)
          Starts the mobile interstitial request / loading / showing process using a default value for loadingTimeoutSecs and retrieving the application id from the Android Manifest.
static void loadShowInterstitial(Activity callingActivity, java.lang.String userId, InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener, java.lang.Boolean shouldStayOpen, java.lang.String backgroundUrl, java.lang.String skinName, int loadingTimeoutSecs)
          Starts the mobile interstitial request / loading / showing process retrieving the application id from the Android Manifest.
static void loadShowInterstitial(Activity callingActivity, java.lang.String userId, InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener, java.lang.Boolean shouldStayOpen, java.lang.String backgroundUrl, java.lang.String skinName, int loadingTimeoutSecs, java.lang.String overriddenAppId)
          Starts the mobile interstitial request / loading / showing process.
static void requestNewCoins(Context context, java.lang.String userId, SPCurrencyServerListener listener, java.lang.String transactionId, java.lang.String securityToken, java.lang.String applicationId)
          Sends a request to the SponsorPay currency server to obtain the variation in amount of virtual currency for a given user.
static OfferBannerRequest requestOfferBanner(Context context, java.lang.String userId, SPOfferBannerListener listener, OfferBanner.AdShape offerBannerAdShape, java.lang.String currencyName, java.lang.String applicationId)
          Requests an Offer Banner to the SponsorPay servers and registers a listener which will be notified when a response is received.
(package private) static void setCookiesIntoCookieManagerInstance(java.lang.String[] cookies, java.lang.String baseUrl, Context context)
          Sets the provided cookie strings into the application's cookie manager for the given base URL.
static void setCustomUIString(SponsorPayPublisher.UIStringIdentifier identifier, int message, Context context)
          Replaces one of the UI messages with the text identified by an Android String resource id.
static void setCustomUIString(SponsorPayPublisher.UIStringIdentifier identifier, java.lang.String message)
          Replaces one of the UI messages with a custom text.
static void setCustomUIStrings(java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.Integer> messages, Context context)
           
static void setCustomUIStrings(java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.String> messages)
          Replaces one or several of the UI messages at once.
static void setShouldUseStagingUrls(boolean value)
           
static boolean shouldUseStagingUrls()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFERENCES_FILENAME

public static final java.lang.String PREFERENCES_FILENAME
See Also:
Constant Field Values

PUBLISHER_SDK_INTERNAL_VERSION

public static final int PUBLISHER_SDK_INTERNAL_VERSION
Publisher SDK version number sent to the server on each request.

See Also:
Constant Field Values

sUIStrings

private static java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.String> sUIStrings
Messages which can be displayed in the user interface.


sDefaultOfferBannerAdShape

private static OfferBanner.AdShape sDefaultOfferBannerAdShape
Default OfferBanner.AdShape used to request Offer Banners to the backend.


sShouldUseStagingUrls

private static boolean sShouldUseStagingUrls

DEFAULT_OFFERWALL_REQUEST_CODE

public static final int DEFAULT_OFFERWALL_REQUEST_CODE
The default request code needed for starting the Offer Wall activity.

See Also:
Constant Field Values
Constructor Detail

SponsorPayPublisher

public SponsorPayPublisher()
Method Detail

initUIStrings

private static void initUIStrings()
Fills sUIStrings with the default messages.


getUIString

public static java.lang.String getUIString(SponsorPayPublisher.UIStringIdentifier identifier)
Gets a particular UI message identified by a SponsorPayPublisher.UIStringIdentifier.

Parameters:
identifier - The identifier of the message to get.
Returns:
The message string.

setCustomUIString

public static void setCustomUIString(SponsorPayPublisher.UIStringIdentifier identifier,
                                     java.lang.String message)
Replaces one of the UI messages with a custom text.

Parameters:
identifier - The identifier of the message to set.
message - Custom text for the message.

setCustomUIStrings

public static void setCustomUIStrings(java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.String> messages)
Replaces one or several of the UI messages at once.

Parameters:
messages - An EnumMap mapping SponsorPayPublisher.UIStringIdentifiers to the respective desired texts.

setCustomUIString

public static void setCustomUIString(SponsorPayPublisher.UIStringIdentifier identifier,
                                     int message,
                                     Context context)
Replaces one of the UI messages with the text identified by an Android String resource id.

Parameters:
identifier - The SponsorPayPublisher.UIStringIdentifier of the message to replace.
message - An Android String resource identifier.
context - An Android context used to fetch the resource

setCustomUIStrings

public static void setCustomUIStrings(java.util.EnumMap<SponsorPayPublisher.UIStringIdentifier,java.lang.Integer> messages,
                                      Context context)

setShouldUseStagingUrls

public static void setShouldUseStagingUrls(boolean value)

shouldUseStagingUrls

public static boolean shouldUseStagingUrls()

getIntentForOfferWallActivity

public static Intent getIntentForOfferWallActivity(Context context,
                                                   java.lang.String userId)

Returns an Intent that can be used to launch the OfferWallActivity.

Will retrieve the publisher application id from the application manifest.

Parameters:
context - The publisher application context.
userId - The current user ID of the host application.
Returns:
An Android Intent which can be used with the Activity method startActivityForResult() to launch the OfferWallActivity.

getIntentForOfferWallActivity

public static Intent getIntentForOfferWallActivity(Context context,
                                                   java.lang.String userId,
                                                   boolean shouldStayOpen)

Returns an Intent that can be used to launch the OfferWallActivity. Lets the caller specify the behavior of the Offer Wall once the user gets redirected out of the application by clicking on an offer.

Will retrieve the publisher application id from the application manifest.

Parameters:
context - The publisher application context.
userId - The current user ID of the host application.
shouldStayOpen - True if the Offer Wall should stay open after the user clicks on an offer and gets redirected out of the app. False to close the Offer Wall.
Returns:
An Android Intent which can be used with the Activity method startActivityForResult() to launch the OfferWallActivity.

getIntentForOfferWallActivity

public static Intent getIntentForOfferWallActivity(Context context,
                                                   java.lang.String userId,
                                                   boolean shouldStayOpen,
                                                   java.lang.String overrideAppId)

Returns an Intent that can be used to launch the OfferWallActivity. Lets the caller specify the behavior of the Offer Wall once the user gets redirected out of the application by clicking on an offer.

Will use the provided publisher application id instead of trying to retrieve it from the application manifest.

Parameters:
context - The publisher application context.
userId - The current user ID of the host application.
shouldStayOpen - True if the Offer Wall should stay open after the user clicks on an offer and gets redirected out of the app. False to close the Offer Wall.
overrideAppId - An app ID which will override the one included in the manifest.
Returns:
An Android Intent which can be used with the Activity method startActivityForResult() to launch the OfferWallActivity.

loadShowInterstitial

public static void loadShowInterstitial(Activity callingActivity,
                                        java.lang.String userId,
                                        InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener,
                                        java.lang.Boolean shouldStayOpen,
                                        java.lang.String backgroundUrl,
                                        java.lang.String skinName,
                                        int loadingTimeoutSecs,
                                        java.lang.String overriddenAppId)
Starts the mobile interstitial request / loading / showing process.

Parameters:
callingActivity - The activity which requests the interstitial. A progress dialog will be shown on top of it and if an ad is returned, the calling activity will be used to launch the InterstitialActivity in order to show the ad.
userId - The current user ID of the host application.
loadingStatusListener - InterstitialLoader.InterstitialLoadingStatusListener to register to be notified of events in the interstitial lifecycle.
shouldStayOpen - Used to specify the behavior of the interstitial once the user clicks on the presented ad and is redirected outside the host publisher app. The default behavior is to close the interstitial and let the user go back to the activity that called the interstitial when they come back to the app. If you want the interstitial not to close until the user does it explicitly, set this parameter to true.
backgroundUrl - Can be set to the absolute URL of an image to use as background graphic for the interstitial. Must include the protocol scheme (http:// or https://) at the beginning of the URL. Leave it null for no custom background.
skinName - Used to specify the name of a custom skin or template for the requested interstitial. Leaving it null will make the interstitial fall back to the DEFAULT template.
loadingTimeoutSecs - Sets the maximum amount of time the interstitial should take to load. If you set it to 0 or a negative number, it will fall back to the default value of 5 seconds.
overriddenAppId - An app ID which will override the one included in the manifest.

loadShowInterstitial

public static void loadShowInterstitial(Activity callingActivity,
                                        java.lang.String userId,
                                        InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener,
                                        java.lang.Boolean shouldStayOpen,
                                        java.lang.String backgroundUrl,
                                        java.lang.String skinName,
                                        int loadingTimeoutSecs)
Starts the mobile interstitial request / loading / showing process retrieving the application id from the Android Manifest.

Parameters:
callingActivity - The activity which requests the interstitial. A progress dialog will be shown on top of it and if an ad is returned, the calling activity will be used to launch the InterstitialActivity in order to show the ad.
userId - The current user ID of the host application.
loadingStatusListener - InterstitialLoader.InterstitialLoadingStatusListener to register to be notified of events in the interstitial lifecycle.
shouldStayOpen - Used to specify the behavior of the interstitial once the user clicks on the presented ad and is redirected outside the host publisher app. The default behavior is to close the interstitial and let the user go back to the activity that called the interstitial when they come back to the app. If you want the interstitial not to close until the user does it explicitly, set this parameter to true.
backgroundUrl - Can be set to the absolute URL of an image to use as background graphic for the interstitial. Must include the protocol scheme (http:// or https://) at the beginning of the URL. Leave it null for no custom background.
skinName - Used to specify the name of a custom skin or template for the requested interstitial. Leaving it null will make the interstitial fall back to the DEFAULT template.
loadingTimeoutSecs - Sets the maximum amount of time the interstitial should take to load. If you set it to 0 or a negative number, it will fall back to the default value of 5 seconds.

loadShowInterstitial

public static void loadShowInterstitial(Activity callingActivity,
                                        java.lang.String userId,
                                        InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener,
                                        java.lang.Boolean shouldStayOpen,
                                        java.lang.String backgroundUrl,
                                        java.lang.String skinName)
Starts the mobile interstitial request / loading / showing process using a default value for loadingTimeoutSecs and retrieving the application id from the Android Manifest.

Parameters:
callingActivity - The activity which requests the interstitial. A progress dialog will be shown on top of it and if an ad is returned, the calling activity will be used to launch the InterstitialActivity in order to show the ad.
userId - The current user ID of the host application.
loadingStatusListener - InterstitialLoader.InterstitialLoadingStatusListener to register to be notified of events in the interstitial lifecycle.
shouldStayOpen - Used to specify the behavior of the interstitial once the user clicks on the presented ad and is redirected outside the host publisher app. The default behavior is to close the interstitial and let the user go back to the activity that called the interstitial when they come back to the app. If you want the interstitial not to close until the user does it explicitly, set this parameter to true.
backgroundUrl - Can be set to the absolute URL of an image to use as background graphic for the interstitial. Must include the protocol scheme (http:// or https://) at the beginning of the URL. Leave it null for no custom background.
skinName - Used to specify the name of a custom skin or template for the requested interstitial. Leaving it null will make the interstitial fall back to the DEFAULT template.

loadShowInterstitial

public static void loadShowInterstitial(Activity callingActivity,
                                        java.lang.String userId,
                                        InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener,
                                        java.lang.Boolean shouldStayOpen)
Starts the mobile interstitial request / loading / showing process using default values for backgroundUrl, skinName, loadingTimeoutSecs and retrieving the application id from the Android Manifest.

Parameters:
callingActivity - The activity which requests the interstitial. A progress dialog will be shown on top of it and if an ad is returned, the calling activity will be used to launch the InterstitialActivity in order to show the ad.
userId - The current user ID of the host application.
loadingStatusListener - InterstitialLoader.InterstitialLoadingStatusListener to register to be notified of events in the interstitial lifecycle.
shouldStayOpen - Used to specify the behavior of the interstitial once the user clicks on the presented ad and is redirected outside the host publisher app. The default behavior is to close the interstitial and let the user go back to the activity that called the interstitial when they come back to the app. If you want the interstitial not to close until the user does it explicitly, set this parameter to true.

loadShowInterstitial

public static void loadShowInterstitial(Activity callingActivity,
                                        java.lang.String userId,
                                        InterstitialLoader.InterstitialLoadingStatusListener loadingStatusListener)
Starts the mobile interstitial request / loading / showing process using default values for shouldStayOpen, backgroundUrl, skinName, loadingTimeoutSecs and retrieving the application id from the Android Manifest.

Parameters:
callingActivity - The activity which requests the interstitial. A progress dialog will be shown on top of it and if an ad is returned, the calling activity will be used to launch the InterstitialActivity in order to show the ad.
userId - The current user ID of the host application.
loadingStatusListener - InterstitialLoader.InterstitialLoadingStatusListener to register to be notified of events in the interstitial lifecycle.

requestNewCoins

public static void requestNewCoins(Context context,
                                   java.lang.String userId,
                                   SPCurrencyServerListener listener,
                                   java.lang.String transactionId,
                                   java.lang.String securityToken,
                                   java.lang.String applicationId)
Sends a request to the SponsorPay currency server to obtain the variation in amount of virtual currency for a given user. Returns immediately, and the answer is delivered to one of the provided listener's callback methods. See SPCurrencyServerListener.

Parameters:
context - Android application context.
userId - The ID of the user for which the delta of coins will be requested.
listener - SPCurrencyServerListener which will be notified of the result of the request.
transactionId - Optionally, provide the ID of the latest known transaction. The delta of coins will be calculated from this transaction (not included) up to the present. Leave it to null to let the SDK use the latest transaction ID it kept track of.
securityToken - Security Token associated with the provided Application ID. It's used to sign the requests and verify the server responses.
applicationId - Application ID assigned by SponsorPay. Provide null to read the Application ID from the Application Manifest.

requestOfferBanner

public static OfferBannerRequest requestOfferBanner(Context context,
                                                    java.lang.String userId,
                                                    SPOfferBannerListener listener,
                                                    OfferBanner.AdShape offerBannerAdShape,
                                                    java.lang.String currencyName,
                                                    java.lang.String applicationId)
Requests an Offer Banner to the SponsorPay servers and registers a listener which will be notified when a response is received.

Parameters:
context - Android application context.
userId - The ID of the user for whom the banner will be requested.
listener - SPOfferBannerListener which will be notified of the results of the request.
offerBannerAdShape - Provide null for this parameter to request a banner of the default dimensions (320 x 50).
currencyName - The name of the currency employed by your application. Provide null if you don't use a custom currency name.
applicationId - Your Application ID, or null to retrieve it from your application manifest.
Returns:
An OfferBannerRequest instance which manages the request to the server on the background.

setCookiesIntoCookieManagerInstance

static void setCookiesIntoCookieManagerInstance(java.lang.String[] cookies,
                                                java.lang.String baseUrl,
                                                Context context)
Sets the provided cookie strings into the application's cookie manager for the given base URL.

Parameters:
cookies - An array of cookie strings.
baseUrl - The base URL to set the cookies for.
context - Android application context.