예제 #1
0
 /**
  * onCreateView
  *
  * <p>handles the special case of the serverport entry which is an int....
  */
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
   // prefs.registerOnSharedPreferenceChangeListener(this);
   for (String key : prefs.getAll().keySet()) {
     Preference pref = findPreference(key);
     if (pref == null) continue;
     if (key.equals("serverport")) pref.setSummary("" + prefs.getInt(key, 0));
     else pref.setSummary(prefs.getString(key, key));
   }
   return super.onCreateView(inflater, container, savedInstanceState);
 }
예제 #2
0
  /**
   * onSharedPreferenceChanged not needed in my code, but still in case i have one listpreference,
   * its takes the selected entry to create the summary (planned when/if i add background images to
   * the buttons...
   */
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key) {
    Preference pref = findPreference(key);
    // Log.d(TAG, "preference change for " + key + " " + pref.getTitle());

    // pref.getTitle();
    if (pref instanceof ListPreference) {
      ListPreference listPref = (ListPreference) pref;
      pref.setSummary(listPref.getEntry());
    } else pref.setSummary(sharedPref.getString(key, key));

    // MainActivity mainAct = (MainActivity) getContext();
    // if(mainAct != null) mainAct.onSharedPreferenceChanged(sharedPref,key);
  }
예제 #3
0
 /**
  * For each list dialog, we display the value selected in the "summary" text. When a new value is
  * selected from the list dialog, update the summary to the selected entry.
  */
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   ListPreference list = (ListPreference) preference;
   int index = list.findIndexOfValue((String) newValue);
   CharSequence entry = list.getEntries()[index];
   preference.setSummary(entry);
   return true;
 }
예제 #4
0
 /**
  * Create the "Select Instruments For Each Track " lists. The list of possible instruments is in
  * MidiFile.java.
  */
 private void createInstrumentPrefs(PreferenceScreen root) {
   PreferenceCategory selectInstrTitle = new PreferenceCategory(this);
   selectInstrTitle.setTitle(R.string.select_instruments_per_track);
   root.addPreference(selectInstrTitle);
   selectInstruments = new ListPreference[options.tracks.length];
   for (int i = 0; i < options.instruments.length; i++) {
     selectInstruments[i] = new ListPreference(this);
     selectInstruments[i].setOnPreferenceChangeListener(this);
     selectInstruments[i].setEntries(MidiFile.Instruments);
     selectInstruments[i].setEntryValues(MidiFile.Instruments);
     selectInstruments[i].setTitle("Track " + i);
     selectInstruments[i].setValueIndex(options.instruments[i]);
     selectInstruments[i].setSummary(selectInstruments[i].getEntry());
     root.addPreference(selectInstruments[i]);
   }
   setAllToPiano = new Preference(this);
   setAllToPiano.setTitle(R.string.set_all_to_piano);
   setAllToPiano.setOnPreferenceClickListener(this);
   root.addPreference(setAllToPiano);
 }
예제 #5
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      addPreferencesFromResource(R.xml.settings_ui_fragment);

      final PreferenceCategory preferenceCategory =
          (PreferenceCategory) findPreference("ui.storage");
      final Preference button_f = (Preference) getPreferenceManager().findPreference("ui.rescan");
      if (button_f != null) {
        button_f.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                MainActivity.fullStorageScan();
                preferenceCategory.removePreference(button_f);
                return true;
              }
            });
      }
      final Preference button_u =
          (Preference) getPreferenceManager().findPreference("ui.clear_unavailable");
      if (button_u != null) {
        button_u.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                IndexingDB iDB = new IndexingDB(getActivity());
                List<GameInfoStruct> games = iDB.getIndexGISList(MainActivity.SORT_NONE);
                iDB.close();
                for (GameInfoStruct game : games) {
                  if (!game.getFile().exists()) {
                    game.removeIndex(getActivity());
                  }
                }
                MainActivity.prepareFileListView(false);
                preferenceCategory.removePreference(button_u);
                return true;
              }
            });
      }
      final Preference button_c =
          (Preference) getPreferenceManager().findPreference("ui.clearcache");
      if (button_c != null) {
        button_c.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                MainActivity.clearCache();
                preferenceCategory.removePreference(button_c);
                return true;
              }
            });
      }
    }
예제 #6
0
 /* Create the "Restore Default Settings" preference */
 private void createRestoreDefaultPrefs(PreferenceScreen root) {
   restoreDefaults = new Preference(this);
   restoreDefaults.setTitle(R.string.restore_defaults);
   restoreDefaults.setOnPreferenceClickListener(this);
   root.addPreference(restoreDefaults);
 }