From: thadh Date: Thu, 16 Apr 2009 16:06:12 +0000 (-0700) Subject: addedAboutAndIcons X-Git-Url: http://gitweb.fperrin.net/?a=commitdiff_plain;ds=sidebyside;h=b34978b4df094d7729849224d65c938ff579e97b;p=Dictionary.git addedAboutAndIcons --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 577a753..479231d 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,5 +11,7 @@ - + + + \ No newline at end of file diff --git a/americanFlag.jpg b/americanFlag.jpg new file mode 100755 index 0000000..8d85b25 Binary files /dev/null and b/americanFlag.jpg differ diff --git a/flags.xcf b/flags.xcf new file mode 100755 index 0000000..b322c28 Binary files /dev/null and b/flags.xcf differ diff --git a/germanFlag.jpg b/germanFlag.jpg new file mode 100755 index 0000000..b796c87 Binary files /dev/null and b/germanFlag.jpg differ diff --git a/res/drawable/icon.png b/res/drawable/icon.png index 7502484..17ccb38 100755 Binary files a/res/drawable/icon.png and b/res/drawable/icon.png differ diff --git a/res/layout/about.xml b/res/layout/about.xml new file mode 100755 index 0000000..d3c130d --- /dev/null +++ b/res/layout/about.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/main.xml b/res/layout/main.xml index e1e4a89..2de3e1a 100755 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -7,7 +7,7 @@ - + - Hello World, Dictionary + Dictionary +Dictionary\nby Thad Hughes + diff --git a/src/com/hughes/android/dictionary/AboutActivity.java b/src/com/hughes/android/dictionary/AboutActivity.java new file mode 100755 index 0000000..8317084 --- /dev/null +++ b/src/com/hughes/android/dictionary/AboutActivity.java @@ -0,0 +1,15 @@ +package com.hughes.android.dictionary; + +import android.app.Activity; +import android.os.Bundle; + +public final class AboutActivity extends Activity { + + /** Called when the activity is first created. */ + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.about); + } + +} diff --git a/src/com/hughes/android/dictionary/Dictionary.java b/src/com/hughes/android/dictionary/Dictionary.java index 7c1565a..9912593 100755 --- a/src/com/hughes/android/dictionary/Dictionary.java +++ b/src/com/hughes/android/dictionary/Dictionary.java @@ -112,29 +112,30 @@ public final class Dictionary implements RAFSerializable { return Math.min(sortedIndex.size() - 1, start); } - public int getTokenRow(final int rowIndex) { + public IndexEntry getIndexEntryForRow(final int rowIndex) { + // TODO: this kinda blows. int r = rowIndex; Row row; while (true) { row = rows.get(r); - if (row.isToken() || row.tokenRow != -1) { + if (row.isToken() || row.indexEntry != null) { break; } --r; } - final int result = row.isToken() ? r : row.tokenRow; + final IndexEntry indexEntry = row.isToken() ? sortedIndex.get(row.getIndex()) : row.indexEntry; for (; r <= rowIndex; ++r) { - rows.get(r).tokenRow = result; + rows.get(r).indexEntry = indexEntry; } - assert rows.get(result).isToken(); - return result; + assert false && rows.get(indexEntry.startRow).isToken(); + return indexEntry; } } public static final class Row implements RAFSerializable { final int index; - int tokenRow = -1; + IndexEntry indexEntry = null; public Row(final int index) { this.index = index; diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 382e81c..daa79dd 100755 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -10,11 +10,14 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import android.app.ListActivity; -import android.graphics.Color; +import android.content.Intent; +import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; import android.text.Editable; +import android.text.Spannable; import android.text.TextWatcher; +import android.text.style.StyleSpan; import android.util.Log; import android.view.ContextMenu; import android.view.KeyEvent; @@ -56,6 +59,8 @@ public class DictionaryActivity extends ListActivity { private DictionaryListAdapter dictionaryListAdapter = new DictionaryListAdapter(); private int selectedRowIndex = -1; private int selectedTokenRowIndex = -1; + + private final Intent aboutIntent = new Intent().setClassName(AboutActivity.class.getPackage().getName(), AboutActivity.class.getCanonicalName()); /** Called when the activity is first created. */ @Override @@ -73,8 +78,7 @@ public class DictionaryActivity extends ListActivity { setContentView(R.layout.main); - final EditText searchText = (EditText) findViewById(R.id.SearchText); - searchText.addTextChangedListener(new DictionaryTextWatcher()); + getSearchText().addTextChangedListener(new DictionaryTextWatcher()); setListAdapter(dictionaryListAdapter); @@ -117,22 +121,24 @@ public class DictionaryActivity extends ListActivity { jumpToRow(destRowIndex); }}); - // Context menu. + // ContextMenu. registerForContextMenu(getListView()); - + + // ItemSelectedListener. getListView().setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView arg0, View arg1, int rowIndex, long arg3) { Log.d("THAD", "onItemSelected: " + rowIndex); selectedRowIndex = rowIndex; - selectedTokenRowIndex = activeLangaugeData.getTokenRow(rowIndex); + selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow; updateSearchText(); } public void onNothingSelected(AdapterView arg0) { }}); - + + // LongClickListener. getListView().setOnItemLongClickListener((new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView arg0, View arg1, int rowIndex, long arg3) { @@ -145,12 +151,33 @@ public class DictionaryActivity extends ListActivity { public String getSelectedRowText() { return activeLangaugeData.rowToString(activeLangaugeData.rows.get(selectedRowIndex)); } + + public EditText getSearchText() { + return (EditText) findViewById(R.id.SearchText); + } + + // ---------------------------------------------------------------- + // OptionsMenu + // ---------------------------------------------------------------- private MenuItem switchLanguageMenuItem = null; @Override public boolean onCreateOptionsMenu(final Menu menu) { switchLanguageMenuItem = menu.add("Switch to language."); + switchLanguageMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener(){ + public boolean onMenuItemClick(final MenuItem menuItem) { + switchLanguage(); + return false; + }}); + + final MenuItem about = menu.add("About..."); + about.setOnMenuItemClickListener(new OnMenuItemClickListener(){ + public boolean onMenuItemClick(final MenuItem menuItem) { + startActivity(aboutIntent); + return false; + }}); + return true; } @@ -159,22 +186,32 @@ public class DictionaryActivity extends ListActivity { switchLanguageMenuItem.setTitle(String.format("Switch to %s", dictionary.languageDatas[Entry.otherLang(activeLangaugeData.lang)].language.symbol)); return super.onPrepareOptionsMenu(menu); } + + void switchLanguage() { + activeLangaugeData = dictionary.languageDatas[(activeLangaugeData == dictionary.languageDatas[0]) ? 1 : 0]; + selectedRowIndex = 0; + selectedTokenRowIndex = 0; + updateLangButton(); + dictionaryListAdapter.notifyDataSetChanged(); + onSearchTextChange(getSearchText().getText().toString()); + } - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - if (item == switchLanguageMenuItem) { - switchLanguage(); - } - return super.onOptionsItemSelected(item); + void updateLangButton() { + final Button langButton = (Button) findViewById(R.id.LangButton); + langButton.setText(activeLangaugeData.language.symbol); } - + + // ---------------------------------------------------------------- + // ContextMenu + // ---------------------------------------------------------------- + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (selectedRowIndex == -1) { return; } - final MenuItem addToWordlist = menu.add("Add to wordlist."); + final MenuItem addToWordlist = menu.add("Add to wordlist: " + wordList.getName()); addToWordlist.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final String rawText = getSelectedRowText(); @@ -191,23 +228,10 @@ public class DictionaryActivity extends ListActivity { }); } - void switchLanguage() { - activeLangaugeData = dictionary.languageDatas[(activeLangaugeData == dictionary.languageDatas[0]) ? 1 : 0]; - updateLangButton(); - dictionaryListAdapter.notifyDataSetChanged(); - final EditText searchText = (EditText) findViewById(R.id.SearchText); - onSearchTextChange(searchText.getText().toString()); - } - - void updateLangButton() { - final Button langButton = (Button) findViewById(R.id.LangButton); - langButton.setText(activeLangaugeData.language.symbol); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getUnicodeChar() != 0) { - final EditText searchText = (EditText) findViewById(R.id.SearchText); + final EditText searchText = getSearchText(); if (!searchText.hasFocus()) { searchText.setText("" + (char)event.getUnicodeChar()); onSearchTextChange(searchText.getText().toString()); @@ -235,17 +259,23 @@ public class DictionaryActivity extends ListActivity { } private void jumpToRow(final int rowIndex) { + Log.d("THAD", "jumpToRow: " + rowIndex); selectedRowIndex = rowIndex; - selectedTokenRowIndex = activeLangaugeData.getTokenRow(rowIndex); + selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow; getListView().setSelection(rowIndex); - getListView().setSelected(true); + getListView().setSelected(true); // TODO: is this doing anything? updateSearchText(); } private void updateSearchText() { - final EditText searchText = (EditText) findViewById(R.id.SearchText); + final EditText searchText = getSearchText(); if (!searchText.hasFocus()) { - searchText.setText(activeLangaugeData.rowToString(activeLangaugeData.rows.get(selectedTokenRowIndex))); + // TODO: Not so nice: + final String word = activeLangaugeData.getIndexEntryForRow(selectedRowIndex).word; + if (!word.equals(searchText.getText().toString())) { + Log.d("THAD", "updateSearchText: setText: " + word); + searchText.setText(word); + } } } @@ -304,6 +334,7 @@ public class DictionaryActivity extends ListActivity { result.setText(activeLangaugeData.rowToString(row)); result.setTextAppearance(parent.getContext(), android.R.style.TextAppearance_Large); + result.setClickable(false); return result; } @@ -341,8 +372,17 @@ public class DictionaryActivity extends ListActivity { // column1.setTextAppearance(parent.getContext(), android.R.style.Text); // TODO: highlight query word in entries. - column1.setText(entry.getAllText(activeLangaugeData.lang)[r]); - column2.setText(entry.getAllText(Entry.otherLang(activeLangaugeData.lang))[r]); + final String col1Text = entry.getAllText(activeLangaugeData.lang)[r]; + column1.setText(col1Text, TextView.BufferType.SPANNABLE); + final Spannable col1Spannable = (Spannable) column1.getText(); + int startPos = 0; + final String token = activeLangaugeData.getIndexEntryForRow(rowIndex).word; + while ((startPos = col1Text.indexOf(token, startPos)) != -1) { + col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + startPos += token.length(); + } + + column2.setText(entry.getAllText(Entry.otherLang(activeLangaugeData.lang))[r], TextView.BufferType.NORMAL); result.addView(tableRow); } @@ -353,7 +393,9 @@ public class DictionaryActivity extends ListActivity { private class DictionaryTextWatcher implements TextWatcher { public void afterTextChanged(Editable searchText) { - onSearchTextChange(searchText.toString()); + if (getSearchText().hasFocus()) { + onSearchTextChange(searchText.toString()); + } } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, diff --git a/src/com/hughes/android/dictionary/R.java b/src/com/hughes/android/dictionary/R.java index 2a750f4..4ec8d9b 100755 --- a/src/com/hughes/android/dictionary/R.java +++ b/src/com/hughes/android/dictionary/R.java @@ -14,19 +14,28 @@ public final class R { public static final int icon=0x7f020000; } public static final class id { - public static final int DownButton=0x7f050005; - public static final int LangButton=0x7f050004; - public static final int SearchBarLinearLayout=0x7f050000; - public static final int SearchBarTableLayout=0x7f050001; - public static final int SearchBarTableRow=0x7f050002; - public static final int SearchText=0x7f050003; - public static final int UpButton=0x7f050006; + public static final int DownButton=0x7f05000d; + public static final int ImageView01=0x7f050002; + public static final int LangButton=0x7f05000c; + public static final int LinearLayout01=0x7f050000; + public static final int LinearLayout02=0x7f050001; + public static final int SearchBarLinearLayout=0x7f050008; + public static final int SearchBarTableLayout=0x7f050009; + public static final int SearchBarTableRow=0x7f05000a; + public static final int SearchText=0x7f05000b; + public static final int UpButton=0x7f05000e; + public static final int author=0x7f050006; + public static final int copyright=0x7f050005; + public static final int email=0x7f050007; + public static final int space1=0x7f050004; + public static final int title=0x7f050003; } public static final class layout { - public static final int main=0x7f030000; + public static final int about=0x7f030000; + public static final int main=0x7f030001; } public static final class string { - public static final int app_name=0x7f040001; - public static final int hello=0x7f040000; + public static final int about_text=0x7f040001; + public static final int app_name=0x7f040000; } }