Android Open Source - libgdx-sample Android Dependent Methods






From Project

Back to project page libgdx-sample.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project libgdx-sample 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 ch.epfl.chili.libgdx_sample.android;
/*from  w  w w . j a  v  a 2s . c  o m*/
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

import ch.epfl.chili.libgdx_sample.PlatformDependentMethods;
import android.content.Context;
import android.util.Log;

/**
 * Container for Android dependent simple methods
 * @author Ayberk zgr
 */
public class AndroidDependentMethods implements PlatformDependentMethods {

  private Context context;
  private Scanner scanner;
  
  /**
   * Creates a new Android dependents method holder.
   * @param context The Android context needed by the platform dependent code
   */
  public AndroidDependentMethods(Context context){
    this.context = context;
  }
  
  @Override
  public String Chilitags_getTagConfigFilename() {
    
    //Get the tag_configuration.yml file bundled with our apk and write it to a location accessible by the native code
    try {
      
      scanner = new Scanner(context.getAssets().open("tag_configuration.yml"));
      Scanner configScanner = scanner.useDelimiter("\\A");
      byte[] configBytes = (configScanner.hasNext() ? configScanner.next() : "").getBytes();
      configScanner.close();
      FileOutputStream newConfigFile = context.openFileOutput("tag_configuration.yml", Context.MODE_PRIVATE);
      newConfigFile.write(configBytes);
      newConfigFile.close();
      
      //Return the absolute path of the newly created configuration file
      return context.getFilesDir() + "/tag_configuration.yml";
      
    } catch (IOException e1) {
      
      //There was no tag_configuration.yml in the assets
      e1.printStackTrace();
      return null;
    }
  }

  @Override
  public String Chilitags_getCalibrationFilename() {
    //TODO DO THE SAME THING AS WITH GETCONFIGFILENAME
    return null;
  }
  
  @Override
  public void print(String message) {
    Log.i("AndroidDependentMethods.print",message);
  }

}




Java Source Code List

ch.epfl.chili.libgdx_sample.DeviceCameraController.java
ch.epfl.chili.libgdx_sample.IOSLauncher.java
ch.epfl.chili.libgdx_sample.LibgdxSample.java
ch.epfl.chili.libgdx_sample.PlatformDependentMethods.java
ch.epfl.chili.libgdx_sample.android.AndroidCameraController.java
ch.epfl.chili.libgdx_sample.android.AndroidDependentMethods.java
ch.epfl.chili.libgdx_sample.android.MainActivity.java
ch.epfl.chili.libgdx_sample.client.HtmlLauncher.java
ch.epfl.chili.libgdx_sample.desktop.DesktopCameraController.java
ch.epfl.chili.libgdx_sample.desktop.DesktopDependentMethods.java
ch.epfl.chili.libgdx_sample.desktop.Main.java
ch.epfl.chili.libgdx_sample.util.Size2D.java