private void writeClientValuePreference(int id, double value) { // update preferences switch (id) { case R.string.prefs_disk_max_pct_header: clientPrefs.disk_max_used_pct = value; break; case R.string.prefs_disk_min_free_gb_header: clientPrefs.disk_min_free_gb = value; break; case R.string.prefs_network_daily_xfer_limit_mb_header: clientPrefs.daily_xfer_limit_mb = value; break; case R.string.battery_charge_min_pct_header: clientPrefs.battery_charge_min_pct = value; break; case R.string.battery_temperature_max_header: clientPrefs.battery_max_temperature = value; break; case R.string.prefs_cpu_number_cpus_header: clientPrefs.max_ncpus_pct = value; // convert value back to number for layout update value = pctCpuCoresToNumber(value); break; case R.string.prefs_cpu_time_max_header: clientPrefs.cpu_usage_limit = value; break; case R.string.prefs_cpu_other_load_suspension_header: clientPrefs.suspend_cpu_usage = value; break; case R.string.prefs_memory_max_idle_header: clientPrefs.ram_max_used_idle_frac = value; break; default: if (Logging.DEBUG) Log.d(Logging.TAG, "onClick (dialog submit button), couldnt match ID"); Toast toast = Toast.makeText( getApplicationContext(), "ooops! something went wrong...", Toast.LENGTH_SHORT); toast.show(); return; } // update list item updateValuePref(id, value); // preferences adapted, write preferences to client new WriteClientPrefsAsync().execute(clientPrefs); }
// onClick of listview items with prefs_layout_listitem_bool public void onCbClick(View view) { if (Logging.DEBUG) Log.d(Logging.TAG, "onCbClick"); Integer ID = (Integer) view.getTag(); CheckBox source = (CheckBox) view; Boolean isSet = source.isChecked(); switch (ID) { case R.string.prefs_autostart_header: // app pref appPrefs.setAutostart(isSet); updateBoolPref(ID, isSet); updateLayout(); break; case R.string.prefs_show_notification_header: // app pref appPrefs.setShowNotification(isSet); if (isSet) ClientNotification.getInstance(getApplicationContext()).update(); else ClientNotification.getInstance(getApplicationContext()).cancel(); updateBoolPref(ID, isSet); updateLayout(); break; case R.string.prefs_show_advanced_header: // app pref appPrefs.setShowAdvanced(isSet); // reload complete layout to remove/add advanced elements populateLayout(); break; case R.string.prefs_run_on_battery_header: // client pref clientPrefs.run_on_batteries = isSet; updateBoolPref(ID, isSet); new WriteClientPrefsAsync().execute(clientPrefs); // async task triggers layout update break; case R.string.prefs_network_wifi_only_header: // client pref clientPrefs.network_wifi_only = isSet; updateBoolPref(ID, isSet); new WriteClientPrefsAsync().execute(clientPrefs); // async task triggers layout update break; } }