Back to project page ScalAR.
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.
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(); }; } }