]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Add menu entry to jump to random word.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 24 Jan 2016 19:26:56 +0000 (20:26 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 24 Jan 2016 19:26:56 +0000 (20:26 +0100)
build.gradle
res/values-de/strings.xml
res/values/strings.xml
src/com/hughes/android/dictionary/DictionaryActivity.java

index 3de4e1885a2b7a71e2430e304f04b8eaf0e670a1..0794423503bec651c699f5d4502e64c340420fe5 100644 (file)
@@ -41,6 +41,9 @@ def utildir = hasProperty("quickdicUtilDir") ? quickdicUtilDir : "../Util"
 android {
     compileSdkVersion 23
     buildToolsVersion "23.0.2"
+    lintOptions {
+        disable "MissingTranslation"
+    }
     buildTypes {
         debug {
             applicationIdSuffix ".debug"
index 246ed7d4fc87c4567adb347a2511305653ac1433..88971b20c0aabea4317f3cb7810c772d7e16de4b 100644 (file)
@@ -43,6 +43,7 @@
     <string name="speak">Sprechen</string>
     <string name="nextWord">Nächstes Wort</string>
     <string name="previousWord">Voriges Wort</string>
+    <string name="randomWord">Zufälliges Wort</string>
     
     <!-- About dictionary. -->
     <string name="dictionaryPath">Datei: %s</string>
index cab5f71476fcaa7a19c21783cc4a7258fc1bd396..1ace5610d3292b9a1312e0ab29b5521bfe7cb805 100644 (file)
@@ -46,6 +46,7 @@
     <string name="speak">Speak</string>
     <string name="nextWord">Next word</string>
     <string name="previousWord">Previous word</string>
+    <string name="randomWord">Random word</string>
 
     <!-- About dictionary. -->
     <string name="dictionaryPath">File: %s</string>
index bd45672730ce08c79e90f0ac083c3f2e1218e574..bb749f82fc333ba587d07a9ce7cc2f226c343cbf 100644 (file)
@@ -129,6 +129,8 @@ public class DictionaryActivity extends ActionBarActivity {
 
     List<RowBase> rowsToShow = null; // if not null, just show these rows.
 
+    final Random rand = new Random();
+
     final Handler uiHandler = new Handler();
 
     private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@@ -168,7 +170,7 @@ public class DictionaryActivity extends ActionBarActivity {
     ImageButton languageButton;
     SearchView.OnQueryTextListener onQueryTextListener;
 
-    MenuItem nextWordMenuItem, previousWordMenuItem;
+    MenuItem nextWordMenuItem, previousWordMenuItem, randomWordMenuItem;
 
     // Never null.
     private File wordList = null;
@@ -784,6 +786,14 @@ public class DictionaryActivity extends ActionBarActivity {
         defocusSearchText();
     }
 
+    void onRandomWordButton() {
+        int destIndexEntry = rand.nextInt(index.sortedIndexEntries.size());
+        final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry);
+        setSearchText(dest.token, false);
+        jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);
+        defocusSearchText();
+    }
+
     // --------------------------------------------------------------------------
     // Options Menu
     // --------------------------------------------------------------------------
@@ -820,6 +830,15 @@ public class DictionaryActivity extends ActionBarActivity {
             });
         }
 
+        randomWordMenuItem = menu.add(getString(R.string.randomWord));
+        randomWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+            @Override
+            public boolean onMenuItemClick(MenuItem item) {
+                onRandomWordButton();
+                return true;
+            }
+        });
+
         application.onCreateGlobalOptionsMenu(this, menu);
 
         {