]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryListActivity.java
Font size pref, reorder a few EntryTypes.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryListActivity.java
index 29ec4b88f94475bfd8095f9c9ac44dd847deb676..004ce2be4edcb459d0faac295d1d187a14c15858 100644 (file)
@@ -1,5 +1,21 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package com.hughes.android.dictionary;
 
+import java.io.File;
+
 import android.app.AlertDialog;
 import android.app.ListActivity;
 import android.content.Context;
@@ -9,6 +25,7 @@ import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.ContextMenu;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -34,6 +51,8 @@ public class DictionaryListActivity extends ListActivity {
   
   
   public void onCreate(Bundle savedInstanceState) {
+    ((DictionaryApplication)getApplication()).applyTheme(this);
+
     super.onCreate(savedInstanceState);
     Log.d(LOG, "onCreate:" + this);
 
@@ -52,7 +71,7 @@ public class DictionaryListActivity extends ListActivity {
     registerForContextMenu(getListView());
 
     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-    final int introMessageId = 0;
+    final int introMessageId = -1;
     if (prefs.getInt(C.INTRO_MESSAGE_SHOWN, 0) < introMessageId) {
       final AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setCancelable(false);
@@ -81,8 +100,9 @@ public class DictionaryListActivity extends ListActivity {
     
     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
     if (prefs.contains(C.DICT_INDEX) && prefs.contains(C.INDEX_INDEX)) {
+      Log.d(LOG, "Skipping Dictionary List, going straight to dictionary.");
       startActivity(DictionaryActivity.getIntent(this, prefs.getInt(C.DICT_INDEX, 0), prefs.getInt(C.INDEX_INDEX, 0), prefs.getString(C.SEARCH_TOKEN, "")));
-      finish();
+      //finish();
       return;
     }
 
@@ -91,6 +111,11 @@ public class DictionaryListActivity extends ListActivity {
       quickDicConfig = new QuickDicConfig();
       PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, quickDicConfig);
     }
+    if (quickDicConfig.currentVersion < QuickDicConfig.LATEST_VERSION) {
+      Log.d(LOG, "Dictionary list is old, updating it.");
+      quickDicConfig.addDefaultDictionaries();
+      quickDicConfig.currentVersion = QuickDicConfig.LATEST_VERSION;
+    }
 
     setListAdapter(new Adapter());
     
@@ -107,6 +132,43 @@ public class DictionaryListActivity extends ListActivity {
             return false;
           }
         });
+
+    final MenuItem addDefaultDictionariesMenuItem = menu.add(R.string.addDefaultDictionaries);
+    addDefaultDictionariesMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+          public boolean onMenuItemClick(final MenuItem menuItem) {
+            quickDicConfig.addDefaultDictionaries();
+            dictionaryConfigsChanged();
+            return false;
+          }
+        });
+
+    final MenuItem removeAllDictionariesMenuItem = menu.add(R.string.removeAllDictionaries);
+    removeAllDictionariesMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+          public boolean onMenuItemClick(final MenuItem menuItem) {
+            quickDicConfig.dictionaryConfigs.clear();
+            dictionaryConfigsChanged();
+            return false;
+          }
+        });
+
+    final MenuItem about = menu.add(getString(R.string.about));
+    about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+      public boolean onMenuItemClick(final MenuItem menuItem) {
+        final Intent intent = new Intent().setClassName(AboutActivity.class
+            .getPackage().getName(), AboutActivity.class.getCanonicalName());
+        startActivity(intent);
+        return false;
+      }
+    });
+    
+    final MenuItem preferences = menu.add(getString(R.string.preferences));
+    preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+      public boolean onMenuItemClick(final MenuItem menuItem) {
+        startActivity(new Intent(DictionaryListActivity.this,
+            PreferenceActivity.class));
+        return false;
+      }
+    });
     
     return true;
   }
@@ -129,12 +191,12 @@ public class DictionaryListActivity extends ListActivity {
     });
 
     if (adapterContextMenuInfo.position > 0) {
-      final MenuItem moveUpMenuItem = menu.add(R.string.moveUp);
-      moveUpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+      final MenuItem moveToTopMenuItem = menu.add(R.string.moveToTop);
+      moveToTopMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
         @Override
         public boolean onMenuItemClick(MenuItem item) {
           final DictionaryConfig dictionaryConfig = quickDicConfig.dictionaryConfigs.remove(adapterContextMenuInfo.position);
-          quickDicConfig.dictionaryConfigs.add(adapterContextMenuInfo.position - 1, dictionaryConfig);
+          quickDicConfig.dictionaryConfigs.add(0, dictionaryConfig);
           dictionaryConfigsChanged();
           return true;
         }
@@ -180,9 +242,14 @@ public class DictionaryListActivity extends ListActivity {
       final DictionaryConfig dictionaryConfig = getItem(position);
       final TableLayout tableLayout = new TableLayout(parent.getContext());
       final TextView view = new TextView(parent.getContext());
+      
+      String name = dictionaryConfig.name;
+      if (!new File(dictionaryConfig.localFile).canRead()) {
+        name = getString(R.string.notOnDevice, dictionaryConfig.name);
+      }
 
-      view.setText(dictionaryConfig.name);
-      view.setTextSize(20);
+      view.setText(name);
+      view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
       tableLayout.addView(view);
 
       return tableLayout;