Finished import export function
This commit is contained in:
parent
1112dde4d8
commit
6f1daa20ea
4 changed files with 71 additions and 40 deletions
|
|
@ -41,6 +41,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
/** Fragments **/
|
/** Fragments **/
|
||||||
private StatusFragment statusFragment;
|
private StatusFragment statusFragment;
|
||||||
|
private BehaviourListFragment behaviourListFragment;
|
||||||
private MenuItem action_execute;
|
private MenuItem action_execute;
|
||||||
private MenuItem action_mark;
|
private MenuItem action_mark;
|
||||||
private boolean backButtonPressed = false;
|
private boolean backButtonPressed = false;
|
||||||
|
|
@ -70,8 +71,9 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
statusFragment = (StatusFragment)
|
statusFragment = (StatusFragment)
|
||||||
getFragmentManager().findFragmentById(R.id.status_fragment);
|
getFragmentManager().findFragmentById(R.id.status_fragment);
|
||||||
|
behaviourListFragment = new BehaviourListFragment();
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(R.id.container, new BehaviourListFragment()).commit();
|
.replace(R.id.container, behaviourListFragment).commit();
|
||||||
|
|
||||||
// Setup Executor
|
// Setup Executor
|
||||||
if(currentExecutor == null) {
|
if(currentExecutor == null) {
|
||||||
|
|
@ -100,8 +102,6 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
updateExecutionState();
|
updateExecutionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,11 +205,14 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (id == R.id.action_import) {
|
else if (id == R.id.action_import) {
|
||||||
FileBrowserDialog browser = FileBrowserDialog.newInstance("/sdcard");
|
FileBrowserDialog browser = FileBrowserDialog.newInstance(
|
||||||
|
"/sdcard", FileBrowserDialog.BrowserMode.SELECT_FILE);
|
||||||
browser.show(this.getFragmentManager(), "import");
|
browser.show(this.getFragmentManager(), "import");
|
||||||
}
|
}
|
||||||
else if (id == R.id.action_export) {
|
else if (id == R.id.action_export) {
|
||||||
//TODO:
|
FileBrowserDialog browser = FileBrowserDialog.newInstance(
|
||||||
|
"/sdcard", FileBrowserDialog.BrowserMode.NEW_FILE);
|
||||||
|
browser.show(this.getFragmentManager(), "export");
|
||||||
}
|
}
|
||||||
else if (id == R.id.action_settings) {
|
else if (id == R.id.action_settings) {
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
|
|
@ -221,10 +224,17 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
try {
|
try {
|
||||||
if(tag.equals("import")) {
|
if(tag.equals("import")) {
|
||||||
currentExecutor.read(file.getAbsolutePath());
|
currentExecutor.read(file.getAbsolutePath());
|
||||||
|
behaviourListFragment.onResume();
|
||||||
|
}
|
||||||
|
else if(tag.equals("export")) {
|
||||||
|
currentExecutor.save(file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unable to import from: "+file.getAbsolutePath(), e);
|
String msg = "Unable to import from file";
|
||||||
Toast.makeText(this, "Unable to import from file", Toast.LENGTH_SHORT).show();
|
if(tag.equals("export"))
|
||||||
|
msg = "Unable to export to file";
|
||||||
|
log.error(msg+": "+file.getAbsolutePath(), e);
|
||||||
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.InputType;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -22,6 +23,7 @@ import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
@ -36,7 +38,7 @@ import org.apache.log4j.Logger;
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
public class FileBrowserDialog extends DialogFragment
|
public class FileBrowserDialog extends DialogFragment
|
||||||
implements OnItemClickListener, DialogInterface.OnKeyListener {
|
implements OnItemClickListener, DialogInterface.OnKeyListener, DialogInterface.OnClickListener{
|
||||||
public static final Logger log = Logger.getLogger(FileBrowserDialog.class);
|
public static final Logger log = Logger.getLogger(FileBrowserDialog.class);
|
||||||
public static final int FOLDER_ICON = R.drawable.folder;
|
public static final int FOLDER_ICON = R.drawable.folder;
|
||||||
public static final int FILE_ICON = R.drawable.file;
|
public static final int FILE_ICON = R.drawable.file;
|
||||||
|
|
@ -44,21 +46,25 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
public static interface OnFileSelectionListener{
|
public static interface OnFileSelectionListener{
|
||||||
public void onFileSelection(String tag, File file);
|
public void onFileSelection(String tag, File file);
|
||||||
}
|
}
|
||||||
|
public static enum BrowserMode{
|
||||||
|
SELECT_FILE, NEW_FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
private BrowserMode mode;
|
||||||
private File root;
|
private File root;
|
||||||
private File path;
|
private File path;
|
||||||
private File selection;
|
private File selection;
|
||||||
private ListView fileListView;
|
|
||||||
private TextView pathView;
|
private TextView pathView;
|
||||||
|
private ListView fileListView;
|
||||||
|
private EditText fileNameView;
|
||||||
private OnFileSelectionListener callback;
|
private OnFileSelectionListener callback;
|
||||||
|
|
||||||
|
|
||||||
|
public static FileBrowserDialog newInstance(String root, BrowserMode mode) {
|
||||||
public static FileBrowserDialog newInstance(String root) {
|
|
||||||
FileBrowserDialog browser = new FileBrowserDialog();
|
FileBrowserDialog browser = new FileBrowserDialog();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("root", root);
|
bundle.putString("root", root);
|
||||||
|
bundle.putString("browser_mode", mode.name());
|
||||||
browser.setArguments(bundle);
|
browser.setArguments(bundle);
|
||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +78,7 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
root = new File(bundle.getString("root"));
|
root = new File(bundle.getString("root"));
|
||||||
callback = (OnFileSelectionListener) activity;
|
callback = (OnFileSelectionListener) activity;
|
||||||
|
mode = BrowserMode.valueOf(bundle.getString("browser_mode"));
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,34 +107,38 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
|
|
||||||
fileListView = new ListView(context);
|
fileListView = new ListView(context);
|
||||||
fileListView.setLayoutParams(new LinearLayout.LayoutParams(
|
fileListView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
LinearLayout.LayoutParams.MATCH_PARENT, // Width
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
LinearLayout.LayoutParams.MATCH_PARENT, // Height
|
||||||
|
1f // Weight
|
||||||
|
));
|
||||||
fileListView.setOnItemClickListener(this);
|
fileListView.setOnItemClickListener(this);
|
||||||
fileListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
fileListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
||||||
|
|
||||||
updateFileList(root);
|
updateFileList(root);
|
||||||
rootView.addView(fileListView);
|
rootView.addView(fileListView);
|
||||||
|
|
||||||
/*EditText fileNameView = new EditText(context);
|
if(mode == BrowserMode.NEW_FILE){
|
||||||
fileNameView.setLayoutParams(new LinearLayout.LayoutParams(
|
View delimiter = new View(context);
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
delimiter.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
fileNameView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||||
rootView.addView(fileNameView);
|
delimiter.getLayoutParams().height = 2;
|
||||||
*/
|
delimiter.setBackgroundResource(android.R.color.darker_gray);
|
||||||
|
rootView.addView(delimiter);
|
||||||
|
|
||||||
|
fileNameView = new EditText(context);
|
||||||
|
fileNameView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||||
|
fileNameView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||||
|
fileNameView.setHint("File Name");
|
||||||
|
rootView.addView(fileNameView);
|
||||||
|
}
|
||||||
|
|
||||||
// Create dialog
|
// Create dialog
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(R.string.configure_behaviour);
|
builder.setTitle("File Browser");
|
||||||
builder.setOnKeyListener(this);
|
builder.setOnKeyListener(this);
|
||||||
builder.setPositiveButton(R.string.action_select, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.action_select, this);
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
if(selection != null)
|
|
||||||
callback.onFileSelection(FileBrowserDialog.this.getTag(), selection);
|
|
||||||
else
|
|
||||||
Toast.makeText(context, "No File Selected", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
|
builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
FileBrowserDialog.this.getDialog().cancel();
|
FileBrowserDialog.this.getDialog().cancel();
|
||||||
|
|
@ -138,7 +148,8 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
if(mode == BrowserMode.SELECT_FILE)
|
||||||
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,14 +160,28 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
if(file.isDirectory()){
|
if(file.isDirectory()){
|
||||||
updateFileList(file);
|
updateFileList(file);
|
||||||
}
|
}
|
||||||
else{
|
else if(mode == BrowserMode.SELECT_FILE){
|
||||||
log.debug("File selected: "+ file.getAbsolutePath());
|
log.debug("File selected: "+ file.getAbsolutePath());
|
||||||
((AlertDialog)this.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
((AlertDialog)this.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||||
selection = file;
|
selection = file;
|
||||||
((FileListAdapter)fileListView.getAdapter()).notifyDataSetChanged();
|
((FileListAdapter)fileListView.getAdapter()).notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
else if(mode == BrowserMode.NEW_FILE){
|
||||||
|
log.debug("File selected: "+ file.getAbsolutePath());
|
||||||
|
fileNameView.setText(file.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(mode == BrowserMode.SELECT_FILE && selection != null)
|
||||||
|
callback.onFileSelection(FileBrowserDialog.this.getTag(), selection);
|
||||||
|
else if(mode == BrowserMode.NEW_FILE && !fileNameView.getText().toString().isEmpty())
|
||||||
|
callback.onFileSelection(FileBrowserDialog.this.getTag(),
|
||||||
|
new File(path, fileNameView.getText().toString()));
|
||||||
|
else
|
||||||
|
Toast.makeText(this.getActivity(), "No File Selected", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||||
|
|
@ -177,7 +202,7 @@ public class FileBrowserDialog extends DialogFragment
|
||||||
if(dir.compareTo(root) <= 0)
|
if(dir.compareTo(root) <= 0)
|
||||||
dir = root;
|
dir = root;
|
||||||
|
|
||||||
log.debug("Browsing folder: "+ dir.getAbsolutePath());
|
log.debug("Listing folder: "+ dir.getAbsolutePath());
|
||||||
ArrayList<File> folders = new ArrayList();
|
ArrayList<File> folders = new ArrayList();
|
||||||
ArrayList<File> files = new ArrayList();
|
ArrayList<File> files = new ArrayList();
|
||||||
for(File file : dir.listFiles()){
|
for(File file : dir.listFiles()){
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.ericsson.uecontrol.gui.EditActivity">
|
tools:context="com.ericsson.uecontrol.gui.EditActivity">
|
||||||
|
|
||||||
<!--<com.ericsson.uecontrol.gui.util.TouchInterceptor
|
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" /> -->
|
|
||||||
<com.ericsson.uecontrol.gui.util.DynamicListView
|
<com.ericsson.uecontrol.gui.util.DynamicListView
|
||||||
android:id="@android:id/list"
|
android:id="@android:id/list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
android:title="@string/action_export"
|
android:title="@string/action_export"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:enabled="false" />
|
android:enabled="true" />
|
||||||
|
|
||||||
<item android:id="@+id/action_settings"
|
<item android:id="@+id/action_settings"
|
||||||
android:title="@string/action_settings"
|
android:title="@string/action_settings"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue