diff --git a/android-aac-enc/src/com/todoroo/aacenc/RecognizerApi.java b/android-aac-enc/src/com/todoroo/aacenc/RecognizerApi.java index d0700b2b0..1959008cb 100644 --- a/android-aac-enc/src/com/todoroo/aacenc/RecognizerApi.java +++ b/android-aac-enc/src/com/todoroo/aacenc/RecognizerApi.java @@ -55,7 +55,7 @@ public class RecognizerApi implements RecognitionListener { this.mListener = listener; } - public void play(String file) { + public static void play(String file) { MediaPlayer mediaPlayer = new MediaPlayer(); try { @@ -70,7 +70,7 @@ public class RecognizerApi implements RecognitionListener { throw new RuntimeException(e); } - Toast.makeText(context, "Playing Audio", Toast.LENGTH_LONG).show(); + //Toast.makeText(context, "Playing Audio", Toast.LENGTH_LONG).show(); } private AACEncoder encoder = new AACEncoder(); diff --git a/astrid/plugin-src/com/todoroo/astrid/files/FileMetadata.java b/astrid/plugin-src/com/todoroo/astrid/files/FileMetadata.java new file mode 100644 index 000000000..945feb35a --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/files/FileMetadata.java @@ -0,0 +1,32 @@ +package com.todoroo.astrid.files; + +import com.todoroo.andlib.data.Property.LongProperty; +import com.todoroo.andlib.data.Property.StringProperty; +import com.todoroo.astrid.data.Metadata; + +public class FileMetadata { + + /** metadata key */ + public static final String METADATA_KEY = "file"; //$NON-NLS-1$ + + /** Constants for file types */ + public static final int FILE_TYPE_AUDIO = 0; + public static final int FILE_TYPE_PDF = 1; + + public static final StringProperty FILE_PATH = new StringProperty(Metadata.TABLE, + Metadata.VALUE1.name); + + public static final LongProperty FILE_TYPE = new LongProperty(Metadata.TABLE, + Metadata.VALUE2.name); + + + public static Metadata createNewFileMetadata(long taskId, String filePath, long fileType) { + Metadata metadata = new Metadata(); + metadata.setValue(Metadata.KEY, METADATA_KEY); + metadata.setValue(Metadata.TASK, taskId); + metadata.setValue(FILE_PATH, filePath); + metadata.setValue(FILE_TYPE, fileType); + return metadata; + } + +} diff --git a/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java new file mode 100644 index 000000000..bc0fd72c7 --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java @@ -0,0 +1,91 @@ +package com.todoroo.astrid.files; + +import java.io.File; +import java.util.ArrayList; + +import android.app.Activity; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; +import android.widget.TextView; + +import com.todoroo.aacenc.RecognizerApi; +import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.andlib.service.Autowired; +import com.todoroo.andlib.service.DependencyInjectionService; +import com.todoroo.andlib.sql.Query; +import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; +import com.todoroo.astrid.data.Metadata; +import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.service.MetadataService; +import com.todoroo.astrid.ui.PopupControlSet; + +public class FilesControlSet extends PopupControlSet { + + @Autowired + private MetadataService metadataService; + + private final ArrayList files = new ArrayList(); + + public FilesControlSet(Activity activity, int viewLayout, int displayViewLayout, int title) { + super(activity, viewLayout, displayViewLayout, title); + DependencyInjectionService.getInstance().inject(this); + } + + @Override + protected void refreshDisplayView() { + LinearLayout display = (LinearLayout) getDisplayView(); + display.removeAllViews(); + for (final File f : files) { + TextView textView = new TextView(activity); + String name = f.getName(); + textView.setText(name); + if (name.contains("audio")) { + textView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + RecognizerApi.play(f.getAbsolutePath()); + } + }); + } + display.addView(textView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); + } + } + + @Override + public void readFromTask(Task task) { + super.readFromTask(task); + TodorooCursor cursor = metadataService.query( + Query.select(Metadata.PROPERTIES) + .where(MetadataCriteria.byTaskAndwithKey(model.getId(), FileMetadata.METADATA_KEY))); + try { + files.clear(); + Metadata metadata = new Metadata(); + for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { + metadata.readFromCursor(cursor); + File file = new File(metadata.getValue(FileMetadata.FILE_PATH)); + files.add(file); + } + } finally { + cursor.close(); + } + } + + @Override + protected void readFromTaskOnInitialize() { + // TODO Auto-generated method stub + } + + @Override + protected String writeToModelAfterInitialized(Task task) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void afterInflate() { + // TODO Auto-generated method stub + } + +} diff --git a/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java b/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java index bcf3262ef..587bb6d15 100644 --- a/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java +++ b/astrid/src/com/todoroo/astrid/ui/QuickAddBar.java @@ -41,9 +41,11 @@ import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.activity.TaskListFragment.OnTaskListItemClickedListener; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.TaskDao; +import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.files.FileMetadata; import com.todoroo.astrid.gcal.GCalControlSet; import com.todoroo.astrid.gcal.GCalHelper; import com.todoroo.astrid.repeats.RepeatControlSet; @@ -338,12 +340,20 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener { } if (currentVoiceFile != null) { - String voiceFile = activity.getExternalFilesDir("audio").toString() + "/" + task.getId() + "_audio.mp4"; - System.err.println("Saving to " + voiceFile); - recognizerApi.convert(voiceFile); + StringBuilder filePathBuilder = new StringBuilder(); + filePathBuilder.append(activity.getExternalFilesDir("audio").toString()) + .append("/") + .append(task.getId()) + .append("_") + .append(DateUtilities.now()) + .append("_audio.mp4"); + String filePath = filePathBuilder.toString(); + System.err.println("Saving to " + filePath); + recognizerApi.convert(filePath); currentVoiceFile = null; - // TODO: attach to task + Metadata fileMetadata = FileMetadata.createNewFileMetadata(task.getId(), filePath, FileMetadata.FILE_TYPE_AUDIO); + metadataService.save(fileMetadata); } fragment.incrementFilterCount();