Permalink
Browse files

Display improvements including new "help" action

  • Loading branch information...
1 parent 1b3fcd3 commit b33b9b20c3f9fed863824ef483518120bf45a1ed @srynot4sale committed Feb 23, 2013
View
@@ -17,7 +17,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nz.net.io.jarvis"
android:versionCode="1"
- android:versionName="1.0">
+ android:versionName="1.0.12">
<application android:icon="@drawable/app_icon" android:label="@string/app_name"
android:description="@string/app_descrip">
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -26,4 +26,10 @@
android:title="@string/lookup_about"
android:icon="@android:drawable/ic_menu_help" />
+ <item
+ android:id="@+id/lookup_help"
+ android:title="@string/lookup_help"
+ android:icon="@android:drawable/ic_menu_help" />
+
+
</menu>
View
@@ -51,5 +51,6 @@
<string name="lookup_about">About</string>
<string name="empty_result">No entry found for this word, or problem reading data.</string>
+ <string name="lookup_help">Help</string>
</resources>
@@ -19,6 +19,7 @@
import android.widget.TextView;
import java.util.Stack;
+import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
@@ -38,6 +39,10 @@
protected Animation mSlideIn;
protected Animation mSlideOut;
+ protected String function;
+ protected String action;
+ protected String data;
+
/**
* History stack of previous words browsed in this session. This is
* referenced when the user taps the "back" key, to possibly intercept and
@@ -131,6 +136,16 @@ protected void setEntryTitle(String entryText) {
mEntryTitle = entryText;
mTitle.setText(mEntryTitle);
}
+
+ Pattern pattern = Pattern.compile("/");
+ String[] parts = pattern.split(entryText, 4);
+ function = parts[1];
+ action = parts[2];
+ if (parts.length > 3) {
+ data = parts[3];
+ } else {
+ data = "";
+ }
}
/**
@@ -144,6 +159,7 @@ protected void setEntryContent(String entryContent) {
html += "div#body { margin-left: 2px; padding: 3px; font-size: 17px; color: #fff; background:rgba(0, 0, 0, 0.5); }";
html += "h3, p, ul { display: block; padding: 1px 10px; }";
html += "ul { padding-left: 30px; }";
+ html += "li { padding-bottom: 5px; }";
html += "a { color: #fff; }";
html += "</style>";
html += "<div id=\"body\">";
@@ -180,7 +196,7 @@ protected void setEntryContent(String entryContent) {
html = html + "<li>";
while (j < item.length()) {
if (j > 0) {
- html = html + "|";
+ html = html + " | ";
}
html = html + item.getString(j);
j++;
@@ -6,22 +6,17 @@
package nz.net.io.jarvis;
-import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
-import android.widget.TextView;
/**
@@ -117,55 +112,6 @@ public boolean dispatchKeyEvent(KeyEvent event) {
return super.dispatchKeyEvent(event);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.lookup, menu);
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.lookup_apicall: {
- onSearchRequested();
- return true;
- }
- case R.id.lookup_about: {
- showAbout();
- return true;
- }
- }
- return false;
- }
-
- /**
- * Show an about dialog that cites data sources.
- */
- protected void showAbout() {
- // Inflate the about message contents
- View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
-
- // When linking text, force to always use default color. This works
- // around a pressed color state bug.
- TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
- int defaultColor = textView.getTextColors().getDefaultColor();
- textView.setTextColor(defaultColor);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setIcon(R.drawable.app_icon);
- builder.setTitle(R.string.app_name);
- builder.setView(messageView);
- builder.create();
- builder.show();
- }
-
/**
* Because we're singleTop, we handle our own new intents. These usually
* come from the {@link SearchManager} when a search is requested, or from
@@ -21,11 +21,13 @@
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
+import android.view.MenuItem;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;
+
/**
* Activity that lets users browse through Wiktionary content. This is just the
* user interface, and all API communication and parsing is handled in
@@ -139,4 +141,36 @@ public void onNewIntent(Intent intent) {
startNavigating(null, true);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.lookup_apicall: {
+ onSearchRequested();
+ return true;
+ }
+ case R.id.lookup_help: {
+ openHelp();
+ return true;
+ }
+ case R.id.lookup_about: {
+ showAbout();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void openHelp() {
+ String func;
+ if (function.length() > 0) {
+ func = function;
+ } else {
+ func = "server";
+ }
+ startNavigating(func+" help", true);
+ }
}

0 comments on commit b33b9b2

Please sign in to comment.