Ejemplo n.º 1
0
  public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
    // Get the name of the selected mineral
    String mineralName = (String) ((ListView) findViewById(R.id.oreList)).getItemAtPosition(pos);
    data.removeMineralFromSector(currentSector, new Mineral(null, mineralName));

    refreshCurrentSector();
    setMineralLists(currentSector);
  }
Ejemplo n.º 2
0
  /**
   * Handles what to do when the add button is clicked. Namely adding the selected mineral to the
   * sector and updating the lists after.
   */
  public void onClick(View v) {
    Mineral mineral = new Mineral();
    String mineralName = (String) ((Spinner) findViewById(R.id.mineralList)).getSelectedItem();

    if (!mineralName.equals(emptyMineralString)) {
      mineral.setMineral(mineralName);

      data.addMineralToSector(currentSector, mineral);
      setMineralLists(currentSector);
    }
  }
Ejemplo n.º 3
0
  /**
   * Gets the currently selected sector
   *
   * @return A Sector containing the information
   */
  public Sector getSelectedSector() {
    Sector info =
        new Sector(
            (String) ((Spinner) findViewById(R.id.systemList)).getSelectedItem(),
            (String) ((Spinner) findViewById(R.id.gridAlphaList)).getSelectedItem(),
            (String) ((Spinner) findViewById(R.id.gridNumList)).getSelectedItem(),
            -1,
            "");

    return data.populate(info);
  }
Ejemplo n.º 4
0
  @Override
  public void onPause() {
    super.onPause();
    // Save the needed preferences
    SharedPreferences.Editor editor = getSharedPreferences(PREFS_NAME, 0).edit();
    // Load the selected items
    Sector selected = getSelectedSector();
    // Dump them all into the right places and save
    editor.putString(PREF_LAST_SYSTEM, selected.getSystem());
    editor.putString(PREF_LAST_SECTOR_APLHA, selected.getAplhaCoord());
    editor.putString(PREF_LAST_SECTOR_NUM, selected.getNumCoord());
    editor.commit();

    data.close();
  }
Ejemplo n.º 5
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    data = new SectorDataSource(this);
    data.open();

    // Get the spinners to use later
    Spinner systemList = (Spinner) findViewById(R.id.systemList);
    Spinner gridAplhaList = (Spinner) findViewById(R.id.gridAlphaList);
    Spinner gridNumList = (Spinner) findViewById(R.id.gridNumList);

    // Make sure we can update the information when something is selected
    systemList.setOnItemSelectedListener(this);
    gridAplhaList.setOnItemSelectedListener(this);
    gridNumList.setOnItemSelectedListener(this);

    // Load up the last selected sector
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

    // Pasted code begins here

    // Set up all the spinners. One for the system and another two for the coords. I hate how messy
    // this is
    ArrayAdapter<String> systemAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Static.systemList);
    systemAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    systemList.setAdapter(systemAdapter);

    // Load the letter selection
    ArrayAdapter<String> gridAlphaAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Static.alphaCoordList);
    gridAlphaAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    gridAplhaList.setAdapter(gridAlphaAdapter);

    // And finally load the number selector
    ArrayAdapter<String> gridNumAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Static.numCoordList);
    gridNumAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    gridNumList.setAdapter(gridNumAdapter);

    // GOGO super uber messy nested method calls and casts!
    systemList.setSelection(
        ((ArrayAdapter<String>) systemList.getAdapter())
            .getPosition(settings.getString(PREF_LAST_SYSTEM, "")));
    gridAplhaList.setSelection(
        ((ArrayAdapter<String>) gridAplhaList.getAdapter())
            .getPosition(settings.getString(PREF_LAST_SECTOR_APLHA, "")));
    gridNumList.setSelection(
        ((ArrayAdapter<String>) gridNumList.getAdapter())
            .getPosition(settings.getString(PREF_LAST_SECTOR_NUM, "")));

    // Add a listener to the add button
    ((Button) findViewById(R.id.button_add_mineral)).setOnClickListener(this);

    // Add the listener to the mineral list
    ((ListView) findViewById(R.id.oreList)).setOnItemClickListener(this);

    // Add the assigned minerals to the list
    Spinner oreSpinner = (Spinner) findViewById(R.id.mineralList);
    // Set up the list
    mineralList = new ArrayList<String>(Static.mineralList);
    // Add it all in
    mineralAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mineralList);
    mineralAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    oreSpinner.setAdapter(mineralAdapter);
  }
Ejemplo n.º 6
0
 private void refreshCurrentSector() {
   currentSector = data.populate(getSelectedSector());
 }
Ejemplo n.º 7
0
 @Override
 public void onResume() {
   super.onResume();
   data.open();
 }