Android Open Source - ScalAR Custom Activity






From Project

Back to project page ScalAR.

License

The source code is released under:

GNU General Public License

If you think the Android project ScalAR 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 edu.dhbw.andar.pub;
//from ww  w. j  a v  a2s  . c o  m
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

import edu.dhbw.andar.ARToolkit;
import edu.dhbw.andar.AndARActivity;
import edu.dhbw.andar.exceptions.AndARException;
import edu.dhbw.andarmodelviewer.R;

/**
 * Example of an application that makes use of the AndAR toolkit.
 * @author Tobi
 *
 */
public class CustomActivity extends AndARActivity {
  
  private final int MENU_SCREENSHOT = 0;

  CustomObject someObject;
  ARToolkit artoolkit;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    CustomRenderer renderer = new CustomRenderer();//optional, may be set to null
    super.setNonARRenderer(renderer);//or might be omited
    try {
      artoolkit = super.getArtoolkit();
      someObject = new CustomObject
        ("test", "barcode.patt", 80.0, new double[]{0,0});
      artoolkit.registerARObject(someObject);
      someObject = new CustomObject
      ("test", "android.patt", 80.0, new double[]{0,0});
      artoolkit.registerARObject(someObject);
      //someObject = new CustomObject
      //("test", "barcode.patt", 80.0, new double[]{0,0});
      //artoolkit.registerARObject(someObject);
      
    } catch (AndARException ex){
      //handle the exception, that means: show the user what happened
      System.out.println("");
    }      
  }

  /**
   * Inform the user about exceptions that occurred in background threads.
   * This exception is rather severe and can not be recovered from.
   * Inform the user and shut down the application.
   */
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {
    Log.e("AndAR EXCEPTION", ex.getMessage());
    finish();
  }  
  
  
  /* (non-Javadoc)
   * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
   */
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {    
    menu.add(0, MENU_SCREENSHOT, 0, getResources().getText(R.string.take_screenshot))
    .setIcon(R.drawable.screenshoticon);
    return true;
  }
  
  /* (non-Javadoc)
   * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
   */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    /*if(item.getItemId()==1) {
      artoolkit.unregisterARObject(someObject);
    } else if(item.getItemId()==0) {
      try {
        someObject = new CustomObject
        ("test", "patt.hiro", 80.0, new double[]{0,0});
        artoolkit.registerARObject(someObject);
      } catch (AndARException e) {
        e.printStackTrace();
      }
    }*/
    switch(item.getItemId()) {
    case MENU_SCREENSHOT:
      new TakeAsyncScreenshot().execute();
      break;
    }
    return true;
  }
  
  class TakeAsyncScreenshot extends AsyncTask<Void, Void, Void> {
    
    private String errorMsg = null;

    @Override
    protected Void doInBackground(Void... params) {
      Bitmap bm = takeScreenshot();
      FileOutputStream fos;
      try {
        fos = new FileOutputStream("/sdcard/AndARScreenshot"+new Date().getTime()+".png");
        bm.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();          
      } catch (FileNotFoundException e) {
        errorMsg = e.getMessage();
        e.printStackTrace();
      } catch (IOException e) {
        errorMsg = e.getMessage();
        e.printStackTrace();
      }  
      return null;
    }
    
    protected void onPostExecute(Void result) {
      if(errorMsg == null)
        Toast.makeText(CustomActivity.this, getResources().getText(R.string.screenshotsaved), Toast.LENGTH_SHORT ).show();
      else
        Toast.makeText(CustomActivity.this, getResources().getText(R.string.screenshotfailed)+errorMsg, Toast.LENGTH_SHORT ).show();
    };
    
  }
  
  
}




Java Source Code List

com.skylion.speech.GoogleTranslate.java
com.skylion.speech.Narrator.java
com.skylion.speech.Synthesiser.java
edu.dhbw.andar.ARObject.java
edu.dhbw.andar.ARToolkit.java
edu.dhbw.andar.AndARActivity.java
edu.dhbw.andar.AndARRenderer.java
edu.dhbw.andar.CameraHolder.java
edu.dhbw.andar.CameraParameters.java
edu.dhbw.andar.CameraPreviewHandler.java
edu.dhbw.andar.CameraStatus.java
edu.dhbw.andar.Config.java
edu.dhbw.andar.GenericFunctions.java
edu.dhbw.andar.exceptions.AndARException.java
edu.dhbw.andar.exceptions.AndARRuntimeException.java
edu.dhbw.andar.interfaces.MarkerVisibilityListener.java
edu.dhbw.andar.interfaces.OpenGLRenderer.java
edu.dhbw.andar.interfaces.PreviewFrameSink.java
edu.dhbw.andar.pub.CustomActivity.java
edu.dhbw.andar.pub.CustomObject.java
edu.dhbw.andar.pub.CustomRenderer.java
edu.dhbw.andar.pub.SimpleBox.java
edu.dhbw.andar.util.GraphicsUtil.java
edu.dhbw.andar.util.IO.java
edu.dhbw.andobjviewer.AugmentedModelViewerActivity.java
edu.dhbw.andobjviewer.CheckFileManagerActivity.java
edu.dhbw.andobjviewer.Config.java
edu.dhbw.andobjviewer.InstructionsActivity.java
edu.dhbw.andobjviewer.ModelChooser.java
edu.dhbw.andobjviewer.graphics.LightingRenderer.java
edu.dhbw.andobjviewer.graphics.Model3D.java
edu.dhbw.andobjviewer.graphics.Renderer.java
edu.dhbw.andobjviewer.models.Group.java
edu.dhbw.andobjviewer.models.Material.java
edu.dhbw.andobjviewer.models.Model.java
edu.dhbw.andobjviewer.models.Vector3D.java
edu.dhbw.andobjviewer.parser.MtlParser.java
edu.dhbw.andobjviewer.parser.ObjParser.java
edu.dhbw.andobjviewer.parser.ParseException.java
edu.dhbw.andobjviewer.parser.SimpleTokenizer.java
edu.dhbw.andobjviewer.parser.Util.java
edu.dhbw.andobjviewer.util.ArrayIterator.java
edu.dhbw.andobjviewer.util.AssetsFileUtil.java
edu.dhbw.andobjviewer.util.BaseFileUtil.java
edu.dhbw.andobjviewer.util.FixedPointUtils.java
edu.dhbw.andobjviewer.util.MatrixUtils.java
edu.dhbw.andobjviewer.util.MemUtil.java
edu.dhbw.andobjviewer.util.SDCardFileUtil.java