Home button in action bar now links back to initial activity

Fixed toasts for route selection errors
This commit is contained in:
dkeen@dkeen-laptop 2012-07-18 10:31:06 -07:00
parent b1be5cde23
commit 749f8ac124
8 changed files with 161 additions and 110 deletions

View File

@ -6,5 +6,6 @@
<classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/>
<classpathentry kind="lib" path="libs/commons-lang3-3.1.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry combineaccessrules="false" kind="src" path="/sherlock"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -43,20 +43,20 @@ public abstract class AbstractRouteSelectionActivity extends Activity {
if (origin == null) {
Toast.makeText(v.getContext(),
com.dougkeen.bart.R.string.error_null_origin,
Toast.LENGTH_LONG);
Toast.LENGTH_LONG).show();
return;
}
if (destination == null) {
Toast.makeText(v.getContext(),
com.dougkeen.bart.R.string.error_null_destination,
Toast.LENGTH_LONG);
Toast.LENGTH_LONG).show();
return;
}
if (origin.equals(destination)) {
Toast.makeText(
v.getContext(),
com.dougkeen.bart.R.string.error_matching_origin_and_destination,
Toast.LENGTH_LONG);
Toast.LENGTH_LONG).show();
return;
}
onOkButtonClick(origin, destination);

View File

@ -128,6 +128,9 @@ public class ViewDeparturesActivity extends ActionBarListActivity {
findViewById(R.id.missingDepartureText).setVisibility(View.VISIBLE);
refreshBoardedDeparture();
getActionBarHelper().setHomeButtonEnabled(true);
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
}
@Override
@ -534,7 +537,11 @@ public class ViewDeparturesActivity extends ActionBarListActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.view_on_bart_site_button) {
if (itemId == android.R.id.home) {
startActivity(new Intent(Intent.ACTION_PICK,
Constants.FAVORITE_CONTENT_URI));
return true;
} else if (itemId == R.id.view_on_bart_site_button) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://m.bart.gov/schedules/qp_results.aspx?type=departure&date=today&time="

View File

@ -1,11 +1,14 @@
package com.dougkeen.bart;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
import com.dougkeen.bart.actionbarcompat.ActionBarActivity;
import com.dougkeen.bart.model.Constants;
public class ViewMapActivity extends ActionBarActivity {
@ -20,6 +23,9 @@ public class ViewMapActivity extends ActionBarActivity {
webview.getSettings().setSupportZoom(true);
webview.loadUrl("file:///android_res/drawable/map.png");
getActionBarHelper().setHomeButtonEnabled(true);
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
}
@Override
@ -29,4 +35,14 @@ public class ViewMapActivity extends ActionBarActivity {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
startActivity(new Intent(Intent.ACTION_PICK,
Constants.FAVORITE_CONTENT_URI));
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -23,75 +23,86 @@ import android.view.Menu;
import android.view.MenuInflater;
/**
* An abstract class that handles some common action bar-related functionality in the app. This
* class provides functionality useful for both phones and tablets, and does not require any Android
* 3.0-specific features, although it uses them if available.
*
* Two implementations of this class are {@link ActionBarHelperBase} for a pre-Honeycomb version of
* the action bar, and {@link ActionBarHelperHoneycomb}, which uses the built-in ActionBar features
* in Android 3.0 and later.
* An abstract class that handles some common action bar-related functionality
* in the app. This class provides functionality useful for both phones and
* tablets, and does not require any Android 3.0-specific features, although it
* uses them if available.
*
* Two implementations of this class are {@link ActionBarHelperBase} for a
* pre-Honeycomb version of the action bar, and {@link ActionBarHelperHoneycomb}
* , which uses the built-in ActionBar features in Android 3.0 and later.
*/
public abstract class ActionBarHelper {
protected Activity mActivity;
protected Activity mActivity;
/**
* Factory method for creating {@link ActionBarHelper} objects for a
* given activity. Depending on which device the app is running, either a basic helper or
* Honeycomb-specific helper will be returned.
*/
public static ActionBarHelper createInstance(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return new ActionBarHelperICS(activity);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return new ActionBarHelperHoneycomb(activity);
} else {
return new ActionBarHelperBase(activity);
}
}
/**
* Factory method for creating {@link ActionBarHelper} objects for a given
* activity. Depending on which device the app is running, either a basic
* helper or Honeycomb-specific helper will be returned.
*/
public static ActionBarHelper createInstance(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return new ActionBarHelperICS(activity);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return new ActionBarHelperHoneycomb(activity);
} else {
return new ActionBarHelperBase(activity);
}
}
protected ActionBarHelper(Activity activity) {
mActivity = activity;
}
protected ActionBarHelper(Activity activity) {
mActivity = activity;
}
/**
* Action bar helper code to be run in {@link Activity#onCreate(android.os.Bundle)}.
*/
public void onCreate(Bundle savedInstanceState) {
}
/**
* Action bar helper code to be run in
* {@link Activity#onCreate(android.os.Bundle)}.
*/
public void onCreate(Bundle savedInstanceState) {
}
/**
* Action bar helper code to be run in {@link Activity#onPostCreate(android.os.Bundle)}.
*/
public void onPostCreate(Bundle savedInstanceState) {
}
/**
* Action bar helper code to be run in
* {@link Activity#onPostCreate(android.os.Bundle)}.
*/
public void onPostCreate(Bundle savedInstanceState) {
}
/**
* Action bar helper code to be run in {@link Activity#onCreateOptionsMenu(android.view.Menu)}.
*
* NOTE: Setting the visibility of menu items in <em>menu</em> is not currently supported.
*/
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
/**
* Action bar helper code to be run in
* {@link Activity#onCreateOptionsMenu(android.view.Menu)}.
*
* NOTE: Setting the visibility of menu items in <em>menu</em> is not
* currently supported.
*/
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
/**
* Action bar helper code to be run in {@link Activity#onTitleChanged(CharSequence, int)}.
*/
protected void onTitleChanged(CharSequence title, int color) {
}
/**
* Action bar helper code to be run in
* {@link Activity#onTitleChanged(CharSequence, int)}.
*/
protected void onTitleChanged(CharSequence title, int color) {
}
/**
* Sets the indeterminate loading state of the item with ID {@link R.id.menu_refresh}.
* (where the item ID was menu_refresh).
*/
public abstract void setRefreshActionItemState(boolean refreshing);
/**
* Sets the indeterminate loading state of the item with ID
* {@link R.id.menu_refresh}. (where the item ID was menu_refresh).
*/
public abstract void setRefreshActionItemState(boolean refreshing);
/**
* Returns a {@link MenuInflater} for use when inflating menus. The implementation of this
* method in {@link ActionBarHelperBase} returns a wrapped menu inflater that can read
* action bar metadata from a menu resource pre-Honeycomb.
*/
public MenuInflater getMenuInflater(MenuInflater superMenuInflater) {
return superMenuInflater;
}
/**
* Returns a {@link MenuInflater} for use when inflating menus. The
* implementation of this method in {@link ActionBarHelperBase} returns a
* wrapped menu inflater that can read action bar metadata from a menu
* resource pre-Honeycomb.
*/
public MenuInflater getMenuInflater(MenuInflater superMenuInflater) {
return superMenuInflater;
}
abstract public void setHomeButtonEnabled(boolean enabled);
abstract public void setDisplayHomeAsUpEnabled(boolean enabled);
}

View File

@ -316,4 +316,12 @@ public class ActionBarHelperBase extends ActionBarHelper {
}
}
@Override
public void setHomeButtonEnabled(boolean enabled) {
}
@Override
public void setDisplayHomeAsUpEnabled(boolean enabled) {
}
}

View File

@ -26,55 +26,65 @@ import android.view.View;
import com.dougkeen.bart.R;
/**
* An extension of {@link ActionBarHelper} that provides Android 3.0-specific functionality for
* Honeycomb tablets. It thus requires API level 11.
* An extension of {@link ActionBarHelper} that provides Android 3.0-specific
* functionality for Honeycomb tablets. It thus requires API level 11.
*/
public class ActionBarHelperHoneycomb extends ActionBarHelper {
private Menu mOptionsMenu;
private View mRefreshIndeterminateProgressView = null;
private Menu mOptionsMenu;
private View mRefreshIndeterminateProgressView = null;
protected ActionBarHelperHoneycomb(Activity activity) {
super(activity);
}
protected ActionBarHelperHoneycomb(Activity activity) {
super(activity);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
mOptionsMenu = menu;
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
mOptionsMenu = menu;
return super.onCreateOptionsMenu(menu);
}
@Override
public void setRefreshActionItemState(boolean refreshing) {
// On Honeycomb, we can set the state of the refresh button by giving it a custom
// action view.
if (mOptionsMenu == null) {
return;
}
@Override
public void setRefreshActionItemState(boolean refreshing) {
// On Honeycomb, we can set the state of the refresh button by giving it
// a custom
// action view.
if (mOptionsMenu == null) {
return;
}
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
if (refreshItem != null) {
if (refreshing) {
if (mRefreshIndeterminateProgressView == null) {
LayoutInflater inflater = (LayoutInflater)
getActionBarThemedContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mRefreshIndeterminateProgressView = inflater.inflate(
R.layout.actionbar_indeterminate_progress, null);
}
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
if (refreshItem != null) {
if (refreshing) {
if (mRefreshIndeterminateProgressView == null) {
LayoutInflater inflater = (LayoutInflater) getActionBarThemedContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mRefreshIndeterminateProgressView = inflater.inflate(
R.layout.actionbar_indeterminate_progress, null);
}
refreshItem.setActionView(mRefreshIndeterminateProgressView);
} else {
refreshItem.setActionView(null);
}
}
}
refreshItem.setActionView(mRefreshIndeterminateProgressView);
} else {
refreshItem.setActionView(null);
}
}
}
/**
* Returns a {@link Context} suitable for inflating layouts for the action bar. The
* implementation for this method in {@link ActionBarHelperICS} asks the action bar for a
* themed context.
*/
protected Context getActionBarThemedContext() {
return mActivity;
}
/**
* Returns a {@link Context} suitable for inflating layouts for the action
* bar. The implementation for this method in {@link ActionBarHelperICS}
* asks the action bar for a themed context.
*/
protected Context getActionBarThemedContext() {
return mActivity;
}
@Override
public void setHomeButtonEnabled(boolean enabled) {
mActivity.getActionBar().setHomeButtonEnabled(enabled);
}
@Override
public void setDisplayHomeAsUpEnabled(boolean enabled) {
mActivity.getActionBar().setDisplayHomeAsUpEnabled(enabled);
}
}

View File

@ -18,8 +18,6 @@ package com.dougkeen.bart.actionbarcompat;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
/**
* An extension of {@link com.example.android.actionbarcompat.ActionBarHelper} that provides Android