]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Got the flags set to a reasonable size.
authorThad Hughes <thadh@google.com>
Sun, 15 Dec 2013 23:30:43 +0000 (15:30 -0800)
committerThad Hughes <thadh@google.com>
Sun, 15 Dec 2013 23:30:43 +0000 (15:30 -0800)
res/layout/dictionary_manager_activity.xml
res/menu/dictionary_manager_options_menu.xml
src/com/hughes/android/dictionary/C.java
src/com/hughes/android/dictionary/DictionaryApplication.java
src/com/hughes/android/dictionary/DictionaryManagerActivity.java

index 07d8596f4b7e169f520f1144c1d13d7d2b43395b..95164c859b8ba5578529efe8c2c56501ff8dc719 100644 (file)
@@ -65,8 +65,8 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_weight="0"
-                    android:textOff="@string/managerShow"
-                    android:textOn="@string/managerHide" />
+                    android:textOff="@string/managerHide"
+                    android:textOn="@string/managerShow" />
             </LinearLayout>
 
             <LinearLayout
index ac85202c1d9eab8b23ad5dadfe515c4327287269..89164bd047f5e1b55420a6804aaf8d42e15b042f 100644 (file)
@@ -4,7 +4,7 @@
     <item android:id="@+id/filterText"
           android:title="@string/managerFilterText"
           android:icon="@drawable/abs__ic_search"
-          android:showAsAction="collapseActionView|ifRoom"
+          android:showAsAction="always"
           android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
         
     <item
