/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.alarmclock;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
/**
* Settings for the Alarm Clock.
*/
public class SettingsActivity extends PreferenceActivity {
private static final int ALARM_STREAM_TYPE_BIT =
1 << AudioManager.STREAM_ALARM;
private static final String KEY_ALARM_IN_SILENT_MODE =
"alarm_in_silent_mode";
private CheckBoxPreference mAlarmInSilentModePref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
mAlarmInSilentModePref =
(CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);
}
@Override
protected void onResume() {
super.onResume();
refresh();
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference == mAlarmInSilentModePref) {
int ringerModeStreamTypes = Settings.System.getInt(
getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
if (mAlarmInSilentModePref.isChecked()) {
ringerModeStreamTypes &= ~ALARM_STREAM_TYPE_BIT;
} else {
ringerModeStreamTypes |= ALARM_STREAM_TYPE_BIT;
}
Settings.System.putInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED,
ringerModeStreamTypes);
return true;
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
private void refresh() {
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
mAlarmInSilentModePref.setChecked(
(silentModeStreams & ALARM_STREAM_TYPE_BIT) == 0);
}
}
|