2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package com.cyanogenmod.eleven.ui.activities;
16 import android.app.AlertDialog;
17 import android.content.DialogInterface;
18 import android.content.DialogInterface.OnClickListener;
19 import android.os.Bundle;
20 import android.preference.Preference;
21 import android.preference.Preference.OnPreferenceClickListener;
22 import android.preference.PreferenceActivity;
23 import android.view.MenuItem;
25 import com.cyanogenmod.eleven.R;
26 import com.cyanogenmod.eleven.cache.ImageFetcher;
27 import com.cyanogenmod.eleven.utils.MusicUtils;
32 * @author Andrew Neal (andrewdneal@gmail.com)
34 @SuppressWarnings("deprecation")
35 public class SettingsActivity extends PreferenceActivity {
41 protected void onCreate(final Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
44 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
47 getActionBar().setIcon(R.drawable.ic_action_back_padded);
48 getActionBar().setHomeButtonEnabled(true);
50 // Add the preferences
51 addPreferencesFromResource(R.xml.settings);
53 // Removes the cache entries
61 public boolean onOptionsItemSelected(final MenuItem item) {
62 switch (item.getItemId()) {
63 case android.R.id.home:
70 return super.onOptionsItemSelected(item);
77 protected void onStart() {
79 MusicUtils.notifyForegroundStateChanged(this, true);
86 protected void onStop() {
88 MusicUtils.notifyForegroundStateChanged(this, false);
92 * Removes all of the cache entries.
94 private void deleteCache() {
95 final Preference deleteCache = findPreference("delete_cache");
96 deleteCache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
98 public boolean onPreferenceClick(final Preference preference) {
99 new AlertDialog.Builder(SettingsActivity.this).setMessage(R.string.delete_warning)
100 .setPositiveButton(android.R.string.ok, new OnClickListener() {
102 public void onClick(final DialogInterface dialog, final int which) {
103 ImageFetcher.getInstance(SettingsActivity.this).clearCaches();
106 .setNegativeButton(R.string.cancel, new OnClickListener() {
108 public void onClick(final DialogInterface dialog, final int which) {