Java tutorial
/* * WiFi Analyzer * Copyright (C) 2016 VREM Software Development <VREMSoftwareDevelopment@gmail.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 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.gammalabs.wifianalyzer.settings; import android.app.ActionBar; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.support.v4.app.NavUtils; import android.view.MenuItem; import com.gammalabs.wifianalyzer.MainActivity; import com.gammalabs.wifianalyzer.MainContext; import com.gammalabs.wifianalyzer.R; public class SettingActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { setCustomTheme(); super.onCreate(savedInstanceState); getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingPreferenceFragment()) .commit(); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } } private void setCustomTheme() { Settings settings = MainContext.INSTANCE.getSettings(); if (settings != null) { ThemeStyle themeStyle = settings.getThemeStyle(); setTheme(themeStyle.themeDeviceDefaultStyle()); } } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { MainActivity.showAds(); NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } public static class SettingPreferenceFragment extends PreferenceFragment { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } } }