Browse Source

Make action bar spinner navigation appear correctly.

pull/11/head
Eric Kok 12 years ago
parent
commit
8199af4e0a
  1. 7
      core/res/layout/list_item_filter.xml
  2. 14
      core/res/layout/list_item_navigation.xml
  3. 13
      core/res/layout/list_item_separator.xml
  4. 4
      core/res/menu/activity_torrents.xml
  5. 14
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 4
      core/src/org/transdroid/core/gui/lists/SimpleListItemView.java
  7. 19
      core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java
  8. 35
      core/src/org/transdroid/core/gui/navigation/FilterListDropDownAdapter.java
  9. 8
      core/src/org/transdroid/core/gui/navigation/FilterSeparatorView.java
  10. 25
      full/AndroidManifest.xml

7
core/res/layout/list_item_filter.xml

@ -2,15 +2,16 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="4dip" android:paddingBottom="@dimen/margin_half"
android:paddingBottom="4dip"
android:paddingLeft="@dimen/margin_default" android:paddingLeft="@dimen/margin_default"
android:paddingRight="@dimen/margin_default" > android:paddingRight="@dimen/margin_default"
android:paddingTop="@dimen/margin_half" >
<TextView <TextView
android:id="@+id/item_text" android:id="@+id/item_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="17sp"
android:textIsSelectable="true" /> android:textIsSelectable="true" />
</FrameLayout> </FrameLayout>

14
core/res/layout/list_item_navigation.xml

@ -2,8 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="4dip" android:orientation="vertical"
android:paddingBottom="4dip"
android:paddingLeft="@dimen/margin_default" android:paddingLeft="@dimen/margin_default"
android:paddingRight="@dimen/margin_default" > android:paddingRight="@dimen/margin_default" >
@ -11,12 +10,17 @@
android:id="@+id/filter_text" android:id="@+id/filter_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textIsSelectable="false" /> android:textColor="@android:color/primary_text_dark"
android:textIsSelectable="false"
android:textSize="17sp" />
<TextView <TextView
android:id="@+id/server_text" android:id="@+id/server_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textIsSelectable="false" /> android:layout_marginTop="-4dip"
android:textColor="@android:color/primary_text_dark"
android:textIsSelectable="false"
android:textSize="13sp" />
</LinearLayout> </LinearLayout>

13
core/res/layout/list_item_separator.xml

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="@dimen/margin_half" android:paddingLeft="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half" android:paddingRight="@dimen/margin_half" >
android:orientation="horizontal" >
<TextView <TextView
android:id="@+id/separator_text" android:id="@+id/separator_text"
style="@style/SectionHeader"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textIsSelectable="false" android:textIsSelectable="false" />
style="@style/SectionHeader" />
</LinearLayout> </FrameLayout>

4
core/res/menu/activity_torrents.xml

@ -3,7 +3,7 @@
<item <item
android:id="@+id/action_add" android:id="@+id/action_add"
android:icon="@drawable/ic_action_new" android:icon="@drawable/ic_action_new"
android:showAsAction="always" android:showAsAction="ifRoom"
android:title="@string/action_add"> android:title="@string/action_add">
<menu> <menu>
<item android:id="@+id/action_add_fromurl" android:title="@string/action_addfromurl" /> <item android:id="@+id/action_add_fromurl" android:title="@string/action_addfromurl" />
@ -14,7 +14,7 @@
<item <item
android:id="@+id/action_search" android:id="@+id/action_search"
android:icon="@drawable/ic_action_search" android:icon="@drawable/ic_action_search"
android:showAsAction="always" android:showAsAction="ifRoom"
android:title="@string/action_search"/> android:title="@string/action_search"/>
<item <item
android:id="@+id/action_rss" android:id="@+id/action_rss"

14
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -105,20 +105,26 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Set up navigation, with an action bar spinner and possibly (if room) with a filter list // Set up navigation, with an action bar spinner and possibly (if room) with a filter list
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setHomeButtonEnabled(false); getSupportActionBar().setHomeButtonEnabled(false);
navigationSpinnerAdapter = FilterListAdapter_.getInstance_(this).setNavigationFilterManager(this); getSupportActionBar().setDisplayShowTitleEnabled(false);
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this).setNavigationFilterManager(this);
// Servers are always added to the action bar spinner // Servers are always added to the action bar spinner
navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings()); navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings());
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
if (filtersList != null) { if (filtersList != null) {
// There was room for a dedicated filter list; add the status types // There was room for a dedicated filter list; create adapter and add the status types
navigationListAdapter = FilterListAdapter_.getInstance_(this); navigationListAdapter = FilterListAdapter_.getInstance_(this);
filtersList.setAdapter(navigationListAdapter);
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this)); navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationListAdapter.updateLabels(new ArrayList<SimpleListItem>());
filtersList.setAdapter(navigationListAdapter);
filtersList.setOnItemSelectedListener(onFilterListItemSelected); filtersList.setOnItemSelectedListener(onFilterListItemSelected);
} else { } else {
// Add status types directly to the action bar spinner // Add status types directly to the action bar spinner
navigationSpinnerAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this)); navigationSpinnerAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationSpinnerAdapter.updateLabels(new ArrayList<SimpleListItem>());
} }
// Now that all items (or at least their adapters) have been added
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
currentFilter = StatusType.getShowAllType(this); currentFilter = StatusType.getShowAllType(this);
// Connect to the last used server // Connect to the last used server

4
core/src/org/transdroid/core/gui/lists/SimpleListItemView.java

