Listitems are now highlighted when in actionmode

This commit is contained in:
daniel oeh 2012-07-05 16:43:57 +02:00
parent 3c4df7a89d
commit 3768761e90
9 changed files with 129 additions and 51 deletions

View File

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="#33B5E5" />
<solid android:color="@color/selection_background" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<solid android:color="#33B5E5" />
<item android:state_focused="true"><shape android:shape="rectangle">
<solid android:color="@color/selection_background" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="selection_background">#33B5E5</color>
</resources>

View File

@ -18,5 +18,6 @@
<color name="navy">#000080</color>
<color name="black">#000000</color>
<color name="bright_blue">#33B5E5</color>
<color name="selection_background">#FEBB20</color>
</resources>

View File

@ -73,6 +73,7 @@ public class DownloadActivity extends SherlockListActivity implements
if (selection != null && mActionMode != null) {
mActionMode.finish();
}
dla.setSelectedItemIndex(position);
selectedDownload = selection;
mActionMode = startActionMode(DownloadActivity.this);
return true;
@ -138,5 +139,6 @@ public class DownloadActivity extends SherlockListActivity implements
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
selectedDownload = null;
dla.setSelectedItemIndex(DownloadlistAdapter.SELECTION_NONE);
}
}

View File

@ -16,9 +16,14 @@ import de.podfetcher.feed.FeedMedia;
import de.podfetcher.util.Converter;
public class DownloadlistAdapter extends ArrayAdapter<DownloadStatus> {
private int selectedItemIndex;
public static final int SELECTION_NONE = -1;
public DownloadlistAdapter(Context context, int textViewResourceId,
DownloadStatus[] objects) {
super(context, textViewResourceId, objects);
selectedItemIndex = SELECTION_NONE;
}
@Override
@ -47,6 +52,13 @@ public class DownloadlistAdapter extends ArrayAdapter<DownloadStatus> {
holder = (Holder) convertView.getTag();
}
if (position == selectedItemIndex) {
convertView.setBackgroundColor(convertView.getResources().getColor(
R.color.selection_background));
} else {
convertView.setBackgroundResource(0);
}
String titleText = null;
if (feedFile.getClass() == FeedMedia.class) {
titleText = ((FeedMedia) feedFile).getItem().getTitle();
@ -72,4 +84,14 @@ public class DownloadlistAdapter extends ArrayAdapter<DownloadStatus> {
TextView percent;
ProgressBar progbar;
}
public int getSelectedItemIndex() {
return selectedItemIndex;
}
public void setSelectedItemIndex(int selectedItemIndex) {
this.selectedItemIndex = selectedItemIndex;
notifyDataSetChanged();
}
}

View File

@ -18,17 +18,23 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
private OnClickListener onButActionClicked;
private boolean showFeedtitle;
private int selectedItemIndex;
public static final int SELECTION_NONE = -1;
public FeedItemlistAdapter(Context context, int textViewResourceId,
List<FeedItem> objects, OnClickListener onButActionClicked, boolean showFeedtitle) {
List<FeedItem> objects, OnClickListener onButActionClicked,
boolean showFeedtitle) {
super(context, textViewResourceId, objects);
this.onButActionClicked = onButActionClicked;
this.showFeedtitle = showFeedtitle;
this.selectedItemIndex = SELECTION_NONE;
}
@Override
@ -57,14 +63,22 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.encInfo = (RelativeLayout) convertView
.findViewById(R.id.enc_info);
if (showFeedtitle) {
holder.feedtitle = (TextView) convertView.findViewById(R.id.txtvFeedname);
holder.feedtitle = (TextView) convertView
.findViewById(R.id.txtvFeedname);
}
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
if (position == selectedItemIndex) {
convertView.setBackgroundColor(convertView.getResources().getColor(
R.color.selection_background));
} else {
convertView.setBackgroundResource(0);
}
holder.title.setText(item.getTitle());
if (showFeedtitle) {
holder.feedtitle.setVisibility(View.VISIBLE);
@ -94,15 +108,15 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
.getSize()));
holder.downloaded.setVisibility(View.GONE);
}
if (item.getMedia().isDownloading()) {
holder.downloading.setVisibility(View.VISIBLE);
} else {
holder.downloading.setVisibility(View.GONE);
}
String type = item.getMedia().getMime_type();
if (type.startsWith("audio")) {
holder.type.setImageResource(R.drawable.type_audio);
} else if (type.startsWith("video")) {
@ -114,6 +128,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.butAction.setFocusable(false);
holder.butAction.setOnClickListener(onButActionClicked);
return convertView;
}
@ -129,4 +144,14 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
ImageButton butAction;
RelativeLayout encInfo;
}
public int getSelectedItemIndex() {
return selectedItemIndex;
}
public void setSelectedItemIndex(int selectedItemIndex) {
this.selectedItemIndex = selectedItemIndex;
notifyDataSetChanged();
}
}

