From: Reimar Döffinger Date: Sat, 30 Jan 2016 09:36:22 +0000 (+0100) Subject: Merge pull request #26 from Kteby/master X-Git-Url: http://gitweb.fperrin.net/?a=commitdiff_plain;h=56c7d964a83199140532764b9ecf05594a2e8531;hp=5f665bc8b167e306d5031a402ecadd4a3a54f64b;p=Dictionary.git Merge pull request #26 from Kteby/master Hide virtual keyboard if searchView text was changed programatically. --- diff --git a/.gitignore b/.gitignore index 72662ab..c94c0c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ +/.gradle +/.idea +/build /gen /.project /bin /lint.xml .DS_Store +*.class diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f872e98..982b0eb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="54" + android:versionName="5.2.3" > Font failure: %s vgl.: %1$s (%2$s) Sprechen - Next word - Previous word + Nächstes Wort + Voriges Wort + Zufälliges Wort Datei: %s diff --git a/res/values/strings.xml b/res/values/strings.xml index cab5f71..a1bc4df 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -27,6 +27,7 @@ Download failed: \n%s. + Could not query download manager.\nIs it disabled or missing? Unzipping dictionary: \n%s Unzipping failed: \n%s Installation finished: \n%s. @@ -46,6 +47,7 @@ Speak Next word Previous word + Random word File: %s diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index c8d99e4..f8cca58 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -129,6 +129,8 @@ public class DictionaryActivity extends ActionBarActivity { List 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; @@ -782,7 +784,7 @@ public class DictionaryActivity extends ActionBarActivity { } } else { // Down - destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size()); + destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size() - 1); } final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry); Log.d(LOG, "onUpDownButton, destIndexEntry=" + dest.token); @@ -791,6 +793,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 // -------------------------------------------------------------------------- @@ -827,6 +837,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); { diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index 159a7f0..dacc6d7 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -131,7 +131,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { final DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); final Cursor cursor = downloadManager.query(query); - if (!cursor.moveToFirst()) { + if (cursor == null || !cursor.moveToFirst()) { Log.e(LOG, "Couldn't find download."); return; } @@ -616,6 +616,16 @@ public class DictionaryManagerActivity extends ActionBarActivity { final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); final Cursor cursor = downloadManager.query(query); + + // Due to a bug, cursor is null instead of empty when + // the download manager is disabled. + if (cursor == null) { + new AlertDialog.Builder(DictionaryManagerActivity.this).setTitle(getString(R.string.error)) + .setMessage(getString(R.string.downloadFailed, R.string.downloadManagerQueryFailed)) + .setNeutralButton("Close", null).show(); + return; + } + while (cursor.moveToNext()) { if (downloadUrl.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI)))) break; diff --git a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java index b99f55b..dd07c4e 100644 --- a/src/com/hughes/android/dictionary/HtmlDisplayActivity.java +++ b/src/com/hughes/android/dictionary/HtmlDisplayActivity.java @@ -21,6 +21,7 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.util.Base64; import android.util.Log; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -108,4 +109,22 @@ public final class HtmlDisplayActivity extends ActionBarActivity { } } + @Override + public void onBackPressed() { + final MyWebView webView = (MyWebView)findViewById(R.id.webView); + if (webView.canGoBack()) webView.goBack(); + else super.onBackPressed(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Explicitly handle the up button press so + // we return to the dictionary. + if (item.getItemId() == android.R.id.home) + { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } }