示例#1
0
  public void test02_TestListPreferences() {
    SharedPreferences preferences =
        mActivity.getSharedPreferences(
            VideoTelephony.ENGINEER_MODE_PREFERENCE, WorkingMode.MODE_WORLD_READABLE);
    assertNotNull(preferences);
    ListPreference audioChanneAdaptPref =
        (ListPreference) mActivity.findPreference(AUDIO_CHANNEL_ADAPTATION);
    assertNotNull(audioChanneAdaptPref);
    audioChanneAdaptPref
        .getOnPreferenceChangeListener()
        .onPreferenceChange(audioChanneAdaptPref, "3");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_AUDIO_CHANNEL_ADAPT, "0"), "3");

    ListPreference videoChanneAdaptlPref =
        (ListPreference) mActivity.findPreference(VIDEO_CHANNEL_ADAPTATION);
    assertNotNull(videoChanneAdaptlPref);
    videoChanneAdaptlPref
        .getOnPreferenceChangeListener()
        .onPreferenceChange(videoChanneAdaptlPref, "3");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_VIDEO_CHANNEL_ADAPT, "0"), "3");

    ListPreference videoChanneRevPref =
        (ListPreference) mActivity.findPreference(VIDEO_CHANNEL_REV);
    assertNotNull(videoChanneRevPref);
    videoChanneRevPref.getOnPreferenceChangeListener().onPreferenceChange(videoChanneRevPref, "1");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_VIDEO_CHANNEL_REVERSE, "0"), "1");

    ListPreference multiPref = (ListPreference) mActivity.findPreference(MULTIPLE_LEVEL);
    assertNotNull(multiPref);
    multiPref.getOnPreferenceChangeListener().onPreferenceChange(multiPref, "3");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_MULTIPLEX_LEVEL, "0"), "3");

    ListPreference videoCdecPref = (ListPreference) mActivity.findPreference(VIDEO_CODEC);
    assertNotNull(videoCdecPref);
    videoCdecPref.getOnPreferenceChangeListener().onPreferenceChange(videoCdecPref, "1");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_VIDEO_CODEC_PREFERENCE, "0"), "1");

    ListPreference useWnsrpPref = (ListPreference) mActivity.findPreference(USE_WNSRP);
    assertNotNull(useWnsrpPref);
    useWnsrpPref.getOnPreferenceChangeListener().onPreferenceChange(useWnsrpPref, "1");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_USE_WNSRP, "0"), "1");

    ListPreference terminalTypePref = (ListPreference) mActivity.findPreference(TERMINAL_TYPE);
    assertNotNull(terminalTypePref);
    terminalTypePref.getOnPreferenceChangeListener().onPreferenceChange(terminalTypePref, "1");
    assertEquals(preferences.getString(VideoTelephony.CONFIG_TERMINAL_TYPE, "0"), "1");
  }
