Android Open Source - Operation-Valkyrie Main Activity






From Project

Back to project page Operation-Valkyrie.

License

The source code is released under:

Terms and conditions Preamble: This Agreement, signed on Jun 10, 2012 [hereinafter: Effective Date] governs the relationship between the Enduser, a private person, (hereinafter: Licensee) and Paul N...

If you think the Android project Operation-Valkyrie 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 valkyrie.ui;
//w  w w.  ja  va 2  s. co  m
import java.io.File;

import valkyrie.file.DecodeBitmaps;
import valkyrie.file.FileManager;
import valkyrie.filter.FilterManager;
import valkyrie.filter.ascii.Ascii;
import valkyrie.main.R;
import valkyrie.ui.gallery.GalleryActivity;
import valkyrie.ui.preview.CameraPreviewViewCV;
import valkyrie.widget.MultiDirectionSlidingDrawer;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.Toast;

/**
 * 
 * COPYRIGHT: Paul Neuhold, Laurenz Theuerkauf, Alexander Ritz, Jakob
 * Schweighofer, Milo Tischler ? Milo Tischler, Jakob Schweighofer, Alexander
 * Ritz, Paul Neuhold, Laurenz Theuerkauf
 * 
 */

/**
 * The application main activity, holds the camera preview, the camera trigger and filter options
 */
public class MainActivity extends Activity {
  private static final String TAG = "MainActivity";

  private FilterManager filterManager = null;
  private MediaPlayer shootSound = null;
  private AudioManager audioManager = null;
  private int volume = 0;
  private FileManager fileManager = null;

  private CameraPreviewViewCV cameraPreview = null;

  /**
   * Initializes the layout, the camera preview, the filter manager, sounds and the layout manager.
   * Sets the activity to fullscreen and warns if the sd card is mounted.
   * 
   * @param Bundle savedInstanceState
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Disable window title bar, for full screen camera preview
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    final Window window = this.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Set activity layout
    this.setContentView(R.layout.main);

    // initialize LayoutManager
    LayoutManager.getInstance().setMainActivity(this);

    // initialize CameraPreviewView with OpenCV
    this.cameraPreview = (CameraPreviewViewCV) this.findViewById(R.id.camera_preview_view);

    // initialize FilterManager
    this.filterManager = new FilterManager(this.getApplicationContext(), R.array.filters, this.cameraPreview);
    this.filterManager.setActiveFilter(new Ascii());

    // initialize FileManager
    this.fileManager = new FileManager(this.getApplicationContext());

    // initialize sound management
    this.shootSound = MediaPlayer.create(this.getApplicationContext(),
        Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));

    this.audioManager = (AudioManager) this.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    this.volume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);

    // check if SD Card is mounted
    String state = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
      Toast.makeText(this.getApplicationContext(), "WARNING: SD Card not mounted!", Toast.LENGTH_SHORT).show();
    }
  }

  /**
   * Takes a picture with the camera and plays the trigger sound / animation. Saves the bitmap to the gallery.
   * 
   * @param View view
   */
  public void takePicture(View view) {
    Log.i(TAG, "clicked: takePicture");

    if (this.cameraPreview.isLocked()) {
      Log.e(TAG, "camera is locked");
      return;
    }

    // Play animation
    ImageButton triggerAnimationSpace = (ImageButton) this.findViewById(R.id.trigger_animation);
    triggerAnimationSpace.setBackgroundResource(R.drawable.trigger_animation);
    AnimationDrawable triggerAnimation = (AnimationDrawable) triggerAnimationSpace.getBackground();
    triggerAnimation.setVisible(false, true);
    triggerAnimation.start();

    // Just a dummy text to appear..
    // Toast.makeText(this.getApplicationContext(), "Take Picture Clicked", Toast.LENGTH_SHORT).show();

    // Play take picture sound effect
    if (volume != 0) {
      this.shootSound.start();
    } else {
      view.playSoundEffect(SoundEffectConstants.CLICK);
    }

    // Actually take picture
    Bitmap bitmap = this.cameraPreview.takePicture();

    if (bitmap == null) {
      Log.e(TAG, "takePicture returned null bitmap");
      this.cameraPreview.resume();
      return;
    }

    // Save image to gallery
    this.fileManager.saveImageToGallery(bitmap);
    DecodeBitmaps.done = false;

    if (bitmap != null) {
      bitmap.recycle();
    }

    this.cameraPreview.resume();
  }

