X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FDictionaryActivity.java;h=77454f9a3e0032af41d5b056de722c577747fdc2;hb=ca5ee70f5d48b4218e15949b7b77b397a281d676;hp=3062b7249a14e2c4f4ab31b6d98bcd76a37ef628;hpb=3b4ed15ecaa3227aae17eceffe5e81285d328faf;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 3062b72..77454f9 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -285,7 +285,7 @@ public class DictionaryActivity extends AppCompatActivity { * -> language in which the phrase is written to -> to which * language shall be translated */ - if (intentAction != null && intentAction.equals("com.hughes.action.ACTION_SEARCH_DICT")) { + if ("com.hughes.action.ACTION_SEARCH_DICT".equals(intentAction)) { String query = intent.getStringExtra(SearchManager.QUERY); String from = intent.getStringExtra("from"); if (from != null) @@ -846,7 +846,7 @@ public class DictionaryActivity extends AppCompatActivity { final LinearLayout result = new LinearLayout(parent.getContext()); - for (int i = 0; dictionaryInfo.indexInfos != null && i < dictionaryInfo.indexInfos.size(); ++i) { + for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) { final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i); final View button = IsoUtils.INSTANCE.createButton(parent.getContext(), indexInfo, application.languageButtonPixels); @@ -1243,7 +1243,7 @@ public class DictionaryActivity extends AppCompatActivity { try { wordList.getParentFile().mkdirs(); final PrintWriter out = new PrintWriter(new FileWriter(wordList, true)); - out.println(rawText.toString()); + out.println(rawText); out.close(); } catch (Exception e) { Log.e(LOG, "Unable to append to " + wordList.getAbsolutePath(), e); @@ -1285,7 +1285,7 @@ public class DictionaryActivity extends AppCompatActivity { Log.d(LOG, "Trying to hide soft keyboard."); final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); View focus = getCurrentFocus(); - if (focus != null) { + if (inputManager != null && focus != null) { inputManager.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } @@ -1351,7 +1351,9 @@ public class DictionaryActivity extends AppCompatActivity { Log.d(LOG, "searchFinished: " + searchOperation + ", searchResult=" + searchResult); currentSearchOperation = null; - uiHandler.postDelayed(new Runnable() { + // Note: it's important to post to the ListView, otherwise + // the jumpToRow will randomly not work. + getListView().post(new Runnable() { @Override public void run() { if (currentSearchOperation == null) { @@ -1370,10 +1372,10 @@ public class DictionaryActivity extends AppCompatActivity { Log.d(LOG, "More coming, waiting for currentSearchOperation."); } } - }, 20); + }); } - private final void jumpToRow(final int row) { + private void jumpToRow(final int row) { Log.d(LOG, "jumpToRow: " + row + ", refocusSearchText=" + false); // getListView().requestFocusFromTouch(); getListView().setSelectionFromTop(row, 0); @@ -1406,7 +1408,7 @@ public class DictionaryActivity extends AppCompatActivity { } public String toString() { - return String.format("SearchOperation(%s,%s)", searchText, interrupted.toString()); + return String.format("SearchOperation(%s,%s)", searchText, interrupted); } @Override @@ -1436,7 +1438,7 @@ public class DictionaryActivity extends AppCompatActivity { Log.d(LOG, "interrupted, skipping searchFinished."); } } catch (Exception e) { - Log.e(LOG, "Failure during search (can happen during Activity close."); + Log.e(LOG, "Failure during search (can happen during Activity close): " + e.getMessage()); } finally { synchronized (this) { done = true; @@ -1501,7 +1503,7 @@ public class DictionaryActivity extends AppCompatActivity { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); scale = dm.density; - } catch (NullPointerException e) + } catch (NullPointerException ignored) {} // Convert the dps to pixels, based on density scale mPaddingDefault = (int) (PADDING_DEFAULT_DP * scale + 0.5f); @@ -1604,19 +1606,6 @@ public class DictionaryActivity extends AppCompatActivity { col1.setTextColor(textColorFg); col2.setTextColor(textColorFg); - // Set the columns in the table. - if (r > 0) { - final TextView bullet = new TextView(tableRow.getContext()); - bullet.setText(" •"); - tableRow.addView(bullet); - } - tableRow.addView(col1, layoutParams); - if (r > 0) { - final TextView bullet = new TextView(tableRow.getContext()); - bullet.setText(" •"); - tableRow.addView(bullet); - } - tableRow.addView(col2, layoutParams); col1.setWidth(1); col2.setWidth(1); @@ -1634,13 +1623,37 @@ public class DictionaryActivity extends AppCompatActivity { col2.setOnLongClickListener(textViewLongClickListenerIndex1); } + // Set the columns in the table. + if (r == 0) { + tableRow.addView(col1, layoutParams); + tableRow.addView(col2, layoutParams); + } else { + for (int i = 0; i < 2; i++) { + final TextView bullet = new TextView(tableRow.getContext()); + bullet.setText(" • "); + LinearLayout wrapped = new LinearLayout(context); + wrapped.setOrientation(LinearLayout.HORIZONTAL); + LinearLayout.LayoutParams p1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0); + wrapped.addView(bullet, p1); + LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); + wrapped.addView(i == 0 ? col1 : col2, p2); + tableRow.addView(wrapped, layoutParams); + } + } + result.addView(tableRow); } for (int r = 0; r < rowCount; ++r) { final TableRow tableRow = (TableRow)result.getChildAt(r); - final TextView col1 = (TextView)tableRow.getChildAt(r == 0 ? 0 : 1); - final TextView col2 = (TextView)tableRow.getChildAt(r == 0 ? 1 : 3); + View left = tableRow.getChildAt(0); + View right = tableRow.getChildAt(1); + if (r > 0) { + left = ((ViewGroup)left).getChildAt(1); + right = ((ViewGroup)right).getChildAt(1); + } + final TextView col1 = (TextView)left; + final TextView col2 = (TextView)right; // Set what's in the columns. final Pair pair = entry.pairs.get(r);