A. Show Offerwall

 * In 'Testing' state, you have to register your device as testing device in order to get ads displayed in your offerwall.

1) Set user name

You have to set user identification string using this API. Login Id is good for identification string.
If you don't have any user identification string, device Id will be fine for this. But please be sure to encrypt these strings when you are to use user's privacy data for identification string such as device Id, phone number and email.

These user identification strings are sent back to your server in parameters of callbacks and you can identify users using these strings. See 
1.6 Callback URL for detail.
(If you set 'Point Management' as 'Managed by Tnk' in the page of publishing configuration, you may skip this step.)

Method 
  - void TnkSession.setUserName(Context context, String userName)

Parameters
 Name  Description
 context  Activity or Context object 
 userName  User identification String (less than 256 bytes)

2) Show Offerwall (Activity)

Launch a offerwall activity. 

Method
  - void TnkSession.showAdList(Context context)
  - void TnkSession.showAdList(Context context, String title)
  - void TnkSession.showAdList(Context context, String title, TnkLayout userLayout)

Parameters
Parameter  Description
 context Activity or Context object.
 title  Title displayed in the offerwall.
 (Default : 'Get free points') 
 userLayout  TnkLayout object representing your own design. See D. Design your Offerwall for Detail.

Sample Code

@Override

public void onCreate(Bundle savedInstanceState) {

    // ...

    final Button button = (Button)findViewById(R.id.main_ad);

    button.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            TnkSession.showAdList(MainActivity.this,"Your title here");

        }

    });




3) Show Offerwall (View)

Launch a offer wall as popup view.
Method
  - void TnkSession.popupAdList(Activity activity)
  - void TnkSession.popupAdList(Activity activity, String title)
  - void TnkSession.popupAdList(Activity activity, String title, TnkAdListener listener)
  - void TnkSession.popupAdList(Activity activity, String title, TnkAdListener listener, TnkLayout userLayout)

Parameters
Parameter  Description
 activity Activity object 
 title  Title displayed in the offerwall.
 (Default : 'Get free points')
 listnener  TnkAdListener object for event handling
 userLayout  TnkLayout object representing your own design. See D. Design your Offerwall for Detail.

Sample Code

@Override

public void onCreate(Bundle savedInstanceState) {

    // ...

    final Button button = (Button)findViewById(R.id.main_ad);

    button.setOnClickListener(new OnClickListener() {

        @Override

        public void onClick(View v) {

            TnkSession.popupAdList(MainActivity.this,"Your title here");

        }

    });



4) AdListView

AdListView is a View that provides offerwall functions. Developers can create a AdListView object using createAdListView() API.

- creating AdListView

Method
  - AdListView TnkSession.createAdListView(Context context, boolean popupStyle)
  - AdListView TnkSession.createAdListView(Context context, TnkLayout userLayout)

Parameters
 Parameter  Description
 context  Activity or Context object 
 popupStyle  Popup style (true) or Full screen style (false)
 userLayout  TnkLayout object representing your own design. See D. Design your Offerwall for Detail.

5) APIs for AdListview

- void loadAdList()
  • Load ads from server and display them.
  • If you embedded AdListView in your view, call loadAdList() to ads get loaded and displayed. 
- void show(Activity activity)
  • Popup AdListView in the current Activity. (using Activity.addContentView() method.)
  • Animation effect is applied when showing and disappearing. See setAnimationType() method below.
  • loadAdList() is called after animation effect is completed.
- void setTitle(String title)
  • Set title in the header of offerwall.
- void setListener(TnkAdListener listener) 
  • Set TnkAdListener object to get notified events when offerwall is shown or closed.
  • TnkAdListener only works when AdListView shows up as popup using show() method.
- void setAnimationType(int showType, int hideType)
  • Set animation type for showing and disappearing AdListView popup.
  • Animation only works when AdListView shows up as popup using show() method.
  • Available animations are as bellows.
 Constants show  disappear 
 TnkSession.ANIMATION_RANDOM Random animation Random animation
 TnkSession.ANIMATION_NONE No animation No animation
 TnkSession.ANIMATION_ALPHA  Fade in animation Fade out animation
 TnkSession.ANIMATION_BOTTOM Slide up from bottom Slide out to bottom
 TnkSession.ANIMATION_TOP Slide down from top Slide out to top
 TnkSession.ANIMATION_LEFT Slide in from left Slide out to left
 TnkSession.ANIMATION_RIGHT Slide in from right Slide out to right
 TnkSession.ANIMATION_SPIN Grow up & spinning Shrinking & spinning
 TnkSession.ANIMATION_FLIP Flip round from left Flip round to right

Sample code

Popup sample

    AdListView adlistView = TnkSession.createAdListView(MainActivity.this, true);

    adlistView.setListener(new TnkAdListener() {

  @Override

  public void onClose(int type) {

  Log.d("tnkad", "#### onClose " + type);

  }


  @Override

  public void onShow() {

  Log.d("tnkad", "#### onShow "); 

  }


  @Override

  public void onFailure(int errCode) {

  }


  @Override

  public void onLoad() {

  }

        });

    

    adlistView.setTitle("Get Free Coins!!");

    

    adlistView.setAnimationType(TnkSession.ANIMATION_BOTTOM, TnkSession.ANIMATION_BOTTOM);


    adlistView.show(MainActivity.this);


Embed Sample

    AdListView adlistView = TnkSession.createAdListView(MainActivity.this, true);

    adlistView.setTitle("Get Free Coins!!");

    

    ViewGroup viewGroup = (ViewGroup)findViewById(R.id.adlist);

    viewGroup.addView(adlistView);

    

    adlistView.loadAdList();

5) TnkAdListener

If you want to get notified when AdListView is shown and disappears, use TnkAdListener interface.
TnkAdListener is originally invented for Interstitial Ad (see 4. Interstitial Ad) but you can also use for AdListview only for onShow() and onClose() event. 

TnkAdListener Interface

public interface TnkAdListener {


// User closed view by clicking close button or pressing back-key

public static final int CLOSE_SIMPLE = 0;


// User clicked an ad in the view

public static final int CLOSE_CLICK = 1;


// User clicked 'exit' button in the view

public static final int CLOSE_EXIT = 2;

public static final int FAIL_NO_AD = -1;  // no ad available

public static final int FAIL_NO_IMAGE = -2; // ad image not available

public static final int FAIL_TIMEOUT = -3; // ad arrived after 5 secs.

public static final int FAIL_CANCELED = -4; // ad frequency settings 

public static final int FAIL_SYSTEM = -9;


/**

* Invoked when popup view is closed 

 * Reason type is passed in type parameter.

* @param type 

*/

public void onClose(int type);

/**

 * Invoke when popup view is shown up.

 */

public void onShow();

public void onFailure(int errCode);

public void onLoad();

}


  • onClose(int type) : Invoked when popup view is closed. The reason code is passed in type parameter.
    • CLOSE_SIMPLE (0) : User closed view by clicking close button or pressing back-key.
    • CLOSE_CLICK (1) : User clicked an ad in the view.
  • onShow() : Invoked when popup view is shown up.
  • AdListView only provide onShow() and onClose() events.
Comments