Added progress dialog when loading a file. Removed some default text from the view. Added safety net to launch the file browser when no file is specified. This last piece of functionality might be replaced with a dialog and better error handling in the future.
This commit is contained in:
parent
c546dba066
commit
2e41cbb5ff
@ -8,7 +8,7 @@
|
|||||||
android:id="@+id/heading"
|
android:id="@+id/heading"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Started" />
|
android:text="" />
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/rocketSimulations"
|
android:id="@+id/rocketSimulations"
|
||||||
|
@ -11,6 +11,7 @@ import net.sf.openrocket.android.simulation.SimulationViewer;
|
|||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -31,11 +32,14 @@ public class OpenRocketViewer extends Activity {
|
|||||||
|
|
||||||
private static final String TAG = "OpenRocketViewer";
|
private static final String TAG = "OpenRocketViewer";
|
||||||
|
|
||||||
TextView header;
|
private ProgressDialog progress;
|
||||||
ListView simulationList;
|
|
||||||
|
|
||||||
Application app;
|
private TextView header;
|
||||||
|
private ListView simulationList;
|
||||||
|
|
||||||
|
private Application app;
|
||||||
|
|
||||||
|
private final static int PICK_ORK_FILE_RESULT = 1;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see android.app.Activity#onCreate(android.os.Bundle)
|
* @see android.app.Activity#onCreate(android.os.Bundle)
|
||||||
@ -55,9 +59,47 @@ public class OpenRocketViewer extends Activity {
|
|||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
Uri file = i.getData();
|
Uri file = i.getData();
|
||||||
String path = file.getPath();
|
|
||||||
|
if ( file == null ) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
intent.setType("file/*");
|
||||||
|
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
loadOrkFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if ( progress != null ) {
|
||||||
|
if ( progress.isShowing() ) {
|
||||||
|
progress.dismiss();
|
||||||
|
}
|
||||||
|
progress = null;
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
switch(requestCode){
|
||||||
|
case PICK_ORK_FILE_RESULT:
|
||||||
|
if(resultCode==RESULT_OK){
|
||||||
|
Uri file = data.getData();
|
||||||
|
loadOrkFile(file);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadOrkFile( Uri file ) {
|
||||||
Log.d(TAG,"Use ork file: " + file);
|
Log.d(TAG,"Use ork file: " + file);
|
||||||
|
String path = file.getPath();
|
||||||
File orkFile = new File(path);
|
File orkFile = new File(path);
|
||||||
|
progress = ProgressDialog.show(this, "Loading file", "");
|
||||||
|
|
||||||
final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {
|
final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -73,6 +115,7 @@ public class OpenRocketViewer extends Activity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
task.execute(orkFile);
|
task.execute(orkFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateContents() {
|
private void updateContents() {
|
||||||
@ -108,6 +151,10 @@ public class OpenRocketViewer extends Activity {
|
|||||||
});
|
});
|
||||||
simulationList.setAdapter(sims);
|
simulationList.setAdapter(sims);
|
||||||
|
|
||||||
|
if ( progress.isShowing() ) {
|
||||||
|
progress.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user