1 package net.sf.openrocket.android.thrustcurve;
\r
3 import java.util.List;
\r
5 import net.sf.openrocket.android.util.AndroidLogWrapper;
\r
6 import net.sf.openrocket.motor.ThrustCurveMotor;
\r
8 public class TCSearchAction extends TCQueryAction {
\r
10 public static TCSearchAction newInstance( SearchRequest searchRequest ) {
\r
11 TCSearchAction frag = new TCSearchAction();
\r
12 frag.task = frag.new Downloader(searchRequest);
\r
16 private class Downloader extends TCQueryAction.TCQueryTask {
\r
18 private SearchRequest searchRequest;
\r
20 private Downloader( SearchRequest searchRequest ) {
\r
21 this.searchRequest = searchRequest;
\r
25 protected String doInBackground(Void... params) {
\r
27 handler.post( new UpdateMessage("Quering Thrustcurve"));
\r
28 SearchResponse res = ThrustCurveAPI.doSearch(searchRequest);
\r
30 int total = res.getResults().size();
\r
32 for( TCMotor mi : res.getResults() ) {
\r
33 StringBuilder message = new StringBuilder();
\r
34 message.append("Downloading details ");
\r
36 message.append(count);
\r
37 message.append(" of " );
\r
38 message.append(total);
\r
39 message.append("\n");
\r
41 message.append(mi.getManufacturer());
\r
42 message.append(" ");
\r
43 message.append(mi.getCommon_name());
\r
44 handler.post(new UpdateMessage(message.toString()));
\r
46 if ( mi.getData_files() == null || mi.getData_files().intValue() == 0 ) {
\r
50 AndroidLogWrapper.d(TCQueryAction.class, mi.toString());
\r
52 List<MotorBurnFile> b = ThrustCurveAPI.downloadData(mi.getMotor_id());
\r
53 List<ThrustCurveMotor> motors = ThrustCurveAPI.extractAllMotors(b);
\r
54 if ( motors != null && motors.size() > 0 ) {
\r
55 for( ThrustCurveMotor motor : motors ) {
\r
56 writeMotor( mi, motor);
\r
60 if ( total < res.getMatches() ) {
\r
62 return "" + total + " motors downloaded, " + res.getMatches() + " matched. Try restricting the query more.";
\r
68 catch( Exception ex){
\r
69 AndroidLogWrapper.d(TCSearchAction.class,ex.toString());
\r
70 return ex.toString();
\r