Android Open Source - addlive-android-sdk-tutorials Tutorial1






From Project

Back to project page addlive-android-sdk-tutorials.

License

The source code is released under:

Copyright (c) 2012 LiveFoundry Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the S...

If you think the Android project addlive-android-sdk-tutorials 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.addlive.tutorials;
//  w  ww  . j av  a  2s .c om
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.graphics.Color;
import android.util.Log;
import android.widget.TextView;

import com.addlive.platform.*;
import com.addlive.service.*;

public class Tutorial1 extends Activity {

  /**
  * ===========================================================================
  * Constants
  * ===========================================================================
  */

  private static final long ADL_APP_ID = 1; // TODO set your app ID here.
  private static final String LOG_TAG = "AddLiveTutorial";
    
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tutorial1);
    
    // Framework initialization.
    initializeAddLive();
  }

  /**
  * ===========================================================================
  * AddLive Platform initialization
  * ===========================================================================
  */

  private void initializeAddLive() {
    
    // ADL.init listener.
    PlatformInitListener listener = new PlatformInitListener() {
      @Override
      public void onInitProgressChanged(InitProgressChangedEvent e) {
        // Actually not used by the platform for now. Just a placeholder.
      }

      @Override
      public void onInitStateChanged(InitStateChangedEvent e) {

        if (e.getState() == InitState.INITIALIZED) {
          
          // Successfully initialized.
          onAdlInitialized();
          } else {
            
            // Unsuccessfully initialized.
            onAdlInitError(e);
          }
      }
    };
    
    // Describes the options allowing platform initialization.
    PlatformInitOptions initOptions = new PlatformInitOptions();
      String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
      
      // Sets the path where platform should look for the native components of the AddLive SDK.
      initOptions.setStorageDir(storageDir);
      
      // Sets the value of the applicationId property.
      initOptions.setApplicationId(ADL_APP_ID);
      
      Log.d(LOG_TAG, "Initializing the AddLive SDK.");
      
      /* Initializes the AddLive ADL. The process is asynchronous and 
       * initialization state changes and progress updates are reported via the
       * listener provided.
       */
      ADL.init(listener, initOptions, this);
  }

  // ===========================================================================

  private void onAdlInitialized() {
    Log.d(LOG_TAG, "AddLive SDK initialized");

    /* getService - Returns a reference to the implementation of the 
     * AddLiveService interface.
     * 
     * getVersion - Returns a version of currently used Service.
     */
      ADL.getService().getVersion(new UIThreadResponder<String>(this) {
        @Override
        protected void handleResult(String version) {
          Log.d(LOG_TAG, "AddLive SDK version: " + version);
          
          // Setting the SDK version on it's label.
          TextView versionLabel = (TextView) findViewById(R.id.sdkVersion);
          versionLabel.setTextColor(Color.GREEN);
          versionLabel.setText(version);
        }

        @Override
        protected void handleError(int errCode, String errMessage) {
          Log.e(LOG_TAG, "Failed to get version string.");
        }
      });
  }

  // ===========================================================================

  private void onAdlInitError(InitStateChangedEvent e) {

    // Setting the error on it's label.
      TextView status = (TextView) findViewById(R.id.error);
      status.setTextColor(Color.RED);
      String errMessage = "ERROR: (" + e.getErrCode() + ") " +
          e.getErrMessage();
      status.setText(errMessage);

      Log.e(LOG_TAG, errMessage);
  }
}




Java Source Code List

com.addlive.tutorials.Tutorial1.java
com.addlive.tutorials.Tutorial2.java
com.addlive.tutorials.Tutorial3.java
com.addlive.tutorials.Tutorial4_1.java
com.addlive.tutorials.Tutorial4.java
com.addlive.tutorials.Tutorial5.java
com.addlive.tutorials.Tutorial6.java
com.addlive.tutorials.Tutorial7.java