]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/PreferenceActivity.java
Fixed add to wordlist on fresh install.
[Dictionary.git] / src / com / hughes / android / dictionary / PreferenceActivity.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary;
16
17 import java.util.List;
18
19 import android.content.SharedPreferences;
20 import android.os.Bundle;
21 import android.preference.ListPreference;
22 import android.preference.PreferenceManager;
23
24 public class PreferenceActivity extends android.preference.PreferenceActivity {
25
26     static boolean prefsMightHaveChanged = false;
27
28     @SuppressWarnings("deprecation")
29     @Override
30     public void onCreate(Bundle savedInstanceState) {
31         final DictionaryApplication application = (DictionaryApplication) getApplication();
32         setTheme(application.getSelectedTheme().themeId);
33         
34         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
35         if (prefs.getString(getString(R.string.quickdicDirectoryKey), "").equals("")) {
36             prefs.edit().putString(getString(R.string.quickdicDirectoryKey), application.getDictDir().getAbsolutePath()).commit();
37         }
38         if (prefs.getString(getString(R.string.wordListFileKey), "").equals("")) {
39             prefs.edit().putString(getString(R.string.wordListFileKey), application.getWordListFile().getAbsolutePath()).commit();
40         }
41
42         /**
43          * @author Dominik Köppl Preference: select default dictionary As this
44          *         list is dynamically generated, we have to do it in this
45          *         fashion
46          */
47         super.onCreate(savedInstanceState);
48         addPreferencesFromResource(R.xml.preferences);
49         ListPreference defaultDic = (ListPreference) findPreference(getResources().getString(
50                 R.string.defaultDicKey));
51         List<DictionaryInfo> dicts = application.getDictionariesOnDevice(null);
52
53         final CharSequence[] entries = new CharSequence[dicts.size()];
54         final CharSequence[] entryvalues = new CharSequence[dicts.size()];
55
56         for (int i = 0; i < entries.length; ++i)
57         {
58             entries[i] = dicts.get(i).dictInfo;
59             entryvalues[i] = dicts.get(i).uncompressedFilename;
60         }
61
62         defaultDic.setEntries(entries);
63         defaultDic.setEntryValues(entryvalues);
64     }
65
66     @Override
67     public void onContentChanged() {
68         super.onContentChanged();
69     }
70 }