import android.view.View.OnClickListener;\r
import android.view.View.OnLongClickListener;\r
import android.view.ViewGroup;\r
+import android.view.ViewGroup.LayoutParams;\r
import android.view.WindowManager;\r
import android.view.inputmethod.InputMethodManager;\r
+import android.webkit.WebView;\r
import android.widget.AdapterView;\r
import android.widget.AdapterView.AdapterContextMenuInfo;\r
import android.widget.BaseAdapter;\r
import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;\r
import com.hughes.android.dictionary.engine.Dictionary;\r
import com.hughes.android.dictionary.engine.EntrySource;\r
+import com.hughes.android.dictionary.engine.HtmlEntry;\r
import com.hughes.android.dictionary.engine.Index;\r
import com.hughes.android.dictionary.engine.Index.IndexEntry;\r
import com.hughes.android.dictionary.engine.PairEntry;\r
// --------------------------------------------------------------------------\r
// IndexAdapter\r
// --------------------------------------------------------------------------\r
+ \r
+ static ViewGroup.LayoutParams WEIGHT_1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0f);\r
+ static ViewGroup.LayoutParams WEIGHT_0 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f);\r
\r
final class IndexAdapter extends BaseAdapter {\r
\r
return getView(position, (PairEntry.Row) row, parent, result);\r
} else if (row instanceof TokenRow) {\r
return getView((TokenRow) row, parent, result);\r
+ } else if (row instanceof HtmlEntry.Row) {\r
+ return getView((HtmlEntry.Row) row, parent, result);\r
} else {\r
throw new IllegalArgumentException("Unsupported Row type: " + row.getClass());\r
}\r
\r
return result;\r
}\r
+ \r
\r
+ private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) {\r
+ final Context context = parent.getContext();\r
+ \r
+ final HtmlEntry htmlEntry = row.getEntry();\r
+ \r
+ //final TableRow tableRow = new TableRow(context);\r
+ final LinearLayout tableRow = new LinearLayout(context);\r
+ result.addView(tableRow);\r
+ \r
+ // Text.\r
+ final TextView textView = new TextView(context);\r
+ textView.setText(htmlEntry.title);\r
+ textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));\r
+ tableRow.addView(textView);\r
+ \r
+ // Button.\r
+ final Button button = new Button(context);\r
+ button.setText("open");\r
+ button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0.0f));\r
+ tableRow.addView(button);\r
+ \r
+ button.setOnClickListener(new OnClickListener() {\r
+ @Override\r
+ public void onClick(View v) {\r
+ startActivity(HtmlDisplayActivity.getHtmlIntent(String.format("<html><head></head><body>%s</body></html>", htmlEntry.html)));\r
+ }\r
+ });\r
+ \r
+ return result;\r
+ }\r
+ \r
private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {\r
final Context context = parent.getContext();\r
final TextView textView = new TextView(context);\r
public final class HtmlDisplayActivity extends Activity {\r
\r
static final String HTML_RES = "html_res";\r
+ static final String HTML = "html";\r
\r
public static Intent getHelpLaunchIntent() {\r
final Intent intent = new Intent();\r
return intent;\r
}\r
\r
+ public static Intent getHtmlIntent(final String html) {\r
+ final Intent intent = new Intent();\r
+ intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(), HtmlDisplayActivity.class.getName());\r
+ intent.putExtra(HTML, html);\r
+ return intent;\r
+ }\r
+\r
/** Called when the activity is first created. */\r
@Override\r
public void onCreate(final Bundle savedInstanceState) {\r
setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId);\r
\r
super.onCreate(savedInstanceState);\r
- setContentView(R.layout.help_activity);\r
+ setContentView(R.layout.html_display_activity);\r
+ \r
final int htmlRes = getIntent().getIntExtra(HTML_RES, -1);\r
- final String html = StringUtil.readToString(getResources().openRawResource(htmlRes));\r
+ final String html;\r
+ if (htmlRes != -1) {\r
+ html = StringUtil.readToString(getResources().openRawResource(htmlRes));\r
+ } else {\r
+ html = getIntent().getStringExtra(HTML);\r
+ }\r
final WebView webView = (WebView) findViewById(R.id.webView);\r
webView.loadData(html, "text/html", "utf-8");\r
\r