Rework the motor browser functionality to make it more tablet friendly.

This commit is contained in:
Kevin Ruland 2012-02-06 01:31:51 +00:00
parent ad86008f28
commit 3f37586278
13 changed files with 326 additions and 262 deletions

View File

@ -72,7 +72,7 @@
</intent-filter>
</activity>
<activity android:name=".android.motor.MotorBrowserActivity" />
<activity android:name=".android.motor.MotorDetailsActivity" />
<activity android:name=".android.motor.BurnPlotActivity" />
<activity android:name=".android.thrustcurve.TCQueryActivity" />
<activity android:name=".android.simulation.SimulationViewActivity" />
<activity android:name=".android.filebrowser.SimpleFileBrowser" />

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/motorBrowserList"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="4"/>
<LinearLayout
android:id="@+id/sidepane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" />
</LinearLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/motorBrowserList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3" />
<LinearLayout
android:id="@+id/sidepane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" />
</LinearLayout>

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/burnPlotFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0px"
android:layout_marginRight="0px"
android:layout_marginTop="5px"
class="net.sf.openrocket.android.motor.BurnPlotFragment"
title="Burn Plot" />
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:content="@+id/motorDetailForm"
android:handle="@+id/handle" >
<ImageView
android:id="@+id/handle"
android:layout_width="match_parent"
android:layout_height="30px"
android:src="@drawable/arrow_up_float"
android:text="" />
<fragment
android:id="@+id/motorDetailForm"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="net.sf.openrocket.android.motor.MotorDetailsFragment" />
</SlidingDrawer>
</FrameLayout>

View File

@ -1,108 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/motorDetailForm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:orientation="vertical"
android:paddingTop="10px" >
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" >
<TableRow >
<TableLayout
android:id="@+id/motorDetailForm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:orientation="vertical"
android:paddingTop="10dp" >
<TextView
android:paddingRight="10px"
android:text="Manufacturer" />
<TableRow>
<EditText
android:id="@+id/motorDetailsManufacturer"
android:layout_width="match_parent"
<TextView
android:paddingRight="10dp"
android:text="Manufacturer" />
<EditText
android:id="@+id/motorDetailsManufacturer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Name" />
<EditText
android:id="@+id/motorDetailsName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Delays" />
<EditText
android:id="@+id/motorDetailsDelays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="number" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Case Info" />
<EditText
android:id="@+id/motorDetailsCaseInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Impulse Class" />
<EditText
android:id="@+id/motorDetailsImpuseClass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Diameter" />
<EditText
android:id="@+id/motorDetailsDiameter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:paddingRight="10dp"
android:text="Length" />
<EditText
android:id="@+id/motorDetailsLength"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false"
android:inputType="text" />
</TableRow>
</TableLayout>
<!--
<Button
android:id="@+id/motorDetailsSaveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
android:text="@string/save" />
-->
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Name" />
<EditText
android:id="@+id/motorDetailsName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Delays" />
<EditText
android:id="@+id/motorDetailsDelays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Case Info" />
<EditText
android:id="@+id/motorDetailsCaseInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Impulse Class" />
<EditText
android:id="@+id/motorDetailsImpuseClass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Diameter" />
<EditText
android:id="@+id/motorDetailsDiameter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
<TableRow >
<TextView
android:paddingRight="10px"
android:text="Length" />
<EditText
android:id="@+id/motorDetailsLength"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:editable="false" />
</TableRow>
</TableLayout>
</ScrollView>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/motorBrowserList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:enabled="true" android:id="@+id/save" android:visible="true" android:title="@string/save"/>
</menu>

View File

