If you think the Android project Calma listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2013 Thomas Schmid//fromwww.java2s.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/package com.scto.android.calma.activities.preferences;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
import com.scto.android.calma.CalmaApp;
import com.scto.android.calma.R;
//import com.scto.android.calma.console.ConsoleBuilder;
import com.scto.android.calma.preferences.AccessMode;
import com.scto.android.calma.preferences.CalmaSettings;
import com.scto.android.calma.preferences.ObjectStringIdentifier;
import com.scto.android.calma.preferences.Preferences;
/**
* A class that manages the commons options of the application
*/publicclass NavigationPreferenceFragment extends TitlePreferenceFragment {
privatestaticfinal String TAG = "NavigationPreferenceFragment"; //$NON-NLS-1$
privatestaticfinalboolean DEBUG = false;
private CheckBoxPreference mUseBackButton;
/**
* @hide
*/boolean mLoaded = false;
privatefinal OnPreferenceChangeListener mOnChangeListener =
new OnPreferenceChangeListener() {
@Override
publicboolean onPreferenceChange(final Preference preference, Object newValue) {
boolean ret = true;
String key = preference.getKey();
if (DEBUG) {
Log.d(TAG,
String.format("New value for %s: %s", //$NON-NLS-1$
key,
String.valueOf(newValue)));
}
// Back button up navigation
if (CalmaSettings.SETTINGS_USE_BACK_BUTTON.getId().compareTo(key) == 0) {
String value = (String)newValue;
int valueId = Integer.valueOf(value).intValue();
String[] labels = getResources().getStringArray(
R.array.use_back_button_mode_labels);
preference.setSummary(labels[valueId]);
}
// Notify the change (only if fragment is loaded. Default values are loaded
// while not in loaded mode)
if (NavigationPreferenceFragment.this.mLoaded && ret) {
Intent intent = new Intent(CalmaSettings.INTENT_SETTING_CHANGED);
intent.putExtra(
CalmaSettings.EXTRA_SETTING_CHANGED_KEY, preference.getKey());
getActivity().sendBroadcast(intent);
}
return ret;
}
};
/**
* {@inheritDoc}
*/
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Change the preference manager
getPreferenceManager().setSharedPreferencesName(Preferences.SETTINGS_FILENAME);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);
// Add the preferences
addPreferencesFromResource(R.xml.preferences_navigation);
// Use back button
this.mUseBackButton =
(CheckBoxPreference)findPreference(
CalmaSettings.SETTINGS_USE_BACK_BUTTON.getId());
this.mUseBackButton.setOnPreferenceChangeListener(this.mOnChangeListener);
// Loaded
this.mLoaded = true;
}
/**
* {@inheritDoc}
*/
@Override
public CharSequence getTitle() {
return getString(R.string.pref_navigation);
}
}