コード例 #1
0
 @SuppressWarnings("deprecation")
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.xml.preference);
   m_rememberUser = (CheckBoxPreference) findPreference(Preferences.REMEMBER_USER);
   m_autoLogin = (CheckBoxPreference) findPreference(Preferences.AUTO_LOGIN);
   m_defaultTab = (ListPreference) findPreference(Preferences.DEFAULT_TAB);
   m_rememberUser.setOnPreferenceChangeListener(this);
   m_rememberUser.setOnPreferenceClickListener(this);
   m_defaultTab.setOnPreferenceChangeListener(this);
   m_defaultTab.setOnPreferenceClickListener(this);
 }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.prefs);

    wifiListPref = (ListPreference) findPreference(KEY_WIFI_MODE); // (R.id.wifi_listpref);
    wifiListPref.setOnPreferenceClickListener(this);
    wifiListPref.setOnPreferenceChangeListener(this);

    String wifimode = WifiReceiver.getWifiSettingSSID(this);
    if (wifimode != null) {
      Log.v(TAG, "wifimode != null ::" + wifimode);
      wifiListPref.setSummary(wifimode);
      wifiListPref.setValue(wifimode);
    }
  }
コード例 #3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * Read preferences resources available at res/xml/preferences.xml
     */
    addPreferencesFromResource(R.xml.preferences);

    checkGps();

    ArrayList<CharSequence> pairedDeviceStrings = new ArrayList<>();
    ArrayList<CharSequence> vals = new ArrayList<>();
    ListPreference listBtDevices =
        (ListPreference) getPreferenceScreen().findPreference(BLUETOOTH_LIST_KEY);
    ArrayList<CharSequence> protocolStrings = new ArrayList<>();
    ListPreference listProtocols =
        (ListPreference) getPreferenceScreen().findPreference(PROTOCOLS_LIST_KEY);
    String[] prefKeys =
        new String[] {
          ENGINE_DISPLACEMENT_KEY,
          VOLUMETRIC_EFFICIENCY_KEY,
          OBD_UPDATE_PERIOD_KEY,
          MAX_FUEL_ECON_KEY
        };
    for (String prefKey : prefKeys) {
      EditTextPreference txtPref =
          (EditTextPreference) getPreferenceScreen().findPreference(prefKey);
      txtPref.setOnPreferenceChangeListener(this);
    }

    /*
     * Available OBD commands
     *
     * TODO This should be read from preferences database
     */
    ArrayList<ObdCommand> cmds = ObdConfig.getCommands();
    PreferenceScreen cmdScr =
        (PreferenceScreen) getPreferenceScreen().findPreference(COMMANDS_SCREEN_KEY);
    for (ObdCommand cmd : cmds) {
      CheckBoxPreference cpref = new CheckBoxPreference(this);
      cpref.setTitle(cmd.getName());
      cpref.setKey(cmd.getName());
      cpref.setChecked(true);
      cmdScr.addPreference(cpref);
    }

    /*
     * Available OBD protocols
     *
     */
    for (ObdProtocols protocol : ObdProtocols.values()) {
      protocolStrings.add(protocol.name());
    }
    listProtocols.setEntries(protocolStrings.toArray(new CharSequence[0]));
    listProtocols.setEntryValues(protocolStrings.toArray(new CharSequence[0]));

    /*
     * Let's use this device Bluetooth adapter to select which paired OBD-II
     * compliant device we'll use.
     */
    final BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBtAdapter == null) {
      listBtDevices.setEntries(pairedDeviceStrings.toArray(new CharSequence[0]));
      listBtDevices.setEntryValues(vals.toArray(new CharSequence[0]));

      // we shouldn't get here, still warn user
      Toast.makeText(this, "This device does not support Bluetooth.", Toast.LENGTH_LONG).show();

      return;
    }

    /*
     * Listen for preferences click.
     *
     * TODO there are so many repeated validations :-/
     */
    final Activity thisActivity = this;
    listBtDevices.setEntries(new CharSequence[1]);
    listBtDevices.setEntryValues(new CharSequence[1]);
    listBtDevices.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            // see what I mean in the previous comment?
            if (mBtAdapter == null || !mBtAdapter.isEnabled()) {
              Toast.makeText(
                      thisActivity,
                      "This device does not support Bluetooth or it is disabled.",
                      Toast.LENGTH_LONG)
                  .show();
              return false;
            }
            return true;
          }
        });

    /*
     * Get paired devices and populate preference list.
     */
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
      for (BluetoothDevice device : pairedDevices) {
        pairedDeviceStrings.add(device.getName() + "\n" + device.getAddress());
        vals.add(device.getAddress());
      }
    }
    listBtDevices.setEntries(pairedDeviceStrings.toArray(new CharSequence[0]));
    listBtDevices.setEntryValues(vals.toArray(new CharSequence[0]));
  }