Added way to delete motor configurations through long click in the configurations tab.

This commit is contained in:
Kevin Ruland 2012-07-25 21:26:40 +00:00
parent e73c5500a5
commit 1eb8f3203f
5 changed files with 60 additions and 5 deletions

View File

@ -13,6 +13,8 @@
<string name="configurePlot">Change Plot</string>
<string name="view_events">View Events</string>
<string name="simulationPlotDialogTitle">Select Series And Events</string>
<string name="DeleteConfigTitle">Delete Motor Configuration</string>
<string name="plot">Plot</string>
<string name="saving">Saving file…</string>
<string name="loading">Loading file…</string>

View File

@ -95,6 +95,11 @@ public class CurrentRocket {
return configId;
}
public synchronized void deleteMotorConfig( Context context, String config ) {
rocketDocument.getRocket().removeMotorConfigurationID(config);
notifyMotorConfigChanged(context);
}
/**
* @param rocketDocument the rocketDocument to set
*/

View File

@ -24,6 +24,7 @@ public abstract class ChangeEventBroadcastReceiver extends BroadcastReceiver {
switch( type ) {
case Events.CONFIGS_CHANGED:
doMotorConfigsChanged();
doSimsChanged();
break;
case Events.SIMS_CHANGED:
doSimsChanged();

View File

@ -15,6 +15,9 @@ import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.unit.UnitGroup;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
@ -23,6 +26,7 @@ import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.view.Menu;
@ -73,6 +77,10 @@ public class Configurations extends ExpandableListFragment {
CurrentRocketHolder.getCurrentRocket().addNewMotorConfig(getActivity());
}
private void removeConfiguration( String config ) {
CurrentRocketHolder.getCurrentRocket().deleteMotorConfig( getActivity(), config );
}
private static class MotorMountInfo {
private RocketComponent mmt;
@ -172,11 +180,11 @@ public class Configurations extends ExpandableListFragment {
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if ( convertView == null ) {
convertView = getActivity().getLayoutInflater().inflate(android.R.layout.simple_expandable_list_item_1,null);
}
String configDescription = rocketDocument.getRocket().getMotorConfigurationNameOrDescription((String) getGroup(groupPosition));
((TextView)convertView.findViewById(android.R.id.text1)).setText( configDescription );
return convertView;
@ -222,9 +230,7 @@ public class Configurations extends ExpandableListFragment {
}
@Override
public boolean isChildSelectable(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
@ -233,6 +239,34 @@ public class Configurations extends ExpandableListFragment {
setListAdapter(configurationAdapter);
}
@Override
public boolean onListItemLongClick(ListView l, View v, int position, long id) {
Object o = getExpandableListAdapter().getGroup(position);
if ( o == null || ! (o instanceof String) ) {
return false;
}
final String motorConfigId = (String)o;
AlertDialog.Builder b = new AlertDialog.Builder( getActivity() );
b.setTitle(R.string.DeleteConfigTitle);
b.setCancelable(true);
b.setPositiveButton(R.string.Delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Configurations.this.removeConfiguration(motorConfigId);
}
});
Dialog dialog = b.create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
return true;
}
private class MotorWizardOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {

View File

@ -51,6 +51,14 @@ ExpandableListView.OnGroupCollapseListener, ExpandableListView.OnGroupExpandList
onListItemClick((ListView) parent, v, position, id);
}
};
final private AdapterView.OnItemLongClickListener mOnLongClickListener = new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return onListItemLongClick( (ListView) parent, view, position, id);
}
};
ExpandableListAdapter mAdapter;
ExpandableListView mList;
@ -135,6 +143,10 @@ ExpandableListView.OnGroupCollapseListener, ExpandableListView.OnGroupExpandList
public void onListItemClick(ListView l, View v, int position, long id) {
}
public boolean onListItemLongClick(ListView l, View v, int position, long id ) {
return false;
}
/** Provide the cursor for the list view. */
public void setListAdapter(ExpandableListAdapter adapter) {
boolean hadAdapter = mAdapter != null;
@ -283,6 +295,7 @@ ExpandableListView.OnGroupCollapseListener, ExpandableListView.OnGroupExpandList
}
mListShown = true;
mList.setOnItemClickListener(mOnClickListener);
mList.setOnItemLongClickListener(mOnLongClickListener);
if (mAdapter != null) {
setListAdapter(mAdapter);
} else {