Skip to content
Snippets Groups Projects
Commit 63176c4b authored by Xavier Gibert's avatar Xavier Gibert
Browse files

mission database saves serialized mission

parent 8de4b82f
No related branches found
No related tags found
No related merge requests found
......@@ -50,4 +50,11 @@
</LinearLayout>
<TextView
android:id="@+id/textViewMissionId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
</LinearLayout>
......@@ -19,9 +19,6 @@
<string name="menu_views_spacecraft_right">Right</string>
<string name="menu_views_earth">Earth</string>
<string name="menu_views_sun">Sun</string>
<string name="sim_mis_mission">Mission:</string>
<string name="sim_mis_description">Description:</string>
<string name="app_name">SatAtt</string>
<string name="about">About</string>
......@@ -128,6 +125,8 @@
<string name="sim_io_error">Simulator IO error</string>
<string name="sim_error">Simulator error</string>
<string name="sim_mission_ended">Mission ended</string>
<string name="sim_mis_mission">Mission:</string>
<string name="sim_mis_description">Description:</string>
<string name="pref_apk_install">Application install</string>
......
......@@ -6,10 +6,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import mission.Mission;
import cs.si.satatt.MainActivity;
import cs.si.satatt.R;
import database.MissionReaderContract.MissionEntry;
import database.MissionReaderDbHelper;
import database.SerializationUtil;
import android.app.Activity;
import android.content.ContentValues;
import android.content.SharedPreferences;
......@@ -153,20 +155,41 @@ public class Installer {
private static boolean addMissionEntry(SQLiteDatabase db){
// Create a new map of values, where column names are the keys
boolean result = true;
ContentValues values = new ContentValues();
values.put(MissionEntry.COLUMN_NAME_ENTRY_ID, "0");
values.put(MissionEntry.COLUMN_NAME_NAME, "Example");
values.put(MissionEntry.COLUMN_NAME_DESCRIPTION, "GTO Mission");
try {
values.put(MissionEntry.COLUMN_NAME_CLASS, SerializationUtil.serialize(new Mission()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Insert the new row, returning the primary key value of the new row
long newRowId;
newRowId = db.insert(
MissionEntry.TABLE_NAME,
null,
values);
if(newRowId!=-1)
return true;
else
return false;
if(newRowId==-1)
result=false;
//Second Example
values = new ContentValues();
values.put(MissionEntry.COLUMN_NAME_NAME, "Example 2");
values.put(MissionEntry.COLUMN_NAME_DESCRIPTION, "GEO Mission");
values.put(MissionEntry.COLUMN_NAME_CLASS, "");
// Insert the new row, returning the primary key value of the new row
newRowId = db.insert(
MissionEntry.TABLE_NAME,
null,
values);
if(newRowId==-1)
result=false;
return result;
}
}
......@@ -8,19 +8,20 @@ public final class MissionReaderContract {
/* Inner class that defines the table contents */
public static abstract class MissionEntry implements BaseColumns {
public static final String TABLE_NAME = "mission";
public static final String COLUMN_NAME_ENTRY_ID = "missionid";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_DESCRIPTION = "description";
public static final String COLUMN_NAME_CLASS = "class";
}
private static final String TEXT_TYPE = " TEXT";
private static final String SERIALIZED_TYPE = " BLOB";
private static final String COMMA_SEP = ",";
static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + MissionEntry.TABLE_NAME + " (" +
MissionEntry._ID + " INTEGER PRIMARY KEY," +
MissionEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE + COMMA_SEP +
MissionEntry.COLUMN_NAME_NAME + TEXT_TYPE + COMMA_SEP +
MissionEntry.COLUMN_NAME_DESCRIPTION + TEXT_TYPE +
MissionEntry.COLUMN_NAME_DESCRIPTION + TEXT_TYPE + COMMA_SEP +
MissionEntry.COLUMN_NAME_CLASS + SERIALIZED_TYPE +
" )";
static final String SQL_DELETE_ENTRIES =
......
package unused;
package database;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import mission.Mission;
import org.orekit.propagation.SpacecraftState;
/**
......@@ -16,13 +18,13 @@ import org.orekit.propagation.SpacecraftState;
public class SerializationUtil {
// deserialize to Object from given file
public static SpacecraftState deserialize(String serialized) throws IOException,
public static Mission deserialize(String serialized) throws IOException,
ClassNotFoundException {
try {
byte b[] = serialized.getBytes();
ByteArrayInputStream bi = new ByteArrayInputStream(b);
ObjectInputStream si = new ObjectInputStream(bi);
SpacecraftState obj = (SpacecraftState) si.readObject();
Mission obj = (Mission) si.readObject();
si.close();
return obj;
} catch (Exception e) {
......
......@@ -146,7 +146,7 @@ public final class SimulatorFragment extends Fragment {
// How you want the results sorted in the resulting Cursor
String sortOrder =
MissionEntry.COLUMN_NAME_NAME + " DESC";
MissionEntry.COLUMN_NAME_NAME + " ASC";
Cursor c = db.query(
MissionEntry.TABLE_NAME, // The table to query
......@@ -163,8 +163,8 @@ public final class SimulatorFragment extends Fragment {
ListAdapter adapter=new SimpleCursorAdapter(this.getActivity().getApplicationContext(),
R.layout.mission_list_item, c,
new String[] {"name", "description"},
new int[] {R.id.textViewMission, R.id.textViewMissionDescription}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
new String[] {"_id", "name", "description"},
new int[] {R.id.textViewMissionId, R.id.textViewMission, R.id.textViewMissionDescription}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER );
missionsList.setAdapter(adapter);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment