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"?>
|
||||
<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"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
@ -60,4 +60,4 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/topRow" />
|
||||
|
||||
</RelativeLayout>
|
||||
</merge>
|
@ -2,5 +2,6 @@
|
||||
<resources>
|
||||
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="blue_selection">#FF2A7998</color>
|
||||
|
||||
</resources>
|
@ -29,7 +29,7 @@ import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -172,17 +172,16 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
||||
}
|
||||
}
|
||||
setListAdapter(mDeparturesAdapter);
|
||||
getListView().setEmptyView(findViewById(android.R.id.empty));
|
||||
getListView().setOnItemClickListener(
|
||||
new AdapterView.OnItemClickListener() {
|
||||
final ListView listView = getListView();
|
||||
listView.setEmptyView(findViewById(android.R.id.empty));
|
||||
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView,
|
||||
View view, int position, long id) {
|
||||
mSelectedDeparture = (Departure) getListAdapter()
|
||||
.getItem(position);
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
public void onItemClick(AdapterView<?> adapterView, View view,
|
||||
int position, long id) {
|
||||
mSelectedDeparture = (Departure) getListAdapter().getItem(
|
||||
position);
|
||||
view.setSelected(true);
|
||||
startDepartureActionMode();
|
||||
}
|
||||
});
|
||||
@ -275,9 +274,8 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
||||
+ mDestination.name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private AdapterView<ListAdapter> getListView() {
|
||||
return (AdapterView<ListAdapter>) findViewById(android.R.id.list);
|
||||
private ListView getListView() {
|
||||
return (ListView) findViewById(android.R.id.list);
|
||||
}
|
||||
|
||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||
@ -487,6 +485,7 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
||||
}
|
||||
|
||||
private void startDepartureActionMode() {
|
||||
if (mActionMode == null)
|
||||
mActionMode = startActionMode(new DepartureActionMode());
|
||||
mActionMode.setTitle(mSelectedDeparture.getTrainDestinationName());
|
||||
mActionMode.setSubtitle(mSelectedDeparture.getTrainLengthText());
|
||||
@ -531,6 +530,8 @@ public class ViewDeparturesActivity extends SherlockFragmentActivity implements
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
getListView().clearChoices();
|
||||
getListView().requestLayout();
|
||||
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.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextSwitcher;
|
||||
import android.widget.TextView;
|
||||
@ -20,6 +21,7 @@ import android.widget.ViewSwitcher.ViewFactory;
|
||||
|
||||
import com.dougkeen.bart.R;
|
||||
import com.dougkeen.bart.controls.CountdownTextView;
|
||||
import com.dougkeen.bart.controls.DepartureListItemLayout;
|
||||
import com.dougkeen.bart.controls.TimedTextSwitcher;
|
||||
import com.dougkeen.bart.model.Departure;
|
||||
import com.dougkeen.bart.model.TextProvider;
|
||||
@ -58,11 +60,11 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view;
|
||||
if (convertView != null && convertView instanceof RelativeLayout) {
|
||||
if (convertView != null
|
||||
&& convertView instanceof DepartureListItemLayout) {
|
||||
view = convertView;
|
||||
} else {
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
view = inflater.inflate(R.layout.departure_listing, parent, false);
|
||||
view = new DepartureListItemLayout(getContext());
|
||||
}
|
||||
|
||||
final Departure departure = getItem(position);
|
||||
|
Loading…
Reference in New Issue
Block a user