Skip to content

Commit

Permalink
Merge pull request Cheesebaron#37 from jamesmontemagno/master
Browse files Browse the repository at this point in the history
Fix logo padding & Implement Custom BaseAdapter for spinner
  • Loading branch information
Cheesebaron committed Apr 22, 2013
2 parents 0cd4b4b + 56d4579 commit f73432a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 30 deletions.
79 changes: 59 additions & 20 deletions LegacyBar.Library/Bar/LegacyBar.cs
Expand Up @@ -329,33 +329,72 @@ public void SetHomeAction(LegacyBarAction legacyBarAction)
((LayoutParams)_titleLayout.LayoutParameters).AddRule(LayoutRules.RightOf, Resource.Id.actionbar_home_bg);
}

public void SetDropDown(Context context, string[] items, EventHandler<AdapterView.ItemSelectedEventArgs> eventHandler)
public int DropDownSelectedItemPosition
{
if (items == null)
return;
//if no items then show the title.
if (items.Length == 0)
get { return _titleDropdown.SelectedItemPosition; }
set
{
_titleView.Visibility = ViewStates.Visible;
_titleDropdown.Visibility = ViewStates.Gone;
try
{
_titleDropdown.SetSelection(value);
}
catch (Exception)
{
}

}
else
{
var previousSelected = _titleDropdown.SelectedItemPosition;
_titleView.Visibility = ViewStates.Gone;
var adapter = new ArrayAdapter(context, Android.Resource.Layout.SimpleSpinnerItem, items);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleDropDownItem1Line);
}

_titleDropdown.Visibility = ViewStates.Visible;
_titleDropdown.Adapter = adapter;
if(eventHandler != null)
_titleDropdown.ItemSelected += eventHandler;

if (previousSelected >= 0 && previousSelected < items.Length)
_titleDropdown.SetSelection(previousSelected);
/// <summary>
/// Sets teh drop down list with a customer adapter and callback when items change
/// if adapter.Count == 0 then the spinner will NOT be shown and you will have to call this method again.
/// </summary>
/// <param name="adapter">Adapter to display</param>
/// <param name="eventHandler">Event handler to callback. (can be null)</param>
public void SetDropDown(BaseAdapter adapter, EventHandler<AdapterView.ItemSelectedEventArgs> eventHandler)
{
if (adapter == null)
return;



if (adapter.Count == 0)
{
_titleView.Visibility = ViewStates.Visible;
_titleDropdown.Visibility = ViewStates.Gone;
}
else
{
var previousSelected = _titleDropdown.SelectedItemPosition;
_titleView.Visibility = ViewStates.Gone;

_titleDropdown.Visibility = ViewStates.Visible;
_titleDropdown.Adapter = adapter;
if (eventHandler != null)
_titleDropdown.ItemSelected += eventHandler;

if (previousSelected >= 0 && previousSelected < adapter.Count)
_titleDropdown.SetSelection(previousSelected);
}
}

/// <summary>
/// Sets the drop down items with a SimpleDropDownItem1Line Array Adapter
/// if items.Length == 0 then the spinner will NOT be shown and you will have to call this method again.
/// </summary>
/// <param name="context">context to create under for adapter</param>
/// <param name="items"> items to set</param>
/// <param name="eventHandler">event handler for item selected change (can be null)</param>
public void SetDropDown(Context context, string[] items, EventHandler<AdapterView.ItemSelectedEventArgs> eventHandler)
{
if (items == null)
return;

var adapter = new ArrayAdapter(context, Android.Resource.Layout.SimpleSpinnerItem, items);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleDropDownItem1Line);

}
SetDropDown(adapter, eventHandler);
}


Expand Down
8 changes: 2 additions & 6 deletions LegacyBar.Library/Resources/Layout/actionbar.axml
Expand Up @@ -27,11 +27,8 @@
android:visibility="visible">
<ImageView
android:id="@+id/actionbar_home_logo"
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="@dimen/actionbar_item_height"
android:scaleType="centerCrop"
android:background="@drawable/actionbar_btn"
android:layout_marginLeft="6dp"
style="@style/actionbarhomelogo"
android:visibility="gone"/>
<RelativeLayout
Expand All @@ -45,9 +42,8 @@
<!-- TODO: Make configurable. -->
<ImageButton
android:id="@+id/actionbar_home_btn"
android:scaleType="center"
android:scaleType="centerCrop"
style="@style/actionbarhomeitem"
android:paddingRight="0dp"
android:background="@drawable/actionbar_btn"/>
</RelativeLayout>
<ImageView
Expand Down
2 changes: 1 addition & 1 deletion LegacyBar.Library/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions LegacyBar.Library/Resources/Values/styles.xml
Expand Up @@ -40,11 +40,15 @@
<item name="android:layout_height">@dimen/actionbar_item_height</item>
<item name="android:layout_marginRight">1px</item>
<item name="android:layout_marginLeft">0px</item>
<item name="android:padding">4dp</item>
<item name="android:padding">8dp</item>
</style>
<style name="actionbarhomelogo">
<style name="actionbarhomelogo" parent="actionbaritem">
<item name="android:layout_width">@dimen/actionbar_home_item_width</item>
<item name="android:layout_height">@dimen/actionbar_item_height</item>
<item name="android:layout_marginRight">1px</item>
<item name="android:layout_marginLeft">6dp</item>
<item name="android:layout_marginLeft">6px</item>
<item name="android:paddingTop">8dp</item>
<item name="android:padding">8dp</item>
</style>
<style name="actionbarprogressbar" parent="@android:style/Widget.ProgressBar.Small">
</style>
Expand Down

0 comments on commit f73432a

Please sign in to comment.