Skip to content

Commit

Permalink
Display improvements including new "help" action
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Barnes committed Feb 23, 2013
1 parent 1b3fcd3 commit b33b9b2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Expand Up @@ -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">

Expand Down
Binary file modified res/drawable/app_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions res/menu/lookup.xml
Expand Up @@ -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>
1 change: 1 addition & 0 deletions res/values/strings.xml
Expand Up @@ -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>
18 changes: 17 additions & 1 deletion src/nz/net/io/jarvis/BaseActivity.java
Expand Up @@ -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;
Expand All @@ -38,6 +39,10 @@ abstract class BaseActivity extends Activity implements AnimationListener {
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
Expand Down Expand Up @@ -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 = "";
}
}

/**
Expand All @@ -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\">";
Expand Down Expand Up @@ -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++;
Expand Down
54 changes: 0 additions & 54 deletions src/nz/net/io/jarvis/GraphicalActivity.java
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/nz/net/io/jarvis/LookupActivity.java
Expand Up @@ -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
Expand Down Expand Up @@ -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.