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)
|
||||||
@ -43,21 +47,59 @@ public class OpenRocketViewer extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Log.d(TAG,"In onCreate");
|
Log.d(TAG,"In onCreate");
|
||||||
|
|
||||||
app = (Application) this.getApplication();
|
app = (Application) this.getApplication();
|
||||||
|
|
||||||
setContentView(R.layout.openrocketviewer);
|
setContentView(R.layout.openrocketviewer);
|
||||||
|
|
||||||
header = (TextView) findViewById(R.id.heading);
|
header = (TextView) findViewById(R.id.heading);
|
||||||
simulationList = (ListView) findViewById(R.id.rocketSimulations);
|
simulationList = (ListView) findViewById(R.id.rocketSimulations);
|
||||||
|
|
||||||
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)
|
||||||
@ -69,17 +111,18 @@ public class OpenRocketViewer extends Activity {
|
|||||||
app.setRocketDocument( result );
|
app.setRocketDocument( result );
|
||||||
updateContents();
|
updateContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
task.execute(orkFile);
|
task.execute(orkFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateContents() {
|
private void updateContents() {
|
||||||
|
|
||||||
OpenRocketDocument rocket = app.getRocketDocument();
|
OpenRocketDocument rocket = app.getRocketDocument();
|
||||||
header.setText( rocket.getRocket().getName());
|
header.setText( rocket.getRocket().getName());
|
||||||
|
|
||||||
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_1,rocket.getSimulations()) {
|
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_1,rocket.getSimulations()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,16 +147,20 @@ public class OpenRocketViewer extends Activity {
|
|||||||
i.putExtra("Simulation",(int)id);
|
i.putExtra("Simulation",(int)id);
|
||||||
startActivityForResult(i, 1/*magic*/);
|
startActivityForResult(i, 1/*magic*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
simulationList.setAdapter(sims);
|
simulationList.setAdapter(sims);
|
||||||
|
|
||||||
|
if ( progress.isShowing() ) {
|
||||||
|
progress.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.rocket_viewer_option_menu, menu);
|
inflater.inflate(R.menu.rocket_viewer_option_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +181,9 @@ public class OpenRocketViewer extends Activity {
|
|||||||
|
|
||||||
public void startMotorBrowser() {
|
public void startMotorBrowser() {
|
||||||
Log.d(TAG,"motorBrowserButton clicked");
|
Log.d(TAG,"motorBrowserButton clicked");
|
||||||
Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);
|
Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user