@ -4,7 +4,7 @@ import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import android.content.Context; import android.content.Context;
import android.widget.LinearLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
@ -12,7 +12,7 @@ import android.widget.TextView;
* @author Eric Kok * @author Eric Kok
*/ */
@EViewGroup(resName="list_item_filter") @EViewGroup(resName="list_item_filter")
public class SimpleListItemView extends LinearLayout { public class SimpleListItemView extends FrameLayout {
@ViewById @ViewById
protected TextView itemText; protected TextView itemText;

19
core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -10,9 +10,6 @@ import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager; import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import android.content.Context; import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import com.commonsware.cwac.merge.MergeAdapter; import com.commonsware.cwac.merge.MergeAdapter;
@ -22,14 +19,14 @@ import com.commonsware.cwac.merge.MergeAdapter;
* @author Eric Kok * @author Eric Kok
*/ */
@EBean @EBean
public class FilterListAdapter extends MergeAdapter implements SpinnerAdapter { public class FilterListAdapter extends MergeAdapter {
@RootContext @RootContext
protected Context context; protected Context context;
private SimpleListItemAdapter serverItems = null; private SimpleListItemAdapter serverItems = null;
private SimpleListItemAdapter statusTypeItems = null; private SimpleListItemAdapter statusTypeItems = null;
private SimpleListItemAdapter labelItems = null; private SimpleListItemAdapter labelItems = null;
private NavigationFilterManager navigationFilterManager; protected NavigationFilterManager navigationFilterManager;
/** /**
* Stores which screen, or manager, handles navigation selection and display * Stores which screen, or manager, handles navigation selection and display
@ -88,17 +85,5 @@ public class FilterListAdapter extends MergeAdapter implements SpinnerAdapter {
this.labelItems = null; this.labelItems = null;
} }
} }
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
NavigationSelectionView filterItemView;
if (convertView == null || !(convertView instanceof NavigationSelectionView)) {
filterItemView = NavigationSelectionView_.build(context).setNavigationFilterManager(navigationFilterManager);
} else {
filterItemView = (NavigationSelectionView) convertView;
}
filterItemView.bind();
return filterItemView;
}
} }

35
core/src/org/transdroid/core/gui/navigation/FilterListDropDownAdapter.java

@ -0,0 +1,35 @@
package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.EBean;
import android.view.View;
import android.view.ViewGroup;
/**
* List adapter that holds filter items, that is, servers, view types and labels and is displayed as content to a
* Spinner instead of a ListView.
* @author Eric Kok
*/
@EBean
public class FilterListDropDownAdapter extends FilterListAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item shown in the spinner
NavigationSelectionView filterItemView;
if (convertView == null || !(convertView instanceof NavigationSelectionView)) {
filterItemView = NavigationSelectionView_.build(context).setNavigationFilterManager(navigationFilterManager);
} else {
filterItemView = (NavigationSelectionView) convertView;
}
filterItemView.bind();
return filterItemView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// This returns the item to show in the drop down list
return super.getView(position, convertView, parent);
}
}

8
core/src/org/transdroid/core/gui/navigation/FilterSeparatorView.java

@ -4,16 +4,16 @@ import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import android.content.Context; import android.content.Context;
import android.widget.LinearLayout; import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
* A list item that shows a sub header or separator (in underlined Holo style). * A list item that shows a sub header or separator (in underlined Holo style).
*
* @author Eric Kok * @author Eric Kok
*/ */
@EViewGroup(resName="list_item_separator") @EViewGroup(resName="list_item_separator")
public class FilterSeparatorView extends LinearLayout { public class FilterSeparatorView extends FrameLayout {
protected String text; protected String text;
@ -31,6 +31,8 @@ public class FilterSeparatorView extends LinearLayout {
*/ */
public FilterSeparatorView setText(String text) { public FilterSeparatorView setText(String text) {
separatorText.setText(text); separatorText.setText(text);
setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT,
AbsListView.LayoutParams.WRAP_CONTENT));
return this; return this;
} }

25
full/AndroidManifest.xml

@ -19,8 +19,11 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
@ -30,10 +33,10 @@
<!-- Main activities --> <!-- Main activities -->
<activity <activity
android:name="org.transdroid.core.gui.TorrentsActivity_" android:name="org.transdroid.core.gui.TorrentsActivity_"
android:label="@string/app_name"
android:icon="@drawable/ic_activity_torrents" android:icon="@drawable/ic_activity_torrents"
android:uiOptions="splitActionBarWhenNarrow" android:label="@string/app_name"
android:theme="@style/TransdroidTheme" > android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -45,13 +48,13 @@
<meta-data <meta-data
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value="org.transdroid.gui.search.Search" /> android:value="org.transdroid.core.gui.SearchActivity_" />
</activity> </activity>
<activity <activity
android:name="org.transdroid.core.gui.DetailsActivity_" android:name="org.transdroid.core.gui.DetailsActivity_"
android:icon="@drawable/ic_activity_torrents" android:icon="@drawable/ic_activity_torrents"
android:uiOptions="splitActionBarWhenNarrow" android:theme="@style/TransdroidTheme"
android:theme="@style/TransdroidTheme" > android:uiOptions="splitActionBarWhenNarrow" >
</activity> </activity>
<!-- Settings screens --> <!-- Settings screens -->
@ -62,12 +65,12 @@
<activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" /> <activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" /> <activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" /> <activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" />
<!-- Search --> <!-- Search -->
<activity <activity
android:name="org.transdroid.core.gui.SearchActivity" android:name="org.transdroid.core.gui.SearchActivity_"
android:label="@string/search_torrentsearch"
android:icon="@drawable/ic_activity_torrents" android:icon="@drawable/ic_activity_torrents"
android:label="@string/search_torrentsearch"
android:theme="@style/TransdroidTheme" > android:theme="@style/TransdroidTheme" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEARCH" /> <action android:name="android.intent.action.SEARCH" />

Loading…
Cancel
Save