Introduced FileMetadata, started on control set

pull/14/head
Sam Bosley 13 years ago
parent 9cef9604e3
commit aaaab09569

@ -55,7 +55,7 @@ public class RecognizerApi implements RecognitionListener {
this.mListener = listener; this.mListener = listener;
} }
public void play(String file) { public static void play(String file) {
MediaPlayer mediaPlayer = new MediaPlayer(); MediaPlayer mediaPlayer = new MediaPlayer();
try { try {
@ -70,7 +70,7 @@ public class RecognizerApi implements RecognitionListener {
throw new RuntimeException(e); 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(); private AACEncoder encoder = new AACEncoder();

@ -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;
}
}

@ -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<File> files = new ArrayList<File>();
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<Metadata> 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
}
}

@ -41,9 +41,11 @@ import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.activity.TaskListFragment.OnTaskListItemClickedListener; import com.todoroo.astrid.activity.TaskListFragment.OnTaskListItemClickedListener;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FileMetadata;
import com.todoroo.astrid.gcal.GCalControlSet; import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.gcal.GCalHelper; import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.repeats.RepeatControlSet; import com.todoroo.astrid.repeats.RepeatControlSet;
@ -338,12 +340,20 @@ public class QuickAddBar extends LinearLayout implements RecognizerApiListener {
} }
if (currentVoiceFile != null) { if (currentVoiceFile != null) {
String voiceFile = activity.getExternalFilesDir("audio").toString() + "/" + task.getId() + "_audio.mp4"; StringBuilder filePathBuilder = new StringBuilder();
System.err.println("Saving to " + voiceFile); filePathBuilder.append(activity.getExternalFilesDir("audio").toString())
recognizerApi.convert(voiceFile); .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; currentVoiceFile = null;
// TODO: attach to task Metadata fileMetadata = FileMetadata.createNewFileMetadata(task.getId(), filePath, FileMetadata.FILE_TYPE_AUDIO);
metadataService.save(fileMetadata);
} }
fragment.incrementFilterCount(); fragment.incrementFilterCount();

Loading…
Cancel
Save