import android.os.SystemClock;
import android.preference.Preference;
import android.preference.PreferenceFragment;
+import android.preference.SwitchPreference;
import de.example.exampletdd.R;
import de.example.exampletdd.NotificationIntentService;
}
connectionPref.setSummary(humanValue);
- // Update Time Rate
- values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
- humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
- keyPreference = this.getActivity().getApplicationContext().getString(
- R.string.weather_preferences_update_time_rate_key);
- connectionPref = this.findPreference(keyPreference);
- value = this.getPreferenceManager().getSharedPreferences()
- .getString(keyPreference, "");
- humanValue = "";
- if (value.equals(values[0])) {
- humanValue = humanValues[0];
- } else if (value.equals(values[1])) {
- humanValue = humanValues[1];
- } else if (value.equals(values[2])) {
- humanValue = humanValues[2];
- } else if (value.equals(values[3])) {
- humanValue = humanValues[3];
- } else if (value.equals(values[4])) {
- humanValue = humanValues[4];
- }
- connectionPref.setSummary(humanValue);
-
// Wind
values = this.getResources().getStringArray(R.array.weather_preferences_wind);
humanValues = this.getResources().getStringArray(R.array.weather_preferences_wind_human_value);
humanValue = humanValues[6];
}
connectionPref.setSummary(humanValue);
+
+ // Update Time Rate
+ values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
+ humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
+ keyPreference = this.getActivity().getApplicationContext().getString(
+ R.string.weather_preferences_update_time_rate_key);
+ connectionPref = this.findPreference(keyPreference);
+ value = this.getPreferenceManager().getSharedPreferences()
+ .getString(keyPreference, "");
+ humanValue = "";
+ if (value.equals(values[0])) {
+ humanValue = humanValues[0];
+ } else if (value.equals(values[1])) {
+ humanValue = humanValues[1];
+ } else if (value.equals(values[2])) {
+ humanValue = humanValues[2];
+ } else if (value.equals(values[3])) {
+ humanValue = humanValues[3];
+ } else if (value.equals(values[4])) {
+ humanValue = humanValues[4];
+ }
+ connectionPref.setSummary(humanValue);
}
@Override
return;
}
- // Update Time Rate
- values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
- humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
- keyValue = this.getActivity().getApplicationContext().getString(
- R.string.weather_preferences_update_time_rate_key);
- if (key.equals(keyValue)) {
- final Preference connectionPref = this.findPreference(key);
- final String value = sharedPreferences.getString(key, "");
- String humanValue = "";
- if (value.equals(values[0])) {
- humanValue = humanValues[0];
- } else if (value.equals(values[1])) {
- humanValue = humanValues[1];
- } else if (value.equals(values[2])) {
- humanValue = humanValues[2];
- } else if (value.equals(values[3])) {
- humanValue = humanValues[3];
- } else if (value.equals(values[4])) {
- humanValue = humanValues[4];
- }
-
- this.updateAlarm(value);
- connectionPref.setSummary(humanValue);
- return;
- }
-
// Wind
values = this.getResources().getStringArray(R.array.weather_preferences_wind);
humanValues = this.getResources().getStringArray(R.array.weather_preferences_wind_human_value);
connectionPref.setSummary(humanValue);
return;
}
+
+ // Notification switch
+ keyValue = this.getActivity().getApplicationContext().getString(
+ R.string.weather_preferences_notifications_switch_key);
+ if (key.equals(keyValue)) {
+ final SwitchPreference preference = (SwitchPreference)this.findPreference(key);
+ if (preference.isChecked())
+ {
+ keyValue = this.getActivity().getApplicationContext().getString(
+ R.string.weather_preferences_update_time_rate_key);
+ final String value = sharedPreferences.getString(keyValue, "");
+ this.updateNotification(value);
+ } else {
+ this.cancelNotification();
+ }
+ }
+ // Update Time Rate
+ values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
+ humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
+ keyValue = this.getActivity().getApplicationContext().getString(
+ R.string.weather_preferences_update_time_rate_key);
+ if (key.equals(keyValue)) {
+ final Preference connectionPref = this.findPreference(key);
+ final String value = sharedPreferences.getString(key, "");
+ String humanValue = "";
+ if (value.equals(values[0])) {
+ humanValue = humanValues[0];
+ } else if (value.equals(values[1])) {
+ humanValue = humanValues[1];
+ } else if (value.equals(values[2])) {
+ humanValue = humanValues[2];
+ } else if (value.equals(values[3])) {
+ humanValue = humanValues[3];
+ } else if (value.equals(values[4])) {
+ humanValue = humanValues[4];
+ }
+
+ this.updateNotification(value);
+ connectionPref.setSummary(humanValue);
+ return;
+ }
}
- private void updateAlarm(final String updateTimeRate) {
+ private void updateNotification(final String updateTimeRate) {
final String[] values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
long chosenInterval = 0;
if (updateTimeRate.equals(values[0])) {
SystemClock.elapsedRealtime(),
chosenInterval,
alarmIntent);
- } else {
- alarmMgr.cancel(alarmIntent);
}
}
+
+ private void cancelNotification() {
+ final AlarmManager alarmMgr =
+ (AlarmManager) this.getActivity().getApplicationContext().getSystemService(Context.ALARM_SERVICE);
+ final Intent serviceIntent =
+ new Intent(this.getActivity().getApplicationContext(), NotificationIntentService.class);
+ final PendingIntent alarmIntent =
+ PendingIntent.getService(
+ this.getActivity().getApplicationContext(),
+ 0,
+ serviceIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ alarmMgr.cancel(alarmIntent);
+ }
}