Permalink
Browse files

Fix for passing in a resource to set home button. Fixes #20.

Removed all unecessary resources from library and moved into sample #23

Updated sample project and the "OtherActivity.cs" to show off how menus work.
  • Loading branch information...
1 parent 43cd5bc commit c59b5a2dd58233355477c0eb7c9e882d3b3cc67f @jamesmontemagno jamesmontemagno committed Mar 28, 2013
@@ -49,20 +49,15 @@ public override bool OnCreateOptionsMenu(IMenu menu)
return base.OnCreateOptionsMenu(menu);
}
- public void AddHomeAction(Type activity)
+ public void AddHomeAction(Type activity, int resId)
{
var homeIntent = new Intent(this, activity);
homeIntent.AddFlags(ActivityFlags.ClearTop);
homeIntent.AddFlags(ActivityFlags.NewTask);
- LegacyBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, Resource.Drawable.ic_launcher));
+ LegacyBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, resId));
LegacyBar.SetDisplayHomeAsUpEnabled(true);
}
- public void AddHomeAction(Action action)
- {
- AddHomeAction(action, Resource.Drawable.ic_launcher);
- }
-
public void AddHomeAction(Action action, int resId, bool isHomeAsUpEnabled = true)
{
LegacyBar.SetHomeAction(new ActionLegacyBarAction(this, action, resId));
@@ -48,20 +48,15 @@ public override bool OnCreateOptionsMenu(IMenu menu)
return base.OnCreateOptionsMenu(menu);
}
- public void AddHomeAction(Type activity)
+ public void AddHomeAction(Type activity, int resId)
{
var homeIntent = new Intent(this, activity);
homeIntent.AddFlags(ActivityFlags.ClearTop);
homeIntent.AddFlags(ActivityFlags.NewTask);
- ActionBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, Resource.Drawable.ic_launcher));
+ ActionBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, resId));
ActionBar.SetDisplayHomeAsUpEnabled(true);
}
- public void AddHomeAction(Action action)
- {
- AddHomeAction(action, Resource.Drawable.ic_launcher);
- }
-
public void AddHomeAction(Action action, int resId, bool isHomeAsUpEnabled = true)
{
ActionBar.SetHomeAction(new ActionLegacyBarAction(this, action, resId));
@@ -49,19 +49,15 @@ public override bool OnCreateOptionsMenu(IMenu menu)
return base.OnCreateOptionsMenu(menu);
}
- public void AddHomeAction(Type activity)
+ public void AddHomeAction(Type activity, int resId)
{
var homeIntent = new Intent(this, activity);
homeIntent.AddFlags(ActivityFlags.ClearTop);
homeIntent.AddFlags(ActivityFlags.NewTask);
- ActionBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, Resource.Drawable.ic_launcher));
+ ActionBar.SetHomeAction(new DefaultLegacyBarAction(this, homeIntent, resId));
ActionBar.SetDisplayHomeAsUpEnabled(true);
}
- public void AddHomeAction(Action action)
- {
- AddHomeAction(action, Resource.Drawable.ic_launcher);
- }
public void AddHomeAction(Action action, int resId, bool isHomeAsUpEnabled = true)
{
@@ -82,11 +82,7 @@
<AndroidResource Include="Resources\Drawable\actionbar_btn_pressed_alt.xml" />
<AndroidResource Include="Resources\Drawable-hdpi\actionbar_back_indicator.png" />
<AndroidResource Include="Resources\Drawable-hdpi\ic_action_overflow_dark.png" />
- <AndroidResource Include="Resources\Drawable-hdpi\ic_launcher.png" />
- <AndroidResource Include="Resources\Drawable-ldpi\ic_launcher.png" />
- <AndroidResource Include="Resources\Drawable-mdpi\ic_launcher.png" />
<AndroidResource Include="Resources\Drawable-mdpi\ic_action_overflow_dark.png" />
- <AndroidResource Include="Resources\Drawable-xhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\Drawable-xhdpi\ic_action_overflow_dark.png" />
<AndroidResource Include="Resources\Layout\actionbar.axml">
<SubType>Designer</SubType>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="LegacyBar.Library">
- <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17" />
+ <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
<application android:label="LegacyBar.Library">
</application>
</manifest>
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
Oops, something went wrong.
@@ -1,13 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="Hello">Hello World!</string>
- <string name="app_name">LegacyBar</string>
<string name="actionbar_activity_not_found">Failed to open intent...</string>
- <string name="some_title">Some Title</string>
- <string name="menu_string_search">Search</string>
- <string name="menu_string_up">up</string>
- <string name="menu_string_down">down</string>
- <string name="menu_string_left">left</string>
- <string name="menu_string_right">right</string>
- <string name="menu_string_refresh">refresh</string>
</resources>
@@ -31,7 +31,7 @@
namespace LegacyBar.Sample
{
[Activity(Label = "Fragment Demo", MainLauncher = false, LaunchMode = LaunchMode.SingleTop,
- Icon = "@drawable/ic_launcher", Theme = "@style/MyTheme")]
+ Icon = "@drawable/icon", Theme = "@style/MyTheme")]
public class FragmentTabActivity : LegacyBarFragmentActivity
{
private TabHost _tabHost;
@@ -56,7 +56,7 @@ protected override void OnCreate(Bundle bundle)
ActionBar = FindViewById<Library.Bar.LegacyBar>(Resource.Id.actionbar);
ActionBar.Title = "Look Fragments";
ActionBar.CurrentActivity = this;
- AddHomeAction(typeof (HomeActivity));
+ AddHomeAction(typeof (HomeActivity), Resource.Drawable.icon);
var action = new MenuItemLegacyBarAction(this, this, Resource.Id.menu_search,
@@ -39,7 +39,7 @@ protected override void OnCreate(Bundle bundle)
LegacyBar = FindViewById<Library.Bar.LegacyBar>(Resource.Id.actionbar);
LegacyBar.CurrentActivity = this;
- LegacyBar.SetHomeLogo(Resource.Drawable.ic_launcher);
+ LegacyBar.SetHomeLogo(Resource.Drawable.icon);
/*
* You can also set the title of the LegacyBar with:
@@ -104,9 +104,7 @@
<Name>LegacyBar.Library</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <Folder Include="Resources\values\" />
- </ItemGroup>
+ <ItemGroup />
<ItemGroup>
<AndroidResource Include="Resources\drawable\ic_action_down.png" />
</ItemGroup>
@@ -272,4 +270,7 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
</ItemGroup>
+ <ItemGroup>
+ <AndroidResource Include="Resources\values\strings.xml" />
+ </ItemGroup>
</Project>
@@ -24,7 +24,7 @@
namespace LegacyBar.Sample
{
[Activity(Label = "OtherActivity", MainLauncher = false, LaunchMode = LaunchMode.SingleTop,
- Icon = "@drawable/ic_launcher", Theme = "@style/MyTheme")]
+ Icon = "@drawable/icon", Theme = "@style/MyTheme")]
internal class OtherActivity : LegacyBarActivity
{
protected override void OnCreate(Bundle savedInstanceState)
@@ -51,16 +51,20 @@ protected override void OnCreate(Bundle savedInstanceState)
break;
}
-
- MenuId = Resource.Menu.mainmenu;
+ //First we will specify the menu we are using.
+ MenuId = Resource.Menu.othermainmenu;
LegacyBar = FindViewById<Library.Bar.LegacyBar>(Resource.Id.actionbar);
+
// You can also assign the title programmatically by passing a
// CharSequence or resource id.
LegacyBar.Title = "Other Activity";
- AddHomeAction(typeof (HomeActivity));
+
+ //Set the Up button to go home, also much set current activity on the Legacy Bar
+ AddHomeAction(typeof (HomeActivity), Resource.Drawable.icon);
LegacyBar.CurrentActivity = this;
+ //always show the search icon no matter what.
var itemActionBarAction = new MenuItemLegacyBarAction(
this, this, Resource.Id.menu_search, LegacyBar.LightIcons ? Resource.Drawable.ic_action_search : Resource.Drawable.ic_action_search_dark,
Resource.String.menu_string_search)
@@ -69,13 +73,34 @@ protected override void OnCreate(Bundle savedInstanceState)
};
LegacyBar.AddAction(itemActionBarAction);
+
+ //the rest of them I will say NEVER show. now on devices with a menu button you can press it and it will show old menus with the icon you specifies in the menu.xml file
+ //on newer devices without a menu button an overflow will appear.
itemActionBarAction = new MenuItemLegacyBarAction(
this, this, Resource.Id.menu_refresh, LegacyBar.LightIcons ? Resource.Drawable.ic_action_refresh :
Resource.Drawable.ic_action_refresh_dark,
Resource.String.menu_string_refresh)
{ActionType = ActionType.Never};
LegacyBar.AddAction(itemActionBarAction);
+ itemActionBarAction = new MenuItemLegacyBarAction(
+ this, this, Resource.Id.menu_test1, LegacyBar.LightIcons ? Resource.Drawable.ic_action_refresh :
+ Resource.Drawable.ic_action_refresh_dark,
+ Resource.String.menu_string_refresh) { ActionType = ActionType.Never };
+ LegacyBar.AddAction(itemActionBarAction);
+
+ itemActionBarAction = new MenuItemLegacyBarAction(
+ this, this, Resource.Id.menu_test2, LegacyBar.LightIcons ? Resource.Drawable.ic_action_refresh :
+ Resource.Drawable.ic_action_refresh_dark,
+ Resource.String.menu_string_refresh) { ActionType = ActionType.Never };
+ LegacyBar.AddAction(itemActionBarAction);
+
+ itemActionBarAction = new MenuItemLegacyBarAction(
+ this, this, Resource.Id.menu_test3, LegacyBar.LightIcons ? Resource.Drawable.ic_action_refresh :
+ Resource.Drawable.ic_action_refresh_dark,
+ Resource.String.menu_string_refresh) { ActionType = ActionType.Never };
+ LegacyBar.AddAction(itemActionBarAction);
+
var bottomActionBar = FindViewById<Library.Bar.LegacyBar>(Resource.Id.bottomActionbar);
var action = new MenuItemLegacyBarAction(this, this, Resource.Id.menu_up, bottomActionBar.LightIcons ? Resource.Drawable.ic_action_up : Resource.Drawable.ic_action_up_dark,
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.0" package="legacybar.sample" android:installLocation="internalOnly">
- <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17" />
+ <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="16" />
<application android:label="LegacyBar Sample"></application>
</manifest>
@@ -20,4 +20,17 @@
<item android:id="@+id/menu_refresh"
android:icon="@drawable/ic_menu_refresh"
android:title="@string/menu_string_refresh"/>
+
+ <item android:id="@+id/menu_test1"
+ android:icon="@drawable/ic_menu_refresh"
+ android:title="@string/menu_string_refresh"/>
+
+ <item android:id="@+id/menu_test2"
+ android:icon="@drawable/ic_menu_refresh"
+ android:title="@string/menu_string_refresh"/>
+
+ <item android:id="@+id/menu_test3"
+ android:icon="@drawable/ic_menu_refresh"
+ android:title="@string/menu_string_refresh"/>
+
</menu>
Oops, something went wrong.

0 comments on commit c59b5a2

Please sign in to comment.