示例#1
0
  private static void showDeleteLocationList(final Activity context) {
    final MythMoteDbManager _dbAdapter = new MythMoteDbManager(context);
    _dbAdapter.open();
    final Cursor cursor = _dbAdapter.fetchAllFrontendLocations();

    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
      final String[] names = new String[count];
      final int[] ids = new int[count];
      for (int i = 0; i < count; i++) {
        names[i] = cursor.getString(cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME));
        ids[i] = cursor.getInt(cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID));
        cursor.moveToNext();
      }

      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setTitle(R.string.delete_location_str);
      builder.setItems(
          names,
          new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
              MythMoteDbManager dbAdapter = new MythMoteDbManager(context);
              dbAdapter.open();
              dbAdapter.deleteFrontendLocation(ids[which]);
              dbAdapter.close();

              setupPreferences((PreferenceActivity) context);
            }
          });
      builder.show();
    }
    cursor.close();
    _dbAdapter.close();
  }
示例#2
0
  public static void SelectLocation(
      final Activity context, final LocationChangedEventListener listener) {
    MythMoteDbManager _dbAdapter = new MythMoteDbManager(context);
    _dbAdapter.open();
    final Cursor cursor = _dbAdapter.fetchAllFrontendLocations();

    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
      final String[] names = new String[count];
      final int[] ids = new int[count];
      for (int i = 0; i < count; i++) {
        names[i] = cursor.getString(cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME));
        ids[i] = cursor.getInt(cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID));
        cursor.moveToNext();
      }

      // show list of locations as a single selected list
      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setTitle(R.string.select_location_str);
      builder.setItems(
          names,
          new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

              // save selected location
              SaveSelectedLocationId(context, ids[which]);

              // notify that we selected a location
              listener.LocationChanged();
            }
          });
      builder.show();
    }
    cursor.close();
    _dbAdapter.close();
  }
示例#3
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);
  }