Rewrite the ThrustCurve search and download process to be orientation friendly.
This commit is contained in:
parent
21fb67f8d2
commit
81cb5abcb1
@ -18,18 +18,16 @@ import android.support.v4.app.DialogFragment;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
public class OpenRocketLoaderActivity extends FragmentActivity
|
public class OpenRocketLoaderActivity extends FragmentActivity
|
||||||
implements TCQueryAction.OnComplete, OpenRocketLoaderFragment.OnOpenRocketFileLoaded
|
implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnOpenRocketFileLoaded
|
||||||
{
|
{
|
||||||
|
|
||||||
private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";
|
private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";
|
||||||
|
private final static String MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG = "missingmotortask";
|
||||||
|
|
||||||
private TCMissingMotorDownloadAction missingMotorDownloadAction;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
missingMotorDownloadAction = new TCMissingMotorDownloadAction(this);
|
|
||||||
if ( savedInstanceState == null || savedInstanceState.getBoolean("isLoading", false) == false ) {
|
if ( savedInstanceState == null || savedInstanceState.getBoolean("isLoading", false) == false ) {
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
Uri file = i.getData();
|
Uri file = i.getData();
|
||||||
@ -44,15 +42,6 @@ implements TCQueryAction.OnComplete, OpenRocketLoaderFragment.OnOpenRocketFileLo
|
|||||||
outState.putBoolean("isLoading", true);
|
outState.putBoolean("isLoading", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if ( missingMotorDownloadAction != null ) {
|
|
||||||
missingMotorDownloadAction.dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadOrkFile( Uri file ) {
|
private void loadOrkFile( Uri file ) {
|
||||||
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
|
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
|
||||||
String path = file.getPath();
|
String path = file.getPath();
|
||||||
@ -93,7 +82,7 @@ implements TCQueryAction.OnComplete, OpenRocketLoaderFragment.OnOpenRocketFileLo
|
|||||||
* Called when the TCMissingMotorDownload process finishes.
|
* Called when the TCMissingMotorDownload process finishes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onTCQueryComplete(String message) {
|
||||||
|
|
||||||
Rocket rocket = ((Application)OpenRocketLoaderActivity.this.getApplication()).getRocketDocument().getRocket();
|
Rocket rocket = ((Application)OpenRocketLoaderActivity.this.getApplication()).getRocketDocument().getRocket();
|
||||||
WarningSet warnings = ((Application)OpenRocketLoaderActivity.this.getApplication()).getWarnings();
|
WarningSet warnings = ((Application)OpenRocketLoaderActivity.this.getApplication()).getWarnings();
|
||||||
@ -120,8 +109,8 @@ implements TCQueryAction.OnComplete, OpenRocketLoaderFragment.OnOpenRocketFileLo
|
|||||||
Rocket rocket = ((Application)OpenRocketLoaderActivity.this.getApplication()).getRocketDocument().getRocket();
|
Rocket rocket = ((Application)OpenRocketLoaderActivity.this.getApplication()).getRocketDocument().getRocket();
|
||||||
Set<ThrustCurveMotorPlaceholder> missingMotors = MissingMotorHelpers.findMissingMotors(rocket);
|
Set<ThrustCurveMotorPlaceholder> missingMotors = MissingMotorHelpers.findMissingMotors(rocket);
|
||||||
|
|
||||||
missingMotorDownloadAction.setMissingMotors(missingMotors);
|
TCMissingMotorDownloadAction motorfrag = TCMissingMotorDownloadAction.newInstance( missingMotors );
|
||||||
missingMotorDownloadAction.start();
|
getSupportFragmentManager().beginTransaction().add( motorfrag, MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG).commit();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,29 +2,25 @@ package net.sf.openrocket.android.thrustcurve;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor;
|
|
||||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
|
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
public class TCMissingMotorDownloadAction extends TCQueryAction {
|
public class TCMissingMotorDownloadAction extends TCQueryAction {
|
||||||
|
|
||||||
private Set<ThrustCurveMotorPlaceholder> missingMotors;
|
public static TCMissingMotorDownloadAction newInstance( Set<ThrustCurveMotorPlaceholder> missingMotors ) {
|
||||||
|
TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction();
|
||||||
public TCMissingMotorDownloadAction(Activity parent) {
|
frag.task = frag.new Downloader(missingMotors);
|
||||||
super(parent);
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMissingMotors( Set<ThrustCurveMotorPlaceholder> missingMotors ) {
|
private class Downloader extends TCQueryAction.TCQueryTask {
|
||||||
this.missingMotors = missingMotors;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Runnable getTask() {
|
|
||||||
return new Downloader();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Downloader implements Runnable {
|
|
||||||
|
|
||||||
|
private Set<ThrustCurveMotorPlaceholder> missingMotors;
|
||||||
|
|
||||||
|
private Downloader( Set<ThrustCurveMotorPlaceholder> missingMotors ) {
|
||||||
|
this.missingMotors = missingMotors;
|
||||||
|
}
|
||||||
|
|
||||||
private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) {
|
private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) {
|
||||||
try {
|
try {
|
||||||
SearchRequest request = new SearchRequest();
|
SearchRequest request = new SearchRequest();
|
||||||
@ -55,55 +51,32 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MotorBurnFile b = new ThrustCurveAPI().downloadData(mi.getMotor_id());
|
|
||||||
|
|
||||||
AndroidLogWrapper.d(TCQueryAction.class, mi.toString());
|
AndroidLogWrapper.d(TCQueryAction.class, mi.toString());
|
||||||
|
|
||||||
ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor();
|
MotorBurnFile b = new ThrustCurveAPI().downloadData(mi.getMotor_id());
|
||||||
|
|
||||||
m.setThrustCurveMotor( b.getThrustCurveMotor() );
|
writeMotor( mi, b);
|
||||||
|
|
||||||
// Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A.
|
|
||||||
m.setImpulseClass(mi.getImpulse_class());
|
|
||||||
if ( "a".equalsIgnoreCase(mi.getImpulse_class())) {
|
|
||||||
if( mi.getCommon_name().startsWith("1/2A") ) {
|
|
||||||
m.setImpulseClass("1/2A");
|
|
||||||
} else if (mi.getCommon_name().startsWith("1/4A") ) {
|
|
||||||
m.setImpulseClass("1/4A");
|
|
||||||
} else if (mi.getCommon_name().startsWith("Micro") ) {
|
|
||||||
m.setImpulseClass("1/8A");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert Case Info.
|
|
||||||
if ( mi.getCase_info() == null
|
|
||||||
|| "single use".equalsIgnoreCase(mi.getCase_info())
|
|
||||||
|| "single-use".equalsIgnoreCase(mi.getCase_info())) {
|
|
||||||
m.setCaseInfo(mi.getType()+ " " + mi.getDiameter() + "x" + mi.getLength());
|
|
||||||
} else {
|
|
||||||
m.setCaseInfo(mi.getCase_info());
|
|
||||||
}
|
|
||||||
|
|
||||||
AndroidLogWrapper.d(TCQueryAction.class,"adding motor " + m.toString());
|
|
||||||
// Write motor.
|
|
||||||
mDbHelper.getMotorDao().insertOrUpdateMotor(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( Exception ex){
|
catch( Exception ex){
|
||||||
AndroidLogWrapper.d(TCQueryAction.class,ex.toString());
|
AndroidLogWrapper.d(TCQueryAction.class,ex.toString());
|
||||||
handler.post( new Error(ex.toString()) );
|
handler.post( new UpdateMessage("Failed") );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected String doInBackground(Void... arg0) {
|
||||||
for ( ThrustCurveMotorPlaceholder motor : missingMotors ) {
|
for ( ThrustCurveMotorPlaceholder motor : missingMotors ) {
|
||||||
AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor);
|
AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor);
|
||||||
downloadMissingMotor(motor);
|
downloadMissingMotor(motor);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
handler.post( new Dismiss() );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
package net.sf.openrocket.android.thrustcurve;
|
package net.sf.openrocket.android.thrustcurve;
|
||||||
|
|
||||||
import net.sf.openrocket.android.db.DbAdapter;
|
import net.sf.openrocket.android.db.DbAdapter;
|
||||||
|
import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor;
|
||||||
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
|
import net.sf.openrocket.android.util.ProgressDialogFragment;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.os.AsyncTask;
|
||||||
import android.app.ProgressDialog;
|
import android.os.Bundle;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCQueryAction is a class which provides all the functionality required
|
* TCQueryAction is a class which provides all the functionality required
|
||||||
@ -25,62 +32,111 @@ import android.os.Handler;
|
|||||||
* When the parent Activity is dismissed, it must call TCQueryAction.dismiss() to free resources.
|
* When the parent Activity is dismissed, it must call TCQueryAction.dismiss() to free resources.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class TCQueryAction {
|
public abstract class TCQueryAction extends Fragment {
|
||||||
|
|
||||||
public interface OnComplete {
|
private final static String PROGRESS_DIALOG_TAG = "progress_dialog";
|
||||||
public void onComplete();
|
|
||||||
|
public interface OnTCQueryCompleteListener {
|
||||||
|
public void onTCQueryComplete(String message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DbAdapter mDbHelper;
|
protected AsyncTask<Void,Void,String> task;
|
||||||
|
|
||||||
private ProgressDialog progress;
|
|
||||||
private Thread downloadThread;
|
|
||||||
protected Handler handler;
|
protected Handler handler;
|
||||||
|
|
||||||
private final Activity parent;
|
private OnTCQueryCompleteListener onCompleteListener;
|
||||||
private OnComplete onCompleteListener;
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Create a new TCQueryAction.
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
*
|
super.onCreate(savedInstanceState);
|
||||||
* If the parent implements TCQueryAction.OnComplete, it will be used as the
|
setRetainInstance(true);
|
||||||
* onCompleteListener and notified when the process is finished.
|
handler = new Handler();
|
||||||
*
|
if ( savedInstanceState == null ) {
|
||||||
* @param parent
|
// this means we are starting for the first time.
|
||||||
*/
|
task.execute((Void)null);
|
||||||
public TCQueryAction( Activity parent ) {
|
|
||||||
this.parent = parent;
|
|
||||||
|
|
||||||
mDbHelper = new DbAdapter(this.parent);
|
|
||||||
mDbHelper.open();
|
|
||||||
|
|
||||||
if (parent instanceof OnComplete ) {
|
|
||||||
this.onCompleteListener = (OnComplete) parent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnCompleteListener(OnComplete onCompleteListener) {
|
|
||||||
this.onCompleteListener = onCompleteListener;
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Runnable getTask();
|
@Override
|
||||||
|
public void onActivityCreated(Bundle arg0) {
|
||||||
public void start() {
|
super.onActivityCreated(arg0);
|
||||||
handler = new Handler();
|
Activity parent = getActivity();
|
||||||
progress = ProgressDialog.show(parent, null, "");
|
if ( parent instanceof OnTCQueryCompleteListener ) {
|
||||||
|
onCompleteListener = (OnTCQueryCompleteListener) parent;
|
||||||
downloadThread = new Thread( getTask() );
|
}
|
||||||
downloadThread.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The return value is a message string which may be displayed by the caller.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected abstract class TCQueryTask extends AsyncTask<Void,Void,String> {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
DialogFragment newFragment = ProgressDialogFragment.newInstance("", "");
|
||||||
|
newFragment.show(getFragmentManager(), PROGRESS_DIALOG_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
public void dismiss() {
|
@Override
|
||||||
// TODO - need to kill the thread.
|
protected void onPostExecute(String obj) {
|
||||||
|
super.onPostExecute(obj);
|
||||||
|
AndroidLogWrapper.d(TCQueryAction.class,"Finished loading " + TCQueryAction.this);
|
||||||
|
dismiss();
|
||||||
|
if (onCompleteListener != null ) {
|
||||||
|
onCompleteListener.onTCQueryComplete(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mDbHelper.close();
|
protected void writeMotor( TCMotor mi, MotorBurnFile b) throws Exception {
|
||||||
|
|
||||||
if ( progress != null && progress.isShowing() ) {
|
DbAdapter mDbHelper = new DbAdapter(getActivity());
|
||||||
|
mDbHelper.open();
|
||||||
|
try {
|
||||||
|
ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor();
|
||||||
|
|
||||||
|
m.setThrustCurveMotor( b.getThrustCurveMotor() );
|
||||||
|
|
||||||
|
// Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A.
|
||||||
|
m.setImpulseClass(mi.getImpulse_class());
|
||||||
|
if ( "a".equalsIgnoreCase(mi.getImpulse_class())) {
|
||||||
|
if( mi.getCommon_name().startsWith("1/2A") ) {
|
||||||
|
m.setImpulseClass("1/2A");
|
||||||
|
} else if (mi.getCommon_name().startsWith("1/4A") ) {
|
||||||
|
m.setImpulseClass("1/4A");
|
||||||
|
} else if (mi.getCommon_name().startsWith("Micro") ) {
|
||||||
|
m.setImpulseClass("1/8A");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert Case Info.
|
||||||
|
if ( mi.getCase_info() == null
|
||||||
|
|| "single use".equalsIgnoreCase(mi.getCase_info())
|
||||||
|
|| "single-use".equalsIgnoreCase(mi.getCase_info())) {
|
||||||
|
m.setCaseInfo(mi.getType()+ " " + mi.getDiameter() + "x" + mi.getLength());
|
||||||
|
} else {
|
||||||
|
m.setCaseInfo(mi.getCase_info());
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidLogWrapper.d(TCQueryAction.class,"adding motor " + m.toString());
|
||||||
|
// Write motor.
|
||||||
|
mDbHelper.getMotorDao().insertOrUpdateMotor(m);
|
||||||
|
} finally {
|
||||||
|
mDbHelper.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void dismiss() {
|
||||||
|
AndroidLogWrapper.d(TCQueryAction.class,"dismiss the progress");
|
||||||
|
ProgressDialogFragment progress = (ProgressDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag(PROGRESS_DIALOG_TAG);
|
||||||
|
if ( progress != null ) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,40 +148,9 @@ public abstract class TCQueryAction {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
progress.setMessage(newMessage);
|
ProgressDialogFragment progress = (ProgressDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag(PROGRESS_DIALOG_TAG);
|
||||||
}
|
if ( progress != null )
|
||||||
}
|
progress.setMessage(newMessage);
|
||||||
|
|
||||||
protected class Dismiss implements Runnable {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
progress.dismiss();
|
|
||||||
if (onCompleteListener != null ) {
|
|
||||||
onCompleteListener.onComplete();
|
|
||||||
}
|
|
||||||
// TCQueryActivity.this.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class Error implements Runnable {
|
|
||||||
private String newMessage;
|
|
||||||
Error( String message ) {
|
|
||||||
this.newMessage = message;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
progress.dismiss();
|
|
||||||
final AlertDialog dialog = new AlertDialog.Builder(parent).create();
|
|
||||||
dialog.setMessage(newMessage);
|
|
||||||
dialog.setButton(DialogInterface.BUTTON_NEUTRAL,"Dismiss", new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface arg0, int arg1) {
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,25 +2,23 @@ package net.sf.openrocket.android.thrustcurve;
|
|||||||
|
|
||||||
import net.sf.openrocket.R;
|
import net.sf.openrocket.R;
|
||||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
import android.app.Activity;
|
import net.sf.openrocket.android.util.ErrorDialogFragment;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
public class TCQueryActivity extends Activity
|
public class TCQueryActivity extends FragmentActivity
|
||||||
implements TCQueryAction.OnComplete
|
implements TCQueryAction.OnTCQueryCompleteListener
|
||||||
{
|
{
|
||||||
|
|
||||||
private TCSearchAction queryAction;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.tcqueryform);
|
setContentView(R.layout.tcqueryform);
|
||||||
|
|
||||||
queryAction = new TCSearchAction(this);
|
|
||||||
|
|
||||||
final Spinner manufacturerField = (Spinner) findViewById(R.id.TCMotorSearchFormManufacturerField);
|
final Spinner manufacturerField = (Spinner) findViewById(R.id.TCMotorSearchFormManufacturerField);
|
||||||
final Spinner impulseField = (Spinner) findViewById(R.id.TCMotorSearchFormImpulseField);
|
final Spinner impulseField = (Spinner) findViewById(R.id.TCMotorSearchFormImpulseField);
|
||||||
@ -33,7 +31,7 @@ implements TCQueryAction.OnComplete
|
|||||||
@Override
|
@Override
|
||||||
public void onClick( View v ) {
|
public void onClick( View v ) {
|
||||||
AndroidLogWrapper.d(TCQueryActivity.class,"submit button clicked");
|
AndroidLogWrapper.d(TCQueryActivity.class,"submit button clicked");
|
||||||
|
|
||||||
String commonName = commonNameField.getText().toString();
|
String commonName = commonNameField.getText().toString();
|
||||||
|
|
||||||
SearchRequest r = new SearchRequest();
|
SearchRequest r = new SearchRequest();
|
||||||
@ -54,29 +52,20 @@ implements TCQueryAction.OnComplete
|
|||||||
}
|
}
|
||||||
r.setCommon_name(commonName);
|
r.setCommon_name(commonName);
|
||||||
|
|
||||||
queryAction.setRequest(r);
|
TCSearchAction motorfrag = TCSearchAction.newInstance( r );
|
||||||
queryAction.start();
|
getSupportFragmentManager().beginTransaction().add( motorfrag, "dloader").commit();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onTCQueryComplete(String message) {
|
||||||
finish();
|
if ( message != null) {
|
||||||
}
|
ErrorDialogFragment error = ErrorDialogFragment.newInstance(message);
|
||||||
|
error.show(getSupportFragmentManager(), "ErrorDialog");
|
||||||
/*
|
} else {
|
||||||
* TODO - ??
|
finish();
|
||||||
@Override
|
}
|
||||||
public Object onRetainNonConfigurationInstance() {
|
|
||||||
return downloadThread;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
queryAction.dismiss();
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,28 @@
|
|||||||
package net.sf.openrocket.android.thrustcurve;
|
package net.sf.openrocket.android.thrustcurve;
|
||||||
|
|
||||||
import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor;
|
|
||||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
public class TCSearchAction extends TCQueryAction {
|
public class TCSearchAction extends TCQueryAction {
|
||||||
|
|
||||||
private SearchRequest request;
|
public static TCSearchAction newInstance( SearchRequest searchRequest ) {
|
||||||
|
TCSearchAction frag = new TCSearchAction();
|
||||||
public TCSearchAction(Activity parent) {
|
frag.task = frag.new Downloader(searchRequest);
|
||||||
super(parent);
|
return frag;
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequest( SearchRequest request ) {
|
|
||||||
this.request = request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Runnable getTask() {
|
private class Downloader extends TCQueryAction.TCQueryTask {
|
||||||
return new Downloader();
|
|
||||||
}
|
private SearchRequest searchRequest;
|
||||||
|
|
||||||
private class Downloader implements Runnable {
|
private Downloader( SearchRequest searchRequest ) {
|
||||||
|
this.searchRequest = searchRequest;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected String doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
handler.post( new UpdateMessage("Quering Thrustcurve"));
|
handler.post( new UpdateMessage("Quering Thrustcurve"));
|
||||||
SearchResponse res = new ThrustCurveAPI().doSearch(request);
|
SearchResponse res = new ThrustCurveAPI().doSearch(searchRequest);
|
||||||
|
|
||||||
int total = res.getResults().size();
|
int total = res.getResults().size();
|
||||||
int count = 1;
|
int count = 1;
|
||||||
@ -48,50 +44,24 @@ public class TCSearchAction extends TCQueryAction {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MotorBurnFile b = new ThrustCurveAPI().downloadData(mi.getMotor_id());
|
|
||||||
|
|
||||||
AndroidLogWrapper.d(TCQueryAction.class, mi.toString());
|
AndroidLogWrapper.d(TCQueryAction.class, mi.toString());
|
||||||
|
|
||||||
ExtendedThrustCurveMotor m = new ExtendedThrustCurveMotor();
|
MotorBurnFile b = new ThrustCurveAPI().downloadData(mi.getMotor_id());
|
||||||
|
|
||||||
m.setThrustCurveMotor( b.getThrustCurveMotor() );
|
writeMotor( mi, b);
|
||||||
|
|
||||||
// Convert impulse class. ThrustCurve puts mmx, 1/4a and 1/2a as A.
|
|
||||||
m.setImpulseClass(mi.getImpulse_class());
|
|
||||||
if ( "a".equalsIgnoreCase(mi.getImpulse_class())) {
|
|
||||||
if( mi.getCommon_name().startsWith("1/2A") ) {
|
|
||||||
m.setImpulseClass("1/2A");
|
|
||||||
} else if (mi.getCommon_name().startsWith("1/4A") ) {
|
|
||||||
m.setImpulseClass("1/4A");
|
|
||||||
} else if (mi.getCommon_name().startsWith("Micro") ) {
|
|
||||||
m.setImpulseClass("1/8A");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert Case Info.
|
|
||||||
if ( mi.getCase_info() == null
|
|
||||||
|| "single use".equalsIgnoreCase(mi.getCase_info())
|
|
||||||
|| "single-use".equalsIgnoreCase(mi.getCase_info())) {
|
|
||||||
m.setCaseInfo(mi.getType()+ " " + mi.getDiameter() + "x" + mi.getLength());
|
|
||||||
} else {
|
|
||||||
m.setCaseInfo(mi.getCase_info());
|
|
||||||
}
|
|
||||||
|
|
||||||
AndroidLogWrapper.d(TCQueryAction.class,"adding motor " + m.toString());
|
|
||||||
// Write motor.
|
|
||||||
mDbHelper.getMotorDao().insertOrUpdateMotor(m);
|
|
||||||
}
|
}
|
||||||
if ( total < res.getMatches() ) {
|
if ( total < res.getMatches() ) {
|
||||||
handler.post( new Error( total + " motors downloaded, " + res.getMatches() + " matched. Try restricting the query more.") );
|
dismiss();
|
||||||
|
return "" + total + " motors downloaded, " + res.getMatches() + " matched. Try restricting the query more.";
|
||||||
} else {
|
} else {
|
||||||
handler.post( new Dismiss());
|
dismiss();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( Exception ex){
|
catch( Exception ex){
|
||||||
AndroidLogWrapper.d(TCQueryAction.class,ex.toString());
|
AndroidLogWrapper.d(TCSearchAction.class,ex.toString());
|
||||||
handler.post( new Error(ex.toString()) );
|
return ex.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package net.sf.openrocket.android.util;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
|
public class ErrorDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public static ErrorDialogFragment newInstance( String message ) {
|
||||||
|
ErrorDialogFragment dialog = new ErrorDialogFragment();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString("message",message);
|
||||||
|
dialog.setArguments(b);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
String message = getArguments().getString("message");
|
||||||
|
final AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
|
||||||
|
dialog.setOwnerActivity(getActivity());
|
||||||
|
dialog.setMessage(message);
|
||||||
|
dialog.setCancelable(false);
|
||||||
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
|
dialog.setButton(DialogInterface.BUTTON_NEUTRAL,"Dismiss", new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,8 @@ import android.support.v4.app.DialogFragment;
|
|||||||
|
|
||||||
public class ProgressDialogFragment extends DialogFragment {
|
public class ProgressDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
ProgressDialog progressDialog;
|
||||||
|
|
||||||
public static ProgressDialogFragment newInstance(String title, String message) {
|
public static ProgressDialogFragment newInstance(String title, String message) {
|
||||||
ProgressDialogFragment fragment = new ProgressDialogFragment();
|
ProgressDialogFragment fragment = new ProgressDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
@ -16,20 +18,35 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
|
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
String title = getArguments().getString("title");
|
String title = null;
|
||||||
String message = getArguments().getString("message");
|
String message = null;
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if ( args != null ) {
|
||||||
|
title = getArguments().getString("title");
|
||||||
|
message = getArguments().getString("message");
|
||||||
|
}
|
||||||
|
|
||||||
ProgressDialog progressDialog = new ProgressDialog(getActivity());
|
AndroidLogWrapper.d(ProgressDialogFragment.class, "onCreateDialog");
|
||||||
|
progressDialog = new ProgressDialog(getActivity());
|
||||||
progressDialog.setTitle(title);
|
progressDialog.setTitle(title);
|
||||||
progressDialog.setMessage(message);
|
progressDialog.setMessage(message);
|
||||||
|
|
||||||
progressDialog.setCancelable(false);
|
progressDialog.setCancelable(false);
|
||||||
|
progressDialog.setCanceledOnTouchOutside(false);
|
||||||
|
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
|
|
||||||
return progressDialog;
|
return progressDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMessage( String message ) {
|
||||||
|
progressDialog.setMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user