2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.ui.activities;
14 import android.app.AlertDialog;
15 import android.content.DialogInterface;
16 import android.content.DialogInterface.OnClickListener;
17 import android.content.Intent;
18 import android.content.pm.PackageInfo;
19 import android.content.pm.PackageManager.NameNotFoundException;
20 import android.os.Bundle;
21 import android.preference.CheckBoxPreference;
22 import android.preference.Preference;
23 import android.preference.Preference.OnPreferenceChangeListener;
24 import android.preference.Preference.OnPreferenceClickListener;
25 import android.preference.PreferenceActivity;
26 import android.view.MenuItem;
28 import com.cyngn.eleven.MusicPlaybackService;
29 import com.cyngn.eleven.R;
30 import com.cyngn.eleven.cache.ImageCache;
31 import com.cyngn.eleven.utils.ApolloUtils;
32 import com.cyngn.eleven.utils.MusicUtils;
33 import com.cyngn.eleven.utils.PreferenceUtils;
38 * @author Andrew Neal (andrewdneal@gmail.com)
40 @SuppressWarnings("deprecation")
41 public class SettingsActivity extends PreferenceActivity {
46 private ImageCache mImageCache;
48 private PreferenceUtils mPreferences;
54 protected void onCreate(final Bundle savedInstanceState) {
55 super.onCreate(savedInstanceState);
57 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
59 // Get the preferences
60 mPreferences = PreferenceUtils.getInstance(this);
62 // Initialze the image cache
63 mImageCache = ImageCache.getInstance(this);
66 getActionBar().setIcon(R.drawable.ic_action_back_padded);
67 getActionBar().setHomeButtonEnabled(true);
69 // Add the preferences
70 addPreferencesFromResource(R.xml.settings);
72 // Removes the cache entries
80 public boolean onOptionsItemSelected(final MenuItem item) {
81 switch (item.getItemId()) {
82 case android.R.id.home:
89 return super.onOptionsItemSelected(item);
96 protected void onStart() {
98 MusicUtils.notifyForegroundStateChanged(this, true);
105 protected void onStop() {
107 MusicUtils.notifyForegroundStateChanged(this, false);
111 * Removes all of the cache entries.
113 private void deleteCache() {
114 final Preference deleteCache = findPreference("delete_cache");
115 deleteCache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
117 public boolean onPreferenceClick(final Preference preference) {
118 new AlertDialog.Builder(SettingsActivity.this).setMessage(R.string.delete_warning)
119 .setPositiveButton(android.R.string.ok, new OnClickListener() {
122 public void onClick(final DialogInterface dialog, final int which) {
123 mImageCache.clearCaches();
125 }).setNegativeButton(R.string.cancel, new OnClickListener() {
128 public void onClick(final DialogInterface dialog, final int which) {