Java tutorial
/* Vertretungsplan - Android-App fr Vertretungsplne von Schulen Copyright (C) 2014 Johan v. Forstner 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 3 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, see [http://www.gnu.org/licenses/]. */ package com.johan.vertretungsplan_2; import android.content.Intent; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.support.v4.preference.PreferenceFragment; import android.util.Log; import com.google.android.gms.analytics.GoogleAnalytics; public class SettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference changeSchoolPref = findPreference("change_school"); if (BuildConfig.FIXED_SCHOOL == null) { changeSchoolPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(getActivity(), SelectSchoolActivity.class); getActivity().startActivity(intent); return true; } }); } CheckBoxPreference analyticsPref = (CheckBoxPreference) findPreference("analytics"); analyticsPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Log.d("Vertretungsplan", "Analytics Opt-out"); GoogleAnalytics.getInstance(getActivity().getApplicationContext()) .setAppOptOut(!(boolean) newValue); return true; } }); } }