index 7baba54e6512b84d97ac922d684813702e226f79..dc4bd0a8ea2a2f10c364d63739a5913730a20f1c 100644 (file)
@@ -22,7 +22,7 @@ public class C {
     public static final String INDEX_SHORT_NAME = "indexShortName";
     public static final String SEARCH_TOKEN = "searchToken";
     public static final String CAN_AUTO_LAUNCH_DICT = "canAutoLaunch";
-    public static final String SHOW_LOCAL = "showLocal";
+    public static final String SHOW_DOWNLOADABLE = "showLocal";
 
     public static final String THANKS_FOR_UPDATING_VERSION = "thanksForUpdatingVersion";
 
index e6b509c2f587ec7d2a13817ef13b9cc82cea8062..bc644695d0d0de87c2cf19f08f6187152f9019a7 100644 (file)
@@ -22,11 +22,14 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.net.Uri;
 import android.preference.PreferenceManager;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.view.ViewGroup.LayoutParams;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
 
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuItem;
@@ -70,6 +73,9 @@ public class DictionaryApplication extends Application {
     final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new LinkedHashMap<String, DictionaryInfo>();
   }
   DictionaryConfig dictionaryConfig = null;
+  
+  
+  int languageButtonPixels = 22;
 
 //  static final class DictionaryHistory implements Serializable {
 //    private static final long serialVersionUID = -4842995032541390284L;
@@ -111,6 +117,10 @@ public class DictionaryApplication extends Application {
     TransliteratorManager.init(null);
     staticInit(getApplicationContext());
     
+    languageButtonPixels = (int) TypedValue.applyDimension(
+            TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics());
+
+    
     // Load the dictionaries we know about.
     dictionaryConfig = PersistentObjectCache.init(getApplicationContext()).read(
             C.DICTIONARY_CONFIGS, DictionaryConfig.class);
@@ -267,6 +277,7 @@ public class DictionaryApplication extends Application {
           final IndexInfo indexInfo) {
       LanguageResources languageResources = Language.isoCodeToResources.get(indexInfo.shortName);
       View result;
+            
       if (languageResources == null || languageResources.flagId <= 0) {
           Button button = new Button(context);
           button.setText(indexInfo.shortName);
@@ -277,9 +288,12 @@ public class DictionaryApplication extends Application {
           button.setScaleType(ScaleType.FIT_CENTER);
           result = button;
       }
+      result.setMinimumWidth(languageButtonPixels);
+      result.setMinimumHeight(languageButtonPixels * 2 / 3);
       result.setOnClickListener(
               new IntentLauncher(context, 
               DictionaryActivity.getLaunchIntent(getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, "")));
+//      result.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
       return result;
   }
 
@@ -401,19 +415,19 @@ public class DictionaryApplication extends Application {
     return result;
   }
   
-  public synchronized List<DictionaryInfo> getAllDictionaries() {
-    final List<DictionaryInfo> result = getDictionariesOnDevice();
-    
-    // The downloadable ones.
-    final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
-    remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
-    final List<DictionaryInfo> toAddSorted = new ArrayList<DictionaryInfo>(remaining.values());
-    Collections.sort(toAddSorted, dictionaryInfoComparator);
-    result.addAll(toAddSorted);
-    
-    return result;
+  public List<DictionaryInfo> getDownloadableDictionaries() {
+      final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(dictionaryConfig.dictionaryFilesOrdered.size());
+      
+      // The downloadable ones.
+      final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
+      remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
+      final List<DictionaryInfo> toAddSorted = new ArrayList<DictionaryInfo>(remaining.values());
+      Collections.sort(toAddSorted, dictionaryInfoComparator);
+      result.addAll(toAddSorted);
+      
+      return result;
   }
-
+  
   public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) {
     return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null;
   }
index b9a85b06324c061be2ead5781f568da13f07bd37..c06ccc30504cfcac927e063629a67c424a709cd7 100644 (file)
@@ -67,7 +67,7 @@ public class DictionaryManagerActivity extends SherlockActivity {
 
     // EditText filterText;
     SearchView filterSearchView;
-    ToggleButton hideDownloadable;
+    ToggleButton showDownloadable;
 
     LinearLayout dictionariesOnDevice;
     LinearLayout downloadableDictionaries;
@@ -125,8 +125,8 @@ public class DictionaryManagerActivity extends SherlockActivity {
         // }
         // });
 
-        hideDownloadable = (ToggleButton) findViewById(R.id.hideDownloadable);
-        hideDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+        showDownloadable = (ToggleButton) findViewById(R.id.hideDownloadable);
+        showDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
             @Override
             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                 onShowLocalChanged();
@@ -171,7 +171,7 @@ public class DictionaryManagerActivity extends SherlockActivity {
         }
 
         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-        hideDownloadable.setChecked(prefs.getBoolean(C.SHOW_LOCAL, false));
+        showDownloadable.setChecked(prefs.getBoolean(C.SHOW_DOWNLOADABLE, false));
 
         if (!blockAutoLaunch &&
                 getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
@@ -294,10 +294,15 @@ public class DictionaryManagerActivity extends SherlockActivity {
     }
 
     private void onShowLocalChanged() {
-        downloadableDictionaries.setVisibility(hideDownloadable.isChecked() ? View.GONE
-                : View.VISIBLE);
+//        downloadableDictionaries.setVisibility(showDownloadable.isChecked() ? View.GONE
+//                : View.VISIBLE);
+        if (filterSearchView != null) {
+            populateDictionaryLists(filterSearchView.getQuery().toString());
+        } else {
+            populateDictionaryLists("");
+        }
         Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
-        prefs.putBoolean(C.SHOW_LOCAL, hideDownloadable.isChecked());
+        prefs.putBoolean(C.SHOW_DOWNLOADABLE, showDownloadable.isChecked());
         prefs.commit();
     }
 
@@ -321,135 +326,44 @@ public class DictionaryManagerActivity extends SherlockActivity {
     private void populateDictionaryLists(String filterText) {
         // On device.
         dictionariesOnDevice.removeAllViews();
-        final List<DictionaryInfo> dictionaryInfos = application.getDictionariesOnDevice();
-        for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
-            View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
-                    R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
-            final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
-            name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
-            
-            LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
-            final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
-            for (IndexInfo indexInfo : sortedIndexInfos) {
-                final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
-                buttons.addView(button);
+        {
+            final List<DictionaryInfo> dictionaryInfos = application.getDictionariesOnDevice();
+            for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
+                View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
+                        R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
+                final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
+                name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+                
+                LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+                final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
+                for (IndexInfo indexInfo : sortedIndexInfos) {
+                    final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
+                    buttons.addView(button);
+                }
+                
+                dictionariesOnDevice.addView(row);
             }
-            
-            dictionariesOnDevice.addView(row);
         }
 
         // Downloadable.
-
+        downloadableDictionaries.removeAllViews();
+        if (showDownloadable.isChecked()) {
+            final List<DictionaryInfo> dictionaryInfos = application.getDownloadableDictionaries();
+            for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
+                View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
+                        R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
+                final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
+                name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+                
+                LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+                final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
+                for (IndexInfo indexInfo : sortedIndexInfos) {
+                    final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
+                    buttons.addView(button);
+                }
+                downloadableDictionaries.addView(row);
+            }
+        }
     }
 
-//    class Adapter extends BaseAdapter {
-//
-//        final List<DictionaryInfo> dictionaryInfos = new ArrayList<DictionaryInfo>();
-//
-//        Adapter() {
-//            final String filter = filterSearchView.getText().toString().trim().toLowerCase();
-//            for (final DictionaryInfo dictionaryInfo : application.getAllDictionaries()) {
-//                boolean canShow = true;
-//                if (hideDownloadable.isChecked()
-//                        && !application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-//                    canShow = false;
-//                }
-//                if (canShow && filter.length() > 0) {
-//                    if (!application.getDictionaryName(dictionaryInfo.uncompressedFilename)
-//                            .toLowerCase().contains(filter)) {
-//                        canShow = false;
-//                    }
-//                }
-//                if (canShow) {
-//                    dictionaryInfos.add(dictionaryInfo);
-//                }
-//            }
-//        }
-//
-//        @Override
-//        public int getCount() {
-//            return dictionaryInfos.size();
-//        }
-//
-//        @Override
-//        public DictionaryInfo getItem(int position) {
-//            return dictionaryInfos.get(position);
-//        }
-//
-//        @Override
-//        public long getItemId(int position) {
-//            return position;
-//        }
-//
-//        @Override
-//        public View getView(final int position, View convertView, final ViewGroup parent) {
-//            if (convertView == null) {
-//                convertView = LayoutInflater.from(parent.getContext()).inflate(
-//                        R.layout.dictionary_manager_row, parent, false);
-//            }
-//
-//            final DictionaryInfo dictionaryInfo = getItem(position);
-//
-//            final TextView textView = (TextView) convertView.findViewById(R.id.dictionaryName);
-//            final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
-//            textView.setText(name);
-//
-//            final Button downloadButton = (Button) convertView
-//                    .findViewById(R.id.dictionaryDownloadButton);
-//            final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
-//            final DictionaryInfo downloadable = application
-//                    .getDownloadable(dictionaryInfo.uncompressedFilename);
-//            if (updateAvailable) {
-//                downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-//                        android.R.drawable.ic_menu_add,
-//                        0, 0, 0);
-//                downloadButton.setText(getString(R.string.downloadButton,
-//                        downloadable.zipBytes / 1024.0 / 1024.0));
-//            } else if (!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-//                downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-//                        android.R.drawable.ic_menu_add,
-//                        0, 0, 0);
-//                downloadButton.setText(getString(R.string.downloadButton,
-//                        downloadable.zipBytes / 1024.0 / 1024.0));
-//            } else {
-//                downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-//                        android.R.drawable.checkbox_on_background,
-//                        0, 0, 0);
-//                downloadButton.setText("");
-//            }
-//            final Intent intent = getDownloadIntent(downloadable);
-//            downloadButton.setOnClickListener(new IntentLauncher(parent.getContext(), intent));
-//
-//            // Add the information about each index.
-//            final TextView dictionaryDetails = (TextView) convertView
-//                    .findViewById(R.id.dictionaryDetails);
-//            final StringBuilder builder = new StringBuilder();
-//            for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
-//                if (builder.length() > 0) {
-//                    builder.append(" | ");
-//                }
-//                builder.append(getString(R.string.indexInfo, indexInfo.shortName,
-//                        indexInfo.mainTokenCount));
-//            }
-//            dictionaryDetails.setText(builder.toString());
-//
-//            // // Because we have a Button inside a ListView row:
-//            // //
-//            // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1
-//            // convertView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
-//            convertView.setClickable(true);
-//            convertView.setFocusable(true);
-//            convertView.setLongClickable(true);
-//            // result.setBackgroundResource(android.R.drawable.menuitem_background);
-//            convertView.setOnClickListener(new TextView.OnClickListener() {
-//                @Override
-//                public void onClick(View v) {
-//                    DictionaryManagerActivity.this.onClick(position);
-//                }
-//            });
-//
-//            return convertView;
-//        }
-//    }
-
 }