Home button in action bar now links back to initial activity
Fixed toasts for route selection errors
This commit is contained in:
parent
b1be5cde23
commit
749f8ac124
@ -6,5 +6,6 @@
|
|||||||
<classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/>
|
<classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/>
|
||||||
<classpathentry kind="lib" path="libs/commons-lang3-3.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 exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/sherlock"/>
|
||||||
<classpathentry kind="output" path="bin/classes"/>
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -43,20 +43,20 @@ public abstract class AbstractRouteSelectionActivity extends Activity {
|
|||||||
if (origin == null) {
|
if (origin == null) {
|
||||||
Toast.makeText(v.getContext(),
|
Toast.makeText(v.getContext(),
|
||||||
com.dougkeen.bart.R.string.error_null_origin,
|
com.dougkeen.bart.R.string.error_null_origin,
|
||||||
Toast.LENGTH_LONG);
|
Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (destination == null) {
|
if (destination == null) {
|
||||||
Toast.makeText(v.getContext(),
|
Toast.makeText(v.getContext(),
|
||||||
com.dougkeen.bart.R.string.error_null_destination,
|
com.dougkeen.bart.R.string.error_null_destination,
|
||||||
Toast.LENGTH_LONG);
|
Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (origin.equals(destination)) {
|
if (origin.equals(destination)) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
v.getContext(),
|
v.getContext(),
|
||||||
com.dougkeen.bart.R.string.error_matching_origin_and_destination,
|
com.dougkeen.bart.R.string.error_matching_origin_and_destination,
|
||||||
Toast.LENGTH_LONG);
|
Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onOkButtonClick(origin, destination);
|
onOkButtonClick(origin, destination);
|
||||||
|
@ -128,6 +128,9 @@ public class ViewDeparturesActivity extends ActionBarListActivity {
|
|||||||
findViewById(R.id.missingDepartureText).setVisibility(View.VISIBLE);
|
findViewById(R.id.missingDepartureText).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
refreshBoardedDeparture();
|
refreshBoardedDeparture();
|
||||||
|
|
||||||
|
getActionBarHelper().setHomeButtonEnabled(true);
|
||||||
|
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -534,7 +537,11 @@ public class ViewDeparturesActivity extends ActionBarListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
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(
|
startActivity(new Intent(
|
||||||
Intent.ACTION_VIEW,
|
Intent.ACTION_VIEW,
|
||||||
Uri.parse("http://m.bart.gov/schedules/qp_results.aspx?type=departure&date=today&time="
|
Uri.parse("http://m.bart.gov/schedules/qp_results.aspx?type=departure&date=today&time="
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package com.dougkeen.bart;
|
package com.dougkeen.bart;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import com.dougkeen.bart.actionbarcompat.ActionBarActivity;
|
import com.dougkeen.bart.actionbarcompat.ActionBarActivity;
|
||||||
|
import com.dougkeen.bart.model.Constants;
|
||||||
|
|
||||||
public class ViewMapActivity extends ActionBarActivity {
|
public class ViewMapActivity extends ActionBarActivity {
|
||||||
|
|
||||||
@ -20,6 +23,9 @@ public class ViewMapActivity extends ActionBarActivity {
|
|||||||
webview.getSettings().setSupportZoom(true);
|
webview.getSettings().setSupportZoom(true);
|
||||||
|
|
||||||
webview.loadUrl("file:///android_res/drawable/map.png");
|
webview.loadUrl("file:///android_res/drawable/map.png");
|
||||||
|
|
||||||
|
getActionBarHelper().setHomeButtonEnabled(true);
|
||||||
|
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,4 +35,14 @@ public class ViewMapActivity extends ActionBarActivity {
|
|||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,75 +23,86 @@ import android.view.Menu;
|
|||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract class that handles some common action bar-related functionality in the app. This
|
* An abstract class that handles some common action bar-related functionality
|
||||||
* class provides functionality useful for both phones and tablets, and does not require any Android
|
* in the app. This class provides functionality useful for both phones and
|
||||||
* 3.0-specific features, although it uses them if available.
|
* 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
|
* Two implementations of this class are {@link ActionBarHelperBase} for a
|
||||||
* the action bar, and {@link ActionBarHelperHoneycomb}, which uses the built-in ActionBar features
|
* pre-Honeycomb version of the action bar, and {@link ActionBarHelperHoneycomb}
|
||||||
* in Android 3.0 and later.
|
* , which uses the built-in ActionBar features in Android 3.0 and later.
|
||||||
*/
|
*/
|
||||||
public abstract class ActionBarHelper {
|
public abstract class ActionBarHelper {
|
||||||
protected Activity mActivity;
|
protected Activity mActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for creating {@link ActionBarHelper} objects for a
|
* Factory method for creating {@link ActionBarHelper} objects for a given
|
||||||
* given activity. Depending on which device the app is running, either a basic helper or
|
* activity. Depending on which device the app is running, either a basic
|
||||||
* Honeycomb-specific helper will be returned.
|
* helper or Honeycomb-specific helper will be returned.
|
||||||
*/
|
*/
|
||||||
public static ActionBarHelper createInstance(Activity activity) {
|
public static ActionBarHelper createInstance(Activity activity) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
return new ActionBarHelperICS(activity);
|
return new ActionBarHelperICS(activity);
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
return new ActionBarHelperHoneycomb(activity);
|
return new ActionBarHelperHoneycomb(activity);
|
||||||
} else {
|
} else {
|
||||||
return new ActionBarHelperBase(activity);
|
return new ActionBarHelperBase(activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ActionBarHelper(Activity activity) {
|
protected ActionBarHelper(Activity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action bar helper code to be run in {@link Activity#onCreate(android.os.Bundle)}.
|
* Action bar helper code to be run in
|
||||||
*/
|
* {@link Activity#onCreate(android.os.Bundle)}.
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
*/
|
||||||
}
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action bar helper code to be run in {@link Activity#onPostCreate(android.os.Bundle)}.
|
* Action bar helper code to be run in
|
||||||
*/
|
* {@link Activity#onPostCreate(android.os.Bundle)}.
|
||||||
public void onPostCreate(Bundle savedInstanceState) {
|
*/
|
||||||
}
|
public void onPostCreate(Bundle savedInstanceState) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action bar helper code to be run in {@link Activity#onCreateOptionsMenu(android.view.Menu)}.
|
* 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.
|
*
|
||||||
*/
|
* NOTE: Setting the visibility of menu items in <em>menu</em> is not
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
* currently supported.
|
||||||
return true;
|
*/
|
||||||
}
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action bar helper code to be run in {@link Activity#onTitleChanged(CharSequence, int)}.
|
* Action bar helper code to be run in
|
||||||
*/
|
* {@link Activity#onTitleChanged(CharSequence, int)}.
|
||||||
protected void onTitleChanged(CharSequence title, int color) {
|
*/
|
||||||
}
|
protected void onTitleChanged(CharSequence title, int color) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the indeterminate loading state of the item with ID {@link R.id.menu_refresh}.
|
* Sets the indeterminate loading state of the item with ID
|
||||||
* (where the item ID was menu_refresh).
|
* {@link R.id.menu_refresh}. (where the item ID was menu_refresh).
|
||||||
*/
|
*/
|
||||||
public abstract void setRefreshActionItemState(boolean refreshing);
|
public abstract void setRefreshActionItemState(boolean refreshing);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link MenuInflater} for use when inflating menus. The implementation of this
|
* Returns a {@link MenuInflater} for use when inflating menus. The
|
||||||
* method in {@link ActionBarHelperBase} returns a wrapped menu inflater that can read
|
* implementation of this method in {@link ActionBarHelperBase} returns a
|
||||||
* action bar metadata from a menu resource pre-Honeycomb.
|
* wrapped menu inflater that can read action bar metadata from a menu
|
||||||
*/
|
* resource pre-Honeycomb.
|
||||||
public MenuInflater getMenuInflater(MenuInflater superMenuInflater) {
|
*/
|
||||||
return superMenuInflater;
|
public MenuInflater getMenuInflater(MenuInflater superMenuInflater) {
|
||||||
}
|
return superMenuInflater;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public void setHomeButtonEnabled(boolean enabled);
|
||||||
|
|
||||||
|
abstract public void setDisplayHomeAsUpEnabled(boolean enabled);
|
||||||
}
|
}
|
||||||
|
@ -316,4 +316,12 @@ public class ActionBarHelperBase extends ActionBarHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHomeButtonEnabled(boolean enabled) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDisplayHomeAsUpEnabled(boolean enabled) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,55 +26,65 @@ import android.view.View;
|
|||||||
import com.dougkeen.bart.R;
|
import com.dougkeen.bart.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An extension of {@link ActionBarHelper} that provides Android 3.0-specific functionality for
|
* An extension of {@link ActionBarHelper} that provides Android 3.0-specific
|
||||||
* Honeycomb tablets. It thus requires API level 11.
|
* functionality for Honeycomb tablets. It thus requires API level 11.
|
||||||
*/
|
*/
|
||||||
public class ActionBarHelperHoneycomb extends ActionBarHelper {
|
public class ActionBarHelperHoneycomb extends ActionBarHelper {
|
||||||
private Menu mOptionsMenu;
|
private Menu mOptionsMenu;
|
||||||
private View mRefreshIndeterminateProgressView = null;
|
private View mRefreshIndeterminateProgressView = null;
|
||||||
|
|
||||||
protected ActionBarHelperHoneycomb(Activity activity) {
|
protected ActionBarHelperHoneycomb(Activity activity) {
|
||||||
super(activity);
|
super(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
mOptionsMenu = menu;
|
mOptionsMenu = menu;
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRefreshActionItemState(boolean refreshing) {
|
public void setRefreshActionItemState(boolean refreshing) {
|
||||||
// On Honeycomb, we can set the state of the refresh button by giving it a custom
|
// On Honeycomb, we can set the state of the refresh button by giving it
|
||||||
// action view.
|
// a custom
|
||||||
if (mOptionsMenu == null) {
|
// action view.
|
||||||
return;
|
if (mOptionsMenu == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
|
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
|
||||||
if (refreshItem != null) {
|
if (refreshItem != null) {
|
||||||
if (refreshing) {
|
if (refreshing) {
|
||||||
if (mRefreshIndeterminateProgressView == null) {
|
if (mRefreshIndeterminateProgressView == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater)
|
LayoutInflater inflater = (LayoutInflater) getActionBarThemedContext()
|
||||||
getActionBarThemedContext().getSystemService(
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
Context.LAYOUT_INFLATER_SERVICE);
|
mRefreshIndeterminateProgressView = inflater.inflate(
|
||||||
mRefreshIndeterminateProgressView = inflater.inflate(
|
R.layout.actionbar_indeterminate_progress, null);
|
||||||
R.layout.actionbar_indeterminate_progress, null);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
refreshItem.setActionView(mRefreshIndeterminateProgressView);
|
refreshItem.setActionView(mRefreshIndeterminateProgressView);
|
||||||
} else {
|
} else {
|
||||||
refreshItem.setActionView(null);
|
refreshItem.setActionView(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Context} suitable for inflating layouts for the action bar. The
|
* Returns a {@link Context} suitable for inflating layouts for the action
|
||||||
* implementation for this method in {@link ActionBarHelperICS} asks the action bar for a
|
* bar. The implementation for this method in {@link ActionBarHelperICS}
|
||||||
* themed context.
|
* asks the action bar for a themed context.
|
||||||
*/
|
*/
|
||||||
protected Context getActionBarThemedContext() {
|
protected Context getActionBarThemedContext() {
|
||||||
return mActivity;
|
return mActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHomeButtonEnabled(boolean enabled) {
|
||||||
|
mActivity.getActionBar().setHomeButtonEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDisplayHomeAsUpEnabled(boolean enabled) {
|
||||||
|
mActivity.getActionBar().setDisplayHomeAsUpEnabled(enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@ package com.dougkeen.bart.actionbarcompat;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An extension of {@link com.example.android.actionbarcompat.ActionBarHelper} that provides Android
|
* An extension of {@link com.example.android.actionbarcompat.ActionBarHelper} that provides Android
|
||||||
|
Loading…
Reference in New Issue
Block a user