Added menu items for selecting and deselecting all items

This commit is contained in:
daniel oeh 2012-07-23 18:12:09 +02:00
parent dfd3dc8bf8
commit 5f7d5d5e04
4 changed files with 48 additions and 10 deletions

View File

@ -128,7 +128,7 @@
</activity>
<activity android:label="@string/about_pref" android:name=".activity.AboutActivity" android:theme="@style/Theme.Sherlock.Light.NoActionBar"></activity>
<activity android:label="@string/opml_import_label" android:name=".activity.OpmlImportActivity"></activity>
<activity android:label="@string/opml_import_label" android:name=".activity.OpmlFeedChooserActivity" android:theme="@style/Theme.Sherlock.Light.NoActionBar"></activity>
<activity android:label="@string/opml_import_label" android:name=".activity.OpmlFeedChooserActivity"></activity>
</application>
</manifest>

View File

@ -5,5 +5,7 @@
<item name="move_up_item" type="id"/>
<item name="move_down_item" type="id"/>
<item type="id" name="clear_queue_item"/>
<item type="id" name="select_all_item"/>
<item type="id" name="deselect_all_item"/>
</resources>

View File

@ -134,5 +134,8 @@
<string name="reading_opml_label">Reading OPML file</string>
<string name="opml_reader_error">An error has occured while reading the opml document:</string>
<string name="opml_import_error_dir_empty">It seems like the import directory is empty. Please copy a OPML file into the directory to import it.</string>
<string name="select_all_label">Select all</string>
<string name="deselect_all_label">Deselect all</string>
</resources>

View File

@ -14,13 +14,15 @@ import android.widget.Button;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.opml.OpmlElement;
public class OpmlFeedChooserActivity extends SherlockActivity {
private static final String TAG = "OpmlFeedChooserActivity";
public static final String EXTRA_SELECTED_ITEMS = "de.danoeh.antennapod.selectedItems";
private Button butConfirm;
@ -43,22 +45,22 @@ public class OpmlFeedChooserActivity extends SherlockActivity {
getTitleList());
feedlist.setAdapter(listAdapter);
butCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_CANCELED);
finish();
}
}
});
butConfirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
SparseBooleanArray checked = feedlist.getCheckedItemPositions();
int checkedCount = 0;
// Get number of checked items
for (int i = 0; i < checked.size(); i++) {
@ -67,7 +69,7 @@ public class OpmlFeedChooserActivity extends SherlockActivity {
}
}
int[] selection = new int[checkedCount];
for (int i = 0, collected = 0; collected < checkedCount; i++) {
for (int i = 0, collected = 0; collected < checkedCount; i++) {
if (checked.valueAt(i)) {
selection[collected] = checked.keyAt(i);
collected++;
@ -76,7 +78,8 @@ public class OpmlFeedChooserActivity extends SherlockActivity {
intent.putExtra(EXTRA_SELECTED_ITEMS, selection);
setResult(RESULT_OK, intent);
finish();
}});
}
});
}
@ -90,6 +93,36 @@ public class OpmlFeedChooserActivity extends SherlockActivity {
}
return result;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, R.id.select_all_item, Menu.NONE,
R.string.select_all_label).setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, R.id.deselect_all_item, Menu.NONE,
R.string.deselect_all_label).setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.select_all_item:
selectAllItems(true);
return true;
case R.id.deselect_all_item:
selectAllItems(false);
return true;
default:
return false;
}
}
private void selectAllItems(boolean b) {
for (int i = 0; i < feedlist.getCount(); i++) {
feedlist.setItemChecked(i, b);
}
}
}