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;
34 import com.cyngn.eleven.widgets.ColorSchemeDialog;
39 * @author Andrew Neal (andrewdneal@gmail.com)
41 @SuppressWarnings("deprecation")
42 public class SettingsActivity extends PreferenceActivity {
47 private ImageCache mImageCache;
49 private PreferenceUtils mPreferences;
55 protected void onCreate(final Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
58 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
60 // Get the preferences
61 mPreferences = PreferenceUtils.getInstance(this);
63 // Initialze the image cache
64 mImageCache = ImageCache.getInstance(this);
67 getActionBar().setDisplayHomeAsUpEnabled(true);
69 // Add the preferences
70 addPreferencesFromResource(R.xml.settings);
74 // Removes the cache entries
77 showOpenSourceLicenses();
78 // Update the version number
80 final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
81 findPreference("version").setSummary(packageInfo.versionName);
82 } catch (final NameNotFoundException e) {
83 findPreference("version").setSummary("?");
91 public boolean onOptionsItemSelected(final MenuItem item) {
92 switch (item.getItemId()) {
93 case android.R.id.home:
100 return super.onOptionsItemSelected(item);
107 protected void onStart() {
109 MusicUtils.notifyForegroundStateChanged(this, true);
116 protected void onStop() {
118 MusicUtils.notifyForegroundStateChanged(this, false);
122 * Initializes the preferences under the "Interface" category
124 private void initInterface() {
125 // Color scheme picker
130 * Shows the {@link ColorSchemeDialog} and then saves the changes.
132 private void updateColorScheme() {
133 final Preference colorScheme = findPreference("color_scheme");
134 colorScheme.setOnPreferenceClickListener(new OnPreferenceClickListener() {
136 public boolean onPreferenceClick(final Preference preference) {
137 ApolloUtils.showColorPicker(SettingsActivity.this);
144 * Removes all of the cache entries.
146 private void deleteCache() {
147 final Preference deleteCache = findPreference("delete_cache");
148 deleteCache.setOnPreferenceClickListener(new OnPreferenceClickListener() {
150 public boolean onPreferenceClick(final Preference preference) {
151 new AlertDialog.Builder(SettingsActivity.this).setMessage(R.string.delete_warning)
152 .setPositiveButton(android.R.string.ok, new OnClickListener() {
155 public void onClick(final DialogInterface dialog, final int which) {
156 mImageCache.clearCaches();
158 }).setNegativeButton(R.string.cancel, new OnClickListener() {
161 public void onClick(final DialogInterface dialog, final int which) {
171 * Show the open source licenses
173 private void showOpenSourceLicenses() {
174 final Preference mOpenSourceLicenses = findPreference("open_source");
175 mOpenSourceLicenses.setOnPreferenceClickListener(new OnPreferenceClickListener() {
178 public boolean onPreferenceClick(final Preference preference) {
179 ApolloUtils.createOpenSourceDialog(SettingsActivity.this).show();