Train selection now stays highlighted while action bar is showing (unusually difficult to pull off... wtf, Android SDK?)
This commit is contained in:
parent
5656750ad6
commit
b69abf9a38
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:bart="http://schemas.android.com/apk/res/com.dougkeen.bart"
|
xmlns:bart="http://schemas.android.com/apk/res/com.dougkeen.bart"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" >
|
android:layout_height="fill_parent" >
|
||||||
@ -60,4 +60,4 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_below="@id/topRow" />
|
android:layout_below="@id/topRow" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</merge>
|
@ -2,5 +2,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<color name="black">#FF000000</color>
|
<color name="black">#FF000000</color>
|
||||||
|
<color name="blue_selection">#FF2A7998</color>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -29,7 +29,7 @@ import android.view.View;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -172,17 +172,16 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setListAdapter(mDeparturesAdapter);
|
setListAdapter(mDeparturesAdapter);
|
||||||
getListView().setEmptyView(findViewById(android.R.id.empty));
|
final ListView listView = getListView();
|
||||||
getListView().setOnItemClickListener(
|
listView.setEmptyView(findViewById(android.R.id.empty));
|
||||||
new AdapterView.OnItemClickListener() {
|
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||||
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapterView,
|
public void onItemClick(AdapterView<?> adapterView, View view,
|
||||||
View view, int position, long id) {
|
int position, long id) {
|
||||||
mSelectedDeparture = (Departure) getListAdapter()
|
mSelectedDeparture = (Departure) getListAdapter().getItem(
|
||||||
.getItem(position);
|
position);
|
||||||
if (mActionMode != null) {
|
view.setSelected(true);
|
||||||
mActionMode.finish();
|
|
||||||
}
|
|
||||||
startDepartureActionMode();
|
startDepartureActionMode();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -275,9 +274,8 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
|||||||
+ mDestination.name);
|
+ mDestination.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
private ListView getListView() {
|
||||||
private AdapterView<ListAdapter> getListView() {
|
return (ListView) findViewById(android.R.id.list);
|
||||||
return (AdapterView<ListAdapter>) findViewById(android.R.id.list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
@ -487,6 +485,7 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startDepartureActionMode() {
|
private void startDepartureActionMode() {
|
||||||
|
if (mActionMode == null)
|
||||||
mActionMode = startActionMode(new DepartureActionMode());
|
mActionMode = startActionMode(new DepartureActionMode());
|
||||||
mActionMode.setTitle(mSelectedDeparture.getTrainDestinationName());
|
mActionMode.setTitle(mSelectedDeparture.getTrainDestinationName());
|
||||||
mActionMode.setSubtitle(mSelectedDeparture.getTrainLengthText());
|
mActionMode.setSubtitle(mSelectedDeparture.getTrainLengthText());
|
||||||
@ -531,6 +530,8 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
|
getListView().clearChoices();
|
||||||
|
getListView().requestLayout();
|
||||||
mActionMode = null;
|
mActionMode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
src/com/dougkeen/bart/controls/DepartureListItemLayout.java
Normal file
42
src/com/dougkeen/bart/controls/DepartureListItemLayout.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package com.dougkeen.bart.controls;
|
||||||
|
|
||||||
|
import com.dougkeen.bart.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.widget.Checkable;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
public class DepartureListItemLayout extends RelativeLayout implements
|
||||||
|
Checkable {
|
||||||
|
|
||||||
|
public DepartureListItemLayout(Context context) {
|
||||||
|
super(context);
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.departure_listing, this,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean mChecked;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return mChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChecked(boolean checked) {
|
||||||
|
mChecked = checked;
|
||||||
|
if (isChecked()) {
|
||||||
|
setBackgroundDrawable(getContext().getResources().getDrawable(
|
||||||
|
R.color.blue_selection));
|
||||||
|
} else {
|
||||||
|
setBackgroundDrawable(getContext().getResources().getDrawable(
|
||||||
|
android.R.color.transparent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toggle() {
|
||||||
|
setChecked(!isChecked());
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ import android.view.ViewGroup;
|
|||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextSwitcher;
|
import android.widget.TextSwitcher;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -20,6 +21,7 @@ import android.widget.ViewSwitcher.ViewFactory;
|
|||||||
|
|
||||||
import com.dougkeen.bart.R;
|
import com.dougkeen.bart.R;
|
||||||
import com.dougkeen.bart.controls.CountdownTextView;
|
import com.dougkeen.bart.controls.CountdownTextView;
|
||||||
|
import com.dougkeen.bart.controls.DepartureListItemLayout;
|
||||||
import com.dougkeen.bart.controls.TimedTextSwitcher;
|
import com.dougkeen.bart.controls.TimedTextSwitcher;
|
||||||
import com.dougkeen.bart.model.Departure;
|
import com.dougkeen.bart.model.Departure;
|
||||||
import com.dougkeen.bart.model.TextProvider;
|
import com.dougkeen.bart.model.TextProvider;
|
||||||
@ -58,11 +60,11 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View view;
|
View view;
|
||||||
if (convertView != null && convertView instanceof RelativeLayout) {
|
if (convertView != null
|
||||||
|
&& convertView instanceof DepartureListItemLayout) {
|
||||||
view = convertView;
|
view = convertView;
|
||||||
} else {
|
} else {
|
||||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
view = new DepartureListItemLayout(getContext());
|
||||||
view = inflater.inflate(R.layout.departure_listing, parent, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Departure departure = getItem(position);
|
final Departure departure = getItem(position);
|
||||||
|
Loading…
Reference in New Issue
Block a user