  /**
   * Intent the gallery activity for displaying the already shot pictures if the folder is not empty. 
   * Checks if the picture folder exists and displays the message if the folder is empty. 
   * 
   * @param View view
   */
  public void showGallery(View view) {
    Log.i("TAG", "clicked: showGallery");

    view.playSoundEffect(SoundEffectConstants.CLICK);

    Intent myIntent = new Intent(MainActivity.this, GalleryActivity.class);

    File galleryFiles = new File(Environment.getExternalStorageDirectory() + "/Valkyrie/Gallery/");

    if (galleryFiles.listFiles() != null) {

      if ((galleryFiles.listFiles().length == 0)) {
        Toast.makeText(this.getApplicationContext(), "There are no Pictures to display", Toast.LENGTH_SHORT)
            .show();
        DecodeBitmaps.done = false;
        new DecodeBitmaps(0);
      }
    } else if ((galleryFiles.listFiles() == null)) {
      Toast.makeText(this.getApplicationContext(), "There are no Pictures to display", Toast.LENGTH_SHORT).show();
    }

    if ((galleryFiles.listFiles() != null)) {
      if ((galleryFiles.listFiles().length != 0)) {
        // Just a dummy text to appear..
        DecodeBitmaps.done = false;
        new DecodeBitmaps(0);
        Log.d(TAG, "filelist length :" + galleryFiles.listFiles().length);
        Toast.makeText(this.getApplicationContext(), "Welcome to the Gallery", Toast.LENGTH_SHORT).show();
        view.playSoundEffect(SoundEffectConstants.CLICK);

        try {
          MainActivity.this.startActivity(myIntent);
        } catch (Exception e) {

        }
      }
    }

  }

  /**
   * Toggles the live preview of the filter effect
   * 
   * @param View view
   */
  public void toggleFilterEffect(View view) {
    Log.i("Tag", "clicked: toggleFilterEffect");

    view.playSoundEffect(SoundEffectConstants.CLICK);

    if (this.cameraPreview.isFilterDisplayed()) {

      ImageButton toggle = (ImageButton) this.findViewById(R.id.filter_effect_toggle);
      toggle.setImageResource(R.drawable.preview_on);

      this.cameraPreview.toggleFilter(false);
    } else {

      ImageButton toggle = (ImageButton) this.findViewById(R.id.filter_effect_toggle);
      toggle.setImageResource(R.drawable.preview_off);

      this.cameraPreview.toggleFilter(true);
    }

    // TODO: Reset or delete or reorganize Shared Prefs (options)
  }

  /**
   * If open, closes the filter options
   */
  @Override
  public void onBackPressed() {
    MultiDirectionSlidingDrawer multiDirectionSlidingDrawer = (MultiDirectionSlidingDrawer) this
        .findViewById(R.id.filter_options_panel);

    if (multiDirectionSlidingDrawer.isOpened()) {
      multiDirectionSlidingDrawer.animateClose();
    } else {
      super.onBackPressed();
    }
  }

  /**
   * If open, closes the filter options, else opens the filter options
   * 
   * @param int keyCode
   * @param KeyEvent event
   */
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
    MultiDirectionSlidingDrawer multiDirectionSlidingDrawer = (MultiDirectionSlidingDrawer) this
        .findViewById(R.id.filter_options_panel);

    if (keyCode == KeyEvent.KEYCODE_MENU) {
      if (multiDirectionSlidingDrawer.isOpened()) {
        multiDirectionSlidingDrawer.animateClose();
      } else {
        multiDirectionSlidingDrawer.animateOpen();
      }
    }

    return super.onKeyUp(keyCode, event);
  }

  /**
   * Not implemented
   */
  @Override
  protected void onPause() {
    Log.i(TAG, "onPause called");
    super.onPause();
  }

  /**
   * Not implemented
   */
  @Override
  protected void onResume() {
    Log.i(TAG, "onResume called");    
    super.onResume();
  }

}




Java Source Code List

