Android Open Source - daisy_main Activity Annotation






From Project

Back to project page daisy_main.

License

The source code is released under:

GNU General Public License

If you think the Android project daisy_main 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 de.uvwxy.daisy.nodemap.gui;
//from www  . jav  a  2  s .co  m
import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
import de.uvwxy.daisy.nodemap.R;
import de.uvwxy.daisy.nodemap.guicontent.CM;
import de.uvwxy.daisy.proto.Messages.Annotation;
import de.uvwxy.daisy.protocol.DaisyData;
import de.uvwxy.daisy.protocol.busmessages.NeedsSync;

public class ActivityAnnotation extends Activity {
  private static final String LOG_TAG = "ActivityAnnotation";

  private static String mFileName = null;
  private MediaRecorder mRecorder = null;
  private MediaPlayer mPlayer = null;

  private ToggleButton tbtnAnnotationRecording;
  private ToggleButton tbtnAnnotationPlayback;
  private Button btnAnnotationSave;
  private EditText etAnnotationText;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_annotation);

    mFileName = CM.DAISY.getDeploymentPath(DaisyData.DAISY_RECORDINGS_FOLDER) + "recording_" + System.currentTimeMillis() + ".amr";

    tbtnAnnotationPlayback = (ToggleButton) findViewById(R.id.tbtnAnnotationPlayback);
    tbtnAnnotationRecording = (ToggleButton) findViewById(R.id.tbtnAnnotationRecording);
    btnAnnotationSave = (Button) findViewById(R.id.btnAnnotationSave);
    etAnnotationText = (EditText) findViewById(R.id.etAnnotationText);

    btnAnnotationSave.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        save();
      }
    });

    tbtnAnnotationRecording.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if (!tbtnAnnotationRecording.isChecked()) {
          stopRecording();
          tbtnAnnotationPlayback.setEnabled(true);
        } else {
          startRecording();
          tbtnAnnotationPlayback.setEnabled(false);
        }
      }
    });

    tbtnAnnotationPlayback.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if (!tbtnAnnotationPlayback.isChecked()) {
          stopPlaying();
          tbtnAnnotationRecording.setEnabled(true);
        } else {
          startPlaying();
          tbtnAnnotationRecording.setEnabled(false);
        }
      }
    });
  }

  private void save() {
    Annotation.Builder b = Annotation.newBuilder();

    boolean ok = false;

    String text = etAnnotationText.getText().toString();
    if (text != null && !text.equals("")) {
      b.setNote(text);
      ok = true;
    }

    File f = new File(mFileName);
    if (f.exists()) {
      b.setAudioFile(f.getName()); // folder is derived from external dir + deployment id
      ok = true;
    }

    if (!ok) {
      Toast.makeText(this, "Recording or Text missing", Toast.LENGTH_LONG).show();
      return;
    }

    b.setTimestamp(System.currentTimeMillis());
    b.setLocation(CM.LOC.getLastProtoLocation());

    b.setTag(CM.DAISY.getNextTag());
    Annotation annotation = b.build();
    CM.BUS.post(annotation);
    CM.BUS.post(new NeedsSync());
    finish();
  }

  @Override
  public void onPause() {
    super.onPause();
    if (mRecorder != null) {
      mRecorder.release();
      mRecorder = null;
    }

    if (mPlayer != null) {
      mPlayer.release();
      mPlayer = null;
    }
  }

  private void startPlaying() {
    mPlayer = new MediaPlayer();
    try {
      mPlayer.setDataSource(mFileName);
      mPlayer.prepare();
      mPlayer.start();
    } catch (IOException e) {
      Log.e(LOG_TAG, "prepare() failed");
    }
  }

  private void stopPlaying() {
    mPlayer.release();
    mPlayer = null;
  }

  private void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
      mRecorder.prepare();
    } catch (IOException e) {
      Log.e(LOG_TAG, "prepare() failed");
    }

    mRecorder.start();
  }

  private void stopRecording() {
    mRecorder.stop();
    mRecorder.release();
    mRecorder = null;
  }

}




Java Source Code List

de.uvwxy.daisy.nodemap.gui.ActivityAnnotation.java
de.uvwxy.daisy.nodemap.gui.ActivityNodeDetails.java
de.uvwxy.daisy.nodemap.gui.DetailActivity.java
de.uvwxy.daisy.nodemap.gui.DetailFragment.java
de.uvwxy.daisy.nodemap.gui.MainListActivity.java
de.uvwxy.daisy.nodemap.gui.MainListFragment.java
de.uvwxy.daisy.nodemap.guicontent.CMARView.java
de.uvwxy.daisy.nodemap.guicontent.CMBalloon.java
de.uvwxy.daisy.nodemap.guicontent.CMLocation.java
de.uvwxy.daisy.nodemap.guicontent.CMLogs.java
de.uvwxy.daisy.nodemap.guicontent.CMMap.java
de.uvwxy.daisy.nodemap.guicontent.CMSensors.java
de.uvwxy.daisy.nodemap.guicontent.CMXBee.java
de.uvwxy.daisy.nodemap.guicontent.CM.java
de.uvwxy.daisy.nodemap.guicontent.IDestroy.java
de.uvwxy.daisy.nodemap.guiviews.CVARView.java
de.uvwxy.daisy.nodemap.guiviews.CVBalloonClient.java
de.uvwxy.daisy.nodemap.guiviews.CVBalloon.java
de.uvwxy.daisy.nodemap.guiviews.CVChat.java
de.uvwxy.daisy.nodemap.guiviews.CVDeploymentData.java
de.uvwxy.daisy.nodemap.guiviews.CVDeployment.java
de.uvwxy.daisy.nodemap.guiviews.CVLogs.java
de.uvwxy.daisy.nodemap.guiviews.CVMap.java
de.uvwxy.daisy.nodemap.guiviews.CVMenuItem.java
de.uvwxy.daisy.nodemap.guiviews.CVParticipantScan.java
de.uvwxy.daisy.nodemap.guiviews.CVXBee.java
de.uvwxy.daisy.nodemap.guiviews.CV.java
de.uvwxy.daisy.nodemap.listobjects.APIMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.CVArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.ChatMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.LogMessageArrayAdapter.java
de.uvwxy.daisy.nodemap.listobjects.SampleGridViewAdapter.java