View File

@ -24,9 +24,13 @@ import android.graphics.Color;
public class FeedlistAdapter extends ArrayAdapter<Feed> {
private static final String TAG = "FeedlistAdapter";
private int selectedItemIndex;
public static final int SELECTION_NONE = -1;
public FeedlistAdapter(Context context, int textViewResourceId,
List<Feed> objects) {
super(context, textViewResourceId, objects);
selectedItemIndex = SELECTION_NONE;
}
@Override
@ -57,6 +61,13 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
holder = (Holder) convertView.getTag();
}
if (position == selectedItemIndex) {
convertView.setBackgroundColor(convertView.getResources().getColor(
R.color.selection_background));
} else {
convertView.setBackgroundResource(0);
}
holder.title.setText(feed.getTitle());
holder.lastUpdate.setText("Last Update: "
+ DateUtils.formatSameDayTime(feed.getLastUpdate().getTime(),
@ -93,4 +104,13 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
ImageView image;
}
public int getSelectedItemIndex() {
return selectedItemIndex;
}
public void setSelectedItemIndex(int selectedItemIndex) {
this.selectedItemIndex = selectedItemIndex;
notifyDataSetChanged();
}
}

View File

@ -28,7 +28,8 @@ import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import android.util.Log;
public class FeedlistFragment extends SherlockListFragment {
public class FeedlistFragment extends SherlockListFragment implements
ActionMode.Callback {
private static final String TAG = "FeedlistFragment";
public static final String EXTRA_SELECTED_FEED = "extra.de.podfetcher.activity.selected_feed";
@ -83,9 +84,10 @@ public class FeedlistFragment extends SherlockListFragment {
if (mActionMode != null) {
mActionMode.finish();
}
fla.setSelectedItemIndex(position);
selectedFeed = selection;
mActionMode = getSherlockActivity().startActionMode(
mActionModeCallback);
FeedlistFragment.this);
}
return true;
@ -132,48 +134,45 @@ public class FeedlistFragment extends SherlockListFragment {
pActivity.startActivity(showFeed);
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
mode.setTitle(selectedFeed.getTitle());
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
mode.setTitle(selectedFeed.getTitle());
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (FeedMenuHandler.onOptionsItemClicked(getSherlockActivity(),
item, selectedFeed)) {
fla.notifyDataSetChanged();
} else {
switch (item.getItemId()) {
case R.id.remove_item:
FeedRemover remover = new FeedRemover(getSherlockActivity()) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
fla.notifyDataSetChanged();
}
};
remover.execute(selectedFeed);
break;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (FeedMenuHandler.onOptionsItemClicked(getSherlockActivity(), item,
selectedFeed)) {
fla.notifyDataSetChanged();
} else {
switch (item.getItemId()) {
case R.id.remove_item:
FeedRemover remover = new FeedRemover(getSherlockActivity()) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
fla.notifyDataSetChanged();
}
};
remover.execute(selectedFeed);
break;
}
mode.finish();
return true;
}
mode.finish();
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
selectedFeed = null;
}
};
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
selectedFeed = null;
fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE);
}
}

View File

@ -140,6 +140,7 @@ public class ItemlistFragment extends SherlockListFragment implements
selectedItem = newSelectedItem;
mActionMode = getSherlockActivity().startActionMode(
ItemlistFragment.this);
fila.setSelectedItemIndex(index);
} else {
mActionMode.finish();
}
@ -151,6 +152,7 @@ public class ItemlistFragment extends SherlockListFragment implements
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
this.getListView().setItemsCanFocus(true);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
@Override
@ -162,6 +164,7 @@ public class ItemlistFragment extends SherlockListFragment implements
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
selectedItem = null;
fila.setSelectedItemIndex(FeedItemlistAdapter.SELECTION_NONE);
}
@Override