Ejemplo n.º 1
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.º 2
0
 @Override
 public void onResume() {
   super.onResume();
   data.open();
 }