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 org.lineageos.eleven.ui.activities;
16 import android.app.AlertDialog;
17 import android.content.DialogInterface;
18 import android.content.DialogInterface.OnClickListener;
19 import android.content.SharedPreferences;
20 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
21 import android.os.Bundle;
22 import android.preference.Preference;
23 import android.preference.Preference.OnPreferenceClickListener;
24 import android.preference.PreferenceActivity;
25 import android.view.MenuItem;
27 import org.lineageos.eleven.R;
28 import org.lineageos.eleven.cache.ImageFetcher;
29 import org.lineageos.eleven.utils.MusicUtils;
30 import org.lineageos.eleven.utils.PreferenceUtils;
35 * @author Andrew Neal (andrewdneal@gmail.com)
37 @SuppressWarnings("deprecation")
38 public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
44 protected void onCreate(final Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
48 getActionBar().setDisplayHomeAsUpEnabled(true);
50 // Add the preferences
51 addPreferencesFromResource(R.xml.settings);
53 // Removes the cache entries
56 PreferenceUtils.getInstance(this).setOnSharedPreferenceChangeListener(this);
63 public boolean onOptionsItemSelected(final MenuItem item) {
64 switch (item.getItemId()) {
65 case android.R.id.home:
72 return super.onOptionsItemSelected(item);
76 * Removes all of the cache entries.
78 private void deleteCache() {
79 final Preference deleteCache = findPreference("delete_cache");
80 deleteCache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
82 public boolean onPreferenceClick(final Preference preference) {
83 new AlertDialog.Builder(SettingsActivity.this).setMessage(R.string.delete_warning)
84 .setPositiveButton(android.R.string.ok, new OnClickListener() {
86 public void onClick(final DialogInterface dialog, final int which) {
87 ImageFetcher.getInstance(SettingsActivity.this).clearCaches();
90 .setNegativeButton(R.string.cancel, new OnClickListener() {
92 public void onClick(final DialogInterface dialog, final int which) {
103 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
105 if (key.equals(PreferenceUtils.SHOW_VISUALIZER) &&
106 sharedPreferences.getBoolean(key, false) && !PreferenceUtils.canRecordAudio(this)) {
107 PreferenceUtils.requestRecordAudio(this);
108 } if (key.equals(PreferenceUtils.SHAKE_TO_PLAY)) {
109 MusicUtils.setShakeToPlayEnabled(sharedPreferences.getBoolean(key, false));
110 } else if (key.equals(PreferenceUtils.SHOW_ALBUM_ART_ON_LOCKSCREEN)) {
111 MusicUtils.setShowAlbumArtOnLockscreen(sharedPreferences.getBoolean(key, true));