示例#2
0
  private static void setupPreferences(PreferenceActivity context) {
    // create Categories
    PreferenceScreen prefScreen = context.getPreferenceManager().createPreferenceScreen(context);
    prefScreen.removeAll();

    // selected location category
    PreferenceCategory selectedCat = new PreferenceCategory(context);
    selectedCat.setTitle(R.string.selected_location_str);
    // location list category
    PreferenceCategory locationListCat = new PreferenceCategory(context);
    locationListCat.setTitle(R.string.location_list_str);
    // general category
    PreferenceCategory generalCat = new PreferenceCategory(context);
    generalCat.setTitle(R.string.general_preferences_str);
    //		//gesture category
    //		PreferenceCategory gestureCat = new PreferenceCategory(context);
    //		gestureCat.setTitle(R.string.gesture_settings_str);

    // add categories to preference screen
    prefScreen.addPreference(selectedCat);
    prefScreen.addPreference(locationListCat);
    //		prefScreen.addPreference(gestureCat);
    prefScreen.addPreference(generalCat);

    // Create add and delete location preferences and add to location list
    locationListCat.addPreference(
        createAddLocationPreference(
            context,
            context.getString(R.string.add_location_str),
            context.getString(R.string.add_location_description_str)));
    locationListCat.addPreference(
        createDeleteLocationPreference(
            context,
            context.getString(R.string.delete_location_str),
            context.getString(R.string.delete_location_description_str)));

    // create apptheme action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_APP_THEME,
            R.string.pref_app_theme,
            R.string.pref_app_theme_description,
            R.array.app_theme_strings,
            R.array.app_theme_values,
            "0"));

    // create mythfrontend update status interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_STATUS_UPDATE_INTERVAL,
            R.string.status_update_interval_str,
            R.string.status_update_interval_description_str,
            R.array.status_Update_Interval_strings,
            R.array.status_Update_Interval_values,
            "0"));

    // create haptic feedback shared preference
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_HAPTIC_FEEDBACK_ENABLED,
            R.string.haptic_feedback_enabled_str,
            R.string.haptic_feedback_enabled_description_str,
            false));

    // create longpress action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_LONGPRESS_ACTION,
            R.string.longpress_action_str,
            R.string.longpress_action_description_str,
            R.array.longpress_action_strings,
            R.array.longpress_action_values,
            "0"));

    // create key repeat interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_KEY_REPEAT_INTERVAL,
            R.string.key_repeat_interval_str,
            R.string.key_repeat_interval_description_str,
            R.array.key_repeat_interval_strings,
            R.array.key_repeat_interval_values,
            "100"));

    // create connection timeout interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_CONNECTION_TIMEOUT_INTERVAL,
            R.string.conection_timeout_interval_str,
            R.string.conection_timeout_interval_description_str,
            R.array.connection_timeout_interval_strings,
            R.array.connection_timeout_interval_values,
            "5000"));

    // create donate button visible checkbox
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_SHOW_DONATE_MENU_ITEM,
            R.string.show_donate_menu_item_str,
            R.string.show_donate_menu_item_str,
            true));

    //		//create gestures enabled
    //		gestureCat.addPreference(createCheckBox(context,
    //				PREF_GESTURES_ENABLED,
    //				R.string.gestures_enabled_str,
    //				R.string.gestures_enabled_str, false));
    //
    //		//gesture list preference
    //		Preference gestureList = createGestureListPreference(context);
    //		gestureCat.addPreference(gestureList);

    // open DB
    MythMoteDbManager _dbAdapter = new MythMoteDbManager(context);
    _dbAdapter.open();

    // get list of locations
    Cursor cursor = _dbAdapter.fetchAllFrontendLocations();

    // get column indexes
    sIdIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID);
    sAddressIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ADDRESS);
    sNameIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME);
    sPortIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_PORT);
    sMacIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_MAC);
    sWifiOnlyIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_WIFIONLY);

    // determine if we have locations saved
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
      // get selected frontend id
      int selected =
          context
              .getSharedPreferences(MYTHMOTE_SHARED_PREFERENCES_ID, MODE_PRIVATE)
              .getInt(MythMotePreferences.PREF_SELECTED_LOCATION, -1);

      // if selected failed
      if (selected == -1) {
        // set to first in list
        selected = cursor.getInt(sIdIndex);
        // save (defaulted) selected location
        SaveSelectedLocationId(context, selected);
      }

      // put each location in the preference list
      for (int i = 0; i < count; i++) {
        locationListCat.addPreference(
            MythMotePreferences.createLocationPreference(
                context,
                cursor.getString(sIdIndex),
                cursor.getString(sNameIndex),
                cursor.getString(sAddressIndex)));

        if (cursor.getInt(sIdIndex) == selected) {
          // create preference for selected location
          selectedCat.addPreference(
              MythMotePreferences.createSelectedLocationPreference(
                  context,
                  context.getString(R.string.selected_location_str),
                  cursor.getString(sNameIndex)));
        }

        cursor.moveToNext();
      }

      // the saved selected location was not found just pick the first one
      if (selectedCat.getPreferenceCount() <= 0) {
        cursor.moveToFirst();
        selectedCat.addPreference(
            MythMotePreferences.createSelectedLocationPreference(
                context,
                context.getString(R.string.selected_location_str),
                cursor.getString(sNameIndex)));

        // save location ID so that it is for real
        SaveSelectedLocationId(context, cursor.getInt(sIdIndex));
      }
    } else {
      selectedCat.addPreference(
          MythMotePreferences.createSelectedLocationPreference(
              context,
              context.getString(R.string.selected_location_str),
              context.getString(R.string.no_frontend_locations_defined_str)));
    }

    cursor.close();
    _dbAdapter.close();

    // set preference screen
    context.setPreferenceScreen(prefScreen);

    // Assign dependences
    //		gestureList.setDependency(PREF_GESTURES_ENABLED);
  }