Commit 6b711b0c authored by CallisteHanriat's avatar CallisteHanriat

adding background color for different wav files

parent 6d9ef299
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize = "16dp"
android:gravity="center_vertical"
android:id="@+id/textFileName"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/listItemFile"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize = "16dp"
android:gravity="center_vertical"
android:id="@+id/textFileName"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/listItemFile"
/>
</RelativeLayout>
package org.lp20.aikuma.ui;
import org.lp20.aikuma2.R;
import android.R.color;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ListFileAdapter extends ArrayAdapter {
private LayoutInflater layoutInflater;
private ContentResolver contentResolver;
static class ViewHolder {
public TextView textFileName;
}
public ListFileAdapter(Context context, String[] files) {
super(context, R.layout.content_dialog_select_file_frag, files);
this.layoutInflater = LayoutInflater.from(context);
this.contentResolver = context.getContentResolver();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
if (rowView == null) {
rowView = this.layoutInflater.inflate(R.layout.content_dialog_select_file_frag, null);
holder = new ViewHolder();
holder.textFileName = (TextView) rowView.findViewById(R.id.textFileName);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
String fileName = (String) getItem(position);
holder.textFileName.setText(fileName);
if (fileName.contains("rspk") && fileName.contains(".wav"))
holder.textFileName.setBackgroundColor(Color.GREEN);
else if (fileName.contains("trsl") && fileName.contains(".wav")){
holder.textFileName.setBackgroundColor(Color.CYAN);
} else {
holder.textFileName.setBackgroundColor(Color.TRANSPARENT);
}
return rowView;
}
}
......@@ -15,6 +15,7 @@ import org.lp20.aikuma.util.AikumaSettings;
import org.lp20.aikuma.util.FileIO;
import org.lp20.aikuma2.R;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.musicg.wave.Wave;
import android.app.AlertDialog;
......@@ -29,7 +30,13 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -108,98 +115,133 @@ public class RespeakingSelection extends AikumaActivity {
/**
* Used to display audio files that the user can choose to load from.
*/
public class FilebrowserDialogFragment extends DialogFragment {
public class FilebrowserDialogFragment extends DialogFragment {
ListView listElement;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_select_file_frag, null);
listElement = (ListView) view.findViewById(R.id.listItemFile);
ListFileAdapter adapter = new ListFileAdapter(getActivity(), mFileList);
listElement.setAdapter(adapter);
//listElement.setOnItemClickListener(this);
listElement.setOnItemClickListener(new OnItemClickListener() {
builder.setTitle("Import audio file");
if(mFileList == null) {
Log.e("importfile", "Showing file picker before loading the file list");
dialog = builder.create();
return dialog;
}
builder.setItems(mFileList, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mChosenFile = mFileList[which];
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
dismiss();
mChosenFile = mFileList[position];
Log.i("importfile", "mChosenFile: " + mChosenFile);
mPath = new File(mPath, mChosenFile);
if (mPath.isDirectory()) {
loadFileList(mPath, ".wav");
showAudioFilebrowserDialog();
} else {
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(RespeakingSelection.this);
File aikumaFile = mPath.getParentFile().getParentFile().getParentFile();
Intent intent;
if (aikumaFile != null && aikumaFile.getAbsolutePath().contains("aikuma")) {
// if recording, send to RespeakingMetadataLig
intent = new Intent(getActivity(), RespeakingMetadataLig.class);
String recordName;
try { recordName = mPath.getName().substring(0,mPath.getName().length()-4); }
catch (Exception e) {recordName = mPath.getName(); }
String dirName = mPath.getParentFile().getName();
intent.putExtra(RecordActivityLig.intent_recordname, recordName);
intent.putExtra("dirname", dirName);
Log.i(TAG, "Respeaking on an existing aikuma file - original record name: " + recordName);
Log.i(TAG, "Respeaking on an existing aikuma file - original record directory name: " + dirName);
int rewind = preferences.getInt("respeaking_rewind", 500);
intent.putExtra(ModeSelection.TRANSLATE_MODE, translateMode);
intent.putExtra(RecordActivityLig.intent_rewindAmount, rewind);
// intent.putExtra(RecordActivityLig.intent_sampleRate, (long) sampleRate);
startActivity(intent);
} else {
UUID uuid = UUID.randomUUID();
try {
Wave wave = new Wave(
new FileInputStream(mPath));
String format = wave.getWaveHeader().getFormat();
int sampleRate = wave.getWaveHeader().
getSampleRate();
int durationMsec = (int) wave.length() * 1000;
int bitsPerSample = wave.getWaveHeader().
getBitsPerSample();
int numChannels = wave.getWaveHeader().
getChannels();
FileUtils.copyFile(mPath,
new File(Recording.getNoSyncRecordingsPath(),
uuid.toString() + ".wav"));
FileUtils.copyFile(mPath,
new File(Recording.getNoSyncRecordingsPath(),
uuid.toString() + "-preview.wav"));
Log.i(TAG, "Copying original recording file to: " +
Recording.getNoSyncRecordingsPath() + "/" + uuid.toString() + ".wav");
intent = new Intent(getActivity(), RecordingMetadataLig.class);
intent.putExtra(RESPEAK, true);
intent.putExtra("tempRecUUID", uuid.toString());
intent.putExtra("sampleRate", sampleRate);
intent.putExtra("duration", durationMsec);
intent.putExtra("format", format);
intent.putExtra("numChannels", numChannels);
intent.putExtra("bitspersample", bitsPerSample);
intent.putExtra(ModeSelection.TRANSLATE_MODE, translateMode);
startActivity(intent);
} catch (FileNotFoundException e) {
Toast.makeText(getActivity(),
"Failed to import the recording.",
Toast.LENGTH_LONG).show();
Log.e(TAG, "Failed to import the file: " + e);
} catch (IOException e) {
Toast.makeText(getActivity(),
"Failed to import the recording.",
Toast.LENGTH_LONG).show();
Log.e(TAG, "Failed to copy the file to the temporary directory: "
+ e);
}
}
}
fileIsNotADirectory();
}
}
});
dialog = builder.show();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Dialog dialog = new Dialog(getActivity());
dialog.setTitle("Import audio file");
if (mFileList == null) {
Log.d("passage", "mFileList==null");
dialog = builder.create();
return dialog;
}
dialog.setContentView(view);
dialog.show();
return dialog;
}
/* @Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
dismiss();
mChosenFile = mFileList[position];
Log.i("importfile", "mChosenFile: " + mChosenFile);
mPath = new File(mPath, mChosenFile);
if (mPath.isDirectory()) {
loadFileList(mPath, ".wav");
showAudioFilebrowserDialog();
} else {
fileIsNotADirectory();
}
}*/
}
/**
* called by the the FileBrowserFragment when the selected item is not a dorectory.
*/
private void fileIsNotADirectory() {
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(RespeakingSelection.this);
File aikumaFile = mPath.getParentFile().getParentFile().getParentFile();
Intent intent;
if (aikumaFile != null && aikumaFile.getAbsolutePath().contains("aikuma")) {
// if recording, send to RespeakingMetadataLig
intent = new Intent(this, RespeakingMetadataLig.class);
String recordName;
try { recordName = mPath.getName().substring(0,mPath.getName().length()-4); }
catch (Exception e) {recordName = mPath.getName(); }
String dirName = mPath.getParentFile().getName();
intent.putExtra(RecordActivityLig.intent_recordname, recordName);
intent.putExtra("dirname", dirName);
Log.i(TAG, "Respeaking on an existing aikuma file - original record name: " + recordName);
Log.i(TAG, "Respeaking on an existing aikuma file - original record directory name: " + dirName);
int rewind = preferences.getInt("respeaking_rewind", 500);
intent.putExtra(ModeSelection.TRANSLATE_MODE, translateMode);
intent.putExtra(RecordActivityLig.intent_rewindAmount, rewind);
// intent.putExtra(RecordActivityLig.intent_sampleRate, (long) sampleRate);
startActivity(intent);
} else {
UUID uuid = UUID.randomUUID();
try {
Wave wave = new Wave(
new FileInputStream(mPath));
String format = wave.getWaveHeader().getFormat();
int sampleRate = wave.getWaveHeader().
getSampleRate();
int durationMsec = (int) wave.length() * 1000;
int bitsPerSample = wave.getWaveHeader().
getBitsPerSample();
int numChannels = wave.getWaveHeader().
getChannels();
FileUtils.copyFile(mPath,
new File(Recording.getNoSyncRecordingsPath(),
uuid.toString() + ".wav"));
FileUtils.copyFile(mPath,
new File(Recording.getNoSyncRecordingsPath(),
uuid.toString() + "-preview.wav"));
Log.i(TAG, "Copying original recording file to: " +
Recording.getNoSyncRecordingsPath() + "/" + uuid.toString() + ".wav");
intent = new Intent(this, RecordingMetadataLig.class);
intent.putExtra(RESPEAK, true);
intent.putExtra("tempRecUUID", uuid.toString());
intent.putExtra("sampleRate", sampleRate);
intent.putExtra("duration", durationMsec);
intent.putExtra("format", format);
intent.putExtra("numChannels", numChannels);
intent.putExtra("bitspersample", bitsPerSample);
intent.putExtra(ModeSelection.TRANSLATE_MODE, translateMode);
startActivity(intent);
} catch (FileNotFoundException e) {
Toast.makeText(this,
"Failed to import the recording.",
Toast.LENGTH_LONG).show();
Log.e(TAG, "Failed to import the file: " + e);
} catch (IOException e) {
Toast.makeText(this,
"Failed to import the recording.",
Toast.LENGTH_LONG).show();
Log.e(TAG, "Failed to copy the file to the temporary directory: "
+ e);
}
}
}
public void onBackPressed(View v) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment