Browse files

Action bar buttons.

(Menu buttons for older devices.)
  • Loading branch information...
1 parent bdd5b5c commit 2d260525affc38e5817cef1764033e69c8204f7f @arantius committed Apr 13, 2012
View
2 AndroidManifest.xml
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
android:versionCode="13" android:versionName="13"
package="com.arantius.tivocommander"
>
- <uses-sdk android:targetSdkVersion="11" android:minSdkVersion="7"></uses-sdk>
+ <uses-sdk android:targetSdkVersion="15" android:minSdkVersion="7"></uses-sdk>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
View
2 project.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-7
+target=android-15
View
14 res/menu/main.xml
@@ -0,0 +1,14 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menu_item_remote" android:icon="@drawable/icon_remote"
+ android:showAsAction="ifRoom" android:title="Remote" />
+ <item android:id="@+id/menu_item_my_shows" android:icon="@drawable/icon_tv32"
+ android:showAsAction="ifRoom" android:title="My Shows" />
+ <item android:id="@+id/menu_item_search" android:icon="@drawable/icon_search"
+ android:showAsAction="ifRoom" android:title="Search" />
+ <item android:id="@+id/menu_item_settings" android:icon="@drawable/icon_cog"
+ android:showAsAction="ifRoom" android:title="Settings" />
+ <item android:id="@+id/menu_item_help" android:icon="@drawable/icon_help"
+ android:showAsAction="ifRoom" android:title="Help" />
+ <item android:id="@+id/menu_item_about" android:icon="@drawable/icon_info"
+ android:showAsAction="ifRoom" android:title="About" />
+</menu>
View
8 src/com/arantius/tivocommander/About.java
@@ -21,6 +21,7 @@
import android.app.Activity;
import android.os.Bundle;
+import android.view.MenuItem;
import android.widget.TextView;
import com.arantius.tivocommander.rpc.MindRpc;
@@ -33,6 +34,13 @@ protected void onCreate(Bundle savedInstanceState) {
TextView title = (TextView) findViewById(R.id.textView1);
title.setText(title.getText() + Utils.getVersion(this));
+
+ Utils.activateHomeButton(this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
}
@Override
View
2 src/com/arantius/tivocommander/Catalog.java
@@ -25,6 +25,8 @@
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
View
12 src/com/arantius/tivocommander/ExploreTabs.java
@@ -23,6 +23,8 @@
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
@@ -99,4 +101,14 @@ protected void onCreate(Bundle savedInstanceState) {
R.drawable.icon_similar));
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return Utils.onCreateOptionsMenu(menu, this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
+ }
}
View
8 src/com/arantius/tivocommander/Help.java
@@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
+import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
@@ -23,6 +24,13 @@ protected void onCreate(Bundle savedInstanceState) {
((TextView) findViewById(R.id.note)).setText(bundle.getString("note"));
findViewById(R.id.note_layout).setVisibility(View.VISIBLE);
}
+
+ Utils.activateHomeButton(this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
}
@Override
View
12 src/com/arantius/tivocommander/MyShows.java
@@ -35,6 +35,8 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@@ -385,6 +387,16 @@ protected void onCreate(Bundle savedInstanceState) {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return Utils.onCreateOptionsMenu(menu, this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
+ }
+
+ @Override
protected void onPause() {
super.onPause();
Utils.log("Activity:Pause:MyShows");
View
12 src/com/arantius/tivocommander/Remote.java
@@ -26,6 +26,8 @@
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
@@ -182,6 +184,16 @@ protected void onCreate(Bundle savedInstanceState) {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return Utils.onCreateOptionsMenu(menu, this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
+ }
+
+ @Override
protected void onResume() {
super.onResume();
Utils.log("Activity:Resume:Remote");
View
12 src/com/arantius/tivocommander/Search.java
@@ -32,6 +32,8 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@@ -254,6 +256,16 @@ protected void onCreate(Bundle savedInstanceState) {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return Utils.onCreateOptionsMenu(menu, this);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return Utils.onOptionsItemSelected(item, this);
+ }
+
+ @Override
protected void onResume() {
super.onResume();
Utils.log("Activity:Resume:Search");
View
51 src/com/arantius/tivocommander/Utils.java
@@ -35,11 +35,16 @@
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;
+import android.app.ActionBar;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.Toast;
public class Utils {
@@ -138,6 +143,52 @@ public static final void mailLog(String log, Context context, String title) {
}
}
+ public final static void activateHomeButton(Activity activity) {
+ ActionBar ab = activity.getActionBar();
+ ab.setDisplayHomeAsUpEnabled(true);
+ }
+
+ public final static boolean onCreateOptionsMenu(Menu menu, Activity activity) {
+ Utils.activateHomeButton(activity);
+ // TODO: Not show the current activity.
+ MenuInflater inflater = activity.getMenuInflater();
+ inflater.inflate(R.menu.main, menu);
+ return true;
+ }
+
+ public final static boolean onOptionsItemSelected(MenuItem item,
+ Activity activity) {
+ Intent intent = null;
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ intent = new Intent(activity, Catalog.class);
+ break;
+ case R.id.menu_item_remote:
+ intent = new Intent(activity, Remote.class);
+ case R.id.menu_item_my_shows:
+ intent = new Intent(activity, MyShows.class);
+ break;
+ case R.id.menu_item_search:
+ intent = new Intent(activity, Search.class);
+ break;
+ case R.id.menu_item_settings:
+ intent = new Intent(activity, Discover.class);
+ break;
+ case R.id.menu_item_help:
+ intent = new Intent(activity, Help.class);
+ break;
+ case R.id.menu_item_about:
+ intent = new Intent(activity, About.class);
+ break;
+ default:
+ Utils.logError("Unknown item ID: " + Integer.toString(item.getItemId()));
+ return false;
+ }
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ activity.startActivity(intent);
+ return true;
+ }
+
public final static Date parseDateStr(String dateStr) {
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
return parseDateTimeStr(dateParser, dateStr);

0 comments on commit 2d26052

Please sign in to comment.