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