Advertisement
Guest User

chartbooster moai

a guest
May 25th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.74 KB | None | 0 0
  1. package com.ziplinegames.moai;
  2.  
  3. import android.app.Activity;
  4. import android.util.Log;
  5.  
  6. import com.chartboost.sdk.*;
  7. //import com.chartboost.sdk.Chartboost.CBAgeGateConfirmation;
  8. //import com.chartboost.sdk.Chartboost.CBAgeGateConfirmation;
  9. import com.chartboost.sdk.Model.CBError.CBClickError;
  10. import com.chartboost.sdk.Model.CBError.CBImpressionError;
  11.  
  12. class MoaiChartBoost {
  13.  
  14.     protected static native void AKUNotifyChartBoostInterstitialDismissed();
  15.     protected static native void AKUNotifyChartBoostInterstitialLoadFailed();
  16.    
  17.     private static int     ad_step = 0;
  18.     private static  Activity sActivity = null;
  19.     private static  MoaiChartBoost instance = null;
  20.     private static  Chartboost cb;
  21.  
  22.  
  23.     private static ChartboostDelegate delegate = new ChartboostDelegate() {
  24.    
  25.        
  26.         public void dismiss(){
  27.             sActivity.runOnUiThread(new Runnable() {
  28.                 public void run() {    
  29.                             synchronized ( Moai.sAkuLock ) {
  30.                                 AKUNotifyChartBoostInterstitialDismissed();
  31.                             };
  32.                 }
  33.             });
  34.         };
  35.        
  36.         //*********************************************************
  37.         //ADS
  38.        
  39.         @Override
  40.         public void didDismissInterstitial(String location) {
  41.             Log.v("LOG", "didDismissInterstitial");
  42.             dismiss();
  43.            
  44.            
  45.            
  46.            
  47.            
  48.             //AKUNotifyChartBoostInterstitialDismissed();    
  49.         }
  50.  
  51.         @Override
  52.         public void didCloseInterstitial(String location) {
  53.             Log.v("LOG", "didCloseInterstitial");
  54.             dismiss();
  55.             //AKUNotifyChartBoostInterstitialDismissed();
  56.         }
  57.  
  58.         @Override
  59.         public void didClickInterstitial(String location) {
  60.             Log.v("LOG", "didClickInterstitial");
  61.             dismiss();
  62.             //AKUNotifyChartBoostInterstitialDismissed();
  63.         }
  64.  
  65.        
  66.        
  67.         //*********************************************************
  68.         //MORE APPS
  69.        
  70.         // @Override
  71.         public void didDismissMoreApps() {
  72.             Log.v("LOG", "MORE APPS : didDismissMoreApps");
  73.             dismiss();
  74.             //AKUNotifyChartBoostInterstitialDismissed();
  75.         }
  76.  
  77.        // @Override
  78.         public void didCloseMoreApps() {
  79.             Log.v("LOG", "MORE APPS : didCloseMoreApps");
  80.             dismiss();
  81.             //AKUNotifyChartBoostInterstitialDismissed();
  82.         }
  83.  
  84.        // @Override
  85.         public void didClickMoreApps() {
  86.             Log.v("LOG", "MORE APPS : didClickMoreApps");
  87.             dismiss();
  88.             //AKUNotifyChartBoostInterstitialDismissed();
  89.         };
  90.                
  91.        
  92.     };
  93.    
  94.    
  95.    
  96.    
  97.     //*****************************************************************************
  98.     //*****************************************************************************
  99.    
  100.  
  101.     public static void onCreate ( Activity activity ) {
  102.         MoaiLog.i ( "MoaiChartBoost onCreate: Initializing Chartboost" );
  103.         sActivity = activity;
  104.     }
  105.  
  106.     public static void onDestroy () {
  107.         MoaiLog.i ( "MoaiChartBoost onDestroy: Destroying Chartboost service" );
  108.         cb.onDestroy(sActivity);
  109.     }
  110.    
  111. //*****************************************************************************
  112. //*****************************************************************************
  113.     public static void init(final String appId, final String appSignature) {       
  114.    
  115.         sActivity.runOnUiThread(new Runnable() {
  116.             public void run() {    
  117.                    
  118.                 Chartboost.startWithAppId(sActivity, appId, appSignature);                 
  119.                 Chartboost.onStart(sActivity);       
  120.                 Chartboost.setDelegate(delegate);
  121.                 Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);             
  122.                 Chartboost.cacheMoreApps(CBLocation.LOCATION_DEFAULT);         
  123.             }
  124.         });
  125.        
  126.     }
  127.  
  128.    
  129.     //*************************************************************
  130.     public static void showInterstitial(String location) {
  131.                 sActivity.runOnUiThread(new Runnable() {
  132.                     public void run() {
  133.                         Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  134.                 }
  135.                 });
  136.            
  137.     }
  138.  
  139.    
  140.     //*************************************************************
  141.     public static boolean hasCachedInterstitial() {
  142.        
  143.        
  144.        
  145.         boolean hasAd = Chartboost.hasInterstitial(CBLocation.LOCATION_DEFAULT);   
  146.        
  147.         //*************************************************************
  148.         // STATIC
  149.         // VIDEO
  150.         // STATIC
  151.         // GAMES
  152.        
  153.        
  154.        
  155.        
  156.         //**********************************************************
  157.         //hasAd = false;
  158.         ad_step = ad_step + 1;
  159.         if (ad_step >= 3) {
  160.             ad_step = 0;
  161.             hasAd = false;
  162.         };     
  163.         Log.v("LOG", "SHOW MORE APPS: "+hasAd+" "+ad_step);        
  164.        
  165.         //**********************************************************
  166.             if (hasAd== false) {       
  167.                 sActivity.runOnUiThread(new Runnable() {
  168.                     public void run() {                        
  169.                             //SHOW
  170.                             Chartboost.showMoreApps(CBLocation.LOCATION_DEFAULT);
  171.                    
  172.                            
  173.                             //LOAD                         
  174.                             Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT); 
  175.                             Chartboost.cacheMoreApps(CBLocation.LOCATION_DEFAULT);
  176.                        
  177.            
  178.                     }});               
  179.             }; 
  180.            
  181.            
  182.            
  183.            
  184.            
  185.         //**********************************************************   
  186.         //SHOW ADD
  187.             if (hasAd == true) {   
  188.                 sActivity.runOnUiThread(new Runnable() {
  189.                     public void run() {
  190.                         //SHOW
  191.                             Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  192.                         //LOAD
  193.                             Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);             
  194.                             Chartboost.cacheMoreApps(CBLocation.LOCATION_DEFAULT);
  195.                            
  196.                 }
  197.                 });
  198.                
  199.             };
  200.            
  201.             return hasAd;
  202.     }
  203.  
  204.    
  205.    
  206.    
  207.    
  208.     //*************************************************************
  209.     public static void loadInterstitial(String location) {
  210.                 sActivity.runOnUiThread(new Runnable() {
  211.                     public void run() {
  212.                         Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);             
  213.                         Chartboost.cacheMoreApps(CBLocation.LOCATION_DEFAULT);
  214.                     }
  215.                 });
  216.     }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement