content: /*
   * This source is part of the
   *      _____  ___   ____
   *  __ / / _ \/ _ | / __/___  _______ _
   * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/
   * \___/_/|_/_/ |_/_/ (_)___/_/  \_, /
   *                              /___/
   * repository.
   *
   * Copyright (C) 2013 Benoit 'BoD' Lubek (BoD@JRAF.org)
   *
   * 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 org.jraf.android.backport.switchwidget.sample;
  
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
  import android.os.Bundle;
  import android.preference.Preference;
  import android.preference.Preference.OnPreferenceClickListener;
  import android.preference.PreferenceManager;
  import android.util.Log;
  import android.widget.Toast;
  
  public class PreferenceActivity extends android.preference.PreferenceActivity {
      private static final String TAG = PreferenceActivity.class.getSimpleName();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
          addPreferencesFromResource(R.xml.preferences);
          findPreference("testKey").setOnPreferenceClickListener(mOnPreferenceClickListener);
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);
      }
  
      @Override
      protected void onStop() {
          PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);
          super.onStop();
      }
  
      private OnSharedPreferenceChangeListener mOnSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
          @Override
          public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
              Toast.makeText(PreferenceActivity.this, String.valueOf(sharedPreferences.getBoolean(key, false)), Toast.LENGTH_SHORT).show();
          }
      };
  
      private OnPreferenceClickListener mOnPreferenceClickListener = new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
              Log.d(TAG, "onPreferenceClick");
              return true;
          }
      };
  }
  