X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=android%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fandroid%2Frocket%2FConfigurations.java;h=9f381de03e5cee5ea49450326c881e894f7d0c66;hb=4095cb0dd61a75b7b6b0bd811f8e803af5b27919;hp=b986a91a2fb17fc7e1101c7f3ad2b8949c469456;hpb=fbf65f0ff8c033467c394e30753548249517de77;p=debian%2Fopenrocket diff --git a/android/src/net/sf/openrocket/android/rocket/Configurations.java b/android/src/net/sf/openrocket/android/rocket/Configurations.java index b986a91a..9f381de0 100644 --- a/android/src/net/sf/openrocket/android/rocket/Configurations.java +++ b/android/src/net/sf/openrocket/android/rocket/Configurations.java @@ -3,7 +3,7 @@ package net.sf.openrocket.android.rocket; import java.util.List; import net.sf.openrocket.R; -import net.sf.openrocket.android.Application; +import net.sf.openrocket.android.CurrentRocketHolder; import net.sf.openrocket.android.db.DbAdapter; import net.sf.openrocket.android.motor.ExtendedThrustCurveMotor; import net.sf.openrocket.android.motor.MotorDelayDialogFragment; @@ -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,8 +26,13 @@ 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; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; + public class Configurations extends ExpandableListFragment { private final static String wizardFrag = "wizardFrag"; @@ -32,30 +40,47 @@ public class Configurations extends ExpandableListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + setHasOptionsMenu(true); View v = inflater.inflate(R.layout.rocket_configurations, container, false); - Button b = (Button) v.findViewById(R.id.openrocketviewerAddConfiguration); - - b.setOnClickListener( new View.OnClickListener() { + return v; + } - @Override - public void onClick(View v) { - ((Application)getActivity().getApplication()).getRocketDocument().getRocket().newMotorConfigurationID(); - Configurations.this.setup(); - } - }); + @Override + public void onResume() { + setup(); + super.onResume(); + } - return v; + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.rocket_viewer_configurations_option_menu, menu); } @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) + { + case R.id.menu_add: + addConfiguration(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + public void refreshConfigsList() { setup(); - } + private void addConfiguration() { + CurrentRocketHolder.getCurrentRocket().addNewMotorConfig(getActivity()); + } + + private void removeConfiguration( String config ) { + CurrentRocketHolder.getCurrentRocket().deleteMotorConfig( getActivity(), config ); + } + private static class MotorMountInfo { private RocketComponent mmt; @@ -91,15 +116,19 @@ public class Configurations extends ExpandableListFragment { } private void setup() { - final OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument(); + final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument(); ExpandableListAdapter configurationAdapter = new BaseExpandableListAdapter() { + // Note: the magic 1 you see below is so the "no motors" configuration + // does not appear in the configuration list. List mmts = rocketDocument.getRocket().getMotorMounts(); @Override public int getGroupCount() { - return rocketDocument.getRocket().getMotorConfigurationIDs().length; + // don't show the "no motors" configuration, so we have one less than the + // array length. + return rocketDocument.getRocket().getMotorConfigurationIDs().length-1; } @Override @@ -109,7 +138,8 @@ public class Configurations extends ExpandableListFragment { @Override public Object getGroup(int groupPosition) { - String config = rocketDocument.getRocket().getMotorConfigurationIDs()[groupPosition]; + // Skip over the "no motors" configuration + String config = rocketDocument.getRocket().getMotorConfigurationIDs()[groupPosition+1]; return config; } @@ -150,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; @@ -200,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; } @@ -211,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) {