Exemple #1
0
  /**
   * Set summary for preference
   *
   * @param pref preference
   * @param init true if no recursive
   */
  private void setSummary(Preference pref, boolean init) {
    if (pref instanceof EditTextPreference) {
      EditTextPreference editPref = (EditTextPreference) pref;
      pref.setSummary(editPref.getText());

      if (editPref.getKey().equals("logfile") && !init) {
        editPref.setText(PrefStore.getLogFile(this));
        pref.setSummary(editPref.getText());
      }
    }

    if (pref instanceof ListPreference) {
      ListPreference listPref = (ListPreference) pref;
      pref.setSummary(listPref.getEntry());
    }

    if (pref instanceof CheckBoxPreference) {
      CheckBoxPreference checkPref = (CheckBoxPreference) pref;

      if (checkPref.getKey().equals("logger") && checkPref.isChecked() && init) {
        requestWritePermissions();
      }
    }
  }
  private void setSummary(Preference pref, boolean init) {
    if (pref instanceof EditTextPreference) {
      EditTextPreference editPref = (EditTextPreference) pref;
      pref.setSummary(editPref.getText());

      if (editPref.getKey().equals("serverdns") && editPref.getText().length() == 0) {
        pref.setSummary(getString(R.string.summary_serverdns_preference));
      }
      if (editPref.getKey().equals("disksize") && editPref.getText().equals("0")) {
        pref.setSummary(getString(R.string.summary_disksize_preference));
      }
      if (editPref.getKey().equals("diskimage") && !init) {
        editPref.setText(PrefStore.getTargetPath(this));
        pref.setSummary(editPref.getText());
      }
      if (editPref.getKey().equals("vncwidth") && editPref.getText().length() == 0) {
        editPref.setText(PrefStore.getScreenWidth(this).toString());
        pref.setSummary(editPref.getText());
      }
      if (editPref.getKey().equals("vncheight") && editPref.getText().length() == 0) {
        editPref.setText(PrefStore.getScreenHeight(this).toString());
        pref.setSummary(editPref.getText());
      }
    }

    if (pref instanceof ListPreference) {
      ListPreference listPref = (ListPreference) pref;
      pref.setSummary(listPref.getEntry());

      if (listPref.getKey().equals("distribution")) {
        ListPreference suite = (ListPreference) findPreference("suite");
        ListPreference architecture = (ListPreference) findPreference("architecture");
        EditTextPreference mirror = (EditTextPreference) findPreference("mirror");
        MultiSelectListPreferenceCompat components =
            (MultiSelectListPreferenceCompat) findPreference("xcomponents");

        String distributionStr = listPref.getValue();

        // suite
        int suiteValuesId =
            PrefStore.getResourceId(this, distributionStr + "_suite_values", "array");
        if (suiteValuesId != -1) {
          suite.setEntries(suiteValuesId);
          suite.setEntryValues(suiteValuesId);
        }
        if (init) {
          int suiteId = PrefStore.getResourceId(this, distributionStr + "_suite", "string");
          if (suiteId != -1) {
            String suiteStr = getString(suiteId);
            if (suiteStr.length() > 0) suite.setValue(suiteStr);
          }
        }
        suite.setSummary(suite.getEntry());
        suite.setEnabled(true);

        // architecture
        int architectureValuesId =
            PrefStore.getResourceId(this, distributionStr + "_architecture_values", "array");
        if (suiteValuesId != -1) {
          architecture.setEntries(architectureValuesId);
          architecture.setEntryValues(architectureValuesId);
        }
        if (init || architecture.getValue().length() == 0) {
          int architectureId =
              PrefStore.getResourceId(
                  this, PrefStore.getArch() + "_" + distributionStr + "_architecture", "string");
          if (architectureId != -1) {
            String architectureStr = getString(architectureId);
            if (architectureStr.length() > 0) architecture.setValue(architectureStr);
          }
        }
        architecture.setSummary(architecture.getEntry());
        architecture.setEnabled(true);

        // mirror
        if (init || mirror.getText().length() == 0) {
          int mirrorId =
              PrefStore.getResourceId(
                  this, PrefStore.getArch() + "_" + distributionStr + "_mirror", "string");
          if (mirrorId != -1) {
            mirror.setText(getString(mirrorId));
          }
        }
        mirror.setSummary(mirror.getText());
        mirror.setEnabled(true);

        // components
        int componentsEntriesId =
            PrefStore.getResourceId(this, distributionStr + "_components_entries", "array");
        int componentsValuesId =
            PrefStore.getResourceId(this, distributionStr + "_components_values", "array");
        if (componentsEntriesId != -1 && componentsValuesId != -1) {
          components.setEntries(componentsEntriesId);
          components.setEntryValues(componentsValuesId);
        }
        if (init) {
          components.setValues(
              new HashSet<String>(
                  Arrays.asList(getResources().getStringArray(R.array.default_components))));
        }
        components.setEnabled(true);

        // RootFS
        if (distributionStr.equals("rootfs")) {
          // suite
          suite.setEnabled(false);
          // architecture
          architecture.setEnabled(false);
          // mirror
          if (init) {
            String archiveFile = PrefStore.getStorage() + "/linux-rootfs.tar.gz";
            mirror.setText(archiveFile);
          }
          mirror.setSummary(mirror.getText());
          mirror.setEnabled(true);
          // components
          components.setEnabled(false);
        }
      }
      if (listPref.getKey().equals("architecture") && init) {
        ListPreference distribution = (ListPreference) findPreference("distribution");
        EditTextPreference mirror = (EditTextPreference) findPreference("mirror");

        String architectureStr = PrefStore.getArch(listPref.getValue());
        String distributionStr = distribution.getValue();

        int mirrorId =
            PrefStore.getResourceId(
                this, architectureStr + "_" + distributionStr + "_mirror", "string");
        if (mirrorId != -1) {
          mirror.setText(getString(mirrorId));
        }

        mirror.setSummary(mirror.getText());
      }
      if (listPref.getKey().equals("deploytype")) {
        EditTextPreference diskimage = (EditTextPreference) findPreference("diskimage");
        EditTextPreference disksize = (EditTextPreference) findPreference("disksize");
        ListPreference fstype = (ListPreference) findPreference("fstype");

        switch (listPref.getValue()) {
          case "file":
            if (init) {
              diskimage.setText(PrefStore.getValues(this, R.string.targetpath_file));
            }
            disksize.setEnabled(true);
            fstype.setEnabled(true);
            break;
          case "partition":
            if (init) {
              diskimage.setText(PrefStore.getValues(this, R.string.targetpath_partition));
            }
            disksize.setEnabled(false);
            fstype.setEnabled(true);
            break;
          case "ram":
            if (init) {
              diskimage.setText(PrefStore.getValues(this, R.string.targetpath_ram));
            }
            disksize.setEnabled(true);
            fstype.setEnabled(false);
            break;
          default:
            if (init) {
              diskimage.setText(PrefStore.getValues(this, R.string.targetpath_directory));
            }
            disksize.setEnabled(false);
            fstype.setEnabled(false);
        }
      }
    }
  }