2 * Copyright (C) 2012 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.cyanogenmod.filemanager.activities.preferences;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.preference.CheckBoxPreference;
23 import android.preference.Preference;
24 import android.preference.Preference.OnPreferenceChangeListener;
25 import android.util.Log;
27 import com.cyanogenmod.filemanager.R;
28 import com.cyanogenmod.filemanager.preferences.FileManagerSettings;
29 import com.cyanogenmod.filemanager.preferences.Preferences;
32 * A class that manages the editor options
34 public class EditorPreferenceFragment extends TitlePreferenceFragment {
36 private static final String TAG = "EditorPreferenceFragment"; //$NON-NLS-1$
38 private static final boolean DEBUG = false;
40 private CheckBoxPreference mNoSuggestions;
41 private CheckBoxPreference mWordWrap;
42 private CheckBoxPreference mHexdump;
44 private CheckBoxPreference mSyntaxHighlight;
50 boolean mLoaded = false;
52 private final OnPreferenceChangeListener mOnChangeListener =
53 new OnPreferenceChangeListener() {
55 public boolean onPreferenceChange(final Preference preference, Object newValue) {
58 String key = preference.getKey();
61 String.format("New value for %s: %s", //$NON-NLS-1$
63 String.valueOf(newValue)));
66 // Notify the change (only if fragment is loaded. Default values are loaded
67 // while not in loaded mode)
68 if (EditorPreferenceFragment.this.mLoaded && ret) {
69 Intent intent = new Intent(FileManagerSettings.INTENT_SETTING_CHANGED);
71 FileManagerSettings.EXTRA_SETTING_CHANGED_KEY, preference.getKey());
72 getActivity().sendBroadcast(intent);
83 public void onCreate(Bundle savedInstanceState) {
84 super.onCreate(savedInstanceState);
86 // Change the preference manager
87 getPreferenceManager().setSharedPreferencesName(Preferences.SETTINGS_FILENAME);
88 getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);
91 // Add the preferences
92 addPreferencesFromResource(R.xml.preferences_editor);
96 (CheckBoxPreference)findPreference(
97 FileManagerSettings.SETTINGS_EDITOR_NO_SUGGESTIONS.getId());
98 this.mNoSuggestions.setOnPreferenceChangeListener(this.mOnChangeListener);
102 (CheckBoxPreference)findPreference(
103 FileManagerSettings.SETTINGS_EDITOR_WORD_WRAP.getId());
104 this.mWordWrap.setOnPreferenceChangeListener(this.mOnChangeListener);
108 (CheckBoxPreference)findPreference(
109 FileManagerSettings.SETTINGS_EDITOR_HEXDUMP.getId());
110 this.mHexdump.setOnPreferenceChangeListener(this.mOnChangeListener);
113 this.mSyntaxHighlight =
114 (CheckBoxPreference)findPreference(
115 FileManagerSettings.SETTINGS_EDITOR_SYNTAX_HIGHLIGHT.getId());
116 this.mSyntaxHighlight.setOnPreferenceChangeListener(this.mOnChangeListener);
126 public CharSequence getTitle() {
127 return getString(R.string.pref_editor);