Commit e6f01dfa authored by hanriaca's avatar hanriaca

Adding Image mode for elicitation, works with progression saving mode

parent 3a27e201
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
package="org.lp20.aikuma2" package="org.lp20.aikuma2"
android:versionCode="010005" android:versionCode="010005"
android:versionName="0.8.4"> android:versionName="0.8.4">
<uses-sdk android:minSdkVersion="14"/> <uses-sdk android:minSdkVersion="16"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...@@ -197,6 +197,8 @@ ...@@ -197,6 +197,8 @@
<activity android:name="org.lp20.aikuma.ui.TranslationSelection"></activity> <activity android:name="org.lp20.aikuma.ui.TranslationSelection"></activity>
<activity android:name="org.lp20.aikuma.ui.RecordElicitation" <activity android:name="org.lp20.aikuma.ui.RecordElicitation"
android:configChanges="orientation|screenSize"></activity> android:configChanges="orientation|screenSize"></activity>
<activity android:name="org.lp20.aikuma.ui.RecordElicitationImage"
android:configChanges="orientation|screenSize"></activity>
<activity android:name="org.lp20.aikuma.ui.CheckMode" <activity android:name="org.lp20.aikuma.ui.CheckMode"
android:configChanges="orientation|screenSize" ></activity> android:configChanges="orientation|screenSize" ></activity>
<activity android:name="org.lp20.aikuma.ui.CheckWordVariant" <activity android:name="org.lp20.aikuma.ui.CheckWordVariant"
......
<?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"
android:id="@+id/layoutListView">
<ImageView
android:layout_width="75dp"
android:layout_height="50dp"
android:src="@drawable/folder_close_icon"
android:id="@+id/image_file_type"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize = "16dp"
android:layout_toRightOf="@+id/image_file_type"
android:gravity="center_vertical"
android:id="@+id/textFolderName"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/image_folder_type"
android:layout_alignParentRight="true"
android:src="@drawable/type_folder_image"
android:visibility="invisible"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<!-- Back button -->
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left">
<Button
android:id="@+id/btn_goBack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableLeft="@drawable/ic_undo_black_24dp"
android:onClick="onButtonBackPressed"
android:text="@string/goBack"
android:textColor="#D32F2F"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp" />
</GridLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableLayoutTitleActivityElicitationIMG">
<TextView
style="@style/MainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elicitation mode"
android:layout_marginBottom="20dp"/>
<View
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:id="@+id/separator"
android:visibility="visible"
android:background="@android:color/darker_gray"
android:layout_marginBottom="50dp"/>
<TextView
android:id="@+id/maintextView2"
style="@style/SecondTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please, read the bold line."
android:layout_marginBottom="25dp" />
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tableLayoutTitleActivityElicitationIMG"
android:id="@+id/linearLayoutTopActivityElicitationIMG">
<TextView
android:id="@+id/image_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
android:typeface="serif" />
<View
android:id="@+id/view1"
android:layout_width="0.2dp"
android:layout_height="40dp"
android:visibility="visible"
android:background="@android:color/darker_gray"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<fragment
android:id="@+id/phrase_player"
android:name="org.lp20.aikuma.ui.ListenFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<ImageView
android:layout_below="@+id/linearLayoutTopActivityElicitationIMG"
android:id="@+id/img_orig"
android:layout_width="800px"
android:layout_height="450px"
android:paddingBottom="10dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeTowBottomsElicitIMG"
android:layout_below="@+id/linearLayoutTopActivityElicitationIMG"
android:layout_toRightOf="@+id/img_orig">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/linearTowBottomsElicitIMG">
<ImageButton
android:id="@+id/btn_record_elicit"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:onClick="onRecordClick"
android:src="@drawable/record" />
<ImageButton
android:id="@+id/btn_next"
android:layout_toRightOf="@+id/btn_record_elicit"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:onClick="onNextClick"
android:src="@drawable/arrow_circle_o_right" />
</LinearLayout>
<ImageButton
android:id="@+id/btn_validate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:onClick="onValidate"
android:layout_below="@+id/linearTowBottomsElicitIMG"
android:src="@drawable/ok_32" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_below="@+id/img_orig">
<TextView
android:id="@+id/elicit_phrase_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>
<TextView
android:id="@+id/elicit_total_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / " />
<view class="org.lp20.aikuma.ui.InterleavedSeekBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/seek_elicit_progression"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxHeight="3dp"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<!-- Back button -->
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left">
<Button
android:id="@+id/btn_goBack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableLeft="@drawable/ic_undo_black_24dp"
android:onClick="onButtonBackPressed"
android:text="@string/goBack"
android:textColor="#D32F2F"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp" />
</GridLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableLayoutTitleActivityElicitationIMG">
<TextView
style="@style/MainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elicitation mode"
android:layout_marginBottom="20dp"/>
<View
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:id="@+id/separator"
android:visibility="visible"
android:background="@android:color/darker_gray"
android:layout_marginBottom="50dp"/>
<TextView
android:id="@+id/maintextView2"
style="@style/SecondTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please, read the bold line."
android:layout_marginBottom="25dp" />
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tableLayoutTitleActivityElicitationIMG"
android:id="@+id/linearLayoutTopActivityElicitationIMG">
<TextView
android:id="@+id/image_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
android:typeface="serif" />
<View
android:id="@+id/view1"
android:layout_width="0.2dp"
android:layout_height="40dp"
android:visibility="visible"
android:background="@android:color/darker_gray"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<fragment
android:id="@+id/phrase_player"
android:name="org.lp20.aikuma.ui.ListenFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<ImageView
android:layout_below="@+id/linearLayoutTopActivityElicitationIMG"
android:id="@+id/img_orig"
android:layout_width="800px"
android:layout_height="450px"
android:paddingBottom="10dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeTowBottomsElicitIMG"
android:layout_below="@+id/linearLayoutTopActivityElicitationIMG"
android:layout_toRightOf="@+id/img_orig">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/linearTowBottomsElicitIMG">
<ImageButton
android:id="@+id/btn_record_elicit"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:onClick="onRecordClick"
android:src="@drawable/record" />
<ImageButton
android:id="@+id/btn_next"
android:layout_toRightOf="@+id/btn_record_elicit"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:onClick="onNextClick"
android:src="@drawable/arrow_circle_o_right" />
</LinearLayout>
<ImageButton
android:id="@+id/btn_validate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:onClick="onValidate"
android:layout_below="@+id/linearTowBottomsElicitIMG"
android:src="@drawable/ok_32" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_below="@+id/img_orig">
<TextView
android:id="@+id/elicit_phrase_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>
<TextView
android:id="@+id/elicit_total_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / " />
<view class="org.lp20.aikuma.ui.InterleavedSeekBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/seek_elicit_progression"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxHeight="3dp"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
\ No newline at end of file
...@@ -138,4 +138,5 @@ ...@@ -138,4 +138,5 @@
<string name="currentLine">currentLine</string> <string name="currentLine">currentLine</string>
<string name="recordDuration">duration</string> <string name="recordDuration">duration</string>
<string name="translation">translation</string> <string name="translation">translation</string>
<string name="selectedFileType">selectedFileType</string>
</resources> </resources>
package org.lp20.aikuma.ui; package org.lp20.aikuma.ui;
import java.io.File; import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FilenameFilter; import java.io.FilenameFilter;
...@@ -27,8 +28,11 @@ import android.preference.PreferenceManager; ...@@ -27,8 +28,11 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ElicitationMode extends AikumaActivity{ public class ElicitationMode extends AikumaActivity{
...@@ -41,6 +45,16 @@ public class ElicitationMode extends AikumaActivity{ ...@@ -41,6 +45,16 @@ public class ElicitationMode extends AikumaActivity{
private String fileType; private String fileType;
private String title; private String title;
public static final int TEXT_MODE = 0;
public static final int IMAGE_MODE = 1;
public static final int VIDEO_MODE = 2;
/**
* used to know if the user press text, image or video button
* this field contains 0 (text), 1 (image) or 2(video)
*/
private int selectedFileType;
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -51,6 +65,7 @@ public class ElicitationMode extends AikumaActivity{ ...@@ -51,6 +65,7 @@ public class ElicitationMode extends AikumaActivity{
public void onImportClick(View _view) { public void onImportClick(View _view) {
switch (_view.getId()) { switch (_view.getId()) {
case R.id.button_byText: case R.id.button_byText:
selectedFileType = TEXT_MODE;
Log.i(TAG, "Import text; view id: " + _view.getId()); Log.i(TAG, "Import text; view id: " + _view.getId());
mPath = Environment.getExternalStorageDirectory(); mPath = Environment.getExternalStorageDirectory();
fileType = ".txt"; fileType = ".txt";
...@@ -58,14 +73,15 @@ public class ElicitationMode extends AikumaActivity{ ...@@ -58,14 +73,15 @@ public class ElicitationMode extends AikumaActivity{
importContent(); importContent();
break; break;
case R.id.button_byImage: case R.id.button_byImage:
selectedFileType = IMAGE_MODE;
Log.i(TAG, "Import image; view id: " + _view.getId()); Log.i(TAG, "Import image; view id: " + _view.getId());
mPath = Environment.getExternalStorageDirectory(); mPath = Environment.getExternalStorageDirectory();
fileType = ".jpg"; fileType = ".jpg";
title = "Import image file"; title = "Import image file";
Toast.makeText(this, "This feature is not yet available...", Toast.LENGTH_LONG).show(); importContent();
// importContent();
break; break;
case R.id.button_byVideo: case R.id.button_byVideo:
selectedFileType = VIDEO_MODE;
Log.i(TAG, "Import video; view id: " + _view.getId()); Log.i(TAG, "Import video; view id: " + _view.getId());
mPath = Environment.getExternalStorageDirectory(); mPath = Environment.getExternalStorageDirectory();
fileType = ".avi"; fileType = ".avi";
...@@ -98,7 +114,16 @@ public class ElicitationMode extends AikumaActivity{ ...@@ -98,7 +114,16 @@ public class ElicitationMode extends AikumaActivity{
return filename.contains(fileType) || sel.isDirectory(); return filename.contains(fileType) || sel.isDirectory();
} }
}; };
mFileList = mPath.list(filter); if (selectedFileType == ElicitationMode.TEXT_MODE)
mFileList = mPath.list(filter);
else {
mFileList = mPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return new File(dir, filename).isDirectory();
}
});
}
} }
else { else {
mFileList= new String[0]; mFileList= new String[0];
...@@ -120,50 +145,94 @@ public class ElicitationMode extends AikumaActivity{ ...@@ -120,50 +145,94 @@ public class ElicitationMode extends AikumaActivity{
* Copied from RespeakingSelection.java * Copied from RespeakingSelection.java
*/ */
public class FilebrowserDialogFragment extends DialogFragment { public class FilebrowserDialogFragment extends DialogFragment {
ListView listElement;
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = null; View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_select_file_frag, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); listElement = (ListView) view.findViewById(R.id.listItemFile);
ListFolderAdapter adapter = new ListFolderAdapter(getActivity(), mFileList, mPath, selectedFileType);
builder.setTitle(title); listElement.setAdapter(adapter);;
if(mFileList == null) {
Log.e(TAG, "import file - Showing file picker before loading the file list"); listElement.setOnItemClickListener(new OnItemClickListener() {
dialog = builder.create(); @Override
return dialog; public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
} dismiss();
builder.setItems(mFileList, new DialogInterface.OnClickListener() { mChosenFile = mFileList[position];
public void onClick(DialogInterface dialog, int which) {
mChosenFile = mFileList[which];
Log.i(TAG, "mChosenFile: " + mChosenFile); Log.i(TAG, "mChosenFile: " + mChosenFile);
mPath = new File(mPath, mChosenFile); mPath = new File(mPath, mChosenFile);
if (mPath.isDirectory()) { if (mPath.isDirectory()) {
loadFileList(mPath, fileType); if (!isSelectionnable(mPath)) {
showAudioFilebrowserDialog(); Log.d("mPath", mPath.getAbsolutePath() + " is not selectionnable");
} else { loadFileList(mPath, fileType);
if (fileType==".txt") { showAudioFilebrowserDialog();
Toast.makeText(ElicitationMode.this, "Selected text: " + mPath, Toast.LENGTH_LONG).show(); } else {
Log.d("mPath", mPath.getAbsolutePath() + " is selectionnable");
actionSelectedFile();
} }
} else {
if (fileType==".jpg") { if (fileType==".jpg") {
Toast.makeText(ElicitationMode.this, "Selected image: " + mPath, Toast.LENGTH_LONG).show(); Toast.makeText(ElicitationMode.this, "Selected folder: " + mPath, Toast.LENGTH_LONG).show();
} }
if (fileType==".avi") { if (fileType==".avi") {
Toast.makeText(ElicitationMode.this, "Selected video: " + mPath, Toast.LENGTH_LONG).show(); Toast.makeText(ElicitationMode.this, "Selected video: " + mPath, Toast.LENGTH_LONG).show();
} }
actionSelectedFile();
Intent intent = new Intent(getActivity(), RecordingMetadataLig.class);
intent.putExtra(importFileName, mPath.getAbsolutePath());
Log.i(TAG, "selected file: " + mPath.getAbsolutePath());
intent.putExtra(ELICITATION, true);
startActivity(intent);
} }
} }
}); });
dialog = builder.show();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(title);
Dialog dialog = new Dialog(getActivity());
if(mFileList == null) {
Toast.makeText(getActivity(), "No files to display", Toast.LENGTH_SHORT).show();
Log.e(TAG, "import file - Showing file picker before loading the file list");
dialog = builder.create();
return dialog;
}
dialog.setContentView(view);
dialog.show();
return dialog; return dialog;
} }
} }
/**
* Function called when we need to know if an entity is queryable
* @param f the selected file (the entity)
* @return true if the file is queryable, false if not.
*/
private boolean isSelectionnable(File f) {
int i = 0;
File[] files = f.listFiles();
switch (selectedFileType) {
case 1:
while( i < files.length && files[i].isFile() && (files[i].getAbsolutePath().contains(".jpg") || files[i].getAbsolutePath().contains("jpeg"))) {
i++;