org.opencv.android.Utils.java
org.opencv.calib3d.Calib3d.java
org.opencv.calib3d.StereoBM.java
org.opencv.calib3d.StereoSGBM.java
org.opencv.core.Algorithm.java
org.opencv.core.Core.java
org.opencv.core.CvException.java
org.opencv.core.CvType.java
org.opencv.core.MatOfByte.java
org.opencv.core.MatOfDMatch.java
org.opencv.core.MatOfDouble.java
org.opencv.core.MatOfFloat4.java
org.opencv.core.MatOfFloat6.java
org.opencv.core.MatOfFloat.java
org.opencv.core.MatOfInt4.java
org.opencv.core.MatOfInt.java
org.opencv.core.MatOfKeyPoint.java
org.opencv.core.MatOfPoint2f.java
org.opencv.core.MatOfPoint3.java
org.opencv.core.MatOfPoint3f.java
org.opencv.core.MatOfPoint.java
org.opencv.core.MatOfRect.java
org.opencv.core.Mat.java
org.opencv.core.Point3.java
org.opencv.core.Point.java
org.opencv.core.Range.java
org.opencv.core.Rect.java
org.opencv.core.RotatedRect.java
org.opencv.core.Scalar.java
org.opencv.core.Size.java
org.opencv.core.TermCriteria.java
org.opencv.features2d.DMatch.java
org.opencv.features2d.DescriptorExtractor.java
org.opencv.features2d.DescriptorMatcher.java
org.opencv.features2d.FeatureDetector.java
org.opencv.features2d.Features2d.java
org.opencv.features2d.GenericDescriptorMatcher.java
org.opencv.features2d.KeyPoint.java
org.opencv.highgui.Highgui.java
org.opencv.highgui.VideoCapture.java
org.opencv.imgproc.Imgproc.java
org.opencv.imgproc.Moments.java
org.opencv.imgproc.Subdiv2D.java
org.opencv.ml.CvANN_MLP_TrainParams.java
org.opencv.ml.CvANN_MLP.java
org.opencv.ml.CvBoostParams.java
org.opencv.ml.CvBoost.java
org.opencv.ml.CvDTreeParams.java
org.opencv.ml.CvDTree.java
org.opencv.ml.CvERTrees.java
org.opencv.ml.CvGBTreesParams.java
org.opencv.ml.CvGBTrees.java
org.opencv.ml.CvKNearest.java
org.opencv.ml.CvNormalBayesClassifier.java
org.opencv.ml.CvParamGrid.java
org.opencv.ml.CvRTParams.java
org.opencv.ml.CvRTrees.java
org.opencv.ml.CvSVMParams.java
org.opencv.ml.CvSVM.java
org.opencv.ml.CvStatModel.java
org.opencv.ml.EM.java
org.opencv.ml.Ml.java
org.opencv.objdetect.CascadeClassifier.java
org.opencv.objdetect.HOGDescriptor.java
org.opencv.objdetect.Objdetect.java
org.opencv.photo.Photo.java
org.opencv.utils.Converters.java
org.opencv.video.BackgroundSubtractorMOG.java
org.opencv.video.BackgroundSubtractor.java
org.opencv.video.KalmanFilter.java
org.opencv.video.Video.java
valkyrie.colorpicker.ColorPickerDialog.java
valkyrie.colorpicker.ColorPicker.java
valkyrie.file.DecodeBitmaps.java
valkyrie.file.FileManager.java
valkyrie.filter.FilterAssets.java
valkyrie.filter.FilterInternalStorage.java
valkyrie.filter.FilterManager.java
valkyrie.filter.FilterUIPosition.java
valkyrie.filter.IFilter.java
valkyrie.filter.ascii.Ascii.java
valkyrie.filter.ascii.Converter.java
valkyrie.filter.ascii.Font.java
valkyrie.filter.ascii.Options.java
valkyrie.filter.canny.Canny.java
valkyrie.filter.grayscale.Grayscale.java
valkyrie.filter.nofilter.NoFilter.java
valkyrie.ui.IUpdateableUI.java
valkyrie.ui.LayoutManager.java
valkyrie.ui.MainActivity.java
valkyrie.ui.UpdateableRelativeLayout.java
valkyrie.ui.gallery.AboutActivity.java
valkyrie.ui.gallery.GalleryActivity.java
valkyrie.ui.gallery.ImageAdapter.java
valkyrie.ui.gallery.ShowPicActivity.java
valkyrie.ui.preview.CameraPreviewViewCV.java
valkyrie.widget.MultiDirectionSlidingDrawer.java
valkyrie.widget.TouchImageView.java