Android Open Source - playnomics-android Playnomics Test App Activity






From Project

Back to project page playnomics-android.

License

The source code is released under:

Apache License

If you think the Android project playnomics-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.playnomics;
/*w  w w .  j  a v  a 2 s  . c  o m*/
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.playnomics.android.sdk.IGoogleCloudMessageConfig;
import com.playnomics.android.sdk.IPushNotificationDelegate;
import com.playnomics.android.sdk.Playnomics;
import com.playnomics.android.sdk.IPlaynomicsSegmentationDelegate;
import com.playnomics.android.util.Logger.LogLevel;

public class PlaynomicsTestAppActivity 
  extends Activity 
  implements IGoogleCloudMessageConfig, IPushNotificationDelegate, IPlaynomicsSegmentationDelegate {
  
  private static final int PICTURE_RESULT = 0;
  private static boolean preloaded = false;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    final long applicationId = 2143315484923938870L;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    Playnomics.setLogLevel(LogLevel.VERBOSE);
    //Playnomics.setTestMode(false);
    Playnomics.start(this, applicationId, "5818fa2f3e0094c2");
    Playnomics.enablePushNotifications(this, this);
    
    if(!preloaded){
      //only preload once
      Playnomics.preloadPlacements("44841d6a2bcec8c9", "a40893b36c6ddb32", "67dbfcad37eccbf9", "5bc049bb66ffc121", "e45c59f627043701");
      preloaded = true;
    }
  }
  
  @Override
  protected void onResume() {
    Playnomics.onActivityResumed(this);
    super.onResume();
  }
  
  @Override
  protected void onPause() {
    Playnomics.onActivityPaused(this);
    super.onPause();
  }

  public void onUserInfoClick(View view) {
    String source = "source";
    String campaign = "campaign";
    GregorianCalendar cal = new GregorianCalendar();
    Date installDate = cal.getTime();
    
    Playnomics.attributeInstall(source, campaign, installDate);
  }
  
  public void onTransactionClick(View view) {
    float price = 0.99f;
    int quantity = 1;
    Playnomics.transactionInUSD(price, quantity);
  }

  public void onMilestoneClick(View view) {
    String eventName = "my event";
    Playnomics.customEvent(eventName);
  }

  public void onHttpClick(View view){
    setupPlacement("44841d6a2bcec8c9");
  }
  
  public void onJsonClick(View view){
    setupPlacement("a40893b36c6ddb32");
  }
  
  public void onNullTargetClick(View view){
    setupPlacement("67dbfcad37eccbf9");
  }
  
  public void onNoAdsClick(View view){
    setupPlacement("5bc049bb66ffc121");
  }
  
  public void onThirdPartyAdClick(View view){
     setupPlacement("e45c59f627043701");
  }
  
  public void onFetchUserSegementIdsClick(View view){
    Playnomics.fetchUserSegmentIds(this);
  }

  public void onLaunchMoreTest(View view){
    Intent moreTest = new Intent(this, PlaynomicsMoreTestActivity.class);   
        this.startActivityForResult(moreTest, PICTURE_RESULT);
  }

  private void setupPlacement (String placementName){
    RichDataFrameDelegate delegate = new RichDataFrameDelegate(placementName, getApplicationContext());
    Playnomics.showPlacement(placementName, this, delegate);
  }

  @Override
  public Class<?> getNotificationDestination() {
    return PlaynomicsTestAppActivity.class;
  }

  @Override
  public int getNotificationIcon() {
    return R.drawable.ic_launcher;
  }

  @Override
  public String getSenderId() {
    return "463115531919";
  }

  @Override
  public void onPushRegistrationSuccess(String registrationId) {
    Log.d(this.getClass().getName(), String.format("Registered device %s", registrationId));
  }

  @Override
  public void onPushRegistrationFailure() {
    Log.e(this.getClass().getName(), "Failed to register device");
  }

  @Override
  public void onPushRegistrationFailure(Exception ex) {
    Log.e(this.getClass().getName(), "Failed to register device", ex);
  }

  @Override
  public void onPushRegistrationFailure(int errorCode) {
    final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    Log.e(this.getClass().getName(), "Failed to register device, GooglePlayServices is out of date");
    
    if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST);
            
            if(dialog != null){
              dialog.show();
            }
        }
  }

  @Override
  public void onFetchedUserSegmentIds(List<Long> segmentationIds) {
    Log.d(this.getClass().getName(), String.format("UserSegmentIds %s", segmentationIds==null?"null":segmentationIds.toString()));
    postToastMessage("UserSegmentIds " + segmentationIds==null?"null":segmentationIds.toString());
  }

  @Override
  public void onFetchedUserSegmentIdsError(String error, String description) {
    Log.d(this.getClass().getName(), String.format("Error UserSegmentIds  %s", error==null?"null":error));
    postToastMessage("Error UserSegmentIds " + error + " " + description);
  }

  public void postToastMessage(final String message){
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(getApplicationContext(), message, duration);
    toast.show();
  }

}




