Upgraded HoloEverywhere, refactored quick route and add route dialogs to use Fragments
This commit is contained in:
parent
38c4c3bd03
commit
bcc40e291d
@ -6,6 +6,5 @@
|
|||||||
<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>
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.dougkeen.bart"
|
package="com.dougkeen.bart"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionCode="19"
|
android:versionCode="20"
|
||||||
android:versionName="2.0.1" >
|
android:versionName="2.0.2" >
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
@ -41,30 +41,6 @@
|
|||||||
<data android:mimeType="vnd.android.cursor.item/com.dougkeen.bart.favorite" />
|
<data android:mimeType="vnd.android.cursor.item/com.dougkeen.bart.favorite" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name="AddRouteActivity"
|
|
||||||
android:label="@string/add_route"
|
|
||||||
android:theme="@style/DialogHoloDark" >
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.INSERT" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
|
|
||||||
<data android:mimeType="vnd.android.cursor.dir/com.dougkeen.bart.favorite" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name="QuickRouteActivity"
|
|
||||||
android:label="@string/quick_departure_lookup"
|
|
||||||
android:theme="@style/DialogHoloDark" >
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.PICK" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
|
|
||||||
<data android:mimeType="vnd.android.cursor.dir/com.dougkeen.bart.arbitraryroute" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="ViewDeparturesActivity"
|
android:name="ViewDeparturesActivity"
|
||||||
android:label="@string/departures" >
|
android:label="@string/departures" >
|
||||||
|
@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@android:id/progress"
|
android:id="@android:id/progress"
|
||||||
style="@style/ProgressBarHolo.Horizontal"
|
style="@style/Holo.ProgressBar.Horizontal"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:indeterminate="true"
|
android:indeterminate="true"
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
android:id="@android:id/empty"
|
android:id="@android:id/empty"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
style="ButtonBar"
|
style="ButtonBar"
|
||||||
|
@ -79,31 +79,4 @@
|
|||||||
android:layout_toLeftOf="@id/return_checkbox_text"
|
android:layout_toLeftOf="@id/return_checkbox_text"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/buttonBar"
|
|
||||||
style="@style/ButtonBar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/return_checkbox"
|
|
||||||
android:orientation="horizontal" >
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/cancelButton"
|
|
||||||
style="ButtonHoloBorderless"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@android:string/cancel" >
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/okButton"
|
|
||||||
style="ButtonHoloBorderless"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@android:string/ok" >
|
|
||||||
</Button>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -11,6 +11,30 @@
|
|||||||
<item name="android:paddingBottom">10dp</item>
|
<item name="android:paddingBottom">10dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="LargeText">
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">20dp</item>
|
||||||
|
<item name="android:ellipsize">end</item>
|
||||||
|
<item name="android:singleLine">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="MediumText">
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">16dp</item>
|
||||||
|
<item name="android:ellipsize">end</item>
|
||||||
|
<item name="android:singleLine">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="SmallText">
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:textSize">12dp</item>
|
||||||
|
<item name="android:ellipsize">end</item>
|
||||||
|
<item name="android:singleLine">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="FavoriteListingTextView">
|
<style name="FavoriteListingTextView">
|
||||||
<item name="android:layout_width">wrap_content</item>
|
<item name="android:layout_width">wrap_content</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
@ -83,10 +107,5 @@
|
|||||||
<style name="bottomButton">
|
<style name="bottomButton">
|
||||||
<item name="android:background">#222</item>
|
<item name="android:background">#222</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="ButtonHoloBorderless" parent="ButtonHoloDark">
|
|
||||||
<item name="android:background">@drawable/btn_borderless_holo_dark</item>
|
|
||||||
<item name="android:textColor">#ffffff</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,84 +0,0 @@
|
|||||||
package com.dougkeen.bart;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.dougkeen.bart.model.Station;
|
|
||||||
|
|
||||||
public abstract class AbstractRouteSelectionActivity extends Activity {
|
|
||||||
|
|
||||||
public AbstractRouteSelectionActivity() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.route_form);
|
|
||||||
|
|
||||||
ArrayAdapter<Station> originSpinnerAdapter = new ArrayAdapter<Station>(
|
|
||||||
this, android.R.layout.simple_spinner_item,
|
|
||||||
Station.getStationList());
|
|
||||||
originSpinnerAdapter
|
|
||||||
.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
|
||||||
((Spinner) findViewById(R.id.origin_spinner))
|
|
||||||
.setAdapter(originSpinnerAdapter);
|
|
||||||
|
|
||||||
ArrayAdapter<Station> destinationSpinnerAdapter = new ArrayAdapter<Station>(
|
|
||||||
this, android.R.layout.simple_spinner_item,
|
|
||||||
Station.getStationList());
|
|
||||||
destinationSpinnerAdapter
|
|
||||||
.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
|
||||||
|
|
||||||
((Spinner) findViewById(R.id.destination_spinner))
|
|
||||||
.setAdapter(destinationSpinnerAdapter);
|
|
||||||
|
|
||||||
Button okButton = (Button) findViewById(R.id.okButton);
|
|
||||||
okButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
Station origin = (Station) ((Spinner) findViewById(R.id.origin_spinner))
|
|
||||||
.getSelectedItem();
|
|
||||||
Station destination = (Station) ((Spinner) findViewById(R.id.destination_spinner))
|
|
||||||
.getSelectedItem();
|
|
||||||
if (origin == null) {
|
|
||||||
Toast.makeText(v.getContext(),
|
|
||||||
com.dougkeen.bart.R.string.error_null_origin,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (destination == null) {
|
|
||||||
Toast.makeText(v.getContext(),
|
|
||||||
com.dougkeen.bart.R.string.error_null_destination,
|
|
||||||
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).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onOkButtonClick(origin, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
Button cancelButton = (Button) findViewById(R.id.cancelButton);
|
|
||||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract protected void onOkButtonClick(Station origin, Station destination);
|
|
||||||
}
|
|
102
src/com/dougkeen/bart/AbstractRouteSelectionFragment.java
Normal file
102
src/com/dougkeen/bart/AbstractRouteSelectionFragment.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package com.dougkeen.bart;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.WazaBe.HoloEverywhere.AlertDialog;
|
||||||
|
import com.dougkeen.bart.model.Station;
|
||||||
|
|
||||||
|
public abstract class AbstractRouteSelectionFragment extends DialogFragment {
|
||||||
|
|
||||||
|
protected String mTitle;
|
||||||
|
|
||||||
|
public AbstractRouteSelectionFragment(String title) {
|
||||||
|
super();
|
||||||
|
mTitle = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
|
||||||
|
final Dialog dialog = getDialog();
|
||||||
|
final FragmentActivity activity = getActivity();
|
||||||
|
ArrayAdapter<Station> originSpinnerAdapter = new ArrayAdapter<Station>(
|
||||||
|
activity, android.R.layout.simple_spinner_item,
|
||||||
|
Station.getStationList());
|
||||||
|
originSpinnerAdapter
|
||||||
|
.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
||||||
|
((Spinner) dialog.findViewById(R.id.origin_spinner))
|
||||||
|
.setAdapter(originSpinnerAdapter);
|
||||||
|
|
||||||
|
ArrayAdapter<Station> destinationSpinnerAdapter = new ArrayAdapter<Station>(
|
||||||
|
activity, android.R.layout.simple_spinner_item,
|
||||||
|
Station.getStationList());
|
||||||
|
destinationSpinnerAdapter
|
||||||
|
.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
||||||
|
|
||||||
|
((Spinner) dialog.findViewById(R.id.destination_spinner))
|
||||||
|
.setAdapter(destinationSpinnerAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final FragmentActivity activity = getActivity();
|
||||||
|
|
||||||
|
return new AlertDialog.Builder(activity)
|
||||||
|
.setTitle(mTitle)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setView(R.layout.route_form)
|
||||||
|
.setPositiveButton(R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int which) {
|
||||||
|
handleOkClick();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int whichButton) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
}).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleOkClick() {
|
||||||
|
final Dialog dialog = getDialog();
|
||||||
|
Station origin = (Station) ((Spinner) dialog
|
||||||
|
.findViewById(R.id.origin_spinner)).getSelectedItem();
|
||||||
|
Station destination = (Station) ((Spinner) dialog
|
||||||
|
.findViewById(R.id.destination_spinner)).getSelectedItem();
|
||||||
|
if (origin == null) {
|
||||||
|
Toast.makeText(dialog.getContext(),
|
||||||
|
com.dougkeen.bart.R.string.error_null_origin,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (destination == null) {
|
||||||
|
Toast.makeText(dialog.getContext(),
|
||||||
|
com.dougkeen.bart.R.string.error_null_destination,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (origin.equals(destination)) {
|
||||||
|
Toast.makeText(
|
||||||
|
dialog.getContext(),
|
||||||
|
com.dougkeen.bart.R.string.error_matching_origin_and_destination,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onOkButtonClick(origin, destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected void onOkButtonClick(Station origin, Station destination);
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package com.dougkeen.bart;
|
package com.dougkeen.bart;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
@ -11,12 +9,17 @@ import com.dougkeen.bart.data.RoutesColumns;
|
|||||||
import com.dougkeen.bart.model.Constants;
|
import com.dougkeen.bart.model.Constants;
|
||||||
import com.dougkeen.bart.model.Station;
|
import com.dougkeen.bart.model.Station;
|
||||||
|
|
||||||
public class AddRouteActivity extends AbstractRouteSelectionActivity {
|
public class AddRouteDialogFragment extends AbstractRouteSelectionFragment {
|
||||||
|
public AddRouteDialogFragment(String title) {
|
||||||
|
super(title);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public void onStart() {
|
||||||
super.onCreate(savedInstanceState);
|
super.onStart();
|
||||||
final View checkboxText = findViewById(R.id.return_checkbox_text);
|
final View checkboxText = getDialog().findViewById(
|
||||||
final View checkbox = findViewById(R.id.return_checkbox);
|
R.id.return_checkbox_text);
|
||||||
|
final View checkbox = getDialog().findViewById(R.id.return_checkbox);
|
||||||
checkboxText.setVisibility(View.VISIBLE);
|
checkboxText.setVisibility(View.VISIBLE);
|
||||||
checkbox.setVisibility(View.VISIBLE);
|
checkbox.setVisibility(View.VISIBLE);
|
||||||
checkboxText.setOnClickListener(new View.OnClickListener() {
|
checkboxText.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -33,19 +36,21 @@ public class AddRouteActivity extends AbstractRouteSelectionActivity {
|
|||||||
values.put(RoutesColumns.FROM_STATION.string, origin.abbreviation);
|
values.put(RoutesColumns.FROM_STATION.string, origin.abbreviation);
|
||||||
values.put(RoutesColumns.TO_STATION.string, destination.abbreviation);
|
values.put(RoutesColumns.TO_STATION.string, destination.abbreviation);
|
||||||
|
|
||||||
Uri newUri = getContentResolver().insert(
|
Uri newUri = getActivity().getContentResolver().insert(
|
||||||
Constants.FAVORITE_CONTENT_URI, values);
|
Constants.FAVORITE_CONTENT_URI, values);
|
||||||
|
|
||||||
if (((CheckBox) findViewById(R.id.return_checkbox)).isChecked()) {
|
if (((CheckBox) getDialog().findViewById(R.id.return_checkbox))
|
||||||
|
.isChecked()) {
|
||||||
values = new ContentValues();
|
values = new ContentValues();
|
||||||
values.put(RoutesColumns.FROM_STATION.string,
|
values.put(RoutesColumns.FROM_STATION.string,
|
||||||
destination.abbreviation);
|
destination.abbreviation);
|
||||||
values.put(RoutesColumns.TO_STATION.string, origin.abbreviation);
|
values.put(RoutesColumns.TO_STATION.string, origin.abbreviation);
|
||||||
|
|
||||||
getContentResolver().insert(Constants.FAVORITE_CONTENT_URI, values);
|
getActivity().getContentResolver().insert(
|
||||||
|
Constants.FAVORITE_CONTENT_URI, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
setResult(RESULT_OK, (new Intent()).setAction(newUri.toString()));
|
dismiss();
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,7 +5,11 @@ import android.content.Intent;
|
|||||||
import com.dougkeen.bart.model.Constants;
|
import com.dougkeen.bart.model.Constants;
|
||||||
import com.dougkeen.bart.model.Station;
|
import com.dougkeen.bart.model.Station;
|
||||||
|
|
||||||
public class QuickRouteActivity extends AbstractRouteSelectionActivity {
|
public class QuickRouteDialogFragment extends AbstractRouteSelectionFragment {
|
||||||
|
|
||||||
|
public QuickRouteDialogFragment(String title) {
|
||||||
|
super(title);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onOkButtonClick(Station origin, Station destination) {
|
protected void onOkButtonClick(Station origin, Station destination) {
|
@ -3,8 +3,6 @@ package com.dougkeen.bart;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.AlertDialog.Builder;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -14,15 +12,20 @@ import android.database.Cursor;
|
|||||||
import android.database.CursorWrapper;
|
import android.database.CursorWrapper;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CursorAdapter;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
import android.widget.SimpleCursorAdapter.ViewBinder;
|
import android.widget.SimpleCursorAdapter.ViewBinder;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockListActivity;
|
import com.WazaBe.HoloEverywhere.AlertDialog;
|
||||||
|
import com.WazaBe.HoloEverywhere.AlertDialog.Builder;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.ActionMode;
|
import com.actionbarsherlock.view.ActionMode;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
@ -33,11 +36,11 @@ import com.dougkeen.bart.model.Constants;
|
|||||||
import com.dougkeen.bart.model.Station;
|
import com.dougkeen.bart.model.Station;
|
||||||
import com.dougkeen.bart.networktasks.GetRouteFareTask;
|
import com.dougkeen.bart.networktasks.GetRouteFareTask;
|
||||||
|
|
||||||
public class RoutesListActivity extends SherlockListActivity {
|
public class RoutesListActivity extends SherlockFragmentActivity {
|
||||||
private static final TimeZone PACIFIC_TIME = TimeZone
|
private static final TimeZone PACIFIC_TIME = TimeZone
|
||||||
.getTimeZone("America/Los_Angeles");
|
.getTimeZone("America/Los_Angeles");
|
||||||
|
|
||||||
private static final int DIALOG_DELETE_EVENT = 0;
|
private static final int DIALOG_DELETE_ROUTE = 0;
|
||||||
|
|
||||||
protected Cursor mQuery;
|
protected Cursor mQuery;
|
||||||
|
|
||||||
@ -89,7 +92,19 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
|
getListView().setOnItemClickListener(
|
||||||
|
new AdapterView.OnItemClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> l, View v,
|
||||||
|
int position, long id) {
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
|
ContentUris.withAppendedId(
|
||||||
|
Constants.FAVORITE_CONTENT_URI, id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
getListView().setEmptyView(findViewById(android.R.id.empty));
|
||||||
getListView().setOnItemLongClickListener(
|
getListView().setOnItemLongClickListener(
|
||||||
new AdapterView.OnItemLongClickListener() {
|
new AdapterView.OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -120,8 +135,9 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startActivity(new Intent(Intent.ACTION_PICK,
|
DialogFragment dialog = new QuickRouteDialogFragment(
|
||||||
Constants.ARBITRARY_ROUTE_CONTENT_URI_ROOT));
|
getString(R.string.quick_departure_lookup));
|
||||||
|
dialog.show(getSupportFragmentManager(), "dialog");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -146,6 +162,22 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private AdapterView<ListAdapter> getListView() {
|
||||||
|
return (AdapterView<ListAdapter>) findViewById(android.R.id.list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CursorAdapter mListAdapter;
|
||||||
|
|
||||||
|
protected CursorAdapter getListAdapter() {
|
||||||
|
return mListAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setListAdapter(SimpleCursorAdapter adapter) {
|
||||||
|
mListAdapter = adapter;
|
||||||
|
getListView().setAdapter(mListAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshFares() {
|
private void refreshFares() {
|
||||||
if (mQuery.moveToFirst()) {
|
if (mQuery.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
@ -222,8 +254,8 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
if (itemId == R.id.add_favorite_menu_button) {
|
if (itemId == R.id.add_favorite_menu_button) {
|
||||||
startActivity(new Intent(Intent.ACTION_INSERT,
|
new AddRouteDialogFragment(getString(R.string.add_route)).show(
|
||||||
Constants.FAVORITE_CONTENT_URI));
|
getSupportFragmentManager(), "dialog");
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.view_system_map_button) {
|
} else if (itemId == R.id.view_system_map_button) {
|
||||||
startActivity(new Intent(this, ViewMapActivity.class));
|
startActivity(new Intent(this, ViewMapActivity.class));
|
||||||
@ -233,41 +265,6 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
|
||||||
ContentUris.withAppendedId(Constants.FAVORITE_CONTENT_URI, id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
|
||||||
if (id == DIALOG_DELETE_EVENT && mCurrentlySelectedUri != null) {
|
|
||||||
final AlertDialog.Builder builder = new Builder(this);
|
|
||||||
builder.setCancelable(false);
|
|
||||||
builder.setMessage("Are you sure you want to delete this route?");
|
|
||||||
builder.setPositiveButton(R.string.yes,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
getContentResolver().delete(mCurrentlySelectedUri,
|
|
||||||
null, null);
|
|
||||||
mCurrentlySelectedUri = null;
|
|
||||||
mCurrentlySelectedOrigin = null;
|
|
||||||
mCurrentlySelectedDestination = null;
|
|
||||||
mActionMode.finish();
|
|
||||||
removeDialog(DIALOG_DELETE_EVENT);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.cancel,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
removeDialog(DIALOG_DELETE_EVENT);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
return super.onCreateDialog(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startContextualActionMode() {
|
private void startContextualActionMode() {
|
||||||
mActionMode = startActionMode(new RouteActionMode());
|
mActionMode = startActionMode(new RouteActionMode());
|
||||||
mActionMode.setTitle(mCurrentlySelectedOrigin.name);
|
mActionMode.setTitle(mCurrentlySelectedOrigin.name);
|
||||||
@ -275,7 +272,6 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class RouteActionMode implements ActionMode.Callback {
|
private final class RouteActionMode implements ActionMode.Callback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
mode.getMenuInflater().inflate(R.menu.route_context_menu, menu);
|
mode.getMenuInflater().inflate(R.menu.route_context_menu, menu);
|
||||||
@ -295,7 +291,31 @@ public class RoutesListActivity extends SherlockListActivity {
|
|||||||
mode.finish();
|
mode.finish();
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.delete) {
|
} else if (item.getItemId() == R.id.delete) {
|
||||||
showDialog(DIALOG_DELETE_EVENT);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
|
RoutesListActivity.this);
|
||||||
|
builder.setCancelable(false);
|
||||||
|
builder.setMessage("Are you sure you want to delete this route?");
|
||||||
|
builder.setPositiveButton(R.string.yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int which) {
|
||||||
|
getContentResolver().delete(
|
||||||
|
mCurrentlySelectedUri, null, null);
|
||||||
|
mCurrentlySelectedUri = null;
|
||||||
|
mCurrentlySelectedOrigin = null;
|
||||||
|
mCurrentlySelectedDestination = null;
|
||||||
|
mActionMode.finish();
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ public class ViewDeparturesActivity extends SherlockListActivity {
|
|||||||
|
|
||||||
private static final int UNCERTAINTY_THRESHOLD = 17;
|
private static final int UNCERTAINTY_THRESHOLD = 17;
|
||||||
|
|
||||||
|
private static final int DIALOG_SET_ALERT = 1;
|
||||||
|
|
||||||
private Uri mUri;
|
private Uri mUri;
|
||||||
|
|
||||||
private Station mOrigin;
|
private Station mOrigin;
|
||||||
|
@ -41,6 +41,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
|||||||
private boolean bikeAllowed;
|
private boolean bikeAllowed;
|
||||||
private String trainLength;
|
private String trainLength;
|
||||||
private boolean requiresTransfer;
|
private boolean requiresTransfer;
|
||||||
|
private boolean transferScheduled;
|
||||||
|
|
||||||
private int minutes;
|
private int minutes;
|
||||||
|
|
||||||
@ -141,6 +142,14 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
|||||||
this.requiresTransfer = requiresTransfer;
|
this.requiresTransfer = requiresTransfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTransferScheduled() {
|
||||||
|
return transferScheduled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransferScheduled(boolean transferScheduled) {
|
||||||
|
this.transferScheduled = transferScheduled;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMinutes() {
|
public int getMinutes() {
|
||||||
return minutes;
|
return minutes;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.dougkeen.bart.model;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RealTimeDepartures {
|
public class RealTimeDepartures {
|
||||||
@ -89,6 +90,9 @@ public class RealTimeDepartures {
|
|||||||
if (route.trainDestinationIsApplicable(destination,
|
if (route.trainDestinationIsApplicable(destination,
|
||||||
departure.getLine())) {
|
departure.getLine())) {
|
||||||
departure.setRequiresTransfer(route.hasTransfer());
|
departure.setRequiresTransfer(route.hasTransfer());
|
||||||
|
departure
|
||||||
|
.setTransferScheduled(Line.YELLOW_ORANGE_SCHEDULED_TRANSFER
|
||||||
|
.equals(route.getDirectLine()));
|
||||||
getDepartures().add(departure);
|
getDepartures().add(departure);
|
||||||
departure.calculateEstimates(time);
|
departure.calculateEstimates(time);
|
||||||
return;
|
return;
|
||||||
@ -100,6 +104,29 @@ public class RealTimeDepartures {
|
|||||||
Collections.sort(getDepartures());
|
Collections.sort(getDepartures());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void finalizeDeparturesList() {
|
||||||
|
boolean hasDirectRoute = false;
|
||||||
|
for (Departure departure : getDepartures()) {
|
||||||
|
if (!departure.getRequiresTransfer()) {
|
||||||
|
hasDirectRoute = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasDirectRoute) {
|
||||||
|
Iterator<Departure> iterator = getDepartures().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Departure departure = iterator.next();
|
||||||
|
if (departure.getRequiresTransfer()
|
||||||
|
&& (!departure.isTransferScheduled() || departure
|
||||||
|
.getDestination().isBetween(getOrigin(),
|
||||||
|
getDestination(), departure.getLine()))) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortDepartures();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Route> getRoutes() {
|
public List<Route> getRoutes() {
|
||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
@ -257,4 +257,16 @@ public enum Station {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBetween(Station origin, Station destination, Line line) {
|
||||||
|
int originIndex = line.stations.indexOf(origin);
|
||||||
|
int destinationIndex = line.stations.indexOf(destination);
|
||||||
|
int stationIndex = line.stations.indexOf(this);
|
||||||
|
if (originIndex < 0 || destinationIndex < 0 || stationIndex < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.abs(stationIndex - originIndex) < Math.abs(destinationIndex
|
||||||
|
- originIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class EtdContentHandler extends DefaultHandler {
|
|||||||
} else if (localName.equals("etd")) {
|
} else if (localName.equals("etd")) {
|
||||||
currentDestination = null;
|
currentDestination = null;
|
||||||
} else if (localName.equals("station")) {
|
} else if (localName.equals("station")) {
|
||||||
realTimeDepartures.sortDepartures();
|
realTimeDepartures.finalizeDeparturesList();
|
||||||
}
|
}
|
||||||
isParsingTag = false;
|
isParsingTag = false;
|
||||||
currentValue = null;
|
currentValue = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user