@ -0,0 +1,23 @@
package net.sf.openrocket.android.motor;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class BurnPlotActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidLogWrapper.d(BurnPlotActivity.class,"onCreate Bundle = "+ String.valueOf(savedInstanceState));
Intent i = getIntent();
long motorId = i.getLongExtra("Motor",-1);
BurnPlotFragment burnPlot = BurnPlotFragment.newInstance(motorId);
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, burnPlot).commit();
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Vector;
import net.sf.openrocket.R;
import net.sf.openrocket.android.db.DbAdapter;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import android.graphics.Color;
import android.graphics.PointF;
@ -27,6 +28,7 @@ import com.androidplot.xy.YValueMarker;
public class BurnPlotFragment extends Fragment implements OnTouchListener {
private ExtendedThrustCurveMotor motor;
private long motorId;
private XYPlot mySimpleXYPlot;
private SimpleXYSeries mySeries;
@ -39,12 +41,44 @@ public class BurnPlotFragment extends Fragment implements OnTouchListener {
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;
public static BurnPlotFragment newInstance( long motorId ) {
BurnPlotFragment frag = new BurnPlotFragment();
Bundle bundle = new Bundle();
bundle.putLong("motorId", motorId);
frag.setArguments(bundle);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
AndroidLogWrapper.d(BurnPlotFragment.class,"onCreate");
if ( savedInstanceState!= null) {
motorId = savedInstanceState.getLong("motorId",-1);
} else {
Bundle b = getArguments();
motorId = b.getLong("motorId");
}
DbAdapter mDbHelper = new DbAdapter(getActivity());
mDbHelper.open();
try {
motor = mDbHelper.getMotorDao().fetchMotor(motorId);
} catch ( Exception e ) {
}
mDbHelper.close();
super.onCreate(savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong("motorId", motorId);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -53,6 +87,7 @@ public class BurnPlotFragment extends Fragment implements OnTouchListener {
mySimpleXYPlot = (XYPlot) v.findViewById(R.id.xyplot);
mySimpleXYPlot.setOnTouchListener(this);
mScaleDetector = new ScaleGestureDetector(v.getContext(), new ScaleListener());
init(motor);
return v;
}
@ -63,7 +98,8 @@ public class BurnPlotFragment extends Fragment implements OnTouchListener {
}
return l;
}
void init( ExtendedThrustCurveMotor motor ) {
private void init( ExtendedThrustCurveMotor motor ) {
mySimpleXYPlot.setUserDomainOrigin(0);
mySimpleXYPlot.setUserRangeOrigin(0);

View File

@ -6,6 +6,7 @@ import net.sf.openrocket.android.PreferencesActivity;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
@ -23,13 +24,8 @@ implements MotorListFragment.OnMotorSelectedListener
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
motorList = MotorListFragment.newInstance();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(android.R.id.content, motorList);
ft.commit();
}
setContentView(R.layout.motorbrowser);
getSupportFragmentManager().beginTransaction().add( R.id.motorBrowserList, new MotorListFragment()).commit();
}
@Override
@ -59,23 +55,19 @@ implements MotorListFragment.OnMotorSelectedListener
View sidepane = findViewById(R.id.sidepane);
if ( /* if multi pane */ sidepane != null ) {
/*
Simulation sim = app.getRocketDocument().getSimulation(simulationId);
SimulationChart chart = new SimulationChart(simulationId);
Fragment graph = SimulationFragment.newInstance(chart);
Fragment graph = BurnPlotFragment.newInstance(motorId);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
// probably only want to update back stack for first time.
ft.addToBackStack("simulationplot");
ft.addToBackStack("burnplot");
ft.replace(R.id.sidepane, graph);
ft.show(graph);
ft.commit();
*/
} else {
Intent i = new Intent(this,MotorDetailsActivity.class);
Intent i = new Intent(this,BurnPlotActivity.class);
i.putExtra("Motor", motorId);
startActivity(i);
}

View File

@ -1,87 +0,0 @@
package net.sf.openrocket.android.motor;
import net.sf.openrocket.R;
import net.sf.openrocket.android.db.DbAdapter;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
public class MotorDetailsActivity extends FragmentActivity
implements SlidingDrawer.OnDrawerCloseListener, SlidingDrawer.OnDrawerOpenListener {
private SlidingDrawer slidingDrawer;
private ImageView handle;
private ExtendedThrustCurveMotor motor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidLogWrapper.d(MotorDetailsActivity.class,"onCreate Bundle = "+ String.valueOf(savedInstanceState));
setContentView(R.layout.motor_detail);
Intent i = getIntent();
long motorId = i.getLongExtra("Motor",-1);
DbAdapter mDbHelper = new DbAdapter(this);
mDbHelper.open();
try {
motor = mDbHelper.getMotorDao().fetchMotor(motorId);
} catch ( Exception e ) {
}
mDbHelper.close();
BurnPlotFragment burnPlot = (BurnPlotFragment) getSupportFragmentManager().findFragmentById(R.id.burnPlotFragment);
burnPlot.init(motor);
MotorDetailsFragment motorDetails = (MotorDetailsFragment) getSupportFragmentManager().findFragmentById(R.id.motorDetailForm);
motorDetails.init(motor);
slidingDrawer = (SlidingDrawer) findViewById(R.id.drawer);
slidingDrawer.setOnDrawerOpenListener(this);
slidingDrawer.setOnDrawerCloseListener(this);
handle = (ImageView) findViewById(R.id.handle);
}
@Override
public void onDrawerOpened() {
handle.setImageResource(R.drawable.arrow_down_float);
}
@Override
public void onDrawerClosed() {
handle.setImageResource(R.drawable.arrow_up_float);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.motor_details_option_menu, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case R.id.save:
// Extract form data to Motor.
// Save motor.
return true;
}
return super.onMenuItemSelected(featureId, item);
}
}

View File

@ -2,15 +2,17 @@ package net.sf.openrocket.android.motor;
import net.sf.openrocket.R;
import net.sf.openrocket.android.db.ConversionUtils;
import net.sf.openrocket.android.db.DbAdapter;
import net.sf.openrocket.motor.ThrustCurveMotor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
public class MotorDetailsFragment extends Fragment {
public class MotorDetailsFragment extends DialogFragment {
EditText manuField;
EditText nameField;
@ -19,7 +21,44 @@ public class MotorDetailsFragment extends Fragment {
EditText impulseClassField;
EditText diameterField;
EditText lengthField;
ExtendedThrustCurveMotor motor;
public static MotorDetailsFragment newInstance( long motorId ) {
MotorDetailsFragment fragment = new MotorDetailsFragment();
Bundle b = new Bundle();
b.putLong("motorId", motorId);
fragment.setArguments(b);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE,getTheme());
Long motorId;
if ( savedInstanceState != null ) {
motorId = savedInstanceState.getLong("motorId");
} else {
Bundle b = getArguments();
motorId = b.getLong("motorId");
}
DbAdapter mDbHelper = new DbAdapter(getActivity());
mDbHelper.open();
try {
motor = mDbHelper.getMotorDao().fetchMotor(motorId);
} catch ( Exception e ) {
}
mDbHelper.close();
}
@Override
public void onSaveInstanceState(Bundle arg0) {
super.onSaveInstanceState(arg0);
arg0.putLong("motorId", motor.getId());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -31,19 +70,37 @@ public class MotorDetailsFragment extends Fragment {
impulseClassField = (EditText) v.findViewById(R.id.motorDetailsImpuseClass);
diameterField = (EditText) v.findViewById(R.id.motorDetailsDiameter);
lengthField = (EditText) v.findViewById(R.id.motorDetailsLength);
init();
/* TODO - enable saving.
((Button) v.findViewById(R.id.motorDetailsSaveButton)).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
MotorDetailsFragment.this.saveChanges();
}
});
*/
return v;
}
public void init( ExtendedThrustCurveMotor m ) {
ThrustCurveMotor tcm = m.getThrustCurveMotor();
private void init( ) {
ThrustCurveMotor tcm = motor.getThrustCurveMotor();
manuField.setText( tcm.getManufacturer().getDisplayName());
nameField.setText( tcm.getDesignation() );
delaysField.setText( ConversionUtils.delaysToString(tcm.getStandardDelays()) );
caseField.setText( m.getCaseInfo());
impulseClassField.setText( m.getImpulseClass());
caseField.setText( motor.getCaseInfo());
impulseClassField.setText( motor.getImpulseClass());
diameterField.setText( String.valueOf(tcm.getDiameter()*1000.0) );
lengthField.setText( String.valueOf(tcm.getLength()*1000.0) );
}
private void saveChanges() {
DbAdapter mDbHelper = new DbAdapter(getActivity());
mDbHelper.open();
try {
mDbHelper.getMotorDao().insertOrUpdateMotor(motor);
} catch ( Exception e ) {
}
}
}

View File

@ -12,6 +12,9 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
@ -35,12 +38,12 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
}
public static MotorListFragment newInstance( ) {
MotorListFragment frag = new MotorListFragment();
return frag;
}
private static final int CONTEXTMENU_DELETE = Menu.FIRST+1;
private static final int CONTEXTMENU_EDIT = Menu.FIRST+2;
private String groupColumnPreferenceKey;
private String groupColumn = MotorDao.CASE_INFO;
@ -165,6 +168,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Motor Operations");
menu.add(Menu.NONE,CONTEXTMENU_DELETE,CONTEXTMENU_DELETE,"Delete");
menu.add(Menu.NONE,CONTEXTMENU_EDIT,CONTEXTMENU_EDIT,"Edit");
super.onCreateContextMenu(menu, v, menuInfo);
}
@ -178,6 +182,21 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
mDbHelper.getMotorDao().deleteMotor(motorId);
refreshData();
return true;
case CONTEXTMENU_EDIT:
// DialogFragment.show() will take care of adding the fragment
// in a transaction. We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = MotorDetailsFragment.newInstance(motorId);
newFragment.show(ft, "dialog");
return true;
}
return super.onContextItemSelected(item);
}
@ -236,5 +255,5 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
setListAdapter(mAdapter);
}
}
}