Java Source Code List

com.playnomics.PlaynomicsMoreTestActivity.java
com.playnomics.PlaynomicsTestAppActivity.java
com.playnomics.RichDataFrameDelegate.java
com.playnomics.android.client.AssetClient.java
com.playnomics.android.client.EventQueue.java
com.playnomics.android.client.EventWorker.java
com.playnomics.android.client.HttpConnectionFactory.java
com.playnomics.android.client.IEventQueue.java
com.playnomics.android.client.IEventWorker.java
com.playnomics.android.client.IHttpConnectionFactory.java
com.playnomics.android.client.PlacementDataClient.java
com.playnomics.android.client.SegmentationClient.java
com.playnomics.android.events.AppPageEvent.java
com.playnomics.android.events.AppPauseEvent.java
com.playnomics.android.events.AppResumeEvent.java
com.playnomics.android.events.AppRunningEvent.java
com.playnomics.android.events.AppStartEvent.java
com.playnomics.android.events.CustomEvent.java
com.playnomics.android.events.ExplicitEvent.java
com.playnomics.android.events.ImplicitEvent.java
com.playnomics.android.events.PlaynomicsEvent.java
com.playnomics.android.events.TransactionEvent.java
com.playnomics.android.events.UserInfoEvent.java
com.playnomics.android.messaging.CloseButton.java
com.playnomics.android.messaging.HtmlAdFactory.java
com.playnomics.android.messaging.HtmlAd.java
com.playnomics.android.messaging.HtmlCloseButton.java
com.playnomics.android.messaging.MessagingManager.java
com.playnomics.android.messaging.NativeCloseButton.java
com.playnomics.android.messaging.Placement.java
com.playnomics.android.messaging.Position.java
com.playnomics.android.messaging.Target.java
com.playnomics.android.messaging.ui.IPlayViewFactory.java
com.playnomics.android.messaging.ui.PlayDialog.java
com.playnomics.android.messaging.ui.PlayViewFactory.java
com.playnomics.android.messaging.ui.PlayWebView.java
com.playnomics.android.messaging.ui.RenderTaskFactory.java
com.playnomics.android.push.GcmBroadcastReceiver.java
com.playnomics.android.push.GcmIntentService.java
com.playnomics.android.push.GcmManager.java
com.playnomics.android.sdk.IGoogleCloudMessageConfig.java
com.playnomics.android.sdk.IPlacementDelegate.java
com.playnomics.android.sdk.IPlaynomicsPlacementDelegate.java
com.playnomics.android.sdk.IPlaynomicsPlacementRawDelegate.java
com.playnomics.android.sdk.IPlaynomicsSegmentationDelegate.java
com.playnomics.android.sdk.IPushConfig.java
com.playnomics.android.sdk.IPushNotificationDelegate.java
com.playnomics.android.sdk.Playnomics.java
com.playnomics.android.segments.UserSegmentIds.java
com.playnomics.android.session.ActivityObserver.java
com.playnomics.android.session.GameSessionInfo.java
com.playnomics.android.session.HeartBeatHandler.java
com.playnomics.android.session.HeartBeatProducer.java
com.playnomics.android.session.IActivityObserver.java
com.playnomics.android.session.ICallbackProcessor.java
com.playnomics.android.session.IHeartBeatProducer.java
com.playnomics.android.session.SessionStateMachine.java
com.playnomics.android.session.Session.java
com.playnomics.android.session.TouchEventHandler.java
com.playnomics.android.session.WindowCallbackProxy.java
com.playnomics.android.util.AndroidLogger.java
com.playnomics.android.util.AsyncTaskRunner.java
com.playnomics.android.util.CacheFile.java
com.playnomics.android.util.Config.java
com.playnomics.android.util.ContextWrapper.java
com.playnomics.android.util.EventTime.java
com.playnomics.android.util.IAsyncCall.java
com.playnomics.android.util.IConfig.java
com.playnomics.android.util.IRandomGenerator.java
com.playnomics.android.util.LargeGeneratedId.java
com.playnomics.android.util.LogWriter.java
com.playnomics.android.util.Logger.java
com.playnomics.android.util.Util.java