]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/QuickDicConfig.java
String changes, focus changes.
[Dictionary.git] / src / com / hughes / android / dictionary / QuickDicConfig.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.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import com.hughes.android.dictionary.engine.Language;
22
23 public final class QuickDicConfig implements Serializable {
24   
25   private static final long serialVersionUID = 6711617368780900979L;
26   
27   // Just increment this to have them all update...
28   static final int LATEST_VERSION = 3;
29   
30   final List<DictionaryConfig> dictionaryConfigs = new ArrayList<DictionaryConfig>();
31   int currentVersion = LATEST_VERSION;
32   
33   public QuickDicConfig() {
34     addDefaultDictionaries();
35   }
36   
37   static final String BASE_URL = "http://quickdic-dictionary.googlecode.com/files/";
38
39   public void addDefaultDictionaries() {
40     {
41       final DictionaryConfig config = new DictionaryConfig();
42       config.name = "German<->English";
43       config.downloadUrl = BASE_URL + "DE-EN_chemnitz_enwiktionary.quickdic.zip";
44       config.localFile = "/sdcard/quickDic/DE-EN_chemnitz_enwiktionary.quickdic";
45       addOrReplace(config);
46     }
47     
48     for (final String iso : Language.isoCodeToWikiName.keySet()) {
49       if (iso.equals("EN") || iso.equals("DE")) {
50         continue;
51       }
52       final DictionaryConfig config = new DictionaryConfig();
53       config.name = String.format("English<->%s", Language.isoCodeToWikiName.get(iso));
54       config.downloadUrl = String.format("%sEN-%s_enwiktionary.quickdic.zip", BASE_URL, iso);
55       config.localFile = String.format("/sdcard/quickDic/EN-%s_enwiktionary.quickdic", iso);
56       addOrReplace(config);
57     }
58
59   }
60
61   private void addOrReplace(final DictionaryConfig dictionaryConfig) {
62     for (int i = 0; i < dictionaryConfigs.size(); ++i) {
63       if (dictionaryConfigs.get(i).name.equals(dictionaryConfig.name)) {
64         dictionaryConfigs.set(i, dictionaryConfig);
65         return;
66       }
67     }
68     dictionaryConfigs.add(dictionaryConfig);
69   }
70
71 }