package com.hughes.android.dictionary;
-import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
-import com.hughes.android.dictionary.engine.Dictionary;
-import com.hughes.android.dictionary.engine.EntrySource;
-import com.hughes.android.dictionary.engine.HtmlEntry;
-import com.hughes.android.dictionary.engine.Index;
-import com.hughes.android.dictionary.engine.Index.IndexEntry;
-import com.hughes.android.dictionary.engine.PairEntry;
-import com.hughes.android.dictionary.engine.PairEntry.Pair;
-import com.hughes.android.dictionary.engine.RowBase;
-import com.hughes.android.dictionary.engine.TokenRow;
-import com.hughes.android.dictionary.engine.TransliteratorManager;
-import com.hughes.android.util.IntentLauncher;
-import com.hughes.android.util.NonLinkClickableSpan;
-
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Context;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
+import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
+import com.hughes.android.dictionary.engine.Dictionary;
+import com.hughes.android.dictionary.engine.EntrySource;
+import com.hughes.android.dictionary.engine.HtmlEntry;
+import com.hughes.android.dictionary.engine.Index;
+import com.hughes.android.dictionary.engine.Index.IndexEntry;
+import com.hughes.android.dictionary.engine.PairEntry;
+import com.hughes.android.dictionary.engine.PairEntry.Pair;
+import com.hughes.android.dictionary.engine.RowBase;
+import com.hughes.android.dictionary.engine.TokenRow;
+import com.hughes.android.dictionary.engine.TransliteratorManager;
+import com.hughes.android.util.IntentLauncher;
+import com.hughes.android.util.NonLinkClickableSpan;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
setContentView(R.layout.dictionary_activity);
searchText = (EditText) findViewById(R.id.SearchText);
-
- langButton = (Button) findViewById(R.id.LangButton);
-
searchText.requestFocus();
searchText.addTextChangedListener(searchTextWatcher);
setSearchText(text, true);
Log.d(LOG, "Trying to restore searchText=" + text);
- final Button clearSearchTextButton = (Button) findViewById(R.id.ClearSearchTextButton);
+ final View clearSearchTextButton = findViewById(R.id.ClearSearchTextButton);
clearSearchTextButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- onClearSearchTextButton(clearSearchTextButton);
+ onClearSearchTextButton();
}
});
clearSearchTextButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.showClearSearchTextButtonKey), true) ? View.VISIBLE
: View.GONE);
- final Button langButton = (Button) findViewById(R.id.LangButton);
+ langButton = (Button) findViewById(R.id.LangButton);
langButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
onLanguageButton();
});
updateLangButton();
- final Button upButton = (Button) findViewById(R.id.UpButton);
+ final View upButton = findViewById(R.id.UpButton);
upButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
onUpDownButton(true);
}
});
- final Button downButton = (Button) findViewById(R.id.DownButton);
+ final View downButton = findViewById(R.id.DownButton);
downButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
onUpDownButton(false);
// Buttons
// --------------------------------------------------------------------------
- private void onClearSearchTextButton(final Button clearSearchTextButton) {
+ private void onClearSearchTextButton() {
setSearchText("", true);
Log.d(LOG, "Trying to show soft keyboard.");
final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
final LinearLayout result = new LinearLayout(parent.getContext());
final DictionaryInfo dictionaryInfo = getItem(position);
- final Button button = new Button(parent.getContext());
- final String name = application
- .getDictionaryName(dictionaryInfo.uncompressedFilename);
- button.setText(name);
- final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
- getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename),
- 0, searchText.getText().toString())) {
- @Override
- protected void onGo() {
- dialog.dismiss();
- DictionaryActivity.this.finish();
+ for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
+ final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);
+ final Button button = new Button(parent.getContext());
+// final String name = application
+// .getDictionaryName(dictionaryInfo.uncompressedFilename);
+ button.setText(indexInfo.shortName);
+ final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
+ getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename),
+ i, searchText.getText().toString())) {
+ @Override
+ protected void onGo() {
+ dialog.dismiss();
+ DictionaryActivity.this.finish();
+ };
};
- };
- button.setOnClickListener(intentLauncher);
- final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- layoutParams.width = 0;
- layoutParams.weight = 1.0f;
- button.setLayoutParams(layoutParams);
- result.addView(button);
+ button.setOnClickListener(intentLauncher);
+ final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ layoutParams.width = 0;
+ layoutParams.weight = 1.0f;
+ button.setLayoutParams(layoutParams);
+ result.addView(button);
+
+ if (i > 0) {
+ final TextView dash = new TextView(parent.getContext());
+ dash.setText("-");
+ result.addView(dash);
+ }
+ }
return result;
}
}
private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) {
- final Context context = parent.getContext();
-
final HtmlEntry htmlEntry = row.getEntry();
-
- // final TableRow tableRow = new TableRow(context);
- final LinearLayout tableRow = new LinearLayout(context);
- result.addView(tableRow);
-
- // Text.
- final TextView textView = new TextView(context);
- textView.setText(htmlEntry.title);
- textView.setLayoutParams(new LinearLayout.LayoutParams(0,
- ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
- tableRow.addView(textView);
-
- // Button.
- final Button button = new Button(context);
- button.setText("open");
- button.setLayoutParams(new LinearLayout.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0.0f));
- tableRow.addView(button);
-
- button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- startActivity(HtmlDisplayActivity.getHtmlIntent(String.format(
- "<html><head></head><body>%s</body></html>", htmlEntry.html)));
- }
- });
-
- return result;
+ return getPossibleHtmlEntryView(htmlEntry.title, false, Collections.singletonList(htmlEntry), parent, result);
}
- private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {
+ private TableLayout getPossibleHtmlEntryView(final String text, final boolean hasMainEntry, final List<HtmlEntry> htmlEntries, ViewGroup parent, final TableLayout result) {
final Context context = parent.getContext();
+
+ final TableRow tableRow = new TableRow(result.getContext());
+ tableRow.setBackgroundResource(hasMainEntry ? theme.tokenRowMainBg
+ : theme.tokenRowOtherBg);
+ tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0);
+ result.addView(tableRow);
+
+
final TextView textView = new TextView(context);
- textView.setText(row.getToken());
+ textView.setText(text);
// Doesn't work:
// textView.setTextColor(android.R.color.secondary_text_light);
textView.setTextAppearance(context, theme.tokenRowFg);
textView.setTypeface(typeface);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 5 * fontSizeSp / 4);
-
- final TableRow tableRow = new TableRow(result.getContext());
+ TableRow.LayoutParams lp = new TableRow.LayoutParams(0);
+ lp.weight = 1.0f;
+ textView.setLayoutParams(lp);
tableRow.addView(textView);
- tableRow.setBackgroundResource(row.hasMainEntry ? theme.tokenRowMainBg
- : theme.tokenRowOtherBg);
- tableRow.setPadding(mPaddingDefault, mPaddingDefault, mPaddingDefault, 0);
- result.addView(tableRow);
+
+
+ if (!htmlEntries.isEmpty()) {
+ final ImageButton button = new ImageButton(context);
+ button.setImageResource(R.drawable.ic_menu_forward);
+ button.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final String html = HtmlEntry.htmlBody(htmlEntries);
+ startActivity(HtmlDisplayActivity.getHtmlIntent(String.format(
+ "<html><head></head><body>%s</body></html>", html), text));
+ }
+ });
+ tableRow.addView(button);
+ lp = new TableRow.LayoutParams(1);
+ lp.weight = 0.0f;
+ button.setLayoutParams(lp);
+ //result.setColumnStretchable(0, true);
+ //result.setColumnStretchable(1, false);
+ }
return result;
}
+
+ private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {
+ final IndexEntry indexEntry = row.getIndexEntry();
+ return getPossibleHtmlEntryView(indexEntry.token, row.hasMainEntry, indexEntry.htmlEntries, parent, result);
+ }
}
+
+
static final Pattern CHAR_DASH = Pattern.compile("['\\p{L}\\p{M}\\p{N}]+");
}
void setFiltered(final SearchOperation searchOperation) {
- ((Button) findViewById(R.id.UpButton)).setEnabled(false);
- ((Button) findViewById(R.id.DownButton)).setEnabled(false);
+ ((ImageButton) findViewById(R.id.UpButton)).setEnabled(false);
+ ((ImageButton) findViewById(R.id.DownButton)).setEnabled(false);
rowsToShow = searchOperation.multiWordSearchResult;
setListAdapter(new IndexAdapter(index, rowsToShow, searchOperation.searchTokens));
}
void clearFiltered() {
- ((Button) findViewById(R.id.UpButton)).setEnabled(true);
- ((Button) findViewById(R.id.DownButton)).setEnabled(true);
+ ((ImageButton) findViewById(R.id.UpButton)).setEnabled(true);
+ ((ImageButton) findViewById(R.id.DownButton)).setEnabled(true);
setListAdapter(new IndexAdapter(index));
rowsToShow = null;
}